X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fyoink;a=blobdiff_plain;f=src%2FMoof%2FRK4.hh;h=806127ecc977c1388b2dcef37f838f2658f86f77;hp=a2e0f1cbe713c62e0eb9b6267c2b2febaecd065a;hb=d5b4262bc0c6cea41c603e8a3a85ab93adfdc36b;hpb=a4debfe4a5f5d339410788971b698ba00cb7f09c diff --git a/src/Moof/RK4.hh b/src/Moof/RK4.hh index a2e0f1c..806127e 100644 --- a/src/Moof/RK4.hh +++ b/src/Moof/RK4.hh @@ -34,9 +34,9 @@ namespace Mf { -// Generic implementation of the RK4 integrator. To use, you need one type -// representing the state and another containing the derivatives of the primary -// state variables. The state class must implement these methods: +// Generic implementations of a few simple integrators. To use, you need one +// type representing the state and another containing the derivatives of the +// primary state variables. The state class must implement these methods: // // void getDerivative(Derivative_Type& derivative, Scalar absoluteTime); // void applyDerivative(const Derivative_Type& derivative, Scalar deltaTime); @@ -64,7 +64,24 @@ inline D evaluate(const S& state, Scalar t, Scalar dt, const D& derivative) template -inline void integrate(S& state, Scalar t, Scalar dt) +inline void euler(S& state, Scalar t, Scalar dt) +{ + D a = evaluate(state, t); + + state.applyDerivative(a, dt); +} + +template +inline void rk2(S& state, Scalar t, Scalar dt) +{ + D a = evaluate(state, t); + D b = evaluate(state, t, dt * 0.5, a); + + state.applyDerivative(b, dt); +} + +template +inline void rk4(S& state, Scalar t, Scalar dt) { D a = evaluate(state, t); D b = evaluate(state, t, dt * 0.5, a);