Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:42:53

0001 /*
0002   [auto_generated]
0003   boost/numeric/odeint/iterator/detail/const_step_iterator_impl.hpp
0004 
0005   [begin_description]
0006   tba.
0007   [end_description]
0008 
0009   Copyright 2013 Karsten Ahnert
0010   Copyright 2013 Mario Mulansky
0011 
0012   Distributed under the Boost Software License, Version 1.0.
0013   (See accompanying file LICENSE_1_0.txt or
0014   copy at http://www.boost.org/LICENSE_1_0.txt)
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      * Specilization for steppers and error steppers
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          * \brief Constructs a const_step_iterator. This constructor should be used to construct the begin iterator.
0058          *
0059          * \param stepper The stepper to use during the iteration.
0060          * \param sys The system function (ODE) to solve.
0061          * \param s The initial state. const_step_iterator stores a reference of s and changes its value during the iteration.
0062          * \param t The initial time.
0063          * \param t_end The end time, at which the iteration should stop.
0064          * \param dt The initial time step.
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          * \brief Constructs a const_step_iterator. This constructor should be used to construct the end iterator.
0075          *
0076          * \param stepper The stepper to use during the iteration.
0077          * \param sys The system function (ODE) to solve.
0078          * \param s The initial state. const_step_iterator stores a reference of s and changes its value during the iteration.
0079          */
0080         const_step_iterator_impl( stepper_type stepper , system_type sys , state_type& /* s */ )
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                 // use integer to compute current time to reduce roundoff errors
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      * Specilization for dense output stepper
0120      */
0121     /**
0122      * \brief ODE Iterator with constant step size. The value type of this iterator is the state type of the stepper.
0123      *
0124      * Implements an ODE iterator solving the ODE with constant steps. Uses dense-output steppers.
0125      * const_step_iterator is a model of single-pass iterator.
0126      *
0127      * 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.
0128      *
0129      * \tparam Stepper The stepper type which should be used during the iteration.
0130      * \tparam System The type of the system function (ODE) which should be solved.
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          * \brief Constructs a const_step_iterator. This constructor should be used to construct the begin iterator.
0152          *
0153          * \param stepper The stepper to use during the iteration.
0154          * \param sys The system function (ODE) to solve.
0155          * \param s The initial state. const_step_iterator stores a reference of s and changes its value during the iteration.
0156          * \param t The initial time.
0157          * \param t_end The end time, at which the iteration should stop.
0158          * \param dt The initial time step.
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          * \brief Constructs a const_step_iterator. This constructor should be used to construct the end iterator.
0174          *
0175          * \param stepper The stepper to use during the iteration.
0176          * \param sys The system function (ODE) to solve.
0177          * \param s The initial state. const_step_iterator stores a reference of s and changes its value during the iteration.
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                 // use integer to compute current time to reduce roundoff errors
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 } // namespace odeint
0224 } // namespace numeric
0225 } // namespace boost
0226 
0227 
0228 #endif // BOOST_NUMERIC_ODEINT_ITERATOR_DETAIL_CONST_STEP_ITERATOR_IMPL_HPP_DEFINED