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

Solution tends to wrong (or not wanted) value

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   April 9, 2020, 19:31
Default Solution tends to wrong (or not wanted) value
  #1
Member
 
Cpt. Convergence
Join Date: Feb 2020
Posts: 98
Rep Power: 8
Captain Convergence is on a distinguished road
Hi all,

I am having problems with my UDRGM. It is a real gas model that below 500 K applies an ideal-gas formulation. However, even though the density and Cp are being calculated properly, the final temperature tends to a very different solution from the ideal gas and therefore my final density (and all other variables) is not the right one.

In order to show you what is going on I have attached a .zip file with the mesh (a 2D simple channel), a journal file (that executes everything for you) and the 2 UDRGMs (one with ideal-gas formulation and the other with real-gas formulation). You can compile and execute the simulations in your computer and check yourselves (it takes less than 1 min to run).

As you will observe, if we use the ideal UDRGM after reaching the ideal-gas formulation, the new solution spreads and it is equal to the previous solution (see image "IDEAL-UDRGM-propagation").

Nonetheless, if we load the real UDRGM after reaching the ideal-gas solution, the solution spreads with a very different values of temperature and the final temperature field is completely different from the ideal-gas solution (see REAL-UDRGM-propagation), and they should be identical since the formulations are the same.

If the CP is the same in the simulations (Cp=1004.16 J/(Kg K) and constant below 500 K), the density, enthalpy and other quantities formulations are the same in both UDRGMs and the boundary conditions are the same, what can cause the dramatic change of temperature?
Attached Images
File Type: jpg IDEAL-UDRGM-propagation.jpg (46.6 KB, 10 views)
File Type: jpg REAL-UDRGM-propagation.jpg (43.7 KB, 8 views)
Attached Files
File Type: zip SimpleCase.zip (27.1 KB, 3 views)
Captain Convergence is offline   Reply With Quote

Old   April 12, 2020, 16:24
Default UDRGM retrieving the wrong temperature
  #2
Member
 
Cpt. Convergence
Join Date: Feb 2020
Posts: 98
Rep Power: 8
Captain Convergence is on a distinguished road
I acknowledged by placing a message warning that the total temperature from the inlet is passed in the functions for calculating the entropy and the enthalpy instead of the temperature and this is spreaded to the entire domain. I mean here:

double ANYNAME_enthalpy(cell_t cell, Thread *thread, double T, double Rho, double P, double yi[])

double ANYNAME_entropy(cell_t cell, Thread *thread, double T, double Rho, double P, double yi[])

Since the total temperature is higher than the static temperature, it makes my simulation to converge to a higher temperature value. Is it posible to retrieve the static temperature instead the total temperature at this functions? Or how could I avoid this error at the boundary?

Last edited by Captain Convergence; April 12, 2020 at 18:47.
Captain Convergence is offline   Reply With Quote

Old   April 13, 2020, 08:02
Default Temperature
  #3
Senior Member
 
vinerm's Avatar
 
Vinerm
Join Date: Jun 2009
Location: Nederland
Posts: 2,946
Blog Entries: 1
Rep Power: 35
vinerm will become famous soon enough
Fluent returns static temperature and not total temperature for these or any other macros. You can observe that for the ideal gas density calculation. The density depends only on static temperature and not on total temperature.
__________________
Regards,
Vinerm

PM to be used if and only if you do not want something to be shared publicly. PM is considered to be of the least priority.
vinerm is offline   Reply With Quote

Old   April 13, 2020, 09:05
Default
  #4
Member
 
Cpt. Convergence
Join Date: Feb 2020
Posts: 98
Rep Power: 8
Captain Convergence is on a distinguished road
I am running a 2D channel where the static temperature is 287 at Mach 5. In order to have that static temperature, I need a total temperature of 1722.98 Kelvin at the inlet and outlet. My UDFs for Enthalpy and Entropy look like this:

/*-------------------------------------------------------------------*/
/*-------------------------------------------------------------------*/
/* ENTHALPY UDF */
/*-------------------------------------------------------------------*/
/*-------------------------------------------------------------------*/

double REAL_enthalpy(cell_t cell, Thread *thread, double Temp, double density, double P, double yi[])
{
double cp = REAL_specific_heat(cell, thread, Temp, density, P, yi); /* Cp = 1004.16 J/(Kg K) IF Temp < 500 Kelvin*/
double h = Temp * cp;
if (Temp>500){
Message("Enthalpy Temp Warning, Temp: %f K\n", Temp);
}

return h; /* (J/Kg) */
}
/*-------------------------------------------------------------------*/
/*-------------------------------------------------------------------*/
/* ENTROPY UDF */
/*-------------------------------------------------------------------*/
/*-------------------------------------------------------------------*/

double REAL_entropy(cell_t cell, Thread *thread, double Temp, double density, double P, double yi[])
{
double RGAS = Runiv/MW0;
double s = REAL_specific_heat(cell, thread, Temp, density, P, yi) * log(fabs(Temp / TDatum)) + RGAS * log(fabs(PDatum / P));
if (Temp>500){
Message("Entropy Temp Warning, Temp: %f K\n", Temp);
}

return s; /* (J/Kg/K) */
}

