differential_equations/methods/apc/
mod.rs1mod apcf4;
4mod apcv4;
5
6use std::marker::PhantomData;
7
8use crate::{
9 status::Status,
10 traits::{Real, State},
11};
12
13pub struct AdamsPredictorCorrector<E, F, T: Real, Y: State<T>, const S: usize> {
14 pub h0: T,
16
17 h: T,
19
20 t: T,
22 y: Y,
23 dydt: Y,
24
25 tf: T,
27
28 t_prev: [T; S],
30 y_prev: [Y; S],
31
32 t_old: T,
34 y_old: Y,
35 dydt_old: Y,
36
37 k: [Y; S],
39
40 evals: usize,
42 steps: usize,
43
44 status: Status<T, Y>,
46
47 pub tol: T,
49 pub h_max: T,
50 pub h_min: T,
51 pub max_steps: usize,
52
53 pub stages: usize,
55
56 family: PhantomData<F>,
58
59 equation: PhantomData<E>,
61}
62
63impl<E, F, T: Real, Y: State<T>, const S: usize> Default
64 for AdamsPredictorCorrector<E, F, T, Y, S>
65{
66 fn default() -> Self {
67 Self {
68 h0: T::zero(),
69 h: T::zero(),
70 t: T::zero(),
71 y: Y::zeros(),
72 dydt: Y::zeros(),
73 t_prev: [T::zero(); S],
74 y_prev: [Y::zeros(); S],
75 t_old: T::zero(),
76 y_old: Y::zeros(),
77 dydt_old: Y::zeros(),
78 k: [Y::zeros(); S],
79 tf: T::zero(),
80 evals: 0,
81 steps: 0,
82 status: Status::Uninitialized,
83 tol: T::from_f64(1.0e-6).unwrap(),
84 h_max: T::infinity(),
85 h_min: T::zero(),
86 max_steps: 10_000,
87 stages: S,
88 family: PhantomData,
89 equation: PhantomData,
90 }
91 }
92}
93
94impl<E, F, T: Real, Y: State<T>, const S: usize> AdamsPredictorCorrector<E, F, T, Y, S> {
95 pub fn tol(mut self, rtol: T) -> Self {
97 self.tol = rtol;
98 self
99 }
100
101 pub fn h0(mut self, h0: T) -> Self {
103 self.h0 = h0;
104 self
105 }
106
107 pub fn h_min(mut self, h_min: T) -> Self {
109 self.h_min = h_min;
110 self
111 }
112
113 pub fn h_max(mut self, h_max: T) -> Self {
115 self.h_max = h_max;
116 self
117 }
118
119 pub fn max_steps(mut self, max_steps: usize) -> Self {
121 self.max_steps = max_steps;
122 self
123 }
124
125 pub fn stages(&self) -> usize {
127 self.stages
128 }
129}