
[Sponsors] 
April 20, 2010, 04:10 
Define profile inlet_temperature in UDF

#1 
Member
mohammad
Join Date: Apr 2010
Posts: 42
Rep Power: 8 
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. 

April 23, 2010, 16:25 

#2 
Member
mohammad
Join Date: Apr 2010
Posts: 42
Rep Power: 8 
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. 

April 26, 2010, 08:27 

#3  
Senior Member
Dragos
Join Date: Mar 2009
Posts: 648
Rep Power: 12 
Quote:


April 26, 2010, 08:30 

#4 
Senior Member
Dragos
Join Date: Mar 2009
Posts: 648
Rep Power: 12 
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) } 

April 26, 2010, 16:10 

#5 
Member
mohammad
Join Date: Apr 2010
Posts: 42
Rep Power: 8 
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. 

April 27, 2010, 02:37 

#6 
Senior Member
Dragos
Join Date: Mar 2009
Posts: 648
Rep Power: 12 
As I said in the above post Define profile inlet_temperature in UDF, 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. 

May 2, 2010, 16:58 

#7 
Member
mohammad
Join Date: Apr 2010
Posts: 42
Rep Power: 8 
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.910808e003 y= 1.928399e003 y= 1.945314e003 y= 1.961578e003 .... I don't know whats the problem with my code. wall temperature is constant and equal 383K. 

May 2, 2010, 17:23 

#8 
Member
mohammad
Join Date: Apr 2010
Posts: 42
Rep Power: 8 
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 

May 3, 2010, 04:52 

#9 
Senior Member
Dragos
Join Date: Mar 2009
Posts: 648
Rep Power: 12 
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 

May 3, 2010, 16:19 

#10 
Member
mohammad
Join Date: Apr 2010
Posts: 42
Rep Power: 8 
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 

May 4, 2010, 01:57 

#11  
Senior Member
Dragos
Join Date: Mar 2009
Posts: 648
Rep Power: 12 
If you hook your function as a boundary condition, then it's ok.
Quote:
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.91e3 => T_inlet=293 ...so what is the problem? 

May 7, 2010, 04:13 

#12 
Member
mohammad
Join Date: Apr 2010
Posts: 42
Rep Power: 8 
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 

May 7, 2010, 05:31 

#13 
Senior Member
Dragos
Join Date: Mar 2009
Posts: 648
Rep Power: 12 
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). 

May 7, 2010, 06:03 

#14 
Member
mohammad
Join Date: Apr 2010
Posts: 42
Rep Power: 8 
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. 

March 13, 2012, 03:35 

#15 
Member
Shashank
Join Date: Apr 2011
Posts: 70
Rep Power: 7 
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 

March 13, 2012, 03:59 

#16 
Member
Shashank
Join Date: Apr 2011
Posts: 70
Rep Power: 7 
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.


March 14, 2012, 12:28 

#17 
Member
mohammad
Join Date: Apr 2010
Posts: 42
Rep Power: 8 
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. 

December 23, 2013, 01:57 

#18  
New Member
xingangzheng
Join Date: Jul 2009
Posts: 11
Rep Power: 8 
Quote:
Do you know the differences betewen the c_T_G and C_T_RG and how to use the C_T_RG ? Thank you! 

December 23, 2013, 04:32 

#19 
Member
mohammad
Join Date: Apr 2010
Posts: 42
Rep Power: 8 
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 nonlimited gradient (G) values."
I always compute cell values rather than face values and I have gotten good results. Best regards, Mohammad 

December 24, 2013, 23:42 

#20  
New Member
xingangzheng
Join Date: Jul 2009
Posts: 11
Rep Power: 8 
thank you very much!
Quote:


Thread Tools  
Display Modes  


Similar Threads  
Thread  Thread Starter  Forum  Replies  Last Post 
HELPSurface Reaction UDF  Ashi  Fluent UDF and Scheme Programming  0  May 25, 2009 09:39 
Missing math.h header  Travis  FLUENT  4  January 15, 2009 12:48 
Help: using udf to define direction  Bo  FLUENT  1  July 16, 2008 06:47 
UDF :Unsteady concentration profile  umesh  FLUENT  4  July 13, 2003 17:07 
UDF update profile  ramesh  FLUENT  0  June 29, 2003 14:14 