I have attached one screeshot 1 iteration after the initialization with a temperature of 287K. As you can observe, the messages that I set inform me that the variable Temp passed from the solver is 1722.98 Kelvin which is the total temperature and it is used to calculate the CP in the enthalpy function. Since the Cp function in the enthalpy function is given the Total temperature instead of the static temperature, the outcome is a highter Cp and thus a higher enthalpy that raises my static temperature from 287 Kelvin to 465 Kelvin.
Attached Images
File Type: png Screenshot.PNG (44.4 KB, 5 views)
Captain Convergence is offline   Reply With Quote

Old   April 13, 2020, 09:21
Default
  #5
Member
 
Cpt. Convergence
Join Date: Feb 2020
Posts: 98
Rep Power: 8
Captain Convergence is on a distinguished road
if instead of calculating the CP in each loop I leave it as constant:

/*-------------------------------------------------------------------*/
/*-------------------------------------------------------------------*/
/* ENTHALPY UDF (INTERPOLATION) */
/*-------------------------------------------------------------------*/
/*-------------------------------------------------------------------*/

double REAL_enthalpy(cell_t cell, Thread *thread, double Temp, double density, double P, double yi[])
{
double cp = 1004.16; // J/(Kg K)
double h = Temp * cp;

if (Temp>500){
Message("Enthalpy Temp Warning, Temp: %f K\n", Temp); // CHECK POSITION!!
}


return h; /* (J/Kg) */
}
/*-------------------------------------------------------------------*/
/*-------------------------------------------------------------------*/
/* ENTROPY UDF */
/*-------------------------------------------------------------------*/
/*-------------------------------------------------------------------*/

double REAL_entropy(cell_t cell, Thread *thread, double Temp, double density, double P, double yi[])
{
double RGAS = Runiv/MW0;
double cp = 1004.16; // J/(Kg K)
double s = cp * log(fabs(Temp / TDatum)) + RGAS * log(fabs(PDatum / P));

if (Temp>500){
Message("Entropy Temp Warning, Temp: %f K\n", Temp);
}

return s; /* (J/Kg/K) */
}

I am still having the same temperature warnings but now the static temperature does not change because the Cp remains constant (See the attached image). But there is an enthalpy calculation error because it is being calculated (apparently) with the Total Temperature.
Attached Images
File Type: png Screenshot.PNG (40.4 KB, 3 views)
Captain Convergence is offline   Reply With Quote

Old   April 13, 2020, 09:43
Default Temperature
  #6
Senior Member
 
vinerm's Avatar
 
Vinerm
Join Date: Jun 2009
Location: Nederland
Posts: 2,946
Blog Entries: 1
Rep Power: 35
vinerm will become famous soon enough
Try reporting both, temperature as well as dynamic temperature. Certainly, there are some cells that will have static temperature equal to total temperature. It has got nothing to do with your boundary condition.
__________________
Regards,
Vinerm

PM to be used if and only if you do not want something to be shared publicly. PM is considered to be of the least priority.
vinerm is offline   Reply With Quote

Old   April 13, 2020, 09:54
Default
  #7
Member
 
Cpt. Convergence
Join Date: Feb 2020
Posts: 98
Rep Power: 8
Captain Convergence is on a distinguished road
And how can I retrieve the dynamic temperature in the UDRGM enthalpy function? Can it be obtained from the variables "cell_t cell" and "Thread *thread"? I tried to find information about their format but I only found information for regular UDFs.
Captain Convergence is offline   Reply With Quote

Old   April 13, 2020, 10:16
Default Dynamic Temperature
  #8
Senior Member
 
vinerm's Avatar
 
Vinerm
Join Date: Jun 2009
Location: Nederland
Posts: 2,946
Blog Entries: 1
Rep Power: 35
vinerm will become famous soon enough
There is no direct macro to fetch dynamic temperature. All you need is to fetch velocity for the cell. If velocity is 0, so would be dynamic temperature. Dynamic temperature is given as

\frac{u^2}{2C_p}
__________________
Regards,
Vinerm

PM to be used if and only if you do not want something to be shared publicly. PM is considered to be of the least priority.
vinerm is offline   Reply With Quote

Old   April 13, 2020, 11:13
Default
  #9
Member
 
Cpt. Convergence
Join Date: Feb 2020
Posts: 98
Rep Power: 8
Captain Convergence is on a distinguished road
I added the highlighted to my UDF

/*-------------------------------------------------------------------*/
double REAL_enthalpy(cell_t cell, Thread *thread, double Temp, double density, double Pabs, double yi[])
{
double Temp2 = C_T(cell,thread);
double Pabs2 = C_P(cell,thread);


double cp = REAL_specific_heat(cell, thread, Temp2, density, Pabs2, yi); /* Cp = 1004.16 J/(Kg K) IF Temp < 500 Kelvin*/
double h = Temp2 * cp;

if (Temp>500){
Message("Enthalpy Temp Warning, Temp: %f K P: %f Pa\n", Temp, Pabs);
Message("Enthalpy Other Monitors, Temp2: %f K P2: %f Pa\n", Temp2, Pabs2);
}

return h; /* (J/Kg) */
}
/*-------------------------------------------------------------------*/

