Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

This is the documentation for an old version of Boost. Click here to view this page for the latest version.
Boost C++ Libraries Home Libraries People FAQ More

PrevUpHomeNext

Class template runge_kutta_dopri5

boost::numeric::odeint::runge_kutta_dopri5 — The Runge-Kutta Dormand-Prince 5 method.

Synopsis

// In header: <boost/numeric/odeint/stepper/runge_kutta_dopri5.hpp>

template<typename State, typename Value = double, typename Deriv = State, 
         typename Time = Value, typename Algebra = range_algebra, 
         typename Operations = default_operations, 
         typename Resizer = initially_resizer> 
class runge_kutta_dopri5 : public boost::numeric::odeint::explicit_error_stepper_fsal_base< Stepper, Order, StepperOrder, ErrorOrder, State, Value, Deriv, Time, Algebra, Operations, Resizer >
{
public:
  // types
  typedef explicit_error_stepper_fsal_base< runge_kutta_dopri5< ... >,... > stepper_base_type;
  typedef stepper_base_type::state_type                                     state_type;       
  typedef stepper_base_type::value_type                                     value_type;       
  typedef stepper_base_type::deriv_type                                     deriv_type;       
  typedef stepper_base_type::time_type                                      time_type;        
  typedef stepper_base_type::algebra_type                                   algebra_type;     
  typedef stepper_base_type::operations_type                                operations_type;  
  typedef stepper_base_type::resizer_type                                   resizer_type;     

  // construct/copy/destruct
  runge_kutta_dopri5(const algebra_type & = algebra_type());

  // public member functions
  template<typename System, typename StateIn, typename DerivIn, 
           typename StateOut, typename DerivOut> 
    void do_step_impl(System, const StateIn &, const DerivIn &, time_type, 
                      StateOut &, DerivOut &, time_type);
  template<typename System, typename StateIn, typename DerivIn, 
           typename StateOut, typename DerivOut, typename Err> 
    void do_step_impl(System, const StateIn &, const DerivIn &, time_type, 
                      StateOut &, DerivOut &, time_type, Err &);
  template<typename StateOut, typename StateIn1, typename DerivIn1, 
           typename StateIn2, typename DerivIn2> 
    void calc_state(time_type, StateOut &, const StateIn1 &, const DerivIn1 &, 
                    time_type, const StateIn2 &, const DerivIn2 &, time_type) const;
  template<typename StateIn> void adjust_size(const StateIn &);
  order_type order(void) const;
  order_type stepper_order(void) const;
  order_type error_order(void) const;
  template<typename System, typename StateInOut> 
    void do_step(System, StateInOut &, time_type, time_type);
  template<typename System, typename StateInOut> 
    void do_step(System, const StateInOut &, time_type, time_type);
  template<typename System, typename StateInOut, typename DerivInOut> 
    boost::disable_if< boost::is_same< StateInOut, time_type >, void >::type 
    do_step(System, StateInOut &, DerivInOut &, time_type, time_type);
  template<typename System, typename StateIn, typename StateOut> 
    boost::disable_if< boost::is_same< StateIn, time_type >, void >::type 
    do_step(System, const StateIn &, time_type, StateOut &, time_type);
  template<typename System, typename StateIn, typename DerivIn, 
           typename StateOut, typename DerivOut> 
    void do_step(System, const StateIn &, const DerivIn &, time_type, 
                 StateOut &, DerivOut &, time_type);
  template<typename System, typename StateInOut, typename Err> 
    void do_step(System, StateInOut &, time_type, time_type, Err &);
  template<typename System, typename StateInOut, typename Err> 
    void do_step(System, const StateInOut &, time_type, time_type, Err &);
  template<typename System, typename StateInOut, typename DerivInOut, 
           typename Err> 
    boost::disable_if< boost::is_same< StateInOut, time_type >, void >::type 
    do_step(System, StateInOut &, DerivInOut &, time_type, time_type, Err &);
  template<typename System, typename StateIn, typename StateOut, typename Err> 
    void do_step(System, const StateIn &, time_type, StateOut &, time_type, 
                 Err &);
  template<typename System, typename StateIn, typename DerivIn, 
           typename StateOut, typename DerivOut, typename Err> 
    void do_step(System, const StateIn &, const DerivIn &, time_type, 
                 StateOut &, DerivOut &, time_type, Err &);
  void reset(void);
  template<typename DerivIn> void initialize(const DerivIn &);
  template<typename System, typename StateIn> 
    void initialize(System, const StateIn &, time_type);
  bool is_initialized(void) const;
  algebra_type & algebra();
  const algebra_type & algebra() const;

