GridFire v0.7.6rc4.0
General Purpose Nuclear Network
Loading...
Searching...
No Matches
gridfire::engine::scratch::GraphEngineScratchPad Struct Referencefinal

Scratchpad for storing CppAD automatic differentiation state for GraphEngine. More...

#include <engine_graph_scratchpad.h>

Inheritance diagram for gridfire::engine::scratch::GraphEngineScratchPad:
[legend]
Collaboration diagram for gridfire::engine::scratch::GraphEngineScratchPad:
[legend]

Public Types

enum class  ADFunRegistrationResult : uint8_t { SUCCESS , ALREADY_REGISTERED }
 Result codes for ADFun registration operations. More...
 

Public Member Functions

bool is_initialized () const override
 Check whether the scratchpad has been initialized.
 
void initialize (const GraphEngine &engine)
 Initialize the scratchpad from a GraphEngine.
 
std::unique_ptr< AbstractScratchPadclone () const override
 Create a deep copy of this scratchpad.
 
- Public Member Functions inherited from gridfire::engine::scratch::AbstractScratchPad
virtual ~AbstractScratchPad ()=default
 Virtual destructor for proper cleanup of derived classes.
 

Public Attributes

std::optional< CppAD::ADFun< double > > rhsADFun
 CppAD function object for evaluating the ODE right-hand side.
 
CppAD::sparse_jac_work jac_work
 Work structure for sparse Jacobian calculations.
 
std::vector< double > local_abundance_cache
 Local cache of abundance values for efficient RHS evaluation.
 
std::unordered_map< size_t, StepDerivatives< double > > stepDerivativesCache
 Cache of step derivatives indexed by timestep identifier.
 
std::unordered_map< size_t, CppAD::sparse_rcv< std::vector< size_t >, std::vector< double > > > jacobianSubsetCache
 Cache of sparse Jacobian subsets indexed by timestep identifier.
 
std::unordered_map< size_t, CppAD::sparse_jac_work > jacWorkCache
 Cache of Jacobian work structures indexed by timestep identifier.
 
std::optional< StepDerivatives< double > > most_recent_rhs_calculation
 The most recent RHS calculation result for warm-starting.
 
bool has_initialized = false
 Flag indicating whether the scratchpad has been initialized.
 

Static Public Attributes

static constexpr auto ID = ScratchPadType::GRAPH_ENGINE_SCRATCHPAD
 Unique identifier for this scratchpad type.
 

Detailed Description

Scratchpad for storing CppAD automatic differentiation state for GraphEngine.

GraphEngineScratchPad provides thread-local storage for all CppAD-related objects needed during ODE integration with the GraphEngine. This includes the ADFun object for evaluating the right-hand side of the ODE and computing Jacobians, as well as various caches to improve performance.

Thread Safety
This class is not thread-safe. CppAD ADFun objects maintain internal state that is modified during Forward and Reverse mode operations. Each thread must have its own scratchpad instance. Use clone() to create independent copies for parallel execution.
Note
When cloning, if the rhsADFun has not been initialized, the clone will also be uninitialized and has_initialized will be false.

Member Enumeration Documentation

◆ ADFunRegistrationResult

Result codes for ADFun registration operations.

Enumerator
SUCCESS 

Registration completed successfully.

ALREADY_REGISTERED 

ADFun was already registered; no action taken.

Member Function Documentation

◆ clone()

std::unique_ptr< AbstractScratchPad > gridfire::engine::scratch::GraphEngineScratchPad::clone ( ) const
inlinenodiscardoverridevirtual

Create a deep copy of this scratchpad.

Creates an independent copy of all internal state, including the CppAD ADFun object and all caches. The clone can be safely used in a separate thread without affecting the original.

Returns
A unique pointer to the cloned scratchpad.
Note
If rhsADFun is not initialized, the clone will also be uninitialized (has_initialized = false).
Examples
scratch.initialize(engine);
// Create independent copies for parallel workers
std::vector<std::unique_ptr<AbstractScratchPad>> worker_pads;
for (int i = 0; i < num_threads; ++i) {
worker_pads.push_back(scratch.clone());
}
Scratchpad memory management for computational engines.
Definition blob.h:69
Definition dynamic_engine_diagnostics.h:39
Scratchpad for storing CppAD automatic differentiation state for GraphEngine.
Definition engine_graph_scratchpad.h:83

Implements gridfire::engine::scratch::AbstractScratchPad.

◆ initialize()

void gridfire::engine::scratch::GraphEngineScratchPad::initialize ( const GraphEngine & engine)
inline

Initialize the scratchpad from a GraphEngine.

Copies the authoritative ADFun from the engine and clears all caches. This method is idempotent; calling it multiple times has no effect after the first successful initialization.

Parameters
engineThe GraphEngine to initialize from.
Examples
GraphEngine engine = create_engine();
scratch.initialize(engine);
// Now safe to use for thread-local computations
auto& adfun = scratch.rhsADFun.value();
A reaction network engine that uses a graph-based representation.
Definition engine_graph.h:100

◆ is_initialized()

bool gridfire::engine::scratch::GraphEngineScratchPad::is_initialized ( ) const
inlinenodiscardoverridevirtual

Check whether the scratchpad has been initialized.

Returns
true if initialized with a valid ADFun, false otherwise.

Implements gridfire::engine::scratch::AbstractScratchPad.

Member Data Documentation

◆ has_initialized

bool gridfire::engine::scratch::GraphEngineScratchPad::has_initialized = false

Flag indicating whether the scratchpad has been initialized.

◆ ID

auto gridfire::engine::scratch::GraphEngineScratchPad::ID = ScratchPadType::GRAPH_ENGINE_SCRATCHPAD
staticconstexpr

Unique identifier for this scratchpad type.

◆ jac_work

CppAD::sparse_jac_work gridfire::engine::scratch::GraphEngineScratchPad::jac_work

Work structure for sparse Jacobian calculations.

Reused across Jacobian evaluations to avoid reallocation.

◆ jacobianSubsetCache

std::unordered_map<size_t, CppAD::sparse_rcv<std::vector<size_t>, std::vector<double> > > gridfire::engine::scratch::GraphEngineScratchPad::jacobianSubsetCache

Cache of sparse Jacobian subsets indexed by timestep identifier.

◆ jacWorkCache

std::unordered_map<size_t, CppAD::sparse_jac_work> gridfire::engine::scratch::GraphEngineScratchPad::jacWorkCache

Cache of Jacobian work structures indexed by timestep identifier.

◆ local_abundance_cache

std::vector<double> gridfire::engine::scratch::GraphEngineScratchPad::local_abundance_cache

Local cache of abundance values for efficient RHS evaluation.

◆ most_recent_rhs_calculation

std::optional<StepDerivatives<double> > gridfire::engine::scratch::GraphEngineScratchPad::most_recent_rhs_calculation

The most recent RHS calculation result for warm-starting.

◆ rhsADFun

std::optional<CppAD::ADFun<double> > gridfire::engine::scratch::GraphEngineScratchPad::rhsADFun

CppAD function object for evaluating the ODE right-hand side.

Contains the computational graph for automatic differentiation.

◆ stepDerivativesCache

std::unordered_map<size_t, StepDerivatives<double> > gridfire::engine::scratch::GraphEngineScratchPad::stepDerivativesCache

Cache of step derivatives indexed by timestep identifier.


The documentation for this struct was generated from the following file: