4 boost/numeric/odeint/iterator/n_step_iterator.hpp
7 Iterator for iterating through the solution of an ODE with constant step size performing exactly n steps.
10 Copyright 2009-2013 Karsten Ahnert
11 Copyright 2009-2013 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_N_STEP_ITERATOR_HPP_INCLUDED
20 #define BOOST_NUMERIC_ODEINT_ITERATOR_N_STEP_ITERATOR_HPP_INCLUDED
23 #include <boost/numeric/odeint/util/stepper_traits.hpp>
24 #include <boost/numeric/odeint/stepper/stepper_categories.hpp>
25 #include <boost/numeric/odeint/iterator/detail/ode_iterator_base.hpp>
26 #include <boost/numeric/odeint/iterator/impl/n_step_iterator_impl.hpp>
34 /* use the n_step_iterator_impl with the right tags */
35 template< class Stepper , class System , class State
37 , class StepperTag = typename base_tag< typename traits::stepper_category< Stepper >::type >::type
40 class n_step_iterator : public n_step_iterator_impl<
41 n_step_iterator< Stepper , System , State , StepperTag > ,
42 Stepper , System , State , detail::ode_state_iterator_tag , StepperTag
45 typedef typename traits::time_type< Stepper >::type time_type;
46 typedef n_step_iterator< Stepper , System , State , StepperTag > iterator_type;
49 n_step_iterator( Stepper stepper , System sys , State &s , time_type t , time_type dt , size_t num_of_steps )
50 : n_step_iterator_impl< iterator_type , Stepper , System , State , detail::ode_state_iterator_tag , StepperTag >( stepper , sys , s , t , dt , num_of_steps )
53 n_step_iterator( Stepper stepper , System sys , State &s )
54 : n_step_iterator_impl< iterator_type , Stepper , System , State , detail::ode_state_iterator_tag , StepperTag >( stepper , sys , s )
60 template< class Stepper , class System , class State >
61 n_step_iterator< Stepper , System, State > make_n_step_iterator_begin(
65 typename traits::time_type< Stepper >::type t ,
66 typename traits::time_type< Stepper >::type dt ,
69 return n_step_iterator< Stepper , System , State >( stepper , system , x , t , dt , num_of_steps );
72 template< class Stepper , class System , class State >
73 n_step_iterator< Stepper , System , State > make_n_step_iterator_end(
78 return n_step_iterator< Stepper , System , State >( stepper , system , x );
81 template< class Stepper , class System , class State >
82 std::pair< n_step_iterator< Stepper , System , State > , n_step_iterator< Stepper , System , State > >
87 typename traits::time_type< Stepper >::type t ,
88 typename traits::time_type< Stepper >::type dt ,
91 return std::make_pair(
92 n_step_iterator< Stepper , System , State >( stepper , system , x , t , dt , num_of_steps ) ,
93 n_step_iterator< Stepper , System , State >( stepper , system , x )
99 * \class n_step_iterator
101 * \brief ODE Iterator with constant 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 starting from t
104 * with n steps and a constant step size dt.
105 * After each iteration the iterator dereferences to the state x at the next
107 * This iterator can be used with Steppers 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_n_steps routine.
112 * n_step_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.
123 * \fn make_n_step_iterator_begin( Stepper stepper , System system , State &x , typename traits::time_type< Stepper >::type t , typename traits::time_type< Stepper >::type dt , size_t num_of_steps )
125 * \brief Factory function for n_step_iterator. Constructs a begin iterator.
127 * \param stepper The stepper to use during the iteration.
128 * \param system The system function (ODE) to solve.
129 * \param x The initial state. const_step_iterator stores a reference of s and changes its value during the iteration.
130 * \param t The initial time.
131 * \param dt The initial time step.
132 * \param num_of_steps The number of steps to be executed.
133 * \returns The n-step iterator.
138 * \fn make_n_step_iterator_end( Stepper stepper , System system , State &x )
139 * \brief Factory function for n_step_iterator. Constructs an end iterator.
141 * \param stepper The stepper to use during the iteration.
142 * \param system The system function (ODE) to solve.
143 * \param x The initial state. const_step_iterator stores a reference of s and changes its value during the iteration.
144 * \returns The const_step_iterator.
149 * \fn make_n_step_range( Stepper stepper , System system , State &x , typename traits::time_type< Stepper >::type t , typename traits::time_type< Stepper >::type dt , , size_t num_of_steps )
151 * \brief Factory function to construct a single pass range of n-step iterators. A range is here a pair
152 * of n_step_iterator.
154 * \param stepper The stepper to use during the iteration.
155 * \param system The system function (ODE) to solve.
156 * \param x The initial state. const_step_iterator store a reference of s and changes its value during the iteration.
157 * \param t The initial time.
158 * \param dt The initial time step.
159 * \param num_of_steps The number of steps to be executed.
160 * \returns The n-step range.
164 } // namespace odeint
165 } // namespace numeric
168 #endif // BOOST_NUMERIC_ODEINT_ITERATOR_CONST_N_STEP_ITERATOR_HPP_INCLUDED