GridFire v0.7.6rc4.0 General Purpose Nuclear Network

Loading...
Searching...
No Matches
Classes | Namespaces
engine_graph_scratchpad.h File Reference

Scratchpad implementation for the GraphEngine using CppAD automatic differentiation. More...

`#include <vector>`
`#include "gridfire/engine/scratchpads/scratchpad_abstract.h"`
`#include "gridfire/engine/scratchpads/types.h"`
`#include "gridfire/engine/engine_graph.h"`
`#include "gridfire/engine/engine_abstract.h"`
`#include "cppad/cppad.hpp"`
`#include <optional>`
Include dependency graph for engine_graph_scratchpad.h:
This graph shows which files directly or indirectly include this file:

## Classes
struct | gridfire::engine::scratch::GraphEngineScratchPad
| Scratchpad for storing CppAD automatic differentiation state for GraphEngine. More...

## Namespaces
namespace | gridfire
namespace | gridfire::engine
namespace | gridfire::engine::scratch
| Scratchpad memory management for computational engines.

## Detailed Description

Scratchpad implementation for the GraphEngine using CppAD automatic differentiation.

This header defines the GraphEngineScratchPad, a concrete implementation of AbstractScratchPad designed for use with the GraphEngine. It provides thread-local storage for CppAD automatic differentiation functions, Jacobian computation work structures, and cached derivatives used during ODE integration.

Purpose
  The GraphEngineScratchPad stores:
  - A local copy of the CppAD ADFun for RHS evaluation
  - Work structures for sparse Jacobian calculations
  - Cached abundance values for efficient reuse
  - Cached step derivatives and Jacobian subsets by timestep
  - The most recent RHS calculation for warm-starting

Examples
  #include "gridfire/engine/scratchpads/engine_graph_scratchpad.h"
  #include "gridfire/engine/engine_graph.h"
  // Create and initialize the scratchpad from a GraphEngine
  gridfire::engine::scratch::GraphEngineScratchPad scratch;
  GraphEngine engine = create_graph_engine();
  scratch.initialize(engine);
  if (scratch.is_initialized()) {
  // Access the local ADFun for thread-safe evaluation
  auto& adfun = scratch.rhsADFun.value();
  // Use cached Jacobian work for efficient sparse computations
  auto& jac_work = scratch.jac_work;
  }
  // Clone for parallel execution
  auto worker_scratch = scratch.clone();
  engine_graph.h
  engine_graph_scratchpad.h
  Scratchpad implementation for the GraphEngine using CppAD automatic differentiation.
  gridfire::engine::scratch::GraphEngineScratchPad
  Scratchpad for storing CppAD automatic differentiation state for GraphEngine.
  Definition engine_graph_scratchpad.h:83
  gridfire::engine::scratch::GraphEngineScratchPad::jac_work
  CppAD::sparse_jac_work jac_work
  Work structure for sparse Jacobian calculations.
  Definition engine_graph_scratchpad.h:98
  gridfire::engine::scratch::GraphEngineScratchPad::clone
  std::unique_ptr< AbstractScratchPad > clone() const override
  Create a deep copy of this scratchpad.
  Definition engine_graph_scratchpad.h:185
  gridfire::engine::scratch::GraphEngineScratchPad::is_initialized
  bool is_initialized() const override
  Check whether the scratchpad has been initialized.
  Definition engine_graph_scratchpad.h:125
  gridfire::engine::scratch::GraphEngineScratchPad::initialize
  void initialize(const GraphEngine &engine)
  Initialize the scratchpad from a GraphEngine.
  Definition engine_graph_scratchpad.h:146
  gridfire::engine::scratch::GraphEngineScratchPad::rhsADFun
  std::optional< CppAD::ADFun< double > > rhsADFun
  CppAD function object for evaluating the ODE right-hand side.
  Definition engine_graph_scratchpad.h:94

Thread Safety
  This class is not thread-safe. Each thread must have its own instance of GraphEngineScratchPad because CppAD ADFun objects maintain internal state that is modified during evaluation. Use clone() to create independent copies for parallel workers, ensuring each thread has its own ADFun instance.

See also
  AbstractScratchPad
  GraphEngine
  CppAD::ADFun