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

Define profile inlet_temperature in UDF

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

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   April 20, 2010, 05:10
Default Define profile inlet_temperature in UDF
  #1
Member
 
mohammad
Join Date: Apr 2010
Posts: 42
Rep Power: 15
mohammadkm is on a distinguished road
Dear users
I am trying to define profile inlet temperature as a function of wall temperature.
I wrote the code and compiled in fluent without any problem but i didnt get the answers that i expected. For instance my fluid temperature in outlet in axis is 112.0 K(!!!) whereas my average inlet temperature is 295 K.
heat flux=4000(w/m2),D=4.5mm.
my profile fluid temperature is:
T=walltemp-(function of heatflux and radius)
here is my code:
# include "udf.h"
# include "math.h"
DEFINE_PROFILE(x_temperature,thread,index)
{
Domain *domain=Get_Domain(1);
real x[ND_ND]; /* this will hold the position vector */
real y;
face_t f;
Thread *t0;
int Zone_ID=4;
t0=Lookup_Thread(domain,Zone_ID);
begin_f_loop(f,thread) /* loops over all faces in the thread passed in the DEFINE macro argument */
{
F_CENTROID(x,f,thread);
y = x[1];
F_PROFILE(f,thread,index) =F_T(f,t0)-(14.58588249*(0.75-((y/0.00225)*(y/0.00225))+(0.25*(pow((y/0.00225),4)))));
}
end_f_loop(f,thread)
}
//////////////////////////////////
How can i compute average inlet tempreture from the equation?
I'm really stuck here and dont know what to do.
could any body help me?
thanks a lot.
mohammadkm is offline   Reply With Quote

Old   April 23, 2010, 17:25
Default
  #2
Member
 
mohammad
Join Date: Apr 2010
Posts: 42
Rep Power: 15
mohammadkm is on a distinguished road
I tried to define profile temperature in tube( with constant wall temperature) with function of radius.I got solution converged with out any problem but fluid temperature is 383 K in all fluid zone!!! and its wrong.
DEFINE_PROFILE(x_temperature,thread,index)
{
real x[ND_ND]; /* this will hold the position vector */
real y;
face_t f;
begin_f_loop(f,thread) /* loops over all faces in the thread passed in the DEFINE macro argument */
{
F_CENTROID(x,f,thread);
y = x[1];
F_PROFILE(f,thread,index) =383+(4.603027808*0.000001*(1-(pow((y/0.00225),4))));
}
end_f_loop(f,thread)
}
please help in me in this problem i really need to solve this problem and i don know what to do.
mohammadkm is offline   Reply With Quote

Old   April 26, 2010, 09:27
Default
  #3
Senior Member
 
dmoroian's Avatar
 
Dragos
Join Date: Mar 2009
Posts: 648
Rep Power: 20
dmoroian is on a distinguished road
Quote:
Originally Posted by mohammadkm View Post
Dear users
I am trying to define profile inlet temperature as a function of wall temperature.
I wrote the code and compiled in fluent without any problem but i didnt get the answers that i expected. For instance my fluid temperature in outlet in axis is 112.0 K(!!!) whereas my average inlet temperature is 295 K.
heat flux=4000(w/m2),D=4.5mm.
my profile fluid temperature is:
T=walltemp-(function of heatflux and radius)
here is my code:
# include "udf.h"
# include "math.h"
DEFINE_PROFILE(x_temperature,thread,index)
{
Domain *domain=Get_Domain(1);
real x[ND_ND]; /* this will hold the position vector */
real y;
face_t f;
Thread *t0;
int Zone_ID=4;
t0=Lookup_Thread(domain,Zone_ID);
begin_f_loop(f,thread) /* loops over all faces in the thread passed in the DEFINE macro argument */
{
F_CENTROID(x,f,thread);
y = x[1];
F_PROFILE(f,thread,index) =F_T(f,t0)-(14.58588249*(0.75-((y/0.00225)*(y/0.00225))+(0.25*(pow((y/0.00225),4)))));
}
end_f_loop(f,thread)
}
//////////////////////////////////
How can i compute average inlet tempreture from the equation?
I'm really stuck here and dont know what to do.
could any body help me?
thanks a lot.
What you're doing is tricky. You're looping over one boundary and use the index to address another boundary. Are you sure they have the same number of faces? Otherwise it can easily happen that F_T(f,t0) is out of bounds.
dmoroian is offline   Reply With Quote

Old   April 26, 2010, 09:30
Default
  #4
Senior Member
 
dmoroian's Avatar
 
Dragos
Join Date: Mar 2009
Posts: 648
Rep Power: 20
dmoroian is on a distinguished road
Print the values of y and you will see what temperatures you should produce:
Code:
DEFINE_PROFILE(x_temperature,thread,index)
{
   real x[ND_ND]; /* this will hold the position vector */
   real y;
   face_t f;
   begin_f_loop(f,thread) /* loops over all faces in the thread passed in the DEFINE macro argument */
   {
      F_CENTROID(x,f,thread);
      y = x[1];
      Message0("y= %e\n",y);
      F_PROFILE(f,thread,index) =383+(4.603027808*0.000001*(1-(pow((y/0.00225),4))));
   }
   end_f_loop(f,thread)
}
dmoroian is offline   Reply With Quote

Old   April 26, 2010, 17:10
Default
  #5
Member
 
mohammad
Join Date: Apr 2010
Posts: 42
Rep Power: 15
mohammadkm is on a distinguished road
Dear dmoroian
thanks for your help, i am new with UDF.
when i used F_T(f,thread) i can compiled without error but in iteration
i got this error:
temperature limited to 1.000000e+000 in 1682 cells on zone 2 in domain 1
temperature limited to 1.000000e+000 in 3009 cells on zone 2 in domain 1
temperature limited to 1.000000e+000 in 4201 cells on zone 2 in domain 1
And it is repeated for other cell.
my boundary condition is laminar flow in tube with(4.5mm Diameter) heat flux constant equal 4000(w/m2)
here is my code which i used this time:
DEFINE_PROFILE(x_velocity,thread,index)
{
real x[ND_ND]; /* this will hold the position vector */
real y;
face_t f;
begin_f_loop(f,thread) /* loops over all faces in the thread passed in the DEFINE macro argument */
{
F_CENTROID(x,f,thread);
y = x[1];
F_PROFILE(f,thread,index) =2* 0.05391789*(1-((y/0.00225)*(y/0.00225))) ;
}
end_f_loop(f,thread)
}
DEFINE_PROFILE(x_temperature,thread,index)
{
real x[ND_ND]; /* this will hold the position vector */
real y;
face_t f;
begin_f_loop(f,thread) /* loops over all faces in the thread passed in the DEFINE macro argument */
{
F_CENTROID(x,f,thread);
y = x[1];
F_PROFILE(f,thread,index) =F_T(f,thread)-(14.58588249*(0.75-((y/0.00225)*(y/0.00225))+(0.25*(pow((y/0.00225),4)))));
}
end_f_loop(f,thread)
}
would please tell me what is my problem?
thanks.
mohammadkm is offline   Reply With Quote

Old   April 27, 2010, 03:37
Default
  #6
Senior Member
 
dmoroian's Avatar
 
Dragos
Join Date: Mar 2009
Posts: 648
Rep Power: 20
dmoroian is on a distinguished road
As I said in the above post http://www.cfd-online.com/Forums/flu...tml#post256327, print the values using a "Message" statement.
This time, you update the face using an older value plus something related to the position of the face centroid.
F_PROFILE(f,thread,index) points to the same variable as F_T(f,thread). Is this what you want?
Most likely, the initial value of the temperature on the surface pointed by F_T(f,thread) is not defined (probably 0), and substracting from that another number will give you a negative number, which should represent a temperature, hence the error.
dmoroian is offline   Reply With Quote

Old   May 2, 2010, 17:58
Default
  #7
Member
 
mohammad
Join Date: Apr 2010
Posts: 42
Rep Power: 15
mohammadkm is on a distinguished road
Thanks for your help dmoroian
As you said i added Message0("y= %e\n",y); to my code and in console message, i got this:
y= 1.910808e-003
y= 1.928399e-003
y= 1.945314e-003
y= 1.961578e-003
....
I don't know whats the problem with my code.
wall temperature is constant and equal 383K.
mohammadkm is offline   Reply With Quote

Old   May 2, 2010, 18:23
Default
  #8
