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

Make sure that DensityEnergyFromPressureTemperature works for all equations of state #449

Open
wants to merge 17 commits into
base: main
Choose a base branch
from

Conversation

Yurlungur
Copy link
Collaborator

@Yurlungur Yurlungur commented Dec 24, 2024

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

  • Adds a test for any bugs fixed. Adds tests for new features.
  • Format your changes by using the make format command after configuring with cmake.
  • Document any new features, update documentation for changes made.
  • Make sure the copyright notice on any files you modified is up to date.
  • After creating a pull request, note it in the CHANGELOG.md file.
  • LANL employees: make sure tests pass both on the github CI and on the Darwin CI

If preparing for a new release, in addition please check the following:

  • Update the version in cmake.
  • Move the changes in the CHANGELOG.md file under a new header for the new release, and reset the categories.
  • Ensure that any when='@main' dependencies are updated to the release version in the package.py

@Yurlungur Yurlungur added bug Something isn't working enhancement New feature or request Testing Additions/changes to the testing infrastruture Robustness Ensures that existing features work as intended labels Dec 24, 2024
@Yurlungur Yurlungur self-assigned this Dec 24, 2024
@@ -36,4 +36,4 @@ jobs:
..
make -j4
make install
make test
ctest --output-on-failure
Copy link
Collaborator Author

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...

Comment on lines +841 to +845
// 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 {
Copy link
Collaborator Author

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.

Comment on lines +870 to +874
// 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;
}
Copy link
Collaborator Author

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.

Comment on lines +680 to +681
rho = 1e7;
temp = 1.5e9;
Copy link
Collaborator Author

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.

Comment on lines +132 to +139
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;
}
}
Copy link
Collaborator Author

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.

Comment on lines +129 to +130
PORTABLE_FORCEINLINE_FUNCTION
Real MinimumDensity() const { return 10 * robust::EPS(); }
Copy link
Collaborator Author

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.

Comment on lines +667 to +669
auto lPofRT = [&](Real lR) { return lP_.interpToReal(Ye, lT, lR); };
auto status = regula_falsi(lPofRT, lP, lrguess, lRhoMin_, lRhoMax_, ROOT_THRESH,
ROOT_THRESH, lrguess);
Copy link
Collaborator Author

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; }
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

EOS depends on $\left(\frac{\rho_0}{\rho}\right)^{1/3}$ so a reasonable bound before the EOS will become ill behaved is this.

Comment on lines -155 to -159
// 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;
Copy link
Collaborator Author

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

Comment on lines +147 to +150
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)) {
Copy link
Collaborator Author

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

@Yurlungur
Copy link
Collaborator Author

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. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request Robustness Ensures that existing features work as intended Testing Additions/changes to the testing infrastruture
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants