integrate_adaptive.hpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /*
  2. [auto_generated]
  3. boost/numeric/odeint/integrate/detail/integrate_adaptive.hpp
  4. [begin_description]
  5. Default Integrate adaptive implementation.
  6. [end_description]
  7. Copyright 2009-2011 Karsten Ahnert
  8. Copyright 2009-2011 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_DETAIL_INTEGRATE_ADAPTIVE_HPP_INCLUDED
  14. #define BOOST_NUMERIC_ODEINT_INTEGRATE_DETAIL_INTEGRATE_ADAPTIVE_HPP_INCLUDED
  15. #include <stdexcept>
  16. #include <boost/numeric/odeint/stepper/stepper_categories.hpp>
  17. #include <boost/numeric/odeint/stepper/controlled_step_result.hpp>
  18. #include <boost/numeric/odeint/iterator/integrate/detail/integrate_const.hpp>
  19. #include <boost/numeric/odeint/iterator/adaptive_time_iterator.hpp>
  20. #include <boost/numeric/odeint/iterator/integrate/detail/functors.hpp>
  21. #include <boost/numeric/odeint/util/bind.hpp>
  22. #include <boost/numeric/odeint/util/unwrap_reference.hpp>
  23. #include <boost/numeric/odeint/util/copy.hpp>
  24. #include <boost/numeric/odeint/util/detail/less_with_sign.hpp>
  25. namespace boost {
  26. namespace numeric {
  27. namespace odeint {
  28. namespace detail {
  29. // forward declaration
  30. template< class Stepper , class System , class State , class Time , class Observer>
  31. size_t integrate_const(
  32. Stepper stepper , System system , State &start_state ,
  33. Time start_time , Time end_time , Time dt ,
  34. Observer observer , stepper_tag );
  35. /*
  36. * integrate_adaptive for simple stepper is basically an integrate_const + some last step
  37. */
  38. template< class Stepper , class System , class State , class Time , class Observer >
  39. size_t integrate_adaptive(
  40. Stepper stepper , System system , State &start_state ,
  41. Time start_time , Time end_time , Time dt ,
  42. Observer observer , stepper_tag
  43. )
  44. {
  45. size_t steps = detail::integrate_const( stepper , system , start_state , start_time ,
  46. end_time , dt , observer , stepper_tag() );
  47. typename odeint::unwrap_reference< Observer >::type &obs = observer;
  48. typename odeint::unwrap_reference< Stepper >::type &st = stepper;
  49. Time end = start_time + dt*steps;
  50. if( less_with_sign( end , end_time , dt ) )
  51. { //make a last step to end exactly at end_time
  52. st.do_step( system , start_state , end , end_time - end );
  53. steps++;
  54. obs( start_state , end_time );
  55. }
  56. return steps;
  57. }
  58. /*
  59. * classical integrate adaptive
  60. */
  61. template< class Stepper , class System , class State , class Time , class Observer >
  62. size_t integrate_adaptive(
  63. Stepper stepper , System system , State &start_state ,
  64. Time &start_time , Time end_time , Time &dt ,
  65. Observer observer , controlled_stepper_tag
  66. )
  67. {
  68. size_t obs_calls = 0;
  69. boost::for_each( make_adaptive_time_range( stepper , system , start_state ,
  70. start_time , end_time , dt ) ,
  71. obs_caller< Observer >( obs_calls , observer ) );
  72. return obs_calls-1;
  73. }
  74. /*
  75. * integrate adaptive for dense output steppers
  76. *
  77. * step size control is used if the stepper supports it
  78. */
  79. template< class Stepper , class System , class State , class Time , class Observer >
  80. size_t integrate_adaptive(
  81. Stepper stepper , System system , State &start_state ,
  82. Time start_time , Time end_time , Time dt ,
  83. Observer observer , dense_output_stepper_tag )
  84. {
  85. size_t obs_calls = 0;
  86. boost::for_each( make_adaptive_time_range( stepper , system , start_state ,
  87. start_time , end_time , dt ) ,
  88. obs_caller< Observer >( obs_calls , observer ) );
  89. return obs_calls-1;
  90. }
  91. } // namespace detail
  92. } // namespace odeint
  93. } // namespace numeric
  94. } // namespace boost
  95. #endif // BOOST_NUMERIC_ODEINT_INTEGRATE_DETAIL_INTEGRATE_ADAPTIVE_HPP_INCLUDED