summaryrefslogtreecommitdiff
path: root/src/solver/midpoint.rs
blob: 08a3e3cc86b5a09b66fc9e0262c7699164cedc90 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
use crate::particle_system::{ParticleSystem, Scalar};
use super::{PhaseSpace, Solver};

impl Solver for ParticleSystem {
    fn step(&mut self, dt: Scalar) {
        let mut state = self.collect_phase_space();

        // Shift to the midpoint
        self.scatter_phase_space(&PhaseSpace {
            0: state.0.clone() + self.compute_derivative().0 * dt / 2.0,
        });

        state.0 += self.compute_derivative().0 * dt;
        self.scatter_phase_space(&state);

        self.t += dt;
    }
}