Mercurial > hg > vamp-build-and-test
comparison DEPENDENCIES/generic/include/boost/numeric/odeint/stepper/adams_bashforth.hpp @ 16:2665513ce2d3
Add boost headers
author | Chris Cannam |
---|---|
date | Tue, 05 Aug 2014 11:11:38 +0100 |
parents | |
children | c530137014c0 |
comparison
equal
deleted
inserted
replaced
15:663ca0da4350 | 16:2665513ce2d3 |
---|---|
1 /* | |
2 [auto_generated] | |
3 boost/numeric/odeint/stepper/adams_bashforth.hpp | |
4 | |
5 [begin_description] | |
6 Implementaton of the Adam-Bashforth method a multistep method used for the predictor step in the | |
7 Adams-Bashforth-Moulton method. | |
8 [end_description] | |
9 | |
10 Copyright 2009-2011 Karsten Ahnert | |
11 Copyright 2009-2011 Mario Mulansky | |
12 | |
13 Distributed under the Boost Software License, Version 1.0. | |
14 (See accompanying file LICENSE_1_0.txt or | |
15 copy at http://www.boost.org/LICENSE_1_0.txt) | |
16 */ | |
17 | |
18 | |
19 #ifndef BOOST_NUMERIC_ODEINT_STEPPER_ADAMS_BASHFORTH_HPP_INCLUDED | |
20 #define BOOST_NUMERIC_ODEINT_STEPPER_ADAMS_BASHFORTH_HPP_INCLUDED | |
21 | |
22 #include <boost/static_assert.hpp> | |
23 | |
24 #include <boost/numeric/odeint/util/bind.hpp> | |
25 #include <boost/numeric/odeint/util/unwrap_reference.hpp> | |
26 | |
27 #include <boost/numeric/odeint/algebra/range_algebra.hpp> | |
28 #include <boost/numeric/odeint/algebra/default_operations.hpp> | |
29 | |
30 #include <boost/numeric/odeint/util/state_wrapper.hpp> | |
31 #include <boost/numeric/odeint/util/is_resizeable.hpp> | |
32 #include <boost/numeric/odeint/util/resizer.hpp> | |
33 | |
34 #include <boost/numeric/odeint/stepper/stepper_categories.hpp> | |
35 #include <boost/numeric/odeint/stepper/runge_kutta4.hpp> | |
36 | |
37 #include <boost/numeric/odeint/stepper/base/algebra_stepper_base.hpp> | |
38 | |
39 #include <boost/numeric/odeint/stepper/detail/adams_bashforth_coefficients.hpp> | |
40 #include <boost/numeric/odeint/stepper/detail/adams_bashforth_call_algebra.hpp> | |
41 #include <boost/numeric/odeint/stepper/detail/rotating_buffer.hpp> | |
42 | |
43 | |
44 | |
45 namespace boost { | |
46 namespace numeric { | |
47 namespace odeint { | |
48 | |
49 | |
50 template< | |
51 size_t Steps , | |
52 class State , | |
53 class Value = double , | |
54 class Deriv = State , | |
55 class Time = Value , | |
56 class Algebra = range_algebra , | |
57 class Operations = default_operations , | |
58 class Resizer = initially_resizer , | |
59 class InitializingStepper = runge_kutta4< State , Value , Deriv , Time , Algebra , Operations, Resizer > | |
60 > | |
61 class adams_bashforth : public algebra_stepper_base< Algebra , Operations > | |
62 { | |
63 | |
64 #ifndef DOXYGEN_SKIP | |
65 BOOST_STATIC_ASSERT(( Steps > 0 )); | |
66 BOOST_STATIC_ASSERT(( Steps < 9 )); | |
67 #endif | |
68 | |
69 public : | |
70 | |
71 typedef State state_type; | |
72 typedef state_wrapper< state_type > wrapped_state_type; | |
73 typedef Value value_type; | |
74 typedef Deriv deriv_type; | |
75 typedef state_wrapper< deriv_type > wrapped_deriv_type; | |
76 typedef Time time_type; | |
77 typedef Resizer resizer_type; | |
78 typedef stepper_tag stepper_category; | |
79 | |
80 typedef InitializingStepper initializing_stepper_type; | |
81 | |
82 typedef typename algebra_stepper_base< Algebra , Operations >::algebra_type algebra_type; | |
83 typedef typename algebra_stepper_base< Algebra , Operations >::operations_type operations_type; | |
84 #ifndef DOXYGEN_SKIP | |
85 typedef adams_bashforth< Steps , State , Value , Deriv , Time , Algebra , Operations , Resizer , InitializingStepper > stepper_type; | |
86 #endif | |
87 static const size_t steps = Steps; | |
88 | |
89 | |
90 | |
91 typedef unsigned short order_type; | |
92 static const order_type order_value = steps; | |
93 | |
94 typedef detail::rotating_buffer< wrapped_deriv_type , steps > step_storage_type; | |
95 | |
96 | |
97 | |
98 order_type order( void ) const { return order_value; } | |
99 | |
100 adams_bashforth( const algebra_type &algebra = algebra_type() ) | |
101 : m_step_storage() , m_resizer() , m_coefficients() , | |
102 m_steps_initialized( 0 ) , m_initializing_stepper() , | |
103 m_algebra( algebra ) | |
104 { } | |
105 | |
106 adams_bashforth( const adams_bashforth &stepper ) | |
107 : m_step_storage( stepper.m_step_storage ) , m_resizer( stepper.m_resizer ) , m_coefficients() , | |
108 m_steps_initialized( stepper.m_steps_initialized ) , m_initializing_stepper( stepper.m_initializing_stepper ) , | |
109 m_algebra( stepper.m_algebra ) | |
110 { } | |
111 | |
112 adams_bashforth& operator=( const adams_bashforth &stepper ) | |
113 { | |
114 m_resizer = stepper.m_resizer; | |
115 m_step_storage = stepper.m_step_storage; | |
116 m_algebra = stepper.m_algebra; | |
117 return *this; | |
118 } | |
119 | |
120 | |
121 /* | |
122 * Version 1 : do_step( system , x , t , dt ); | |
123 * | |
124 * solves the forwarding problem | |
125 */ | |
126 template< class System , class StateInOut > | |
127 void do_step( System system , StateInOut &x , time_type t , time_type dt ) | |
128 { | |
129 do_step( system , x , t , x , dt ); | |
130 } | |
131 | |
132 /** | |
133 * \brief Second version to solve the forwarding problem, can be called with Boost.Range as StateInOut. | |
134 */ | |
135 template< class System , class StateInOut > | |
136 void do_step( System system , const StateInOut &x , time_type t , time_type dt ) | |
137 { | |
138 do_step( system , x , t , x , dt ); | |
139 } | |
140 | |
141 | |
142 | |
143 /* | |
144 * Version 2 : do_step( system , in , t , out , dt ); | |
145 * | |
146 * solves the forwarding problem | |
147 */ | |
148 | |
149 template< class System , class StateIn , class StateOut > | |
150 void do_step( System system , const StateIn &in , time_type t , StateOut &out , time_type dt ) | |
151 { | |
152 do_step_impl( system , in , t , out , dt ); | |
153 } | |
154 | |
155 /** | |
156 * \brief Second version to solve the forwarding problem, can be called with Boost.Range as StateOut. | |
157 */ | |
158 template< class System , class StateIn , class StateOut > | |
159 void do_step( System system , const StateIn &in , time_type t , const StateOut &out , time_type dt ) | |
160 { | |
161 do_step_impl( system , in , t , out , dt ); | |
162 } | |
163 | |
164 | |
165 template< class StateType > | |
166 void adjust_size( const StateType &x ) | |
167 { | |
168 resize_impl( x ); | |
169 } | |
170 | |
171 const step_storage_type& step_storage( void ) const | |
172 { | |
173 return m_step_storage; | |
174 } | |
175 | |
176 step_storage_type& step_storage( void ) | |
177 { | |
178 return m_step_storage; | |
179 } | |
180 | |
181 template< class ExplicitStepper , class System , class StateIn > | |
182 void initialize( ExplicitStepper explicit_stepper , System system , StateIn &x , time_type &t , time_type dt ) | |
183 { | |
184 typename odeint::unwrap_reference< ExplicitStepper >::type &stepper = explicit_stepper; | |
185 typename odeint::unwrap_reference< System >::type &sys = system; | |
186 | |
187 m_resizer.adjust_size( x , detail::bind( &stepper_type::template resize_impl<StateIn> , detail::ref( *this ) , detail::_1 ) ); | |
188 | |
189 for( size_t i=0 ; i<steps-1 ; ++i ) | |
190 { | |
191 if( i != 0 ) m_step_storage.rotate(); | |
192 sys( x , m_step_storage[0].m_v , t ); | |
193 stepper.do_step( system , x , m_step_storage[0].m_v , t , dt ); | |
194 t += dt; | |
195 } | |
196 m_steps_initialized = steps; | |
197 } | |
198 | |
199 template< class System , class StateIn > | |
200 void initialize( System system , StateIn &x , time_type &t , time_type dt ) | |
201 { | |
202 initialize( detail::ref( m_initializing_stepper ) , system , x , t , dt ); | |
203 } | |
204 | |
205 void reset( void ) | |
206 { | |
207 m_steps_initialized = 0; | |
208 } | |
209 | |
210 bool is_initialized( void ) const | |
211 { | |
212 return m_steps_initialized >= steps; | |
213 } | |
214 | |
215 const initializing_stepper_type& initializing_stepper( void ) const { return m_initializing_stepper; } | |
216 | |
217 initializing_stepper_type& initializing_stepper( void ) { return m_initializing_stepper; } | |
218 | |
219 private: | |
220 | |
221 template< class System , class StateIn , class StateOut > | |
222 void do_step_impl( System system , const StateIn &in , time_type t , StateOut &out , time_type dt ) | |
223 { | |
224 typename odeint::unwrap_reference< System >::type &sys = system; | |
225 if( m_resizer.adjust_size( in , detail::bind( &stepper_type::template resize_impl<StateIn> , detail::ref( *this ) , detail::_1 ) ) ) | |
226 { | |
227 m_steps_initialized = 0; | |
228 } | |
229 | |
230 if( m_steps_initialized < steps - 1 ) | |
231 { | |
232 if( m_steps_initialized != 0 ) m_step_storage.rotate(); | |
233 sys( in , m_step_storage[0].m_v , t ); | |
234 m_initializing_stepper.do_step( system , in , m_step_storage[0].m_v , t , out , dt ); | |
235 m_steps_initialized++; | |
236 } | |
237 else | |
238 { | |
239 m_step_storage.rotate(); | |
240 sys( in , m_step_storage[0].m_v , t ); | |
241 detail::adams_bashforth_call_algebra< steps , algebra_type , operations_type >()( m_algebra , in , out , m_step_storage , m_coefficients , dt ); | |
242 } | |
243 } | |
244 | |
245 | |
246 template< class StateIn > | |
247 bool resize_impl( const StateIn &x ) | |
248 { | |
249 bool resized( false ); | |
250 for( size_t i=0 ; i<steps ; ++i ) | |
251 { | |
252 resized |= adjust_size_by_resizeability( m_step_storage[i] , x , typename is_resizeable<deriv_type>::type() ); | |
253 } | |
254 return resized; | |
255 } | |
256 | |
257 step_storage_type m_step_storage; | |
258 resizer_type m_resizer; | |
259 const detail::adams_bashforth_coefficients< value_type , steps > m_coefficients; | |
260 size_t m_steps_initialized; | |
261 initializing_stepper_type m_initializing_stepper; | |
262 | |
263 | |
264 | |
265 | |
266 | |
267 | |
268 | |
269 protected: | |
270 | |
271 algebra_type m_algebra; | |
272 }; | |
273 | |
274 | |
275 /***** DOXYGEN *****/ | |
276 | |
277 /** | |
278 * \class adams_bashforth | |
279 * \brief The Adams-Bashforth multistep algorithm. | |
280 * | |
281 * The Adams-Bashforth method is a multi-step algorithm with configurable step | |
282 * number. The step number is specified as template parameter Steps and it | |
283 * then uses the result from the previous Steps steps. See also | |
284 * <a href="http://en.wikipedia.org/wiki/Linear_multistep_method">en.wikipedia.org/wiki/Linear_multistep_method</a>. | |
285 * Currently, a maximum of Steps=8 is supported. | |
286 * The method is explicit and fulfills the Stepper concept. Step size control | |
287 * or continuous output are not provided. | |
288 * | |
289 * This class derives from algebra_base and inherits its interface via | |
290 * CRTP (current recurring template pattern). For more details see | |
291 * algebra_stepper_base. | |
292 * | |
293 * \tparam Steps The number of steps (maximal 8). | |
294 * \tparam State The state type. | |
295 * \tparam Value The value type. | |
296 * \tparam Deriv The type representing the time derivative of the state. | |
297 * \tparam Time The time representing the independent variable - the time. | |
298 * \tparam Algebra The algebra type. | |
299 * \tparam Operations The operations type. | |
300 * \tparam Resizer The resizer policy type. | |
301 * \tparam InitializingStepper The stepper for the first two steps. | |
302 */ | |
303 | |
304 /** | |
305 * \fn adams_bashforth::adams_bashforth( const algebra_type &algebra ) | |
306 * \brief Constructs the adams_bashforth class. This constructor can be used as a default | |
307 * constructor if the algebra has a default constructor. | |
308 * \param algebra A copy of algebra is made and stored. | |
309 */ | |
310 | |
311 /** | |
312 * \fn order_type adams_bashforth::order( void ) const | |
313 * \brief Returns the order of the algorithm, which is equal to the number of steps. | |
314 * \return order of the method. | |
315 */ | |
316 | |
317 /** | |
318 * \fn void adams_bashforth::do_step( System system , StateInOut &x , time_type t , time_type dt ) | |
319 * \brief This method performs one step. It transforms the result in-place. | |
320 * | |
321 * \param system The system function to solve, hence the r.h.s. of the ordinary differential equation. It must fulfill the | |
322 * Simple System concept. | |
323 * \param x The state of the ODE which should be solved. After calling do_step the result is updated in x. | |
324 * \param t The value of the time, at which the step should be performed. | |
325 * \param dt The step size. | |
326 */ | |
327 | |
328 /** | |
329 * \fn void adams_bashforth::do_step( System system , const StateIn &in , time_type t , StateOut &out , time_type dt ) | |
330 * \brief The method performs one step with the stepper passed by Stepper. The state of the ODE is updated out-of-place. | |
331 * | |
332 * \param system The system function to solve, hence the r.h.s. of the ODE. It must fulfill the | |
333 * Simple System concept. | |
334 * \param in The state of the ODE which should be solved. in is not modified in this method | |
335 * \param t The value of the time, at which the step should be performed. | |
336 * \param out The result of the step is written in out. | |
337 * \param dt The step size. | |
338 */ | |
339 | |
340 /** | |
341 * \fn void adams_bashforth::adjust_size( const StateType &x ) | |
342 * \brief Adjust the size of all temporaries in the stepper manually. | |
343 * \param x A state from which the size of the temporaries to be resized is deduced. | |
344 */ | |
345 | |
346 | |
347 /** | |
348 * \fn const step_storage_type& adams_bashforth::step_storage( void ) const | |
349 * \brief Returns the storage of intermediate results. | |
350 * \return The storage of intermediate results. | |
351 */ | |
352 | |
353 /** | |
354 * \fn step_storage_type& adams_bashforth::step_storage( void ) | |
355 * \brief Returns the storage of intermediate results. | |
356 * \return The storage of intermediate results. | |
357 */ | |
358 | |
359 /** | |
360 * \fn void adams_bashforth::initialize( ExplicitStepper explicit_stepper , System system , StateIn &x , time_type &t , time_type dt ) | |
361 * \brief Initialized the stepper. Does Steps-1 steps with the explicit_stepper to fill the buffer. | |
362 * \param explicit_stepper the stepper used to fill the buffer of previous step results | |
363 * \param system The system function to solve, hence the r.h.s. of the ordinary differential equation. It must fulfill the | |
364 * Simple System concept. | |
365 * \param x The state of the ODE which should be solved. After calling do_step the result is updated in x. | |
366 * \param t The value of the time, at which the step should be performed. | |
367 * \param dt The step size. | |
368 */ | |
369 | |
370 /** | |
371 * \fn void adams_bashforth::initialize( System system , StateIn &x , time_type &t , time_type dt ) | |
372 * \brief Initialized the stepper. Does Steps-1 steps with an internal instance of InitializingStepper to fill the buffer. | |
373 * \note The state x and time t are updated to the values after Steps-1 initial steps. | |
374 * \param system The system function to solve, hence the r.h.s. of the ordinary differential equation. It must fulfill the | |
375 * Simple System concept. | |
376 * \param x The initial state of the ODE which should be solved, updated in this method. | |
377 * \param t The initial value of the time, updated in this method. | |
378 * \param dt The step size. | |
379 */ | |
380 | |
381 /** | |
382 * \fn void adams_bashforth::reset( void ) | |
383 * \brief Resets the internal buffer of the stepper. | |
384 */ | |
385 | |
386 /** | |
387 * \fn bool adams_bashforth::is_initialized( void ) const | |
388 * \brief Returns true if the stepper has been initialized. | |
389 * \return bool true if stepper is initialized, false otherwise | |
390 */ | |
391 | |
392 /** | |
393 * \fn const initializing_stepper_type& adams_bashforth::initializing_stepper( void ) const | |
394 * \brief Returns the internal initializing stepper instance. | |
395 * \return initializing_stepper | |
396 */ | |
397 | |
398 /** | |
399 * \fn const initializing_stepper_type& adams_bashforth::initializing_stepper( void ) const | |
400 * \brief Returns the internal initializing stepper instance. | |
401 * \return initializing_stepper | |
402 */ | |
403 | |
404 /** | |
405 * \fn initializing_stepper_type& adams_bashforth::initializing_stepper( void ) | |
406 * \brief Returns the internal initializing stepper instance. | |
407 * \return initializing_stepper | |
408 */ | |
409 | |
410 } // odeint | |
411 } // numeric | |
412 } // boost | |
413 | |
414 | |
415 | |
416 #endif // BOOST_NUMERIC_ODEINT_STEPPER_ADAMS_BASHFORTH_HPP_INCLUDED |