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

Fluent udf--spatial derivative of user-defined scalar

Register Blogs Community New Posts Updated Threads Search

Like Tree7Likes
  • 2 Post By vinerm
  • 1 Post By vinerm
  • 2 Post By vinerm
  • 2 Post By vinerm

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   July 29, 2009, 10:36
Default Fluent udf--spatial derivative of user-defined scalar
  #1
Senior Member
 
Troy Snyder
Join Date: Jul 2009
Location: Akron, OH
Posts: 220
Rep Power: 19
tas38 is on a distinguished road
I would like to be able to take spatial derivatives of arbitrary scalar variables within a fluent udf. However, if for example, I put C_U(c,t) into user defined scalar 0 and then define user-defined scalar 1 as C_UDSI(c,t,1)=C_UDSI_G(c,t,0)[1], it produces erroneous values for scalar 1. Does anyone have any suggestions?

I would like to have such capability as I am attemping to add momentum source terms via udf that involve vorticity and vorticity magnitude, which are not explicitly defined field variables for use in udfs.
tas38 is offline   Reply With Quote

Old   February 9, 2011, 04:05
Default
  #2
New Member
 
tom pan
Join Date: Nov 2010
Posts: 14
Rep Power: 16
tompa is on a distinguished road
I have the same question.
Do you know how to solve it now?
I do need the anwser on my problem.
tompa is offline   Reply With Quote

Old   March 14, 2020, 11:12
Default
  #3
Member
 
Tanvir
Join Date: Nov 2016
Posts: 45
Rep Power: 10
wassli is on a distinguished road
Hi,
i am facing same problem in calculating derivatives.
can you please help me getting rid of this.
waiting for reply,
Thanks
wassli is offline   Reply With Quote

Old   March 16, 2020, 12:37
Default Derivatives
  #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
Do you face issue with the calculation of gradients or are the numbers being calculated wrong?
__________________
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   March 16, 2020, 12:49
Default
  #5
Member
 
Tanvir
Join Date: Nov 2016
Posts: 45
Rep Power: 10
wassli is on a distinguished road
Sir i get the gradients by using user defined scalar but numbers i get seems totally wrong. the core of code is
DUDY = fabs(C_DUDY(c,t));
C_UDSI(c,t,0) = C_T(c,t);
C_UDSI(c,t,1) = C_R(c,t);
C_UDSI(c,t,2) = C_CP(c,t);
DTDY = abs(C_UDSI_G(c,t,0)[1]);
DrhoDy = abs(C_UDSI_G(c,t,1)[1]);
DCPDY = abs(C_UDSI_G(c,t,2)[1]);
then i print the values but sometime it gives me positive values and sometimes negatives values are obtained regardless of using 'fabs' command.
//Message0("\n Velocity Gradient is %f",DUDY);
//Message0("\n Temp Gradient is %f",DTDY);
//Message0("\n Density Gradient is %f",DrhoDy);
//Message0("\n Heat capacity Gradient is %f",DCPDY);
wassli is offline   Reply With Quote

Old   March 16, 2020, 13:28
Default Derivatives
  #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
To get the derivatives of temperature, density, and C_p, you don't need to assign their values to scalars, until there is some other requirement. You can fetch their gradients using C_T_G and C_R_G. There are no gradient operators for C_p. By assigning value of the variable to scalar does not assign its gradient to the gradient of the scalar. However, if you keep the solution of scalar disabled, then you might get correct values. I have never used the method of assigning field to a scalar and then fetching gradients of the scalar. But for sure, you have keep the solution for the scalar disabled otherwise the field will change and will no longer represent whatever field was assigned to the scalar.
wassli and by1704116 like 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   March 16, 2020, 14:04
Default
  #7
Member
 
Tanvir
Join Date: Nov 2016
Posts: 45
Rep Power: 10
wassli is on a distinguished road
Thank you so much sir for your valuable advice . i will try this.. please tell me how can i access cell yPlus , because i need yplus in the code to compute turbulent prandtle number.
Thanks
wassli is offline   Reply With Quote

Old   March 16, 2020, 14:21
Default Yplus
  #8
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
Within a UDF, you may access y^+ using SV_WALL_YPLUS like

C_STORAGE_R(c, t, SV_WALL_YPLUS)
wassli 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   March 16, 2020, 14:41
Default
  #9