  // private member functions
  template<typename StateIn> bool resize_k_x_tmp_impl(const StateIn &);
  template<typename StateIn> bool resize_dxdt_tmp_impl(const StateIn &);
};

Description

The Runge-Kutta Dormand-Prince 5 method is a very popular method for solving ODEs, see . The method is explicit and fulfills the Error Stepper concept. Step size control is provided but continuous output is available which make this method favourable for many applications.

This class derives from explicit_error_stepper_fsal_base and inherits its interface via CRTP (current recurring template pattern). The method possesses the FSAL (first-same-as-last) property. See explicit_error_stepper_fsal_base for more details.

Template Parameters

  1. typename State

    The state type.

  2. typename Value = double

    The value type.

  3. typename Deriv = State

    The type representing the time derivative of the state.

  4. typename Time = Value

    The time representing the independent variable - the time.

  5. typename Algebra = range_algebra

    The algebra type.

  6. typename Operations = default_operations

    The operations type.

  7. typename Resizer = initially_resizer

    The resizer policy type.

runge_kutta_dopri5 public construct/copy/destruct

  1. runge_kutta_dopri5(const algebra_type & algebra = algebra_type());
    Constructs the runge_kutta_dopri5 class. This constructor can be used as a default constructor if the algebra has a default constructor.

    Parameters:

    algebra

    A copy of algebra is made and stored inside explicit_stepper_base.

