-
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
Merged
Merged
Changes from all 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 50c08e7
formatting
jonahm-LANL acd9def
Tests pass on macbook. Still need to add a few tests
jonahm-LANL 608a772
swap default to findRoot because it respects bounds
jonahm-LANL 0bdead9
tests complete for everything except eospac and spiner
jonahm-LANL 0a4b61a
update zsplit
jonahm-LANL f1d1fc4
changelog
jonahm-LANL c5f75a5
missing auto
jonahm-LANL 838b720
it works on my machine...
jonahm-LANL 365dd65
output on failure please
jonahm-LANL 376223f
just change tests to output-on-failure... and also loosen EPS in case…
jonahm-LANL 9b083fa
lets try this...
jonahm-LANL c3182ff
make default implementation more robust maybe I hope
jonahm-LANL 1034b38
put default rho gues close to STP
jonahm-LANL d6e80ee
put default rho gues close to STP
jonahm-LANL 5f79307
re-tighten bounds after initial guess problem resolved
jonahm-LANL 0e61f98
oops missing boolean not
jonahm-LANL cc8db8f
add several comments based on Jeff's feedback
jonahm-LANL 58bc9c9
try 1e-8 MINR_DEFAULT
jonahm-LANL 99aa6cd
Make base class use MaximumDensity
jonahm-LANL 1e72ff5
update docs
jonahm-LANL 26dd8f5
typo
jonahm-LANL be2f5b9
ok... lets try this
jonahm-LANL 44e738b
make tests more effectively check for accurate pressure
jonahm-LANL fed072a
residual
jonahm-LANL 8cc2508
formatting
jonahm-LANL 6dc8cae
namespace
jonahm-LANL bc5f10e
tweak how to check this residual to work when P = 0
jonahm-LANL 813e773
oops need to do magnitudes
jonahm-LANL e0e587c
come up with sensible bounds for power series EOSs.
jonahm-LANL cf286de
I give up. 1e-4 it is
jonahm-LANL 2cdcc08
comment
jonahm-LANL 1d1873f
remove unused variable
jonahm-LANL ceec265
tighter tolerances
jonahm-LANL 8424efc
relax tolerance for chekc
jonahm-LANL 7d9c90a
remove the maximum densities... we're never going to hit those bounds…
jonahm-LANL ee5e374
also add sanity check for rhomax vs rhomin
jonahm-LANL 38bba46
missed leading underscore
jonahm-LANL a74bd26
stupid C++ deleting copy constructor for const correctness
jonahm-LANL 5f8e8e0
choose worse, but more generic guess... does that help?
jonahm-LANL 74ee377
is it because rho is uninitialized?
jonahm-LANL 9e4f844
update docs
jonahm-LANL 1cd2f9d
add introspection for pressure
jonahm-LANL 6967e55
add default nullptr argument
jonahm-LANL 144b90b
change name
jonahm-LANL File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,4 +36,4 @@ jobs: | |
.. | ||
make -j4 | ||
make install | ||
make test | ||
ctest --output-on-failure | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,4 +36,4 @@ jobs: | |
.. | ||
make -j4 | ||
make install | ||
make test | ||
ctest --output-on-failure |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,11 +16,14 @@ | |
#define _SINGULARITY_EOS_EOS_EOS_BASE_ | ||
|
||
#include <cstring> | ||
#include <limits> | ||
#include <string> | ||
|
||
#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 { | ||
|
@@ -781,6 +784,23 @@ class EosBase { | |
PORTABLE_FORCEINLINE_FUNCTION | ||
Real MinimumTemperature() const { return 0; } | ||
|
||
// Report maximum value of density. Default is unbounded. | ||
// JMM: Should we use actual infinity, the largest real, or just a | ||
// big number? For comparisons, actual infinity is better. It also | ||
// has the advantage of being projective with modifiers that modify | ||
// the max. On the other hand, it's more fraught if someone tries to | ||
// put it into a formula without guarding against it. | ||
PORTABLE_FORCEINLINE_FUNCTION | ||
Real MaximumDensity() const { return 1e100; } | ||
|
||
// These are for the PT space PTE solver to bound the iterations in | ||
// a safe range. | ||
PORTABLE_FORCEINLINE_FUNCTION | ||
Real MinimumPressure() const { return 0; } | ||
// Gruneisen EOS's often have a maximum density, which implies a maximum pressure. | ||
PORTABLE_FORCEINLINE_FUNCTION | ||
Real MaximumPressureAtTemperature([[maybe_unused]] const Real T) const { return 1e100; } | ||
|
||
PORTABLE_INLINE_FUNCTION | ||
Real RhoPmin(const Real temp) const { return 0.0; } | ||
|
||
|
@@ -836,6 +856,58 @@ 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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
using RootFinding1D::findRoot; // more robust but slower. Better default. | ||
using RootFinding1D::Status; | ||
|
||
// Pressure is not monotone in density at low densities, which can | ||
// prevent convergence. We want to approach tension from above, | ||
// not below. Choose close to, but above, normal density for a | ||
// metal like copper. | ||
constexpr Real DEFAULT_RHO_GUESS = 12; | ||
|
||
CRTP copy = *(static_cast<CRTP const *>(this)); | ||
|
||
// P(rho) not monotone. When relevant, bound rhopmin. | ||
Real rhomin = std::max(copy.RhoPmin(temp), copy.MinimumDensity()); | ||
Real rhomax = copy.MaximumDensity(); | ||
PORTABLE_REQUIRE(rhomax > rhomin, "max bound > min bound"); | ||
|
||
auto PofRT = [&](const Real r) { | ||
return copy.PressureFromDensityTemperature(r, temp, lambda); | ||
}; | ||
Real rhoguess = rho; // use input density | ||
if ((rhoguess <= rhomin) || (rhoguess >= rhomax)) { // avoid edge effects | ||
if ((rhomin < DEFAULT_RHO_GUESS) && (DEFAULT_RHO_GUESS < rhomax)) { | ||
rhoguess = DEFAULT_RHO_GUESS; | ||
} else { | ||
rhoguess = 0.5 * (rhomin + rhomax); | ||
} | ||
} | ||
auto status = findRoot(PofRT, press, rhoguess, rhomin, rhomax, robust::EPS(), | ||
robust::EPS(), rho); | ||
// JMM: This needs to not fail and instead return something sane. | ||
// If root find failed to converge, density will at least be | ||
// within bounds. | ||
if (status != Status::SUCCESS) { | ||
PORTABLE_WARN("DensityEnergyFromPressureTemperature failed to find root\n"); | ||
} | ||
sie = copy.InternalEnergyFromDensityTemperature(rho, temp, lambda); | ||
return; | ||
} | ||
PORTABLE_INLINE_FUNCTION void DensityEnergyFromPressureTemperature(const Real press, | ||
const Real temp, | ||
Real &rho, | ||
Real &sie) const { | ||
CRTP copy = *(static_cast<CRTP const *>(this)); | ||
copy.DensityEnergyFromPressureTemperature(press, temp, static_cast<Real *>(nullptr), | ||
rho, sie); | ||
} | ||
|
||
// Serialization | ||
/* | ||
The methodology here is there are *three* size methods all EOS's provide: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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...