Chris@16: /* Chris@16: [auto_generated] Chris@16: boost/numeric/odeint/stepper/explicit_generic_rk.hpp Chris@16: Chris@16: [begin_description] Chris@16: Implementation of the generic Runge-Kutta steppers. This is the base class for many Runge-Kutta steppers. Chris@16: [end_description] Chris@16: Chris@101: Copyright 2011-2013 Mario Mulansky Chris@101: Copyright 2011-2013 Karsten Ahnert Chris@101: Copyright 2012 Christoph Koke Chris@16: Chris@16: Distributed under the Boost Software License, Version 1.0. Chris@16: (See accompanying file LICENSE_1_0.txt or Chris@16: copy at http://www.boost.org/LICENSE_1_0.txt) Chris@16: */ Chris@16: Chris@16: Chris@16: #ifndef BOOST_NUMERIC_ODEINT_STEPPER_EXPLICIT_GENERIC_RK_HPP_INCLUDED Chris@16: #define BOOST_NUMERIC_ODEINT_STEPPER_EXPLICIT_GENERIC_RK_HPP_INCLUDED Chris@16: Chris@16: Chris@16: #include Chris@16: Chris@16: Chris@16: #include Chris@16: #include Chris@16: #include Chris@101: #include Chris@101: #include Chris@16: #include Chris@16: Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: Chris@16: namespace boost { Chris@16: namespace numeric { Chris@16: namespace odeint { Chris@16: Chris@16: //forward declarations Chris@16: Chris@16: #ifndef DOXYGEN_SKIP Chris@16: template< Chris@16: size_t StageCount, Chris@16: size_t Order, Chris@16: class State , Chris@16: class Value = double , Chris@16: class Deriv = State , Chris@16: class Time = Value , Chris@101: class Algebra = typename algebra_dispatcher< State >::algebra_type , Chris@101: class Operations = typename operations_dispatcher< State >::operations_type , Chris@16: class Resizer = initially_resizer Chris@16: > Chris@16: class explicit_generic_rk; Chris@16: Chris@16: Chris@16: struct stage_vector; Chris@16: Chris@16: template< class T , class Constant > Chris@16: struct array_wrapper Chris@16: { Chris@16: typedef const typename boost::array< T , Constant::value > type; Chris@16: }; Chris@16: Chris@16: template< class T , size_t i > Chris@16: struct stage Chris@16: { Chris@16: T c; Chris@16: boost::array< T , i > a; Chris@16: }; Chris@16: Chris@16: Chris@16: template< class T , class Constant > Chris@16: struct stage_wrapper Chris@16: { Chris@16: typedef stage< T , Constant::value > type; Chris@16: }; Chris@16: #endif Chris@16: Chris@16: Chris@16: template< Chris@16: size_t StageCount, Chris@16: size_t Order, Chris@16: class State , Chris@16: class Value , Chris@16: class Deriv , Chris@16: class Time , Chris@16: class Algebra , Chris@16: class Operations , Chris@16: class Resizer Chris@16: > Chris@16: #ifndef DOXYGEN_SKIP Chris@16: class explicit_generic_rk : public explicit_stepper_base< Chris@16: explicit_generic_rk< StageCount , Order , State , Value , Deriv , Time , Algebra , Operations , Resizer > , Chris@16: Order , State , Value , Deriv , Time , Algebra , Operations , Resizer > Chris@16: #else Chris@16: class explicit_generic_rk : public explicit_stepper_base Chris@16: #endif Chris@16: { Chris@16: Chris@16: public: Chris@16: Chris@16: #ifndef DOXYGEN_SKIP Chris@16: typedef explicit_stepper_base< Chris@16: explicit_generic_rk< StageCount , Order , State , Value , Deriv ,Time , Algebra , Operations , Resizer > , Chris@16: Order , State , Value , Deriv , Time , Algebra , Chris@16: Operations , Resizer > stepper_base_type; Chris@16: #else Chris@16: typedef explicit_stepper_base< ... > stepper_base_type; Chris@16: #endif Chris@16: Chris@16: typedef typename stepper_base_type::state_type state_type; Chris@16: typedef typename stepper_base_type::wrapped_state_type wrapped_state_type; Chris@16: typedef typename stepper_base_type::value_type value_type; Chris@16: typedef typename stepper_base_type::deriv_type deriv_type; Chris@16: typedef typename stepper_base_type::wrapped_deriv_type wrapped_deriv_type; Chris@16: typedef typename stepper_base_type::time_type time_type; Chris@16: typedef typename stepper_base_type::algebra_type algebra_type; Chris@16: typedef typename stepper_base_type::operations_type operations_type; Chris@16: typedef typename stepper_base_type::resizer_type resizer_type; Chris@16: Chris@16: #ifndef DOXYGEN_SKIP Chris@16: typedef explicit_generic_rk< StageCount , Order , State , Value , Deriv ,Time , Algebra , Operations , Resizer > stepper_type; Chris@16: #endif Chris@16: Chris@16: typedef detail::generic_rk_algorithm< StageCount , Value , Algebra , Operations > rk_algorithm_type; Chris@16: Chris@16: typedef typename rk_algorithm_type::coef_a_type coef_a_type; Chris@16: typedef typename rk_algorithm_type::coef_b_type coef_b_type; Chris@16: typedef typename rk_algorithm_type::coef_c_type coef_c_type; Chris@16: Chris@16: #ifndef DOXYGEN_SKIP Chris@16: static const size_t stage_count = StageCount; Chris@16: #endif Chris@16: Chris@16: public: Chris@16: Chris@16: explicit_generic_rk( const coef_a_type &a , const coef_b_type &b , const coef_c_type &c , Chris@16: const algebra_type &algebra = algebra_type() ) Chris@16: : stepper_base_type( algebra ) , m_rk_algorithm( a , b , c ) Chris@16: { } Chris@16: Chris@16: Chris@16: template< class System , class StateIn , class DerivIn , class StateOut > Chris@16: void do_step_impl( System system , const StateIn &in , const DerivIn &dxdt , Chris@16: time_type t , StateOut &out , time_type dt ) Chris@16: { Chris@16: m_resizer.adjust_size( in , detail::bind( &stepper_type::template resize_impl< StateIn > , detail::ref( *this ) , detail::_1 ) ); Chris@16: Chris@16: // actual calculation done in generic_rk.hpp Chris@16: m_rk_algorithm.do_step( stepper_base_type::m_algebra , system , in , dxdt , t , out , dt , m_x_tmp.m_v , m_F ); Chris@16: } Chris@16: Chris@16: template< class StateIn > Chris@16: void adjust_size( const StateIn &x ) Chris@16: { Chris@16: resize_impl( x ); Chris@16: stepper_base_type::adjust_size( x ); Chris@16: } Chris@16: Chris@16: private: Chris@16: Chris@16: template< class StateIn > Chris@16: bool resize_impl( const StateIn &x ) Chris@16: { Chris@16: bool resized( false ); Chris@16: resized |= adjust_size_by_resizeability( m_x_tmp , x , typename is_resizeable::type() ); Chris@16: for( size_t i = 0 ; i < StageCount-1 ; ++i ) Chris@16: { Chris@16: resized |= adjust_size_by_resizeability( m_F[i] , x , typename is_resizeable::type() ); Chris@16: } Chris@16: return resized; Chris@16: } Chris@16: Chris@16: Chris@16: rk_algorithm_type m_rk_algorithm; Chris@16: Chris@16: resizer_type m_resizer; Chris@16: Chris@16: wrapped_state_type m_x_tmp; Chris@16: wrapped_deriv_type m_F[StageCount-1]; Chris@16: Chris@16: }; Chris@16: Chris@16: Chris@16: Chris@16: /*********** DOXYGEN *************/ Chris@16: Chris@16: /** Chris@16: * \class explicit_generic_rk Chris@16: * \brief A generic implementation of explicit Runge-Kutta algorithms. This class is as a base class Chris@16: * for all explicit Runge-Kutta steppers. Chris@16: * Chris@16: * This class implements the explicit Runge-Kutta algorithms without error estimation in a generic way. Chris@16: * The Butcher tableau is passed to the stepper which constructs the stepper scheme with the help of a Chris@16: * template-metaprogramming algorithm. ToDo : Add example! Chris@16: * Chris@16: * This class derives explicit_stepper_base which provides the stepper interface. Chris@16: * Chris@16: * \tparam StageCount The number of stages of the Runge-Kutta algorithm. Chris@16: * \tparam Order The order of the stepper. Chris@16: * \tparam State The type representing the state of the ODE. Chris@16: * \tparam Value The floating point type which is used in the computations. Chris@16: * \tparam Time The type representing the independent variable - the time - of the ODE. Chris@16: * \tparam Algebra The algebra type. Chris@16: * \tparam Operations The operations type. Chris@16: * \tparam Resizer The resizer policy type. Chris@16: */ Chris@16: Chris@16: /** Chris@16: * \fn explicit_generic_rk::explicit_generic_rk( const coef_a_type &a , const coef_b_type &b , const coef_c_type &c , const algebra_type &algebra ) Chris@16: * \brief Constructs the explicit_generic_rk class. See examples section for details on the coefficients. Chris@16: * \param a Triangular matrix of parameters b in the Butcher tableau. Chris@16: * \param b Last row of the butcher tableau. Chris@16: * \param c Parameters to calculate the time points in the Butcher tableau. Chris@16: * \param algebra A copy of algebra is made and stored inside explicit_stepper_base. Chris@16: */ Chris@16: Chris@16: /** Chris@16: * \fn explicit_generic_rk::do_step_impl( System system , const StateIn &in , const DerivIn &dxdt , time_type t , StateOut &out , time_type dt ) Chris@16: * \brief This method performs one step. The derivative `dxdt` of `in` at the time `t` is passed to the method. Chris@16: * The result is updated out of place, hence the input is in `in` and the output in `out`. Chris@16: * Access to this step functionality is provided by explicit_stepper_base and Chris@16: * `do_step_impl` should not be called directly. Chris@16: * Chris@16: * \param system The system function to solve, hence the r.h.s. of the ODE. It must fulfill the Chris@16: * Simple System concept. Chris@16: * \param in The state of the ODE which should be solved. in is not modified in this method Chris@16: * \param dxdt The derivative of x at t. Chris@16: * \param t The value of the time, at which the step should be performed. Chris@16: * \param out The result of the step is written in out. Chris@16: * \param dt The step size. Chris@16: */ Chris@16: Chris@16: Chris@16: /** Chris@16: * \fn explicit_generic_rk::adjust_size( const StateIn &x ) Chris@16: * \brief Adjust the size of all temporaries in the stepper manually. Chris@16: * \param x A state from which the size of the temporaries to be resized is deduced. Chris@16: */ Chris@16: Chris@16: } Chris@16: } Chris@16: } Chris@16: #endif // BOOST_NUMERIC_ODEINT_STEPPER_EXPLICIT_GENERIC_RK_HPP_INCLUDED