1 #ifndef _utl_RK4ODEIntegrator_h_
2 #define _utl_RK4ODEIntegrator_h_
19 template<
class DerivativeFunctor,
class VectorType>
31 const VectorType&
GetY()
const {
return fY; }
34 Advance(
const double dx,
const VectorType& dYdX)
38 const double dx2 = 0.5 * dx;
40 for (
unsigned int i = 0; i < n; ++i)
41 y1[i] =
fY[i] + dx2 * dYdX[i];
43 const double x1 =
fX + dx2;
47 for (
unsigned int i = 0; i < n; ++i)
48 y1[i] =
fY[i] + dx2 * dYdX1[i];
53 for (
unsigned int i = 0; i < n; ++i) {
54 y1[i] =
fY[i] + dx * dYdX2[i];
61 const double dx6 = (1./6) * dx;
62 for (
unsigned int i = 0; i < n; ++i)
63 fY[i] += dx6 * (dYdX[i] + dYdX1[i] + 2.*dYdX2[i]);
83 explicit operator bool()
const {
return fStatus; }
88 Copy(
const unsigned int n,
const VectorType&
a, VectorType&
b)
90 for (
unsigned int i = 0; i < n; ++i)
160 template<
class DerivativeFunctor>
166 template<
class VectorType>
168 Begin(
const double x,
const VectorType& y)
DerivativeFunctor & fDerivativeFunctor
RK4Iterator(const double x, const VectorType &y, DerivativeFunctor &d)
RK4Iterator< DerivativeFunctor, VectorType > Begin(const double x, const VectorType &y)
DerivativeFunctor & GetDerivativeFunctor()
bool Advance(const double dx, const VectorType &dYdX)
const VectorType & GetY() const
RK4Iterator & operator+=(const double dx)
static void Copy(const unsigned int n, const VectorType &a, VectorType &b)
bool Advance(const double dx)
RK4Iterator & operator-=(const double dx)
RK4ODEIntegrator(DerivativeFunctor &d)
DerivativeFunctor & fDerivativeFunctor