Fluent udf give zero instead of coordinate location
I am working on DEFINE_TURBULENT_PROFILE. However, x[ND_ND] doesn't seems to work for me as it gives me zero. When I try monitoring its output (e.g. Message("x=%g and y=%g \n", x[0], x[1]);) on Fluent's console, I saw this instead - x=0 and y=0.
Basically it just keeps showing me zero. Even when I try "Message("x=%g and y=%g \n", x[0], 2);" but it shows 0 instead of 2! When I try outputting other output like S, the message doesn't show 0. Is x[ND_ND] ONLY for the "DEFINE_PROFILE" udf? Does it works for others like mine case? |
Typecast
That's because you are expecting the compiler to do the typecasting for you. 2 is an integer and you are trying to print it as float or double. Use 2. or 2.0. Furthermore, %g is not a good format specifier for such numbers, use %f or %lf.
|
Thanks for the reply. My issue is I am trying to define eddy viscosity as a function of position. I use xx=x[0] and y=x[0] but the position keep giving me 0. Because of this, my eddy viscosity is no longer a function of position as the position is constantly 0!
E.g. I try if (y>0.1) {S=2} else {S=1}. My solver keeps giving y=0 and thus the above sample if-else loop is meaningless as S is constantly 2. |
The Code
Most likely the reason is as I mentioned earlier, use of int values in place of real. If it is something other than that, I'd suggest you to copy whole code here for faster debugging.
|
The code works fine other than the if-else which does not switch as x & y are constantly equals to 0.
DEFINE_TURBULENT_VISCOSITY(test_mu_t,c,t) { real x[ND_ND]; real xx,y; real mu_t; real rho = C_R(c,t); real k = C_K(c,t); real d = C_D(c,t); real Omega, alpha; real dudx = C_DUDX(c,t); real dudy = C_DUDY(c,t); real dvdx = C_DVDX(c,t); real dvdy = C_DVDY(c,t); xx = x[0]; y = x[1]; alpha = 1+y; if (xx >= -0.1 && xx <= 0){ Omega = sqrt(abs(2*((0.5*(dudy-dvdx)-(1.76656/(alpha)))*(0.5*(dvdx-dudy)+(1.76656/(alpha)))*2))); //+ (d/k)*Cw*epsilon_xy*(31.76656/(alpha*R)); } else { Omega = sqrt(abs(0.5*((dudy-dvdx)*(dvdx-dudy) + (dvdx-dudy)*(dudy-dvdx)))); Message("Check to see if loop reaches here. x=%g.\n",xx); } mu_t = Cmu*rho*k*5/(SQR(Omega)); return mu_t; } |
Centroid
xx and y are 0 because x itself is 0. You have to use C_CENTROID(x, c, t) before setting xx = x[0] and y = x[1].
|
May i know how to use C_CENTROID(x, c, t)?
Do I just include C_CENTROID(x, c, t)? According to this site (https://www.afs.enea.it/project/nept...ec-define-init), DEFINE_TURBULENT_VISCOSITY(test_mu_t,c,t) { real x[ND_ND]; real xx,y; real mu_t; real rho = C_R(c,t); real k = C_K(c,t); real d = C_D(c,t); real Omega, alpha; real dudx = C_DUDX(c,t); real dudy = C_DUDY(c,t); real dvdx = C_DVDX(c,t); real dvdy = C_DVDY(c,t); C_CENTROID(x, c, t) xx = x[0]; y = x[1]; alpha = 1+y; if (xx >= -0.1 && xx <= 0){ Omega = sqrt(abs(2*((0.5*(dudy-dvdx)-(1.76656/(alpha)))*(0.5*(dvdx-dudy)+(1.76656/(alpha)))*2))); //+ (d/k)*Cw*epsilon_xy*(31.76656/(alpha*R)); } else { Omega = sqrt(abs(0.5*((dudy-dvdx)*(dvdx-dudy) + (dvdx-dudy)*(dudy-dvdx)))); Message("Check to see if it reaches here. x=%g.\n",xx); } mu_t = Cmu*rho*k*5/(SQR(Omega)); return mu_t; } |
Thanks so much! It works!
|
Good
Nice to know.
|
All times are GMT -4. The time now is 10:19. |