Struct Solver

Source
pub struct Solver<T>
where T: Number,
{ /* private fields */ }
Expand description

§Default values

When creating a new Solver with Solver::new(), this is the default configuration:

  • method: Method::RK4

  • weights for the intermediate points:

    • Method::RK2: vec![1, 1],
    • Method::RK4: vec![1, 2, 2, 1],

(Note that each internal value of the vector will be converted to T via T::from_str_radix().)

§Example

use ode::{Method, Solver};

let time_interval: [f32; 2] = [0., 100.];
let ini_cond: Vec<f32> = vec![0.];

// simple config
Solver::new(&time_interval, &ini_cond)
    .method(Method::RK4)
    .solve(|t: &f32, _: &Vec<f32>| vec![2.*t]);

// complex config
let mut s = Solver::new(&time_interval, &ini_cond);
s.method(Method::RK4);

// run the solver
let (times, pos) = s.solve(|t: &f32, _: &Vec<f32>| vec![2.*t]);

Implementations§

Source§

impl<T> Solver<T>
where T: Number,

Source

pub fn new(time_interval: &[T; 2], initial_conditions: &Vec<T>) -> Solver<T>

Start building a new Solver.

Default values are:

  • method: Method::RK4,
  • intermidiate point weights: vec![1, 2, 2, 1]
  • step size: 10e-3

(Note that these values will be converted to T via T::from_str_radix().)

Source

pub fn method(&mut self, new_method: Method) -> &mut Solver<T>

Select the desired algorithm to solve the givem problem, also updating the weights based on default values. To manually alter these values, please check Self::change_weight().

Source

pub fn weights(&mut self, new_weights: Vec<T>) -> &mut Solver<T>

Modify the default weighting applyed to each intermidiate point.

Source

pub fn validate(&self) -> bool

Validates the data passed to the solver.

This is tipically called by run() before attempting to solve the passed function, but was made public so the data can be verified and corrected without a panic.

Data checks are:

  • Self::weights.len() should match the selected method:

    • Method::RK2 requires 2 weights;
    • Method::RK4 requires 4 weights;
Source

pub fn solve<F>(&self, function: F) -> (Vec<T>, Vec<Vec<T>>)
where F: Function<T>,

Check and run the solver, returning the results of the calculation.

Notice that, before the solver actually runs, it validates its data by calling Self::validate() within an assert!. See that function for more details.

Auto Trait Implementations§

§

impl<T> Freeze for Solver<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for Solver<T>
where T: RefUnwindSafe,

§

impl<T> Send for Solver<T>
where T: Send,

§

impl<T> Sync for Solver<T>
where T: Sync,

§

impl<T> Unpin for Solver<T>
where T: Unpin,

§

impl<T> UnwindSafe for Solver<T>
where T: 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.