Skip to main content

OdeProblem

Struct OdeProblem 

Source
pub struct OdeProblem { /* private fields */ }
Expand description

A built ODE problem, ready to be integrated to a target time with one of the available solvers (see Method and OdeProblem::solve).

Implementations§

Source§

impl OdeProblem

Source

pub fn new<F>(rhs: F, y0: Vec<f64>, t0: f64) -> Result<Self, OdeError>
where F: Fn(f64, &[f64], &mut [f64]) + 'static,

Build a problem with default tolerances (rtol = atol = 1e-6).

§Errors

Returns OdeError::Invalid if y0 is empty (the default tolerances are always strictly positive, so they never trigger an error here).

Source

pub fn from_rhs<R: RhsCallable + 'static>( rhs: R, y0: Vec<f64>, t0: f64, ) -> Result<Self, OdeError>

Build a problem from any RhsCallable (e.g. a JitRhs, with the cranelift-jit feature).

§Errors

Returns OdeError::Invalid if y0 is empty.

Source

pub fn nstates(&self) -> usize

Number of state variables.

Source

pub fn t0(&self) -> f64

Initial time of the problem (the t0 passed at construction).

Source

pub fn y0(&self) -> &[f64]

Initial state of the problem (the y0 passed at construction).

Source

pub fn respawn(&self, y0: Vec<f64>, t0: f64) -> Result<Self, OdeError>

Produce a fresh problem that shares this problem’s RHS and tolerances but starts from a new initial state y0 at time t0. This is used by multi-scale orchestration (see tpt-sci-sim-core) to step an ODE forward incrementally from its current state rather than re-integrating from the original t0 each time.

§Errors

Returns OdeError::Invalid if y0 is empty (the shared tolerances are strictly positive, so they never trigger an error here).

Source§

impl OdeProblem

Source

pub fn solve(&self, method: Method, t_final: f64) -> Result<Vec<f64>, OdeError>

Integrate the problem from its initial time to t_final and return the state vector at t_final, using the requested method.

§Errors

Returns OdeError if the integration fails (non-convergent Newton step, collapsed step size, or step budget exceeded).

Source

pub fn solve_events( &self, method: Method, t_final: f64, events: &[Event], ) -> Result<EventSolution, OdeError>

Integrate to t_final while watching the given Events.

Every sign change of an event function is reported in EventSolution::hits. Each crossing is bracketed by the accepted step and located by bisection on that step’s cubic-Hermite dense output, so its accuracy is that of the interpolant (roughly O(h⁴) per step), not round-off. If a terminal event fires, integration stops at its crossing and EventSolution::t_end is that time; otherwise t_end is t_final.

§Errors

Returns OdeError if the integration fails (see OdeProblem::solve).

§Examples

A bouncing ball that hits the floor at t = √(2h/g):

use tpt_sci_ode::{Method, OdeProblem};
use tpt_sci_ode::events::{Direction, Event};

// State [height, velocity]; g = 9.81.
let prob = OdeProblem::new(
    |_t, y, dy| {
        dy[0] = y[1];
        dy[1] = -9.81;
    },
    vec![10.0, 0.0],
    0.0,
)
.unwrap();
let floor = Event::new(|_t, y| y[0])
    .direction(Direction::Falling)
    .terminal();
let sol = prob.solve_events(Method::Tsit45, 10.0, &[floor]).unwrap();
let expected = (2.0 * 10.0 / 9.81f64).sqrt();
assert!((sol.t_end - expected).abs() < 1e-6);
Source

pub fn solve_dense( &self, method: Method, t_eval: &[f64], ) -> Result<Vec<Vec<f64>>, OdeError>

Integrate at each time in t_eval (each strictly increasing and beyond t0) and return one state vector per evaluation time.

The integrator lands exactly on each t_eval point and interpolates with a cubic Hermite polynomial between accepted steps, so output is exact at the requested times.

§Errors

Returns OdeError if the integration fails (see OdeProblem::solve).

§Panics

Panics if t_eval is non-empty but its last element cannot be read (only reachable if t_eval is mutated concurrently); for a normal non-empty slice this is unreachable.

Source§

impl OdeProblem

Source

pub fn solve_trajectory( &self, method: Method, t_eval: &[f64], names: &[&str], ) -> Result<Trajectory, OdeError>

Integrate and return the dense output as a named Trajectory.

names must have one entry per state variable. Output is produced at each point of t_eval (see OdeProblem::solve_dense).

§Errors

Returns OdeError::Invalid if names does not match the state size, or any error from the integration itself.

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<T> ByRef<T> for T

Source§

fn by_ref(&self) -> &T

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> DistributionExt for T
where T: ?Sized,

Source§

fn rand<T>(&self, rng: &mut (impl Rng + ?Sized)) -> T
where Self: Distribution<T>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Imply<T> for U
where T: ?Sized, U: ?Sized,

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V