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

Merged
merged 45 commits into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
4a210b5
add RhoE of PT to base class and implement where relevant
jonahm-LANL Dec 23, 2024
50c08e7
formatting
jonahm-LANL Dec 23, 2024
acd9def
Tests pass on macbook. Still need to add a few tests
jonahm-LANL Dec 24, 2024
608a772
swap default to findRoot because it respects bounds
jonahm-LANL Dec 24, 2024
0bdead9
tests complete for everything except eospac and spiner
jonahm-LANL Dec 24, 2024
0a4b61a
update zsplit
jonahm-LANL Dec 24, 2024
f1d1fc4
changelog
jonahm-LANL Dec 24, 2024
c5f75a5
missing auto
jonahm-LANL Dec 24, 2024
838b720
it works on my machine...
jonahm-LANL Dec 24, 2024
365dd65
output on failure please
jonahm-LANL Dec 24, 2024
376223f
just change tests to output-on-failure... and also loosen EPS in case…
jonahm-LANL Dec 24, 2024
9b083fa
lets try this...
jonahm-LANL Dec 24, 2024
c3182ff
make default implementation more robust maybe I hope
jonahm-LANL Dec 25, 2024
1034b38
put default rho gues close to STP
jonahm-LANL Dec 25, 2024
d6e80ee
put default rho gues close to STP
jonahm-LANL Dec 25, 2024
5f79307
re-tighten bounds after initial guess problem resolved
jonahm-LANL Dec 25, 2024
0e61f98
oops missing boolean not
jonahm-LANL Dec 25, 2024
cc8db8f
add several comments based on Jeff's feedback
jonahm-LANL Jan 3, 2025
58bc9c9
try 1e-8 MINR_DEFAULT
jonahm-LANL Jan 3, 2025
99aa6cd
Make base class use MaximumDensity
jonahm-LANL Jan 3, 2025
1e72ff5
update docs
jonahm-LANL Jan 3, 2025
26dd8f5
typo
jonahm-LANL Jan 3, 2025
be2f5b9
ok... lets try this
jonahm-LANL Jan 3, 2025
44e738b
make tests more effectively check for accurate pressure
jonahm-LANL Jan 3, 2025
fed072a
residual
jonahm-LANL Jan 3, 2025
8cc2508
formatting
jonahm-LANL Jan 3, 2025
6dc8cae
namespace
jonahm-LANL Jan 3, 2025
bc5f10e
tweak how to check this residual to work when P = 0
jonahm-LANL Jan 3, 2025
813e773
oops need to do magnitudes
jonahm-LANL Jan 3, 2025
e0e587c
come up with sensible bounds for power series EOSs.
jonahm-LANL Jan 3, 2025
cf286de
I give up. 1e-4 it is
jonahm-LANL Jan 3, 2025
2cdcc08
comment
jonahm-LANL Jan 3, 2025
1d1873f
remove unused variable
jonahm-LANL Jan 3, 2025
ceec265
tighter tolerances
jonahm-LANL Jan 3, 2025
8424efc
relax tolerance for chekc
jonahm-LANL Jan 3, 2025
7d9c90a
remove the maximum densities... we're never going to hit those bounds…
jonahm-LANL Jan 3, 2025
ee5e374
also add sanity check for rhomax vs rhomin
jonahm-LANL Jan 3, 2025
38bba46
missed leading underscore
jonahm-LANL Jan 3, 2025
a74bd26
stupid C++ deleting copy constructor for const correctness
jonahm-LANL Jan 3, 2025
5f8e8e0
choose worse, but more generic guess... does that help?
jonahm-LANL Jan 3, 2025
74ee377
is it because rho is uninitialized?
jonahm-LANL Jan 3, 2025
9e4f844
update docs
jonahm-LANL Jan 4, 2025
1cd2f9d
add introspection for pressure
jonahm-LANL Jan 8, 2025
6967e55
add default nullptr argument
jonahm-LANL Jan 9, 2025
144b90b
change name
jonahm-LANL Jan 9, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/tests_minimal.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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...

