CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   Fluent UDF and Scheme Programming (https://www.cfd-online.com/Forums/fluent-udf/)
-   -   Define profile inlet_temperature in UDF (https://www.cfd-online.com/Forums/fluent-udf/75232-define-profile-inlet_temperature-udf.html)

Define profile inlet_temperature in UDF

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:
here is my code:
# include "udf.h"
# include "math.h"
{
Domain *domain=Get_Domain(1);
real x[ND_ND]; /* this will hold the position vector */
real y;
face_t f;
int Zone_ID=4;
begin_f_loop(f,thread) /* loops over all faces in the thread passed in the DEFINE macro argument */
{
y = x[1];
}
}
//////////////////////////////////
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.

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.
{
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 */
{
y = x[1];
}
}
please help in me in this problem i really need to solve this problem and i don know what to do.

 dmoroian April 26, 2010 08:27

Quote:
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 April 26, 2010 08:30

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) }```

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:
{
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 */
{
y = x[1];
}
}
{
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 */
{
y = x[1];
}
}
would please tell me what is my problem?
thanks.

 dmoroian April 27, 2010 02:37

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.

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.

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:
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
{
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 */
{
y = x[1];
b=x[0];
a=295+(15.8038854*b);
}
}

 dmoroian May 3, 2010 04:52

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

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

 dmoroian May 4, 2010 01:57

If you hook your function as a boundary condition, then it's ok.

Quote:
 Originally Posted by mohammadkm (Post 257227) 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?

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"
{
cell_t c;
face_t f;
domain = Get_Domain(1);
/* Fill UDS with the variable. */
{
begin_c_loop (c,t)
{
C_UDSI(c,t,0) = C_T(c,t);
}
end_c_loop (c,t)
}
{
begin_f_loop (f,t)
{
F_UDSI(f,t,0) = F_T(f,t);
}
end_f_loop (f,t)
}
}
{
Domain *domain;
cell_t c;
domain=Get_Domain(1);
/* Fill the UDM with magnitude of gradient. */
{
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

 dmoroian May 7, 2010 05:31

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).

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)
I found another profile temperature in "Heat Convection(Latif M. Jiji)" and i hooked this code to fluent:
{
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 */
{
y = x[1];
b=x[0];
}
}
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.

 shashank312 March 13, 2012 03:35

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 March 13, 2012 03:59

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.

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.

 ustbdynamic December 23, 2013 01:57

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!

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

I always compute cell values rather than face values and I have gotten good results.
Best regards,