annotate DEPENDENCIES/generic/include/boost/numeric/odeint/stepper/adams_bashforth.hpp @ 46:d572322e2efe

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