diff options
author | Chanho Park <chanho61.park@samsung.com> | 2014-12-11 18:55:56 +0900 |
---|---|---|
committer | Chanho Park <chanho61.park@samsung.com> | 2014-12-11 18:55:56 +0900 |
commit | 08c1e93fa36a49f49325a07fe91ff92c964c2b6c (patch) | |
tree | 7a7053ceb8874b28ec4b868d4c49b500008a102e /boost/numeric/odeint/stepper/base | |
parent | bb4dd8289b351fae6b55e303f189127a394a1edd (diff) | |
download | boost-08c1e93fa36a49f49325a07fe91ff92c964c2b6c.tar.gz boost-08c1e93fa36a49f49325a07fe91ff92c964c2b6c.tar.bz2 boost-08c1e93fa36a49f49325a07fe91ff92c964c2b6c.zip |
Imported Upstream version 1.57.0upstream/1.57.0
Diffstat (limited to 'boost/numeric/odeint/stepper/base')
5 files changed, 2126 insertions, 0 deletions
diff --git a/boost/numeric/odeint/stepper/base/algebra_stepper_base.hpp b/boost/numeric/odeint/stepper/base/algebra_stepper_base.hpp new file mode 100644 index 0000000000..3b014f8e18 --- /dev/null +++ b/boost/numeric/odeint/stepper/base/algebra_stepper_base.hpp @@ -0,0 +1,91 @@ +/* + [auto_generated] + boost/numeric/odeint/stepper/base/algebra_stepper_base.hpp + + [begin_description] + Base class for all steppers with an algebra and operations. + [end_description] + + Copyright 2012-2013 Karsten Ahnert + Copyright 2012 Mario Mulansky + + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or + copy at http://www.boost.org/LICENSE_1_0.txt) + */ + + +#ifndef BOOST_NUMERIC_ODEINT_STEPPER_BASE_ALGEBRA_STEPPER_BASE_HPP_INCLUDED +#define BOOST_NUMERIC_ODEINT_STEPPER_BASE_ALGEBRA_STEPPER_BASE_HPP_INCLUDED + + +namespace boost { +namespace numeric { +namespace odeint { + +template< class Algebra , class Operations > +class algebra_stepper_base +{ +public: + + typedef Algebra algebra_type; + typedef Operations operations_type; + + algebra_stepper_base( const algebra_type &algebra = algebra_type() ) + : m_algebra( algebra ) { } + + algebra_type& algebra() + { + return m_algebra; + } + + const algebra_type& algebra() const + { + return m_algebra; + } + +protected: + + algebra_type m_algebra; +}; + + +/******* DOXYGEN *******/ + +/** + * \class algebra_stepper_base + * \brief Base class for all steppers with algebra and operations. + * + * This class serves a base class for all steppers with algebra and operations. It holds the + * algebra and provides access to the algebra. The operations are not instantiated, since they are + * static classes inside the operations class. + * + * \tparam Algebra The type of the algebra. Must fulfill the Algebra Concept, at least partially to work + * with the stepper. + * \tparam Operations The type of the operations. Must fulfill the Operations Concept, at least partially + * to work with the stepper. + */ + + /** + * \fn algebra_stepper_base::algebra_stepper_base( const algebra_type &algebra = algebra_type() ) + * \brief Constructs a algebra_stepper_base and creates the algebra. This constructor can be used as a default + * constructor if the algebra has a default constructor. + * \param algebra The algebra_stepper_base stores and uses a copy of algebra. + */ + + /** + * \fn algebra_type& algebra_stepper_base::algebra() + * \return A reference to the algebra which is held by this class. + */ + + /** + * \fn const algebra_type& algebra_stepper_base::algebra() const + * \return A const reference to the algebra which is held by this class. + */ + +} // odeint +} // numeric +} // boost + + +#endif // BOOST_NUMERIC_ODEINT_STEPPER_BASE_ALGEBRA_STEPPER_BASE_HPP_INCLUDED diff --git a/boost/numeric/odeint/stepper/base/explicit_error_stepper_base.hpp b/boost/numeric/odeint/stepper/base/explicit_error_stepper_base.hpp new file mode 100644 index 0000000000..3ba11a4fe0 --- /dev/null +++ b/boost/numeric/odeint/stepper/base/explicit_error_stepper_base.hpp @@ -0,0 +1,561 @@ +/* + [auto_generated] + boost/numeric/odeint/stepper/base/explicit_error_stepper_base.hpp + + [begin_description] + Base class for all explicit Runge Kutta stepper which are also error steppers. + [end_description] + + Copyright 2010-2013 Karsten Ahnert + Copyright 2010-2012 Mario Mulansky + Copyright 2012 Christoph Koke + + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or + copy at http://www.boost.org/LICENSE_1_0.txt) + */ + + +#ifndef BOOST_NUMERIC_ODEINT_STEPPER_BASE_EXPLICIT_ERROR_STEPPER_BASE_HPP_INCLUDED +#define BOOST_NUMERIC_ODEINT_STEPPER_BASE_EXPLICIT_ERROR_STEPPER_BASE_HPP_INCLUDED + +#include <boost/utility/enable_if.hpp> +#include <boost/type_traits/is_same.hpp> + + +#include <boost/numeric/odeint/util/bind.hpp> +#include <boost/numeric/odeint/util/unwrap_reference.hpp> +#include <boost/numeric/odeint/util/state_wrapper.hpp> +#include <boost/numeric/odeint/util/is_resizeable.hpp> +#include <boost/numeric/odeint/util/resizer.hpp> + +#include <boost/numeric/odeint/stepper/stepper_categories.hpp> + +#include <boost/numeric/odeint/stepper/base/algebra_stepper_base.hpp> + +namespace boost { +namespace numeric { +namespace odeint { + + +/* + * base class for explicit stepper and error steppers + * models the stepper AND the error stepper concept + * + * this class provides the following do_step variants: + * do_step( sys , x , t , dt ) + * do_step( sys , x , dxdt , t , dt ) + * do_step( sys , in , t , out , dt ) + * do_step( sys , in , dxdt , t , out , dt ) + * do_step( sys , x , t , dt , xerr ) + * do_step( sys , x , dxdt , t , dt , xerr ) + * do_step( sys , in , t , out , dt , xerr ) + * do_step( sys , in , dxdt , t , out , dt , xerr ) + */ +template< +class Stepper , +unsigned short Order , +unsigned short StepperOrder , +unsigned short ErrorOrder , +class State , +class Value , +class Deriv , +class Time , +class Algebra , +class Operations , +class Resizer +> +class explicit_error_stepper_base : public algebra_stepper_base< Algebra , Operations > +{ +public: + + typedef algebra_stepper_base< Algebra , Operations > algebra_stepper_base_type; + typedef typename 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_tag stepper_category; + #ifndef DOXYGEN_SKIP + typedef state_wrapper< state_type > wrapped_state_type; + typedef state_wrapper< deriv_type > wrapped_deriv_type; + typedef explicit_error_stepper_base< Stepper , Order , StepperOrder , ErrorOrder , + State , Value , Deriv , Time , Algebra , Operations , Resizer > internal_stepper_base_type; + #endif + + typedef unsigned short order_type; + static const order_type order_value = Order; + static const order_type stepper_order_value = StepperOrder; + static const order_type error_order_value = ErrorOrder; + + + explicit_error_stepper_base( const algebra_type &algebra = algebra_type() ) + : algebra_stepper_base_type( algebra ) + { } + + order_type order( void ) const + { + return order_value; + } + + order_type stepper_order( void ) const + { + return stepper_order_value; + } + + order_type error_order( void ) const + { + return error_order_value; + } + + + + /* + * Version 1 : do_step( sys , x , t , dt ) + * + * the two overloads are needed in order to solve the forwarding problem + */ + template< class System , class StateInOut > + void do_step( System system , StateInOut &x , time_type t , time_type dt ) + { + do_step_v1( system , x , t , dt ); + } + + /** + * \brief Second version to solve the forwarding problem, can be called with Boost.Range as StateInOut. + */ + template< class System , class StateInOut > + void do_step( System system , const StateInOut &x , time_type t , time_type dt ) + { + do_step_v1( system , x , t , dt ); + } + + + + /* + * Version 2 : do_step( sys , x , dxdt , t , dt ) + * + * this version does not solve the forwarding problem, boost.range can not be used + * + * the disable is needed to avoid ambiguous overloads if state_type = time_type + */ + template< class System , class StateInOut , class DerivIn > + typename 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 ) + { + this->stepper().do_step_impl( system , x , dxdt , t , x , dt ); + } + + + /* + * Version 3 : do_step( sys , in , t , out , dt ) + * + * this version does not solve the forwarding problem, boost.range can not be used + * + * the disable is needed to avoid ambiguous overloads if state_type = time_type + */ + template< class System , class StateIn , class StateOut > + typename 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 ) + { + typename odeint::unwrap_reference< System >::type &sys = system; + m_resizer.adjust_size( in , detail::bind( &internal_stepper_base_type::template resize_impl<StateIn> , detail::ref( *this ) , detail::_1 ) ); + sys( in , m_dxdt.m_v ,t ); + this->stepper().do_step_impl( system , in , m_dxdt.m_v , t , out , dt ); + } + + /* + * Version 4 :do_step( sys , in , dxdt , t , out , dt ) + * + * this version does not solve the forwarding problem, boost.range can not be used + * + * the disable is needed to avoid ambiguous overloads if state_type = time_type + */ + template< class System , class StateIn , class DerivIn , class StateOut > + typename boost::disable_if< boost::is_same< DerivIn , time_type > , void >::type + do_step( System system , const StateIn &in , const DerivIn &dxdt , time_type t , StateOut &out , time_type dt ) + { + this->stepper().do_step_impl( system , in , dxdt , t , out , dt ); + } + + + + + + /* + * Version 5 :do_step( sys , x , t , dt , xerr ) + * + * the two overloads are needed in order to solve the forwarding problem + */ + template< class System , class StateInOut , class Err > + void do_step( System system , StateInOut &x , time_type t , time_type dt , Err &xerr ) + { + do_step_v5( system , x , t , dt , xerr ); + } + + /** + * \brief Second version to solve the forwarding problem, can be called with Boost.Range as StateInOut. + */ + template< class System , class StateInOut , class Err > + void do_step( System system , const StateInOut &x , time_type t , time_type dt , Err &xerr ) + { + do_step_v5( system , x , t , dt , xerr ); + } + + + /* + * Version 6 :do_step( sys , x , dxdt , t , dt , xerr ) + * + * this version does not solve the forwarding problem, boost.range can not be used + * + * the disable is needed to avoid ambiguous overloads if state_type = time_type + */ + template< class System , class StateInOut , class DerivIn , class Err > + typename 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 , Err &xerr ) + { + this->stepper().do_step_impl( system , x , dxdt , t , x , dt , xerr ); + } + + + /* + * Version 7 : do_step( sys , in , t , out , dt , xerr ) + * + * this version does not solve the forwarding problem, boost.range can not be used + */ + template< class System , class StateIn , class StateOut , class Err > + void do_step( System system , const StateIn &in , time_type t , StateOut &out , time_type dt , Err &xerr ) + { + typename odeint::unwrap_reference< System >::type &sys = system; + m_resizer.adjust_size( in , detail::bind( &internal_stepper_base_type::template resize_impl<StateIn> , detail::ref( *this ) , detail::_1 ) ); + sys( in , m_dxdt.m_v ,t ); + this->stepper().do_step_impl( system , in , m_dxdt.m_v , t , out , dt , xerr ); + } + + + /* + * Version 8 : do_step( sys , in , dxdt , t , out , dt , xerr ) + * + * this version does not solve the forwarding problem, boost.range can not be used + */ + template< class System , class StateIn , class DerivIn , class StateOut , class Err > + void do_step( System system , const StateIn &in , const DerivIn &dxdt , time_type t , StateOut &out , time_type dt , Err &xerr ) + { + this->stepper().do_step_impl( system , in , dxdt , t , out , dt , xerr ); + } + + template< class StateIn > + void adjust_size( const StateIn &x ) + { + resize_impl( x ); + } + + + +private: + + template< class System , class StateInOut > + void do_step_v1( System system , StateInOut &x , time_type t , time_type dt ) + { + typename odeint::unwrap_reference< System >::type &sys = system; + m_resizer.adjust_size( x , detail::bind( &internal_stepper_base_type::template resize_impl<StateInOut> , detail::ref( *this ) , detail::_1 ) ); + sys( x , m_dxdt.m_v , t ); + this->stepper().do_step_impl( system , x , m_dxdt.m_v , t , x , dt ); + } + + template< class System , class StateInOut , class Err > + void do_step_v5( System system , StateInOut &x , time_type t , time_type dt , Err &xerr ) + { + typename odeint::unwrap_reference< System >::type &sys = system; + m_resizer.adjust_size( x , detail::bind( &internal_stepper_base_type::template resize_impl<StateInOut> , detail::ref( *this ) , detail::_1 ) ); + sys( x , m_dxdt.m_v ,t ); + this->stepper().do_step_impl( system , x , m_dxdt.m_v , t , x , dt , xerr ); + } + + template< class StateIn > + bool resize_impl( const StateIn &x ) + { + return adjust_size_by_resizeability( m_dxdt , x , typename is_resizeable<deriv_type>::type() ); + } + + stepper_type& stepper( void ) + { + return *static_cast< stepper_type* >( this ); + } + + const stepper_type& stepper( void ) const + { + return *static_cast< const stepper_type* >( this ); + } + + + resizer_type m_resizer; + +protected: + + wrapped_deriv_type m_dxdt; +}; + + + + +/******** DOXYGEN *******/ + +/** + * \class explicit_error_stepper_base + * \brief Base class for explicit steppers with error estimation. This class can used with + * controlled steppers for step size control. + * + * This class serves as the base class for all explicit steppers with algebra and operations. In contrast to + * explicit_stepper_base it also estimates the error and can be used in a controlled stepper to provide + * step size control. + * + * \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_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 , xerr )`. + * explicit_error_stepper_base derives from algebra_stepper_base. + * + * explicit_error_stepper_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 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 in-place, but the derivative at the point `t` + * must be explicitly passed in `dxdt`. + * - `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 , 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. + * - `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 in-place, but the derivative at the + * point `t` must be passed in `dxdt`. 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 , t , out , dt , xerr )` - This methods updates the state out-of-place and estimates + * the error during the step. Furthermore, the derivative at `t` must be passed in `dxdt`. + * + * \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 );` + * + * \note The time `t` is not advanced by the stepper. This has to done manually, or by the appropriate `integrate` + * routines or `iterator`s. + * + * \tparam Stepper The stepper on which this class should work. It is used via CRTP, hence explicit_stepper_base + * provides the interface for the Stepper. + * \tparam Order The order of a stepper if the stepper is used without error estimation. + * \tparam StepperOrder The order of a step if the stepper is used with error estimation. Usually Order and StepperOrder have + * the same value. + * \tparam ErrorOrder The order of the error step if the stepper is used with error estimation. + * \tparam State The state type for the stepper. + * \tparam 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. + * \tparam 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. + * \tparam 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. + * \tparam Algebra The algebra type which must fulfill the Algebra Concept. + * \tparam Operations The type for the operations which must fulfill the Operations Concept. + * \tparam Resizer The resizer policy class. + */ + + + /** + * \fn explicit_error_stepper_base::explicit_error_stepper_base( const algebra_type &algebra = algebra_type() ) + * + * \brief Constructs a explicit_error_stepper_base class. This constructor can be used as a default + * constructor if the algebra has a default constructor. + * \param algebra A copy of algebra is made and stored inside explicit_stepper_base. + */ + + /** + * \fn explicit_error_stepper_base::order( void ) const + * \return Returns the order of the stepper if it used without error estimation. + */ + + /** + * \fn explicit_error_stepper_base::stepper_order( void ) const + * \return Returns the order of a step if the stepper is used without error estimation. + */ + + /** + * \fn explicit_error_stepper_base::error_order( void ) const + * \return Returns the order of an error step if the stepper is used without error estimation. + */ + + /** + * \fn explicit_error_stepper_base::do_step( System system , StateInOut &x , time_type t , time_type dt ) + * \brief This method performs one step. It transforms the result in-place. + * + * \param system The system function to solve, hence the r.h.s. of the ordinary differential equation. It must fulfill the + * Simple System concept. + * \param x The state of the ODE which should be solved. After calling do_step the result is updated in x. + * \param t The value of the time, at which the step should be performed. + * \param dt The step size. + */ + + /** + * \fn explicit_error_stepper_base::do_step( System system , StateInOut &x , const DerivIn &dxdt , time_type t , time_type dt ) + * \brief 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. It is supposed to be used in the following way: + * + * \code + * sys( x , dxdt , t ); + * stepper.do_step( sys , x , dxdt , t , dt ); + * \endcode + * + * 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. + * + * \param system The system function to solve, hence the r.h.s. of the ODE. It must fulfill the + * Simple System concept. + * \param x The state of the ODE which should be solved. After calling do_step the result is updated in x. + * \param dxdt The derivative of x at t. + * \param t The value of the time, at which the step should be performed. + * \param dt The step size. + */ + + /** + * \fn explicit_error_stepper_base::do_step( System system , const StateIn &in , time_type t , StateOut &out , time_type dt ) + * \brief 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 This method does not solve the forwarding problem. + * + * \param system The system function to solve, hence the r.h.s. of the ODE. It must fulfill the + * Simple System concept. + * \param in The state of the ODE which should be solved. in is not modified in this method + * \param t The value of the time, at which the step should be performed. + * \param out The result of the step is written in out. + * \param dt The step size. + */ + + + /** + * \fn explicit_error_stepper_base::do_step( System system , const StateIn &in , const DerivIn &dxdt , time_type t , StateOut &out , time_type dt ) + * \brief 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. It is supposed to be used in the following way: + * + * \code + * sys( in , dxdt , t ); + * stepper.do_step( sys , in , dxdt , t , out , dt ); + * \endcode + * + * This method is disabled if DerivIn and Time are of same type. + * + * \note This method does not solve the forwarding problem. + * + * \param system The system function to solve, hence the r.h.s. of the ODE. It must fulfill the + * Simple System concept. + * \param in The state of the ODE which should be solved. in is not modified in this method + * \param dxdt The derivative of x at t. + * \param t The value of the time, at which the step should be performed. + * \param out The result of the step is written in out. + * \param dt The step size. + */ + + /** + * \fn explicit_error_stepper_base::do_step( System system , StateInOut &x , time_type t , time_type dt , Err &xerr ) + * \brief The method performs one step with the stepper passed by Stepper and estimates the error. The state of the ODE + * is updated in-place. + * + * \param system The system function to solve, hence the r.h.s. of the ODE. It must fulfill the + * Simple System concept. + * \param x The state of the ODE which should be solved. x is updated by this method. + * \param t The value of the time, at which the step should be performed. + * \param dt The step size. + * \param xerr The estimation of the error is stored in xerr. + */ + + /** + * \fn explicit_error_stepper_base::do_step( System system , StateInOut &x , const DerivIn &dxdt , time_type t , time_type dt , Err &xerr ) + * \brief 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. It is supposed to be used in the following way: + * + * \code + * sys( x , dxdt , t ); + * stepper.do_step( sys , x , dxdt , t , dt , xerr ); + * \endcode + * + * The result is updated in place in x. This method is disabled if Time and DerivIn 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. + * + * \param system The system function to solve, hence the r.h.s. of the ODE. It must fulfill the + * Simple System concept. + * \param x The state of the ODE which should be solved. After calling do_step the result is updated in x. + * \param dxdt The derivative of x at t. + * \param t The value of the time, at which the step should be performed. + * \param dt The step size. + * \param xerr The error estimate is stored in xerr. + */ + + /** + * \fn explicit_error_stepper_base::do_step( System system , const StateIn &in , time_type t , StateOut &out , time_type dt , Err &xerr ) + * \brief 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 This method does not solve the forwarding problem. + * + * \param system The system function to solve, hence the r.h.s. of the ODE. It must fulfill the + * Simple System concept. + * \param in The state of the ODE which should be solved. in is not modified in this method + * \param t The value of the time, at which the step should be performed. + * \param out The result of the step is written in out. + * \param dt The step size. + * \param xerr The error estimate. + */ + + + /** + * \fn explicit_error_stepper_base::do_step( System system , const StateIn &in , const DerivIn &dxdt , time_type t , StateOut &out , time_type dt , Err &xerr ) + * \brief 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. It is supposed to be used in the following way: + * + * \code + * sys( in , dxdt , t ); + * stepper.do_step( sys , in , dxdt , t , out , dt ); + * \endcode + * + * This method is disabled if DerivIn and Time are of same type. + * + * \note This method does not solve the forwarding problem. + * + * \param system The system function to solve, hence the r.h.s. of the ODE. It must fulfill the + * Simple System concept. + * \param in The state of the ODE which should be solved. in is not modified in this method + * \param dxdt The derivative of x at t. + * \param t The value of the time, at which the step should be performed. + * \param out The result of the step is written in out. + * \param dt The step size. + * \param xerr The error estimate. + */ + + + /** + * \fn explicit_error_stepper_base::adjust_size( const StateIn &x ) + * \brief Adjust the size of all temporaries in the stepper manually. + * \param x A state from which the size of the temporaries to be resized is deduced. + */ + +} // odeint +} // numeric +} // boost + +#endif // BOOST_NUMERIC_ODEINT_STEPPER_BASE_EXPLICIT_ERROR_STEPPER_BASE_HPP_INCLUDED diff --git a/boost/numeric/odeint/stepper/base/explicit_error_stepper_fsal_base.hpp b/boost/numeric/odeint/stepper/base/explicit_error_stepper_fsal_base.hpp new file mode 100644 index 0000000000..a055c7fa5f --- /dev/null +++ b/boost/numeric/odeint/stepper/base/explicit_error_stepper_fsal_base.hpp @@ -0,0 +1,659 @@ +/* + [auto_generated] + boost/numeric/odeint/stepper/base/explicit_error_stepper_fsal_base.hpp + + [begin_description] + Base class for all explicit first-same-as-last Runge Kutta steppers. + [end_description] + + Copyright 2010-2013 Karsten Ahnert + Copyright 2010-2012 Mario Mulansky + Copyright 2012 Christoph Koke + + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or + copy at http://www.boost.org/LICENSE_1_0.txt) + */ + + +#ifndef BOOST_NUMERIC_ODEINT_STEPPER_BASE_EXPLICIT_ERROR_STEPPER_FSAL_BASE_HPP_INCLUDED +#define BOOST_NUMERIC_ODEINT_STEPPER_BASE_EXPLICIT_ERROR_STEPPER_FSAL_BASE_HPP_INCLUDED + +#include <boost/utility/enable_if.hpp> +#include <boost/type_traits/is_same.hpp> + + +#include <boost/numeric/odeint/util/bind.hpp> +#include <boost/numeric/odeint/util/unwrap_reference.hpp> +#include <boost/numeric/odeint/util/state_wrapper.hpp> +#include <boost/numeric/odeint/util/is_resizeable.hpp> +#include <boost/numeric/odeint/util/resizer.hpp> +#include <boost/numeric/odeint/util/copy.hpp> + +#include <boost/numeric/odeint/stepper/stepper_categories.hpp> + +#include <boost/numeric/odeint/stepper/base/algebra_stepper_base.hpp> + +namespace boost { +namespace numeric { +namespace odeint { + +/* + * base class for explicit stepper and error steppers with the fsal property + * models the stepper AND the error stepper fsal concept + * + * this class provides the following do_step overloads + * do_step( sys , x , t , dt ) + * do_step( sys , x , dxdt , t , dt ) + * do_step( sys , in , t , out , dt ) + * do_step( sys , in , dxdt_in , t , out , dxdt_out , dt ) + * do_step( sys , x , t , dt , xerr ) + * do_step( sys , x , dxdt , t , dt , xerr ) + * do_step( sys , in , t , out , dt , xerr ) + * do_step( sys , in , dxdt_in , t , out , dxdt_out , dt , xerr ) + */ +template< +class Stepper , +unsigned short Order , +unsigned short StepperOrder , +unsigned short ErrorOrder , +class State , +class Value , +class Deriv , +class Time , +class Algebra , +class Operations , +class Resizer +> +class explicit_error_stepper_fsal_base : public algebra_stepper_base< Algebra , Operations > +{ +public: + + typedef algebra_stepper_base< Algebra , Operations > algebra_stepper_base_type; + typedef typename 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; + + #ifndef DOXYGEN_SKIP + typedef state_wrapper< state_type > wrapped_state_type; + typedef state_wrapper< deriv_type > wrapped_deriv_type; + typedef explicit_error_stepper_fsal_base< Stepper , Order , StepperOrder , ErrorOrder , + State , Value , Deriv , Time , Algebra , Operations , Resizer > internal_stepper_base_type; + #endif + + + typedef unsigned short order_type; + static const order_type order_value = Order; + static const order_type stepper_order_value = StepperOrder; + static const order_type error_order_value = ErrorOrder; + + explicit_error_stepper_fsal_base( const algebra_type &algebra = algebra_type() ) + : algebra_stepper_base_type( algebra ) , m_first_call( true ) + { } + + order_type order( void ) const + { + return order_value; + } + + order_type stepper_order( void ) const + { + return stepper_order_value; + } + + order_type error_order( void ) const + { + return error_order_value; + } + + + /* + * version 1 : do_step( sys , x , t , dt ) + * + * the two overloads are needed in order to solve the forwarding problem + */ + template< class System , class StateInOut > + void do_step( System system , StateInOut &x , time_type t , time_type dt ) + { + do_step_v1( system , x , t , dt ); + } + + /** + * \brief Second version to solve the forwarding problem, can be called with Boost.Range as StateInOut. + */ + template< class System , class StateInOut > + void do_step( System system , const StateInOut &x , time_type t , time_type dt ) + { + do_step_v1( system , x , t , dt ); + } + + + /* + * version 2 : do_step( sys , x , dxdt , t , dt ) + * + * this version does not solve the forwarding problem, boost.range can not be used + * + * the disable is needed to avoid ambiguous overloads if state_type = time_type + */ + template< class System , class StateInOut , class DerivInOut > + typename 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 ) + { + m_first_call = true; + this->stepper().do_step_impl( system , x , dxdt , t , x , dxdt , dt ); + } + + + /* + * version 3 : do_step( sys , in , t , out , dt ) + * + * this version does not solve the forwarding problem, boost.range can not be used + * + * the disable is needed to avoid ambiguous overloads if state_type = time_type + */ + template< class System , class StateIn , class StateOut > + typename 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 ) + { + if( m_resizer.adjust_size( in , detail::bind( &internal_stepper_base_type::template resize_impl< StateIn > , detail::ref( *this ) , detail::_1 ) ) || m_first_call ) + { + initialize( system , in , t ); + } + this->stepper().do_step_impl( system , in , m_dxdt.m_v , t , out , m_dxdt.m_v , dt ); + } + + + /* + * version 4 : do_step( sys , in , dxdt_in , t , out , dxdt_out , dt ) + * + * this version does not solve the forwarding problem, boost.range can not be used + */ + template< class System , class StateIn , class DerivIn , class StateOut , class DerivOut > + void do_step( System system , const StateIn &in , const DerivIn &dxdt_in , time_type t , + StateOut &out , DerivOut &dxdt_out , time_type dt ) + { + m_first_call = true; + this->stepper().do_step_impl( system , in , dxdt_in , t , out , dxdt_out , dt ); + } + + + + + + /* + * version 5 : do_step( sys , x , t , dt , xerr ) + * + * the two overloads are needed in order to solve the forwarding problem + */ + template< class System , class StateInOut , class Err > + void do_step( System system , StateInOut &x , time_type t , time_type dt , Err &xerr ) + { + do_step_v5( system , x , t , dt , xerr ); + } + + /** + * \brief Second version to solve the forwarding problem, can be called with Boost.Range as StateInOut. + */ + template< class System , class StateInOut , class Err > + void do_step( System system , const StateInOut &x , time_type t , time_type dt , Err &xerr ) + { + do_step_v5( system , x , t , dt , xerr ); + } + + + /* + * version 6 : do_step( sys , x , dxdt , t , dt , xerr ) + * + * this version does not solve the forwarding problem, boost.range can not be used + * + * the disable is needed to avoid ambiguous overloads if state_type = time_type + */ + template< class System , class StateInOut , class DerivInOut , class Err > + typename 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 ) + { + m_first_call = true; + this->stepper().do_step_impl( system , x , dxdt , t , x , dxdt , dt , xerr ); + } + + + + + /* + * version 7 : do_step( sys , in , t , out , dt , xerr ) + * + * this version does not solve the forwarding problem, boost.range can not be used + */ + template< class System , class StateIn , class StateOut , class Err > + void do_step( System system , const StateIn &in , time_type t , StateOut &out , time_type dt , Err &xerr ) + { + if( m_resizer.adjust_size( in , detail::bind( &internal_stepper_base_type::template resize_impl< StateIn > , detail::ref( *this ) , detail::_1 ) ) || m_first_call ) + { + initialize( system , in , t ); + } + this->stepper().do_step_impl( system , in , m_dxdt.m_v , t , out , m_dxdt.m_v , dt , xerr ); + } + + + /* + * version 8 : do_step( sys , in , dxdt_in , t , out , dxdt_out , dt , xerr ) + * + * this version does not solve the forwarding problem, boost.range can not be used + */ + template< class System , class StateIn , class DerivIn , class StateOut , class DerivOut , class 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 ) + { + m_first_call = true; + this->stepper().do_step_impl( system , in , dxdt_in , t , out , dxdt_out , dt , xerr ); + } + + template< class StateIn > + void adjust_size( const StateIn &x ) + { + resize_impl( x ); + } + + void reset( void ) + { + m_first_call = true; + } + + template< class DerivIn > + void initialize( const DerivIn &deriv ) + { + boost::numeric::odeint::copy( deriv , m_dxdt.m_v ); + m_first_call = false; + } + + template< class System , class StateIn > + void initialize( System system , const StateIn &x , time_type t ) + { + typename odeint::unwrap_reference< System >::type &sys = system; + sys( x , m_dxdt.m_v , t ); + m_first_call = false; + } + + bool is_initialized( void ) const + { + return ! m_first_call; + } + + + +private: + + template< class System , class StateInOut > + void do_step_v1( System system , StateInOut &x , time_type t , time_type dt ) + { + if( m_resizer.adjust_size( x , detail::bind( &internal_stepper_base_type::template resize_impl< StateInOut > , detail::ref( *this ) , detail::_1 ) ) || m_first_call ) + { + initialize( system , x , t ); + } + this->stepper().do_step_impl( system , x , m_dxdt.m_v , t , x , m_dxdt.m_v , dt ); + } + + template< class System , class StateInOut , class Err > + void do_step_v5( System system , StateInOut &x , time_type t , time_type dt , Err &xerr ) + { + if( m_resizer.adjust_size( x , detail::bind( &internal_stepper_base_type::template resize_impl< StateInOut > , detail::ref( *this ) , detail::_1 ) ) || m_first_call ) + { + initialize( system , x , t ); + } + this->stepper().do_step_impl( system , x , m_dxdt.m_v , t , x , m_dxdt.m_v , dt , xerr ); + } + + template< class StateIn > + bool resize_impl( const StateIn &x ) + { + return adjust_size_by_resizeability( m_dxdt , x , typename is_resizeable<deriv_type>::type() ); + } + + + stepper_type& stepper( void ) + { + return *static_cast< stepper_type* >( this ); + } + + const stepper_type& stepper( void ) const + { + return *static_cast< const stepper_type* >( this ); + } + + + resizer_type m_resizer; + bool m_first_call; + +protected: + + + wrapped_deriv_type m_dxdt; +}; + + +/******* DOXYGEN *******/ + +/** + * \class explicit_error_stepper_fsal_base + * \brief 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. + * + * 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 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 + * + * \code + * 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 ); + * \endcode + * + * 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 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 );` + * + * \note The time `t` is not advanced by the stepper. This has to done manually, or by the appropriate `integrate` + * routines or `iterator`s. + * + * \tparam Stepper The stepper on which this class should work. It is used via CRTP, hence explicit_stepper_base + * provides the interface for the Stepper. + * \tparam Order The order of a stepper if the stepper is used without error estimation. + * \tparam StepperOrder The order of a step if the stepper is used with error estimation. Usually Order and StepperOrder have + * the same value. + * \tparam ErrorOrder The order of the error step if the stepper is used with error estimation. + * \tparam State The state type for the stepper. + * \tparam 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. + * \tparam 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. + * \tparam 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. + * \tparam Algebra The algebra type which must fulfill the Algebra Concept. + * \tparam Operations The type for the operations which must fulfill the Operations Concept. + * \tparam Resizer The resizer policy class. + */ + + + + /** + * \fn explicit_error_stepper_fsal_base::explicit_error_stepper_fsal_base( const algebra_type &algebra ) + * \brief Constructs a explicit_stepper_fsal_base class. This constructor can be used as a default + * constructor if the algebra has a default constructor. + * \param algebra A copy of algebra is made and stored inside explicit_stepper_base. + */ + + + /** + * \fn explicit_error_stepper_fsal_base::order( void ) const + * \return Returns the order of the stepper if it used without error estimation. + */ + + /** + * \fn explicit_error_stepper_fsal_base::stepper_order( void ) const + * \return Returns the order of a step if the stepper is used without error estimation. + */ + + + /** + * \fn explicit_error_stepper_fsal_base::error_order( void ) const + * \return Returns the order of an error step if the stepper is used without error estimation. + */ + + /** + * \fn explicit_error_stepper_fsal_base::do_step( System system , StateInOut &x , time_type t , time_type dt ) + * \brief This method performs one step. It transforms the result in-place. + * + * \note This method uses the internal state of the stepper. + * + * \param system The system function to solve, hence the r.h.s. of the ordinary differential equation. It must fulfill the + * Simple System concept. + * \param x The state of the ODE which should be solved. After calling do_step the result is updated in x. + * \param t The value of the time, at which the step should be performed. + * \param dt The step size. + */ + + + /** + * \fn explicit_error_stepper_fsal_base::do_step( System system , StateInOut &x , DerivInOut &dxdt , time_type t , time_type dt ) + * \brief 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: + * + * \code + * ode( x , dxdt , t ); + * for( ... ) + * { + * stepper.do_step( ode , x , dxdt , t , dt ); + * t += dt; + * } + * \endcode + * + * \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 This method does not solve the forwarding problem. + * + * \param system The system function to solve, hence the r.h.s. of the ODE. It must fulfill the + * Simple System concept. + * \param x The state of the ODE which should be solved. After calling do_step the result is updated in x. + * \param dxdt The derivative of x at t. After calling `do_step` dxdt is updated to the new value. + * \param t The value of the time, at which the step should be performed. + * \param dt The step size. + */ + + /** + * \fn explicit_error_stepper_fsal_base::do_step( System system , const StateIn &in , time_type t , StateOut &out , time_type dt ) + * \brief 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 This method uses the internal state of the stepper. + * + * \note This method does not solve the forwarding problem. + * + * \param system The system function to solve, hence the r.h.s. of the ODE. It must fulfill the + * Simple System concept. + * \param in The state of the ODE which should be solved. in is not modified in this method + * \param t The value of the time, at which the step should be performed. + * \param out The result of the step is written in out. + * \param dt The step size. + */ + + /** + * \fn explicit_error_stepper_fsal_base::do_step( System system , const StateIn &in , const DerivIn &dxdt_in , time_type t , StateOut &out , DerivOut &dxdt_out , time_type dt ) + * \brief 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 This method does not solve the forwarding problem. + * + * \note This method does NOT use the internal state of the stepper. + * + * \param system The system function to solve, hence the r.h.s. of the ODE. It must fulfill the + * Simple System concept. + * \param in The state of the ODE which should be solved. in is not modified in this method + * \param dxdt_in The derivative of x at t. + * \param t The value of the time, at which the step should be performed. + * \param out The result of the step is written in out. + * \param dxdt_out The updated derivative of `out` at `t+dt`. + * \param dt The step size. + */ + + /** + * \fn explicit_error_stepper_fsal_base::do_step( System system , StateInOut &x , time_type t , time_type dt , Err &xerr ) + * \brief 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 This method uses the internal state of the stepper. + * + * \param system The system function to solve, hence the r.h.s. of the ODE. It must fulfill the + * Simple System concept. + * \param x The state of the ODE which should be solved. x is updated by this method. + * \param t The value of the time, at which the step should be performed. + * \param dt The step size. + * \param xerr The estimation of the error is stored in xerr. + */ + + /** + * \fn explicit_error_stepper_fsal_base::do_step( System system , StateInOut &x , DerivInOut &dxdt , time_type t , time_type dt , Err &xerr ) + * \brief 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 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 This method does NOT use the internal state of the stepper. + * + * \note This method does not solve the forwarding problem. + * + * \param system The system function to solve, hence the r.h.s. of the ODE. It must fulfill the + * Simple System concept. + * \param x The state of the ODE which should be solved. After calling do_step the result is updated in x. + * \param dxdt The derivative of x at t. After calling `do_step` this value is updated to the new value at `t+dt`. + * \param t The value of the time, at which the step should be performed. + * \param dt The step size. + * \param xerr The error estimate is stored in xerr. + */ + + + /** + * \fn explicit_error_stepper_fsal_base::do_step( System system , const StateIn &in , time_type t , StateOut &out , time_type dt , Err &xerr ) + * \brief 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 This method uses the internal state of the stepper. + * + * \note This method does not solve the forwarding problem. + * + * \param system The system function to solve, hence the r.h.s. of the ODE. It must fulfill the + * Simple System concept. + * \param in The state of the ODE which should be solved. in is not modified in this method + * \param t The value of the time, at which the step should be performed. + * \param out The result of the step is written in out. + * \param dt The step size. + * \param xerr The error estimate. + */ + + /** + * \fn explicit_error_stepper_fsal_base::do_step( System system , const StateIn &in , const DerivIn &dxdt_in , time_type t , StateOut &out , DerivOut &dxdt_out , time_type dt , Err &xerr ) + * \brief 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 This method does NOT use the internal state of the stepper. + * + * \note This method does not solve the forwarding problem. + * + * \param system The system function to solve, hence the r.h.s. of the ODE. It must fulfill the + * Simple System concept. + * \param in The state of the ODE which should be solved. in is not modified in this method + * \param dxdt_in The derivative of x at t. + * \param t The value of the time, at which the step should be performed. + * \param out The result of the step is written in out. + * \param dxdt_out The new derivative at `t+dt` is written into this variable. + * \param dt The step size. + * \param xerr The error estimate. + */ + + /** + * \fn explicit_error_stepper_fsal_base::adjust_size( const StateIn &x ) + * \brief Adjust the size of all temporaries in the stepper manually. + * \param x A state from which the size of the temporaries to be resized is deduced. + */ + + /** + * \fn explicit_error_stepper_fsal_base::reset( void ) + * \brief 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. + */ + + /** + * \fn explicit_error_stepper_fsal_base::initialize( const DerivIn &deriv ) + * \brief Initializes the internal state of the stepper. + * \param 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`. + */ + + /** + * \fn explicit_error_stepper_fsal_base::initialize( System system , const StateIn &x , time_type t ) + * \brief Initializes the internal state of the stepper. + * + * This method is equivalent to + * \code + * Deriv dxdt; + * system( x , dxdt , t ); + * stepper.initialize( dxdt ); + * \endcode + * + * \param system The system function for the next calls of `do_step`. + * \param x The current state of the ODE. + * \param t The current time of the ODE. + */ + + /** + * \fn explicit_error_stepper_fsal_base::is_initialized( void ) const + * \brief 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. + */ + +} // odeint +} // numeric +} // boost + +#endif // BOOST_NUMERIC_ODEINT_STEPPER_BASE_EXPLICIT_ERROR_STEPPER_FSAL_BASE_HPP_INCLUDED diff --git a/boost/numeric/odeint/stepper/base/explicit_stepper_base.hpp b/boost/numeric/odeint/stepper/base/explicit_stepper_base.hpp new file mode 100644 index 0000000000..40aab80399 --- /dev/null +++ b/boost/numeric/odeint/stepper/base/explicit_stepper_base.hpp @@ -0,0 +1,384 @@ +/* + [auto_generated] + boost/numeric/odeint/stepper/base/explicit_stepper_base.hpp + + [begin_description] + Base class for all explicit Runge Kutta steppers. + [end_description] + + Copyright 2010-2013 Karsten Ahnert + Copyright 2010-2012 Mario Mulansky + Copyright 2012 Christoph Koke + + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or + copy at http://www.boost.org/LICENSE_1_0.txt) + */ + + +#ifndef BOOST_NUMERIC_ODEINT_STEPPER_BASE_EXPLICIT_STEPPER_BASE_HPP_INCLUDED +#define BOOST_NUMERIC_ODEINT_STEPPER_BASE_EXPLICIT_STEPPER_BASE_HPP_INCLUDED + + +#include <boost/utility/enable_if.hpp> +#include <boost/type_traits/is_same.hpp> + +#include <boost/numeric/odeint/util/bind.hpp> +#include <boost/numeric/odeint/util/unwrap_reference.hpp> + +#include <boost/numeric/odeint/util/state_wrapper.hpp> +#include <boost/numeric/odeint/util/resizer.hpp> +#include <boost/numeric/odeint/util/is_resizeable.hpp> + +#include <boost/numeric/odeint/stepper/stepper_categories.hpp> + +#include <boost/numeric/odeint/stepper/base/algebra_stepper_base.hpp> + +namespace boost { +namespace numeric { +namespace odeint { + +/* + * base class for explicit steppers + * models the stepper concept + * + * this class provides the following overloads + * do_step( sys , x , t , dt ) + * do_step( sys , in , t , out , dt ) + * do_step( sys , x , dxdt_in , t , dt ) + * do_step( sys , in , dxdt_in , t , out , dt ) + */ + +template< +class Stepper , +unsigned short Order , +class State , +class Value , +class Deriv , +class Time , +class Algebra , +class Operations , +class Resizer +> +class explicit_stepper_base : public algebra_stepper_base< Algebra , Operations > +{ +public: + + #ifndef DOXYGEN_SKIP + typedef explicit_stepper_base< Stepper , Order , State , Value , Deriv , Time , Algebra , Operations , Resizer > internal_stepper_base_type; + #endif // DOXYGEN_SKIP + + + 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 typename algebra_stepper_base_type::algebra_type algebra_type; + typedef typename algebra_stepper_base_type::operations_type operations_type; + typedef unsigned short order_type; + + #ifndef DOXYGEN_SKIP + typedef state_wrapper< state_type > wrapped_state_type; + typedef state_wrapper< deriv_type > wrapped_deriv_type; + #endif // DOXYGEN_SKIP + + + static const order_type order_value = Order; + + + explicit_stepper_base( const algebra_type &algebra = algebra_type() ) + : algebra_stepper_base_type( algebra ) + { } + + /** + * \return Returns the order of the stepper. + */ + order_type order( void ) const + { + return order_value; + } + + + /* + * Version 1 : do_step( sys , x , t , dt ) + * + * the two overloads are needed in order to solve the forwarding problem + */ + template< class System , class StateInOut > + void do_step( System system , StateInOut &x , time_type t , time_type dt ) + { + do_step_v1( system , x , t , dt ); + } + + /** + * \brief Second version to solve the forwarding problem, can be called with Boost.Range as StateInOut. + */ + template< class System , class StateInOut > + void do_step( System system , const StateInOut &x , time_type t , time_type dt ) + { + do_step_v1( system , x , t , dt ); + } + + /* + * Version 2 : do_step( sys , x , dxdt , t , dt ) + * + * this version does not solve the forwarding problem, boost.range can not be used + * + * the disable is needed to avoid ambiguous overloads if state_type = time_type + */ + template< class System , class StateInOut , class DerivIn > + typename 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 ) + { + this->stepper().do_step_impl( system , x , dxdt , t , x , dt ); + } + + + /* + * Version 3 : do_step( sys , in , t , out , dt ) + * + * this version does not solve the forwarding problem, boost.range can not be used + */ + template< class System , class StateIn , class StateOut > + void do_step( System system , const StateIn &in , time_type t , StateOut &out , time_type dt ) + { + typename odeint::unwrap_reference< System >::type &sys = system; + m_resizer.adjust_size( in , detail::bind( &internal_stepper_base_type::template resize_impl<StateIn> , detail::ref( *this ) , detail::_1 ) ); + sys( in , m_dxdt.m_v ,t ); + this->stepper().do_step_impl( system , in , m_dxdt.m_v , t , out , dt ); + } + + + /* + * Version 4 : do_step( sys , in , dxdt , t , out , dt ) + * + * this version does not solve the forwarding problem, boost.range can not be used + */ + template< class System , class StateIn , class DerivIn , class StateOut > + void do_step( System system , const StateIn &in , const DerivIn &dxdt , time_type t , StateOut &out , time_type dt ) + { + this->stepper().do_step_impl( system , in , dxdt , t , out , dt ); + } + + template< class StateIn > + void adjust_size( const StateIn &x ) + { + resize_impl( x ); + } + +private: + + stepper_type& stepper( void ) + { + return *static_cast< stepper_type* >( this ); + } + + const stepper_type& stepper( void ) const + { + return *static_cast< const stepper_type* >( this ); + } + + + template< class StateIn > + bool resize_impl( const StateIn &x ) + { + return adjust_size_by_resizeability( m_dxdt , x , typename is_resizeable<deriv_type>::type() ); + } + + + template< class System , class StateInOut > + void do_step_v1( System system , StateInOut &x , time_type t , time_type dt ) + { + typename odeint::unwrap_reference< System >::type &sys = system; + m_resizer.adjust_size( x , detail::bind( &internal_stepper_base_type::template resize_impl< StateInOut > , detail::ref( *this ) , detail::_1 ) ); + sys( x , m_dxdt.m_v ,t ); + this->stepper().do_step_impl( system , x , m_dxdt.m_v , t , x , dt ); + } + + + resizer_type m_resizer; + +protected: + + wrapped_deriv_type m_dxdt; +}; + + +/******* DOXYGEN *********/ + +/** + * \class explicit_stepper_base + * \brief Base class for explicit steppers without step size control and without dense output. + * + * 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 + * + * \code + * 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 ); + * } + * }; + * \endcode + * + * 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 + * + * \code + * sys( x , dxdt , t ); + * stepper.do_step( sys , x , dxdt , t , dt ); // the value of dxdt is used here + * t += dt; + * \endcode + * + * 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 `boost::ref` + * or `std::ref`, for example `stepper.do_step( boost::ref( sys ) , x , t , dt );` + * + * \note The time `t` is not advanced by the stepper. This has to done manually, or by the appropriate `integrate` routines or `iterator`s. + * + * \tparam Stepper The stepper on which this class should work. It is used via CRTP, hence explicit_stepper_base + * provides the interface for the Stepper. + * \tparam Order The order of the stepper. + * \tparam State The state type for the stepper. + * \tparam 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. + * \tparam 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. + * \tparam 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. + * \tparam Algebra The algebra type which must fulfill the Algebra Concept. + * \tparam Operations The type for the operations which must fulfill the Operations Concept. + * \tparam Resizer The resizer policy class. + */ + + + /** + * \fn explicit_stepper_base::explicit_stepper_base( const algebra_type &algebra ) + * \brief Constructs a explicit_stepper_base class. This constructor can be used as a default + * constructor if the algebra has a default constructor. + * \param algebra A copy of algebra is made and stored inside explicit_stepper_base. + */ + + /** + * \fn explicit_stepper_base::order_type order( void ) const + * \return Returns the order of the stepper. + */ + + /** + * \fn explicit_stepper_base::do_step( System system , StateInOut &x , time_type t , time_type dt ) + * \brief This method performs one step. It transforms the result in-place. + * + * \param system The system function to solve, hence the r.h.s. of the ordinary differential equation. It must fulfill the + * Simple System concept. + * \param x The state of the ODE which should be solved. After calling do_step the result is updated in x. + * \param t The value of the time, at which the step should be performed. + * \param dt The step size. + */ + + + /** + * \fn explicit_stepper_base::do_step( System system , StateInOut &x , const DerivIn &dxdt , time_type t , time_type dt ) + + * \brief 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: + * + * \code + * sys( x , dxdt , t ); + * stepper.do_step( sys , x , dxdt , t , dt ); + * \endcode + * + * 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. + * + * \param system The system function to solve, hence the r.h.s. of the ODE. It must fulfill the + * Simple System concept. + * \param x The state of the ODE which should be solved. After calling do_step the result is updated in x. + * \param dxdt The derivative of x at t. + * \param t The value of the time, at which the step should be performed. + * \param dt The step size. + */ + + /** + * \fn void explicit_stepper_base::do_step( System system , const StateIn &in , time_type t , StateOut &out , time_type dt ) + * \brief The method performs one step. The state of the ODE is updated out-of-place. + * \note This method does not solve the forwarding problem. + * + * \param system The system function to solve, hence the r.h.s. of the ODE. It must fulfill the + * Simple System concept. + * \param in The state of the ODE which should be solved. in is not modified in this method + * \param t The value of the time, at which the step should be performed. + * \param out The result of the step is written in out. + * \param dt The step size. + */ + + /** + * \fn void explicit_stepper_base::do_step( System system , const StateIn &in , const DerivIn &dxdt , time_type t , StateOut &out , time_type dt ) + * \brief 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: + * + * \code + * sys( in , dxdt , t ); + * stepper.do_step( sys , in , dxdt , t , out , dt ); + * \endcode + * + * \note This method does not solve the forwarding problem. + * + * \param system The system function to solve, hence the r.h.s. of the ODE. It must fulfill the + * Simple System concept. + * \param in The state of the ODE which should be solved. in is not modified in this method + * \param dxdt The derivative of x at t. + * \param t The value of the time, at which the step should be performed. + * \param out The result of the step is written in out. + * \param dt The step size. + */ + + /** + * \fn void explicit_stepper_base::adjust_size( const StateIn &x ) + * \brief Adjust the size of all temporaries in the stepper manually. + * \param x A state from which the size of the temporaries to be resized is deduced. + */ + +} // odeint +} // numeric +} // boost + +#endif // BOOST_NUMERIC_ODEINT_STEPPER_BASE_EXPLICIT_STEPPER_BASE_HPP_INCLUDED diff --git a/boost/numeric/odeint/stepper/base/symplectic_rkn_stepper_base.hpp b/boost/numeric/odeint/stepper/base/symplectic_rkn_stepper_base.hpp new file mode 100644 index 0000000000..ea3523e5bb --- /dev/null +++ b/boost/numeric/odeint/stepper/base/symplectic_rkn_stepper_base.hpp @@ -0,0 +1,431 @@ +/* + [auto_generated] + boost/numeric/odeint/stepper/base/symplectic_rkn_stepper_base.hpp + + [begin_description] + Base class for symplectic Runge-Kutta-Nystrom steppers. + [end_description] + + Copyright 2011-2013 Karsten Ahnert + Copyright 2011-2013 Mario Mulansky + Copyright 2012 Christoph Koke + + Distributed under the Boost Software License, Version 1.0. + (See accompanying file LICENSE_1_0.txt or + copy at http://www.boost.org/LICENSE_1_0.txt) + */ + + +#ifndef BOOST_NUMERIC_ODEINT_STEPPER_BASE_SYMPLECTIC_RKN_STEPPER_BASE_HPP_INCLUDED +#define BOOST_NUMERIC_ODEINT_STEPPER_BASE_SYMPLECTIC_RKN_STEPPER_BASE_HPP_INCLUDED + +#include <boost/array.hpp> + +#include <boost/numeric/odeint/util/bind.hpp> +#include <boost/numeric/odeint/util/unwrap_reference.hpp> + +#include <boost/numeric/odeint/util/copy.hpp> +#include <boost/numeric/odeint/util/is_pair.hpp> + +#include <boost/numeric/odeint/util/state_wrapper.hpp> +#include <boost/numeric/odeint/util/resizer.hpp> + +#include <boost/numeric/odeint/stepper/stepper_categories.hpp> + +#include <boost/numeric/odeint/stepper/base/algebra_stepper_base.hpp> + + + + +namespace boost { +namespace numeric { +namespace odeint { + + +template< +size_t NumOfStages , +unsigned short Order , +class Coor , +class Momentum , +class Value , +class CoorDeriv , +class MomentumDeriv , +class Time , +class Algebra , +class Operations , +class Resizer +> +class symplectic_nystroem_stepper_base : public algebra_stepper_base< Algebra , Operations > +{ + +public: + + typedef algebra_stepper_base< Algebra , Operations > algebra_stepper_base_type; + typedef typename algebra_stepper_base_type::algebra_type algebra_type; + typedef typename algebra_stepper_base_type::operations_type operations_type; + + const static size_t num_of_stages = NumOfStages; + typedef Coor coor_type; + typedef Momentum momentum_type; + typedef std::pair< coor_type , momentum_type > state_type; + typedef CoorDeriv coor_deriv_type; + typedef state_wrapper< coor_deriv_type> wrapped_coor_deriv_type; + typedef MomentumDeriv momentum_deriv_type; + typedef state_wrapper< momentum_deriv_type > wrapped_momentum_deriv_type; + typedef std::pair< coor_deriv_type , momentum_deriv_type > deriv_type; + typedef Value value_type; + typedef Time time_type; + typedef Resizer resizer_type; + typedef stepper_tag stepper_category; + + #ifndef DOXYGEN_SKIP + typedef symplectic_nystroem_stepper_base< NumOfStages , Order , Coor , Momentum , Value , + CoorDeriv , MomentumDeriv , Time , Algebra , Operations , Resizer > internal_stepper_base_type; + #endif + typedef unsigned short order_type; + + static const order_type order_value = Order; + + typedef boost::array< value_type , num_of_stages > coef_type; + + symplectic_nystroem_stepper_base( const coef_type &coef_a , const coef_type &coef_b , const algebra_type &algebra = algebra_type() ) + : algebra_stepper_base_type( algebra ) , m_coef_a( coef_a ) , m_coef_b( coef_b ) , + m_dqdt_resizer() , m_dpdt_resizer() , m_dqdt() , m_dpdt() + { } + + + order_type order( void ) const + { + return order_value; + } + + /* + * Version 1 : do_step( system , x , t , dt ) + * + * This version does not solve the forwarding problem, boost.range can not be used. + */ + template< class System , class StateInOut > + void do_step( System system , const StateInOut &state , time_type t , time_type dt ) + { + typedef typename odeint::unwrap_reference< System >::type system_type; + do_step_impl( system , state , t , state , dt , typename is_pair< system_type >::type() ); + } + + /** + * \brief Same function as above. It differs only in a different const specifier in order + * to solve the forwarding problem, can be used with Boost.Range. + */ + template< class System , class StateInOut > + void do_step( System system , StateInOut &state , time_type t , time_type dt ) + { + typedef typename odeint::unwrap_reference< System >::type system_type; + do_step_impl( system , state , t , state , dt , typename is_pair< system_type >::type() ); + } + + + + + /* + * Version 2 : do_step( system , q , p , t , dt ); + * + * For Convenience + * + * The two overloads are needed in order to solve the forwarding problem. + */ + template< class System , class CoorInOut , class MomentumInOut > + void do_step( System system , CoorInOut &q , MomentumInOut &p , time_type t , time_type dt ) + { + do_step( system , std::make_pair( detail::ref( q ) , detail::ref( p ) ) , t , dt ); + } + + /** + * \brief Same function as do_step( system , q , p , t , dt ). It differs only in a different const specifier in order + * to solve the forwarding problem, can be called with Boost.Range. + */ + template< class System , class CoorInOut , class MomentumInOut > + void do_step( System system , const CoorInOut &q , const MomentumInOut &p , time_type t , time_type dt ) + { + do_step( system , std::make_pair( detail::ref( q ) , detail::ref( p ) ) , t , dt ); + } + + + + + + /* + * Version 3 : do_step( system , in , t , out , dt ) + * + * The forwarding problem is not solved in this version + */ + template< class System , class StateIn , class StateOut > + void do_step( System system , const StateIn &in , time_type t , StateOut &out , time_type dt ) + { + typedef typename odeint::unwrap_reference< System >::type system_type; + do_step_impl( system , in , t , out , dt , typename is_pair< system_type >::type() ); + } + + + template< class StateType > + void adjust_size( const StateType &x ) + { + resize_dqdt( x ); + resize_dpdt( x ); + } + + /** \brief Returns the coefficients a. */ + const coef_type& coef_a( void ) const { return m_coef_a; } + + /** \brief Returns the coefficients b. */ + const coef_type& coef_b( void ) const { return m_coef_b; } + +private: + + // stepper for systems with function for dq/dt = f(p) and dp/dt = -f(q) + template< class System , class StateIn , class StateOut > + void do_step_impl( System system , const StateIn &in , time_type t , StateOut &out , time_type dt , boost::mpl::true_ ) + { + typedef typename odeint::unwrap_reference< System >::type system_type; + typedef typename odeint::unwrap_reference< typename system_type::first_type >::type coor_deriv_func_type; + typedef typename odeint::unwrap_reference< typename system_type::second_type >::type momentum_deriv_func_type; + system_type &sys = system; + coor_deriv_func_type &coor_func = sys.first; + momentum_deriv_func_type &momentum_func = sys.second; + + typedef typename odeint::unwrap_reference< StateIn >::type state_in_type; + typedef typename odeint::unwrap_reference< typename state_in_type::first_type >::type coor_in_type; + typedef typename odeint::unwrap_reference< typename state_in_type::second_type >::type momentum_in_type; + const state_in_type &state_in = in; + const coor_in_type &coor_in = state_in.first; + const momentum_in_type &momentum_in = state_in.second; + + typedef typename odeint::unwrap_reference< StateOut >::type state_out_type; + typedef typename odeint::unwrap_reference< typename state_out_type::first_type >::type coor_out_type; + typedef typename odeint::unwrap_reference< typename state_out_type::second_type >::type momentum_out_type; + state_out_type &state_out = out; + coor_out_type &coor_out = state_out.first; + momentum_out_type &momentum_out = state_out.second; + + m_dqdt_resizer.adjust_size( coor_in , detail::bind( &internal_stepper_base_type::template resize_dqdt< coor_in_type > , detail::ref( *this ) , detail::_1 ) ); + m_dpdt_resizer.adjust_size( momentum_in , detail::bind( &internal_stepper_base_type::template resize_dpdt< momentum_in_type > , detail::ref( *this ) , detail::_1 ) ); + + // ToDo: check sizes? + + for( size_t l=0 ; l<num_of_stages ; ++l ) + { + if( l == 0 ) + { + coor_func( momentum_in , m_dqdt.m_v ); + this->m_algebra.for_each3( coor_out , coor_in , m_dqdt.m_v , + typename operations_type::template scale_sum2< value_type , time_type >( 1.0 , m_coef_a[l] * dt ) ); + momentum_func( coor_out , m_dpdt.m_v ); + this->m_algebra.for_each3( momentum_out , momentum_in , m_dpdt.m_v , + typename operations_type::template scale_sum2< value_type , time_type >( 1.0 , m_coef_b[l] * dt ) ); + } + else + { + coor_func( momentum_out , m_dqdt.m_v ); + this->m_algebra.for_each3( coor_out , coor_out , m_dqdt.m_v , + typename operations_type::template scale_sum2< value_type , time_type >( 1.0 , m_coef_a[l] * dt ) ); + momentum_func( coor_out , m_dpdt.m_v ); + this->m_algebra.for_each3( momentum_out , momentum_out , m_dpdt.m_v , + typename operations_type::template scale_sum2< value_type , time_type >( 1.0 , m_coef_b[l] * dt ) ); + } + } + } + + + // stepper for systems with only function dp /dt = -f(q), dq/dt = p, time not required but still expected for compatibility reasons + template< class System , class StateIn , class StateOut > + void do_step_impl( System system , const StateIn &in , time_type /* t */ , StateOut &out , time_type dt , boost::mpl::false_ ) + { + typedef typename odeint::unwrap_reference< System >::type momentum_deriv_func_type; + momentum_deriv_func_type &momentum_func = system; + + typedef typename odeint::unwrap_reference< StateIn >::type state_in_type; + typedef typename odeint::unwrap_reference< typename state_in_type::first_type >::type coor_in_type; + typedef typename odeint::unwrap_reference< typename state_in_type::second_type >::type momentum_in_type; + const state_in_type &state_in = in; + const coor_in_type &coor_in = state_in.first; + const momentum_in_type &momentum_in = state_in.second; + + typedef typename odeint::unwrap_reference< StateOut >::type state_out_type; + typedef typename odeint::unwrap_reference< typename state_out_type::first_type >::type coor_out_type; + typedef typename odeint::unwrap_reference< typename state_out_type::second_type >::type momentum_out_type; + state_out_type &state_out = out; + coor_out_type &coor_out = state_out.first; + momentum_out_type &momentum_out = state_out.second; + + + // m_dqdt not required when called with momentum_func only - don't resize + // m_dqdt_resizer.adjust_size( coor_in , detail::bind( &internal_stepper_base_type::template resize_dqdt< coor_in_type > , detail::ref( *this ) , detail::_1 ) ); + m_dpdt_resizer.adjust_size( momentum_in , detail::bind( &internal_stepper_base_type::template resize_dpdt< momentum_in_type > , detail::ref( *this ) , detail::_1 ) ); + + + // ToDo: check sizes? + + // step 0 + this->m_algebra.for_each3( coor_out , coor_in , momentum_in , + typename operations_type::template scale_sum2< value_type , time_type >( 1.0 , m_coef_a[0] * dt ) ); + momentum_func( coor_out , m_dpdt.m_v ); + this->m_algebra.for_each3( momentum_out , momentum_in , m_dpdt.m_v , + typename operations_type::template scale_sum2< value_type , time_type >( 1.0 , m_coef_b[0] * dt ) ); + + for( size_t l=1 ; l<num_of_stages ; ++l ) + { + this->m_algebra.for_each3( coor_out , coor_out , momentum_out , + typename operations_type::template scale_sum2< value_type , time_type >( 1.0 , m_coef_a[l] * dt ) ); + momentum_func( coor_out , m_dpdt.m_v ); + this->m_algebra.for_each3( momentum_out , momentum_out , m_dpdt.m_v , + typename operations_type::template scale_sum2< value_type , time_type >( 1.0 , m_coef_b[l] * dt ) ); + } + } + + template< class StateIn > + bool resize_dqdt( const StateIn &x ) + { + return adjust_size_by_resizeability( m_dqdt , x , typename is_resizeable<coor_deriv_type>::type() ); + } + + template< class StateIn > + bool resize_dpdt( const StateIn &x ) + { + return adjust_size_by_resizeability( m_dpdt , x , typename is_resizeable<momentum_deriv_type>::type() ); + } + + + const coef_type m_coef_a; + const coef_type m_coef_b; + + resizer_type m_dqdt_resizer; + resizer_type m_dpdt_resizer; + wrapped_coor_deriv_type m_dqdt; + wrapped_momentum_deriv_type m_dpdt; + +}; + +/********* DOXYGEN *********/ + +/** + * \class symplectic_nystroem_stepper_base + * \brief Base class for all symplectic steppers of Nystroem type. + * + * This class is the base class for the symplectic Runge-Kutta-Nystroem steppers. Symplectic steppers are usually + * used to solve Hamiltonian systems and they conserve the phase space volume, see + * <a href="http://en.wikipedia.org/wiki/Symplectic_integrator">en.wikipedia.org/wiki/Symplectic_integrator</a>. + * Furthermore, the energy is conserved + * in average. In detail this class of steppers can be used to solve separable Hamiltonian systems which can be written + * in the form H(q,p) = H1(p) + H2(q). q is usually called the coordinate, while p is the momentum. The equations of motion + * are dq/dt = dH1/dp, dp/dt = -dH2/dq. + * + * ToDo : add formula for solver and explanation of the coefficients + * + * symplectic_nystroem_stepper_base uses odeints algebra and operation system. Step size and error estimation are not + * provided for this class of solvers. It derives from algebra_stepper_base. Several `do_step` variants are provided: + * + * - `do_step( sys , x , t , dt )` - The classical `do_step` method. The sys can be either a pair of function objects + * for the coordinate or the momentum part or one function object for the momentum part. `x` is a pair of coordinate + * and momentum. The state is updated in-place. + * - `do_step( sys , q , p , t , dt )` - This method is similar to the method above with the difference that the coordinate + * and the momentum are passed explicitly and not packed into a pair. + * - `do_step( sys , x_in , t , x_out , dt )` - This method transforms the state out-of-place. `x_in` and `x_out` are here pairs + * of coordinate and momentum. + * + * \tparam NumOfStages Number of stages. + * \tparam Order The order of the stepper. + * \tparam Coor The type representing the coordinates q. + * \tparam Momentum The type representing the coordinates p. + * \tparam Value The basic value type. Should be something like float, double or a high-precision type. + * \tparam CoorDeriv The type representing the time derivative of the coordinate dq/dt. + * \tparam MomemtnumDeriv The type representing the time derivative of the momentum dp/dt. + * \tparam Time The type representing the time t. + * \tparam Algebra The algebra. + * \tparam Operations The operations. + * \tparam Resizer The resizer policy. + */ + + /** + * \fn symplectic_nystroem_stepper_base::symplectic_nystroem_stepper_base( const coef_type &coef_a , const coef_type &coef_b , const algebra_type &algebra ) + * \brief Constructs a symplectic_nystroem_stepper_base class. The parameters of the specific Nystroem method and the + * algebra have to be passed. + * \param coef_a The coefficients a. + * \param coef_b The coefficients b. + * \param algebra A copy of algebra is made and stored inside explicit_stepper_base. + */ + + /** + * \fn symplectic_nystroem_stepper_base::order( void ) const + * \return Returns the order of the stepper. + */ + + /** + * \fn symplectic_nystroem_stepper_base::do_step( System system , const StateInOut &state , time_type t , time_type dt ) + * \brief This method performs one step. The system can be either a pair of two function object + * describing the momentum part and the coordinate part or one function object describing only + * the momentum part. In this case the coordinate is assumed to be trivial dq/dt = p. The state + * is updated in-place. + * + * \note boost::ref or std::ref can be used for the system as well as for the state. So, it is correct + * to write `stepper.do_step( make_pair( std::ref( fq ) , std::ref( fp ) ) , make_pair( std::ref( q ) , std::ref( p ) ) , t , dt )`. + * + * \note This method solves the forwarding problem. + * + * \param system The system, can be represented as a pair of two function object or one function object. See above. + * \param state The state of the ODE. It is a pair of Coor and Momentum. The state is updated in-place, therefore, the + * new value of the state will be written into this variable. + * \param t The time of the ODE. It is not advanced by this method. + * \param dt The time step. + */ + + /** + * \fn symplectic_nystroem_stepper_base::do_step( System system , CoorInOut &q , MomentumInOut &p , time_type t , time_type dt ) + * \brief This method performs one step. The system can be either a pair of two function object + * describing the momentum part and the coordinate part or one function object describing only + * the momentum part. In this case the coordinate is assumed to be trivial dq/dt = p. The state + * is updated in-place. + * + * \note boost::ref or std::ref can be used for the system. So, it is correct + * to write `stepper.do_step( make_pair( std::ref( fq ) , std::ref( fp ) ) , q , p , t , dt )`. + * + * \note This method solves the forwarding problem. + * + * \param system The system, can be represented as a pair of two function object or one function object. See above. + * \param q The coordinate of the ODE. It is updated in-place. Therefore, the new value of the coordinate will be written + * into this variable. + * \param p The momentum of the ODE. It is updated in-place. Therefore, the new value of the momentum will be written info + * this variable. + * \param t The time of the ODE. It is not advanced by this method. + * \param dt The time step. + */ + + /** + * \fn symplectic_nystroem_stepper_base::do_step( System system , const StateIn &in , time_type t , StateOut &out , time_type dt ) + * \brief This method performs one step. The system can be either a pair of two function object + * describing the momentum part and the coordinate part or one function object describing only + * the momentum part. In this case the coordinate is assumed to be trivial dq/dt = p. The state + * is updated out-of-place. + * + * \note boost::ref or std::ref can be used for the system. So, it is correct + * to write `stepper.do_step( make_pair( std::ref( fq ) , std::ref( fp ) ) , x_in , t , x_out , dt )`. + * + * \note This method NOT solve the forwarding problem. + * + * \param system The system, can be represented as a pair of two function object or one function object. See above. + * \param in The state of the ODE, which is a pair of coordinate and momentum. The state is updated out-of-place, therefore the + * new value is written into out + * \param t The time of the ODE. It is not advanced by this method. + * \param out The new state of the ODE. + * \param dt The time step. + */ + + /** + * \fn symplectic_nystroem_stepper_base::adjust_size( const StateType &x ) + * \brief Adjust the size of all temporaries in the stepper manually. + * \param x A state from which the size of the temporaries to be resized is deduced. + */ + +} // namespace odeint +} // namespace numeric +} // namespace boost + + +#endif // BOOST_NUMERIC_ODEINT_STEPPER_BASE_SYMPLECTIC_RKN_STEPPER_BASE_HPP_INCLUDED |