srenevey / ode-solvers

Numerical methods to solve ordinary differential equations in Rust.
BSD 3-Clause "New" or "Revised" License
64 stars 26 forks source link

system trait #4

Closed burrbull closed 5 years ago

burrbull commented 5 years ago

I have additional propose for improving your solvers. But this is breaking change and some more user code.

With this change you can use non-const external values in equations.

srenevey commented 5 years ago

Could you please explain why 08dcae55903677a865d1ce00908e0fd0377499fc is required ?

burrbull commented 5 years ago

Abstract example:

struct Solver {
    k: f64;
}
impl System<State> for Solver {
    // Equations of motion of the system
    fn system(&self, _t: Time, y: &State, dy: &mut State) {
        dy[0] = ...
    }
    fn solout(&mut self, t: Time, _y: &State, _dy: &State) -> bool {
        self.k = foo(t, self.k);
        false
    }
}

fn main {
     for k in 1..10 {
          let solver = Solver {k: k as f64};
          let mut stepper = Dopri5::new(solver, ...);
          let res = stepper.integrate();
          ...
     }
}