File indexing completed on 2025-01-18 09:42:53
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018 #ifndef BOOST_NUMERIC_ODEINT_ITERATOR_DETAIL_CONST_STEP_ITERATOR_IMPL_HPP_DEFINED
0019 #define BOOST_NUMERIC_ODEINT_ITERATOR_DETAIL_CONST_STEP_ITERATOR_IMPL_HPP_DEFINED
0020
0021 #include <boost/numeric/odeint/iterator/detail/ode_iterator_base.hpp>
0022 #include <boost/numeric/odeint/util/unit_helper.hpp>
0023
0024
0025
0026 namespace boost {
0027 namespace numeric {
0028 namespace odeint {
0029
0030
0031 template< class Iterator , class Stepper , class System , class State , typename Tag , class StepperTag >
0032 class const_step_iterator_impl;
0033
0034
0035
0036
0037
0038 template< class Iterator , class Stepper , class System , class State , typename Tag >
0039 class const_step_iterator_impl< Iterator , Stepper , System , State , Tag , stepper_tag >
0040 : public detail::ode_iterator_base< Iterator , Stepper , System , State , Tag >
0041 {
0042 private:
0043
0044 typedef Stepper stepper_type;
0045 typedef System system_type;
0046 typedef typename boost::numeric::odeint::unwrap_reference< stepper_type >::type unwrapped_stepper_type;
0047 typedef State state_type;
0048 typedef typename traits::time_type< stepper_type >::type time_type;
0049 typedef typename traits::value_type< stepper_type >::type ode_value_type;
0050 #ifndef DOXYGEN_SKIP
0051 typedef detail::ode_iterator_base< Iterator , Stepper , System , State , Tag > base_type;
0052 #endif
0053
0054 public:
0055
0056
0057
0058
0059
0060
0061
0062
0063
0064
0065
0066 const_step_iterator_impl( stepper_type stepper , system_type sys , state_type &s , time_type t , time_type t_end , time_type dt )
0067 : base_type( stepper , sys , t , dt ) , m_t_start( t ) , m_t_end( t_end ) , m_state( &s ) , m_step( 0 )
0068 {
0069 if( detail::less_with_sign( this->m_t_end , this->m_t , this->m_dt ) )
0070 this->m_at_end = true;
0071 }
0072
0073
0074
0075
0076
0077
0078
0079
0080 const_step_iterator_impl( stepper_type stepper , system_type sys , state_type& )
0081 : base_type( stepper , sys ) { }
0082
0083 protected:
0084
0085 friend class boost::iterator_core_access;
0086
0087 void increment()
0088 {
0089 if( detail::less_eq_with_sign( static_cast<time_type>(this->m_t+this->m_dt) ,
0090 this->m_t_end , this->m_dt ) )
0091 {
0092 unwrapped_stepper_type &stepper = this->m_stepper;
0093 stepper.do_step( this->m_system , *this->m_state , this->m_t , this->m_dt );
0094
0095 this->m_step++;
0096 this->m_t = this->m_t_start + static_cast< typename unit_value_type<time_type>::type >(this->m_step)*this->m_dt;
0097 } else {
0098 this->m_at_end = true;
0099 }
0100 }
0101
0102 public:
0103 const state_type& get_state() const
0104 {
0105 return *m_state;
0106 }
0107
0108 private:
0109 time_type m_t_start;
0110 time_type m_t_end;
0111 state_type* m_state;
0112 size_t m_step;
0113
0114 };
0115
0116
0117
0118
0119
0120
0121
0122
0123
0124
0125
0126
0127
0128
0129
0130
0131
0132 template< class Iterator , class Stepper , class System , class State , typename Tag >
0133 class const_step_iterator_impl< Iterator , Stepper , System , State , Tag , dense_output_stepper_tag >
0134 : public detail::ode_iterator_base< Iterator , Stepper , System , State , Tag >
0135 {
0136 private:
0137
0138 typedef Stepper stepper_type;
0139 typedef System system_type;
0140 typedef typename boost::numeric::odeint::unwrap_reference< stepper_type >::type unwrapped_stepper_type;
0141 typedef State state_type;
0142 typedef typename traits::time_type< stepper_type >::type time_type;
0143 typedef typename traits::value_type< stepper_type >::type ode_value_type;
0144 #ifndef DOXYGEN_SKIP
0145 typedef detail::ode_iterator_base< Iterator , Stepper , System , State , Tag > base_type;
0146 #endif
0147
0148 public:
0149
0150
0151
0152
0153
0154
0155
0156
0157
0158
0159
0160 const_step_iterator_impl( stepper_type stepper , system_type sys , state_type &s , time_type t , time_type t_end , time_type dt )
0161 : base_type( stepper , sys , t , dt ) , m_t_start( t ) , m_t_end( t_end ) , m_state( &s ) , m_step( 0 )
0162 {
0163 if( detail::less_eq_with_sign( this->m_t , this->m_t_end , this->m_dt ) )
0164 {
0165 unwrapped_stepper_type &st = this->m_stepper;
0166 st.initialize( * ( this->m_state ) , this->m_t , this->m_dt );
0167 } else {
0168 this->m_at_end = true;
0169 }
0170 }
0171
0172
0173
0174
0175
0176
0177
0178
0179 const_step_iterator_impl( stepper_type stepper , system_type sys , state_type &s )
0180 : base_type( stepper , sys ) , m_state( &s )
0181 {
0182 }
0183
0184
0185
0186 protected:
0187
0188 friend class boost::iterator_core_access;
0189
0190 void increment( void )
0191 {
0192 if( detail::less_eq_with_sign( static_cast<time_type>(this->m_t+this->m_dt) ,
0193 this->m_t_end , this->m_dt ) )
0194 {
0195 unwrapped_stepper_type &stepper = this->m_stepper;
0196
0197 this->m_step++;
0198 this->m_t = this->m_t_start + static_cast< typename unit_value_type<time_type>::type >(this->m_step)*this->m_dt;
0199 while( detail::less_with_sign( stepper.current_time() , this->m_t ,
0200 stepper.current_time_step() ) )
0201 {
0202 stepper.do_step( this->m_system );
0203 }
0204 stepper.calc_state( this->m_t , *( this->m_state ) );
0205 } else {
0206 this->m_at_end = true;
0207 }
0208 }
0209
0210 public:
0211 const state_type& get_state() const
0212 {
0213 return *m_state;
0214 }
0215
0216 private:
0217 time_type m_t_start;
0218 time_type m_t_end;
0219 state_type* m_state;
0220 size_t m_step;
0221 };
0222
0223 }
0224 }
0225 }
0226
0227
0228 #endif