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 for the latest Boost documentation.
Boost C++ Libraries Home Libraries People FAQ More

PrevUpHomeNext

Class template explicit_error_stepper_fsal_base

boost::numeric::odeint::explicit_error_stepper_fsal_base — Base class for explicit steppers with error estimation and stepper fulfilling the FSAL (first-same-as-last) property. This class can be used with controlled steppers for step size control.

Synopsis

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

template<typename Stepper, unsigned short Order, unsigned short StepperOrder, 
         unsigned short ErrorOrder, typename State, typename Value, 
         typename Deriv, typename Time, typename Algebra, typename Operations, 
         typename Resizer> 
class explicit_error_stepper_fsal_base :
  public boost::numeric::odeint::algebra_stepper_base< Algebra, Operations >
{
public:
  // types
  typedef algebra_stepper_base< Algebra, Operations > algebra_stepper_base_type;
  typedef algebra_stepper_base_type::algebra_type     algebra_type;             
  typedef State                                       state_type;               
  typedef Value                                       value_type;               
  typedef Deriv                                       deriv_type;               
  typedef Time                                        time_type;                
  typedef Resizer                                     resizer_type;             
  typedef Stepper                                     stepper_type;             
  typedef explicit_error_stepper_fsal_tag             stepper_category;         
  typedef unsigned short                              order_type;               

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

  // public member functions
  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 &);
  template<typename StateIn> void adjust_size(const StateIn &);
  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 System, typename StateInOut> 
    void do_step_v1(System, StateInOut &, time_type, time_type);
  template<typename System, typename StateInOut, typename Err> 
    void do_step_v5(System, StateInOut &, time_type, time_type, Err &);
  template<typename StateIn> bool resize_impl(const StateIn &);
  stepper_type & stepper(void);
  const stepper_type & stepper(void) const;

  // public data members
  static const order_type order_value;
  static const order_type stepper_order_value;
  static const order_type error_order_value;
};

Description

This class serves as the base class for all explicit steppers with algebra and operations and which fulfill the FSAL property. In contrast to explicit_stepper_base it also estimates the error and can be used in a controlled stepper to provide step size control.

The FSAL property means that the derivative of the system at t+dt is already used in the current step going from t to t +dt. Therefore, some more do_steps method can be introduced and the controlled steppers can explicitly make use of this property.

[Note] Note

This stepper provides `do_step` methods with and without error estimation. It has therefore three orders, one for the order of a step if the error is not estimated. The other two orders are the orders of the step and the error step if the error estimation is performed.

explicit_error_stepper_fsal_base is used as the interface in a CRTP (currently recurring template pattern). In order to work correctly the parent class needs to have a method `do_step_impl( system , in , dxdt_in , t , out , dxdt_out , dt , xerr )`. explicit_error_stepper_fsal_base derives from algebra_stepper_base.

This class can have an intrinsic state depending on the explicit usage of the `do_step` method. This means that some `do_step` methods are expected to be called in order. For example the `do_step( sys , x , t , dt , xerr )` will keep track of the derivative of `x` which is the internal state. The first call of this method is recognized such that one does not explicitly initialize the internal state, so it is safe to use this method like

 stepper_type stepper;
 stepper.do_step( sys , x , t , dt , xerr );
 stepper.do_step( sys , x , t , dt , xerr );
 stepper.do_step( sys , x , t , dt , xerr );

But it is unsafe to call this method with different system functions after each other. Do do so, one must initialize the internal state with the `initialize` method or reset the internal state with the `reset` method.

