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