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 property updates in BinarySolutionTabulatedThermo #606

Merged
merged 3 commits into from
Mar 7, 2019

Conversation

speth
Copy link
Member

@speth speth commented Mar 5, 2019

Because IdealSolidSolnPhase::_updateThermo wasn't a virtual method, and the signature wasn't the same as BinarySolutionTabulatedThermo::_updateThermo (const vs non-const), calls to this method
from IdealSolidSolnPhase weren't being overridden by BinarySolutionTabulatedThermo::_updateThermo as expected.

After fixing this, there was still a problem in the case the temperature changed but the mole fractions were the same, where the tabulated correction to the enthalpy / entropy was being replaced by the pure species values. Now, we store the tabulated values and apply them every time.

Since IdealSolidSolnPhase::_updateThermo wasn't a virtual method, and
the signatures didn't match (const vs non-const), calls to this method
from IdealSolidSolnPhase weren't being overridden by
BinarySolutionTabulatedThermo::_updateThermo as expected.
@codecov
Copy link

codecov bot commented Mar 6, 2019

Codecov Report

Merging #606 into master will increase coverage by 0.01%.
The diff coverage is 88.88%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #606      +/-   ##
==========================================
+ Coverage    68.5%   68.52%   +0.01%     
==========================================
  Files         363      363              
  Lines       39962    39953       -9     
==========================================
  Hits        27376    27376              
+ Misses      12586    12577       -9
Impacted Files Coverage Δ
...ude/cantera/thermo/BinarySolutionTabulatedThermo.h 33.33% <ø> (ø) ⬆️
include/cantera/thermo/IdealSolidSolnPhase.h 41.66% <ø> (ø) ⬆️
test/thermo/BinarySolutionTabulatedThermo_Test.cpp 100% <100%> (ø) ⬆️
src/thermo/BinarySolutionTabulatedThermo.cpp 76.04% <85.71%> (+5.39%) ⬆️

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 1f70f77...3c97fa0. Read the comment docs.

@decaluwe
Copy link
Member

decaluwe commented Mar 6, 2019 via email

Copy link
Member

@decaluwe decaluwe left a comment

Choose a reason for hiding this comment

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

Hi Ray, thanks for catching this and cleaning it up. This all looks good to me.

@@ -156,15 +156,15 @@ class BinarySolutionTabulatedThermo : public IdealSolidSolnPhase
size_t m_kk_tab;

//! Current tabulated species mole fraction
double m_xlast;
mutable double m_xlast;

//! Vector for storing tabulated thermo
vector_fp m_molefrac_tab;
vector_fp m_enthalpy_tab;
vector_fp m_entropy_tab;

private:
Copy link
Member

Choose a reason for hiding this comment

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

Just for my own growth, can you explain what adding const after the method name does?

Copy link
Member Author

Choose a reason for hiding this comment

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

A method with const at the end of the declaration cannot modify any member variables of the class, except those that are marked as mutable. See this SO answer for a more detailed explanation.

The fact that a non-const function does not override a const function which otherwise has the same signature is one of C++'s many subtle "gotchas".

@@ -52,6 +52,9 @@ TEST_F(BinarySolutionTabulatedThermo_Test,interp_h)
{
set_defect_X(xmin + i*dx);
EXPECT_NEAR(expected_result[i], test_phase->enthalpy_mole(), 1.e-6);
// enthalpy is temperature-independent
Copy link
Member

Choose a reason for hiding this comment

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

This is correct for the cti file on which this test is built, but am I correct that it is not necessarily true of the phase model (i.e. the excess terms are added to the species "standard state" terms, which are calculated according to whatever is in the cti file?)

If I'm correct about that, there are two rather minor concerns:

  1. The test could easily be broken if the underlying cti file is updated w/ temperature-dependent species thermo. Thinking while I write, here, but this is actually a good thing, in that the cti probably shouldn't be changed in that way. It is good to be able to verify that temperature updates and composition updates are 'disentangled,' and the temperature-independent thermo provides a good pathway for this.
  2. Also a very minor concern, but someone reading this test suite to learn more about the class might get the wrong impression. Chances are vanishingly small that this would happen, particularly as there are other, better places to learn about the class. But it crossed my mind...

Copy link
Member Author

Choose a reason for hiding this comment

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

Correct, that is a property of the example input file which sets the standard state to be h(T) = 0, not of the model as a whole. In general, I would expect changes to the test data files to cause some of the tests to fail -- if you can change the data files and all the tests still succeed, I'd argue that the tests aren't checking the right things.

I will update the comment to indicate why the enthalpy is temperature independent in this particular case, to avoid any confusion.

m_tlast = tnow;
m_xlast = xnow;
} else if (m_tlast != tnow) {
Copy link
Member

Choose a reason for hiding this comment

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

Thanks for catching this. I know I thought through the logic when I was doing this, and am having a hard time figuring out if I actually thought this previous approach was satisfactory, or just forgot to go back and fix it.

Anyway, the new approach is a lot better, regardless.

In the case where temperature changes but the mole fractions are the same, we
still need to apply the enthalpy and entropy offsets to the tabulated species.
The value of m_xlast should only be set to a valid value by _updateThermo,
after it has calculated values for the tabulated enthalpy and entropy.
@speth speth merged commit bdc8168 into Cantera:master Mar 7, 2019
@speth speth deleted the fix-binary-tabulated branch March 7, 2019 00:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants