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
impl OdeProblem
Sourcepub fn new<F>(rhs: F, y0: Vec<f64>, t0: f64) -> Result<Self, OdeError>
pub fn new<F>(rhs: F, y0: Vec<f64>, t0: f64) -> Result<Self, OdeError>
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).
Sourcepub fn from_rhs<R: RhsCallable + 'static>(
rhs: R,
y0: Vec<f64>,
t0: f64,
) -> Result<Self, OdeError>
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.
Sourcepub fn respawn(&self, y0: Vec<f64>, t0: f64) -> Result<Self, OdeError>
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
impl OdeProblem
Sourcepub fn solve_events(
&self,
method: Method,
t_final: f64,
events: &[Event],
) -> Result<EventSolution, OdeError>
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);Sourcepub fn solve_dense(
&self,
method: Method,
t_eval: &[f64],
) -> Result<Vec<Vec<f64>>, OdeError>
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
impl OdeProblem
Sourcepub fn solve_trajectory(
&self,
method: Method,
t_eval: &[f64],
names: &[&str],
) -> Result<Trajectory, OdeError>
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§
impl !RefUnwindSafe for OdeProblem
impl !Send for OdeProblem
impl !Sync for OdeProblem
impl !UnwindSafe for OdeProblem
impl Freeze for OdeProblem
impl Unpin for OdeProblem
impl UnsafeUnpin for OdeProblem
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> DistributionExt for Twhere
T: ?Sized,
impl<T> DistributionExt for Twhere
T: ?Sized,
impl<T, U> Imply<T> for U
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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 moreSource§impl<T> Pointable for T
impl<T> Pointable for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.