-
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
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.
singularity-eos/eos/eos_base.hpp
Outdated
// 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.
singularity-eos/eos/eos_mgusup.hpp
Outdated
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.
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.
Honestly the
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 will add a comment to this effect.
singularity-eos/eos/eos_mgusup.hpp
Outdated
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. :) |
singularity-eos/eos/eos_mgusup.hpp
Outdated
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.
Honestly the
… anyway and I think they might be interacting badly with GPUs
OK... that took longer than I thought it would. All tests now passing once again and the machinery is more flexible and robust. @jhp-lanl please re-review when you get the chance. I believe I've addressed all your concerns. I also noticed that the |
Ping @jhp-lanl |
I'll try to re-review that by the end of today. |
Snuck in introspection for pressure into this MR as well. |
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.
Approving because none of my comments are really blocking. That said, I do think the name change to MaximumPressureAtTemperature()
would be preferable. I also think the documentation should be changed to indicate that there could be a temperature dependence for the maximum pressure if an EOS supports it.
doc/sphinx/src/using-eos.rst
Outdated
.. cpp:function:: Real MaximumPressureFromTemperature() const; | ||
|
||
provides a maximum possible pressure an equation of state | ||
supports. (Most models are unbounded in pressure.) This is again | ||
useful for root finds. |
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.
If you're modeling this off of what I did in the Gruneisen EOS, this isn't correct. This gives the maximum pressure at a given temperature. If you increase the temperature, the maximum pressure will increase.
For a sesame table, this would simply be
I know our convention is to use "From" in our lookup functions, but I'd argue this is subtly different and should be "At" instead. I'd argue our lookups are saying "Return a quantity given the provided state" ("Given" would be more accurate in the naming, but I'm not proposing it here). By contrast, this function does not take a complete thermodynamic state, instead taking a single variable and returning the information to form a complete state. Temperature by itself is not a complete thermodynamic state.
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 completely agree--I change the name. For the tabulated equations of state, I actually do pull it out and record it now (thinking ahead), but I let this float as the table interpolation does extrapolate off the top of the table. It's not particularly trustworthy, but it's not a hard limit. Only Gruneisen currently reports a maximum pressure bound. On the other hand, I do have each table report the minimum pressure, which is important.
Thanks for the review, @jhp-lanl ! Agree with your comments and have addressed them. Will merge once tests pass on re-git. |
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