runge_kutta_dopri5 public member functions

  1. template<typename System, typename StateIn, typename DerivIn, 
             typename StateOut, typename DerivOut> 
      void do_step_impl(System system, const StateIn & in, 
                        const DerivIn & dxdt_in, time_type t, StateOut & out, 
                        DerivOut & dxdt_out, time_type dt);
    This method performs one step. The derivative `dxdt_in` of `in` at the time `t` is passed to the method. The result is updated out-of-place, hence the input is in `in` and the output in `out`. Furthermore, the derivative is update out-of-place, hence the input is assumed to be in `dxdt_in` and the output in `dxdt_out`. Access to this step functionality is provided by explicit_error_stepper_fsal_base and `do_step_impl` should not be called directly.

    Parameters:

    dt

    The step size.

    dxdt_in

    The derivative of x at t. dxdt_in is not modified by this method

    dxdt_out

    The result of the new derivative at time t+dt.

    in

    The state of the ODE which should be solved. in is not modified in this method

    out

    The result of the step is written in out.

    system

    The system function to solve, hence the r.h.s. of the ODE. It must fulfill the Simple System concept.

    t

    The value of the time, at which the step should be performed.

  2. template<typename System, typename StateIn, typename DerivIn, 
             typename StateOut, typename DerivOut, typename Err> 
      void do_step_impl(System system, const StateIn & in, 
                        const DerivIn & dxdt_in, time_type t, StateOut & out, 
                        DerivOut & dxdt_out, time_type dt, Err & xerr);
    This method performs one step. The derivative `dxdt_in` of `in` at the time `t` is passed to the method. The result is updated out-of-place, hence the input is in `in` and the output in `out`. Furthermore, the derivative is update out-of-place, hence the input is assumed to be in `dxdt_in` and the output in `dxdt_out`. Access to this step functionality is provided by explicit_error_stepper_fsal_base and `do_step_impl` should not be called directly. An estimation of the error is calculated.

    Parameters:

    dt

    The step size.

    dxdt_in

    The derivative of x at t. dxdt_in is not modified by this method

    dxdt_out

    The result of the new derivative at time t+dt.

    in

    The state of the ODE which should be solved. in is not modified in this method

    out

    The result of the step is written in out.

    system

    The system function to solve, hence the r.h.s. of the ODE. It must fulfill the Simple System concept.

    t

    The value of the time, at which the step should be performed.

    xerr

    An estimation of the error.

  3. template<typename StateOut, typename StateIn1, typename DerivIn1, 
             typename StateIn2, typename DerivIn2> 
      void calc_state(time_type t, StateOut & x, const StateIn1 & x_old, 
                      const DerivIn1 & deriv_old, time_type t_old, 
                      const StateIn2 &, const DerivIn2 & deriv_new, 
                      time_type t_new) const;
    This method is used for continuous output and it calculates the state `x` at a time `t` from the knowledge of two states `old_state` and `current_state` at time points `t_old` and `t_new`. It also uses internal variables to calculate the result. Hence this method must be called after two successful `do_step` calls.
  4. template<typename StateIn> void adjust_size(const StateIn & x);
    Adjust the size of all temporaries in the stepper manually.

    Parameters:

    x

    A state from which the size of the temporaries to be resized is deduced.

  5. order_type order(void) const;

    Returns:

    Returns the order of the stepper if it used without error estimation.

  6. order_type stepper_order(void) const;

    Returns:

    Returns the order of a step if the stepper is used without error estimation.

  7. order_type error_order(void) const;

    Returns:

    Returns the order of an error step if the stepper is used without error estimation.

  8. template<typename System, typename StateInOut> 
      void do_step(System system, StateInOut & x, time_type t, time_type dt);
    This method performs one step. It transforms the result in-place.
    [Note] Note

    This method uses the internal state of the stepper.

    Parameters:

    dt

    The step size.

    system

    The system function to solve, hence the r.h.s. of the ordinary differential equation. It must fulfill the Simple System concept.

    t

    The value of the time, at which the step should be performed.

    x

    The state of the ODE which should be solved. After calling do_step the result is updated in x.

  9. template<typename System, typename StateInOut> 
      void do_step(System system, const StateInOut & x, time_type t, time_type dt);
    Second version to solve the forwarding problem, can be called with Boost.Range as StateInOut.
  10. template<typename System, typename StateInOut, typename DerivInOut> 
      boost::disable_if< boost::is_same< StateInOut, time_type >, void >::type 
      do_step(System system, StateInOut & x, DerivInOut & dxdt, time_type t, 
              time_type dt);
    The method performs one step with the stepper passed by Stepper. Additionally to the other methods the derivative of x is also passed to this method. Therefore, dxdt must be evaluated initially:
     ode( x , dxdt , t );
     for( ... )
     {
         stepper.do_step( ode , x , dxdt , t , dt );
         t += dt;
     }
    
    [Note] Note

    This method does NOT use the initial state, since the first derivative is explicitly passed to this method.

    The result is updated in place in x as well as the derivative dxdt. This method is disabled if Time and StateInOut are of the same type. In this case the method could not be distinguished from other `do_step` versions.

    [Note] Note

    This method does not solve the forwarding problem.

    Parameters:

    dt

    The step size.

    dxdt

    The derivative of x at t. After calling `do_step` dxdt is updated to the new value.

    system

    The system function to solve, hence the r.h.s. of the ODE. It must fulfill the Simple System concept.

    t

    The value of the time, at which the step should be performed.

    x

    The state of the ODE which should be solved. After calling do_step the result is updated in x.

  11. template<typename System, typename StateIn, typename StateOut> 
      boost::disable_if< boost::is_same< StateIn, time_type >, void >::type 
      do_step(System system, const StateIn & in, time_type t, StateOut & out, 
              time_type dt);
    The method performs one step with the stepper passed by Stepper. The state of the ODE is updated out-of-place. This method is disabled if StateIn and Time are the same type. In this case the method can not be distinguished from other `do_step` variants.
    [Note] Note

    This method uses the internal state of the stepper.

    This method does not solve the forwarding problem.

    Parameters:

    dt

    The step size.

    in

    The state of the ODE which should be solved. in is not modified in this method

    out

    The result of the step is written in out.

    system

    The system function to solve, hence the r.h.s. of the ODE. It must fulfill the Simple System concept.

    t

    The value of the time, at which the step should be performed.

  12. template<typename System, typename StateIn, typename DerivIn, 
             typename StateOut, typename DerivOut> 
      void do_step(System system, const StateIn & in, const DerivIn & dxdt_in, 
                   time_type t, StateOut & out, DerivOut & dxdt_out, 
                   time_type dt);
    The method performs one step with the stepper passed by Stepper. The state of the ODE is updated out-of-place. Furthermore, the derivative of x at t is passed to the stepper and updated by the stepper to its new value at t+dt.
    [Note] Note

    This method does not solve the forwarding problem.

    This method does NOT use the internal state of the stepper.

    Parameters:

    dt

    The step size.

    dxdt_in

    The derivative of x at t.

    dxdt_out

    The updated derivative of `out` at `t+dt`.

    in

    The state of the ODE which should be solved. in is not modified in this method

    out

    The result of the step is written in out.

    system

    The system function to solve, hence the r.h.s. of the ODE. It must fulfill the Simple System concept.

    t

    The value of the time, at which the step should be performed.

  13. template<typename System, typename StateInOut, typename Err> 
      void do_step(System system, StateInOut & x, time_type t, time_type dt, 
                   Err & xerr);
    The method performs one step with the stepper passed by Stepper and estimates the error. The state of the ODE is updated in-place.
    [Note] Note

    This method uses the internal state of the stepper.

    Parameters:

    dt

    The step size.

    system

    The system function to solve, hence the r.h.s. of the ODE. It must fulfill the Simple System concept.

    t

    The value of the time, at which the step should be performed.

    x

    The state of the ODE which should be solved. x is updated by this method.

    xerr

    The estimation of the error is stored in xerr.

  14. template<typename System, typename StateInOut, typename Err> 
      void do_step(System system, const StateInOut & x, time_type t, time_type dt, 
                   Err & xerr);
    Second version to solve the forwarding problem, can be called with Boost.Range as StateInOut.
  15. template<typename System, typename StateInOut, typename DerivInOut, 
             typename Err> 
      boost::disable_if< boost::is_same< StateInOut, time_type >, void >::type 
      do_step(System system, StateInOut & x, DerivInOut & dxdt, time_type t, 
              time_type dt, Err & xerr);
    The method performs one step with the stepper passed by Stepper. Additionally to the other method the derivative of x is also passed to this method and updated by this method.
    [Note] Note

    This method does NOT use the internal state of the stepper.

    The result is updated in place in x. This method is disabled if Time and Deriv are of the same type. In this case the method could not be distinguished from other `do_step` versions. This method is disabled if StateInOut and Time are of the same type.

    [Note] Note

    This method does NOT use the internal state of the stepper.

    This method does not solve the forwarding problem.

    Parameters:

    dt

    The step size.

    dxdt

    The derivative of x at t. After calling `do_step` this value is updated to the new value at `t+dt`.

    system

    The system function to solve, hence the r.h.s. of the ODE. It must fulfill the Simple System concept.

    t

    The value of the time, at which the step should be performed.

    x

    The state of the ODE which should be solved. After calling do_step the result is updated in x.

    xerr

    The error estimate is stored in xerr.

  16. template<typename System, typename StateIn, typename StateOut, typename Err> 
      void do_step(System system, const StateIn & in, time_type t, StateOut & out, 
                   time_type dt, Err & xerr);
    The method performs one step with the stepper passed by Stepper. The state of the ODE is updated out-of-place. Furthermore, the error is estimated.
    [Note] Note

    This method uses the internal state of the stepper.

    This method does not solve the forwarding problem.

    Parameters:

    dt

    The step size.

    in

    The state of the ODE which should be solved. in is not modified in this method

    out

    The result of the step is written in out.

    system

    The system function to solve, hence the r.h.s. of the ODE. It must fulfill the Simple System concept.

    t

    The value of the time, at which the step should be performed.

    xerr

    The error estimate.

  17. template<typename System, typename StateIn, typename DerivIn, 
             typename StateOut, typename DerivOut, typename Err> 
      void do_step(System system, const StateIn & in, const DerivIn & dxdt_in, 
                   time_type t, StateOut & out, DerivOut & dxdt_out, 
                   time_type dt, Err & xerr);
    The method performs one step with the stepper passed by Stepper. The state of the ODE is updated out-of-place. Furthermore, the derivative of x at t is passed to the stepper and the error is estimated.
    [Note] Note

    This method does NOT use the internal state of the stepper.

    This method does not solve the forwarding problem.

    Parameters:

    dt

    The step size.

    dxdt_in

    The derivative of x at t.

    dxdt_out

    The new derivative at `t+dt` is written into this variable.

    in

    The state of the ODE which should be solved. in is not modified in this method

    out

    The result of the step is written in out.

    system

    The system function to solve, hence the r.h.s. of the ODE. It must fulfill the Simple System concept.

    t

    The value of the time, at which the step should be performed.

    xerr

    The error estimate.

  18. void reset(void);
    Resets the internal state of this stepper. After calling this method it is safe to use all `do_step` method without explicitly initializing the stepper.
  19. template<typename DerivIn> void initialize(const DerivIn & deriv);
    Initializes the internal state of the stepper.

    Parameters:

    deriv

    The derivative of x. The next call of `do_step` expects that the derivative of `x` passed to `do_step` has the value of `deriv`.

  20. template<typename System, typename StateIn> 
      void initialize(System system, const StateIn & x, time_type t);
    Initializes the internal state of the stepper.

    This method is equivalent to

     Deriv dxdt;
     system( x , dxdt , t );
     stepper.initialize( dxdt );
    

    Parameters:

    system

    The system function for the next calls of `do_step`.

    t

    The current time of the ODE.

    x

    The current state of the ODE.

  21. bool is_initialized(void) const;
    Returns if the stepper is already initialized. If the stepper is not initialized, the first call of `do_step` will initialize the state of the stepper. If the stepper is already initialized the system function can not be safely exchanged between consecutive `do_step` calls.
  22. algebra_type & algebra();

    Returns:

    A reference to the algebra which is held by this class.

  23. const algebra_type & algebra() const;

    Returns:

    A const reference to the algebra which is held by this class.

runge_kutta_dopri5 private member functions

  1. template<typename StateIn> bool resize_k_x_tmp_impl(const StateIn & x);
  2. template<typename StateIn> bool resize_dxdt_tmp_impl(const StateIn & x);

PrevUpHomeNext