Virtual Testbed
Ship dynamics simulator for extreme conditions
Public Types | Public Member Functions | List of all members
vtb::core::RKF45< T > Class Template Reference

Runge—Khutta—Fehlberg initial value problem solver. More...

#include <rkf45.hh>

Public Types

typedef T value_type
 

Public Member Functions

 RKF45 (const RKF45 &)=default
 
RKF45operator= (const RKF45 &)=default
 
 RKF45 (RKF45 &&)=default
 
RKF45operator= (RKF45 &&)=default
 
template<class Function , int N>
blitz::TinyVector< T, N > solve (Function f, T t0, T t1, const blitz::TinyVector< T, N > &x0)
 Solve system of ordinary differential equations with right hand sides f. More...
 
template<class Function , int N>
blitz::TinyVector< T, N > operator() (Function f, T t0, T t1, const blitz::TinyVector< T, N > &x0)
 Solve system of ordinary differential equations with right hand sides f. More...
 
min_step () const noexcept
 
void min_step (T rhs)
 
max_step () const noexcept
 
void max_step (T rhs)
 
tolerance () const noexcept
 
void tolerance (T rhs)
 
void verbose (bool rhs) noexcept
 
bool verbose () const noexcept
 

Detailed Description

template<class T>
class vtb::core::RKF45< T >

Runge—Khutta—Fehlberg initial value problem solver.

Date
2018-07-13
Author
Ivan Gankevich

Definition at line 24 of file rkf45.hh.

Member Function Documentation

◆ operator()()

template<class T >
template<class Function , int N>
blitz::TinyVector<T,N> vtb::core::RKF45< T >::operator() ( Function  f,
t0,
t1,
const blitz::TinyVector< T, N > &  x0 
)
inline

Solve system of ordinary differential equations with right hand sides f.

Date
2018-07-13
Author
Ivan Gankevich
Parameters
[in]fright hand sides of the equations
[in]t0initial time instant
[in]t1final time instant
[in]x0initial value at \(t=t_0\)
Returns
\(\vec{x}\) at \(t=t_1\)
  • The system of equations is written as \(\dot{\vec{x}} = f\left(\vec{x}\right).\)
  • The solution is computed for interval \((t_0,t_1]\).
  • The algorithm is described in [mathews2004].

Definition at line 244 of file rkf45.hh.

◆ solve()

template<class T >
template<class Function , int N>
blitz::TinyVector<T,N> vtb::core::RKF45< T >::solve ( Function  f,
t0,
t1,
const blitz::TinyVector< T, N > &  x0 
)
inline

Solve system of ordinary differential equations with right hand sides f.

Date
2018-07-13
Author
Ivan Gankevich
Parameters
[in]fright hand sides of the equations
[in]t0initial time instant
[in]t1final time instant
[in]x0initial value at \(t=t_0\)
Returns
\(\vec{x}\) at \(t=t_1\)
  • The system of equations is written as \(\dot{\vec{x}} = f\left(\vec{x}\right).\)
  • The solution is computed for interval \((t_0,t_1]\).
  • The algorithm is described in [mathews2004].

Calculate coefficients:

\begin{eqnarray*} k_1 &=& h f\left(t_i, x_i\right) \\ k_2 &=& h f\left( t_i + \frac{1}{4}h, x_i + \frac{1}{4}k_1 \right) \\ k_3 &=& h f\left( t_i + \frac{3}{8}h, x_i + \frac{3}{32}k_1 + \frac{9}{32}k_2 \right) \\ k_4 &=& h f\left( t_i + \frac{12}{13}h, x_i + \frac{1932}{2197}k_1 - \frac{7200}{2197}k_2 + \frac{7296}{2197}k_3 \right) \\ k_5 &=& h f\left( t_i + h, x_i + \frac{439}{216}k_1 - 8 k_2 + \frac{3680}{513}k_3 - \frac{845}{4104}k_4 \right) \\ k_6 &=& h f\left( t_i + \frac{1}{2}h, x_i - \frac{8}{27}k_1 + 2 k_2 - \frac{3544}{2565}k_3 + \frac{1859}{4104}k_4 - \frac{11}{40}k_5 \right) \end{eqnarray*}

Calculate \(x_{i+1}\) using a Runge—Kutta method of order 4. N.B. \(k_2\) is not used here.

\[ x_{i+1} = x_i + \frac{25}{216}k_1 + \frac{1408}{2565}k_3 + \frac{2197}{4101}k_4 - \frac{1}{5}k_5 \]

Calculate \(x_{i+1}\) (denoted here as \(z_{i+1}\)) using a Runge—Kutta method of order 5. N.B. \(k_2\) is not used here.

\[ z_{i+1} = z_i + \frac{16}{135}k_1 + \frac{6656}{12825}k_3 + \frac{28561}{56430}k_4 - \frac{9}{50}k_5 + \frac{2}{55}k_6 \]

Calculate optimal step size \(sh\).

\[ s = \left( \frac{\textrm{tol} \, h} {2\,\textrm{max}\left|x_{i+1} - z_{i+1}\right|} \right)^{1/4} \]

Clamp step size \(h\) to \([h_{\textrm{min}},h_{\textrm{max}}]\). Clamp time instant to \([t_{\textrm{min}},t_{\textrm{max}}]\).

Definition at line 67 of file rkf45.hh.