File indexing completed on 2025-01-18 09:42:56
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019 #ifndef BOOST_NUMERIC_ODEINT_STEPPER_EXPLICIT_ERROR_GENERIC_RK_HPP_INCLUDED
0020 #define BOOST_NUMERIC_ODEINT_STEPPER_EXPLICIT_ERROR_GENERIC_RK_HPP_INCLUDED
0021
0022 #include <boost/numeric/odeint/stepper/base/explicit_error_stepper_base.hpp>
0023
0024 #include <boost/numeric/odeint/algebra/default_operations.hpp>
0025 #include <boost/numeric/odeint/algebra/range_algebra.hpp>
0026 #include <boost/numeric/odeint/algebra/algebra_dispatcher.hpp>
0027 #include <boost/numeric/odeint/algebra/operations_dispatcher.hpp>
0028 #include <boost/numeric/odeint/stepper/detail/generic_rk_algorithm.hpp>
0029 #include <boost/numeric/odeint/stepper/detail/generic_rk_call_algebra.hpp>
0030 #include <boost/numeric/odeint/stepper/detail/generic_rk_operations.hpp>
0031
0032 #include <boost/numeric/odeint/util/state_wrapper.hpp>
0033 #include <boost/numeric/odeint/util/is_resizeable.hpp>
0034 #include <boost/numeric/odeint/util/resizer.hpp>
0035
0036
0037
0038 namespace boost {
0039 namespace numeric {
0040 namespace odeint {
0041
0042
0043 template<
0044 size_t StageCount,
0045 size_t Order,
0046 size_t StepperOrder ,
0047 size_t ErrorOrder ,
0048 class State ,
0049 class Value = double ,
0050 class Deriv = State ,
0051 class Time = Value ,
0052 class Algebra = typename algebra_dispatcher< State >::algebra_type ,
0053 class Operations = typename operations_dispatcher< State >::operations_type ,
0054 class Resizer = initially_resizer
0055 >
0056 #ifndef DOXYGEN_SKIP
0057 class explicit_error_generic_rk
0058 : public explicit_error_stepper_base<
0059 explicit_error_generic_rk< StageCount , Order , StepperOrder , ErrorOrder , State ,
0060 Value , Deriv , Time , Algebra , Operations , Resizer > ,
0061 Order , StepperOrder , ErrorOrder , State , Value , Deriv , Time , Algebra ,
0062 Operations , Resizer >
0063 #else
0064 class explicit_error_generic_rk : public explicit_error_stepper_base
0065 #endif
0066 {
0067
0068 public:
0069 #ifndef DOXYGEN_SKIP
0070 typedef explicit_error_stepper_base<
0071 explicit_error_generic_rk< StageCount , Order , StepperOrder , ErrorOrder , State ,
0072 Value , Deriv , Time , Algebra , Operations , Resizer > ,
0073 Order , StepperOrder , ErrorOrder , State , Value , Deriv , Time , Algebra ,
0074 Operations , Resizer > stepper_base_type;
0075 #else
0076 typedef explicit_stepper_base< ... > stepper_base_type;
0077 #endif
0078 typedef typename stepper_base_type::state_type state_type;
0079 typedef typename stepper_base_type::wrapped_state_type wrapped_state_type;
0080 typedef typename stepper_base_type::value_type value_type;
0081 typedef typename stepper_base_type::deriv_type deriv_type;
0082 typedef typename stepper_base_type::wrapped_deriv_type wrapped_deriv_type;
0083 typedef typename stepper_base_type::time_type time_type;
0084 typedef typename stepper_base_type::algebra_type algebra_type;
0085 typedef typename stepper_base_type::operations_type operations_type;
0086 typedef typename stepper_base_type::resizer_type resizer_type;
0087 #ifndef DOXYGEN_SKIP
0088 typedef explicit_error_generic_rk< StageCount , Order , StepperOrder , ErrorOrder , State ,
0089 Value , Deriv , Time , Algebra , Operations , Resizer > stepper_type;
0090 #endif
0091 typedef detail::generic_rk_algorithm< StageCount , Value , Algebra , Operations > rk_algorithm_type;
0092
0093 typedef typename rk_algorithm_type::coef_a_type coef_a_type;
0094 typedef typename rk_algorithm_type::coef_b_type coef_b_type;
0095 typedef typename rk_algorithm_type::coef_c_type coef_c_type;
0096
0097 static const size_t stage_count = StageCount;
0098
0099 private:
0100
0101
0102 public:
0103
0104
0105
0106 explicit_error_generic_rk( const coef_a_type &a ,
0107 const coef_b_type &b ,
0108 const coef_b_type &b2 ,
0109 const coef_c_type &c ,
0110 const algebra_type &algebra = algebra_type() )
0111 : stepper_base_type( algebra ) , m_rk_algorithm( a , b , c ) , m_b2( b2 )
0112 { }
0113
0114
0115 template< class System , class StateIn , class DerivIn , class StateOut , class Err >
0116 void do_step_impl( System system , const StateIn &in , const DerivIn &dxdt ,
0117 time_type t , StateOut &out , time_type dt , Err &xerr )
0118 {
0119
0120 do_step_impl( system , in , dxdt , t , out , dt );
0121
0122
0123 detail::template generic_rk_call_algebra< StageCount , algebra_type >()( stepper_base_type::m_algebra ,
0124 xerr , dxdt , m_F , detail::generic_rk_scale_sum_err< StageCount , operations_type , value_type , time_type >( m_b2 , dt) );
0125 }
0126
0127
0128 template< class System , class StateIn , class DerivIn , class StateOut >
0129 void do_step_impl( System system , const StateIn &in , const DerivIn &dxdt ,
0130 time_type t , StateOut &out , time_type dt )
0131 {
0132 m_resizer.adjust_size( in , detail::bind( &stepper_type::template resize_impl< StateIn > , detail::ref( *this ) , detail::_1 ) );
0133
0134
0135 m_rk_algorithm.do_step( stepper_base_type::m_algebra , system , in , dxdt , t , out , dt , m_x_tmp.m_v , m_F );
0136 }
0137
0138
0139 template< class StateIn >
0140 void adjust_size( const StateIn &x )
0141 {
0142 resize_impl( x );
0143 stepper_base_type::adjust_size( x );
0144 }
0145
0146
0147 private:
0148
0149 template< class StateIn >
0150 bool resize_impl( const StateIn &x )
0151 {
0152 bool resized( false );
0153 resized |= adjust_size_by_resizeability( m_x_tmp , x , typename is_resizeable<state_type>::type() );
0154 for( size_t i = 0 ; i < StageCount-1 ; ++i )
0155 {
0156 resized |= adjust_size_by_resizeability( m_F[i] , x , typename is_resizeable<deriv_type>::type() );
0157 }
0158 return resized;
0159 }
0160
0161
0162 rk_algorithm_type m_rk_algorithm;
0163 coef_b_type m_b2;
0164
0165 resizer_type m_resizer;
0166
0167 wrapped_state_type m_x_tmp;
0168 wrapped_deriv_type m_F[StageCount-1];
0169
0170 };
0171
0172
0173
0174
0175
0176
0177
0178
0179
0180
0181
0182
0183
0184
0185
0186
0187
0188
0189
0190
0191
0192
0193
0194
0195
0196
0197
0198
0199
0200
0201
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 #endif