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>

source

pub fn new(x: Vec<T>, y: Vec<V>) -> Self

source

pub fn with_capacity(n: usize) -> Self

source

pub fn push(&mut self, x: T, y: V)

source

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,
    );
}
source

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>

source§

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)

Performs copy-assignment from source. Read more
source§

impl<T: Debug, V: Debug> Debug for SolverResult<T, V>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<T, V> Default for SolverResult<T, V>

default implementation starts with empty vectors for x and y

source§

fn default() -> Self

Returns the “default value” for a type. Read more
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>
where T: FloatNumber, F: System<T, OVector<T, D>>, DefaultAllocator: Allocator<T, D>,

source§

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>
where T: FloatNumber, F: System<T, OVector<T, D>>, DefaultAllocator: Allocator<T, D>,

source§

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 Rk4<T, OVector<T, D>, F>
where T: FloatNumber, F: System<T, OVector<T, D>>, DefaultAllocator: Allocator<T, D>,

source§

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>

§

impl<T, V> Send for SolverResult<T, V>
where T: Send, V: Send,

§

impl<T, V> Sync for SolverResult<T, V>
where T: Sync, V: Sync,

§

impl<T, V> Unpin for SolverResult<T, V>
where T: Unpin, V: Unpin,

§

impl<T, V> UnwindSafe for SolverResult<T, V>
where T: UnwindSafe, V: 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> Same for T

§

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> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

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>,

§

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.