integrate_times.hpp 8.9 KB

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