Struct Euler

Source
pub struct Euler<'a, N, D, T, F>
where N: ComplexField + Copy, D: Dimension, T: Clone, F: Derivative<N, D, T> + 'a, DefaultAllocator: Allocator<N, D>,
{ /* private fields */ }
Expand description

Euler solver for an IVP.

Solves an initial value problem using Euler’s method.

§Examples

use std::error::Error;
use bacon_sci::{BSVector, ivp::{Euler, IVPSolver, IVPError}};
fn derivative(_t: f64, state: &[f64], _p: &mut ()) -> Result<BSVector<f64, 1>, Box<dyn Error>> {
    Ok(BSVector::<f64, 1>::from_column_slice(state))
}

fn example() -> Result<(), IVPError> {
    let solver = Euler::new()?
        .with_maximum_dt(0.001)?
        .with_initial_conditions_slice(&[1.0])?
        .with_initial_time(0.0)?
        .with_ending_time(1.0)?
        .with_derivative(derivative)
        .solve(())?;
    let path = solver.collect_vec()?;

    for (time, state) in &path {
        assert!((time.exp() - state.column(0)[0]).abs() <= 0.001);
    }
    Ok(())
}

Trait Implementations§

Source§

impl<'a, N, D, T, F> IVPSolver<'a, D> for Euler<'a, N, D, T, F>
where N: ComplexField + Copy, D: Dimension, T: Clone, F: Derivative<N, D, T> + 'a, DefaultAllocator: Allocator<N, D>,

Source§

fn with_tolerance(self, _tol: Self::RealField) -> Result<Self, Self::Error>

Unused for Euler, call is a no-op

Source§

fn with_maximum_dt(self, max: Self::RealField) -> Result<Self, Self::Error>

If there is not time step already, set, then set the time step. If there is, set the time step to the average of that and the max passed in.

Source§

fn with_minimum_dt(self, min: Self::RealField) -> Result<Self, Self::Error>

If there is not time step already, set, then set the time step. If there is, set the time step to the average of that and the max passed in.

Source§

type Error = IVPError

Error type. IVPError must be able to convert to the error type.
Source§

type Field = N

The field, complex or real, that the solver is operating on.
Source§

type RealField = <N as ComplexField>::RealField

The real field associated with the solver’s Field.
Source§

type Derivative = F

The type signature of the derivative function to use
Source§

type UserData = T

Arbitrary data provided by the user for the derivative function
Source§

type Solver = EulerSolver<'a, N, D, T, F>

The type that actually does the solving.
Source§

fn new() -> Result<Self, Self::Error>

Create the solver. Will fail for dynamically sized solvers
Source§

fn new_dyn(size: usize) -> Result<Self, Self::Error>

Create the solver with a run-time dimension. Will fail for statically sized solvers
Source§

fn dim(&self) -> D

Gets the dimension of the solver
Source§

fn with_initial_time( self, initial: Self::RealField, ) -> Result<Self, Self::Error>

Source§

fn with_ending_time(self, ending: Self::RealField) -> Result<Self, Self::Error>

Source§

fn with_initial_conditions( self, start: BVector<Self::Field, D>, ) -> Result<Self, Self::Error>

The initial conditions of the problem, in a BVector. Should reset any previous values.
Source§

fn with_derivative(self, derivative: Self::Derivative) -> Self

Sets the derivative function to use during the solve
Source§

fn solve( self, data: Self::UserData, ) -> Result<IVPIterator<D, Self::Solver>, Self::Error>

Turns the solver into an iterator over the solution, using IVPStep::step
Source§

fn with_initial_conditions_slice( self, start: &[Self::Field], ) -> Result<Self, Self::Error>

The initial conditions of the problem, should reset any previous values.

Auto Trait Implementations§

§

impl<'a, N, D, T, F> !Freeze for Euler<'a, N, D, T, F>

§

impl<'a, N, D, T, F> !RefUnwindSafe for Euler<'a, N, D, T, F>

§

impl<'a, N, D, T, F> !Send for Euler<'a, N, D, T, F>

§

impl<'a, N, D, T, F> !Sync for Euler<'a, N, D, T, F>

§

impl<'a, N, D, T, F> !Unpin for Euler<'a, N, D, T, F>

§

impl<'a, N, D, T, F> !UnwindSafe for Euler<'a, N, D, T, F>

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> 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 = 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.