GridFire v0.7.1_rc2
General Purpose Nuclear Network
Loading...
Searching...
No Matches
PyDynamicEngine Class Referencefinal

#include <py_engine.h>

Inheritance diagram for PyDynamicEngine:
[legend]
Collaboration diagram for PyDynamicEngine:
[legend]

Public Member Functions

const std::vector< fourdst::atomic::Species > & getNetworkSpecies () const override
 PyDynamicEngine Implementation ///.
 
std::expected< gridfire::engine::StepDerivatives< double >, gridfire::engine::EngineStatuscalculateRHSAndEnergy (const fourdst::composition::CompositionAbstract &comp, double T9, double rho) const override
 Calculate the right-hand side (dY/dt) and energy generation.
 
gridfire::engine::NetworkJacobian generateJacobianMatrix (const fourdst::composition::CompositionAbstract &comp, double T9, double rho) const override
 Generate the Jacobian matrix for the current state.
 
gridfire::engine::NetworkJacobian generateJacobianMatrix (const fourdst::composition::CompositionAbstract &comp, double T9, double rho, const std::vector< fourdst::atomic::Species > &activeSpecies) const override
 Generate the Jacobian matrix for the current state using a subset of active species.
 
gridfire::engine::NetworkJacobian generateJacobianMatrix (const fourdst::composition::CompositionAbstract &comp, double T9, double rho, const gridfire::engine::SparsityPattern &sparsityPattern) const override
 Generate the Jacobian matrix for the current state with a specified sparsity pattern.
 
void generateStoichiometryMatrix () override
 Generate the stoichiometry matrix for the network.
 
int getStoichiometryMatrixEntry (const fourdst::atomic::Species &species, const gridfire::reaction::Reaction &reaction) const override
 Get an entry from the stoichiometry matrix.
 
double calculateMolarReactionFlow (const gridfire::reaction::Reaction &reaction, const fourdst::composition::CompositionAbstract &comp, double T9, double rho) const override
 Calculate the molar reaction flow for a given reaction.
 
const gridfire::reaction::ReactionSetgetNetworkReactions () const override
 Get the set of logical reactions in the network.
 
void setNetworkReactions (const gridfire::reaction::ReactionSet &reactions) override
 Set the reactions for the network.
 
std::expected< std::unordered_map< fourdst::atomic::Species, double >, gridfire::engine::EngineStatusgetSpeciesTimescales (const fourdst::composition::CompositionAbstract &comp, double T9, double rho) const override
 Compute timescales for all species in the network.
 
std::expected< std::unordered_map< fourdst::atomic::Species, double >, gridfire::engine::EngineStatusgetSpeciesDestructionTimescales (const fourdst::composition::CompositionAbstract &comp, double T9, double rho) const override
 Compute destruction timescales for all species in the network.
 
fourdst::composition::Composition update (const gridfire::NetIn &netIn) override
 Update the internal state of the engine.
 
bool isStale (const gridfire::NetIn &netIn) override
 Check if the engine's internal state is stale.
 
void setScreeningModel (gridfire::screening::ScreeningType model) override
 Set the electron screening model.
 
gridfire::screening::ScreeningType getScreeningModel () const override
 Get the current electron screening model.
 
size_t getSpeciesIndex (const fourdst::atomic::Species &species) const override
 Get the index of a species in the network.
 
std::vector< double > mapNetInToMolarAbundanceVector (const gridfire::NetIn &netIn) const override
 Map a NetIn object to a vector of molar abundances.
 
gridfire::engine::PrimingReport primeEngine (const gridfire::NetIn &netIn) override
 Prime the engine with initial conditions.
 
gridfire::engine::BuildDepthType getDepth () const override
 Get the depth of the network.
 
void rebuild (const fourdst::composition::CompositionAbstract &comp, gridfire::engine::BuildDepthType depth) override
 Rebuild the network with a specified depth.
 
gridfire::engine::EnergyDerivatives calculateEpsDerivatives (const fourdst::composition::CompositionAbstract &comp, double T9, double rho) const override
 Calculate the derivatives of the energy generation rate with respect to T and rho.
 
fourdst::composition::Composition collectComposition (const fourdst::composition::CompositionAbstract &comp, double T9, double rho) const override
 Recursively collect composition from current engine and any sub engines if they exist.
 
gridfire::engine::SpeciesStatus getSpeciesStatus (const fourdst::atomic::Species &species) const override
 Get the status of a species in the network.
 
- Public Member Functions inherited from gridfire::engine::Engine
virtual ~Engine ()=default
 Virtual destructor.
 

Private Attributes

std::vector< fourdst::atomic::Species > m_species_cache
 

Member Function Documentation

◆ calculateEpsDerivatives()

gridfire::engine::EnergyDerivatives PyDynamicEngine::calculateEpsDerivatives ( const fourdst::composition::CompositionAbstract &  comp,
double  T9,
double  rho 
) const
overridevirtual

Calculate the derivatives of the energy generation rate with respect to T and rho.

Parameters
compComposition object containing current abundances.
T9Temperature in units of 10^9 K.
rhoDensity in g/cm^3.
Returns
EnergyDerivatives containing dEps/dT and dEps/dRho.

This method computes the partial derivatives of the specific nuclear energy generation rate with respect to temperature and density for the current state.

Implements gridfire::engine::DynamicEngine.

◆ calculateMolarReactionFlow()

double PyDynamicEngine::calculateMolarReactionFlow ( const gridfire::reaction::Reaction reaction,
const fourdst::composition::CompositionAbstract &  comp,
double  T9,
double  rho 
) const
overridevirtual

Calculate the molar reaction flow for a given reaction.

Parameters
reactionThe reaction for which to calculate the flow.
compComposition object containing current abundances.
T9Temperature in units of 10^9 K.
rhoDensity in g/cm^3.
Returns
Molar flow rate for the reaction (e.g., mol/g/s).

This method computes the net rate at which the given reaction proceeds under the current state.

Implements gridfire::engine::DynamicEngine.

◆ calculateRHSAndEnergy()

std::expected< gridfire::engine::StepDerivatives< double >, gridfire::engine::EngineStatus > PyDynamicEngine::calculateRHSAndEnergy ( const fourdst::composition::CompositionAbstract &  comp,
double  T9,
double  rho 
) const
overridevirtual

Calculate the right-hand side (dY/dt) and energy generation.

Parameters
compComposition object containing current abundances.
T9Temperature in units of 10^9 K.
rhoDensity in g/cm^3.
Returns
expected<StepDerivatives<double>> containing either dY/dt and energy generation rate or a stale engine error indicating that the engine must be updated

This function must be implemented by derived classes to compute the time derivatives of all species and the specific nuclear energy generation rate for the current state.

Implements gridfire::engine::Engine.

◆ collectComposition()

fourdst::composition::Composition PyDynamicEngine::collectComposition ( const fourdst::composition::CompositionAbstract &  comp,
double  T9,
double  rho 
) const
overridevirtual

Recursively collect composition from current engine and any sub engines if they exist.

If species i is defined in comp and in any sub engine or self composition then the molar abundance of species i in the returned composition will be that defined in comp. If there are species defined in sub engine compositions which are not defined in comp then their molar abundances will be based on the reported values from each sub engine.

Note
It is up to each engine to decide how to handle filling in the return composition.
These methods return an unfinalized composition which must then be finalized by the caller
Parameters
compInput composition to "normalize".
T9
rho
Returns
An updated composition which is a superset of comp. This may contain species which were culled, for example, by either QSE partitioning or reaction flow rate culling

Implements gridfire::engine::DynamicEngine.

◆ generateJacobianMatrix() [1/3]

gridfire::engine::NetworkJacobian PyDynamicEngine::generateJacobianMatrix ( const fourdst::composition::CompositionAbstract &  comp,
double  T9,
double  rho 
) const
overridevirtual

Generate the Jacobian matrix for the current state.

Parameters
compComposition object containing current abundances.
T9Temperature in units of 10^9 K.
rhoDensity in g/cm^3.

This method must compute and store the Jacobian matrix (∂(dY/dt)_i/∂Y_j) for the current state. The matrix can then be accessed via getJacobianMatrixEntry().

Implements gridfire::engine::DynamicEngine.

◆ generateJacobianMatrix() [2/3]

gridfire::engine::NetworkJacobian PyDynamicEngine::generateJacobianMatrix ( const fourdst::composition::CompositionAbstract &  comp,
double  T9,
double  rho,
const gridfire::engine::SparsityPattern sparsityPattern 
) const
overridevirtual

Generate the Jacobian matrix for the current state with a specified sparsity pattern.

Parameters
compComposition object containing current abundances.
T9Temperature in units of 10^9 K.
rhoDensity in g/cm^3.
sparsityPatternThe sparsity pattern to use for the Jacobian matrix.

This method must compute and store the Jacobian matrix (∂(dY/dt)_i/∂Y_j) for the current state using automatic differentiation, taking into account the provided sparsity pattern. The matrix can then be accessed via getJacobianMatrixEntry().

See also
getJacobianMatrixEntry()

Implements gridfire::engine::DynamicEngine.

