-
Notifications
You must be signed in to change notification settings - Fork 9
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
Make sure that DensityEnergyFromPressureTemperature works for all equations of state #449
base: main
Are you sure you want to change the base?
Conversation
@@ -36,4 +36,4 @@ jobs: | |||
.. | |||
make -j4 | |||
make install | |||
make test | |||
ctest --output-on-failure |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I'd like to leave this permanently. You still get a summary out at the end, but here we can see what went wrong with a test. Useful for debugging, especially when the CI machine and your laptop disagree...
// JMM: This method is often going to be overloaded for special cases. | ||
template <typename Indexer_t = Real *> | ||
PORTABLE_INLINE_FUNCTION void | ||
DensityEnergyFromPressureTemperature(const Real press, const Real temp, | ||
Indexer_t &&lambda, Real &rho, Real &sie) const { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This default implementation is usually not optimal but does seem to work if a given EOS doesn't need special cases. In general, though, an EOS should overload and implement its own.
// JMM: This needs to not fail and instead return something sane | ||
if (status != Status::SUCCESS) { | ||
PORTABLE_WARN("DensityEnergyFromPressureTemperature failed to find root\n"); | ||
rho = rhoguess; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a function that may be passed data and I see it as similar to a PTE solve. Even if it fails out, something reasonable must be done.
rho = 1e7; | ||
temp = 1.5e9; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Conditions for an oxygen burning shell in a stellar core.
PORTABLE_FORCEINLINE_FUNCTION | ||
Real MaximumDensity() const { | ||
if (_s > 1) { | ||
return 0.99 * robust::ratio(_s * _rho0, _s - 1); | ||
} else { // for s <= 1, no maximum, but we need to pick something. | ||
return 1e3 * _rho0; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are the conditions where the reference isotherm is a positive temperature.
PORTABLE_FORCEINLINE_FUNCTION | ||
Real MinimumDensity() const { return 10 * robust::EPS(); } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the reference isotherm scales as _rho0/rho, the EOS diverges at zero density. This bounds it at least to some degree.
auto lPofRT = [&](Real lR) { return lP_.interpToReal(Ye, lT, lR); }; | ||
auto status = regula_falsi(lPofRT, lP, lrguess, lRhoMin_, lRhoMax_, ROOT_THRESH, | ||
ROOT_THRESH, lrguess); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the EOS is tabulated in logrho, use logrho for the root find.
@@ -131,6 +131,10 @@ class Vinet : public EosBase<Vinet> { | |||
ValuesAtReferenceState(Real &rho, Real &temp, Real &sie, Real &press, Real &cv, | |||
Real &bmod, Real &dpde, Real &dvdt, | |||
Indexer_t &&lambda = static_cast<Real *>(nullptr)) const; | |||
|
|||
PORTABLE_FORCEINLINE_FUNCTION | |||
Real MinimumDensity() const { return std::cbrt(10 * robust::EPS()) * _rho0; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
EOS depends on
// Density/Energy from P/T not unique, if used will give error | ||
template <typename Indexer_t = Real *> | ||
PORTABLE_INLINE_FUNCTION void | ||
DensityEnergyFromPressureTemperature(const Real press, const Real temp, | ||
Indexer_t &&lambda, Real &rho, Real &sie) const; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use the default in the base class
template <typename EOS, typename Indexer_t = Real *> | ||
PORTABLE_INLINE_FUNCTION bool | ||
CheckRhoSieFromPT(EOS eos, Real rho, Real T, | ||
Indexer_t &&lambda = static_cast<Real *>(nullptr)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Convenience function to let me test the functionality more easily
Ok that was finicky but tests on github now seem to be passing. re-git tests appear to be having some network issues. Ping @rbberger for after the holidays. :) |
PR Summary
The easiest way to get the Jacobian for the PT-space PTE solver we are building is to ensure that the
DensityEnergyFromPressureTemperature
call works consistently for all equations of state. This MR makes sure thats the case and threads this call through all the tests.To ease this process, I added a base class implementation. However, I think most classes will want their own implementations, and I added them when appropriate.
PR Checklist
make format
command after configuring withcmake
.If preparing for a new release, in addition please check the following:
when='@main'
dependencies are updated to the release version in the package.py