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

temperature gradient problem in udf

Register Blogs Members List Search Today's Posts Mark Forums Read

Like Tree1Likes
  • 1 Post By HenrikS

Reply
 
LinkBack Thread Tools Display Modes
Old   March 25, 2009, 05:08
Default temperature gradient problem in udf
  #1
New Member
 
souviktor
Join Date: Mar 2009
Posts: 11
Rep Power: 8
Souviktor is on a distinguished road
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;
}
Souviktor is offline   Reply With Quote

Old   March 25, 2009, 05:53
Default
  #2
Member
 
Henrik Ström
Join Date: Mar 2009
Posts: 32
Rep Power: 8
HenrikS is on a distinguished road
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
Arjun Jayakumar likes this.
HenrikS is offline   Reply With Quote

Old   March 31, 2009, 08:43
Default
  #3
New Member
 
souviktor
Join Date: Mar 2009
Posts: 11
Rep Power: 8
Souviktor is on a distinguished road
Thanks a lot Henriks ,Your code snippet worked like a charm...!!!!
Souviktor is offline   Reply With Quote

Reply

Tags
access, gradient, temperature, udf, violation

Thread Tools
Display Modes

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 On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help! Compiled UDF problem 4 Wave tank tutorial Shane FLUENT 1 September 3, 2010 02:32
Temperature gradient Jaho CFX 2 March 12, 2009 20:36
Urgent,species gradient problem zhou FLUENT 0 March 4, 2004 13:59
UDF reading the temperature gradient Fabian FLUENT 1 May 29, 2003 20:18
Direct calculation of temperature gradient J.W.Ryu FLUENT 5 December 27, 2001 07:39


All times are GMT -4. The time now is 05:43.