Member
 
Tanvir
Join Date: Nov 2016
Posts: 45
Rep Power: 10
wassli is on a distinguished road
Sir i have used it before but it ends up in segmentation fault right after very first iteration.
wassli is offline   Reply With Quote

Old   March 16, 2020, 16:13
Default Segmentation Violation
  #10
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
Segmentation violation error implies that UDF is trying to access a memory that is unavailable. That most likely happens because y^+ is defined only for faces and not for cells. So, use F_STORAGE_R instead of C_STORAGE_R.
wassli and by1704116 like 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   March 17, 2020, 07:49
Default
  #11
Member
 
Tanvir
Join Date: Nov 2016
Posts: 45
Rep Power: 10
wassli is on a distinguished road
Hi Sir,
so for i have progressed in storing yplus as a userdefined memory info and core of code is
DEFINE_ADJUST(adjust_fcn,d)
{
Thread *tf1, *tc1;
face_t f1;
cell_t c1;

real yplus;
int zone_id1; /* Wall in the geometry */
zone_id1 = 6;
tf1 = Lookup_Thread(d, zone_id1);

begin_f_loop(f1, tf1)
{
c1 = F_C0(f1,tf1);
tc1 = THREAD_T0(tf1);
yplus = F_STORAGE_R(f1,tf1,SV_WALL_YPLUS_UTAU);

C_UDMI(f1,tf1,0) = yplus;
printf(" \n yplus is %f ", C_UDMI(f1,tf1,0));
}
end_f_loop(f1, tf1)
}

But when i call this UDMI in Prandtl No Macro it gives me error which seems like i am not calling the right memory INFO . and i have tried many ways but could not succeed in this. Can you help me please..
wassli is offline   Reply With Quote

Old   March 17, 2020, 08:35
Default Arguments
  #12
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
The reason is that you are using wrong arguments for C_UDMI. This has to be C_UDMI(c1, tc1,0)
__________________
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   March 19, 2020, 05:37
Default Gradients
  #13
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
In your code for Prandtl number, you are trying to access gradients. Therefore, you have to do a little more work. Either assign the memory for gradients within the UDF or use the command

solve set expert

to tell Fluent NOT to free up the temporary memory. Only then the gradients become available in a UDF. To assign memory within UDF, search the forum for Scalar_Reconstruction. You will find all the commands required.
wassli and by1704116 like 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   October 26, 2020, 22:05
Default
  #14
New Member
 
Join Date: Jun 2020
Posts: 6
Rep Power: 6
BryceLos is on a distinguished road
Quote:
Originally Posted by wassli View Post
Hi Sir,
so for i have progressed in storing yplus as a userdefined memory info and core of code is
DEFINE_ADJUST(adjust_fcn,d)
{
Thread *tf1, *tc1;
face_t f1;
cell_t c1;

real yplus;
int zone_id1; /* Wall in the geometry */
zone_id1 = 6;
tf1 = Lookup_Thread(d, zone_id1);

begin_f_loop(f1, tf1)
{
c1 = F_C0(f1,tf1);
tc1 = THREAD_T0(tf1);
yplus = F_STORAGE_R(f1,tf1,SV_WALL_YPLUS_UTAU);

C_UDMI(f1,tf1,0) = yplus;
printf(" \n yplus is %f ", C_UDMI(f1,tf1,0));
}
end_f_loop(f1, tf1)
}

But when i call this UDMI in Prandtl No Macro it gives me error which seems like i am not calling the right memory INFO . and i have tried many ways but could not succeed in this. Can you help me please..
Dear Wassli,

You solved this on Prandtl number implementation based on yplus via UDF? Could you share the codes? Since I am stuck for a long time.

Thanks,
Bryce
BryceLos is offline   Reply With Quote

Reply


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
UDF in Fluent Andrew Fluent UDF and Scheme Programming 5 March 7, 2016 04:38
User defined scalar Tomik FLUENT 0 February 8, 2007 20:23
User defined function of mass flow rate Eric FLUENT 1 April 22, 2005 19:15
UDF of Zimont model in fluent Z Main CFD Forum 0 February 17, 2005 04:07
User defined rotational velocity in FLUENT Abhinav FLUENT 1 June 10, 2003 09:31


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