FLUENT - Workaround for calculating a species gradient normal to a surface within a udf



Fluent gives a SEGMENTATION fault if one tries to calculate the gradient of species (except first species) using C_YI_G(c,t,i) macro.
Workaround for above problem is to store the mass fraction of species in UDS cell variables and then compute the gradient of User defined scalars which will give the species gradient.

/*****************************************************************/
/* UDF FOR Calculating the gradient in the normal direction to any surface */
/* Written by Ajay Parihar, Fluent India */

#include "udf.h"

DEFINE_ON_DEMAND(on_demand_calc)
{
Domain *d;
face_t f;
real NV_VEC(A);
real NV_VEC(B);
real mag;
cell_t c;
Thread *t, *tc;
d = Get_Domain(1); /*Get the domain ID*/
int wall_id=4; /* Modify the ID of surface on which you want to calculate the species gradient*/
t=Lookup_Thread(d,wall_id); /* Get the thread id of that surface*/

/* Loop over all surface faces*/
begin_f_loop(f,t)
{
F_AREA(A,f,t); /*Get the area vector*/
mag=NV_MAG(A); /*Magnitude of the area vector*/
NV_VS(B,=,A,/,mag);/*Calculate Unit vector B*/
c=F_C0(f,t);
tc=F_C0_THREAD(f,t);
C_UDSI(c,tc,0)=C_YI(c,tc,0); /*Store the first species mass fraction in a UDS*/
C_UDSI(c,tc,1)=C_YI(c,tc,1);/*Store the second species mass fraction in a UDS*/
C_UDSI(c,tc,2)=C_YI(c,tc,2);/*Store the third species mass fraction in a UDS*/

C_UDSI(c,tc,3)=NV_DOT(C_UDSI_G(c,tc,0),B);/*Store the first species gradient in normal dir in a UDS*/
C_UDSI(c,tc,4)=NV_DOT(C_UDSI_G(c,tc,1),B);/*Store the second species gradient in normal dir in a UDS*/
C_UDSI(c,tc,5)=NV_DOT(C_UDSI_G(c,tc,2),B);/*Store the third species gradient in normal dir in a UDS*/
/****Note: For post-processing check the contours of User scaler 3,4 and 5*/
}
end_f_loop(f, t)
}





Show Form
No comments yet. Be the first to add a comment!