1use crate::{Method, Stats};
2
3pub(crate) struct Workspace {
5 pub(crate) stats: Stats,
7
8 pub(crate) follows_reject_step: bool,
10
11 pub(crate) iterations_diverging: bool,
13
14 pub(crate) h_multiplier_diverging: f64,
16
17 pub(crate) h_prev: f64,
19
20 pub(crate) h_new: f64,
22
23 pub(crate) rel_error_prev: f64,
25
26 pub(crate) rel_error: f64,
28
29 pub(crate) stiff_x_first_detect: f64,
31
32 pub(crate) stiff_h_times_rho: f64,
34
35 pub(crate) stiff_n_detection_no: usize,
37
38 pub(crate) stiff_n_detection_yes: usize,
40
41 pub(crate) stiff_detected: bool,
43}
44
45impl Workspace {
46 pub(crate) fn new(method: Method) -> Self {
48 Workspace {
49 stats: Stats::new(method),
50 follows_reject_step: false,
51 iterations_diverging: false,
52 h_multiplier_diverging: 1.0,
53 h_prev: 0.0,
54 h_new: 0.0,
55 rel_error_prev: 0.0,
56 rel_error: 0.0,
57 stiff_x_first_detect: f64::MAX,
58 stiff_h_times_rho: 0.0,
59 stiff_n_detection_no: 0,
60 stiff_n_detection_yes: 0,
61 stiff_detected: false,
62 }
63 }
64
65 pub(crate) fn reset(&mut self, h: f64, rel_error_prev_min: f64) {
67 self.stats.reset(h);
68 self.follows_reject_step = false;
69 self.iterations_diverging = false;
70 self.h_multiplier_diverging = 1.0;
71 self.h_prev = h;
72 self.h_new = h;
73 self.rel_error_prev = rel_error_prev_min;
74 self.rel_error = 0.0;
75 self.stiff_x_first_detect = f64::MAX;
76 self.stiff_h_times_rho = 0.0;
77 self.stiff_n_detection_no = 0;
78 self.stiff_n_detection_yes = 0;
79 self.stiff_detected = false;
80 }
81}