pub struct Simulation { /* private fields */ }Expand description
A multi-scale simulation orchestrating a set of SubModels.
The orchestrator drives all sub-models forward to a shared target time with
adaptive sub-stepping: each sub-step is the largest dt that advances no
model past the target and exceeds no model’s max_step. After every
sub-step, all registered Couplings fire (writing cross-scale inputs),
so models of differing time scales stay coupled without overshooting.
Implementations§
Source§impl Simulation
impl Simulation
Sourcepub fn add_model(
&mut self,
model: impl SubModel + 'static,
) -> Result<(), SimError>
pub fn add_model( &mut self, model: impl SubModel + 'static, ) -> Result<(), SimError>
Register a sub-model. Returns an error if the id is already taken.
§Errors
Returns SimError::DuplicateModel if a model with the same id is
already registered.
Sourcepub fn add_coupling(&mut self, coupling: Coupling)
pub fn add_coupling(&mut self, coupling: Coupling)
Register a cross-scale Coupling. The source and target models must
already be registered (or will be — couplings are applied by id at
step_until time, so order does not matter).
Sourcepub fn global_time(&self) -> f64
pub fn global_time(&self) -> f64
Current global simulation time (the minimum model time, i.e. how far all models have been driven together).
Sourcepub fn step_until(&mut self, target: f64) -> Result<(), SimError>
pub fn step_until(&mut self, target: f64) -> Result<(), SimError>
Advance all sub-models together until the global time reaches target.
Sub-steps are chosen so that no model overshoots target and no model
exceeds its max_step. After each sub-step every coupling is applied.
§Errors
Returns SimError::NonAdvancingStep if target <= global_time, or
propagates any error returned by a sub-model’s advance/restore_state
or by a coupling (e.g. SimError::UnknownModel).
§Panics
Panics if an internally registered model is missing from the registry (a logic invariant; should never happen in practice).
Sourcepub fn snapshot(&self) -> Checkpoint
pub fn snapshot(&self) -> Checkpoint
Capture a Checkpoint of the current global time and every model’s
state and internal time.
§Panics
Panics if an internally registered model is missing from the registry (a logic invariant; should never happen in practice).
Sourcepub fn restore(&mut self, checkpoint: &Checkpoint) -> Result<(), SimError>
pub fn restore(&mut self, checkpoint: &Checkpoint) -> Result<(), SimError>
Restore every model (and the global clock) from a Checkpoint. Models
present in the checkpoint but not in the simulation are ignored; models
in the simulation but missing from the checkpoint keep their current
state.
§Errors
Returns SimError::UnknownModel if a model id present in the
checkpoint is not registered in the simulation, or propagates any error
from the sub-model’s restore_state (e.g. a state-length mismatch).