Member
 
mohammad
Join Date: Apr 2010
Posts: 42
Rep Power: 15
mohammadkm is on a distinguished road
This time i tried to define profile temperature in tube with constant heat flux.
As you know wall temperature varies linearly with distance and the function is:
T(wall)=T0+A*Z (*)
T0:is inlet temperature
A:is constant value which is known
Z:is distance
So my profile temperature is:
T=T(walltemp)-(function of radius) (**)
The problem is how can i compute inlet temperature? we cant assume a value(for example 295K) because if we assume that inlet temperature is 295K in equation (*), from equation (**) inlet temperature will be 288.83 which is not 295 K!!!
I read an article which define profile temperature as a function of wall temperature. How ever i don't know how they compute inlet temperature?
I used this code, and fluent compute inlet temperature 288.83K
DEFINE_PROFILE(x_temperature,thread,index)
{
Domain *domain=Get_Domain(1);
real x[ND_ND]; /* this will hold the position vector */
real y,a,b;
face_t f;
begin_f_loop(f,thread) /* loops over all faces in the thread passed in the DEFINE macro argument */
{
F_CENTROID(x,f,thread);
y = x[1];
b=x[0];
a=295+(15.8038854*b);
F_PROFILE(f,thread,index) =a-(14.85148515*(0.75-((y/0.00225)*(y/0.00225))+(0.25*(pow((y/0.00225),4)))));
}
end_f_loop(f,thread)
}
I confused and asked my teacher but he couldn't answer. please help me with this problem. Thanks again
mohammadkm is offline   Reply With Quote

Old   May 3, 2010, 05:52
Default
  #9
Senior Member
 
dmoroian's Avatar
 
Dragos
Join Date: Mar 2009
Posts: 648
Rep Power: 20
dmoroian is on a distinguished road
Where do you hook your x_temperature?
After I red your posts, I got the impression that you are trying to setup the temperature in the entire domain. I don't think you can do that with a DEFINE_PROFILE macro!

Dragos
dmoroian is offline   Reply With Quote

Old   May 3, 2010, 17:19
Default
  #10
Member
 
mohammad
Join Date: Apr 2010
Posts: 42
Rep Power: 15
mohammadkm is on a distinguished road
Dear dmoroian
I hook my x_temperature in Boundary condition>inlet(velocity inlet)>Thermal
change constant value to libudf:x_temperature.
If i cant do it with define_profile macro, so how can i do it?
I just want to define develop flow in tube and not to have transient.
thanks
mohammadkm is offline   Reply With Quote

Old   May 4, 2010, 02:57
Default
  #11
Senior Member
 
dmoroian's Avatar
 
Dragos
Join Date: Mar 2009
Posts: 648
Rep Power: 20
dmoroian is on a distinguished road
If you hook your function as a boundary condition, then it's ok.

Quote:
Originally Posted by mohammadkm View Post
This time i tried to define profile y = x[1];
...
b=x[0];
a=295+(15.8038854*b);
F_PROFILE(f,thread,index) =a-(14.85148515*(0.75-((y/0.00225)*(y/0.00225))+(0.25*(pow((y/0.00225),4)))));
...
I assume that Ox is the axial coordinate, and Oy is the radial coordinate of your domain.
You define your temperature as T_inlet = 295+15.8*x-(14.9*(0.75-(y/0.00225)^2+(0.25*(y/0.0025)^4)
Taking an example: x=0, y=1.91e-3 => T_inlet=293
...so what is the problem?
dmoroian is offline   Reply With Quote

Old   May 7, 2010, 05:13
Default
  #12
Member
 
mohammad
Join Date: Apr 2010
Posts: 42
Rep Power: 15
mohammadkm is on a distinguished road
Dear dmoroian
Thank you so much my problem solved. However i encountered another problem.
I wrote the udf to compute:
[(dT/dx)^2]+[(dT/dy)^2]
T:is temperature
I can compile and get answer without any error, but i think my code is wrong(or incomplete) to compute gradient temperature!!.(I am relatively new to UDF).
This is my code:
# include "udf.h"
# include "math.h"
DEFINE_ADJUST(adjust_gradient, domain)
{
Thread *t;
cell_t c;
face_t f;
domain = Get_Domain(1);
/* Fill UDS with the variable. */
thread_loop_c (t,domain)
{
begin_c_loop (c,t)
{
C_UDSI(c,t,0) = C_T(c,t);
}
end_c_loop (c,t)
}
thread_loop_f (t,domain)
{
if (THREAD_STORAGE(t,SV_UDS_I(0))!=NULL)
begin_f_loop (f,t)
{
F_UDSI(f,t,0) = F_T(f,t);
}
end_f_loop (f,t)
}
}
DEFINE_ON_DEMAND(store_gradient)
{
Domain *domain;
cell_t c;
Thread *t;
domain=Get_Domain(1);
/* Fill the UDM with magnitude of gradient. */
thread_loop_c (t,domain)
{
begin_c_loop (c,t)
{
C_UDMI(c,t,0) =(pow(NV_MAG(C_UDSI_G(c,t,0)),2));
}
end_c_loop (c,t)
}
}
////////////////////////////////////////////////////////////
1)Do i have to compute gradient temperature in face too?if yes how can i do that?
2)Do i have to use C_T_RG(c,t)?whats the diffrence between C_T_G and C_T_RG?
I hope you can solve my problem, thanks again
mohammadkm is offline   Reply With Quote

