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

Fix Redlich-Kwong equilibrium calculations #898

Merged
merged 3 commits into from
Jul 10, 2020
Merged

Conversation

speth
Copy link
Member

@speth speth commented Jul 9, 2020

Changes proposed in this pull request

  • Fix documentation of ThermoPhase::setToEquilState: The values passed into this function are the nondimensional (species) chemical potentials, not the element potentials. The method ChemEquil::setToEquilState already handles calculation of the chemical potentials from the element potentials.
  • Fix use of element potential method with IdealSolidSolnPhase: The implementation of IdealSolidSolnPhase::setToEquilState incorrectly used the input array as the element potentials rather than the species chemical potentials. The modified implementation corresponds to that of the IdealGasPhase class. The previous implementation seems to generally have resulted in an exception being raised, which normally results in falling back to the Gibbs solver, so this shouldn't have been producing incorrect results.
  • Remove incorrect RedlichKwongMFTP::setToEquilState implementation: The inversion of setting the mole fractions based on the chemical potentials is not obvious for non-ideal phases, and the implementation here based on an ideal phase leads to incorrect equilibrium solutions.

If applicable, fill in the issue number this pull request is fixing

Fixes #847.

Checklist

  • There is a clear use-case for this code change
  • The commit message has a short title & references relevant issues
  • Build passes (scons build & scons test) and unit tests address code coverage
  • The pull request is ready for review

speth added 3 commits July 9, 2020 17:23
The values passed into this function are the nondimensional (species) chemical
potentials, not the element potentials. The method ChemEquil::setToEquilState
already handles calculation of the chemical potentials from the element
potentials.
The implementation of IdealSolidSolnPhase::setToEquilState incorrectly used
the input array as the element potentials rather than the species chemical
potentials. The modified implementation corresponds to that of the
IdealGasPhase class.

The previous implementation seems to generally have resulted in an exception
being raised, which normally results in falling back to the Gibbs solver,
so this shouldn't have been producing incorrect results.
The inversion of setting the mole fractions based on the chemical potentials
is not obvious for non-ideal phases, and the implementation here based on
an ideal phase leads to incorrect equilibrium solutions.
@decaluwe
Copy link
Member

decaluwe commented Jul 9, 2020

Thanks @speth. Gave it a look through, and this all looks good to me; pretty non-controversial.

Just a note to myself / cross-ref to make sure we similarly remove this method for the nascent Peng-Robinson phase in #641, before merging (if we haven't already done so).

@codecov
Copy link

codecov bot commented Jul 9, 2020

Codecov Report

Merging #898 into main will increase coverage by 0.05%.
The diff coverage is 58.33%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #898      +/-   ##
==========================================
+ Coverage   71.11%   71.17%   +0.05%     
==========================================
  Files         376      376              
  Lines       46201    46190      -11     
==========================================
+ Hits        32858    32877      +19     
+ Misses      13343    13313      -30     
Impacted Files Coverage Δ
include/cantera/thermo/IdealSolidSolnPhase.h 62.50% <ø> (ø)
include/cantera/thermo/RedlichKwongMFTP.h 100.00% <ø> (ø)
include/cantera/thermo/ThermoPhase.h 28.28% <0.00%> (ø)
src/thermo/RedlichKwongMFTP.cpp 78.04% <ø> (+1.55%) ⬆️
src/thermo/IdealSolidSolnPhase.cpp 66.39% <63.63%> (+6.47%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 07dac7b...a957808. Read the comment docs.

@speth speth merged commit 773523a into Cantera:main Jul 10, 2020
@speth speth deleted the fix-rk-equil branch July 10, 2020 00:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

"Element potential" equilibrium solver finds incorrect solution for Redlich-Kwong phase
2 participants