Chris@16
|
1 /*
|
Chris@16
|
2 [auto_generated]
|
Chris@16
|
3 boost/numeric/odeint/stepper/explicit_generic_rk.hpp
|
Chris@16
|
4
|
Chris@16
|
5 [begin_description]
|
Chris@16
|
6 Implementation of the generic Runge-Kutta steppers. This is the base class for many Runge-Kutta steppers.
|
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_EXPLICIT_GENERIC_RK_HPP_INCLUDED
|
Chris@16
|
19 #define BOOST_NUMERIC_ODEINT_STEPPER_EXPLICIT_GENERIC_RK_HPP_INCLUDED
|
Chris@16
|
20
|
Chris@16
|
21
|
Chris@16
|
22 #include <boost/array.hpp>
|
Chris@16
|
23
|
Chris@16
|
24
|
Chris@16
|
25 #include <boost/numeric/odeint/stepper/base/explicit_stepper_base.hpp>
|
Chris@16
|
26 #include <boost/numeric/odeint/algebra/range_algebra.hpp>
|
Chris@16
|
27 #include <boost/numeric/odeint/algebra/default_operations.hpp>
|
Chris@16
|
28 #include <boost/numeric/odeint/stepper/detail/generic_rk_algorithm.hpp>
|
Chris@16
|
29
|
Chris@16
|
30 #include <boost/numeric/odeint/util/state_wrapper.hpp>
|
Chris@16
|
31 #include <boost/numeric/odeint/util/is_resizeable.hpp>
|
Chris@16
|
32 #include <boost/numeric/odeint/util/resizer.hpp>
|
Chris@16
|
33
|
Chris@16
|
34 namespace boost {
|
Chris@16
|
35 namespace numeric {
|
Chris@16
|
36 namespace odeint {
|
Chris@16
|
37
|
Chris@16
|
38 //forward declarations
|
Chris@16
|
39
|
Chris@16
|
40 #ifndef DOXYGEN_SKIP
|
Chris@16
|
41 template<
|
Chris@16
|
42 size_t StageCount,
|
Chris@16
|
43 size_t Order,
|
Chris@16
|
44 class State ,
|
Chris@16
|
45 class Value = double ,
|
Chris@16
|
46 class Deriv = State ,
|
Chris@16
|
47 class Time = Value ,
|
Chris@16
|
48 class Algebra = range_algebra ,
|
Chris@16
|
49 class Operations = default_operations ,
|
Chris@16
|
50 class Resizer = initially_resizer
|
Chris@16
|
51 >
|
Chris@16
|
52 class explicit_generic_rk;
|
Chris@16
|
53
|
Chris@16
|
54
|
Chris@16
|
55 struct stage_vector;
|
Chris@16
|
56
|
Chris@16
|
57 template< class T , class Constant >
|
Chris@16
|
58 struct array_wrapper
|
Chris@16
|
59 {
|
Chris@16
|
60 typedef const typename boost::array< T , Constant::value > type;
|
Chris@16
|
61 };
|
Chris@16
|
62
|
Chris@16
|
63 template< class T , size_t i >
|
Chris@16
|
64 struct stage
|
Chris@16
|
65 {
|
Chris@16
|
66 T c;
|
Chris@16
|
67 boost::array< T , i > a;
|
Chris@16
|
68 };
|
Chris@16
|
69
|
Chris@16
|
70
|
Chris@16
|
71 template< class T , class Constant >
|
Chris@16
|
72 struct stage_wrapper
|
Chris@16
|
73 {
|
Chris@16
|
74 typedef stage< T , Constant::value > type;
|
Chris@16
|
75 };
|
Chris@16
|
76 #endif
|
Chris@16
|
77
|
Chris@16
|
78
|
Chris@16
|
79 template<
|
Chris@16
|
80 size_t StageCount,
|
Chris@16
|
81 size_t Order,
|
Chris@16
|
82 class State ,
|
Chris@16
|
83 class Value ,
|
Chris@16
|
84 class Deriv ,
|
Chris@16
|
85 class Time ,
|
Chris@16
|
86 class Algebra ,
|
Chris@16
|
87 class Operations ,
|
Chris@16
|
88 class Resizer
|
Chris@16
|
89 >
|
Chris@16
|
90 #ifndef DOXYGEN_SKIP
|
Chris@16
|
91 class explicit_generic_rk : public explicit_stepper_base<
|
Chris@16
|
92 explicit_generic_rk< StageCount , Order , State , Value , Deriv , Time , Algebra , Operations , Resizer > ,
|
Chris@16
|
93 Order , State , Value , Deriv , Time , Algebra , Operations , Resizer >
|
Chris@16
|
94 #else
|
Chris@16
|
95 class explicit_generic_rk : public explicit_stepper_base
|
Chris@16
|
96 #endif
|
Chris@16
|
97 {
|
Chris@16
|
98
|
Chris@16
|
99 public:
|
Chris@16
|
100
|
Chris@16
|
101 #ifndef DOXYGEN_SKIP
|
Chris@16
|
102 typedef explicit_stepper_base<
|
Chris@16
|
103 explicit_generic_rk< StageCount , Order , State , Value , Deriv ,Time , Algebra , Operations , Resizer > ,
|
Chris@16
|
104 Order , State , Value , Deriv , Time , Algebra ,
|
Chris@16
|
105 Operations , Resizer > stepper_base_type;
|
Chris@16
|
106 #else
|
Chris@16
|
107 typedef explicit_stepper_base< ... > stepper_base_type;
|
Chris@16
|
108 #endif
|
Chris@16
|
109
|
Chris@16
|
110 typedef typename stepper_base_type::state_type state_type;
|
Chris@16
|
111 typedef typename stepper_base_type::wrapped_state_type wrapped_state_type;
|
Chris@16
|
112 typedef typename stepper_base_type::value_type value_type;
|
Chris@16
|
113 typedef typename stepper_base_type::deriv_type deriv_type;
|
Chris@16
|
114 typedef typename stepper_base_type::wrapped_deriv_type wrapped_deriv_type;
|
Chris@16
|
115 typedef typename stepper_base_type::time_type time_type;
|
Chris@16
|
116 typedef typename stepper_base_type::algebra_type algebra_type;
|
Chris@16
|
117 typedef typename stepper_base_type::operations_type operations_type;
|
Chris@16
|
118 typedef typename stepper_base_type::resizer_type resizer_type;
|
Chris@16
|
119
|
Chris@16
|
120 #ifndef DOXYGEN_SKIP
|
Chris@16
|
121 typedef explicit_generic_rk< StageCount , Order , State , Value , Deriv ,Time , Algebra , Operations , Resizer > stepper_type;
|
Chris@16
|
122 #endif
|
Chris@16
|
123
|
Chris@16
|
124 typedef detail::generic_rk_algorithm< StageCount , Value , Algebra , Operations > rk_algorithm_type;
|
Chris@16
|
125
|
Chris@16
|
126 typedef typename rk_algorithm_type::coef_a_type coef_a_type;
|
Chris@16
|
127 typedef typename rk_algorithm_type::coef_b_type coef_b_type;
|
Chris@16
|
128 typedef typename rk_algorithm_type::coef_c_type coef_c_type;
|
Chris@16
|
129
|
Chris@16
|
130 #ifndef DOXYGEN_SKIP
|
Chris@16
|
131 static const size_t stage_count = StageCount;
|
Chris@16
|
132 #endif
|
Chris@16
|
133
|
Chris@16
|
134 public:
|
Chris@16
|
135
|
Chris@16
|
136 explicit_generic_rk( const coef_a_type &a , const coef_b_type &b , const coef_c_type &c ,
|
Chris@16
|
137 const algebra_type &algebra = algebra_type() )
|
Chris@16
|
138 : stepper_base_type( algebra ) , m_rk_algorithm( a , b , c )
|
Chris@16
|
139 { }
|
Chris@16
|
140
|
Chris@16
|
141
|
Chris@16
|
142 template< class System , class StateIn , class DerivIn , class StateOut >
|
Chris@16
|
143 void do_step_impl( System system , const StateIn &in , const DerivIn &dxdt ,
|
Chris@16
|
144 time_type t , StateOut &out , time_type dt )
|
Chris@16
|
145 {
|
Chris@16
|
146 m_resizer.adjust_size( in , detail::bind( &stepper_type::template resize_impl< StateIn > , detail::ref( *this ) , detail::_1 ) );
|
Chris@16
|
147
|
Chris@16
|
148 // actual calculation done in generic_rk.hpp
|
Chris@16
|
149 m_rk_algorithm.do_step( stepper_base_type::m_algebra , system , in , dxdt , t , out , dt , m_x_tmp.m_v , m_F );
|
Chris@16
|
150 }
|
Chris@16
|
151
|
Chris@16
|
152 template< class StateIn >
|
Chris@16
|
153 void adjust_size( const StateIn &x )
|
Chris@16
|
154 {
|
Chris@16
|
155 resize_impl( x );
|
Chris@16
|
156 stepper_base_type::adjust_size( x );
|
Chris@16
|
157 }
|
Chris@16
|
158
|
Chris@16
|
159 private:
|
Chris@16
|
160
|
Chris@16
|
161 template< class StateIn >
|
Chris@16
|
162 bool resize_impl( const StateIn &x )
|
Chris@16
|
163 {
|
Chris@16
|
164 bool resized( false );
|
Chris@16
|
165 resized |= adjust_size_by_resizeability( m_x_tmp , x , typename is_resizeable<state_type>::type() );
|
Chris@16
|
166 for( size_t i = 0 ; i < StageCount-1 ; ++i )
|
Chris@16
|
167 {
|
Chris@16
|
168 resized |= adjust_size_by_resizeability( m_F[i] , x , typename is_resizeable<deriv_type>::type() );
|
Chris@16
|
169 }
|
Chris@16
|
170 return resized;
|
Chris@16
|
171 }
|
Chris@16
|
172
|
Chris@16
|
173
|
Chris@16
|
174 rk_algorithm_type m_rk_algorithm;
|
Chris@16
|
175
|
Chris@16
|
176 resizer_type m_resizer;
|
Chris@16
|
177
|
Chris@16
|
178 wrapped_state_type m_x_tmp;
|
Chris@16
|
179 wrapped_deriv_type m_F[StageCount-1];
|
Chris@16
|
180
|
Chris@16
|
181 };
|
Chris@16
|
182
|
Chris@16
|
183
|
Chris@16
|
184
|
Chris@16
|
185 /*********** DOXYGEN *************/
|
Chris@16
|
186
|
Chris@16
|
187 /**
|
Chris@16
|
188 * \class explicit_generic_rk
|
Chris@16
|
189 * \brief A generic implementation of explicit Runge-Kutta algorithms. This class is as a base class
|
Chris@16
|
190 * for all explicit Runge-Kutta steppers.
|
Chris@16
|
191 *
|
Chris@16
|
192 * This class implements the explicit Runge-Kutta algorithms without error estimation in a generic way.
|
Chris@16
|
193 * The Butcher tableau is passed to the stepper which constructs the stepper scheme with the help of a
|
Chris@16
|
194 * template-metaprogramming algorithm. ToDo : Add example!
|
Chris@16
|
195 *
|
Chris@16
|
196 * This class derives explicit_stepper_base which provides the stepper interface.
|
Chris@16
|
197 *
|
Chris@16
|
198 * \tparam StageCount The number of stages of the Runge-Kutta algorithm.
|
Chris@16
|
199 * \tparam Order The order of the stepper.
|
Chris@16
|
200 * \tparam State The type representing the state of the ODE.
|
Chris@16
|
201 * \tparam Value The floating point type which is used in the computations.
|
Chris@16
|
202 * \tparam Time The type representing the independent variable - the time - of the ODE.
|
Chris@16
|
203 * \tparam Algebra The algebra type.
|
Chris@16
|
204 * \tparam Operations The operations type.
|
Chris@16
|
205 * \tparam Resizer The resizer policy type.
|
Chris@16
|
206 */
|
Chris@16
|
207
|
Chris@16
|
208 /**
|
Chris@16
|
209 * \fn explicit_generic_rk::explicit_generic_rk( const coef_a_type &a , const coef_b_type &b , const coef_c_type &c , const algebra_type &algebra )
|
Chris@16
|
210 * \brief Constructs the explicit_generic_rk class. See examples section for details on the coefficients.
|
Chris@16
|
211 * \param a Triangular matrix of parameters b in the Butcher tableau.
|
Chris@16
|
212 * \param b Last row of the butcher tableau.
|
Chris@16
|
213 * \param c Parameters to calculate the time points in the Butcher tableau.
|
Chris@16
|
214 * \param algebra A copy of algebra is made and stored inside explicit_stepper_base.
|
Chris@16
|
215 */
|
Chris@16
|
216
|
Chris@16
|
217 /**
|
Chris@16
|
218 * \fn explicit_generic_rk::do_step_impl( System system , const StateIn &in , const DerivIn &dxdt , time_type t , StateOut &out , time_type dt )
|
Chris@16
|
219 * \brief This method performs one step. The derivative `dxdt` of `in` at the time `t` is passed to the method.
|
Chris@16
|
220 * The result is updated out of place, hence the input is in `in` and the output in `out`.
|
Chris@16
|
221 * Access to this step functionality is provided by explicit_stepper_base and
|
Chris@16
|
222 * `do_step_impl` should not be called directly.
|
Chris@16
|
223 *
|
Chris@16
|
224 * \param system The system function to solve, hence the r.h.s. of the ODE. It must fulfill the
|
Chris@16
|
225 * Simple System concept.
|
Chris@16
|
226 * \param in The state of the ODE which should be solved. in is not modified in this method
|
Chris@16
|
227 * \param dxdt The derivative of x at t.
|
Chris@16
|
228 * \param t The value of the time, at which the step should be performed.
|
Chris@16
|
229 * \param out The result of the step is written in out.
|
Chris@16
|
230 * \param dt The step size.
|
Chris@16
|
231 */
|
Chris@16
|
232
|
Chris@16
|
233
|
Chris@16
|
234 /**
|
Chris@16
|
235 * \fn explicit_generic_rk::adjust_size( const StateIn &x )
|
Chris@16
|
236 * \brief Adjust the size of all temporaries in the stepper manually.
|
Chris@16
|
237 * \param x A state from which the size of the temporaries to be resized is deduced.
|
Chris@16
|
238 */
|
Chris@16
|
239
|
Chris@16
|
240 }
|
Chris@16
|
241 }
|
Chris@16
|
242 }
|
Chris@16
|
243 #endif // BOOST_NUMERIC_ODEINT_STEPPER_EXPLICIT_GENERIC_RK_HPP_INCLUDED
|