SolverNoSensi

Struct SolverNoSensi 

Source
pub struct SolverNoSensi<UserData, F, const N: usize> { /* private fields */ }
Expand description

The ODE solver without sensitivities.

§Type Arguments

  • F is the type of the right-hand side function

  • UserData is the type of the supplementary arguments for the right-hand-side. If unused, should be ().

  • N is the “problem size”, that is the dimension of the state space.

Implementations§

Source§

impl<UserData, F, const N: usize> Solver<UserData, F, N>
where F: Fn(Realtype, &[Realtype; N], &mut [Realtype; N], &UserData) -> RhsResult,

Source

pub fn new( method: LinearMultistepMethod, f: F, t0: Realtype, y0: &[Realtype; N], rtol: Realtype, atol: AbsTolerance<N>, user_data: UserData, ) -> Result<Self>

Create a new solver.

Examples found in repository?
examples/oscillator_no_sensi.rs (lines 11-19)
3fn main() {
4    let y0 = [0., 1.];
5    //define the right-hand-side
6    fn f(_t: Realtype, y: &[Realtype; 2], ydot: &mut [Realtype; 2], k: &Realtype) -> RhsResult {
7        *ydot = [y[1], -y[0] * k];
8        RhsResult::Ok
9    }
10    //initialize the solver
11    let mut solver = SolverNoSensi::new(
12        LinearMultistepMethod::Adams,
13        f,
14        0.,
15        &y0,
16        1e-4,
17        AbsTolerance::scalar(1e-4),
18        1e-2,
19    )
20    .unwrap();
21    //and solve
22    let ts: Vec<_> = (1..100).collect();
23    println!("0,{},{}", y0[0], y0[1]);
24    for &t in &ts {
25        let (_tret, &[x, xdot]) = solver.step(t as _, StepKind::Normal).unwrap();
26        println!("{},{},{}", t, x, xdot);
27    }
28}
Source

pub fn step( &mut self, tout: Realtype, step_kind: StepKind, ) -> Result<(Realtype, &[Realtype; N])>

Takes a step according to step_kind (see StepKind).

Returns a tuple (t_out,&y(t_out)) where t_out is the time reached by the solver as dictated by step_kind, and y(t_out) is an array of the state variables at that time.

Examples found in repository?
examples/oscillator_no_sensi.rs (line 25)
3fn main() {
4    let y0 = [0., 1.];
5    //define the right-hand-side
6    fn f(_t: Realtype, y: &[Realtype; 2], ydot: &mut [Realtype; 2], k: &Realtype) -> RhsResult {
7        *ydot = [y[1], -y[0] * k];
8        RhsResult::Ok
9    }
10    //initialize the solver
11    let mut solver = SolverNoSensi::new(
12        LinearMultistepMethod::Adams,
13        f,
14        0.,
15        &y0,
16        1e-4,
17        AbsTolerance::scalar(1e-4),
18        1e-2,
19    )
20    .unwrap();
21    //and solve
22    let ts: Vec<_> = (1..100).collect();
23    println!("0,{},{}", y0[0], y0[1]);
24    for &t in &ts {
25        let (_tret, &[x, xdot]) = solver.step(t as _, StepKind::Normal).unwrap();
26        println!("{},{},{}", t, x, xdot);
27    }
28}

Trait Implementations§

Source§

impl<UserData, F, const N: usize> Drop for Solver<UserData, F, N>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<UserData, F, const N: usize> Freeze for Solver<UserData, F, N>

§

impl<UserData, F, const N: usize> RefUnwindSafe for Solver<UserData, F, N>
where UserData: RefUnwindSafe, F: RefUnwindSafe,

§

impl<UserData, F, const N: usize> !Send for Solver<UserData, F, N>

§

impl<UserData, F, const N: usize> !Sync for Solver<UserData, F, N>

§

impl<UserData, F, const N: usize> Unpin for Solver<UserData, F, N>

§

impl<UserData, F, const N: usize> UnwindSafe for Solver<UserData, F, N>
where UserData: UnwindSafe, F: UnwindSafe,

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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.