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

temperature gradient problem in udf

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

Like Tree7Likes
  • 6 Post By HenrikS
  • 1 Post By Ras0ul

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   March 25, 2009, 04:08
Default temperature gradient problem in udf
  #1
New Member
 
souviktor
Join Date: Mar 2009
Posts: 11
Rep Power: 17
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, 04:53
Default
  #2
Member
 
Henrik Ström
Join Date: Mar 2009
Posts: 33
Rep Power: 17
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
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: 17
Souviktor is on a distinguished road
Thanks a lot Henriks ,Your code snippet worked like a charm...!!!!
Souviktor is offline   Reply With Quote

Old   July 11, 2015, 15:49
Default temperature gradient fluent
  #4
New Member
 
Rasoul
Join Date: Jun 2015
Posts: 3
Rep Power: 10
Ras0ul is on a distinguished road
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
salehorafi likes this.
Ras0ul is offline   Reply With Quote

Old   February 25, 2019, 14:25
Default
  #5
New Member
 
Abhi
Join Date: Jan 2018
Posts: 27
Rep Power: 8
abhilasht is on a distinguished road
Quote:
Originally Posted by Ras0ul View Post
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
Did you solve this problem?
abhilasht is offline   Reply With Quote

Old   February 26, 2019, 06:37
Default
  #6
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 26
pakk will become famous soon enough
There is no indication that Fluent can not "properly calculate the square of the temperature gradient".
It is much more likely that Ras0ul made a mistake in his code.


But, because he never posted his code, we can not find out the truth.




(I don't understand why so many people ask here for help with their code, but then don't post their code... I really don't know what they expect to happen.)
pakk is offline   Reply With Quote

Old   March 10, 2019, 05:48
Unhappy
  #7
New Member
 
Jayant Kumar
Join Date: Mar 2019
Posts: 2
Rep Power: 0
Jayant Kumar is on a distinguished road
i have a cfd problem setup in which i have to insert a udf for soil temperature distribution with respect to depth and real time as an initial condition. I have the equation for it right now i have insert a constant soil temperature patch., please help in how may i proceed?
Jayant Kumar is offline   Reply With Quote

Reply

Tags
access, gradient, temperature, udf, violation

Thread Tools Search this Thread
Search this Thread:

Advanced Search
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 Off
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 19:36
Urgent,species gradient problem zhou FLUENT 0 March 4, 2004 12: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 06:39


All times are GMT -4. The time now is 20:04.