3 boost/numeric/odeint/stepper/runge_kutta4.hpp
6 Implementation of the classical Runge-Kutta stepper with the generic stepper.
9 Copyright 2011-2013 Mario Mulansky
10 Copyright 2011-2013 Karsten Ahnert
12 Distributed under the Boost Software License, Version 1.0.
13 (See accompanying file LICENSE_1_0.txt or
14 copy at http://www.boost.org/LICENSE_1_0.txt)
18 #ifndef BOOST_NUMERIC_ODEINT_STEPPER_RUNGE_KUTTA4_HPP_INCLUDED
19 #define BOOST_NUMERIC_ODEINT_STEPPER_RUNGE_KUTTA4_HPP_INCLUDED
24 #include <boost/fusion/container/vector.hpp>
25 #include <boost/fusion/container/generation/make_vector.hpp>
27 #include <boost/numeric/odeint/stepper/explicit_generic_rk.hpp>
28 #include <boost/numeric/odeint/algebra/range_algebra.hpp>
29 #include <boost/numeric/odeint/algebra/default_operations.hpp>
30 #include <boost/numeric/odeint/algebra/algebra_dispatcher.hpp>
31 #include <boost/numeric/odeint/algebra/operations_dispatcher.hpp>
33 #include <boost/array.hpp>
35 #include <boost/numeric/odeint/util/resizer.hpp>
44 template< class Value = double >
45 struct rk4_coefficients_a1 : boost::array< Value , 1 >
47 rk4_coefficients_a1( void )
49 (*this)[0] = static_cast< Value >( 1 ) / static_cast< Value >( 2 );
53 template< class Value = double >
54 struct rk4_coefficients_a2 : boost::array< Value , 2 >
56 rk4_coefficients_a2( void )
58 (*this)[0] = static_cast<Value>(0);
59 (*this)[1] = static_cast< Value >( 1 ) / static_cast< Value >( 2 );
64 template< class Value = double >
65 struct rk4_coefficients_a3 : boost::array< Value , 3 >
67 rk4_coefficients_a3( void )
69 (*this)[0] = static_cast<Value>(0);
70 (*this)[1] = static_cast<Value>(0);
71 (*this)[2] = static_cast<Value>(1);
75 template< class Value = double >
76 struct rk4_coefficients_b : boost::array< Value , 4 >
78 rk4_coefficients_b( void )
80 (*this)[0] = static_cast<Value>(1)/static_cast<Value>(6);
81 (*this)[1] = static_cast<Value>(1)/static_cast<Value>(3);
82 (*this)[2] = static_cast<Value>(1)/static_cast<Value>(3);
83 (*this)[3] = static_cast<Value>(1)/static_cast<Value>(6);
87 template< class Value = double >
88 struct rk4_coefficients_c : boost::array< Value , 4 >
90 rk4_coefficients_c( void )
92 (*this)[0] = static_cast<Value>(0);
93 (*this)[1] = static_cast< Value >( 1 ) / static_cast< Value >( 2 );
94 (*this)[2] = static_cast< Value >( 1 ) / static_cast< Value >( 2 );
95 (*this)[3] = static_cast<Value>(1);
104 class Value = double ,
105 class Deriv = State ,
107 class Algebra = typename algebra_dispatcher< State >::algebra_type ,
108 class Operations = typename operations_dispatcher< State >::operations_type ,
109 class Resizer = initially_resizer
112 class runge_kutta4 : public explicit_generic_rk< 4 , 4 , State , Value , Deriv , Time ,
113 Algebra , Operations , Resizer >
115 class runge_kutta4 : public explicit_generic_rk
122 typedef explicit_generic_rk< 4 , 4 , State , Value , Deriv , Time ,
123 Algebra , Operations , Resizer > stepper_base_type;
125 typedef typename stepper_base_type::state_type state_type;
126 typedef typename stepper_base_type::value_type value_type;
127 typedef typename stepper_base_type::deriv_type deriv_type;
128 typedef typename stepper_base_type::time_type time_type;
129 typedef typename stepper_base_type::algebra_type algebra_type;
130 typedef typename stepper_base_type::operations_type operations_type;
131 typedef typename stepper_base_type::resizer_type resizer_type;
134 typedef typename stepper_base_type::wrapped_state_type wrapped_state_type;
135 typedef typename stepper_base_type::wrapped_deriv_type wrapped_deriv_type;
136 typedef typename stepper_base_type::stepper_type stepper_type;
139 runge_kutta4( const algebra_type &algebra = algebra_type() ) : stepper_base_type(
140 boost::fusion::make_vector( rk4_coefficients_a1<Value>() , rk4_coefficients_a2<Value>() , rk4_coefficients_a3<Value>() ) ,
141 rk4_coefficients_b<Value>() , rk4_coefficients_c<Value>() , algebra )
147 * \class runge_kutta4
148 * \brief The classical Runge-Kutta stepper of fourth order.
150 * The Runge-Kutta method of fourth order is one standard method for
151 * solving ordinary differential equations and is widely used, see also
152 * <a href="http://en.wikipedia.org/wiki/Runge%E2%80%93Kutta_methods">en.wikipedia.org/wiki/Runge-Kutta_methods</a>
153 * The method is explicit and fulfills the Stepper concept. Step size control
154 * or continuous output are not provided.
156 * This class derives from explicit_stepper_base and inherits its interface via CRTP (current recurring template pattern).
157 * Furthermore, it derivs from explicit_generic_rk which is a generic Runge-Kutta algorithm. For more details see
158 * explicit_stepper_base and explicit_generic_rk.
160 * \tparam State The state type.
161 * \tparam Value The value type.
162 * \tparam Deriv The type representing the time derivative of the state.
163 * \tparam Time The time representing the independent variable - the time.
164 * \tparam Algebra The algebra type.
165 * \tparam Operations The operations type.
166 * \tparam Resizer The resizer policy type.
170 * \fn runge_kutta4::runge_kutta4( const algebra_type &algebra = algebra_type() )
171 * \brief Constructs the runge_kutta4 class. This constructor can be used as a default
172 * constructor if the algebra has a default constructor.
173 * \param algebra A copy of algebra is made and stored inside explicit_stepper_base.
181 #endif // BOOST_NUMERIC_ODEINT_STEPPER_RUNGE_KUTTA4_HPP_INCLUDED