# Temperature and Strain Rate Dependent Viscosity UDF Code

 Register Blogs Members List Search Today's Posts Mark Forums Read

 March 28, 2022, 02:45 Temperature and Strain Rate Dependent Viscosity UDF Code #1 New Member   SANDIPSINH Join Date: Mar 2022 Posts: 2 Rep Power: 0 #include "udf.h" #include "mem.h" #define Q 145000 //J/mol #define A 8.86e+6 #define n 3.55 #define R 8.314 //J/molK #define alpha 0.045 DEFINE_PROPERTY(cell_viscosity, c, t) { real temp = C_T(c, t); real mu_lam; real Z; real Flow_stress; real x; real strain; if (strain < 0) { strain = 10; } else { strain = C_STRAIN_RATE_MAG(c, t); } Z = (strain)*exp(Q / (R*temp)); x = pow((Z / A), (1. / n)); Flow_stress = (1. / alpha)*(log(x + sqrt(pow(x, 2) + 1.))); mu_lam = Flow_stress / (3.*strain); if (mu_lam > 0) return mu_lam; } we are trying to define the viscosity in term of strain rate and temperature using UDF code but, we are not getting value as expected.

 March 31, 2022, 22:57 #2 Senior Member   Alexander Join Date: Apr 2013 Posts: 2,363 Rep Power: 34 you should specify what exactly is different from your expectations compile the code and you will get following output: Code: ```warning C4715: 'cell_viscosity' : not all control paths return a value warning C4700: uninitialized local variable 'strain' used``` fix that take into account that DEFINE_PROPERTY macro is a loop over all cells in domain, but your variable strain contains only 1 value for the last cell, it overwrites each other cell. You may use used defined memory to store strain on each cell Also I would initialize strain for the 0-time moment __________________ best regards ****************************** press LIKE if this message was helpful

 April 5, 2022, 11:48 #3 New Member   SANDIPSINH Join Date: Mar 2022 Posts: 2 Rep Power: 0 Can you please show us how to do that because I am new to this and when I try this code every cell get's same viscosity value.