CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > ANSYS > FLUENT

Fluent udf give zero instead of coordinate location

Register Blogs Community New Posts Updated Threads Search

Like Tree1Likes
  • 1 Post By vinerm

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   June 2, 2020, 04:35
Default Fluent udf give zero instead of coordinate location
  #1
Member
 
Join Date: Feb 2019
Posts: 69
Rep Power: 7
cfdnewb123 is on a distinguished road
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?
cfdnewb123 is offline   Reply With Quote

Old   June 2, 2020, 05:21
Default Typecast
  #2
Senior Member
 
vinerm's Avatar
 
Vinerm
Join Date: Jun 2009
Location: Nederland
Posts: 2,946
Blog Entries: 1
Rep Power: 36
vinerm will become famous soon enough
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.
vinerm is offline   Reply With Quote

Old   June 2, 2020, 09:28
Default
  #3
Member
 
Join Date: Feb 2019
Posts: 69
Rep Power: 7
cfdnewb123 is on a distinguished road
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.
cfdnewb123 is offline   Reply With Quote

Old   June 2, 2020, 09:30
Default The Code
  #4
Senior Member
 
vinerm's Avatar
 
Vinerm
Join Date: Jun 2009
Location: Nederland
Posts: 2,946
Blog Entries: 1
Rep Power: 36
vinerm will become famous soon enough
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.
vinerm is offline   Reply With Quote

Old   June 2, 2020, 09:47
Default
  #5
Member
 
Join Date: Feb 2019
Posts: 69
Rep Power: 7
cfdnewb123 is on a distinguished road
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;
}
cfdnewb123 is offline   Reply With Quote

Old   June 2, 2020, 09:51
Default Centroid
  #6
Senior Member
 
vinerm's Avatar
 
Vinerm
Join Date: Jun 2009
Location: Nederland
Posts: 2,946
Blog Entries: 1
Rep Power: 36
vinerm will become famous soon enough
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].
cfdnewb123 likes this.
__________________
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.
vinerm is offline   Reply With Quote

Old   June 2, 2020, 09:55
Default
  #7
Member
 
Join Date: Feb 2019
Posts: 69
Rep Power: 7
cfdnewb123 is on a distinguished road
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;
}
cfdnewb123 is offline   Reply With Quote

Old   June 2, 2020, 09:59
Default
  #8
Member
 
Join Date: Feb 2019
Posts: 69
Rep Power: 7
cfdnewb123 is on a distinguished road
Thanks so much! It works!
cfdnewb123 is offline   Reply With Quote

Old   June 2, 2020, 10:15
Default Good
  #9
Senior Member
 
vinerm's Avatar
 
Vinerm
Join Date: Jun 2009
Location: Nederland
Posts: 2,946
Blog Entries: 1
Rep Power: 36
vinerm will become famous soon enough
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.
vinerm is offline   Reply With Quote

Reply

Tags
ansys, fluent, udf


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


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


All times are GMT -4. The time now is 16:39.