As I was suspecting, fluent is retrieving by default the total pressure and total temperature at least in the entropy and enthalpy functions (see the attached image). Now I have to check again all my functions to make sure that the right temperatures and pressures are being used.
Attached Images
File Type: png Screenshot.PNG (43.4 KB, 5 views)
Captain Convergence is offline   Reply With Quote

Old   April 13, 2020, 12:26
Default
  #10
Member
 
Cpt. Convergence
Join Date: Feb 2020
Posts: 98
Rep Power: 8
Captain Convergence is on a distinguished road
I have obtained the static Pressure and static Temperature in every UDRGM function by using these commands at the beginning of each function:

Temp = C_T(cell,thread);
Pabs = C_P(cell,thread);

Unfortunately now I have the opposite issue and the temperature tends to 0 Kelvin. I have attached the contours of dynamic temperature and static temperature. It doesn't go to 0 because I have limited the minimum temperature to 200 Kelvin. For some reason that I cannot understand there are many extrange interactions at the inlet.

Honestly I don't know why I am having so many issues with this simple case and what else I should try...
Attached Images
File Type: jpg dyn-temp.jpg (47.7 KB, 5 views)
File Type: jpg temp.jpg (41.8 KB, 2 views)
Captain Convergence is offline   Reply With Quote

Old   April 14, 2020, 03:31
Default T and P
  #11
Senior Member
 
vinerm's Avatar
 
Vinerm
Join Date: Jun 2009
Location: Nederland
Posts: 2,946
Blog Entries: 1
Rep Power: 35
vinerm will become famous soon enough
I did not observe any difference in temperature and pressure returned by Fluent and C_T and C_P. Fluent does return absolute static pressure and absolute static temperature and NOT total values. Do note that there will be difference during the initialization. You have to run the case for at least 1 iteration.
__________________
Regards,
Vinerm

PM to be used if and only if you do not want something to be shared publicly. PM is considered to be of the least priority.
vinerm is offline   Reply With Quote

Old   April 14, 2020, 05:01
Default
  #12
Member
 
Cpt. Convergence
Join Date: Feb 2020
Posts: 98
Rep Power: 8
Captain Convergence is on a distinguished road
Then the only thing left is that my Enthalpy dependence on the Cp makes the density-based solver converge to very extrange values at the inlet. Which shouldn't occur because the Cp is constant below 500 K but maybe within the solver the calculations tend to higher or lower values of temperature and that's why I have the error at the inlet.
Captain Convergence is offline   Reply With Quote

Old   April 14, 2020, 06:03
Default Boundary
  #13
Senior Member
 
vinerm's Avatar
 
Vinerm
Join Date: Jun 2009
Location: Nederland
Posts: 2,946
Blog Entries: 1
Rep Power: 35
vinerm will become famous soon enough
Inlet is a boundary where user specifies the values. Fluent does not do any calculation at Inlet. The only calculation is for static temperature that is determined from simple relation between stagnation temperature, static temperature, material properties, and Mach.
__________________
Regards,
Vinerm

PM to be used if and only if you do not want something to be shared publicly. PM is considered to be of the least priority.
vinerm is offline   Reply With Quote

Old   April 14, 2020, 06:13
Default
  #14
Member
 
Cpt. Convergence
Join Date: Feb 2020
Posts: 98
Rep Power: 8
Captain Convergence is on a distinguished road
Is there any possibility to keep that static temperature as constant with a user-defined value?
Captain Convergence is offline   Reply With Quote

Old   April 14, 2020, 06:15
Default Fixed Values
  #15
Senior Member
 
vinerm's Avatar
 
Vinerm
Join Date: Jun 2009
Location: Nederland
Posts: 2,946
Blog Entries: 1
Rep Power: 35
vinerm will become famous soon enough
If you want to keep static temperature fixed throughout the cell zone, then go to cell zone conditions, enabled Fixed Values, and then fix temperature to any value you want. Fixing static temperature at the inlet is not possible for ideal or real gas because it is not independent of the flow.
__________________
Regards,
Vinerm

PM to be used if and only if you do not want something to be shared publicly. PM is considered to be of the least priority.
vinerm is offline   Reply With Quote

Reply


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
Stable but wrong solution in VOF method Ulixes FLUENT 0 May 1, 2017 14:08
Ansys CFD POST constructs a solution history from wrong file. Wingman ANSYS 2 November 28, 2016 17:01
grid dependancy gueynard a. Main CFD Forum 19 June 27, 2014 21:22
Naca 0012 (compressible and inviscid) flow convergence problem bipulsaha FLUENT 1 July 6, 2011 07:51
Wall functions Abhijit Tilak Main CFD Forum 6 February 5, 1999 01:16


All times are GMT -4. The time now is 01:29.