C++ Module: flatStochasticWorkspace

FlatStochasticWorkspace holds stage data used by several native stochastic Runge–Kutta families. It borrows finalized object, noise-binding, and noise-slot descriptors from the integrator. Those descriptors must outlive the bound workspace.

bind() allocates the requested drift columns, diffusion columns, combination buffers, and scratch vectors before committing the borrowed references. reset() releases both storage and references. Neither operation belongs in a stage loop.

Drift rows follow derivative-buffer order. Diffusion rows are packed by global noise source and contain only registered tangents. Each scratch vector has one entry per global source. Capture methods copy live values into stage columns; combination methods write weighted sums into reusable buffers without resizing. Methods that write one diffusion slot leave the other slots unchanged, so the recurrence must populate every slot it later reads.

See Dynamics state and integrator architecture for how this workspace fits between noise topology, candidate assembly, and concrete stochastic recurrences.


Reusable drift and packed-diffusion stages for stochastic methods.

class FlatStochasticWorkspace
#include <flatStochasticWorkspace.h>

Stage matrices and reusable combinations for stochastic RK recurrences.

Drift columns use concatenated derivative-buffer order. Diffusion columns use packed global-slot order and contain only registered tangents. Scratch vectors have one entry per global source. bind() allocates all storage before committing borrowed descriptor references; those descriptors must remain alive and unchanged until reset(). Numerical methods choose the stage counts and populate each stage before reading it. Capture/combination calls do not allocate or resize storage.

Public Functions

inline bool isBound() const noexcept

Report whether stage storage and borrowed topology were committed.

void bind(const std::vector<StochasticObjectDescriptor> &objects, const std::vector<StochasticNoiseBinding> &bindings, const std::vector<StochasticNoiseSlot> &slots, size_t driftStageCount, size_t diffusionStageCount, size_t scratchVectorCount)

Allocate method storage against a finalized stochastic binding.

Note

Calling bind() on an already bound workspace leaves it unchanged.

Parameters:
  • objects – Object buffers in integration order; borrowed until reset().

  • bindings – Packed diffusion endpoints; borrowed until reset().

  • slots – Global noise ranges; borrowed until reset().

  • driftStageCount – Number of derivative-stage columns.

  • diffusionStageCount – Number of diffusion-stage columns.

  • scratchVectorCount – Number of per-source scratch vectors.

void reset() noexcept

Release stage storage and forget borrowed topology without throwing.

inline const Eigen::VectorXd &drift() const noexcept

Borrow the latest weighted drift combination.

inline const Eigen::VectorXd &diffusions() const noexcept

Borrow packed combinations; uncomputed slots are unspecified.

inline Eigen::VectorXd &vector(size_t index)

Borrow a method scratch vector indexed by global noise source.

inline const Eigen::VectorXd &vector(size_t index) const

Borrow a read-only method scratch vector.

inline void captureDrift(size_t stage)

Copy live derivatives into one stage column.

inline void captureAllDiffusions(size_t stage)

Capture every global source into one diffusion-stage column.

inline void captureDiffusion(size_t slotIndex, size_t stage)

Capture only the tangents belonging to one global source.

inline void copyDiffusion(size_t slotIndex, size_t destination, size_t source)

Copy one source’s tangent block between stage columns.

template<size_t count>
inline void writeDrift(const std::array<double, count> &factors, size_t length, size_t firstStage = 0)

Combine length populated drift stages from firstStage; length must be positive.

template<size_t count>
inline void writeDiffusion(size_t slotIndex, const std::array<double, count> &factors, size_t length, size_t firstStage = 0)

Combine one source’s populated stages; other source blocks remain unchanged.

inline void writeDiffusionStage(size_t slotIndex, size_t stage)

Copy one source’s stage block into the combined diffusion buffer.

Private Members

bool bound = false

True when buffers and descriptor references are ready.

const std::vector<StochasticObjectDescriptor> *objects = nullptr

Borrowed object buffers.

const std::vector<StochasticNoiseBinding> *bindings = nullptr

Borrowed packed endpoints.

const std::vector<StochasticNoiseSlot> *slots = nullptr

Borrowed global-source ranges.

Eigen::MatrixXd driftStages

Derivative scalars by drift stage; each column is contiguous.

Eigen::MatrixXd diffusionStages

Packed tangent scalars by diffusion stage.

Eigen::VectorXd combinedDrift

Reusable weighted sum of drift columns.

Eigen::VectorXd combinedDiffusion

Weighted sums, written one global slot at a time.

std::vector<Eigen::VectorXd> vectors

Method scratch, with one entry per global source.