Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistent thermo calculations in BinarySolutionTabulatedThermo #1302

Closed
speth opened this issue Jun 1, 2022 · 1 comment · Fixed by #1442
Closed

Inconsistent thermo calculations in BinarySolutionTabulatedThermo #1302

speth opened this issue Jun 1, 2022 · 1 comment · Fixed by #1442

Comments

@speth
Copy link
Member

speth commented Jun 1, 2022

Problem description

For the BinarySolutionTabulatedThermo phase:

  • molar volume computed using the volume_mole function (in Python) disagrees with calculating the mole fraction weighted sum of the partial molar volumes.
  • molar enthalpy computed using the enthalpy_mole function disagrees with calculating the mole fraction weighted sum of the partial molar enthalpies.

Steps to reproduce

# setup
>>> import cantera as ct
>>> p = ct.Solution('lithium_ion_battery.yaml', 'anode')
>>> p.TPX = 350, 10*101325, [0.9, 0.1]

# molar volume
>>> p.volume_mole
0.0341882587444934
>>> sum(p.partial_molar_volumes * p.X)
0.03449907488986783

# molar enthalpy
>>> p.enthalpy_mole
1475155.1278555722
>>> sum(p.partial_molar_enthalpies * p.X)
1475438.5688689428

System information

  • Cantera version: 2.6.0 and main at 8fbb4bc

Additional context

This was discovered as part of #1299, which implements Cantera/enhancements#114.

@speth speth changed the title Inconsistent molar volume calculation in BinarySolutionTabulatedThermo Inconsistent thermo calculations in BinarySolutionTabulatedThermo Jun 1, 2022
@dschmider-HSOG
Copy link
Contributor

Hi Ray,

I came across this issue and had a look at the behavior. The composition of the phase that is used for the test ([0.9 0.1]) lies outside the provided molefraction in ‘lithium_ion_battery.yaml’. When calling p.volume_mole, BinarySolutionTabulatedThermo::interpolate is invoked, which currently does not extrapolate and therefore caps values below and above the provided molefractions. p.partial_molar_volumes is also capped but since the partial molar volumes are anyways constant in this case, it doesn’t matter. Therefore, p.volume_mole and sum(p.partial_molar_volumes * p.X) return different values.
If the test is done at a different composition within the provided range, for example [0.7 0.3], the results are equivalent for both p.volume_mole and sum(p.partial_molar_volumes * p.X).

linear

I also applied this test to a phase with tabulated molar-volume (‘BinarySolutionTabulatedThermo.yaml’). At molefractions that are provided in the table, p.volume_mole and sum(p.partial_molar_volumes * p.X) are equivalent but at values in-between the tabulated points, the results deviate slightly as a consequence of interpolation (see zoomed-in plot).

nonlinear
nonlinear_zoom

Worse, however, is that the enthalpy doesn’t match. This made me notice, that there are still some getter methods concerning (molar) quantities, that have to be overloaded in BinarySolutionTabulatedThermo to be able to handle non-linear molar volumes, namely:

  • getChemPotentials
  • getChemPotentials_RT
  • getPartialMolarEnthalpies
  • getPureGibbs
  • getGibbs_RT
  • getIntEnergy_RT
  • getIntEnergy_RT_ref

Currently, these methods still use m_speciesMolarVolume as implemented in IdealSolidSolnPhase where I guess it should actually be the partial molar volume at the current state, since it is no longer necessarily constant.

A possible solution to fix the missing extrapolation behavior could be to automatically append the pure species values of the tabulated quantities at molefractions 0 and 1 during initThermo. Additionally, if the user already provides tabulated data for the whole range from 0 to 1 it should be checked for consistency with the pure species values provided in the species section.
I think this might also be related to Issue #1303

Best regards,
David

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Development

Successfully merging a pull request may close this issue.

2 participants