Skip to main content

bima_rs/integrator/
mod.rs

1use crate::{ vec3::Vec3, vec6::Vec6};
2mod bulirsch_stoer;
3mod euler;
4pub mod leap_frog;
5mod rk4;
6
7#[derive(Clone, Debug)]
8pub enum Integrator {
9    Euler,
10    RK4,
11    BS,
12    LeapFrog(leap_frog::State),
13}
14
15impl Integrator {
16    pub fn new_leap_frog() -> Self {
17        Integrator::LeapFrog(leap_frog::State::FirstDrift)
18    }
19}
20
21pub struct Solution {
22    pub w: Vec6,
23    pub a: Option<Vec3>,
24}
25
26impl Solution {
27    pub fn new(w: Vec6, a: Option<Vec3>) -> Self {
28        Solution { w, a }
29    }
30    pub fn unzip(self) -> (Vec6, Option<Vec3>) {
31        (self.w, self.a)
32    }
33}
34
35pub fn euler<F: FnMut(Vec6, bool) -> Vec6>(w: Vec6, dt: f64, wdot_func: F) -> Solution {
36    euler::solve(w, dt, wdot_func)
37}
38
39pub fn rk4<F: FnMut(Vec6, bool) -> Vec6>(w: Vec6, dt: f64, wdot_func: F) -> Solution {
40    rk4::solve(w, dt, wdot_func)
41}
42
43pub fn bs<F: FnMut(Vec6, bool) -> Vec6>(w: Vec6, dt: f64, wdot_func: F) -> Solution {
44    bulirsch_stoer::solve(w, dt, wdot_func)
45}
46
47pub fn lf<F: FnMut(Vec6, bool) -> Vec6>(
48    w: Vec6,
49    dt: f64,
50    wdot_func: F,
51    state: leap_frog::State,
52) -> Solution {
53    leap_frog::solve(w, dt, wdot_func, state)
54}