CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   Fluent UDF and Scheme Programming (https://www.cfd-online.com/Forums/fluent-udf/)
-   -   Fluent udf--spatial derivative of user-defined scalar (https://www.cfd-online.com/Forums/fluent-udf/66960-fluent-udf-spatial-derivative-user-defined-scalar.html)

tas38 July 29, 2009 09:36

Fluent udf--spatial derivative of user-defined scalar
 
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.

tompa February 9, 2011 03:05

I have the same question.
Do you know how to solve it now?
I do need the anwser on my problem.

wassli March 14, 2020 10:12

Hi,
i am facing same problem in calculating derivatives.
can you please help me getting rid of this.
waiting for reply,
Thanks

vinerm March 16, 2020 11:37

Derivatives
 
Do you face issue with the calculation of gradients or are the numbers being calculated wrong?

wassli March 16, 2020 11:49

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);

vinerm March 16, 2020 12:28

Derivatives
 
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 March 16, 2020 13:04

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

vinerm March 16, 2020 13:21

Yplus
 
Within a UDF, you may access y^+ using SV_WALL_YPLUS like

C_STORAGE_R(c, t, SV_WALL_YPLUS)

wassli March 16, 2020 13:41

Sir i have used it before but it ends up in segmentation fault right after very first iteration.

vinerm March 16, 2020 15:13

Segmentation Violation
 
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 March 17, 2020 06:49

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..

vinerm March 17, 2020 07:35

Arguments
 
The reason is that you are using wrong arguments for C_UDMI. This has to be C_UDMI(c1, tc1,0)

vinerm March 19, 2020 04:37

Gradients
 
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.

BryceLos October 26, 2020 21:05

Quote:

Originally Posted by wassli (Post 761852)
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


All times are GMT -4. The time now is 14:18.