File indexing completed on 2025-07-05 08:40:09
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 static_assert(( Steps > 0 && Steps < 9 ), "Must have between 1 and 8 steps inclusive");
0060 #endif
0061
0062 public :
0063
0064 typedef State state_type;
0065 typedef state_wrapper< state_type > wrapped_state_type;
0066 typedef Value value_type;
0067 typedef Deriv deriv_type;
0068 typedef state_wrapper< deriv_type > wrapped_deriv_type;
0069 typedef Time time_type;
0070 typedef Algebra algebra_type;
0071 typedef Operations operations_type;
0072 typedef Resizer resizer_type;
0073 typedef stepper_tag stepper_category;
0074 typedef InitializingStepper initializing_stepper_type;
0075
0076 static const size_t steps = Steps;
0077 #ifndef DOXYGEN_SKIP
0078 typedef adams_bashforth< steps , state_type , value_type , deriv_type , time_type , algebra_type , operations_type , resizer_type, initializing_stepper_type > adams_bashforth_type;
0079 typedef adams_moulton< steps , state_type , value_type , deriv_type , time_type , algebra_type , operations_type , resizer_type > adams_moulton_type;
0080 typedef adams_bashforth_moulton< steps , state_type , value_type , deriv_type , time_type , algebra_type , operations_type , resizer_type , initializing_stepper_type> stepper_type;
0081 #endif
0082 typedef unsigned short order_type;
0083 static const order_type order_value = steps;
0084
0085
0086 adams_bashforth_moulton( void )
0087 : m_adams_bashforth() , m_adams_moulton( m_adams_bashforth.algebra() )
0088 , m_x() , m_resizer()
0089 { }
0090
0091 adams_bashforth_moulton( const algebra_type &algebra )
0092 : m_adams_bashforth( algebra ) , m_adams_moulton( m_adams_bashforth.algebra() )
0093 , m_x() , m_resizer()
0094 { }
0095
0096 order_type order( void ) const { return order_value; }
0097
0098 template< class System , class StateInOut >
0099 void do_step( System system , StateInOut &x , time_type t , time_type dt )
0100 {
0101 do_step_impl1( system , x , t , dt );
0102 }
0103
0104
0105
0106
0107 template< class System , class StateInOut >
0108 void do_step( System system , const StateInOut &x , time_type t , time_type dt )
0109 {
0110 do_step_impl1( system , x , t , dt );
0111 }
0112
0113 template< class System , class StateIn , class StateOut >
0114 void do_step( System system , const StateIn &in , time_type t , const StateOut &out , time_type dt )
0115 {
0116 do_step_impl2( system , in , t , out , dt );
0117 }
0118
0119
0120
0121
0122 template< class System , class StateIn , class StateOut >
0123 void do_step( System system , const StateIn &in , time_type t , StateOut &out , time_type dt )
0124 {
0125 do_step_impl2( system , in ,t , out , dt );
0126 }
0127
0128
0129 template< class StateType >
0130 void adjust_size( const StateType &x )
0131 {
0132 m_adams_bashforth.adjust_size( x );
0133 m_adams_moulton.adjust_size( x );
0134 resize_impl( x );
0135 }
0136
0137
0138 template< class ExplicitStepper , class System , class StateIn >
0139 void initialize( ExplicitStepper explicit_stepper , System system , StateIn &x , time_type &t , time_type dt )
0140 {
0141 m_adams_bashforth.initialize( explicit_stepper , system , x , t , dt );
0142 }
0143
0144
0145 template< class System , class StateIn >
0146 void initialize( System system , StateIn &x , time_type &t , time_type dt )
0147 {
0148 m_adams_bashforth.initialize( system , x , t , dt );
0149 }
0150
0151
0152 void reset(void)
0153 {
0154 m_adams_bashforth.reset();
0155 }
0156
0157
0158
0159 private:
0160
0161 template< typename System , typename StateInOut >
0162 void do_step_impl1( System system , StateInOut &x , time_type t , time_type dt )
0163 {
0164 if( m_adams_bashforth.is_initialized() )
0165 {
0166 m_resizer.adjust_size(x, [this](auto&& arg) { return this->resize_impl<StateInOut>(std::forward<decltype(arg)>(arg)); });
0167 m_adams_bashforth.do_step( system , x , t , m_x.m_v , dt );
0168 m_adams_moulton.do_step( system , x , m_x.m_v , t+dt , x , dt , m_adams_bashforth.step_storage() );
0169 }
0170 else
0171 {
0172 m_adams_bashforth.do_step( system , x , t , dt );
0173 }
0174 }
0175
0176 template< typename System , typename StateIn , typename StateInOut >
0177 void do_step_impl2( System system , StateIn const &in , time_type t , StateInOut & out , time_type dt )
0178 {
0179 if( m_adams_bashforth.is_initialized() )
0180 {
0181 m_resizer.adjust_size(in, [this](auto&& arg) { return this->resize_impl<StateIn>(std::forward<decltype(arg)>(arg)); });
0182 m_adams_bashforth.do_step( system , in , t , m_x.m_v , dt );
0183 m_adams_moulton.do_step( system , in , m_x.m_v , t+dt , out , dt , m_adams_bashforth.step_storage() );
0184 }
0185 else
0186 {
0187 m_adams_bashforth.do_step( system , in , t , out , dt );
0188 }
0189 }
0190
0191
0192 template< class StateIn >
0193 bool resize_impl( const StateIn &x )
0194 {
0195 return adjust_size_by_resizeability( m_x , x , typename is_resizeable< state_type >::type() );
0196 }
0197
0198 adams_bashforth_type m_adams_bashforth;
0199 adams_moulton_type m_adams_moulton;
0200 wrapped_state_type m_x;
0201 resizer_type m_resizer;
0202 };
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 #endif