CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (https://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   Enthalpy to temperature (https://www.cfd-online.com/Forums/openfoam-programming-development/81597-enthalpy-temperature.html)

Enthalpy to temperature

Hi all,
I am new to OpenFOAM. I was looking at where OpenFOAM does the h to T (or hs top T) conversion, and I noted that they use a Newton iteration mthod. But when I try to trace the sepcific heat they use in this equation, they seem to use Cp=Cp(T) and not Cp=Cp(T,Yi). This is the file I am talking about:-
$FOAM/src/thermophysicalModels/specie/thermo/janaf Can anyone confirm/explain this? Thanks in advance.  Farshad_Noravesh July 17, 2011 04:39 h to T conversion Hi, I have exactly the same question. Thanks Farshad  adhiraj July 17, 2011 10:37 Enthalpy to T I have dug deep since this post, and have the answers. When they go for the h->T conversion they hold the composition fixed, and define a new 'gas' with the composition averaged thermal properties. It is the Cp of this mixture gas that is (rightly) used to compute T.  isabel February 13, 2012 11:51 Hi all, I am looking for the extract of the code where the conversion from h to T is done but I do not find it. Can anybody tell me where it is?  adhiraj February 13, 2012 18:35 Check under Quote: $FOAM_SRC/thermophysicalModels/specie/thermo/specieThermo

 isabel February 14, 2012 04:44

Thank you very much. I found the iteration in these lines:

// return the temperature corresponding to the value of the
// thermodynamic property f, given the function f = F(T) and dF(T)/dT
template<class thermo>
inline scalar specieThermo<thermo>::T
(
scalar f,
scalar T0,
scalar (specieThermo<thermo>::*F)(const scalar) const,
scalar (specieThermo<thermo>::*dFdT)(const scalar) const
) const
{
scalar Test = T0;
scalar Tnew = T0;
scalar Ttol = T0*tol_;
int iter = 0;

do
{
Test = Tnew;
Tnew = Test - ((this->*F)(Test) - f)/(this->*dFdT)(Test);

if (iter++ > maxIter_)
{
FatalErrorIn
(
"specieThermo<thermo>::T(scalar f, scalar T0, "
"scalar (specieThermo<thermo>::*F)(const scalar) const, "
"scalar (specieThermo<thermo>::*dFdT)(const scalar) const"
") const"
) << "Maximum number of iterations exceeded"
<< abort(FatalError);
}

} while (mag(Tnew - Test) > Ttol);

return Tnew;
}

There is something I do not understhand. What does “this->” means?

 megacrout February 14, 2012 10:25

I might be wrong but I don´t think this is an OF-specific function.
Ecosia (instead of googling it) "this pointer" or "this pointer c++" or such.
Tibo

It is a C++ keyword. "this" acts like a pointer to the object whose member function is under consideration.

 isabel February 15, 2012 10:15

Dear friends,

I have another doubt about these files. Where are defined the functions F and dFdT?

They are the function and its derivative.
The Newton iteration in this case calculates T, given F(T) and dF/dT(T).
The function gets pointers to the functions F and dF/dt.

If the energy variable is enthalpy h, then F=h(T) and dF/dt=Cp(T).
If it is internal energy e, then F=e and dF/dT=Cv(T).

The code resolves these at runtime, and sends the appropriate pointers to the Newton iteration routine.

 isabel February 16, 2012 05:32

Dear friends,

Thank you very much for your help. I need to simulate melting of a solid. In that case, the enthalpy is given by the following equation:

http://fotos.miarroba.es/lamasgaldo/4-energy-equation3/ http://fotos.miarroba.es/lamasgaldo/4-energy-equation3/ http://fotos.miarroba.es/lamasgaldo/...3/#anchorPhotohttp://www.cfd-online.com/Forums/[im...3/#anchorPhotohttp://fotos.miarroba.es/lamasgaldo/...3/#anchorPhoto http://fotos.miarroba.es/lamasgaldo/...-equation3.jpg http://fotos.miarroba.es/lamasgaldo/3-energy-equation3
http://fotos.miarroba.es/th/32d6/204...2D4F3CD61F.jpg

where L is the latent heat and alpha_l the mass fraction of the liquid phase.

How do I implement the term alpha_l*L in the functions F and dFdT?

Hi,
I would use
Code:

    F=H     dFdT=Cp
This is because, H=H(T) is the relationship you are trying to invert.
And, at that point you will typically hold the composition fixed, so that \alpha, L and H_{ref} are fixed. So, dFdT=Cp.
This of course assumes that L is not a function of T.

 lfgmarc July 20, 2012 22:00

A Little question?

Hi, I have a little question,

I understand that if i.e, the energy variable is enthalpy F=h(T) and dF/dT=Cp(T), my question is in where it is defined in the code that F and dF/dt take these variables as arguments.

 ahmmedshakil June 13, 2014 11:07

Enthalpy-temperature for melting problem

Hi isabel ,
Will you please guide me how you implemented the melting problem ?

Quote:
 Originally Posted by isabel (Post 344726) Dear friends, Thank you very much for your help. I need to simulate melting of a solid. In that case, the enthalpy is given by the following equation: http://fotos.miarroba.es/lamasgaldo/4-energy-equation3/ http://fotos.miarroba.es/lamasgaldo/4-energy-equation3/ http://fotos.miarroba.es/lamasgaldo/...3/#anchorPhotohttp://www.cfd-online.com/Forums/[im...3/#anchorPhotohttp://fotos.miarroba.es/lamasgaldo/...3/#anchorPhoto http://fotos.miarroba.es/lamasgaldo/...-equation3.jpg http://fotos.miarroba.es/lamasgaldo/3-energy-equation3 http://fotos.miarroba.es/th/32d6/204...2D4F3CD61F.jpg where L is the latent heat and alpha_l the mass fraction of the liquid phase. How do I implement the term alpha_l*L in the functions F and dFdT?

 Mhmnabil October 31, 2016 10:36

function "f"

Hi All,

I just don't know where that "f" is coming from in OpenFOAM??? I know "F" and "dFdT", but I don't understand "f" in the Newton's routine!!

Quote:
 Originally Posted by adhiraj (Post 344594) They are the function and its derivative. The Newton iteration in this case calculates T, given F(T) and dF/dT(T). The function gets pointers to the functions F and dF/dt. If the energy variable is enthalpy h, then F=h(T) and dF/dt=Cp(T). If it is internal energy e, then F=e and dF/dT=Cv(T). The code resolves these at runtime, and sends the appropriate pointers to the Newton iteration routine.

 Mhmnabil October 31, 2016 10:38

Newton's Routine

What is that "f" in the routine?! Where does it come from?

Quote:
 Originally Posted by isabel (Post 344288) Thank you very much. I found the iteration in these lines: // return the temperature corresponding to the value of the // thermodynamic property f, given the function f = F(T) and dF(T)/dT template inline scalar specieThermo::T ( scalar f, scalar T0, scalar (specieThermo::*F)(const scalar) const, scalar (specieThermo::*dFdT)(const scalar) const ) const { scalar Test = T0; scalar Tnew = T0; scalar Ttol = T0*tol_; int iter = 0; do { Test = Tnew; Tnew = Test - ((this->*F)(Test) - f)/(this->*dFdT)(Test); if (iter++ > maxIter_) { FatalErrorIn ( "specieThermo::T(scalar f, scalar T0, " "scalar (specieThermo::*F)(const scalar) const, " "scalar (specieThermo::*dFdT)(const scalar) const" ") const" ) << "Maximum number of iterations exceeded" << abort(FatalError); } } while (mag(Tnew - Test) > Ttol); return Tnew; } There is something I do not understhand. What does “this->” means?

 qjh888 May 31, 2017 02:26

Could anybody help me to find where it is defined in the code that F and dF/dt take these variables as arguments??

Thanks!

 All times are GMT -4. The time now is 23:57.