4 boost/numeric/odeint/iterator/adaptive_iterator.hpp
7 Iterator for iterating throught the solution of an ODE with adaptive step size. The dereferenced types containes also the time.
10 Copyright 2012-2013 Karsten Ahnert
11 Copyright 2012 Mario Mulansky
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)
19 #ifndef BOOST_NUMERIC_ODEINT_ITERATOR_ADAPTIVE_ITERATOR_HPP_INCLUDED
20 #define BOOST_NUMERIC_ODEINT_ITERATOR_ADAPTIVE_ITERATOR_HPP_INCLUDED
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>
32 /* use the adaptive_iterator_impl with the right tags */
33 template< class Stepper , class System , class State
35 , class StepperTag = typename base_tag< typename traits::stepper_category< Stepper >::type >::type
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
43 typedef typename traits::time_type< Stepper >::type time_type;
44 typedef adaptive_iterator< Stepper , System , State , StepperTag > iterator_type;
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 )
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 )
59 template< class Stepper , class System , class State >
60 adaptive_iterator< Stepper , System , State > make_adaptive_iterator_begin(
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 )
68 return adaptive_iterator< Stepper , System , State >( stepper , system , x , t_start , t_end , dt );
72 template< class Stepper , class System , class State >
73 adaptive_iterator< Stepper , System , State > make_adaptive_iterator_end(
78 return adaptive_iterator< Stepper , System , State >( stepper , system , x );
82 template< class Stepper , class System , class State >
83 std::pair< adaptive_iterator< Stepper , System , State > , adaptive_iterator< Stepper , System , State > >
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 )
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 )
99 * \class adaptive_iterator
101 * \brief ODE Iterator with adaptive step size. The value type of this iterator is the state type of the stepper.
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.
112 * adaptive_iterator is a model of single-pass iterator.
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.
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.
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 )
132 * \brief Factory function for adaptive_iterator. Constructs a begin iterator.
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.
145 * \fn make_adaptive_iterator_end( Stepper stepper , System system , State &x )
146 * \brief Factory function for adaptive_iterator. Constructs a end iterator.
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.
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 )
161 * \brief Factory function to construct a single pass range of adaptive iterators. A range is here a pair of adaptive_iterator.
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.
177 } // namespace odeint
178 } // namespace numeric
183 #endif // BOOST_NUMERIC_ODEINT_ITERATOR_ADAPTIVE_ITERATOR_HPP_INCLUDED