Old   May 7, 2010, 06:31
Default
  #13
Senior Member
 
dmoroian's Avatar
 
Dragos
Join Date: Mar 2009
Posts: 648
Rep Power: 20
dmoroian is on a distinguished road
If you found the solution, you are supposed to share it with the rest of the forum, then for a new problem, open a new thread.
However, your code should work if you have run at least one iteration, have convective scalars and tell fluent to store the gradients (all three of them are described in the manuals).
dmoroian is offline   Reply With Quote

Old   May 7, 2010, 07:03
Default
  #14
Member
 
mohammad
Join Date: Apr 2010
Posts: 42
Rep Power: 15
mohammadkm is on a distinguished road
my problem was :
when we write: a=295+(15.8038854*b); we assume that inlet temperature is 295K.
and when we hook this to fluent, fluent compute inlet temperature 283K!!!( it must be 295K not 283K),So the formula of perofile temperature or surface temperature is wrong or incomplete.(Im not sure)
F_PROFILE(f,thread,index) =a-(14.85148515*(0.75-((y/0.00225)*(y/0.00225))+(0.25*(pow((y/0.00225),4)))));
I found another profile temperature in "Heat Convection(Latif M. Jiji)" and i hooked this code to fluent:
DEFINE_PROFILE(x_temperature,thread,index)
{
Domain *domain=Get_Domain(1);
real x[ND_ND]; /* this will hold the position vector */
real y,b;
face_t f;
begin_f_loop(f,thread) /* loops over all faces in the thread passed in the DEFINE macro argument */
{
F_CENTROID(x,f,thread);
y = x[1];
b=x[0];
F_PROFILE(f,thread,index) =295+(11734506.78*(pow((y/2),2)-(pow(y,4)/(8.1*0.00001))))-4.331683168+(15.8038854*b);
}
end_f_loop(f,thread)
}
As we can see i assume inlet temperature 295 K and fluent compute inlet temperature 295.27K, so the profile temperature is right and problem solved.
Thanks dmoroian for your help. I hope it can be helpful for other users.
mohammadkm is offline   Reply With Quote

Old   March 13, 2012, 03:35
Default
  #15
Member
 
Shashank
Join Date: Apr 2011
Posts: 74
Rep Power: 14
shashank312 is on a distinguished road
Mohammad,

Could you tell me exactly how you solved the last bit? How did FLUENT respond to the changes you made in your code? You mean instead of a proposed constant (say "a" in your case), we need to put that value (295 in your case) into the profile?

Thanks,

Shashank
shashank312 is offline   Reply With Quote

Old   March 13, 2012, 03:59
Default
  #16
Member
 
Shashank
Join Date: Apr 2011
Posts: 74
Rep Power: 14
shashank312 is on a distinguished road
Or did you use a different profile in the fluid altogether?! If yes, then how should that affect the temperature of the wall? It should be 295 in both cases. Obviously, Fluent does something different in the second case, which is what I am asking from you.
shashank312 is offline   Reply With Quote

Old   March 14, 2012, 12:28
Default
  #17
Member
 
mohammad
Join Date: Apr 2010
Posts: 42
Rep Power: 15
mohammadkm is on a distinguished road
Dear shashank
The first temp profile is a function of heat flux, and I couldn't write the UDF. So, I used another profile temp which is not function of heat flux , and I got it from "Heat Convection(Latif M. Jiji)". The second formula was easy to write the udf.
mohammadkm is offline   Reply With Quote

Old   December 23, 2013, 01:57
Default
  #18
Member
 
xingangzheng
Join Date: Jul 2009
Posts: 37
Rep Power: 16
ustbdynamic is on a distinguished road
Quote:
Originally Posted by mohammadkm View Post
Dear dmoroian
Thank you so much my problem solved. However i encountered another problem.
I wrote the udf to compute:
[(dT/dx)^2]+[(dT/dy)^2]
T:is temperature
I can compile and get answer without any error, but i think my code is wrong(or incomplete) to compute gradient temperature!!.(I am relatively new to UDF).
This is my code:
# include "udf.h"
# include "math.h"
DEFINE_ADJUST(adjust_gradient, domain)
{
Thread *t;
cell_t c;
face_t f;
domain = Get_Domain(1);
/* Fill UDS with the variable. */
thread_loop_c (t,domain)
{
begin_c_loop (c,t)
{
C_UDSI(c,t,0) = C_T(c,t);
}
end_c_loop (c,t)
}
thread_loop_f (t,domain)
{
if (THREAD_STORAGE(t,SV_UDS_I(0))!=NULL)
begin_f_loop (f,t)
{
F_UDSI(f,t,0) = F_T(f,t);
}
end_f_loop (f,t)
}
}
DEFINE_ON_DEMAND(store_gradient)
{
Domain *domain;
cell_t c;
Thread *t;
domain=Get_Domain(1);
/* Fill the UDM with magnitude of gradient. */
thread_loop_c (t,domain)
{
begin_c_loop (c,t)
{
C_UDMI(c,t,0) =(pow(NV_MAG(C_UDSI_G(c,t,0)),2));
}
end_c_loop (c,t)
}
}
////////////////////////////////////////////////////////////
1)Do i have to compute gradient temperature in face too?if yes how can i do that?
2)Do i have to use C_T_RG(c,t)?whats the diffrence between C_T_G and C_T_RG?
I hope you can solve my problem, thanks again
Dear mohammad
Do you know the differences betewen the c_T_G and C_T_RG and how to use the C_T_RG ?
Thank you!
ustbdynamic is offline   Reply With Quote

Old   December 23, 2013, 04:32
Default
  #19
Member
 
mohammad
Join Date: Apr 2010
Posts: 42
Rep Power: 15
mohammadkm is on a distinguished road
Dear USTBdynamic,
I do not have experience in working with C_T_RG. But, I got this from Fluent guidance.
" Therefore, if your UDF needs to compute face values from cell
gradients, you should use the reconstruction gradient (RG) values instead of non-limited gradient (G) values."

I always compute cell values rather than face values and I have gotten good results.
Best regards,
Mohammad
mohammadkm is offline   Reply With Quote

Old   December 24, 2013, 23:42
Default
  #20
Member
 
xingangzheng
Join Date: Jul 2009
Posts: 37
Rep Power: 16
ustbdynamic is on a distinguished road
thank you very much!



Quote:
Originally Posted by mohammadkm View Post
Dear USTBdynamic,
I do not have experience in working with C_T_RG. But, I got this from Fluent guidance.
" Therefore, if your UDF needs to compute face values from cell

gradients, you should use the reconstruction gradient (RG) values instead of non-limited gradient (G) values."

I always compute cell values rather than face values and I have gotten good results.
Best regards,
Mohammad
ustbdynamic is offline   Reply With Quote

Reply

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----Surface Reaction UDF Ashi Fluent UDF and Scheme Programming 1 May 19, 2020 22:13
Missing math.h header Travis FLUENT 4 January 15, 2009 12:48
Help: using udf to define direction Bo FLUENT 1 July 16, 2008 07:47
UDF :Unsteady concentration profile umesh FLUENT 4 July 13, 2003 18:07
UDF update profile ramesh FLUENT 0 June 29, 2003 15:14


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