integrate_times.hpp 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. /*
  2. [auto_generated]
  3. boost/numeric/odeint/integrate/integrate_times.hpp
  4. [begin_description]
  5. Integration of ODEs with observation at user defined points
  6. [end_description]
  7. Copyright 2011-2013 Karsten Ahnert
  8. Copyright 2011-2015 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_INTEGRATE_INTEGRATE_TIMES_HPP_INCLUDED
  14. #define BOOST_NUMERIC_ODEINT_INTEGRATE_INTEGRATE_TIMES_HPP_INCLUDED
  15. #include <boost/range.hpp>
  16. #include <boost/numeric/odeint/stepper/stepper_categories.hpp>
  17. #include <boost/numeric/odeint/integrate/null_observer.hpp>
  18. #include <boost/numeric/odeint/integrate/check_adapter.hpp>
  19. #include <boost/numeric/odeint/integrate/detail/integrate_times.hpp>
  20. namespace boost {
  21. namespace numeric {
  22. namespace odeint {
  23. /*
  24. * \brief Integrates while calling the observer at the time points given by sequence [times_start, time_end)
  25. * the two overloads are needed in order to solve the forwarding problem
  26. */
  27. template< class Stepper , class System , class State , class TimeIterator , class Time , class Observer , class StepOverflowChecker >
  28. size_t integrate_times(
  29. Stepper stepper , System system , State &start_state ,
  30. TimeIterator times_start , TimeIterator times_end , Time dt ,
  31. Observer observer , StepOverflowChecker checker )
  32. {
  33. // unwrap references
  34. typedef typename odeint::unwrap_reference< Stepper >::type stepper_type;
  35. typedef typename odeint::unwrap_reference< Observer >::type observer_type;
  36. typedef typename odeint::unwrap_reference< StepOverflowChecker >::type checker_type;
  37. typedef typename stepper_type::stepper_category stepper_category;
  38. // pass on checked stepper and observer
  39. // checked_stepper/observer use references internally, so passing by value is fine
  40. return detail::integrate_times(
  41. checked_stepper<stepper_type, checker_type>(stepper, checker) ,
  42. system , start_state ,
  43. times_start , times_end , dt ,
  44. checked_observer<observer_type, checker_type>(observer, checker),
  45. stepper_category() );
  46. }
  47. /**
  48. * \brief Solves the forwarding problem, can be called with Boost.Range as start_state.
  49. */
  50. template< class Stepper , class System , class State , class TimeIterator , class Time , class Observer , class StepOverflowChecker >
  51. size_t integrate_times(
  52. Stepper stepper , System system , const State &start_state ,
  53. TimeIterator times_start , TimeIterator times_end , Time dt ,
  54. Observer observer , StepOverflowChecker checker )
  55. {
  56. typedef typename odeint::unwrap_reference< Stepper >::type stepper_type;
  57. typedef typename odeint::unwrap_reference< Observer >::type observer_type;
  58. typedef typename odeint::unwrap_reference< StepOverflowChecker >::type checker_type;
  59. typedef typename stepper_type::stepper_category stepper_category;
  60. stepper_type &st = stepper;
  61. observer_type &obs = observer;
  62. checker_type &chk = checker;
  63. return detail::integrate_times(
  64. checked_stepper<stepper_type, checker_type>(stepper, checker) ,
  65. system , start_state ,
  66. times_start , times_end , dt ,
  67. checked_observer<observer_type, checker_type>(observer, checker),
  68. stepper_category() );
  69. }
  70. /**
  71. * \brief The same function as above, but with the observation times given as range.
  72. */
  73. template< class Stepper , class System , class State , class TimeRange , class Time , class Observer , class StepOverflowChecker >
  74. size_t integrate_times(
  75. Stepper stepper , System system , State &start_state ,
  76. const TimeRange &times , Time dt ,
  77. Observer observer , StepOverflowChecker checker )
  78. {
  79. return integrate_times(
  80. stepper , system , start_state ,
  81. boost::begin( times ) , boost::end( times ) , dt , observer , checker );
  82. }
  83. /**
  84. * \brief Solves the forwarding problem, can be called with Boost.Range as start_state.
  85. */
  86. template< class Stepper , class System , class State , class TimeRange , class Time , class Observer , class StepOverflowChecker >
  87. size_t integrate_times(
  88. Stepper stepper , System system , const State &start_state ,
  89. const TimeRange &times , Time dt ,
  90. Observer observer , StepOverflowChecker checker )
  91. {
  92. return integrate_times(
  93. stepper , system , start_state ,
  94. boost::begin( times ) , boost::end( times ) , dt , observer , checker );
  95. }
  96. /*
  97. * The same functions as above, but without a StepOverflowChecker
  98. */
  99. template< class Stepper , class System , class State , class TimeIterator , class Time , class Observer >
  100. size_t integrate_times(
  101. Stepper stepper , System system , State &start_state ,
  102. TimeIterator times_start , TimeIterator times_end , Time dt ,
  103. Observer observer )
  104. {
  105. typedef typename odeint::unwrap_reference< Stepper >::type::stepper_category stepper_category;
  106. // simply don't use checked_* adapters
  107. return detail::integrate_times(
  108. stepper , system , start_state ,
  109. times_start , times_end , dt ,
  110. observer , stepper_category() );
  111. }
  112. /**
  113. * \brief Solves the forwarding problem, can be called with Boost.Range as start_state.
  114. */
  115. template< class Stepper , class System , class State , class TimeIterator , class Time , class Observer >
  116. size_t integrate_times(
  117. Stepper stepper , System system , const State &start_state ,
  118. TimeIterator times_start , TimeIterator times_end , Time dt ,
  119. Observer observer )
  120. {
  121. typedef typename odeint::unwrap_reference< Stepper >::type::stepper_category stepper_category;
  122. return detail::integrate_times(
  123. stepper , system , start_state ,
  124. times_start , times_end , dt ,
  125. observer , stepper_category() );
  126. }
  127. /**
  128. * \brief The same function as above, but with the observation times given as range.
  129. */
  130. template< class Stepper , class System , class State , class TimeRange , class Time , class Observer >
  131. size_t integrate_times(
  132. Stepper stepper , System system , State &start_state ,
  133. const TimeRange &times , Time dt ,
  134. Observer observer )
  135. {
  136. return integrate_times(
  137. stepper , system , start_state ,
  138. boost::begin( times ) , boost::end( times ) , dt , observer );
  139. }
  140. /**
  141. * \brief Solves the forwarding problem, can be called with Boost.Range as start_state.
  142. */
  143. template< class Stepper , class System , class State , class TimeRange , class Time , class Observer >
  144. size_t integrate_times(
  145. Stepper stepper , System system , const State &start_state ,
  146. const TimeRange &times , Time dt ,
  147. Observer observer )
  148. {
  149. return integrate_times(
  150. stepper , system , start_state ,
  151. boost::begin( times ) , boost::end( times ) , dt , observer);
  152. }
  153. /********* DOXYGEN ***********/
  154. /**
  155. * \fn size_t integrate_times( Stepper stepper , System system , State &start_state , TimeIterator times_start , TimeIterator times_end , Time dt , Observer observer )
  156. * \brief Integrates the ODE with observer calls at given time points.
  157. *
  158. * Integrates the ODE given by system using the given stepper. This function
  159. * does observer calls at the subsequent time points given by the range
  160. * times_start, times_end. If the stepper has not step size control, the
  161. * step size might be reduced occasionally to ensure observer calls exactly
  162. * at the time points from the given sequence. If the stepper is a
  163. * ControlledStepper, the step size is adjusted to meet the error bounds,
  164. * but also might be reduced occasionally to ensure correct observer calls.
  165. * If a DenseOutputStepper is provided, the dense output functionality is
  166. * used to call the observer at the given times. The end time of the
  167. * integration is always *(end_time-1).
  168. * If a max_step_checker is provided as StepOverflowChecker, a
  169. * no_progress_error is thrown if too many steps (default: 500) are
  170. * performed without progress, i.e. in between observer calls. If no
  171. * checker is provided, no such overflow check is performed.
  172. *
  173. * \param stepper The stepper to be used for numerical integration.
  174. * \param system Function/Functor defining the rhs of the ODE.
  175. * \param start_state The initial condition x0.
  176. * \param times_start Iterator to the start time
  177. * \param times_end Iterator to the end time
  178. * \param dt The time step between observer calls, _not_ necessarily the
  179. * time step of the integration.
  180. * \param observer Function/Functor called at equidistant time intervals.
  181. * \param checker [optional] Functor to check for step count overflows, if no
  182. * checker is provided, no exception is thrown.
  183. * \return The number of steps performed.
  184. */
  185. } // namespace odeint
  186. } // namespace numeric
  187. } // namespace boost
  188. #endif // BOOST_NUMERIC_ODEINT_INTEGRATE_INTEGRATE_TIMES_HPP_INCLUDED