Skip to main content

Simulation

Struct Simulation 

Source
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

Source

pub fn new() -> Self

Create an empty simulation at global time 0.0.

Source

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.

Source

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).

Source

pub fn model(&self, id: &str) -> Option<&dyn SubModel>

Borrow a registered model by id.

Source

pub fn global_time(&self) -> f64

Current global simulation time (the minimum model time, i.e. how far all models have been driven together).

Source

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).

Source

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).

Source

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).

Trait Implementations§

Source§

impl Default for Simulation

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.