◆ generateJacobianMatrix() [3/3]

gridfire::engine::NetworkJacobian PyDynamicEngine::generateJacobianMatrix ( const fourdst::composition::CompositionAbstract &  comp,
double  T9,
double  rho,
const std::vector< fourdst::atomic::Species > &  activeSpecies 
) const
overridevirtual

Generate the Jacobian matrix for the current state using a subset of active species.

Parameters
compComposition object containing current abundances.
T9Temperature in units of 10^9 K.
rhoDensity in g/cm^3.
activeSpeciesThe set of species to include in the Jacobian calculation.

This method must compute and store the Jacobian matrix (∂(dY/dt)_i/∂Y_j) for the current state, considering only the specified subset of active species. The matrix can then be accessed via getJacobianMatrixEntry().

Implements gridfire::engine::DynamicEngine.

◆ generateStoichiometryMatrix()

void PyDynamicEngine::generateStoichiometryMatrix ( )
overridevirtual

Generate the stoichiometry matrix for the network.

This method must compute and store the stoichiometry matrix, which encodes the net change of each species in each reaction.

Implements gridfire::engine::DynamicEngine.

◆ getDepth()

gridfire::engine::BuildDepthType PyDynamicEngine::getDepth ( ) const
inlineoverridevirtual

Get the depth of the network.

Returns
The depth of the network, which may indicate the level of detail or complexity in the reaction network.

This method is intended to provide information about the network's structure, such as how many layers of reactions or species are present. It can be useful for diagnostics and understanding the network's complexity.

Reimplemented from gridfire::engine::DynamicEngine.

◆ getNetworkReactions()

const gridfire::reaction::ReactionSet & PyDynamicEngine::getNetworkReactions ( ) const
overridevirtual

Get the set of logical reactions in the network.

Returns
Reference to the LogicalReactionSet containing all reactions.

Implements gridfire::engine::DynamicEngine.

◆ getNetworkSpecies()

const std::vector< fourdst::atomic::Species > & PyDynamicEngine::getNetworkSpecies ( ) const
overridevirtual

PyDynamicEngine Implementation ///.

Implements gridfire::engine::Engine.

◆ getScreeningModel()

gridfire::screening::ScreeningType PyDynamicEngine::getScreeningModel ( ) const
overridevirtual

Get the current electron screening model.

Returns
The currently active screening model type.
Usage Example:
screening::ScreeningType currentModel = myEngine.getScreeningModel();

Implements gridfire::engine::DynamicEngine.

◆ getSpeciesDestructionTimescales()

std::expected< std::unordered_map< fourdst::atomic::Species, double >, gridfire::engine::EngineStatus > PyDynamicEngine::getSpeciesDestructionTimescales ( const fourdst::composition::CompositionAbstract &  comp,
double  T9,
double  rho 
) const
overridevirtual

Compute destruction timescales for all species in the network.

Parameters
compComposition object containing current abundances.
T9Temperature in units of 10^9 K.
rhoDensity in g/cm^3.
Returns
Map from Species to their destruction timescales (s).

This method estimates the destruction timescale for each species, which can be useful for understanding reaction flows and equilibrium states.

Implements gridfire::engine::DynamicEngine.

◆ getSpeciesIndex()

size_t PyDynamicEngine::getSpeciesIndex ( const fourdst::atomic::Species &  species) const
overridevirtual

Get the index of a species in the network.

Parameters
speciesThe species to look up.

This method allows querying the index of a specific species in the engine's internal representation. It is useful for accessing species data efficiently.

Implements gridfire::engine::DynamicEngine.

◆ getSpeciesStatus()

gridfire::engine::SpeciesStatus PyDynamicEngine::getSpeciesStatus ( const fourdst::atomic::Species &  species) const
overridevirtual

Get the status of a species in the network.

Parameters
speciesThe species to check.
Returns
SpeciesStatus indicating whether the species is active, inactive, or culled.

This method allows querying the current status of a specific species within the engine's network.

Implements gridfire::engine::DynamicEngine.

◆ getSpeciesTimescales()

std::expected< std::unordered_map< fourdst::atomic::Species, double >, gridfire::engine::EngineStatus > PyDynamicEngine::getSpeciesTimescales ( const fourdst::composition::CompositionAbstract &  comp,
double  T9,
double  rho 
) const
overridevirtual

Compute timescales for all species in the network.

Parameters
compComposition object containing current abundances.
T9Temperature in units of 10^9 K.
rhoDensity in g/cm^3.
Returns
Map from Species to their characteristic timescales (s).

This method estimates the timescale for abundance change of each species, which can be used for timestep control, diagnostics, and reaction network culling.

