numeric_algs/symplectic/integration/
suzuki.rs

1use super::{super::State, Integrator, StepSize};
2
3pub struct SuzukiIntegrator {
4    default_step: f64,
5}
6
7impl SuzukiIntegrator {
8    pub fn new(step_size: f64) -> Self {
9        Self {
10            default_step: step_size,
11        }
12    }
13
14    pub fn set_default_step(&mut self, step: f64) {
15        self.default_step = step;
16    }
17}
18
19const CBRT4: f64 = 1.58740105196819947; // cube root of 4
20
21// Algorithm constants
22const L: f64 = 1.0 / (4.0 - CBRT4);
23const C1: f64 = 0.5 * L;
24const C2: f64 = L;
25const C3: f64 = 0.5 * (1.0 - 3.0 * L);
26const C4: f64 = 0.5 * (1.0 - 3.0 * L);
27const C5: f64 = L;
28const C6: f64 = 0.5 * L;
29
30const D1: f64 = L;
31const D2: f64 = L;
32const D3: f64 = 1.0 - 4.0 * L;
33const D4: f64 = L;
34const D5: f64 = L;
35
36impl<S: State> Integrator<S> for SuzukiIntegrator {
37    fn propagate_in_place<DF1, DF2>(
38        &mut self,
39        start: &mut S,
40        pos_diff_eq: DF1,
41        momentum_diff_eq: DF2,
42        step_size: StepSize,
43    ) where
44        DF1: Fn(&S) -> S::PositionDerivative,
45        DF2: Fn(&S) -> S::MomentumDerivative,
46    {
47        let h = match step_size {
48            StepSize::UseDefault => self.default_step,
49            StepSize::Step(x) => x,
50        };
51
52        start.shift_position_in_place(&pos_diff_eq(start), h * C1);
53        start.shift_momentum_in_place(&momentum_diff_eq(start), h * D1);
54        start.shift_position_in_place(&pos_diff_eq(start), h * C2);
55        start.shift_momentum_in_place(&momentum_diff_eq(start), h * D2);
56        start.shift_position_in_place(&pos_diff_eq(start), h * C3);
57        start.shift_momentum_in_place(&momentum_diff_eq(start), h * D3);
58        start.shift_position_in_place(&pos_diff_eq(start), h * C4);
59        start.shift_momentum_in_place(&momentum_diff_eq(start), h * D4);
60        start.shift_position_in_place(&pos_diff_eq(start), h * C5);
61        start.shift_momentum_in_place(&momentum_diff_eq(start), h * D5);
62        start.shift_position_in_place(&pos_diff_eq(start), h * C6);
63    }
64}