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>,
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>
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>
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>
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 RealField = <N as ComplexField>::RealField
type RealField = <N as ComplexField>::RealField
The real field associated with the solver’s Field.
Source§type Derivative = F
type Derivative = F
The type signature of the derivative function to use
Source§type Solver = EulerSolver<'a, N, D, T, F>
type Solver = EulerSolver<'a, N, D, T, F>
The type that actually does the solving.
Source§fn new() -> Result<Self, Self::Error>
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>
fn new_dyn(size: usize) -> Result<Self, Self::Error>
Create the solver with a run-time dimension.
Will fail for statically sized solvers
fn with_initial_time( self, initial: Self::RealField, ) -> Result<Self, Self::Error>
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>
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
fn with_derivative(self, derivative: Self::Derivative) -> Self
Sets the derivative function to use during the solve
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> 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
Mutably borrows from an owned value. Read more
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>
The inverse inclusion map: attempts to construct
self
from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
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
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
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self
to the equivalent element of its superset.