tpt_sci_sim_core/lib.rs
1//! # tpt-sci-sim-core
2//!
3//! Multi-scale simulation orchestration for the `tpt-science` pillar: the
4//! layer *above* [`tpt_sci_ode`] and [`tpt_sci_grid`] that a "multi-scale
5//! computational platform" (the motivating use case for `tpt-soma` and
6//! `tpt-cerebrum`) actually needs and that neither solver crate provides
7//! alone.
8//!
9//! It provides:
10//!
11//! - **Time-stepping across heterogeneous sub-models.** Each [`SubModel`]
12//! advances on its own internal time scale (`max_step`) while a
13//! [`Simulation`] drives them all forward to a shared target time, taking
14//! the largest sub-step that no model would overshoot.
15//! - **Cross-scale coupling.** A [`Coupling`] maps the state of one model onto
16//! the input buffer of another after every sub-step, so a fast model's
17//! output can drive a slow one (or vice versa).
18//! - **Checkpointing.** [`Simulation::snapshot`] / [`Simulation::restore`]
19//! capture and restore every model's state and the global clock, for
20//! resumable / reproducible runs.
21//!
22//! ## Example
23//!
24//! ```rust
25//! use tpt_sci_sim_core::{OdeSubModel, Simulation, SubModel};
26//!
27//! // A single fast exponential-decay sub-model: dy/dt = -y, y(0) = 1.
28//! let decay = OdeSubModel::new(
29//! "decay",
30//! |_t, y, dydt| dydt[0] = -y[0],
31//! vec![1.0],
32//! 0.0,
33//! );
34//! let mut sim = Simulation::new();
35//! sim.add_model(decay).unwrap();
36//! sim.step_until(1.0).unwrap();
37//! let y = sim.model("decay").unwrap().state()[0];
38//! assert!((y - std::f64::consts::E.recip()).abs() < 1e-3);
39//! ```
40
41pub mod coupling;
42pub mod diffusion_model;
43pub mod error;
44pub mod ode_model;
45pub mod sim;
46pub mod submodel;
47
48pub use coupling::{Coupling, CouplingFn};
49pub use diffusion_model::DiffusionSubModel;
50pub use error::SimError;
51pub use ode_model::OdeSubModel;
52pub use sim::{Checkpoint, Simulation};
53pub use submodel::SubModel;