times_iterator.hpp 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. /*
  2. [auto_generated]
  3. boost/numeric/odeint/iterator/times_iterator.hpp
  4. [begin_description]
  5. Iterator for iterating through the solution of an ODE with oscillator calls at times from a given sequence.
  6. [end_description]
  7. Copyright 2009-2013 Karsten Ahnert
  8. Copyright 2009-2013 Mario Mulansky
  9. Distributed under the Boost Software License, Version 1.0.
  10. (See accompanying file LICENSE_1_0.txt or
  11. copy at http://www.boost.org/LICENSE_1_0.txt)
  12. */
  13. #ifndef BOOST_NUMERIC_ODEINT_ITERATOR_TIMES_ITERATOR_HPP_INCLUDED
  14. #define BOOST_NUMERIC_ODEINT_ITERATOR_TIMES_ITERATOR_HPP_INCLUDED
  15. #include <boost/numeric/odeint/util/stepper_traits.hpp>
  16. #include <boost/numeric/odeint/stepper/stepper_categories.hpp>
  17. #include <boost/numeric/odeint/iterator/detail/ode_iterator_base.hpp>
  18. #include <boost/numeric/odeint/iterator/impl/times_iterator_impl.hpp>
  19. namespace boost {
  20. namespace numeric {
  21. namespace odeint {
  22. /* use the times_iterator_impl with the right tags */
  23. template< class Stepper , class System , class State , class TimeIterator
  24. #ifndef DOXYGEN_SKIP
  25. , class StepperTag = typename base_tag< typename traits::stepper_category< Stepper >::type >::type
  26. #endif
  27. >
  28. class times_iterator : public times_iterator_impl<
  29. times_iterator< Stepper , System , State , TimeIterator , StepperTag > ,
  30. Stepper , System , State , TimeIterator , detail::ode_state_iterator_tag , StepperTag
  31. >
  32. {
  33. typedef typename traits::time_type< Stepper >::type time_type;
  34. typedef times_iterator< Stepper , System , State , TimeIterator , StepperTag > iterator_type;
  35. public:
  36. times_iterator( Stepper stepper , System sys , State &s ,
  37. TimeIterator t_start , TimeIterator t_end , time_type dt )
  38. : times_iterator_impl< iterator_type , Stepper , System , State , TimeIterator, detail::ode_state_iterator_tag , StepperTag >( stepper , sys , s , t_start , t_end , dt )
  39. {}
  40. times_iterator( Stepper stepper , System sys , State &s )
  41. : times_iterator_impl< iterator_type , Stepper , System , State , TimeIterator , detail::ode_state_iterator_tag , StepperTag >( stepper , sys , s )
  42. {}
  43. };
  44. /* make functions */
  45. template< class Stepper , class System , class State , class TimeIterator >
  46. times_iterator< Stepper , System, State , TimeIterator > make_times_iterator_begin(
  47. Stepper stepper ,
  48. System system ,
  49. State &x ,
  50. TimeIterator t_start ,
  51. TimeIterator t_end ,
  52. typename traits::time_type< Stepper >::type dt )
  53. {
  54. return times_iterator< Stepper , System , State , TimeIterator >( stepper , system , x , t_start , t_end , dt );
  55. }
  56. // ToDo: requires to specifically provide the TimeIterator template parameter, can this be improved?
  57. template< class TimeIterator , class Stepper , class System , class State >
  58. times_iterator< Stepper , System , State , TimeIterator > make_times_iterator_end(
  59. Stepper stepper ,
  60. System system ,
  61. State &x )
  62. //TimeIterator t_end )
  63. {
  64. return times_iterator< Stepper , System , State , TimeIterator >( stepper , system , x );
  65. }
  66. template< class Stepper , class System , class State , class TimeIterator >
  67. std::pair< times_iterator< Stepper , System , State , TimeIterator > ,
  68. times_iterator< Stepper , System , State , TimeIterator > >
  69. make_times_range(
  70. Stepper stepper ,
  71. System system ,
  72. State &x ,
  73. TimeIterator t_start ,
  74. TimeIterator t_end ,
  75. typename traits::time_type< Stepper >::type dt )
  76. {
  77. return std::make_pair(
  78. times_iterator< Stepper , System , State , TimeIterator >( stepper , system , x , t_start , t_end , dt ) ,
  79. times_iterator< Stepper , System , State , TimeIterator >( stepper , system , x )
  80. );
  81. }
  82. /**
  83. * \class times_iterator
  84. *
  85. * \brief ODE Iterator with given evaluation points. The value type of this iterator is the state type of the stepper.
  86. *
  87. * Implements an iterator representing the solution of an ODE from *t_start
  88. * to *t_end evaluated at time points given by the sequence t_start to t_end.
  89. * t_start and t_end are iterators representing a sequence of time points
  90. * where the solution of the ODE should be evaluated.
  91. * After each iteration the iterator dereferences to the state x at the next
  92. * time *t_start++ until t_end is reached.
  93. * This iterator can be used with Steppers, ControlledSteppers and
  94. * DenseOutputSteppers and it always makes use of the all the given steppers
  95. * capabilities. A for_each over such an iterator range behaves similar to
  96. * the integrate_times routine.
  97. *
  98. * times_iterator is a model of single-pass iterator.
  99. *
  100. * 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.
  101. *
  102. * \tparam Stepper The stepper type which should be used during the iteration.
  103. * \tparam System The type of the system function (ODE) which should be solved.
  104. * \tparam State The state type of the ODE.
  105. * \tparam TimeIterator The iterator type for the sequence of time points.
  106. */
  107. /**
  108. * \fn make_times_iterator_begin( Stepper stepper ,
  109. System system ,
  110. State &x ,
  111. TimeIterator t_start ,
  112. TimeIterator t_end ,
  113. typename traits::time_type< Stepper >::type dt )
  114. *
  115. * \brief Factory function for times_iterator. Constructs a begin iterator.
  116. *
  117. * \param stepper The stepper to use during the iteration.
  118. * \param system The system function (ODE) to solve.
  119. * \param x The initial state. const_step_iterator stores a reference of s and changes its value during the iteration.
  120. * \param t_start Begin iterator of the sequence of evaluation time points.
  121. * \param t_end End iterator of the sequence of evaluation time points.
  122. * \param dt The initial time step.
  123. * \returns The times iterator.
  124. */
  125. /**
  126. * \fn make_times_iterator_end( Stepper stepper , System system , State &x )
  127. * \brief Factory function for times_iterator. Constructs an end iterator.
  128. *
  129. * \tparam TimesIterator The iterator type of the time sequence, must be specifically provided.
  130. *
  131. * \param stepper The stepper to use during the iteration.
  132. * \param system The system function (ODE) to solve.
  133. * \param x The initial state. const_step_iterator stores a reference of s and changes its value during the iteration.
  134. * \returns The times iterator.
  135. *
  136. * This function needs the TimeIterator type specifically defined as a
  137. * template parameter.
  138. */
  139. /**
  140. * \fn make_times_range( Stepper stepper , System system , State &x ,
  141. TimeIterator t_start ,
  142. TimeIterator t_end ,
  143. typename traits::time_type< Stepper >::type dt )
  144. *
  145. * \brief Factory function to construct a single pass range of times iterators. A range is here a pair
  146. * of times_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. const_step_iterator store a reference of s and changes its value during the iteration.
  151. * \param t_start Begin iterator of the sequence of evaluation time points.
  152. * \param t_end End iterator of the sequence of evaluation time points.
  153. * \param dt The initial time step.
  154. * \returns The times iterator range.
  155. */
  156. } // namespace odeint
  157. } // namespace numeric
  158. } // namespace boost
  159. #endif // BOOST_NUMERIC_ODEINT_ITERATOR_TIMES_ITERATOR_HPP_INCLUDED