Implements gridfire::engine::DynamicEngine.

◆ getStoichiometryMatrixEntry()

int PyDynamicEngine::getStoichiometryMatrixEntry ( const fourdst::atomic::Species &  species,
const gridfire::reaction::Reaction reaction 
) const
overridevirtual

Get an entry from the stoichiometry matrix.

Parameters
speciesspecies to look up stoichiometry for.
reactionreaction to find
Returns
Stoichiometric coefficient for the species in the reaction.

The stoichiometry matrix must have been generated by generateStoichiometryMatrix().

Implements gridfire::engine::DynamicEngine.

◆ isStale()

bool PyDynamicEngine::isStale ( const gridfire::NetIn netIn)
overridevirtual

Check if the engine's internal state is stale.

Parameters
netInA struct containing the current network input, such as temperature, density, and composition.
Returns
True if the engine's state is stale and needs to be updated; false otherwise.

This method allows derived classes to determine if their internal state is out-of-date with respect to the provided network conditions. If the engine is stale, it may require a call to update() before performing calculations.

Usage Example:
NetIn input = { ... };
if (myEngine.isStale(input)) {
// Update the engine before proceeding
}

Implements gridfire::engine::DynamicEngine.

◆ mapNetInToMolarAbundanceVector()

std::vector< double > PyDynamicEngine::mapNetInToMolarAbundanceVector ( const gridfire::NetIn netIn) const
overridevirtual

Map a NetIn object to a vector of molar abundances.

Parameters
netInThe input conditions for the network.
Returns
A vector of molar abundances corresponding to the species in the network.

This method converts the input conditions into a vector of molar abundances, which can be used for further calculations or diagnostics.

Implements gridfire::engine::DynamicEngine.

◆ primeEngine()

gridfire::engine::PrimingReport PyDynamicEngine::primeEngine ( const gridfire::NetIn netIn)
overridevirtual

Prime the engine with initial conditions.

Parameters
netInThe input conditions for the network.
Returns
PrimingReport containing information about the priming process.

This method is used to prepare the engine for calculations by setting up initial conditions, reactions, and species. It may involve compiling reaction rates, initializing internal data structures, and performing any necessary pre-computation.

Implements gridfire::engine::DynamicEngine.

◆ rebuild()

void PyDynamicEngine::rebuild ( const fourdst::composition::CompositionAbstract &  comp,
gridfire::engine::BuildDepthType  depth 
)
inlineoverridevirtual

Rebuild the network with a specified depth.

Parameters
compThe composition to rebuild the network with.
depthThe desired depth of the network.

This method is intended to allow dynamic adjustment of the network's depth, which may involve adding or removing species and reactions based on the specified depth. However, not all engines support this operation.

Reimplemented from gridfire::engine::DynamicEngine.

◆ setNetworkReactions()

void PyDynamicEngine::setNetworkReactions ( const gridfire::reaction::ReactionSet reactions)
overridevirtual

Set the reactions for the network.

Parameters
reactionsThe set of reactions to use in the network.

This method replaces the current set of reactions in the network with the provided set. It marks the engine as stale, requiring regeneration of matrices and recalculation of rates.

Implements gridfire::engine::DynamicEngine.

◆ setScreeningModel()

void PyDynamicEngine::setScreeningModel ( gridfire::screening::ScreeningType  model)
overridevirtual

Set the electron screening model.

Parameters
modelThe type of screening model to use for reaction rate calculations.

This method allows changing the screening model at runtime. Screening corrections account for the electrostatic shielding of nuclei by electrons, which affects reaction rates in dense stellar plasmas.

Usage Example:
myEngine.setScreeningModel(screening::ScreeningType::WEAK);
Postcondition
The engine will use the specified screening model for subsequent rate calculations.

Implements gridfire::engine::DynamicEngine.

◆ update()

fourdst::composition::Composition PyDynamicEngine::update ( const gridfire::NetIn netIn)
overridevirtual

Update the internal state of the engine.

Parameters
netInA struct containing the current network input, such as temperature, density, and composition.

This method is intended to be implemented by derived classes to update their internal state based on the provided network conditions. For example, an adaptive engine might use this to re-evaluate which reactions and species are active. For other engines that do not support manually updating, this method might do nothing.

Usage Example:
NetIn input = { ... };
myEngine.update(input);
Postcondition
The internal state of the engine is updated to reflect the new conditions.

Implements gridfire::engine::DynamicEngine.

Member Data Documentation

◆ m_species_cache

std::vector<fourdst::atomic::Species> PyDynamicEngine::m_species_cache
mutableprivate

The documentation for this class was generated from the following files: