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/n_step_iterator_impl.hpp
0004 
0005   [begin_description]
0006   tba.
0007   [end_description]
0008 
0009   Copyright 2009-2013 Karsten Ahnert
0010   Copyright 2009-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_N_STEP_ITERATOR_IMPL_HPP_DEFINED
0019 #define BOOST_NUMERIC_ODEINT_ITERATOR_DETAIL_N_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 n_step_iterator_impl;
0033 
0034 
0035     /*
0036      * Specilization for steppers and error steppers
0037      */
0038     /**
0039      * \brief ODE Iterator performing exactly n steps with constant step size. The value type of this iterator is the state type of the stepper.
0040      *
0041      * Implements an ODE iterator solving the ODE with constant step size. Uses steppers fulfilling the Stepper concept.
0042      * n_step_iterator is a model of single-pass iterator.
0043      *
0044      * 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.
0045      *
0046      * \tparam Stepper The stepper type which should be used during the iteration.
0047      * \tparam System The type of the system function (ODE) which should be solved.
0048      */
0049     template< class Iterator , class Stepper , class System , class State , typename Tag >
0050     class n_step_iterator_impl< Iterator , Stepper , System , State , Tag , stepper_tag >
0051         : public detail::ode_iterator_base< Iterator , Stepper , System , State , Tag >
0052     {
0053     private:
0054 
0055         typedef Stepper stepper_type;
0056         typedef System system_type;
0057         typedef typename boost::numeric::odeint::unwrap_reference< stepper_type >::type unwrapped_stepper_type;
0058         typedef State state_type;
0059         typedef typename traits::time_type< stepper_type >::type time_type;
0060         typedef typename traits::value_type< stepper_type >::type ode_value_type;
0061         #ifndef DOXYGEN_SKIP
0062         typedef detail::ode_iterator_base< Iterator , Stepper , System , State , Tag > base_type;
0063         #endif
0064 
0065     public:
0066    
0067         /**
0068          * \brief Constructs a n_step_iterator. This constructor should be used to construct the begin iterator.
0069          *
0070          * \param stepper The stepper to use during the iteration.
0071          * \param sys The system function (ODE) to solve.
0072          * \param s The initial state. const_step_iterator stores a reference of s and changes its value during the iteration.
0073          * \param t The initial time.
0074          * \param dt The initial time step.
0075          * \param num_of_steps the number of steps to be executed.
0076          */
0077         n_step_iterator_impl( stepper_type stepper , system_type sys , state_type &s ,
0078                               time_type t , time_type dt , size_t num_of_steps )
0079             : base_type( stepper , sys , t , dt ) , m_t_start( t ) , m_state( &s ) ,
0080               m_steps(num_of_steps) , m_step( 0 )
0081         { }
0082 
0083         /**
0084          * \brief Constructs a const_step_iterator. This constructor should be used to construct the end iterator.
0085          *
0086          * \param stepper The stepper to use during the iteration.
0087          * \param sys The system function (ODE) to solve.
0088          * \param s The initial state. const_step_iterator stores a reference of s and changes its value during the iteration.
0089          */
0090         n_step_iterator_impl( stepper_type stepper , system_type sys , state_type &s )
0091             : base_type( stepper , sys ) , m_state( &s ) { }
0092 
0093     protected:
0094 
0095         friend class boost::iterator_core_access;
0096 
0097         void increment()
0098         {
0099             if( this->m_step < this->m_steps )
0100             {
0101                 unwrapped_stepper_type &stepper = this->m_stepper;
0102                 stepper.do_step( this->m_system , *this->m_state , this->m_t , this->m_dt );
0103                 // use integer to compute current time to reduce roundoff errors
0104                 this->m_step++;
0105                 this->m_t = this->m_t_start + static_cast< typename unit_value_type<time_type>::type >(this->m_step)*this->m_dt;
0106             } else {
0107                 this->m_at_end = true;
0108 
0109             }
0110         }
0111 
0112     public:
0113         const state_type& get_state() const
0114         {
0115             return *m_state;
0116         }
0117 
0118 
0119     private:
0120         time_type m_t_start;
0121         time_type m_t_end;
0122         state_type* m_state;
0123         size_t m_steps;
0124         size_t m_step;
0125 
0126     };
0127 
0128 
0129 
0130 
0131     /*
0132      * Specilization for dense output stepper
0133      */
0134     /**
0135      * \brief ODE Iterator with step-size control and dense output.
0136      *
0137      * Implements an ODE iterator solving the ODE with constant steps. Uses dense-output steppers.
0138      * n_step_iterator is a model of single-pass iterator.
0139      *
0140      * 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.
0141      *
0142      * \tparam Stepper The stepper type which should be used during the iteration.
0143      * \tparam System The type of the system function (ODE) which should be solved.
0144      */
0145     template< class Iterator , class Stepper , class System , class State , typename Tag >
0146     class n_step_iterator_impl< Iterator , Stepper , System , State , Tag , dense_output_stepper_tag >
0147         : public detail::ode_iterator_base< Iterator , Stepper , System , State , Tag >
0148     {
0149     private:
0150 
0151         typedef Stepper stepper_type;
0152         typedef System system_type;
0153         typedef typename boost::numeric::odeint::unwrap_reference< stepper_type >::type unwrapped_stepper_type;
0154         typedef State state_type;
0155         typedef typename traits::time_type< stepper_type >::type time_type;
0156         typedef typename traits::value_type< stepper_type >::type ode_value_type;
0157         #ifndef DOXYGEN_SKIP
0158         typedef detail::ode_iterator_base< Iterator , Stepper , System , State , Tag > base_type;
0159         #endif
0160 
0161     public:
0162 
0163         /**
0164          * \brief Constructs a const_step_iterator. This constructor should be used to construct the begin iterator.
0165          *
0166          * \param stepper The stepper to use during the iteration.
0167          * \param sys The system function (ODE) to solve.
0168          * \param s The initial state. const_step_iterator stores a reference of s and changes its value during the iteration.
0169          * \param t The initial time.
0170          * \param dt The initial time step.
0171          * \param num_of_steps the number of steps to be executed.
0172          */
0173         n_step_iterator_impl( stepper_type stepper , system_type sys , state_type &s ,
0174                               time_type t , time_type dt , size_t num_of_steps )
0175             : base_type( stepper , sys , t , dt ) , m_t_start( t ) , m_state( &s ) ,
0176               m_steps( num_of_steps ) , m_step( 0 )
0177         {
0178             unwrapped_stepper_type &st = this->m_stepper;
0179             st.initialize( * ( this->m_state ) , this->m_t , this->m_dt );
0180         }
0181 
0182         /**
0183          * \brief Constructs a const_step_iterator. This constructor should be used to construct the end iterator.
0184          *
0185          * \param stepper The stepper to use during the iteration.
0186          * \param sys The system function (ODE) to solve.
0187          * \param s The initial state. const_step_iterator stores a reference of s and changes its value during the iteration.
0188          */
0189         n_step_iterator_impl( stepper_type stepper , system_type sys , state_type &s )
0190             : base_type( stepper , sys ) , m_state( &s )
0191         {
0192         }
0193 
0194 
0195 
0196     protected:
0197 
0198         friend class boost::iterator_core_access;
0199 
0200         void increment( void )
0201         {
0202             if( this->m_step < this->m_steps )
0203             {
0204                 unwrapped_stepper_type &stepper = this->m_stepper;
0205                 // use integer to compute current time to reduce roundoff errors
0206                 this->m_step++;
0207                 this->m_t = this->m_t_start + static_cast< typename unit_value_type<time_type>::type >(this->m_step)*this->m_dt;
0208                 while( detail::less_with_sign( stepper.current_time() , this->m_t ,
0209                        stepper.current_time_step() ) )
0210                 {
0211                     stepper.do_step( this->m_system );
0212                 }
0213                 stepper.calc_state( this->m_t , *( this->m_state ) );
0214             } else {
0215                 this->m_at_end = true;
0216             }
0217         }
0218 
0219     public:
0220         const state_type& get_state() const
0221         {
0222             return *m_state;
0223         }
0224 
0225 
0226     private:
0227         time_type m_t_start;
0228         time_type m_t_end;
0229         state_type* m_state;
0230         size_t m_steps;
0231         size_t m_step;
0232     };
0233 
0234 } // namespace odeint
0235 } // namespace numeric
0236 } // namespace boost
0237 
0238 
0239 #endif // BOOST_NUMERIC_ODEINT_ITERATOR_DETAIL_N_STEP_ITERATOR_IMPL_HPP_DEFINED