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>
impl<UserData, F, const N: usize> Solver<UserData, F, N>
Sourcepub fn new(
method: LinearMultistepMethod,
f: F,
t0: Realtype,
y0: &[Realtype; N],
rtol: Realtype,
atol: AbsTolerance<N>,
user_data: UserData,
) -> Result<Self>
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}
Sourcepub fn step(
&mut self,
tout: Realtype,
step_kind: StepKind,
) -> Result<(Realtype, &[Realtype; N])>
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§
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> 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