]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | /* |
2 | [auto_generated] | |
3 | boost/numeric/odeint/stepper/adams_bashforth_moulton.hpp | |
4 | ||
5 | [begin_description] | |
6 | Implementation of the Adams-Bashforth-Moulton method, a predictor-corrector multistep method. | |
7 | [end_description] | |
8 | ||
9 | Copyright 2011-2013 Karsten Ahnert | |
10 | Copyright 2011-2013 Mario Mulansky | |
11 | Copyright 2012 Christoph Koke | |
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_MOULTON_HPP_INCLUDED | |
20 | #define BOOST_NUMERIC_ODEINT_STEPPER_ADAMS_BASHFORTH_MOULTON_HPP_INCLUDED | |
21 | ||
22 | ||
23 | #include <boost/numeric/odeint/util/bind.hpp> | |
24 | ||
25 | #include <boost/numeric/odeint/stepper/stepper_categories.hpp> | |
26 | #include <boost/numeric/odeint/algebra/range_algebra.hpp> | |
27 | #include <boost/numeric/odeint/algebra/default_operations.hpp> | |
28 | #include <boost/numeric/odeint/algebra/algebra_dispatcher.hpp> | |
29 | #include <boost/numeric/odeint/algebra/operations_dispatcher.hpp> | |
30 | ||
31 | #include <boost/numeric/odeint/util/state_wrapper.hpp> | |
32 | #include <boost/numeric/odeint/util/resizer.hpp> | |
33 | ||
34 | #include <boost/numeric/odeint/stepper/adams_bashforth.hpp> | |
35 | #include <boost/numeric/odeint/stepper/adams_moulton.hpp> | |
36 | ||
37 | ||
38 | ||
39 | namespace boost { | |
40 | namespace numeric { | |
41 | namespace odeint { | |
42 | ||
43 | ||
44 | template< | |
45 | size_t Steps , | |
46 | class State , | |
47 | class Value = double , | |
48 | class Deriv = State , | |
49 | class Time = Value , | |
50 | class Algebra = typename algebra_dispatcher< State >::algebra_type , | |
51 | class Operations = typename operations_dispatcher< State >::operations_type , | |
52 | class Resizer = initially_resizer, | |
53 | class InitializingStepper = runge_kutta4< State , Value , Deriv , Time , Algebra , Operations, Resizer > | |
54 | > | |
55 | class adams_bashforth_moulton | |
56 | { | |
57 | ||
58 | #ifndef DOXYGEN_SKIP | |
59 | BOOST_STATIC_ASSERT(( Steps > 0 )); | |
60 | BOOST_STATIC_ASSERT(( Steps < 9 )); | |
61 | #endif | |
62 | ||
63 | public : | |
64 | ||
65 | typedef State state_type; | |
66 | typedef state_wrapper< state_type > wrapped_state_type; | |
67 | typedef Value value_type; | |
68 | typedef Deriv deriv_type; | |
69 | typedef state_wrapper< deriv_type > wrapped_deriv_type; | |
70 | typedef Time time_type; | |
71 | typedef Algebra algebra_type; | |
72 | typedef Operations operations_type; | |
73 | typedef Resizer resizer_type; | |
74 | typedef stepper_tag stepper_category; | |
75 | typedef InitializingStepper initializing_stepper_type; | |
76 | ||
77 | static const size_t steps = Steps; | |
78 | #ifndef DOXYGEN_SKIP | |
79 | typedef adams_bashforth< steps , state_type , value_type , deriv_type , time_type , algebra_type , operations_type , resizer_type, initializing_stepper_type > adams_bashforth_type; | |
80 | typedef adams_moulton< steps , state_type , value_type , deriv_type , time_type , algebra_type , operations_type , resizer_type > adams_moulton_type; | |
81 | typedef adams_bashforth_moulton< steps , state_type , value_type , deriv_type , time_type , algebra_type , operations_type , resizer_type , initializing_stepper_type> stepper_type; | |
82 | #endif //DOXYGEN_SKIP | |
83 | typedef unsigned short order_type; | |
84 | static const order_type order_value = steps; | |
85 | ||
86 | /** \brief Constructs the adams_bashforth class. */ | |
87 | adams_bashforth_moulton( void ) | |
88 | : m_adams_bashforth() , m_adams_moulton( m_adams_bashforth.algebra() ) | |
89 | , m_x() , m_resizer() | |
90 | { } | |
91 | ||
92 | adams_bashforth_moulton( const algebra_type &algebra ) | |
93 | : m_adams_bashforth( algebra ) , m_adams_moulton( m_adams_bashforth.algebra() ) | |
94 | , m_x() , m_resizer() | |
95 | { } | |
96 | ||
97 | order_type order( void ) const { return order_value; } | |
98 | ||
99 | template< class System , class StateInOut > | |
100 | void do_step( System system , StateInOut &x , time_type t , time_type dt ) | |
101 | { | |
102 | do_step_impl1( system , x , t , dt ); | |
103 | } | |
104 | ||
105 | /** | |
106 | * \brief Second version to solve the forwarding problem, can be called with Boost.Range as StateInOut. | |
107 | */ | |
108 | template< class System , class StateInOut > | |
109 | void do_step( System system , const StateInOut &x , time_type t , time_type dt ) | |
110 | { | |
111 | do_step_impl1( system , x , t , dt ); | |
112 | } | |
113 | ||
114 | template< class System , class StateIn , class StateOut > | |
115 | void do_step( System system , const StateIn &in , time_type t , const StateOut &out , time_type dt ) | |
116 | { | |
117 | do_step_impl2( system , in , t , out , dt ); | |
118 | } | |
119 | ||
120 | /** | |
121 | * \brief Second version to solve the forwarding problem, can be called with Boost.Range as StateOut. | |
122 | */ | |
123 | template< class System , class StateIn , class StateOut > | |
124 | void do_step( System system , const StateIn &in , time_type t , StateOut &out , time_type dt ) | |
125 | { | |
126 | do_step_impl2( system , in ,t , out , dt ); | |
127 | } | |
128 | ||
129 | ||
130 | template< class StateType > | |
131 | void adjust_size( const StateType &x ) | |
132 | { | |
133 | m_adams_bashforth.adjust_size( x ); | |
134 | m_adams_moulton.adjust_size( x ); | |
135 | resize_impl( x ); | |
136 | } | |
137 | ||
138 | ||
139 | template< class ExplicitStepper , class System , class StateIn > | |
140 | void initialize( ExplicitStepper explicit_stepper , System system , StateIn &x , time_type &t , time_type dt ) | |
141 | { | |
142 | m_adams_bashforth.initialize( explicit_stepper , system , x , t , dt ); | |
143 | } | |
144 | ||
145 | ||
146 | template< class System , class StateIn > | |
147 | void initialize( System system , StateIn &x , time_type &t , time_type dt ) | |
148 | { | |
149 | m_adams_bashforth.initialize( system , x , t , dt ); | |
150 | } | |
151 | ||
152 | ||
153 | ||
154 | private: | |
155 | ||
156 | template< typename System , typename StateInOut > | |
157 | void do_step_impl1( System system , StateInOut &x , time_type t , time_type dt ) | |
158 | { | |
159 | if( m_adams_bashforth.is_initialized() ) | |
160 | { | |
161 | m_resizer.adjust_size( x , detail::bind( &stepper_type::template resize_impl< StateInOut > , detail::ref( *this ) , detail::_1 ) ); | |
162 | m_adams_bashforth.do_step( system , x , t , m_x.m_v , dt ); | |
163 | m_adams_moulton.do_step( system , x , m_x.m_v , t+dt , x , dt , m_adams_bashforth.step_storage() ); | |
164 | } | |
165 | else | |
166 | { | |
167 | m_adams_bashforth.do_step( system , x , t , dt ); | |
168 | } | |
169 | } | |
170 | ||
171 | template< typename System , typename StateIn , typename StateInOut > | |
172 | void do_step_impl2( System system , StateIn const &in , time_type t , StateInOut & out , time_type dt ) | |
173 | { | |
174 | if( m_adams_bashforth.is_initialized() ) | |
175 | { | |
176 | m_resizer.adjust_size( in , detail::bind( &stepper_type::template resize_impl< StateInOut > , detail::ref( *this ) , detail::_1 ) ); | |
177 | m_adams_bashforth.do_step( system , in , t , m_x.m_v , dt ); | |
178 | m_adams_moulton.do_step( system , in , m_x.m_v , t , out , dt , m_adams_bashforth.step_storage() ); | |
179 | } | |
180 | else | |
181 | { | |
182 | m_adams_bashforth.do_step( system , in , t , out , dt ); | |
183 | } | |
184 | } | |
185 | ||
186 | ||
187 | template< class StateIn > | |
188 | bool resize_impl( const StateIn &x ) | |
189 | { | |
190 | return adjust_size_by_resizeability( m_x , x , typename is_resizeable< state_type >::type() ); | |
191 | } | |
192 | ||
193 | adams_bashforth_type m_adams_bashforth; | |
194 | adams_moulton_type m_adams_moulton; | |
195 | wrapped_state_type m_x; | |
196 | resizer_type m_resizer; | |
197 | }; | |
198 | ||
199 | ||
200 | /********* DOXYGEN ********/ | |
201 | ||
202 | /** | |
203 | * \class adams_bashforth_moulton | |
204 | * \brief The Adams-Bashforth-Moulton multistep algorithm. | |
205 | * | |
206 | * The Adams-Bashforth method is a multi-step predictor-corrector algorithm | |
207 | * with configurable step number. The step number is specified as template | |
208 | * parameter Steps and it then uses the result from the previous Steps steps. | |
209 | * See also | |
210 | * <a href="http://en.wikipedia.org/wiki/Linear_multistep_method">en.wikipedia.org/wiki/Linear_multistep_method</a>. | |
211 | * Currently, a maximum of Steps=8 is supported. | |
212 | * The method is explicit and fulfills the Stepper concept. Step size control | |
213 | * or continuous output are not provided. | |
214 | * | |
215 | * This class derives from algebra_base and inherits its interface via | |
216 | * CRTP (current recurring template pattern). For more details see | |
217 | * algebra_stepper_base. | |
218 | * | |
219 | * \tparam Steps The number of steps (maximal 8). | |
220 | * \tparam State The state type. | |
221 | * \tparam Value The value type. | |
222 | * \tparam Deriv The type representing the time derivative of the state. | |
223 | * \tparam Time The time representing the independent variable - the time. | |
224 | * \tparam Algebra The algebra type. | |
225 | * \tparam Operations The operations type. | |
226 | * \tparam Resizer The resizer policy type. | |
227 | * \tparam InitializingStepper The stepper for the first two steps. | |
228 | */ | |
229 | ||
230 | /** | |
231 | * \fn adams_bashforth_moulton::adams_bashforth_moulton( const algebra_type &algebra ) | |
232 | * \brief Constructs the adams_bashforth class. This constructor can be used as a default | |
233 | * constructor if the algebra has a default constructor. | |
234 | * \param algebra A copy of algebra is made and stored. | |
235 | */ | |
236 | ||
237 | /** | |
238 | * \fn adams_bashforth_moulton::order( void ) const | |
239 | * \brief Returns the order of the algorithm, which is equal to the number of steps+1. | |
240 | * \return order of the method. | |
241 | */ | |
242 | ||
243 | /** | |
244 | * \fn adams_bashforth_moulton::do_step( System system , StateInOut &x , time_type t , time_type dt ) | |
245 | * \brief This method performs one step. It transforms the result in-place. | |
246 | * | |
247 | * \param system The system function to solve, hence the r.h.s. of the ordinary differential equation. It must fulfill the | |
248 | * Simple System concept. | |
249 | * \param x The state of the ODE which should be solved. After calling do_step the result is updated in x. | |
250 | * \param t The value of the time, at which the step should be performed. | |
251 | * \param dt The step size. | |
252 | */ | |
253 | ||
254 | ||
255 | /** | |
256 | * \fn adams_bashforth_moulton::do_step( System system , const StateIn &in , time_type t , const StateOut &out , time_type dt ) | |
257 | * \brief The method performs one step with the stepper passed by Stepper. The state of the ODE is updated out-of-place. | |
258 | * | |
259 | * \param system The system function to solve, hence the r.h.s. of the ODE. It must fulfill the | |
260 | * Simple System concept. | |
261 | * \param in The state of the ODE which should be solved. in is not modified in this method | |
262 | * \param t The value of the time, at which the step should be performed. | |
263 | * \param out The result of the step is written in out. | |
264 | * \param dt The step size. | |
265 | */ | |
266 | ||
267 | /** | |
268 | * \fn adams_bashforth_moulton::adjust_size( const StateType &x ) | |
269 | * \brief Adjust the size of all temporaries in the stepper manually. | |
270 | * \param x A state from which the size of the temporaries to be resized is deduced. | |
271 | */ | |
272 | ||
273 | /** | |
274 | * \fn adams_bashforth_moulton::initialize( ExplicitStepper explicit_stepper , System system , StateIn &x , time_type &t , time_type dt ) | |
275 | * \brief Initialized the stepper. Does Steps-1 steps with the explicit_stepper to fill the buffer. | |
276 | * \note The state x and time t are updated to the values after Steps-1 initial steps. | |
277 | * \param explicit_stepper the stepper used to fill the buffer of previous step results | |
278 | * \param system The system function to solve, hence the r.h.s. of the ordinary differential equation. It must fulfill the | |
279 | * Simple System concept. | |
280 | * \param x The initial state of the ODE which should be solved, updated after in this method. | |
281 | * \param t The initial time, updated in this method. | |
282 | * \param dt The step size. | |
283 | */ | |
284 | ||
285 | /** | |
286 | * \fn adams_bashforth_moulton::initialize( System system , StateIn &x , time_type &t , time_type dt ) | |
287 | * \brief Initialized the stepper. Does Steps-1 steps using the standard initializing stepper | |
288 | * of the underlying adams_bashforth stepper. | |
289 | * \param system The system function to solve, hence the r.h.s. of the ordinary differential equation. It must fulfill the | |
290 | * Simple System concept. | |
291 | * \param x The state of the ODE which should be solved. After calling do_step the result is updated in x. | |
292 | * \param t The value of the time, at which the step should be performed. | |
293 | * \param dt The step size. | |
294 | */ | |
295 | ||
296 | ||
297 | } // odeint | |
298 | } // numeric | |
299 | } // boost | |
300 | ||
301 | ||
302 | ||
303 | #endif // BOOST_NUMERIC_ODEINT_STEPPER_ADAMS_BASHFORTH_MOULTON_HPP_INCLUDED |