Chris@16: /* Chris@16: [auto_generated] Chris@16: boost/numeric/odeint/stepper/runge_kutta4.hpp Chris@16: Chris@16: [begin_description] Chris@16: Implementation of the classical Runge-Kutta stepper with the generic stepper. Chris@16: [end_description] Chris@16: Chris@101: Copyright 2011-2013 Mario Mulansky Chris@101: Copyright 2011-2013 Karsten Ahnert 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_RUNGE_KUTTA4_HPP_INCLUDED Chris@16: #define BOOST_NUMERIC_ODEINT_STEPPER_RUNGE_KUTTA4_HPP_INCLUDED Chris@16: Chris@16: Chris@16: Chris@16: Chris@16: #include Chris@16: #include Chris@16: Chris@16: #include Chris@16: #include Chris@16: #include Chris@101: #include Chris@101: #include Chris@16: Chris@16: #include Chris@16: Chris@16: #include Chris@16: Chris@16: Chris@16: Chris@16: namespace boost { Chris@16: namespace numeric { Chris@16: namespace odeint { Chris@16: Chris@16: #ifndef DOXYGEN_SKIP Chris@16: template< class Value = double > Chris@16: struct rk4_coefficients_a1 : boost::array< Value , 1 > Chris@16: { Chris@16: rk4_coefficients_a1( void ) Chris@16: { Chris@16: (*this)[0] = static_cast< Value >( 1 ) / static_cast< Value >( 2 ); Chris@16: } Chris@16: }; Chris@16: Chris@16: template< class Value = double > Chris@16: struct rk4_coefficients_a2 : boost::array< Value , 2 > Chris@16: { Chris@16: rk4_coefficients_a2( void ) Chris@16: { Chris@16: (*this)[0] = static_cast(0); Chris@16: (*this)[1] = static_cast< Value >( 1 ) / static_cast< Value >( 2 ); Chris@16: } Chris@16: }; Chris@16: Chris@16: Chris@16: template< class Value = double > Chris@16: struct rk4_coefficients_a3 : boost::array< Value , 3 > Chris@16: { Chris@16: rk4_coefficients_a3( void ) Chris@16: { Chris@16: (*this)[0] = static_cast(0); Chris@16: (*this)[1] = static_cast(0); Chris@16: (*this)[2] = static_cast(1); Chris@16: } Chris@16: }; Chris@16: Chris@16: template< class Value = double > Chris@16: struct rk4_coefficients_b : boost::array< Value , 4 > Chris@16: { Chris@16: rk4_coefficients_b( void ) Chris@16: { Chris@16: (*this)[0] = static_cast(1)/static_cast(6); Chris@16: (*this)[1] = static_cast(1)/static_cast(3); Chris@16: (*this)[2] = static_cast(1)/static_cast(3); Chris@16: (*this)[3] = static_cast(1)/static_cast(6); Chris@16: } Chris@16: }; Chris@16: Chris@16: template< class Value = double > Chris@16: struct rk4_coefficients_c : boost::array< Value , 4 > Chris@16: { Chris@16: rk4_coefficients_c( void ) Chris@16: { Chris@16: (*this)[0] = static_cast(0); Chris@16: (*this)[1] = static_cast< Value >( 1 ) / static_cast< Value >( 2 ); Chris@16: (*this)[2] = static_cast< Value >( 1 ) / static_cast< Value >( 2 ); Chris@16: (*this)[3] = static_cast(1); Chris@16: } Chris@16: }; Chris@16: #endif Chris@16: Chris@16: Chris@16: Chris@16: template< 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: #ifndef DOXYGEN_SKIP Chris@16: class runge_kutta4 : public explicit_generic_rk< 4 , 4 , State , Value , Deriv , Time , Chris@16: Algebra , Operations , Resizer > Chris@16: #else Chris@16: class runge_kutta4 : public explicit_generic_rk Chris@16: #endif Chris@16: { Chris@16: Chris@16: public: Chris@16: Chris@16: #ifndef DOXYGEN_SKIP Chris@16: typedef explicit_generic_rk< 4 , 4 , State , Value , Deriv , Time , Chris@16: Algebra , Operations , Resizer > stepper_base_type; Chris@16: #endif Chris@16: typedef typename stepper_base_type::state_type 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::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 typename stepper_base_type::wrapped_state_type wrapped_state_type; Chris@16: typedef typename stepper_base_type::wrapped_deriv_type wrapped_deriv_type; Chris@16: typedef typename stepper_base_type::stepper_type stepper_type; Chris@16: #endif Chris@16: Chris@16: runge_kutta4( const algebra_type &algebra = algebra_type() ) : stepper_base_type( Chris@16: boost::fusion::make_vector( rk4_coefficients_a1() , rk4_coefficients_a2() , rk4_coefficients_a3() ) , Chris@16: rk4_coefficients_b() , rk4_coefficients_c() , algebra ) Chris@16: { } Chris@16: Chris@16: }; Chris@16: Chris@16: /** Chris@16: * \class runge_kutta4 Chris@16: * \brief The classical Runge-Kutta stepper of fourth order. Chris@16: * Chris@16: * The Runge-Kutta method of fourth order is one standard method for Chris@16: * solving ordinary differential equations and is widely used, see also Chris@16: * en.wikipedia.org/wiki/Runge-Kutta_methods Chris@16: * The method is explicit and fulfills the Stepper concept. Step size control Chris@16: * or continuous output are not provided. Chris@16: * Chris@16: * This class derives from explicit_stepper_base and inherits its interface via CRTP (current recurring template pattern). Chris@16: * Furthermore, it derivs from explicit_generic_rk which is a generic Runge-Kutta algorithm. For more details see Chris@16: * explicit_stepper_base and explicit_generic_rk. Chris@16: * Chris@16: * \tparam State The state type. Chris@16: * \tparam Value The value type. Chris@16: * \tparam Deriv The type representing the time derivative of the state. Chris@16: * \tparam Time The time representing the independent variable - the time. 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 runge_kutta4::runge_kutta4( const algebra_type &algebra = algebra_type() ) Chris@16: * \brief Constructs the runge_kutta4 class. This constructor can be used as a default Chris@16: * constructor if the algebra has a default constructor. Chris@16: * \param algebra A copy of algebra is made and stored inside explicit_stepper_base. Chris@16: */ Chris@16: Chris@16: } Chris@16: } Chris@16: } Chris@16: Chris@16: Chris@16: #endif // BOOST_NUMERIC_ODEINT_STEPPER_RUNGE_KUTTA4_HPP_INCLUDED