integrate_n_steps.hpp 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. /*
  2. [auto_generated]
  3. boost/numeric/odeint/integrate/integrate_n_steps.hpp
  4. [begin_description]
  5. Integration of n steps with constant time size. Adaptive and dense-output methods are fully supported.
  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_N_STEPS_HPP_INCLUDED
  14. #define BOOST_NUMERIC_ODEINT_INTEGRATE_INTEGRATE_N_STEPS_HPP_INCLUDED
  15. #include <boost/type_traits/is_same.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/detail/integrate_n_steps.hpp>
  19. #include <boost/numeric/odeint/integrate/check_adapter.hpp>
  20. namespace boost {
  21. namespace numeric {
  22. namespace odeint {
  23. /*
  24. * Integrates n steps
  25. *
  26. * the two overloads are needed in order to solve the forwarding problem
  27. */
  28. template< class Stepper , class System , class State , class Time , class Observer , class StepOverflowChecker >
  29. Time integrate_n_steps(
  30. Stepper stepper , System system , State &start_state ,
  31. Time start_time , Time dt , size_t num_of_steps ,
  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. return detail::integrate_n_steps(
  40. checked_stepper<stepper_type, checker_type>(stepper, checker),
  41. system , start_state ,
  42. start_time , dt , num_of_steps ,
  43. checked_observer<observer_type, checker_type>(observer, checker),
  44. stepper_category() );
  45. }
  46. /**
  47. * \brief Solves the forwarding problem, can be called with Boost.Range as start_state.
  48. */
  49. template< class Stepper , class System , class State , class Time , class Observer , class StepOverflowChecker >
  50. Time integrate_n_steps(
  51. Stepper stepper , System system , const State &start_state ,
  52. Time start_time , Time dt , size_t num_of_steps ,
  53. Observer observer , StepOverflowChecker checker )
  54. {
  55. typedef typename odeint::unwrap_reference< Stepper >::type stepper_type;
  56. typedef typename odeint::unwrap_reference< Observer >::type observer_type;
  57. typedef typename odeint::unwrap_reference< StepOverflowChecker >::type checker_type;
  58. typedef typename stepper_type::stepper_category stepper_category;
  59. return detail::integrate_n_steps(
  60. checked_stepper<stepper_type, checker_type>(stepper, checker),
  61. system , start_state ,
  62. start_time , dt , num_of_steps ,
  63. checked_observer<observer_type, checker_type>(observer, checker),
  64. stepper_category() );
  65. }
  66. /**
  67. * \brief The same function as above, but without checker.
  68. */
  69. template< class Stepper , class System , class State , class Time , class Observer >
  70. Time integrate_n_steps(
  71. Stepper stepper , System system , State &start_state ,
  72. Time start_time , Time dt , size_t num_of_steps , Observer observer )
  73. {
  74. typedef typename odeint::unwrap_reference<Stepper>::type::stepper_category stepper_category;
  75. return detail::integrate_n_steps(
  76. stepper , system , start_state ,
  77. start_time , dt , num_of_steps ,
  78. observer , stepper_category() );
  79. }
  80. /**
  81. * \brief Solves the forwarding problem, can be called with Boost.Range as start_state.
  82. */
  83. template< class Stepper , class System , class State , class Time , class Observer >
  84. Time integrate_n_steps(
  85. Stepper stepper , System system , const State &start_state ,
  86. Time start_time , Time dt , size_t num_of_steps , Observer observer )
  87. {
  88. typedef typename odeint::unwrap_reference<Stepper>::type::stepper_category stepper_category;
  89. return detail::integrate_n_steps(
  90. stepper , system , start_state ,
  91. start_time , dt , num_of_steps ,
  92. observer , stepper_category() );
  93. }
  94. /**
  95. * \brief The same function as above, but without observer calls.
  96. */
  97. template< class Stepper , class System , class State , class Time >
  98. Time integrate_n_steps(
  99. Stepper stepper , System system , State &start_state ,
  100. Time start_time , Time dt , size_t num_of_steps )
  101. {
  102. return integrate_n_steps(stepper, system, start_state, start_time,
  103. dt, num_of_steps, null_observer());
  104. }
  105. /**
  106. * \brief Solves the forwarding problem, can be called with Boost.Range as start_state.
  107. */
  108. template< class Stepper , class System , class State , class Time >
  109. Time integrate_n_steps(
  110. Stepper stepper , System system , const State &start_state ,
  111. Time start_time , Time dt , size_t num_of_steps )
  112. {
  113. return integrate_n_steps(stepper, system, start_state, start_time,
  114. dt, num_of_steps, null_observer());
  115. }
  116. /************* DOXYGEN *************/
  117. /**
  118. * \fn Time integrate_n_steps( Stepper stepper , System system , State &start_state , Time start_time , Time dt , size_t num_of_steps , Observer observer )
  119. * \brief Integrates the ODE with constant step size.
  120. *
  121. * This function is similar to integrate_const. The observer is called at
  122. * equidistant time intervals t0 + n*dt.
  123. * If the Stepper is a normal stepper without step size control, dt is also
  124. * used for the numerical scheme. If a ControlledStepper is provided, the
  125. * algorithm might reduce the step size to meet the error bounds, but it is
  126. * ensured that the observer is always called at equidistant time points
  127. * t0 + n*dt. If a DenseOutputStepper is used, the step size also may vary
  128. * and the dense output is used to call the observer at equidistant time
  129. * points. The final integration time is always t0 + num_of_steps*dt.
  130. * If a max_step_checker is provided as StepOverflowChecker, a
  131. * no_progress_errror is thrown if too many steps (default: 500) are
  132. * performed without progress, i.e. in between observer calls. If no
  133. * checker is provided, no such overflow check is performed.
  134. *
  135. * \param stepper The stepper to be used for numerical integration.
  136. * \param system Function/Functor defining the rhs of the ODE.
  137. * \param start_state The initial condition x0.
  138. * \param start_time The initial time t0.
  139. * \param dt The time step between observer calls, _not_ necessarily the
  140. * time step of the integration.
  141. * \param num_of_steps Number of steps to be performed
  142. * \param observer Function/Functor called at equidistant time intervals.
  143. * \param checker [optional] Functor to check for step count overflows, if no
  144. * checker is provided, no exception is thrown.
  145. * \return The number of steps performed.
  146. */
  147. } // namespace odeint
  148. } // namespace numeric
  149. } // namespace boost
  150. #endif // BOOST_NUMERIC_ODEINT_INTEGRATE_INTEGRATE_N_STEPS_HPP_INCLUDED