Struct ode_solvers::dop_shared::SolverResult
source · pub struct SolverResult<T, V>(/* private fields */);
Expand description
A struct that holds the result of a solver/stepper run
Implementations§
source§impl<T, V> SolverResult<T, V>
impl<T, V> SolverResult<T, V>
pub fn new(x: Vec<T>, y: Vec<V>) -> Self
pub fn with_capacity(n: usize) -> Self
pub fn push(&mut self, x: T, y: V)
sourcepub fn append(&mut self, other: SolverResult<T, V>)
pub fn append(&mut self, other: SolverResult<T, V>)
Examples found in repository?
examples/bouncing_ball.rs (line 58)
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
fn main() {
// Initial state: At 10m with zero velocity
let mut y0 = State::new(10.0, 0., 0.);
let mut num_bounces = 0;
let mut combined_solver_results = Result::default();
while num_bounces < MAX_BOUNCES && y0[0] >= 0.001 {
// Create the structure containing the ODEs.
let system = BouncingBall;
// Create a stepper and run the integration.
// Use comments to see differences with Dopri
//let mut stepper = Dopri5::new(system, 0., 10.0, 0.01, y0, 1.0e-2, 1.0e-6);
let mut stepper = Rk4::new(system, 0f32, y0, 10f32, 0.01f32);
let res = stepper.integrate();
// Handle result.
match res {
Ok(stats) => println!("{}", stats),
Err(e) => println!("An error occured: {}", e),
}
num_bounces = num_bounces + 1;
// solout may not be called and therefore end not "smooth" when observing dense values with dopri5 or dop853
// Therefore we seach for the point where the results turn zero
let (_, y_out) = stepper.results().get();
let f = y_out.iter().find(|y| y[0] <= 0.);
if f.is_none() {
// that should not happen...
break;
}
let last_state = f.unwrap();
println!("Last state: {:?}", last_state);
y0[0] = last_state[0].abs();
y0[1] = -1. * last_state[1] * BOUNCE;
// beware in the case of dopri5 or dop853 the results contain a lot of invalid data with y[0] < 0
combined_solver_results.append(stepper.into());
}
let path = Path::new("./outputs/bouncing_ball.dat");
save(
combined_solver_results.get().0,
combined_solver_results.get().1,
path,
);
}
sourcepub fn get(&self) -> (&Vec<T>, &Vec<V>)
pub fn get(&self) -> (&Vec<T>, &Vec<V>)
Returns a pair that contains references to the internal vectors
Examples found in repository?
examples/bouncing_ball.rs (line 44)
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
fn main() {
// Initial state: At 10m with zero velocity
let mut y0 = State::new(10.0, 0., 0.);
let mut num_bounces = 0;
let mut combined_solver_results = Result::default();
while num_bounces < MAX_BOUNCES && y0[0] >= 0.001 {
// Create the structure containing the ODEs.
let system = BouncingBall;
// Create a stepper and run the integration.
// Use comments to see differences with Dopri
//let mut stepper = Dopri5::new(system, 0., 10.0, 0.01, y0, 1.0e-2, 1.0e-6);
let mut stepper = Rk4::new(system, 0f32, y0, 10f32, 0.01f32);
let res = stepper.integrate();
// Handle result.
match res {
Ok(stats) => println!("{}", stats),
Err(e) => println!("An error occured: {}", e),
}
num_bounces = num_bounces + 1;
// solout may not be called and therefore end not "smooth" when observing dense values with dopri5 or dop853
// Therefore we seach for the point where the results turn zero
let (_, y_out) = stepper.results().get();
let f = y_out.iter().find(|y| y[0] <= 0.);
if f.is_none() {
// that should not happen...
break;
}
let last_state = f.unwrap();
println!("Last state: {:?}", last_state);
y0[0] = last_state[0].abs();
y0[1] = -1. * last_state[1] * BOUNCE;
// beware in the case of dopri5 or dop853 the results contain a lot of invalid data with y[0] < 0
combined_solver_results.append(stepper.into());
}
let path = Path::new("./outputs/bouncing_ball.dat");
save(
combined_solver_results.get().0,
combined_solver_results.get().1,
path,
);
}
Trait Implementations§
source§impl<T: Clone, V: Clone> Clone for SolverResult<T, V>
impl<T: Clone, V: Clone> Clone for SolverResult<T, V>
source§fn clone(&self) -> SolverResult<T, V>
fn clone(&self) -> SolverResult<T, V>
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresource§impl<T, V> Default for SolverResult<T, V>
impl<T, V> Default for SolverResult<T, V>
default implementation starts with empty vectors for x and y
source§impl<T, D: Dim, F> Into<SolverResult<T, Matrix<T, D, Const<1>, <DefaultAllocator as Allocator<T, D>>::Buffer>>> for Dop853<T, OVector<T, D>, F>
impl<T, D: Dim, F> Into<SolverResult<T, Matrix<T, D, Const<1>, <DefaultAllocator as Allocator<T, D>>::Buffer>>> for Dop853<T, OVector<T, D>, F>
source§fn into(self) -> SolverResult<T, OVector<T, D>>
fn into(self) -> SolverResult<T, OVector<T, D>>
Converts this type into the (usually inferred) input type.
source§impl<T, D: Dim, F> Into<SolverResult<T, Matrix<T, D, Const<1>, <DefaultAllocator as Allocator<T, D>>::Buffer>>> for Dopri5<T, OVector<T, D>, F>
impl<T, D: Dim, F> Into<SolverResult<T, Matrix<T, D, Const<1>, <DefaultAllocator as Allocator<T, D>>::Buffer>>> for Dopri5<T, OVector<T, D>, F>
source§fn into(self) -> SolverResult<T, OVector<T, D>>
fn into(self) -> SolverResult<T, OVector<T, D>>
Converts this type into the (usually inferred) input type.
Auto Trait Implementations§
impl<T, V> RefUnwindSafe for SolverResult<T, V>where
T: RefUnwindSafe,
V: RefUnwindSafe,
impl<T, V> Send for SolverResult<T, V>
impl<T, V> Sync for SolverResult<T, V>
impl<T, V> Unpin for SolverResult<T, V>
impl<T, V> UnwindSafe for SolverResult<T, V>where
T: UnwindSafe,
V: 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
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.