]> Dogcows Code - chaz/yoink/blobdiff - src/Moof/RK4.hh
random changes
[chaz/yoink] / src / Moof / RK4.hh
index a2e0f1cbe713c62e0eb9b6267c2b2febaecd065a..806127ecc977c1388b2dcef37f838f2658f86f77 100644 (file)
@@ -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<typename S, typename D>
-inline void integrate(S& state, Scalar t, Scalar dt)
+inline void euler(S& state, Scalar t, Scalar dt)
+{
+       D a = evaluate<S,D>(state, t);
+
+       state.applyDerivative(a, dt);
+}
+
+template<typename S, typename D>
+inline void rk2(S& state, Scalar t, Scalar dt)
+{
+       D a = evaluate<S,D>(state, t);
+       D b = evaluate<S,D>(state, t, dt * 0.5, a);
+
+       state.applyDerivative(b, dt);
+}
+
+template<typename S, typename D>
+inline void rk4(S& state, Scalar t, Scalar dt)
 {
        D a = evaluate<S,D>(state, t);
        D b = evaluate<S,D>(state, t, dt * 0.5, a);
This page took 0.020873 seconds and 4 git commands to generate.