-
Notifications
You must be signed in to change notification settings - Fork 11
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
Create minimum energy modifier #375
base: main
Are you sure you want to change the base?
Conversation
Wow it compiled first time!? The modifier isn't compiled yet, but the default minimum energy stuff should be compiling, which might mean what I wrote works? I'd still like to make an explicit unit test something along the lines of asserting that the energy is the zero temperature energy. |
Would this play nicely with the options that @annapiegra added for eospac @jhp-lanl ? It sounds similar though I don't recall the details. I assume it matters which order an energy shift is applied so that will need to be taken into account when constructing the modifier list. |
This is the exact function that @annapiegra added, but when it was added it was basically disabled (would throw an error) for any EOS other than EOSPAC. This basically changes that so that every EOS will have some notion of minimum energy by default. |
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.
Very clean how this came out. I wonder if we should make this more "monolithic" and just provide bounds on all independent variables.
I assume that would mean expanding this to enforce a minimum density and temperature as well? That seems pretty straight-foward and might be pretty easy to implement. I don't know if I'd want to do anything with upper bounds though. I feel that an extrapolation approach might be a superior way to handle upper-bounds. Speaking of extrapolation, I suppose that if a table has a non-zero lower temperature bound we might want to apply an extrapolation layer first that extends the minimum energy/temperature to 0 K first and then this would lie on top of it. |
I think it might be nice to impose energy and temperature floors together, yeah. 👍
That's fair... but is that always going to be valid going forward? What about an EOS that is for, e.g., a single phase as @aematts is planning to use?
True! I actually think what you've implemented here is a nice template for that kind of thing. |
That's a good point, but I think there's an important difference: I'm constraining the input to be on the EOS surface whereas I think @aematts is going to want to constrain the output such that it's clear when a phase EOS isn't valid. From my limited understanding of kinetic phase transitions, you might want to set a domain of validity for a phase EOS and not constrain yourself to that domain, but instead maybe provide a flag to indicate that you're not in the range of validity anymore. For example, you could return an infinite Gibbs free energy (or equivalent) when you're outside the domain of validity (which is basically a constant extrapolation). That way the rate at which that phase is created can be set to identically zero. Either way, I anticipate that we'll have to create additional modifiers to handle these use scenarios. |
Yeah fair enough. I may be over-engineering here. |
@Yurlungur I think this is ready for final review (sorry for the long delay) |
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.
Non-blocking request. But overall looks good!
Oh and I still need to test this code. I'll try to do that here shortly. |
@jonahm-LANL It looks like This is ready for final review (really just the test was added, but there are a few more changes) |
CI is failing on LLNL systems. DO NOT MERGE |
Sounds good. I'll add it in a subsequent MR.
|
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.
Looks good. One more suggestion caught. I think I fixed the problems on re-git in #473. But we should double check that before merging this.
Notably though, tabular SESAME tables can result in unexpected behavior. The | ||
``EOSPAC`` and ``SpinerEOSDependsRhoT`` models both rely on the result when | ||
EOSPAC querries the cold energy table (306). This energy *can* differ from the | ||
zero K isotherm for two reasons: | ||
|
||
#. The zero K isotherm includes the zero point energy. In other words, it is the | ||
energy of the lowest energy level whereas the cold curve is the energy of the | ||
potential well itself. This effect may be insignificant. | ||
|
||
#. In the absence of a 306 table for the material, EOSPAC will instead report | ||
the lowest isotherm's energy in place of a cold curve. If a given table does | ||
not extend to zero K, then an extrapolaiton is *not* performed. This results | ||
in an energy floor from the lowest temperature on the table, **not** from | ||
an extrapolated energy at zero K. | ||
|
||
.. note:: | ||
|
||
This modifier is only compatible with EOS where the | ||
``MinInternalEnergyFromDensity`` function is properly defined. Where it isn't | ||
defined, an error will occur at runtime. |
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.
👍 for careful documentation here
inline constexpr bool IsModified() const { return true; } | ||
|
||
inline constexpr T UnmodifyOnce() { return t_; } | ||
|
||
inline constexpr decltype(auto) GetUnmodifiedObject() { | ||
return t_.GetUnmodifiedObject(); | ||
} |
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.
inline constexpr bool IsModified() const { return true; } | |
inline constexpr T UnmodifyOnce() { return t_; } | |
inline constexpr decltype(auto) GetUnmodifiedObject() { | |
return t_.GetUnmodifiedObject(); | |
} | |
PORTABLE_FORCEINLINE_FUNCTION Real MaximumDensity() const { | |
return t_.MaximumDensity(); | |
} | |
PORTABLE_FORCEINLINE_FUNCTION Real MinimumPressure() const { | |
return t_.MinimumPressure(); | |
} | |
PORTABLE_FORCEINLINE_FUNCTION Real MaximumPressureAtTemperature(const Real temp) const { | |
return t_.MaximumPressureAtTemperature(temp); | |
} | |
template <typename Indexer_t = Real *> | |
PORTABLE_INLINE_FUNCTION Real MeanAtomicMassFromDensityTemperature( | |
const Real rho, const Real temperature, | |
Indexer_t &&lambda = static_cast<Real *>(nullptr)) const { | |
return t_.MeanAtomicMassFromDensityTemperature(rho, temperature, lambda); | |
} | |
template <typename Indexer_t = Real *> | |
PORTABLE_INLINE_FUNCTION Real MeanAtomicNumberFromDensityTemperature( | |
const Real rho, const Real temperature, | |
Indexer_t &&lambda = static_cast<Real *>(nullptr)) const { | |
return t_.MeanAtomicNumberFromDensityTemperature(rho, temperature, lambda); | |
} | |
SG_ADD_MODIFIER_METHODS(T, t_); | |
SG_ADD_MODIFIER_MEAN_METHODS(t_) |
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.
Ah my bad, I forgot how old this had become. I'll add those
// Helper function to copy a collection of EOS to device memory | ||
template <typename EOSArrT, typename EOS_T> | ||
EOS_T *copy_eos_arr_to_device(const int num_eos, EOSArrT eos_arr) { | ||
// Assumes that GetOnDevice() has already been called for each EOS in eos_arr | ||
const size_t EOS_bytes = num_eos * sizeof(EOS_T); | ||
EOS_T *v_EOS = (EOS_T *)PORTABLE_MALLOC(EOS_bytes); | ||
const size_t bytes = num_eos * sizeof(EOS_T); | ||
portableCopyToDevice(v_EOS, eos_arr.data(), bytes); | ||
return v_EOS; | ||
} | ||
|
||
// Helper function to call Finalize() on each eos in an array (host side) | ||
template <typename EOSArrT> | ||
void finalize_eos_arr(EOSArrT eos_arr) { | ||
// Call Finalize on each EOS on the host | ||
for (auto eos : eos_arr) { | ||
eos.Finalize(); | ||
} | ||
} |
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.
nice
PR Summary
Creates a minimum energy modifier and unifies EOS behind a default behavior of returning the zero K isotherm as the minimum possible internal energy.
Some notes:
Fixes #318
PR Checklist
make format
command after configuring withcmake
.If preparing for a new release, in addition please check the following: