Cantera / cantera

Chemical kinetics, thermodynamics, and transport tool suite
https://cantera.org
Other
581 stars 342 forks source link

Inconsistent Enthalpies #1642

Closed Michael-ljn closed 8 months ago

Michael-ljn commented 8 months ago

Problem description

The enthalpies are inconsistent after updating to Cantera 3.0.0.

After importing Cantera as ct , I use the following commands:

w=ct.Water() w.basis="mass" w.TP=273.15+25,ct.one_atm

w.h to obtain the specific enthalpy returns something very weird and that does not equal w.cp*w.T. After some checks, w.cp*w.T returns the correct result and w.h not.

System information

Attachments

since the issue is very basic, here is a screenshot:

Screenshot 2023-10-26 at 20 36 39
bryanwweber commented 8 months ago

Hi, thanks for reporting this. How are you validating what the correct enthalpy is? Enthalpy requires a reference state, so you should really only compare differences in enthalpy between states, not absolute values.

Michael-ljn commented 8 months ago

Yes, sorry for not putting the delta in the screenshot, I wanted to highlight that w.cp*w.T and w.h are not equal, which leads to some issues for me. I use in my code both cp, h and even H separately for a given quantity, using ct.Quantity(). As you plug in some large values for the mass in ct.Quantity(), there is a noticeable disbalance. I avoided the issue by using w.cp*w.T only, but then I am not sure if I can use the w.cp*w.T value when setting HP values.

In the screenshot below, I set a new state at 60°C

Screenshot 2023-10-26 at 22 07 20
bryanwweber commented 8 months ago

I think this result makes sense. The root of the misunderstanding, I think, is that ct.Water() actually represents a pure fluid that can assume liquid, two-phase, or gas states, with a correspondingly complicated equation of state. Therefore, I think the problem is how you're computing Delta h for the cp * T case. The definition of change of enthalpy (assuming c_p is a function of temperature only and c_p is continuous) is

Delta h = \int T_ref T_2 c_p(T) dT - \int T_ref T_1 c_p(T) dT

However, when calculating c_p_2 T_2 - c_p_1 T_1, you're not accounting for the variation of c_p with temperature, which the underlying equation of state in ct.Water() is accounting for. In addition, c_p in general is also a function of pressure, which I'm pretty sure is also accounted for by the equation of state implemented in ct.Water() (although the variation is likely small for these liquid states). Finally, if you were to cross a phase change, the ct.Water() class also accounts for phase changes, in which c_p is infinite and we have to add the enthalpy of vaporization (in the case of liquid->vapor change).

Also, just to note a typo in your first image, c_p is the specific heat at constant pressure, not constant volume, c_p = \left\ \frac{\partial h}{ \partial T} \right)_P

Michael-ljn commented 8 months ago

I see, I was under the impression that the cp captured all variations between the states and that specific enthalpy was directly derived from the computed value of the cp. This is why I assumed cp*T could be used interchangeably with the specific enthalpy. I will stick to delta h in that case.

Thanks a lot for your help on this!

(About the typo yes indeed, I copied the wrong line from the documentation and manually corrected for Cp but forgot to past the correct line from the doc 😅)

bryanwweber commented 8 months ago

Just to be extra clear:

I was under the impression that the cp captured all variations between the states

Cantera captures the cp variation between states for all the thermo models that Cantera supports, except the constant cp model which is constant by definition. That means you need to integrate from T1 to T2 to have the correct Delta h. And that's only for the case where cp is a function of temperature only (which is ideal gases and incompressible fluids). As I said, for the ct.Water() class, it implements a more complicated equation of state which accounts for both temperature and pressure variation in cp. The reference work is noted here: https://github.com/Cantera/cantera/blob/60ea75af4a3f34f163da07502953913a1a313cf8/interfaces/cython/cantera/liquidvapor.py#L17

decaluwe commented 8 months ago

Just chiming in to add two aspects that haven't been explicitly mentioned (I think; apologies if I simply missed it).

Michael-ljn commented 8 months ago

Thank you both for your detailed explanation and time on this!