-
Notifications
You must be signed in to change notification settings - Fork 21
Add a SpinerEosDependsRhoSie constructor that uses an existing eos object to generate a spiner eos #632
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
Merged
Merged
Add a SpinerEosDependsRhoSie constructor that uses an existing eos object to generate a spiner eos #632
Changes from all commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
05614f8
Add a SpinerEosDependsRhoSie constructor that takes an existing eos a…
buechlerm 9c668ef
Add AI disclaimer
buechlerm 983fdf2
Docuemnt the constructor
buechlerm 828d4e3
Add concepts for has_cv nad has_gamma
buechlerm 678a907
Add some more concepts
buechlerm 946a34d
Finish bulk modulus and associated derivatives
buechlerm cdb063f
Fix abar access and other logic
buechlerm 4b6a120
add a test for initializing with eospac
buechlerm b25a5e7
Fix test and update documentation
buechlerm a1955e6
Add an example of the custom eos to spiner process
buechlerm 7bf7bd7
Move and rename claude plan
buechlerm 58e6667
Formated files, but maybe not the correct clang-format version
buechlerm 9aa7b65
Add ai notice in example program
buechlerm ea3be96
Add a changelog entry
buechlerm 672cb1f
Moved method detection helpers to base/eos_concepts.hpp
buechlerm b627b93
Add method verification for bounds
buechlerm 47d5450
add appropriate agentic disclaimer in eos_concepts.hpp
buechlerm 67482ec
Create generic finite difference algorithm
buechlerm 2474442
Fix errors using the finite difference
buechlerm 6ee5dc6
Convert one more block to using generic central difference
buechlerm 3b334e8
Add evaluateion of min/max rho and min temperature to begining of the…
buechlerm 6986300
add a general finite difference with bounds
buechlerm 58bf318
Fixtemplate parameter
buechlerm 857d1ef
Fix typos
buechlerm 5989a70
Add generic EOS-to-Spiner constructors for RhoT
buechlerm 77c316c
Merge testing of the rho_t and rho_sie constructors into 1 file
buechlerm 367d4c4
Actually add the merged test file
buechlerm 5b90ab6
Apply formating
buechlerm de20e4e
Correct the licence date
buechlerm 5715148
Fix inconsistencies between spinerTableGridParams and sesame2spiner
buechlerm 363d32f
Apply formatting
buechlerm bc5ab8a
Update licence date in sesame2spiner/generate_files.{cpp,hpp}
buechlerm fbd3f83
Add blank line at the end of eos_concepts.hpp
buechlerm 6899a13
Use first order forward and backward difference on the boundaries
buechlerm c70a76d
Try to improve description on choice of rho_sie vs rho_temp
buechlerm 48385a3
Merge branch 'main' into buechler/spiner_constructor
Yurlungur 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 hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -1720,6 +1720,215 @@ constructor for ``SpinerEOSDependsRhoSie`` is identical. | |
| ``SpinerEOS`` model does **not** support the | ||
| ``MeanAtomicProperties`` struct. | ||
|
|
||
| Constructing SpinerEOS from a Generic EOS | ||
| ''''''''''''''''''''''''''''''''''''''''''' | ||
|
|
||
| ``SpinerEOSDependsRhoSie`` can also be constructed directly from any | ||
| analytic or tabulated EOS object, allowing you to tabulate any equation | ||
| of state into the high-performance Spiner format in memory. This is | ||
| useful for converting analytic models (like ``IdealGas``, ``Gruneisen``, | ||
| etc.) into tabulated form, or for creating custom resolution tables | ||
| from existing EOS models. | ||
|
|
||
| The constructor has the signature: | ||
|
|
||
| .. code-block:: cpp | ||
|
|
||
| template <typename EOS> | ||
| SpinerEOSDependsRhoSie(const EOS &source_eos, | ||
| const SpinerTableGridParams ¶ms, | ||
| bool reproducibility_mode = false); | ||
|
|
||
| where ``source_eos`` is any EOS object that provides the standard | ||
| singularity-eos interface (at minimum: | ||
| ``TemperatureFromDensityInternalEnergy``, | ||
| ``InternalEnergyFromDensityTemperature``, | ||
| ``PressureFromDensityTemperature``, and | ||
| ``PressureFromDensityInternalEnergy``). The ``params`` struct controls | ||
| the grid construction and material properties. | ||
|
|
||
| The ``SpinerTableGridParams`` struct contains grid parameters that match | ||
| the options available in ``sesame2spiner``: | ||
|
|
||
| .. code-block:: cpp | ||
|
|
||
| struct SpinerTableGridParams { | ||
| // Density bounds | ||
| Real rhoMin, rhoMax; | ||
| int numRho = -1; // -1 means use numRhoPerDecade | ||
| int numRhoPerDecade = 350; | ||
|
|
||
| // Temperature bounds | ||
| Real TMin, TMax; | ||
| int numT = -1; // -1 means use numTPerDecade | ||
| int numTPerDecade = 100; | ||
|
|
||
| // Specific internal energy bounds | ||
| Real sieMin, sieMax; | ||
| int numSie = -1; // -1 means use numSiePerDecade | ||
| int numSiePerDecade = 100; | ||
|
|
||
| // Material properties | ||
| int matid = 0; | ||
| Real Abar = NaN; // defaults from source EOS if available | ||
| Real Zbar = NaN; | ||
| Real rhoNormal = NaN; // defaults to geometric mean of bounds | ||
|
|
||
| // Piecewise grid options (see Piecewise Spiner Grids section) | ||
| bool piecewiseRho = true; | ||
| bool piecewiseT = true; | ||
| bool piecewiseSie = true; | ||
| Real rhoCoarseFactorLo = 3.0; | ||
| Real rhoCoarseFactorHi = 5.0; | ||
| Real TCoarseFactor = 1.5; | ||
| Real sieCoarseFactor = 1.5; | ||
| Real rhoFineDiameterDecades = 1.5; | ||
| Real TSplitPoint = 1e4; | ||
|
|
||
| // Advanced options | ||
| Real shrinklRhoBounds = 0.0; | ||
| Real shrinklTBounds = 0.0; | ||
| Real shrinkleBounds = 0.0; | ||
| Real strictlyPositiveMinRho = 1e-8; | ||
| Real strictlyPositiveMinT = 1e-2; | ||
| }; | ||
|
|
||
| Defaults follow the ``sesame2spiner`` tool conventions. The grid | ||
| construction automatically handles offset computation for negative | ||
| values (especially important for specific internal energy). | ||
|
|
||
| Example usage: | ||
|
|
||
| .. code-block:: cpp | ||
|
|
||
| #include <singularity-eos/eos/eos.hpp> | ||
|
|
||
| // Create an analytic EOS | ||
| constexpr Real Cv = 2.0; | ||
| constexpr Real gm1 = 0.4; | ||
| IdealGas ideal(gm1, Cv); | ||
|
|
||
| // Set up grid parameters | ||
| SpinerTableGridParams params; | ||
| params.rhoMin = 1e-3; | ||
| params.rhoMax = 1e3; | ||
| params.TMin = 1e2; | ||
| params.TMax = 1e5; | ||
| params.sieMin = Cv * params.TMin; | ||
| params.sieMax = Cv * params.TMax; | ||
| params.matid = 1001; | ||
| params.numRhoPerDecade = 100; // optional: finer resolution | ||
|
|
||
| // Construct SpinerEOS from the IdealGas | ||
| SpinerEOSDependsRhoSie spiner_eos(ideal, params); | ||
|
|
||
| // Use like any other SpinerEOS | ||
| Real P = spiner_eos.PressureFromDensityTemperature(rho, T); | ||
| Real T_out = spiner_eos.TemperatureFromDensityInternalEnergy(rho, sie); | ||
|
|
||
| .. note:: | ||
|
|
||
| This constructor only supports ``TableSplit::Total``. Electron-only | ||
| and ion-cold splits are not available for generic EOS, as these | ||
| require additional physics that generic EOS models may not provide. | ||
|
buechlerm marked this conversation as resolved.
|
||
|
|
||
| .. note:: | ||
|
|
||
| The constructor automatically detects and uses optional EOS methods | ||
| when available to improve accuracy: | ||
|
|
||
| - ``GruneisenParamFromDensityTemperature`` or | ||
| ``GruneisenParamFromDensityInternalEnergy`` for computing dP/dE | ||
| - ``SpecificHeatFromDensityTemperature`` or | ||
| ``SpecificHeatFromDensityInternalEnergy`` for computing dT/dE | ||
| - ``PressureFromDensityInternalEnergy`` for direct pressure lookups | ||
| (otherwise uses chain rule conversions) | ||
|
|
||
| If these methods are not provided, derivatives are computed via centered | ||
| finite differences. Bulk modulus is always computed consistently from | ||
| derivatives using the internal ``calcBMod_()`` method. | ||
|
|
||
| Material properties (``MeanAtomicMass()`` and ``MeanAtomicNumber()``) | ||
| are automatically extracted from the source EOS if available and not | ||
| specified in ``params``. | ||
|
|
||
| Constructing SpinerEOSDependsRhoT from a Generic EOS | ||
| ''''''''''''''''''''''''''''''''''''''''''''''''''''' | ||
|
|
||
| ``SpinerEOSDependsRhoT`` also supports construction from any analytic or | ||
| tabulated EOS object using the same ``SpinerTableGridParams`` struct. The | ||
| RhoT variant is simpler and more memory-efficient than RhoSie, storing only | ||
| (ρ,T)-indexed tables rather than both (ρ,T) and (ρ,sie) tables. | ||
|
|
||
| The constructor signature is identical to RhoSie: | ||
|
|
||
| .. code-block:: cpp | ||
|
|
||
| template <typename EOS> | ||
| SpinerEOSDependsRhoT(const EOS &source_eos, | ||
| const SpinerTableGridParams ¶ms, | ||
| bool reproducibility_mode = false); | ||
|
|
||
| The same ``SpinerTableGridParams`` struct is used for both constructors. | ||
| RhoT-specific notes: | ||
|
|
||
| - The ``sieMin``, ``sieMax``, ``numSie``, ``numSiePerDecade``, | ||
| ``piecewiseSie``, and ``sieCoarseFactor`` parameters are ignored | ||
| (only relevant for RhoSie) | ||
| - All other parameters work identically | ||
|
|
||
| Example usage: | ||
|
|
||
| .. code-block:: cpp | ||
|
|
||
| #include <singularity-eos/eos/eos.hpp> | ||
|
|
||
| // Create an analytic EOS | ||
| constexpr Real Cv = 2.0; | ||
| constexpr Real gm1 = 0.4; | ||
| IdealGas ideal(gm1, Cv); | ||
|
|
||
| // Set up grid parameters (same struct as RhoSie) | ||
| SpinerTableGridParams params; | ||
| params.rhoMin = 1e-3; | ||
| params.rhoMax = 1e3; | ||
| params.TMin = 1e2; | ||
| params.TMax = 1e5; | ||
| params.matid = 1001; | ||
| params.numRhoPerDecade = 100; | ||
|
|
||
| // Construct SpinerEOSDependsRhoT | ||
| SpinerEOSDependsRhoT spiner_eos(ideal, params); | ||
|
|
||
| // Use like any other SpinerEOSDependsRhoT | ||
| Real P = spiner_eos.PressureFromDensityTemperature(rho, T); | ||
| Real sie = spiner_eos.InternalEnergyFromDensityTemperature(rho, T); | ||
| Real T_inv = spiner_eos.TemperatureFromDensityInternalEnergy(rho, sie); | ||
|
|
||
| .. note:: | ||
|
|
||
| **Choosing between RhoT and RhoSie**: | ||
|
|
||
| - Use ``SpinerEOSDependsRhoT`` when: | ||
|
Collaborator
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. Should we mention something about accuracy of root finds vs lookups? |
||
| - Your code primarily uses (ρ,T) lookups | ||
| - Memory efficiency is important | ||
| - You rarely require direct (ρ,sie) queries | ||
|
|
||
| - Use ``SpinerEOSDependsRhoSie`` when: | ||
| - Your code frequently uses both (ρ,T) and (ρ,sie) lookups | ||
| - You want direct P(ρ,sie) evaluation without additional inversion or root-finding steps | ||
| - You're using mixed-cell closure models (PTE, etc.) that naturally operate in (ρ,sie) | ||
|
|
||
| In general, SpinerEOSDependsRhoT is the more natural representation for EOS tables tabulated in (ρ,T), while SpinerEOSDependsRhoSie can provide better performance when frequent (ρ,sie) evaluations are required. The optimal choice depends on the access patterns and closure algorithms used by a particular application. | ||
|
|
||
| .. note:: | ||
|
|
||
| Like RhoSie, the RhoT constructor automatically detects optional EOS | ||
| methods (``GruneisenParamFromDensityTemperature``, | ||
| ``SpecificHeatFromDensityTemperature``, etc.) and uses them when available. | ||
| Otherwise, finite differences are used. Material properties are | ||
| automatically extracted from the source EOS. | ||
|
|
||
| Additionally Spiner EOS models support mass fraction lookups of the form | ||
|
|
||
| .. code-block:: cpp | ||
|
|
||
This file contains hidden or 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.
Uh oh!
There was an error while loading. Please reload this page.