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 pressure dependence in IdealSolidSolnPhase::getPartialMolarEnthalpies #1087

Merged
merged 3 commits into from
Sep 16, 2021

Conversation

decaluwe
Copy link
Member

@decaluwe decaluwe commented Aug 19, 2021

Changes proposed in this pull request

  • Adds proper pressure dependence to IdealSolidSolnPhase::getPartialMolarEnthalpies

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

Closes #1080

If applicable, provide an example illustrating new features this pull request is introducing
Previously, the partial molar enthalpies had no pressure dependence for this class. As a check, the sum of partial molar enthalpy times mole fraction should equal the average phase molar enthalpy. Prior to this change:

import cantera as ct
import numpy as np

gas = ct.Solution('IdealSolidSolnPhaseExample.yaml',"solidSolutionExample")

# At standard pressure: h_mole = sum(X_k*h_k)
h_mole = gas.enthalpy_mole
h_check = np.dot(gas.partial_molar_enthalpies, gas.X)
print(h_mole - h_check)
0

# At non-standard pressure, h_mole shows the correct pressure dependence, but the partial molar enthalpies do not:
gas.TP = None, 3*ct.one_atm
h_mole = gas.enthalpy_mole
h_check = np.dot(gas.partial_molar_enthalpies, gas.X)
print(h_mole, h_check)
303975

With the implemented correction:

import cantera as ct
import numpy as np

gas = ct.Solution('IdealSolidSolnPhaseExample.yaml',"solidSolutionExample")

# At standard pressure: h_mole = sum(X_k*h_k)
h_mole = gas.enthalpy_mole
h_check = np.dot(gas.partial_molar_enthalpies, gas.X)
print(h_mole - h_check)
0

# At non-standard pressure, h_mole shows the correct pressure dependence, but the partial molar enthalpies do not:
gas.TP = None, 3*ct.one_atm
h_mole = gas.enthalpy_mole
h_check = np.dot(gas.partial_molar_enthalpies, gas.X)
print(h_mole, h_check)
0

Checklist

  • The pull request includes a clear description of this code change
  • Commit messages have short titles and reference relevant issues
  • Build passes (scons build & scons test) and unit tests address code coverage
  • Style & formatting of contributed code follows contributing guidelines
  • The pull request is ready for review

@decaluwe decaluwe force-pushed the IdealSolid branch 2 times, most recently from 01b0710 to 6892199 Compare August 19, 2021 12:46
@decaluwe
Copy link
Member Author

One question: I moved the "multiply by RT" step into the for loop. Would it be faster, computationally, to keep this outside the loop, using scale?

@codecov
Copy link

codecov bot commented Aug 19, 2021

Codecov Report

Merging #1087 (e0f84fa) into main (78f893f) will increase coverage by 0.01%.
The diff coverage is 87.85%.

❗ Current head e0f84fa differs from pull request most recent head f09de99. Consider uploading reports for the commit f09de99 to get more accurate results
Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1087      +/-   ##
==========================================
+ Coverage   73.45%   73.46%   +0.01%     
==========================================
  Files         362      364       +2     
  Lines       47554    47626      +72     
==========================================
+ Hits        34929    34987      +58     
- Misses      12625    12639      +14     
Impacted Files Coverage Δ
include/cantera/base/global.h 93.33% <ø> (ø)
include/cantera/kinetics/GasKinetics.h 100.00% <ø> (ø)
include/cantera/kinetics/Kinetics.h 55.88% <0.00%> (ø)
include/cantera/kinetics/MultiRate.h 82.60% <ø> (ø)
include/cantera/kinetics/Reaction.h 100.00% <ø> (ø)
src/clib/ct.cpp 8.29% <0.00%> (-0.06%) ⬇️
src/thermo/IdealSolidSolnPhase.cpp 68.65% <83.33%> (+0.23%) ⬆️
src/kinetics/GasKinetics.cpp 92.61% <85.71%> (-0.43%) ⬇️
src/kinetics/Reaction.cpp 89.20% <85.71%> (-1.24%) ⬇️
src/kinetics/ReactionRateFactory.cpp 93.33% <93.33%> (ø)
... and 18 more

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 78f893f...f09de99. Read the comment docs.

@decaluwe
Copy link
Member Author

FYI, I'm going to add a test to check that h_mole = sum(h_k * X_k), as in the commit message.

- Test that `enthalpy_mole = sum(X_k * h_k)` for `IdealSolidSolnPhase`
class, where `X_k` is mole fraction and `h_k` partial molar enthalpy.
- Also test the pressure independence of this equality, by verifying at
pressures 1 atm and 2 atm.
@decaluwe
Copy link
Member Author

Okay, once the tests finish running, this should be ready for review.

@decaluwe decaluwe requested a review from speth August 19, 2021 21:45
Copy link
Member

@speth speth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

As to the question about calling scale versus multiplying by RT() inside the loop, I think the latter (as you've opted for) is better, as it involves only one loop -- the scale function would have to loop internally anyway.

@speth speth merged commit 457b1a4 into Cantera:main Sep 16, 2021
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.

IdealSolidSolnPhase::getPartialMolarEnthalpies - needs pressure dependence?
2 participants