Chris@16
|
1 /*
|
Chris@16
|
2 [auto_generated]
|
Chris@16
|
3 boost/numeric/odeint/stepper/runge_kutta4.hpp
|
Chris@16
|
4
|
Chris@16
|
5 [begin_description]
|
Chris@16
|
6 Implementation of the classical Runge-Kutta stepper with the generic stepper.
|
Chris@16
|
7 [end_description]
|
Chris@16
|
8
|
Chris@101
|
9 Copyright 2011-2013 Mario Mulansky
|
Chris@101
|
10 Copyright 2011-2013 Karsten Ahnert
|
Chris@16
|
11
|
Chris@16
|
12 Distributed under the Boost Software License, Version 1.0.
|
Chris@16
|
13 (See accompanying file LICENSE_1_0.txt or
|
Chris@16
|
14 copy at http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
15 */
|
Chris@16
|
16
|
Chris@16
|
17
|
Chris@16
|
18 #ifndef BOOST_NUMERIC_ODEINT_STEPPER_RUNGE_KUTTA4_HPP_INCLUDED
|
Chris@16
|
19 #define BOOST_NUMERIC_ODEINT_STEPPER_RUNGE_KUTTA4_HPP_INCLUDED
|
Chris@16
|
20
|
Chris@16
|
21
|
Chris@16
|
22
|
Chris@16
|
23
|
Chris@16
|
24 #include <boost/fusion/container/vector.hpp>
|
Chris@16
|
25 #include <boost/fusion/container/generation/make_vector.hpp>
|
Chris@16
|
26
|
Chris@16
|
27 #include <boost/numeric/odeint/stepper/explicit_generic_rk.hpp>
|
Chris@16
|
28 #include <boost/numeric/odeint/algebra/range_algebra.hpp>
|
Chris@16
|
29 #include <boost/numeric/odeint/algebra/default_operations.hpp>
|
Chris@101
|
30 #include <boost/numeric/odeint/algebra/algebra_dispatcher.hpp>
|
Chris@101
|
31 #include <boost/numeric/odeint/algebra/operations_dispatcher.hpp>
|
Chris@16
|
32
|
Chris@16
|
33 #include <boost/array.hpp>
|
Chris@16
|
34
|
Chris@16
|
35 #include <boost/numeric/odeint/util/resizer.hpp>
|
Chris@16
|
36
|
Chris@16
|
37
|
Chris@16
|
38
|
Chris@16
|
39 namespace boost {
|
Chris@16
|
40 namespace numeric {
|
Chris@16
|
41 namespace odeint {
|
Chris@16
|
42
|
Chris@16
|
43 #ifndef DOXYGEN_SKIP
|
Chris@16
|
44 template< class Value = double >
|
Chris@16
|
45 struct rk4_coefficients_a1 : boost::array< Value , 1 >
|
Chris@16
|
46 {
|
Chris@16
|
47 rk4_coefficients_a1( void )
|
Chris@16
|
48 {
|
Chris@16
|
49 (*this)[0] = static_cast< Value >( 1 ) / static_cast< Value >( 2 );
|
Chris@16
|
50 }
|
Chris@16
|
51 };
|
Chris@16
|
52
|
Chris@16
|
53 template< class Value = double >
|
Chris@16
|
54 struct rk4_coefficients_a2 : boost::array< Value , 2 >
|
Chris@16
|
55 {
|
Chris@16
|
56 rk4_coefficients_a2( void )
|
Chris@16
|
57 {
|
Chris@16
|
58 (*this)[0] = static_cast<Value>(0);
|
Chris@16
|
59 (*this)[1] = static_cast< Value >( 1 ) / static_cast< Value >( 2 );
|
Chris@16
|
60 }
|
Chris@16
|
61 };
|
Chris@16
|
62
|
Chris@16
|
63
|
Chris@16
|
64 template< class Value = double >
|
Chris@16
|
65 struct rk4_coefficients_a3 : boost::array< Value , 3 >
|
Chris@16
|
66 {
|
Chris@16
|
67 rk4_coefficients_a3( void )
|
Chris@16
|
68 {
|
Chris@16
|
69 (*this)[0] = static_cast<Value>(0);
|
Chris@16
|
70 (*this)[1] = static_cast<Value>(0);
|
Chris@16
|
71 (*this)[2] = static_cast<Value>(1);
|
Chris@16
|
72 }
|
Chris@16
|
73 };
|
Chris@16
|
74
|
Chris@16
|
75 template< class Value = double >
|
Chris@16
|
76 struct rk4_coefficients_b : boost::array< Value , 4 >
|
Chris@16
|
77 {
|
Chris@16
|
78 rk4_coefficients_b( void )
|
Chris@16
|
79 {
|
Chris@16
|
80 (*this)[0] = static_cast<Value>(1)/static_cast<Value>(6);
|
Chris@16
|
81 (*this)[1] = static_cast<Value>(1)/static_cast<Value>(3);
|
Chris@16
|
82 (*this)[2] = static_cast<Value>(1)/static_cast<Value>(3);
|
Chris@16
|
83 (*this)[3] = static_cast<Value>(1)/static_cast<Value>(6);
|
Chris@16
|
84 }
|
Chris@16
|
85 };
|
Chris@16
|
86
|
Chris@16
|
87 template< class Value = double >
|
Chris@16
|
88 struct rk4_coefficients_c : boost::array< Value , 4 >
|
Chris@16
|
89 {
|
Chris@16
|
90 rk4_coefficients_c( void )
|
Chris@16
|
91 {
|
Chris@16
|
92 (*this)[0] = static_cast<Value>(0);
|
Chris@16
|
93 (*this)[1] = static_cast< Value >( 1 ) / static_cast< Value >( 2 );
|
Chris@16
|
94 (*this)[2] = static_cast< Value >( 1 ) / static_cast< Value >( 2 );
|
Chris@16
|
95 (*this)[3] = static_cast<Value>(1);
|
Chris@16
|
96 }
|
Chris@16
|
97 };
|
Chris@16
|
98 #endif
|
Chris@16
|
99
|
Chris@16
|
100
|
Chris@16
|
101
|
Chris@16
|
102 template<
|
Chris@16
|
103 class State ,
|
Chris@16
|
104 class Value = double ,
|
Chris@16
|
105 class Deriv = State ,
|
Chris@16
|
106 class Time = Value ,
|
Chris@101
|
107 class Algebra = typename algebra_dispatcher< State >::algebra_type ,
|
Chris@101
|
108 class Operations = typename operations_dispatcher< State >::operations_type ,
|
Chris@16
|
109 class Resizer = initially_resizer
|
Chris@16
|
110 >
|
Chris@16
|
111 #ifndef DOXYGEN_SKIP
|
Chris@16
|
112 class runge_kutta4 : public explicit_generic_rk< 4 , 4 , State , Value , Deriv , Time ,
|
Chris@16
|
113 Algebra , Operations , Resizer >
|
Chris@16
|
114 #else
|
Chris@16
|
115 class runge_kutta4 : public explicit_generic_rk
|
Chris@16
|
116 #endif
|
Chris@16
|
117 {
|
Chris@16
|
118
|
Chris@16
|
119 public:
|
Chris@16
|
120
|
Chris@16
|
121 #ifndef DOXYGEN_SKIP
|
Chris@16
|
122 typedef explicit_generic_rk< 4 , 4 , State , Value , Deriv , Time ,
|
Chris@16
|
123 Algebra , Operations , Resizer > stepper_base_type;
|
Chris@16
|
124 #endif
|
Chris@16
|
125 typedef typename stepper_base_type::state_type state_type;
|
Chris@16
|
126 typedef typename stepper_base_type::value_type value_type;
|
Chris@16
|
127 typedef typename stepper_base_type::deriv_type deriv_type;
|
Chris@16
|
128 typedef typename stepper_base_type::time_type time_type;
|
Chris@16
|
129 typedef typename stepper_base_type::algebra_type algebra_type;
|
Chris@16
|
130 typedef typename stepper_base_type::operations_type operations_type;
|
Chris@16
|
131 typedef typename stepper_base_type::resizer_type resizer_type;
|
Chris@16
|
132
|
Chris@16
|
133 #ifndef DOXYGEN_SKIP
|
Chris@16
|
134 typedef typename stepper_base_type::wrapped_state_type wrapped_state_type;
|
Chris@16
|
135 typedef typename stepper_base_type::wrapped_deriv_type wrapped_deriv_type;
|
Chris@16
|
136 typedef typename stepper_base_type::stepper_type stepper_type;
|
Chris@16
|
137 #endif
|
Chris@16
|
138
|
Chris@16
|
139 runge_kutta4( const algebra_type &algebra = algebra_type() ) : stepper_base_type(
|
Chris@16
|
140 boost::fusion::make_vector( rk4_coefficients_a1<Value>() , rk4_coefficients_a2<Value>() , rk4_coefficients_a3<Value>() ) ,
|
Chris@16
|
141 rk4_coefficients_b<Value>() , rk4_coefficients_c<Value>() , algebra )
|
Chris@16
|
142 { }
|
Chris@16
|
143
|
Chris@16
|
144 };
|
Chris@16
|
145
|
Chris@16
|
146 /**
|
Chris@16
|
147 * \class runge_kutta4
|
Chris@16
|
148 * \brief The classical Runge-Kutta stepper of fourth order.
|
Chris@16
|
149 *
|
Chris@16
|
150 * The Runge-Kutta method of fourth order is one standard method for
|
Chris@16
|
151 * solving ordinary differential equations and is widely used, see also
|
Chris@16
|
152 * <a href="http://en.wikipedia.org/wiki/Runge%E2%80%93Kutta_methods">en.wikipedia.org/wiki/Runge-Kutta_methods</a>
|
Chris@16
|
153 * The method is explicit and fulfills the Stepper concept. Step size control
|
Chris@16
|
154 * or continuous output are not provided.
|
Chris@16
|
155 *
|
Chris@16
|
156 * This class derives from explicit_stepper_base and inherits its interface via CRTP (current recurring template pattern).
|
Chris@16
|
157 * Furthermore, it derivs from explicit_generic_rk which is a generic Runge-Kutta algorithm. For more details see
|
Chris@16
|
158 * explicit_stepper_base and explicit_generic_rk.
|
Chris@16
|
159 *
|
Chris@16
|
160 * \tparam State The state type.
|
Chris@16
|
161 * \tparam Value The value type.
|
Chris@16
|
162 * \tparam Deriv The type representing the time derivative of the state.
|
Chris@16
|
163 * \tparam Time The time representing the independent variable - the time.
|
Chris@16
|
164 * \tparam Algebra The algebra type.
|
Chris@16
|
165 * \tparam Operations The operations type.
|
Chris@16
|
166 * \tparam Resizer The resizer policy type.
|
Chris@16
|
167 */
|
Chris@16
|
168
|
Chris@16
|
169 /**
|
Chris@16
|
170 * \fn runge_kutta4::runge_kutta4( const algebra_type &algebra = algebra_type() )
|
Chris@16
|
171 * \brief Constructs the runge_kutta4 class. This constructor can be used as a default
|
Chris@16
|
172 * constructor if the algebra has a default constructor.
|
Chris@16
|
173 * \param algebra A copy of algebra is made and stored inside explicit_stepper_base.
|
Chris@16
|
174 */
|
Chris@16
|
175
|
Chris@16
|
176 }
|
Chris@16
|
177 }
|
Chris@16
|
178 }
|
Chris@16
|
179
|
Chris@16
|
180
|
Chris@16
|
181 #endif // BOOST_NUMERIC_ODEINT_STEPPER_RUNGE_KUTTA4_HPP_INCLUDED
|