1 | /* |
2 | [auto_generated] |
3 | boost/numeric/odeint/stepper/runge_kutta4.hpp |
4 | |
5 | [begin_description] |
6 | Implementation of the classical Runge-Kutta stepper with the generic stepper. |
7 | [end_description] |
8 | |
9 | Copyright 2011-2013 Mario Mulansky |
10 | Copyright 2011-2013 Karsten Ahnert |
11 | |
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) |
15 | */ |
16 | |
17 | |
18 | #ifndef BOOST_NUMERIC_ODEINT_STEPPER_RUNGE_KUTTA4_HPP_INCLUDED |
19 | #define BOOST_NUMERIC_ODEINT_STEPPER_RUNGE_KUTTA4_HPP_INCLUDED |
20 | |
21 | |
22 | |
23 | |
24 | #include <boost/fusion/container/vector.hpp> |
25 | #include <boost/fusion/container/generation/make_vector.hpp> |
26 | |
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> |
32 | |
33 | #include <boost/array.hpp> |
34 | |
35 | #include <boost/numeric/odeint/util/resizer.hpp> |
36 | |
37 | |
38 | |
39 | namespace boost { |
40 | namespace numeric { |
41 | namespace odeint { |
42 | |
43 | #ifndef DOXYGEN_SKIP |
44 | template< class Value = double > |
45 | struct rk4_coefficients_a1 : boost::array< Value , 1 > |
46 | { |
47 | rk4_coefficients_a1( void ) |
48 | { |
49 | (*this)[0] = static_cast< Value >( 1 ) / static_cast< Value >( 2 ); |
50 | } |
51 | }; |
52 | |
53 | template< class Value = double > |
54 | struct rk4_coefficients_a2 : boost::array< Value , 2 > |
55 | { |
56 | rk4_coefficients_a2( void ) |
57 | { |
58 | (*this)[0] = static_cast<Value>(0); |
59 | (*this)[1] = static_cast< Value >( 1 ) / static_cast< Value >( 2 ); |
60 | } |
61 | }; |
62 | |
63 | |
64 | template< class Value = double > |
65 | struct rk4_coefficients_a3 : boost::array< Value , 3 > |
66 | { |
67 | rk4_coefficients_a3( void ) |
68 | { |
69 | (*this)[0] = static_cast<Value>(0); |
70 | (*this)[1] = static_cast<Value>(0); |
71 | (*this)[2] = static_cast<Value>(1); |
72 | } |
73 | }; |
74 | |
75 | template< class Value = double > |
76 | struct rk4_coefficients_b : boost::array< Value , 4 > |
77 | { |
78 | rk4_coefficients_b( void ) |
79 | { |
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); |
84 | } |
85 | }; |
86 | |
87 | template< class Value = double > |
88 | struct rk4_coefficients_c : boost::array< Value , 4 > |
89 | { |
90 | rk4_coefficients_c( void ) |
91 | { |
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); |
96 | } |
97 | }; |
98 | #endif |
99 | |
100 | |
101 | |
102 | template< |
103 | class State , |
104 | class Value = double , |
105 | class Deriv = State , |
106 | class Time = Value , |
107 | class Algebra = typename algebra_dispatcher< State >::algebra_type , |
108 | class Operations = typename operations_dispatcher< State >::operations_type , |
109 | class Resizer = initially_resizer |
110 | > |
111 | #ifndef DOXYGEN_SKIP |
112 | class runge_kutta4 : public explicit_generic_rk< 4 , 4 , State , Value , Deriv , Time , |
113 | Algebra , Operations , Resizer > |
114 | #else |
115 | class runge_kutta4 : public explicit_generic_rk |
116 | #endif |
117 | { |
118 | |
119 | public: |
120 | |
121 | #ifndef DOXYGEN_SKIP |
122 | typedef explicit_generic_rk< 4 , 4 , State , Value , Deriv , Time , |
123 | Algebra , Operations , Resizer > stepper_base_type; |
124 | #endif |
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; |
132 | |
133 | #ifndef DOXYGEN_SKIP |
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; |
137 | #endif |
138 | |
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 ) |
142 | { } |
143 | |
144 | }; |
145 | |
146 | /** |
147 | * \class runge_kutta4 |
148 | * \brief The classical Runge-Kutta stepper of fourth order. |
149 | * |
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. |
155 | * |
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. |
159 | * |
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. |
167 | */ |
168 | |
169 | /** |
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. |
174 | */ |
175 | |
176 | } |
177 | } |
178 | } |
179 | |
180 | |
181 | #endif // BOOST_NUMERIC_ODEINT_STEPPER_RUNGE_KUTTA4_HPP_INCLUDED |
182 | |