2 changes: 1 addition & 1 deletion .github/workflows/tests_minimal_kokkos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ jobs:
..
make -j4
make install
make test
ctest --output-on-failure
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- [[PR444]](https://github.com/lanl/singularity-eos/pull/444) Add Z split modifier and electron ideal gas EOS

### Fixed (Repair bugs, etc)
- [[PR449]](https://github.com/lanl/singularity-eos/pull/449) Ensure that DensityEnergyFromPressureTemperature works for all equations of state and is properly tested
- [[PR439]](https://github.com/lanl/singularity-eos/pull/439) Add mean atomic mass and number to EOS API
- [[PR437]](https://github.com/lanl/singularity-eos/pull/437) Fix segfault on HIP, clean up warnings, add strict sanitizer test

Expand Down
40 changes: 40 additions & 0 deletions singularity-eos/eos/eos_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
#include <ports-of-call/portability.hpp>
#include <ports-of-call/portable_errors.hpp>
#include <singularity-eos/base/constants.hpp>
#include <singularity-eos/base/robust_utils.hpp>
#include <singularity-eos/base/root-finding-1d/root_finding.hpp>
#include <singularity-eos/base/variadic_utils.hpp>

namespace singularity {
Expand Down Expand Up @@ -836,6 +838,44 @@ class EosBase {
PORTABLE_ALWAYS_THROW_OR_ABORT(msg);
}

// 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 {
Comment on lines +859 to +863
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.

// TODO(JMM): A lot hardcoded in here... Hopefully relevent EOS's
// overwrite.
constexpr Real MAXFAC = 1e8;
constexpr Real EPS = 10 * robust::EPS();
constexpr Real MINR_DEFAULT = 1e-4;
jhp-lanl marked this conversation as resolved.
Show resolved Hide resolved
constexpr Real DEFAULT_RHO_GUESS = 4;
using RootFinding1D::findRoot; // more robust but slower. Better default.
using RootFinding1D::Status;
CRTP copy = *(static_cast<CRTP const *>(this));
auto PofRT = [&](const Real r) {
return copy.PressureFromDensityTemperature(r, temp, lambda);
};
// JMM: This can't be zero, in case MinimumDensity is zero
Real rhomin = std::max(MINR_DEFAULT, copy.MinimumDensity());
Real rhomax = MAXFAC * rhomin;
Real rhoguess = rho; // use input density
if ((rhoguess < rhomin) || (rhoguess > rhomax)) {
if ((rhomin < DEFAULT_RHO_GUESS) && (rhomax > DEFAULT_RHO_GUESS)) {
rhoguess = DEFAULT_RHO_GUESS;
} else {
rhoguess = 0.5 * (rhomin + rhomax);
}
}
auto status = findRoot(PofRT, press, rhoguess, rhomin, rhomax, EPS, EPS, rho);
// 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.

sie = copy.InternalEnergyFromDensityTemperature(rho, temp, lambda);
return;
}

// Serialization
/*
The methodology here is there are *three* size methods all EOS's provide:
Expand Down
31 changes: 26 additions & 5 deletions singularity-eos/eos/eos_helmholtz.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -676,16 +676,37 @@ class Helmholtz : public EosBase<Helmholtz> {
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 {
// JMM: I'm not sure what to put here or if it matters. Some
// reference state, maybe stellar denity, would be appropriate.
PORTABLE_ALWAYS_ABORT("Stub");
// TODO(JMM): Is this right???
rho = 1e7;
temp = 1.5e9;
Yurlungur marked this conversation as resolved.
Show resolved Hide resolved
FillEos(rho, temp, sie, press, cv, bmod,
thermalqs::specific_internal_energy | thermalqs::pressure |
thermalqs::specific_heat | thermalqs::bulk_modulus,
lambda);
dpde = GruneisenParamFromDensityTemperature(rho, temp, lambda) * rho;
dvdt = 0;
}
template <typename Indexer_t = Real *>
PORTABLE_INLINE_FUNCTION void
DensityEnergyFromPressureTemperature(const Real press, const Real temp,
Indexer_t &&lambda, Real &rho, Real &sie) const {
// This is only used for mixed cell closures. Stubbing it out for now.
PORTABLE_ALWAYS_ABORT("Stub");
using RootFinding1D::regula_falsi;
using RootFinding1D::Status;
PORTABLE_REQUIRE(temp > = 0, "Non-negative temperature required");
auto PofRT = [&](const Real r) {
return PressureFromDensityTemperature(r, temp, lambda);
};
auto status = regula_falsi(PofRT, press, 1e7, electrons_.rhoMin(),
electrons_.rhoMax(), 1.0e-8, 1.0e-8, rho);
if (status != Status::SUCCESS) {
PORTABLE_THROW_OR_ABORT("Helmholtz::DensityEnergyFromPressureTemperature: "
"Root find failed to find a solution given P, T\n");
}
if (rho < 0.) {
PORTABLE_THROW_OR_ABORT("Helmholtz::DensityEnergyFromPressureTemperature: "
"Root find produced negative energy solution\n");
}
sie = InternalEnergyFromDensityTemperature(rho, temp, lambda);
}
static std::string EosType() { return std::string("Helmholtz"); }
static std::string EosPyType() { return EosType(); }
Expand Down
55 changes: 43 additions & 12 deletions singularity-eos/eos/eos_mgusup.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,47 @@ class MGUsup : public EosBase<MGUsup> {
FillEos(Real &rho, Real &temp, Real &energy, Real &press, Real &cv, Real &bmod,
const unsigned long output,
Indexer_t &&lambda = static_cast<Real *>(nullptr)) const;

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.


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.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Honestly the $s &lt; 0$ case implies that the fundamental shock derivative is negative and the EOS is no longer convex, so it's not a very useful EOS. I think what you picked is as good as any for that case.

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 will add a comment to this effect.


template <typename Indexer_t = Real *>
PORTABLE_INLINE_FUNCTION void
DensityEnergyFromPressureTemperature(const Real press, const Real temp,
Yurlungur marked this conversation as resolved.
Show resolved Hide resolved
Indexer_t &&lambda, Real &rho, Real &sie) const {
using RootFinding1D::findRoot;
using RootFinding1D::Status;
// JMM: diverges for rho -> 0
// and for s > 1 and rho -> rho0
Real rhomin = MinimumDensity();
Real rhomax = MaximumDensity();
auto PofRT = [&](const Real r) {
return PressureFromDensityTemperature(r, temp, lambda);
};
Real rhoguess = rho; // use input density
if ((rhoguess < rhomin) || (rhoguess > rhomax)) {
rhoguess = 0.5 * (rhomin + rhomax);
}
// JMM: regula_falsi does not respect bounds
auto status = findRoot(PofRT, press, rhoguess, rhomin, rhomax, robust::EPS(),
robust::EPS(), rho);
if (status != Status::SUCCESS) {
PORTABLE_THROW_OR_ABORT(
"DensityEnergyFromPressureTemperature failed to find root\n");
}
sie = InternalEnergyFromDensityTemperature(rho, temp, lambda);
return;
}

template <typename Indexer_t = Real *>
PORTABLE_INLINE_FUNCTION void
ValuesAtReferenceState(Real &rho, Real &temp, Real &sie, Real &press, Real &cv,
Expand All @@ -148,11 +189,6 @@ class MGUsup : public EosBase<MGUsup> {
_AZbar.PrintParams();
printf("\n\n");
}
// Density/Energy from P/T not unique, if used will give error
template <typename Indexer_t>
PORTABLE_INLINE_FUNCTION void
DensityEnergyFromPressureTemperature(const Real press, const Real temp,
Indexer_t &&lambda, Real &rho, Real &sie) const;
inline void Finalize() {}
static std::string EosType() { return std::string("MGUsup"); }
static std::string EosPyType() { return EosType(); }
Expand Down Expand Up @@ -200,6 +236,8 @@ PORTABLE_INLINE_FUNCTION Real MGUsup::HugTemperatureFromDensity(Real rho) const
Real eta = 1.0 - robust::ratio(_rho0, rho);
Real f1 = 1.0 - _s * eta;
if (f1 <= 0.0) {
printf("f1, eta, rho, rho0, s = %.14e %.14e %.14e %.14e %.14e\n", f1, eta, rho, _rho0,
_s);
Yurlungur marked this conversation as resolved.
Show resolved Hide resolved
PORTABLE_ALWAYS_THROW_OR_ABORT("MGUsup model parameters s and rho0 together with rho "
"give a negative argument for a logarithm.");
}
Expand Down Expand Up @@ -350,13 +388,6 @@ PORTABLE_INLINE_FUNCTION Real MGUsup::BulkModulusFromDensityInternalEnergy(
value = robust::ratio(_rho0, rho) * value;
return value;
}
// AEM: Give error since function is not well defined
template <typename Indexer_t>
PORTABLE_INLINE_FUNCTION void MGUsup::DensityEnergyFromPressureTemperature(
const Real press, const Real temp, Indexer_t &&lambda, Real &rho, Real &sie) const {
EOS_ERROR("MGUsup::DensityEnergyFromPressureTemperature: "
"Not implemented.\n");
}
// AEM: We should add entropy and Gruneissen parameters here so that it is complete
// If we add also alpha and BT, those should also be in here.
template <typename Indexer_t>
Expand Down
12 changes: 0 additions & 12 deletions singularity-eos/eos/eos_powermg.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,6 @@ class PowerMG : public EosBase<PowerMG> {
}
printf("\n\n");
}
// Density/Energy from P/T not unique, if used will give error
template <typename Indexer_t>
PORTABLE_INLINE_FUNCTION void
DensityEnergyFromPressureTemperature(const Real press, const Real temp,
Indexer_t &&lambda, Real &rho, Real &sie) const;
inline void Finalize() {}
static std::string EosType() { return std::string("PowerMG"); }
static std::string EosPyType() { return EosType(); }
Expand Down Expand Up @@ -431,13 +426,6 @@ PORTABLE_INLINE_FUNCTION Real PowerMG::EntropyFromDensityInternalEnergy(
}
return value;
}
// AEM: Give error since function is not well defined
template <typename Indexer_t>
PORTABLE_INLINE_FUNCTION void PowerMG::DensityEnergyFromPressureTemperature(
const Real press, const Real temp, Indexer_t &&lambda, Real &rho, Real &sie) const {
EOS_ERROR("PowerMG::DensityEnergyFromPressureTemperature: "
"Not implemented.\n");
}
// AEM: We should add entropy and Gruneissen parameters here so that it is complete
// If we add also alpha and BT, those should also be in here.
template <typename Indexer_t>
Expand Down
8 changes: 0 additions & 8 deletions singularity-eos/eos/eos_sap_polynomial.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,14 +209,6 @@ class SAP_Polynomial : public EosBase<SAP_Polynomial> {
printf(" b3 = %g\n", _b3);
_AZbar.PrintParams();
}
template <typename Indexer_t>
PORTABLE_INLINE_FUNCTION void
DensityEnergyFromPressureTemperature(const Real press, const Real temp,
Indexer_t &&lambda, Real &rho, Real &sie) const {
PORTABLE_WARN("This function is a stub for an incomplete EoS.");
sie = 0.0;
rho = 0.0;
}
inline void Finalize() {}
static std::string EosType() { return std::string("SAP_Polynomial"); }
static std::string EosPyType() { return EosType(); }
Expand Down
20 changes: 19 additions & 1 deletion singularity-eos/eos/eos_stellar_collapse.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -653,7 +653,25 @@ PORTABLE_INLINE_FUNCTION Real StellarCollapse::GruneisenParamFromDensityInternal
template <typename Indexer_t>
PORTABLE_INLINE_FUNCTION void StellarCollapse::DensityEnergyFromPressureTemperature(
const Real press, const Real temp, Indexer_t &&lambda, Real &rho, Real &sie) const {
EOS_ERROR("StellarCollapse::DensityEnergyFromPRessureTemperature is a stub");
using RootFinding1D::regula_falsi;
using RootFinding1D::Status;
checkLambda_(lambda);
Real lrguess = lRho_(rho);
Real lT = lT_(temp);
Real lP = P2lP_(press);
Real Ye = lambda[Lambda::Ye];

if ((lrguess < lRhoMin_) || (lrguess > lRhoMax_)) {
lrguess = lRho_(rhoNormal_);
}
auto lPofRT = [&](Real lR) { return lP_.interpToReal(Ye, lT, lR); };
auto status = regula_falsi(lPofRT, lP, lrguess, lRhoMin_, lRhoMax_, ROOT_THRESH,
ROOT_THRESH, lrguess);
Comment on lines +669 to +671
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.


Real lE = lE_.interpToReal(Ye, lT, lrguess);
rho = rho_(lrguess);
sie = le2e_(lE);
lambda[Lambda::lT] = lT;
}

template <typename Indexer_t>
Expand Down
16 changes: 4 additions & 12 deletions singularity-eos/eos/eos_vinet.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.


// Generic functions provided by the base class. These contain e.g. the vector
// overloads that use the scalar versions declared here
SG_ADD_BASE_CLASS_USINGS(Vinet)
Expand All @@ -152,11 +156,6 @@ class Vinet : public EosBase<Vinet> {
}
printf("\n\n");
}
// 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;
Comment on lines -155 to -159
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

inline void Finalize() {}
static std::string EosType() { return std::string("Vinet"); }
static std::string EosPyType() { return EosType(); }
Expand Down Expand Up @@ -375,13 +374,6 @@ PORTABLE_INLINE_FUNCTION Real Vinet::BulkModulusFromDensityInternalEnergy(
Vinet_F_DT_func(rho, temp, output);
return output[7] * output[7] * rho;
}
// AEM: Give error since function is not well defined
template <typename Indexer_t>
PORTABLE_INLINE_FUNCTION void Vinet::DensityEnergyFromPressureTemperature(
const Real press, const Real temp, Indexer_t &&lambda, Real &rho, Real &sie) const {
EOS_ERROR("Vinet::DensityEnergyFromPressureTemperature: "
"Not implemented.\n");
}
// AEM: We should add entropy and Gruneissen parameters here so that it is complete
// If we add also alpha and BT, those should also be in here.
template <typename Indexer_t>
Expand Down
10 changes: 10 additions & 0 deletions singularity-eos/eos/modifiers/zsplit_eos.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,16 @@ class ZSplit : public EosBase<ZSplit<ztype, T>> {
// dvdt, dpde unchanged
}

template <typename Indexer_t = Real *>
PORTABLE_FUNCTION void
DensityEnergyFromPressureTemperature(const Real press, const Real temp,
Indexer_t &&lambda, Real &rho, Real &sie) const {
const Real scale = GetScale_(lambda);
const Real iscale = GetInvScale_(lambda);
t_.DensityEnergyFromPressureTemperature(iscale * press, temp, lambda, rho, sie);
sie *= scale;
}

PORTABLE_INLINE_FUNCTION
int nlambda() const noexcept { return NL + t_.nlambda(); }
static constexpr unsigned long PreferredInput() { return T::PreferredInput(); }
Expand Down
29 changes: 29 additions & 0 deletions test/eos_unit_test_helpers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include <memory>

#include <ports-of-call/portability.hpp>
#include <singularity-eos/base/robust_utils.hpp>

inline std::string demangle(const char *name) {

Expand Down Expand Up @@ -143,6 +144,34 @@ inline void compare_two_eoss(const E1 &test_e, const E2 &ref_e) {
return;
}

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

const Real P = eos.PressureFromDensityTemperature(rho, T, lambda);
const Real sie = eos.InternalEnergyFromDensityTemperature(rho, T, lambda);
Real rtest, etest;
eos.DensityEnergyFromPressureTemperature(P, T, lambda, rtest, etest);
Real bmod = eos.BulkModulusFromDensityTemperature(rho, T, lambda);
bool results_good = (isClose(rho, rtest, bmod * 1e-8) || isClose(rho, rtest, 1e-8)) &&
(isClose(sie, etest, bmod * 1e-8) || isClose(sie, etest, 1e-8));
if (!results_good) {
Real P_test = eos.PressureFromDensityTemperature(rtest, T, lambda);
Real residual = P_test - P;
printf("RhoSie of PT failure!\n"
"\trho_true = %.14e\n"
"\tsie_true = %.14e\n"
"\tP = %.14e\n"
"\tT = %.14e\n"
"\trho = %.14e\n"
"\tsie = %.14e\n"
"\tP_test = %.14e\n"
"\tresidual = %.14e\n",
rho, sie, P, T, rtest, etest, P_test, residual);
}
return results_good;
}

// Macro that checks for an exception or is a no-op depending on
// whether or not a non-serial backend is supplied
#ifdef PORTABILITY_STRATEGY_NONE
Expand Down
12 changes: 12 additions & 0 deletions test/test_eos_carnahan_starling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,18 @@ SCENARIO("CarnahanStarling1", "[CarnahanStarling][CarnahanStarling1]") {
"Energy");
}
}

WHEN("We check RhoSie from PT") {
int nwrong = 0;
portableReduce(
"Check RhoSieFromPT", 0, 1,
PORTABLE_LAMBDA(const int i, int &nw) {
nw +=
!CheckRhoSieFromPT(eos, 7.8290736890381501e-03, 1.5320999999999999e+03);
},
nwrong);
REQUIRE(nwrong == 0);
}
}
}
}
Expand Down
Loading
Loading