1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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
use std::fmt;
use thiserror::Error;
pub trait System<V> {
fn system(&self, x: f64, y: &V, dy: &mut V);
fn solout(&mut self, _x: f64, _y: &V, _dy: &V) -> bool {
false
}
}
#[derive(PartialEq, Eq)]
pub enum OutputType {
Dense,
Sparse,
}
#[derive(Debug, Error)]
pub enum IntegrationError {
#[error("Stopped at x = {x}. Need more than {n_step} steps.")]
MaxNumStepReached { x: f64, n_step: u32 },
#[error("Stopped at x = {x}. Step size underflow.")]
StepSizeUnderflow { x: f64 },
#[error("The problem seems to become stiff at x = {x}.")]
StiffnessDetected { x: f64 },
}
#[derive(Clone, Copy, Debug)]
pub struct Stats {
pub num_eval: u32,
pub accepted_steps: u32,
pub rejected_steps: u32,
}
impl Stats {
pub(crate) fn new() -> Stats {
Stats {
num_eval: 0,
accepted_steps: 0,
rejected_steps: 0,
}
}
#[deprecated(since = "0.2.0", note = "Use std::fmt::Display instead")]
pub fn print(&self) {
println!("{}", self);
}
}
impl fmt::Display for Stats {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
writeln!(f, "Number of function evaluations: {}", self.num_eval)?;
writeln!(f, "Number of accepted steps: {}", self.accepted_steps)?;
write!(f, "Number of rejected steps: {}", self.rejected_steps)
}
}