33 #ifndef DISCRETIZATION_RUNGE_KUTTA_HPP 34 #define DISCRETIZATION_RUNGE_KUTTA_HPP 42 #include <boost/array.hpp> 52 template <std::
size_t RKOrder>
53 inline constexpr
const std::size_t aijIdx(
const std::size_t& _i,
const std::size_t& _j)
55 return 2 * RKOrder - 1 + _i * (_i + 1) / 2 + _j;
57 template <std::
size_t RKOrder>
58 inline constexpr
const std::size_t ciIdx(
const std::size_t& _i)
62 template <std::
size_t RKOrder>
63 inline constexpr
const std::size_t bjIdx(
const std::size_t& _j)
65 return RKOrder - 1 + _j;
80 template <std::size_t StateNmSize, std::size_t RKOrder,
typename... RKCoeff>
83 static constexpr
const std::array<double,
sizeof...(RKCoeff)> coeff = {
86 static std::array<StateArray<StateNmSize>, RKOrder> dX;
90 static double _arc0, _dArc;
95 throw "Wrong specialization of RungeKutta::discretize called (system state value size != function state value " 101 const double& b0 = coeff[bjIdx<RKOrder>(0)];
103 for (std::size_t si = 0; si < StateNmSize; ++si)
106 dX[0].value(si) = stateDot.
value(si);
107 deltaX.
value(si) = b0 * dX[0].value(si);
110 for (std::size_t i = 0; i < RKOrder - 1; ++i)
113 for (std::size_t j = 0; j <= i; ++j)
115 const double& aij = coeff[aijIdx<RKOrder>(i, j)];
116 for (std::size_t si = 0; si < StateNmSize; ++si)
118 deltaXi.
value(si) += aij * dX[j].value(si);
122 for (std::size_t si = 0; si < StateNmSize; ++si)
127 _arc0 + _dArc * coeff[ciIdx<RKOrder>(i)],
131 const double& bipp = coeff[bjIdx<RKOrder>(i + 1)];
132 for (std::size_t si = 0; si < StateNmSize; ++si)
135 deltaX.
value(si) += bipp * dX[i + 1].value(si);
139 for (std::size_t si = 0; si < StateNmSize; ++si)
150 _dArc = _arc - _stateSim.stateArc();
152 State& stateDelta = _stateSim.stateNmDelta(_dArc);
153 for (std::size_t si = 0; si < _stateSim.stateNm().valueSize(); ++si)
155 _stateSim.stateNm().
value(si) += stateDelta.
value(si);
161 #endif // DISCRETIZATION_RUNGE_KUTTA_HPP void discretize(StateSim &_stateSim, const double &_arc)
Templetized generic discretization function.
previous evaluation arc <= this evaluation arc
virtual State & stateNm()=0
Reference to the actual numerical-computed state.
virtual double & value(const std::size_t &_i)=0
Access state variable based on index _i.
void discretize< 0, 0 >(StateSim &_stateSim, const double &_arc)
Specialization for using a user-defined discretization function.
virtual void setStateCfNmStep(const double &_arc, const ParamFuncs::EvalArcGuarantee &_evalArcGuarantee=ParamFuncs::EvalArcGuarantee::AFTER_LAST)
virtual double & value(const std::size_t &_i) override
Access state variable based on index _i.
virtual size_t valueSize() const =0
Size of the state variables.
Generic tree-like recursive structure that allows sub-structure access as well as ordered (array-like...
virtual State & stateNmDot()=0
Computes numerical continuous arc state transition (return) based on internal closed-form state (stat...
std::array< double, N > & valuesArray()
Reference to the state variables array.
virtual void setStateCf(const double &_arc, const ParamFuncs::EvalArcGuarantee &_evalArcGuarantee=ParamFuncs::EvalArcGuarantee::AFTER_LAST)=0
Sets closed-form state at arc _arc.
Interface for a state simulator structure that performs numerical integration of not-closed-form stat...
virtual double stateArc() const =0
Value of the current arc parametrization of the state.