1 [/============================================================================
4 Copyright 2012-2013 Karsten Ahnert
5 Copyright 2012-2013 Mario Mulansky
6 Copyright 2012 Sylwester Arabas
8 Use, modification and distribution is subject to the Boost Software License,
9 Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
10 http://www.boost.org/LICENSE_1_0.txt)
11 =============================================================================/]
14 [section Iterators and Ranges]
18 odeint supports iterators that iterate along an approximate solution of an ordinary differential equation. Iterators offer you an alternative to the integrate functions. Furthermore, many of the standard algorithms in the C++ standard library and Boost.Range can be used with the odeint's iterators.
20 [import ../examples/const_step_iterator.cpp]
22 Several iterator types are provided, in consistence with the
23 __integrate_functions. Hence there are `const_step_iterator`,
24 `adaptive_step_iterator`, `n_step_iterator` and `times_iterator` -- each of
25 them in two versions: either with only the `state` or with a
26 `std::pair<state,time>` as value type. They are all single pass iterators. In
27 the following, we show a few examples of how to use those iterators together
30 [const_step_iterator_accumulate]
32 In this example all x-values of the solution are accumulated. Note, how
33 dereferencing the iterator gives the current state `x` of the ODE (the second
34 argument of the accumulate lambda). The iterator
35 itself does not occur directly in this example but it is generated by the
36 factory functions `make_const_step_iterator_begin` and
37 `make_const_step_iterator_end`. odeint also supports Boost.Range, that allows
38 to write the above example in a more compact form with the factory function
39 `make_const_step_range`, but now using `boost::accumulate` from __bost_range:
41 [const_step_iterator_accumulate_range]
43 The second iterator type is also a iterator with const step size. But the value type of this iterator consists here of a pair of the time and the state of the solution of the ODE. An example is
45 [const_step_time_iterator_accumulate_range]
47 The factory functions are now `make_const_step_time_iterator_begin`,
48 `make_const_step_time_iterator_end` and `make_const_step_time_range`.
49 Note, how the lambda now expects a `std::pair` as this is the value type of
50 the `const_step_time_iterator`'s.
53 [import ../examples/adaptive_iterator.cpp]
55 Next, we discuss the adaptive iterators which are completely
56 analogous to the const step iterators, but are based on adaptive stepper
57 routines and thus adjust the step size during the iteration. Examples are
59 [adaptive_iterator_accumulate_range]
61 [adaptive_time_iterator_accumulate_range]
63 [note 'adaptive_iterator` and `adaptive_time_iterator' can only be used with
64 __controlled_stepper or __dense_output_stepper.]
66 In general one can say that iterating over a range of a `const_step_iterator`
67 behaves like an `integrate_const` function call, and similarly for
68 `adaptive_iterator` and `integrate_adaptive`, `n_step_iterator` and
69 `integrate_n_steps`, and finally `times_iterator` and `integrate_times`.
71 Below we list the most important properties of the exisiting iterators:
75 [section const_step_iterator]
77 * Definition: `const_step_iterator< Stepper , System , State >`
78 * `value_type` is `State`
79 * `reference_type` is `State const&`
81 * `make_const_step_iterator_begin( stepper , system , state , t_start , t_end , dt )`
82 * `make_const_step_iterator_end( stepper , system , state )`
83 * `make_const_step_range( stepper , system , state , t_start , t_end , dt )`
84 * This stepper works with all steppers fulfilling the Stepper concept or the DenseOutputStepper concept.
85 * The value of `state` is the current state of the ODE during the iteration.
89 [section const_step_time_iterator]
91 * Definition: `const_step_time_iterator< Stepper , System , State >`
92 * `value_type` is `std::pair< State , Stepper::time_type >`
93 * `reference_type` is `std::pair< State const& , Stepper::time_type > const&`
95 * `make_const_step_time_iterator_begin( stepper , system , state , t_start , t_end , dt )`
96 * `make_const_step_time_iterator_end( stepper , system , state )`
97 * `make_const_step_time_range( stepper , system , state , t_start , t_end , dt )`
98 * This stepper works with all steppers fulfilling the Stepper concept or the DenseOutputStepper concept.
99 * This stepper updates the value of `state`. The value of `state` is the current state of the ODE during the iteration.
105 [section adaptive_step_iterator]
107 * Definition: `adaptive_iterator< Stepper , System , State >`
108 * `value_type` is `State`
109 * `reference_type` is `State const&`
111 * `make_adaptive_iterator_begin( stepper , system , state , t_start , t_end , dt )`
112 * `make_adaptive_iterator_end( stepper , system , state )`
113 * `make_adaptive_range( stepper , system , state , t_start , t_end , dt )`
114 * This stepper works with all steppers fulfilling the ControlledStepper concept or the DenseOutputStepper concept.
115 * For steppers fulfilling the ControlledStepper concept `state` is modified according to the current state of the ODE. For DenseOutputStepper the state is not modified due to performance optimizations, but the steppers itself.
120 [section adaptive_step_time_iterator]
122 * Definition: `adaptive_iterator< Stepper , System , State >`
123 * `value_type` is `std::pair< State , Stepper::time_type >`
124 * `reference_type` is `std::pair< State const& , Stepper::time_type > const&`
126 * `make_adaptive_time_iterator_begin( stepper , system , state , t_start , t_end , dt )`
127 * `make_adaptive_time_iterator_end( stepper , system , state )`
128 * `make_adaptive_time_range( stepper , system , state , t_start , t_end , dt )`
129 * This stepper works with all steppers fulfilling the ControlledStepper concept or the DenseOutputStepper concept.
130 * For steppers fulfilling the ControlledStepper concept `state` is modified according to the current state of the ODE. For DenseOutputStepper the state is not modified due to performance optimizations, but the stepper itself.
136 [section n_step_iterator]
138 * Definition: `n_step_iterator< Stepper , System , State >`
139 * `value_type` is `State`
140 * `reference_type` is `State const&`
142 * `make_n_step_iterator_begin( stepper , system , state , t_start , dt , num_of_steps )`
143 * `make_n_step_iterator_end( stepper , system , state )`
144 * `make_n_step_range( stepper , system , state , t_start , dt , num_of_steps )`
145 * This stepper works with all steppers fulfilling the Stepper concept or the DenseOutputStepper concept.
146 * The value of `state` is the current state of the ODE during the iteration.
150 [section n_step_time_iterator]
152 * Definition: `n_step_time_iterator< Stepper , System , State >`
153 * `value_type` is `std::pair< State , Stepper::time_type >`
154 * `reference_type` is `std::pair< State const& , Stepper::time_type > const&`
156 * `make_n_step_time_iterator_begin( stepper , system , state , t_start , dt , num_of_steps )`
157 * `make_n_step_time_iterator_end( stepper , system , state )`
158 * `make_n_step_time_range( stepper , system , state , t_start , dt , num_of_steps )`
159 * This stepper works with all steppers fulfilling the Stepper concept or the DenseOutputStepper concept.
160 * This stepper updates the value of `state`. The value of `state` is the current state of the ODE during the iteration.
166 [section times_iterator]
168 * Definition: `times_iterator< Stepper , System , State , TimeIterator >`
169 * `value_type` is `State`
170 * `reference_type` is `State const&`
172 * `make_times_iterator_begin( stepper , system , state , t_start , t_end , dt )`
173 * `make_times_iterator_end( stepper , system , state )`
174 * `make_times_range( stepper , system , state , t_start , t_end , dt )`
175 * This stepper works with all steppers fulfilling the Stepper concept, the ControlledStepper concept or the DenseOutputStepper concept.
176 * The value of `state` is the current state of the ODE during the iteration.
180 [section times_time_iterator]
182 * Definition: `times_time_iterator< Stepper , System , State , TimeIterator>`
183 * `value_type` is `std::pair< State , Stepper::time_type >`
184 * `reference_type` is `std::pair< State const& , Stepper::time_type > const&`
186 * `make_times_time_iterator_begin( stepper , system , state , t_start , t_end , dt )`
187 * `make_times_time_step_iterator_end( stepper , system , state )`
188 * `make_times_time_range( stepper , system , state , t_start , t_end , dt )`
189 * This stepper works with all steppers fulfilling the Stepper concept, the ControlledStepper concept or the DenseOutputStepper concept.
190 * This stepper updates the value of `state`. The value of `state` is the current state of the ODE during the iteration.