File indexing completed on 2025-01-18 09:42:55
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019 #ifndef BOOST_NUMERIC_ODEINT_STEPPER_ADAMS_BASHFORTH_MOULTON_HPP_INCLUDED
0020 #define BOOST_NUMERIC_ODEINT_STEPPER_ADAMS_BASHFORTH_MOULTON_HPP_INCLUDED
0021
0022
0023 #include <boost/numeric/odeint/util/bind.hpp>
0024
0025 #include <boost/numeric/odeint/stepper/stepper_categories.hpp>
0026 #include <boost/numeric/odeint/algebra/range_algebra.hpp>
0027 #include <boost/numeric/odeint/algebra/default_operations.hpp>
0028 #include <boost/numeric/odeint/algebra/algebra_dispatcher.hpp>
0029 #include <boost/numeric/odeint/algebra/operations_dispatcher.hpp>
0030
0031 #include <boost/numeric/odeint/util/state_wrapper.hpp>
0032 #include <boost/numeric/odeint/util/resizer.hpp>
0033
0034 #include <boost/numeric/odeint/stepper/adams_bashforth.hpp>
0035 #include <boost/numeric/odeint/stepper/adams_moulton.hpp>
0036
0037
0038
0039 namespace boost {
0040 namespace numeric {
0041 namespace odeint {
0042
0043
0044 template<
0045 size_t Steps ,
0046 class State ,
0047 class Value = double ,
0048 class Deriv = State ,
0049 class Time = Value ,
0050 class Algebra = typename algebra_dispatcher< State >::algebra_type ,
0051 class Operations = typename operations_dispatcher< State >::operations_type ,
0052 class Resizer = initially_resizer,
0053 class InitializingStepper = runge_kutta4< State , Value , Deriv , Time , Algebra , Operations, Resizer >
0054 >
0055 class adams_bashforth_moulton
0056 {
0057
0058 #ifndef DOXYGEN_SKIP
0059 BOOST_STATIC_ASSERT(( Steps > 0 ));
0060 BOOST_STATIC_ASSERT(( Steps < 9 ));
0061 #endif
0062
0063 public :
0064
0065 typedef State state_type;
0066 typedef state_wrapper< state_type > wrapped_state_type;
0067 typedef Value value_type;
0068 typedef Deriv deriv_type;
0069 typedef state_wrapper< deriv_type > wrapped_deriv_type;
0070 typedef Time time_type;
0071 typedef Algebra algebra_type;
0072 typedef Operations operations_type;
0073 typedef Resizer resizer_type;
0074 typedef stepper_tag stepper_category;
0075 typedef InitializingStepper initializing_stepper_type;
0076
0077 static const size_t steps = Steps;
0078 #ifndef DOXYGEN_SKIP
0079 typedef adams_bashforth< steps , state_type , value_type , deriv_type , time_type , algebra_type , operations_type , resizer_type, initializing_stepper_type > adams_bashforth_type;
0080 typedef adams_moulton< steps , state_type , value_type , deriv_type , time_type , algebra_type , operations_type , resizer_type > adams_moulton_type;
0081 typedef adams_bashforth_moulton< steps , state_type , value_type , deriv_type , time_type , algebra_type , operations_type , resizer_type , initializing_stepper_type> stepper_type;
0082 #endif
0083 typedef unsigned short order_type;
0084 static const order_type order_value = steps;
0085
0086
0087 adams_bashforth_moulton( void )
0088 : m_adams_bashforth() , m_adams_moulton( m_adams_bashforth.algebra() )
0089 , m_x() , m_resizer()
0090 { }
0091
0092 adams_bashforth_moulton( const algebra_type &algebra )
0093 : m_adams_bashforth( algebra ) , m_adams_moulton( m_adams_bashforth.algebra() )
0094 , m_x() , m_resizer()
0095 { }
0096
0097 order_type order( void ) const { return order_value; }
0098
0099 template< class System , class StateInOut >
0100 void do_step( System system , StateInOut &x , time_type t , time_type dt )
0101 {
0102 do_step_impl1( system , x , t , dt );
0103 }
0104
0105
0106
0107
0108 template< class System , class StateInOut >
0109 void do_step( System system , const StateInOut &x , time_type t , time_type dt )
0110 {
0111 do_step_impl1( system , x , t , dt );
0112 }
0113
0114 template< class System , class StateIn , class StateOut >
0115 void do_step( System system , const StateIn &in , time_type t , const StateOut &out , time_type dt )
0116 {
0117 do_step_impl2( system , in , t , out , dt );
0118 }
0119
0120
0121
0122
0123 template< class System , class StateIn , class StateOut >
0124 void do_step( System system , const StateIn &in , time_type t , StateOut &out , time_type dt )
0125 {
0126 do_step_impl2( system , in ,t , out , dt );
0127 }
0128
0129
0130 template< class StateType >
0131 void adjust_size( const StateType &x )
0132 {
0133 m_adams_bashforth.adjust_size( x );
0134 m_adams_moulton.adjust_size( x );
0135 resize_impl( x );
0136 }
0137
0138
0139 template< class ExplicitStepper , class System , class StateIn >
0140 void initialize( ExplicitStepper explicit_stepper , System system , StateIn &x , time_type &t , time_type dt )
0141 {
0142 m_adams_bashforth.initialize( explicit_stepper , system , x , t , dt );
0143 }
0144
0145
0146 template< class System , class StateIn >
0147 void initialize( System system , StateIn &x , time_type &t , time_type dt )
0148 {
0149 m_adams_bashforth.initialize( system , x , t , dt );
0150 }
0151
0152
0153 void reset(void)
0154 {
0155 m_adams_bashforth.reset();
0156 }
0157
0158
0159
0160 private:
0161
0162 template< typename System , typename StateInOut >
0163 void do_step_impl1( System system , StateInOut &x , time_type t , time_type dt )
0164 {
0165 if( m_adams_bashforth.is_initialized() )
0166 {
0167 m_resizer.adjust_size( x , detail::bind( &stepper_type::template resize_impl< StateInOut > , detail::ref( *this ) , detail::_1 ) );
0168 m_adams_bashforth.do_step( system , x , t , m_x.m_v , dt );
0169 m_adams_moulton.do_step( system , x , m_x.m_v , t+dt , x , dt , m_adams_bashforth.step_storage() );
0170 }
0171 else
0172 {
0173 m_adams_bashforth.do_step( system , x , t , dt );
0174 }
0175 }
0176
0177 template< typename System , typename StateIn , typename StateInOut >
0178 void do_step_impl2( System system , StateIn const &in , time_type t , StateInOut & out , time_type dt )
0179 {
0180 if( m_adams_bashforth.is_initialized() )
0181 {
0182 m_resizer.adjust_size( in , detail::bind( &stepper_type::template resize_impl< StateInOut > , detail::ref( *this ) , detail::_1 ) );
0183 m_adams_bashforth.do_step( system , in , t , m_x.m_v , dt );
0184 m_adams_moulton.do_step( system , in , m_x.m_v , t+dt , out , dt , m_adams_bashforth.step_storage() );
0185 }
0186 else
0187 {
0188 m_adams_bashforth.do_step( system , in , t , out , dt );
0189 }
0190 }
0191
0192
0193 template< class StateIn >
0194 bool resize_impl( const StateIn &x )
0195 {
0196 return adjust_size_by_resizeability( m_x , x , typename is_resizeable< state_type >::type() );
0197 }
0198
0199 adams_bashforth_type m_adams_bashforth;
0200 adams_moulton_type m_adams_moulton;
0201 wrapped_state_type m_x;
0202 resizer_type m_resizer;
0203 };
0204
0205
0206
0207
0208
0209
0210
0211
0212
0213
0214
0215
0216
0217
0218
0219
0220
0221
0222
0223
0224
0225
0226
0227
0228
0229
0230
0231
0232
0233
0234
0235
0236
0237
0238
0239
0240
0241
0242
0243
0244
0245
0246
0247
0248
0249
0250
0251
0252
0253
0254
0255
0256
0257
0258
0259
0260
0261
0262
0263
0264
0265
0266
0267
0268
0269
0270
0271
0272
0273
0274
0275
0276
0277
0278
0279
0280
0281
0282
0283
0284
0285
0286
0287
0288
0289
0290
0291
0292
0293
0294
0295
0296
0297
0298
0299
0300
0301
0302
0303
0304
0305
0306
0307
0308 }
0309 }
0310 }
0311
0312
0313
0314 #endif