CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   Fluent UDF and Scheme Programming (http://www.cfd-online.com/Forums/fluent-udf/)
-   -   temperature gradient problem in udf (http://www.cfd-online.com/Forums/fluent-udf/62985-temperature-gradient-problem-udf.html)

Souviktor March 25, 2009 05:08

temperature gradient problem in udf
 
Hi all,I am using a udf to attach 2 body forces(source terms in momentum equation)one in x direction and another in y direction with 2 define_source macros written in same source file.


They both call a third function for some computational task(like a sin or cos function,entirely mathematical stuff).

Now,the problem is I am using c_t_g macro to calculate temperature gradient in both the source functions.I read in the manual
"In order to retain the gradient data (when you want to set up user-de ned scalar transport equations, for example), you can prevent the solver from freeing up memory by issuing the text command solve/set/expert and then answering yes to the question Keep temporary solver memory from being freed?. Note that when you do this, all of the gradient data is retained, but the calculation requires more memory to run."


I did that...But I am getting ACCESS VIOLATION during runtime...
Please help....

the udf is as follows....




Code:


#include "udf.h"

real getfld(real x_cord,real y_cord,int option)
{

real px,py,sinphi,cosphi,ans,r,H1;
 
px=.01;
py=-.005;

r=sqrt((x_cord-px)*(x_cord-px)+(y_cord-py)*(y_cord-py));
sinphi=fabs((y_cord-py)/r);
if(x_cord>px)
 cosphi=sqrt(1-sinphi*sinphi);
else
 cosphi=-sqrt(1-sinphi*sinphi);

H1=29.6/(r*r);


if (option==1)
  ans=2*H1*cosphi*sinphi;

else
  if(option==2)
    ans=H1*(sinphi*sinphi-cosphi*cosphi);
  else
    ans=H1;

return ans;

}








DEFINE_SOURCE(kbf_source_x, c, t, dS, eqn)
{
real x[ND_ND],beta_p,muzero,kai_m_zero,T_star,Tempt,term1,term2;
real denct,x1,y1,px,py,rsinphi,cosphi,Hx,Hy,H_east,H_west,del_H_square_del_x,del_T_del_x,del_T_del_y;
real con, source;

muzero=4*3.1454*.0000001;
kai_m_zero=.1;
beta_p=5.6*0.0001;

C_CENTROID(x, c, t);
x1=x[0];
y1-x[1];

Hx=getfld(x1,y1,1);
Hy=getfld(x1,y1,2);

H_east=getfld(x1+0.00001,y1,3);
H_west=getfld(x1-0.00001,y1,3);
del_H_square_del_x=(H_east*H_east-H_west*H_west)/.00002;
Tempt=C_T(c,t);
T_star=300;
                     
del_T_del_x=C_T_G(c,t)[0];           
del_T_del_y=C_T_G(c,t)[1];         



term1=.5*muzero*kai_m_zero*(1-beta_p*(Tempt-T_star))*del_H_square_del_x;
term2=muzero*kai_m_zero*kai_m_zero*beta_p*(Hx*del_T_del_x+Hy*del_T_del_y)*Hx;


source=term1+term2;
dS[eqn]=0;
return source;
}











DEFINE_SOURCE(kbf_source_y, c, t, dS, eqn)
{
real x[ND_ND],beta_p,muzero,kai_m_zero,T_star,Tempt,term1,term2;
real denct,x1,y1,px,py,rsinphi,cosphi,Hx,Hy,H_south,H_north,del_H_square_del_y,del_T_del_x,del_T_del_y;
real con, source;

muzero=4*3.1454*.0000001;
kai_m_zero=.1;
beta_p=5.6*0.0001;

C_CENTROID(x, c, t);
x1=x[0];
y1-x[1];

Hx=getfld(x1,y1,1);
Hy=getfld(x1,y1,2);

H_north=getfld(x1,y1+0.00001,3);
H_south=getfld(x1,y1-0.00001,3);
del_H_square_del_y=(H_north*H_north-H_south*H_south)/.00002;
Tempt=C_T(c,t);
T_star=300;

                     
del_T_del_x=C_T_G(c,t)[0];           
del_T_del_y=C_T_G(c,t)[1];         


term1=.5*muzero*kai_m_zero*(1-beta_p*(Tempt-T_star))*del_H_square_del_y;

term2=muzero*kai_m_zero*kai_m_zero*beta_p*(Hx*del_T_del_x+Hy*del_T_del_y)*Hy;


source=term1+term2;
dS[eqn]=0;
return source;
}


HenrikS March 25, 2009 05:53

If you turn on "Keep temporary solver memory from being freed", Fluent will start to store gradient data. However, there will be no gradient data stored from the previous iteration, so in your first iteration these will be undefined, which might cause your problem. Either turn the option on and do one or several iterations/time steps before you start your "real" simulation, to ensure that the gradients are there, or rewrite your code to include something like:

if ( NULL != THREAD_STORAGE(t,SV_T_G) )
{
temp_gradient_x = C_T_G(c,t)[0];
}
else
{
/* first iteration OR option to store gradients not turned on */
temp_gradient_x = 0.0;
}

Hope this helps!

/Henrik

Souviktor March 31, 2009 08:43

Thanks a lot Henriks ,Your code snippet worked like a charm...!!!!

Ras0ul July 11, 2015 15:49

temperature gradient fluent
 
Dear all
I entered the entropy generation equation in custom field function.but my result is wrong(not validated with paper). I examined my results and found that Fluent calculate the temperature gradient, but it can not properly calculate the square of the temperature gradient!!!
please help with this problem
thanks


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