explicit_error_stepper_fsal_base provides several overloaded `do_step` methods, see the list below. Only two of them are needed to fulfill the Error Stepper concept. The other ones are for convenience and for better performance. Some of them simply update the state out-of-place, while other expect that the first derivative at `t` is passed to the stepper.

  • `do_step( sys , x , t , dt )` - The classical `do_step` method needed to fulfill the Error Stepper concept. The state is updated in-place. A type modelling a Boost.Range can be used for x.

  • `do_step( sys , x , dxdt , t , dt )` - This method updates the state x and the derivative dxdt in-place. It is expected that dxdt has the value of the derivative of x at time t.

  • `do_step( sys , in , t , out , dt )` - This method updates the state out-of-place, hence the result of the step is stored in `out`.

  • `do_step( sys , in , dxdt_in , t , out , dxdt_out , dt )` - This method updates the state and the derivative out-of-place. It expects that the derivative at the point `t` is explicitly passed in `dxdt_in`.

  • `do_step( sys , x , t , dt , xerr )` - This `do_step` method is needed to fulfill the Error Stepper concept. The state is updated in-place and an error estimate is calculated. A type modelling a Boost.Range can be used for x.

  • `do_step( sys , x , dxdt , t , dt , xerr )` - This method updates the state and the derivative in-place. It is assumed that the dxdt has the value of the derivative of x at time t. An error estimate is calculated.

  • `do_step( sys , in , t , out , dt , xerr )` - This method updates the state out-of-place and estimates the error during the step.

  • `do_step( sys , in , dxdt_in , t , out , dxdt_out , dt , xerr )` - This methods updates the state and the derivative out-of-place and estimates the error during the step. It is assumed the dxdt_in is derivative of in at time t.

[Note] Note

The system is always passed as value, which might result in poor performance if it contains data. In this case it can be used with `boost::ref` or `std::ref`, for example `stepper.do_step( boost::ref( sys ) , x , t , dt );`

The time `t` is not advanced by the stepper. This has to done manually, or by the appropriate `integrate` routines or `iterator`s.

Template Parameters

  1. typename Stepper

    The stepper on which this class should work. It is used via CRTP, hence explicit_stepper_base provides the interface for the Stepper.

  2. unsigned short Order

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

  3. unsigned short StepperOrder

    The order of a step if the stepper is used with error estimation. Usually Order and StepperOrder have the same value.

  4. unsigned short ErrorOrder

    The order of the error step if the stepper is used with error estimation.

  5. typename State

    The state type for the stepper.

  6. typename Value

    The value type for the stepper. This should be a floating point type, like float, double, or a multiprecision type. It must not necessary be the value_type of the State. For example the State can be a `vector< complex< double > >` in this case the Value must be double. The default value is double.

  7. typename Deriv

    The type representing time derivatives of the state type. It is usually the same type as the state type, only if used with Boost.Units both types differ.

  8. typename Time

    The type representing the time. Usually the same type as the value type. When Boost.Units is used, this type has usually a unit.

  9. typename Algebra

    The algebra type which must fulfill the Algebra Concept.

  10. typename Operations

    The type for the operations which must fulfill the Operations Concept.

  11. typename Resizer

    The resizer policy class.

explicit_error_stepper_fsal_base public construct/copy/destruct

  1. explicit_error_stepper_fsal_base(const algebra_type & algebra = algebra_type());
    Constructs a explicit_stepper_fsal_base 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.

explicit_error_stepper_fsal_base public member functions

  1. order_type order(void) const;

    Returns:

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

  2. order_type stepper_order(void) const;

    Returns:

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

  3. order_type error_order(void) const;

    Returns:

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

  4. 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.

  5. 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.
  6. 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.

  7. 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.

  8. 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.

  9. 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.

  10. 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.
  11. 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.

  12. 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.

  13. 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.

  14. 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.

  15. 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.
  16. 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`.

  17. 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.

  18. 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.
  19. algebra_type & algebra();

    Returns:

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

  20. const algebra_type & algebra() const;

    Returns:

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

explicit_error_stepper_fsal_base private member functions

  1. template<typename System, typename StateInOut> 
      void do_step_v1(System system, StateInOut & x, time_type t, time_type dt);
  2. template<typename System, typename StateInOut, typename Err> 
      void do_step_v5(System system, StateInOut & x, time_type t, time_type dt, 
                      Err & xerr);
  3. template<typename StateIn> bool resize_impl(const StateIn & x);
  4. stepper_type & stepper(void);
  5. const stepper_type & stepper(void) const;

PrevUpHomeNext