|
[Sponsors] |
Fluent udf give zero instead of coordinate location |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
June 2, 2020, 04:35 |
Fluent udf give zero instead of coordinate location
|
#1 |
Member
Join Date: Feb 2019
Posts: 69
Rep Power: 7 |
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? |
|
June 2, 2020, 05:21 |
Typecast
|
#2 |
Senior Member
|
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.
__________________
Regards, Vinerm PM to be used if and only if you do not want something to be shared publicly. PM is considered to be of the least priority. |
|
June 2, 2020, 09:28 |
|
#3 |
Member
Join Date: Feb 2019
Posts: 69
Rep Power: 7 |
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. |
|
June 2, 2020, 09:30 |
The Code
|
#4 |
Senior Member
|
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.
__________________
Regards, Vinerm PM to be used if and only if you do not want something to be shared publicly. PM is considered to be of the least priority. |
|
June 2, 2020, 09:47 |
|
#5 |
Member
Join Date: Feb 2019
Posts: 69
Rep Power: 7 |
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; } |
|
June 2, 2020, 09:51 |
Centroid
|
#6 |
Senior Member
|
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].
__________________
Regards, Vinerm PM to be used if and only if you do not want something to be shared publicly. PM is considered to be of the least priority. |
|
June 2, 2020, 09:55 |
|
#7 |
Member
Join Date: Feb 2019
Posts: 69
Rep Power: 7 |
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; } |
|
June 2, 2020, 09:59 |
|
#8 |
Member
Join Date: Feb 2019
Posts: 69
Rep Power: 7 |
Thanks so much! It works!
|
|
June 2, 2020, 10:15 |
Good
|
#9 |
Senior Member
|
Nice to know.
__________________
Regards, Vinerm PM to be used if and only if you do not want something to be shared publicly. PM is considered to be of the least priority. |
|
Tags |
ansys, fluent, udf |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Passing udf value to fluent | durg | Fluent UDF and Scheme Programming | 2 | February 11, 2019 13:55 |
Fluent do not use my velocity field(by UDF) to solve energy equation | tangleiplus | Fluent UDF and Scheme Programming | 6 | January 21, 2019 22:28 |
Fluent Boundary Condition with UDF | amitjoshi | FLUENT | 0 | November 16, 2018 03:21 |
Integrating data from UDF to Fluent | say2017 | FLUENT | 0 | October 20, 2017 14:50 |
Beginner help, coordinate udf with output file | nb92 | Fluent UDF and Scheme Programming | 0 | March 20, 2014 05:16 |