CFD Online Discussion Forums

CFD Online Discussion Forums (
-   FLUENT (
-   -   UDF for energy source (

JoĆ£o Fernandes October 16, 2008 18:35

UDF for energy source
Hi there, folks!

I am trying to model the flow and heat transfer to a supercritical fluid (compressed gas above its critical pressure and critical temperature) near the pseudo critical point, the fluid is CO2. Near the pseudo critical point, the specific heat increases extraordinarily what makes it difficult to model by using polynomial functions of temperature (the first thing I tried!), so I developed a UDF to calculate the value of the specific heat as a function of both pressure and temperature, the problem is that I cannot hook this UDF to the Materials form. As a way to overcome this constrain I thought of defining an extra term in the energy equation defining it as an energy source through all the domain occupied by the gas, here it is:

DEFINE_SOURCE(cell_energy,c,t,dS,eqn) {

real source ;

real cp ;

real vol = C_VOLUME(c,t) ;

real cubic_root_vol = pow(vol,0.3333333) ;

real twall = 323 ;



/* source term */

source = C_R(c,t) * C_U(c,t) * (cp - 840.37) * C_T(c,t) / cubic_root_vol ;

/* derivative of source term */

dS[eqn] = C_R(c,t) * (cp - 840.37) * C_U(c,t) / cubic_root_vol ;

return source ;




But I am not sure if everything's ok with the definition of the energy source (my geometry is simply a straight tube and its axis is on the z-direction). The energy source should account for both radial and axial temperature gradients of temperature. Can you tell me how to do this if the previous UDF is not correct?

Many thanks in advance,

Best regards


CDE October 16, 2008 19:11

Re: UDF for energy source
I'm not sure if the method you are trying to use will work or not. Can you use the piecewise-linear function for Cp?

As for the UDF, take out the begin_c_loop(c,t), you don't need it for a DEFINE_SOURCE UDF. The UDF is automatically called for each cell so you only need to return the value for a single cell.

JoĆ£o Fernandes October 16, 2008 19:37

Re: UDF for energy source

I tried first the polynomials and piecewise linear, but for instance at the pressure of 80bar, the cp can variate from 3000 J/kg.K to 60000 J/kg.K if the temperature changes by 4 or 5 degrees. To describe such variations I have to use polynomials of high degree. Other problem is the coefficients of the polynomials, since for the larger coefficients even the round up Fluent does can change extraordinarily the magnitude of the value of the Cp calculated. Maybe you can have some comments on this.

Thank you very much, in deed, for answering so quickly,

Best regards,


CDE October 16, 2008 21:32

Re: UDF for energy source
If you define enough points in the piecewise linear function in the temperature regions you are most interested in, then the temperature dependance of Cp should be accurate. Try defining 40 points over the 4-5 degrees region.

The only other option I can see is to disable the heat transfer calculation in Fluent and define it completely using UDF source terms and Cp.

JoĆ£o Fernandes October 17, 2008 04:53

Re: UDF for energy source
Hi again CDE,

I would like to thank you very much your suggestions, I will follow your advice namely the piecewise linear function. I have the UDF for the calculation of Cp, can you give me some hints about how to solve the problem disabling the heat transfer and just using UDFs and energy sources? I am a new user of Fluent and this method seems to be very complicated, anyway I would appreciate a lot your considerations about how to apply it.

Once again, many thanks in advance,

Best regards


All times are GMT -4. The time now is 21:53.