1 2 /* 3 [auto_generated] 4 boost/numeric/odeint/iterator/adaptive_iterator.hpp 5 6 [begin_description] 7 Iterator for iterating throught the solution of an ODE with adaptive step size. The dereferenced types containes also the time. 8 [end_description] 9 10 Copyright 2012-2013 Karsten Ahnert 11 Copyright 2012 Mario Mulansky 12 13 Distributed under the Boost Software License, Version 1.0. 14 (See accompanying file LICENSE_1_0.txt or 15 copy at http://www.boost.org/LICENSE_1_0.txt) 16 */ 17 18 19 #ifndef BOOST_NUMERIC_ODEINT_ITERATOR_ADAPTIVE_ITERATOR_HPP_INCLUDED 20 #define BOOST_NUMERIC_ODEINT_ITERATOR_ADAPTIVE_ITERATOR_HPP_INCLUDED 21 22 #include <boost/numeric/odeint/util/stepper_traits.hpp> 23 #include <boost/numeric/odeint/util/unit_helper.hpp> 24 #include <boost/numeric/odeint/stepper/stepper_categories.hpp> 25 #include <boost/numeric/odeint/stepper/controlled_step_result.hpp> 26 #include <boost/numeric/odeint/iterator/impl/adaptive_iterator_impl.hpp> 27 28 namespace boost { 29 namespace numeric { 30 namespace odeint { 31 32 /* use the adaptive_iterator_impl with the right tags */ 33 template< class Stepper , class System , class State 34 #ifndef DOXYGEN_SKIP 35 , class StepperTag = typename base_tag< typename traits::stepper_category< Stepper >::type >::type 36 #endif 37 > 38 class adaptive_iterator : public adaptive_iterator_impl< 39 adaptive_iterator< Stepper , System , State , StepperTag > , 40 Stepper , System , State , detail::ode_state_iterator_tag , StepperTag 41 > 42 { 43 typedef typename traits::time_type< Stepper >::type time_type; 44 typedef adaptive_iterator< Stepper , System , State , StepperTag > iterator_type; 45 46 public: adaptive_iterator(Stepper stepper,System sys,State & s,time_type t_start,time_type t_end,time_type dt)47 adaptive_iterator( Stepper stepper , System sys , State &s , time_type t_start , time_type t_end , time_type dt ) 48 : adaptive_iterator_impl< iterator_type , Stepper , System , State , detail::ode_state_iterator_tag , StepperTag >( stepper , sys , s , t_start , t_end , dt ) 49 {} 50 adaptive_iterator(Stepper stepper,System sys,State & s)51 adaptive_iterator( Stepper stepper , System sys , State &s ) 52 : adaptive_iterator_impl< iterator_type , Stepper , System , State , detail::ode_state_iterator_tag , StepperTag >( stepper , sys , s ) 53 {} 54 }; 55 56 57 58 59 template< class Stepper , class System , class State > make_adaptive_iterator_begin(Stepper stepper,System system,State & x,typename traits::time_type<Stepper>::type t_start,typename traits::time_type<Stepper>::type t_end,typename traits::time_type<Stepper>::type dt)60 adaptive_iterator< Stepper , System , State > make_adaptive_iterator_begin( 61 Stepper stepper , 62 System system , 63 State &x , 64 typename traits::time_type< Stepper >::type t_start , 65 typename traits::time_type< Stepper >::type t_end , 66 typename traits::time_type< Stepper >::type dt ) 67 { 68 return adaptive_iterator< Stepper , System , State >( stepper , system , x , t_start , t_end , dt ); 69 } 70 71 72 template< class Stepper , class System , class State > make_adaptive_iterator_end(Stepper stepper,System system,State & x)73 adaptive_iterator< Stepper , System , State > make_adaptive_iterator_end( 74 Stepper stepper , 75 System system , 76 State &x ) 77 { 78 return adaptive_iterator< Stepper , System , State >( stepper , system , x ); 79 } 80 81 82 template< class Stepper , class System , class State > 83 std::pair< adaptive_iterator< Stepper , System , State > , adaptive_iterator< Stepper , System , State > > make_adaptive_range(Stepper stepper,System system,State & x,typename traits::time_type<Stepper>::type t_start,typename traits::time_type<Stepper>::type t_end,typename traits::time_type<Stepper>::type dt)84 make_adaptive_range( 85 Stepper stepper , 86 System system , 87 State &x , 88 typename traits::time_type< Stepper >::type t_start , 89 typename traits::time_type< Stepper >::type t_end , 90 typename traits::time_type< Stepper >::type dt ) 91 { 92 return std::make_pair( 93 adaptive_iterator< Stepper , System , State >( stepper , system , x , t_start , t_end , dt ) , 94 adaptive_iterator< Stepper , System , State >( stepper , system , x ) 95 ); 96 } 97 98 /** 99 * \class adaptive_iterator 100 * 101 * \brief ODE Iterator with adaptive step size. The value type of this iterator is the state type of the stepper. 102 * 103 * Implements an iterator representing the solution of an ODE from t_start 104 * to t_end evaluated at steps with an adaptive step size dt. 105 * After each iteration the iterator dereferences to the state x at the next 106 * time t+dt where dt is controlled by the stepper. 107 * This iterator can be used with ControlledSteppers and 108 * DenseOutputSteppers and it always makes use of the all the given steppers 109 * capabilities. A for_each over such an iterator range behaves similar to 110 * the integrate_adaptive routine. 111 * 112 * adaptive_iterator is a model of single-pass iterator. 113 * 114 * 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. 115 * 116 * \tparam Stepper The stepper type which should be used during the iteration. 117 * \tparam System The type of the system function (ODE) which should be solved. 118 * \tparam State The state type of the ODE. 119 */ 120 121 122 123 124 125 126 /** 127 * \fn make_adaptive_iterator_begin( Stepper stepper , System system , State &x , 128 typename traits::time_type< Stepper >::type t_start , 129 typename traits::time_type< Stepper >::type t_end , 130 typename traits::time_type< Stepper >::type dt ) 131 * 132 * \brief Factory function for adaptive_iterator. Constructs a begin iterator. 133 * 134 * \param stepper The stepper to use during the iteration. 135 * \param system The system function (ODE) to solve. 136 * \param x The initial state. 137 * \param t_start The initial time. 138 * \param t_end The end time, at which the iteration should stop. 139 * \param dt The initial time step. 140 * \returns The adaptive iterator. 141 */ 142 143 144 /** 145 * \fn make_adaptive_iterator_end( Stepper stepper , System system , State &x ) 146 * \brief Factory function for adaptive_iterator. Constructs a end iterator. 147 * 148 * \param stepper The stepper to use during the iteration. 149 * \param system The system function (ODE) to solve. 150 * \param x The initial state. 151 * \returns The adaptive iterator. 152 */ 153 154 155 /** 156 * \fn make_adaptive_range( Stepper stepper , System system , State &x , 157 typename traits::time_type< Stepper >::type t_start , 158 typename traits::time_type< Stepper >::type t_end , 159 typename traits::time_type< Stepper >::type dt ) 160 * 161 * \brief Factory function to construct a single pass range of adaptive iterators. A range is here a pair of adaptive_iterator. 162 * 163 * \param stepper The stepper to use during the iteration. 164 * \param system The system function (ODE) to solve. 165 * \param x The initial state. 166 * \param t_start The initial time. 167 * \param t_end The end time, at which the iteration should stop. 168 * \param dt The initial time step. 169 * \returns The adaptive range. 170 */ 171 172 173 174 175 176 177 } // namespace odeint 178 } // namespace numeric 179 } // namespace boost 180 181 182 183 #endif // BOOST_NUMERIC_ODEINT_ITERATOR_ADAPTIVE_ITERATOR_HPP_INCLUDED 184