...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
Home | Libraries | People | FAQ | More |
boost::numeric::odeint::explicit_stepper_base — Base class for explicit steppers without step size control and without dense output.
// In header: <boost/numeric/odeint/stepper/base/explicit_stepper_base.hpp> template<typename Stepper, unsigned short Order, typename State, typename Value, typename Deriv, typename Time, typename Algebra, typename Operations, typename Resizer> class explicit_stepper_base : public boost::numeric::odeint::algebra_stepper_base< Algebra, Operations > { public: // types 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 stepper_tag stepper_category; typedef algebra_stepper_base< Algebra, Operations > algebra_stepper_base_type; typedef algebra_stepper_base_type::algebra_type algebra_type; typedef algebra_stepper_base_type::operations_type operations_type; typedef unsigned short order_type; // public member functions 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 DerivIn> boost::disable_if< boost::is_same< DerivIn, time_type >, void >::type do_step(System, StateInOut &, const DerivIn &, time_type, time_type); template<typename System, typename StateIn, typename StateOut> void do_step(System, const StateIn &, time_type, StateOut &, time_type); template<typename System, typename StateIn, typename DerivIn, typename StateOut> void do_step(System, const StateIn &, const DerivIn &, time_type, StateOut &, time_type); template<typename StateIn> void adjust_size(const StateIn &); const algebra_type & algebra() const; // private member functions stepper_type & stepper(void); const stepper_type & stepper(void) const; template<typename StateIn> bool resize_impl(const StateIn &); template<typename System, typename StateInOut> void do_step_v1(System, StateInOut &, time_type, time_type); // public data members static const order_type order_value; __pad0__; };
This class serves as the base class for all explicit steppers with algebra and operations. Step size control and error estimation as well as dense output are not provided. explicit_stepper_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 , dt )
. This is method is used by explicit_stepper_base. explicit_stepper_base derives from algebra_stepper_base. An example how this class can be used is
* template< class State , class Value , class Deriv , class Time , class Algebra , class Operations , class Resizer > * class custom_euler : public explicit_stepper_base< 1 , State , Value , Deriv , Time , Algebra , Operations , Resizer > * { * public: * * typedef explicit_stepper_base< 1 , State , Value , Deriv , Time , Algebra , Operations , Resizer > base_type; * * custom_euler( const Algebra &algebra = Algebra() ) { } * * template< class Sys , class StateIn , class DerivIn , class StateOut > * void do_step_impl( Sys sys , const StateIn &in , const DerivIn &dxdt , Time t , StateOut &out , Time dt ) * { * m_algebra.for_each3( out , in , dxdt , Operations::scale_sum2< Value , Time >( 1.0 , dt ); * } * * template< class State > * void adjust_size( const State &x ) * { * base_type::adjust_size( x ); * } * }; *
For the Stepper concept only the do_step( sys , x , t , dt )
needs to be implemented. But this class provides additional do_step
variants since the stepper is explicit. These methods can be used to increase the performance in some situation, for example if one needs to analyze dxdt
during each step. In this case one can use
* sys( x , dxdt , t ); * stepper.do_step( sys , x , dxdt , t , dt ); // the value of dxdt is used here * t += dt; *
In detail explicit_stepper_base provides the following do_step
variants
do_step( sys , x , t , dt )
- The classical do_step
method needed to fulfill the Stepper concept. The state is updated in-place. A type modelling a Boost.Range can be used for x.
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 , x , dxdt , t , dt )
- This method updates the state in-place, but the derivative at the point t
must be explicitly passed in dxdt
. For an example see the code snippet above.
do_step( sys , in , dxdt , t , out , dt )
- This method update the state out-of-place and expects that the derivative at the point t
is explicitly passed in dxdt
. It is a combination of the two do_step
methods above.
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 The time |
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.
unsigned short Order
The order of the stepper.
typename State
The state type for the stepper.
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.
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.
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.
typename Algebra
The algebra type which must fulfill the Algebra Concept.
typename Operations
The type for the operations which must fulfill the Operations Concept.
typename Resizer
The resizer policy class.
explicit_stepper_base
public member functionstemplate<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.
Parameters: |
|
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.
template<typename System, typename StateInOut, typename DerivIn> boost::disable_if< boost::is_same< DerivIn, time_type >, void >::type do_step(System system, StateInOut & x, const DerivIn & dxdt, time_type t, time_type dt);The method performs one step. Additionally to the other method the derivative of x is also passed to this method. It is supposed to be used in the following way:
* sys( x , dxdt , t ); * stepper.do_step( sys , x , dxdt , t , dt ); *
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.
Note | |
---|---|
This method does not solve the forwarding problem. |
Parameters: |
|
template<typename System, typename StateIn, typename StateOut> void do_step(System system, const StateIn & in, time_type t, StateOut & out, time_type dt);The method performs one step. The state of the ODE is updated out-of-place.
Note | |
---|---|
This method does not solve the forwarding problem. |
Parameters: |
|
template<typename System, typename StateIn, typename DerivIn, typename StateOut> void do_step(System system, const StateIn & in, const DerivIn & dxdt, time_type t, StateOut & out, time_type dt);The method performs one step. The state of the ODE is updated out-of-place. Furthermore, the derivative of x at t is passed to the stepper. It is supposed to be used in the following way:
* sys( in , dxdt , t ); * stepper.do_step( sys , in , dxdt , t , out , dt ); *
Note | |
---|---|
This method does not solve the forwarding problem. |
Parameters: |
|
template<typename StateIn> void adjust_size(const StateIn & x);Adjust the size of all temporaries in the stepper manually.
Parameters: |
|
const algebra_type & algebra() const;
Returns: |
A reference to the algebra which is held by this class. A const reference to the algebra which is held by this class. |