1 /* 2 [auto_generated] 3 boost/numeric/odeint/iterator/detail/const_step_iterator_impl.hpp 4 5 [begin_description] 6 tba. 7 [end_description] 8 9 Copyright 2013 Karsten Ahnert 10 Copyright 2013 Mario Mulansky 11 12 Distributed under the Boost Software License, Version 1.0. 13 (See accompanying file LICENSE_1_0.txt or 14 copy at http://www.boost.org/LICENSE_1_0.txt) 15 */ 16 17 18 #ifndef BOOST_NUMERIC_ODEINT_ITERATOR_DETAIL_CONST_STEP_ITERATOR_IMPL_HPP_DEFINED 19 #define BOOST_NUMERIC_ODEINT_ITERATOR_DETAIL_CONST_STEP_ITERATOR_IMPL_HPP_DEFINED 20 21 #include <boost/numeric/odeint/iterator/detail/ode_iterator_base.hpp> 22 #include <boost/numeric/odeint/util/unit_helper.hpp> 23 24 25 26 namespace boost { 27 namespace numeric { 28 namespace odeint { 29 30 31 template< class Iterator , class Stepper , class System , class State , typename Tag , class StepperTag > 32 class const_step_iterator_impl; 33 34 35 /* 36 * Specilization for steppers and error steppers 37 */ 38 template< class Iterator , class Stepper , class System , class State , typename Tag > 39 class const_step_iterator_impl< Iterator , Stepper , System , State , Tag , stepper_tag > 40 : public detail::ode_iterator_base< Iterator , Stepper , System , State , Tag > 41 { 42 private: 43 44 typedef Stepper stepper_type; 45 typedef System system_type; 46 typedef typename boost::numeric::odeint::unwrap_reference< stepper_type >::type unwrapped_stepper_type; 47 typedef State state_type; 48 typedef typename traits::time_type< stepper_type >::type time_type; 49 typedef typename traits::value_type< stepper_type >::type ode_value_type; 50 #ifndef DOXYGEN_SKIP 51 typedef detail::ode_iterator_base< Iterator , Stepper , System , State , Tag > base_type; 52 #endif 53 54 public: 55 56 /** 57 * \brief Constructs a const_step_iterator. This constructor should be used to construct the begin iterator. 58 * 59 * \param stepper The stepper to use during the iteration. 60 * \param sys The system function (ODE) to solve. 61 * \param s The initial state. const_step_iterator stores a reference of s and changes its value during the iteration. 62 * \param t The initial time. 63 * \param t_end The end time, at which the iteration should stop. 64 * \param dt The initial time step. 65 */ const_step_iterator_impl(stepper_type stepper,system_type sys,state_type & s,time_type t,time_type t_end,time_type dt)66 const_step_iterator_impl( stepper_type stepper , system_type sys , state_type &s , time_type t , time_type t_end , time_type dt ) 67 : base_type( stepper , sys , t , dt ) , m_t_start( t ) , m_t_end( t_end ) , m_state( &s ) , m_step( 0 ) 68 { 69 if( detail::less_with_sign( this->m_t_end , this->m_t , this->m_dt ) ) 70 this->m_at_end = true; 71 } 72 73 /** 74 * \brief Constructs a const_step_iterator. This constructor should be used to construct the end iterator. 75 * 76 * \param stepper The stepper to use during the iteration. 77 * \param sys The system function (ODE) to solve. 78 * \param s The initial state. const_step_iterator stores a reference of s and changes its value during the iteration. 79 */ const_step_iterator_impl(stepper_type stepper,system_type sys,state_type &)80 const_step_iterator_impl( stepper_type stepper , system_type sys , state_type& /* s */ ) 81 : base_type( stepper , sys ) { } 82 83 protected: 84 85 friend class boost::iterator_core_access; 86 increment()87 void increment() 88 { 89 if( detail::less_eq_with_sign( static_cast<time_type>(this->m_t+this->m_dt) , 90 this->m_t_end , this->m_dt ) ) 91 { 92 unwrapped_stepper_type &stepper = this->m_stepper; 93 stepper.do_step( this->m_system , *this->m_state , this->m_t , this->m_dt ); 94 // use integer to compute current time to reduce roundoff errors 95 this->m_step++; 96 this->m_t = this->m_t_start + static_cast< typename unit_value_type<time_type>::type >(this->m_step)*this->m_dt; 97 } else { 98 this->m_at_end = true; 99 } 100 } 101 102 public: get_state() const103 const state_type& get_state() const 104 { 105 return *m_state; 106 } 107 108 private: 109 time_type m_t_start; 110 time_type m_t_end; 111 state_type* m_state; 112 size_t m_step; 113 114 }; 115 116 117 118 /* 119 * Specilization for dense output stepper 120 */ 121 /** 122 * \brief ODE Iterator with constant step size. The value type of this iterator is the state type of the stepper. 123 * 124 * Implements an ODE iterator solving the ODE with constant steps. Uses dense-output steppers. 125 * const_step_iterator is a model of single-pass iterator. 126 * 127 * The value type of this iterator is the state type of the stepper. Hence one can only access the state and not the current time. 128 * 129 * \tparam Stepper The stepper type which should be used during the iteration. 130 * \tparam System The type of the system function (ODE) which should be solved. 131 */ 132 template< class Iterator , class Stepper , class System , class State , typename Tag > 133 class const_step_iterator_impl< Iterator , Stepper , System , State , Tag , dense_output_stepper_tag > 134 : public detail::ode_iterator_base< Iterator , Stepper , System , State , Tag > 135 { 136 private: 137 138 typedef Stepper stepper_type; 139 typedef System system_type; 140 typedef typename boost::numeric::odeint::unwrap_reference< stepper_type >::type unwrapped_stepper_type; 141 typedef State state_type; 142 typedef typename traits::time_type< stepper_type >::type time_type; 143 typedef typename traits::value_type< stepper_type >::type ode_value_type; 144 #ifndef DOXYGEN_SKIP 145 typedef detail::ode_iterator_base< Iterator , Stepper , System , State , Tag > base_type; 146 #endif 147 148 public: 149 150 /** 151 * \brief Constructs a const_step_iterator. This constructor should be used to construct the begin iterator. 152 * 153 * \param stepper The stepper to use during the iteration. 154 * \param sys The system function (ODE) to solve. 155 * \param s The initial state. const_step_iterator stores a reference of s and changes its value during the iteration. 156 * \param t The initial time. 157 * \param t_end The end time, at which the iteration should stop. 158 * \param dt The initial time step. 159 */ const_step_iterator_impl(stepper_type stepper,system_type sys,state_type & s,time_type t,time_type t_end,time_type dt)160 const_step_iterator_impl( stepper_type stepper , system_type sys , state_type &s , time_type t , time_type t_end , time_type dt ) 161 : base_type( stepper , sys , t , dt ) , m_t_start( t ) , m_t_end( t_end ) , m_state( &s ) , m_step( 0 ) 162 { 163 if( detail::less_eq_with_sign( this->m_t , this->m_t_end , this->m_dt ) ) 164 { 165 unwrapped_stepper_type &st = this->m_stepper; 166 st.initialize( * ( this->m_state ) , this->m_t , this->m_dt ); 167 } else { 168 this->m_at_end = true; 169 } 170 } 171 172 /** 173 * \brief Constructs a const_step_iterator. This constructor should be used to construct the end iterator. 174 * 175 * \param stepper The stepper to use during the iteration. 176 * \param sys The system function (ODE) to solve. 177 * \param s The initial state. const_step_iterator stores a reference of s and changes its value during the iteration. 178 */ const_step_iterator_impl(stepper_type stepper,system_type sys,state_type & s)179 const_step_iterator_impl( stepper_type stepper , system_type sys , state_type &s ) 180 : base_type( stepper , sys ) , m_state( &s ) 181 { 182 } 183 184 185 186 protected: 187 188 friend class boost::iterator_core_access; 189 increment(void)190 void increment( void ) 191 { 192 if( detail::less_eq_with_sign( static_cast<time_type>(this->m_t+this->m_dt) , 193 this->m_t_end , this->m_dt ) ) 194 { 195 unwrapped_stepper_type &stepper = this->m_stepper; 196 // use integer to compute current time to reduce roundoff errors 197 this->m_step++; 198 this->m_t = this->m_t_start + static_cast< typename unit_value_type<time_type>::type >(this->m_step)*this->m_dt; 199 while( detail::less_with_sign( stepper.current_time() , this->m_t , 200 stepper.current_time_step() ) ) 201 { 202 stepper.do_step( this->m_system ); 203 } 204 stepper.calc_state( this->m_t , *( this->m_state ) ); 205 } else { 206 this->m_at_end = true; 207 } 208 } 209 210 public: get_state() const211 const state_type& get_state() const 212 { 213 return *m_state; 214 } 215 216 private: 217 time_type m_t_start; 218 time_type m_t_end; 219 state_type* m_state; 220 size_t m_step; 221 }; 222 223 } // namespace odeint 224 } // namespace numeric 225 } // namespace boost 226 227 228 #endif // BOOST_NUMERIC_ODEINT_ITERATOR_DETAIL_CONST_STEP_ITERATOR_IMPL_HPP_DEFINED 229