integrate_const.hpp 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. /*
  2. [auto_generated]
  3. boost/numeric/odeint/integrate/integrate_const.hpp
  4. [begin_description]
  5. Constant integration of ODEs, meaning that the state of the ODE is observed on constant time intervals.
  6. The routines makes full use of adaptive and dense-output methods.
  7. [end_description]
  8. Copyright 2011-2013 Karsten Ahnert
  9. Copyright 2011-2015 Mario Mulansky
  10. Distributed under the Boost Software License, Version 1.0.
  11. (See accompanying file LICENSE_1_0.txt or
  12. copy at http://www.boost.org/LICENSE_1_0.txt)
  13. */
  14. #ifndef BOOST_NUMERIC_ODEINT_INTEGRATE_INTEGRATE_CONST_HPP_INCLUDED
  15. #define BOOST_NUMERIC_ODEINT_INTEGRATE_INTEGRATE_CONST_HPP_INCLUDED
  16. #include <boost/type_traits/is_same.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_const.hpp>
  21. #include <boost/numeric/odeint/integrate/detail/integrate_adaptive.hpp>
  22. namespace boost {
  23. namespace numeric {
  24. namespace odeint {
  25. /*
  26. * Integrates with constant time step dt.
  27. */
  28. template<class Stepper, class System, class State, class Time, class Observer, class StepOverflowChecker>
  29. size_t integrate_const(
  30. Stepper stepper, System system, State &start_state,
  31. Time start_time, Time end_time, Time dt,
  32. Observer observer, StepOverflowChecker checker
  33. ) {
  34. typedef typename odeint::unwrap_reference<Stepper>::type::stepper_category stepper_category;
  35. // we want to get as fast as possible to the end
  36. // no overflow checks needed
  37. if (boost::is_same<null_observer, Observer>::value) {
  38. return detail::integrate_adaptive(
  39. stepper, system, start_state,
  40. start_time, end_time, dt,
  41. observer, stepper_category());
  42. }
  43. else {
  44. // unwrap references
  45. typedef typename odeint::unwrap_reference< Stepper >::type stepper_type;
  46. typedef typename odeint::unwrap_reference< Observer >::type observer_type;
  47. typedef typename odeint::unwrap_reference< StepOverflowChecker >::type checker_type;
  48. return detail::integrate_const(checked_stepper<stepper_type, checker_type>(stepper, checker),
  49. system, start_state,
  50. start_time, end_time, dt,
  51. checked_observer<observer_type, checker_type>(observer, checker),
  52. stepper_category());
  53. }
  54. }
  55. /**
  56. * \brief Second version to solve the forwarding problem,
  57. * can be called with Boost.Range as start_state.
  58. */
  59. template<class Stepper, class System, class State, class Time, class Observer, class StepOverflowChecker >
  60. size_t integrate_const(
  61. Stepper stepper, System system, const State &start_state,
  62. Time start_time, Time end_time, Time dt,
  63. Observer observer, StepOverflowChecker checker
  64. ) {
  65. typedef typename odeint::unwrap_reference<Stepper>::type::stepper_category stepper_category;
  66. // we want to get as fast as possible to the end
  67. if (boost::is_same<null_observer, Observer>::value) {
  68. return detail::integrate_adaptive(
  69. stepper, system, start_state,
  70. start_time, end_time, dt,
  71. observer, stepper_category());
  72. }
  73. else {
  74. typedef typename odeint::unwrap_reference< Stepper >::type stepper_type;
  75. typedef typename odeint::unwrap_reference< Observer >::type observer_type;
  76. typedef typename odeint::unwrap_reference< StepOverflowChecker >::type checker_type;
  77. return detail::integrate_const(checked_stepper<stepper_type, checker_type>(stepper, checker),
  78. system, start_state,
  79. start_time, end_time, dt,
  80. checked_observer<observer_type, checker_type>(observer, checker),
  81. stepper_category());
  82. }
  83. }
  84. /**
  85. * \brief integrate_const without step overflow checker
  86. */
  87. template<class Stepper, class System, class State, class Time, class Observer>
  88. size_t integrate_const(
  89. Stepper stepper, System system, State &start_state,
  90. Time start_time, Time end_time, Time dt, Observer observer)
  91. {
  92. typedef typename odeint::unwrap_reference<Stepper>::type::stepper_category stepper_category;
  93. return detail::integrate_const(stepper, system, start_state,
  94. start_time, end_time, dt, observer, stepper_category());
  95. }
  96. /**
  97. * \brief Second version to solve the forwarding problem,
  98. * can be called with Boost.Range as start_state.
  99. */
  100. template<class Stepper, class System, class State, class Time, class Observer>
  101. size_t integrate_const(
  102. Stepper stepper, System system, const State &start_state,
  103. Time start_time, Time end_time, Time dt, Observer observer
  104. ) {
  105. typedef typename odeint::unwrap_reference<Stepper>::type::stepper_category stepper_category;
  106. return detail::integrate_const(stepper, system, start_state,
  107. start_time, end_time, dt, observer, stepper_category());
  108. }
  109. /**
  110. * \brief integrate_const without observer calls
  111. */
  112. template<class Stepper, class System, class State, class Time>
  113. size_t integrate_const(
  114. Stepper stepper, System system, State &start_state,
  115. Time start_time, Time end_time, Time dt
  116. ) {
  117. return integrate_const(stepper, system, start_state, start_time, end_time, dt, null_observer());
  118. }
  119. /**
  120. * \brief Second version to solve the forwarding problem,
  121. * can be called with Boost.Range as start_state.
  122. */
  123. template<class Stepper, class System, class State, class Time>
  124. size_t integrate_const(
  125. Stepper stepper, System system, const State &start_state,
  126. Time start_time, Time end_time, Time dt
  127. ) {
  128. return integrate_const(stepper, system, start_state, start_time, end_time, dt, null_observer());
  129. }
  130. /********* DOXYGEN *********/
  131. /**
  132. * \fn integrate_const( Stepper stepper , System system , State &start_state , Time start_time ,
  133. * Time end_time , Time dt , Observer observer , StepOverflowChecker checker )
  134. * \brief Integrates the ODE with constant step size.
  135. *
  136. * Integrates the ODE defined by system using the given stepper.
  137. * This method ensures that the observer is called at constant intervals dt.
  138. * If the Stepper is a normal stepper without step size control, dt is also
  139. * used for the numerical scheme. If a ControlledStepper is provided, the
  140. * algorithm might reduce the step size to meet the error bounds, but it is
  141. * ensured that the observer is always called at equidistant time points
  142. * t0 + n*dt. If a DenseOutputStepper is used, the step size also may vary
  143. * and the dense output is used to call the observer at equidistant time
  144. * points.
  145. * If a max_step_checker is provided as StepOverflowChecker, a
  146. * no_progress_error is thrown if too many steps (default: 500) are performed
  147. * without progress, i.e. in between observer calls. If no checker is provided,
  148. * no such overflow check is performed.
  149. *
  150. * \param stepper The stepper to be used for numerical integration.
  151. * \param system Function/Functor defining the rhs of the ODE.
  152. * \param start_state The initial condition x0.
  153. * \param start_time The initial time t0.
  154. * \param end_time The final integration time tend.
  155. * \param dt The time step between observer calls, _not_ necessarily the
  156. * time step of the integration.
  157. * \param observer [optional] Function/Functor called at equidistant time intervals.
  158. * \param checker [optional] Functor to check for step count overflows, if no
  159. * checker is provided, no exception is thrown.
  160. * \return The number of steps performed.
  161. */
  162. } // namespace odeint
  163. } // namespace numeric
  164. } // namespace boost
  165. #endif // BOOST_NUMERIC_ODEINT_INTEGRATE_INTEGRATE_CONST_HPP_INCLUDED