integrate_const.hpp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /*
  2. [auto_generated]
  3. boost/numeric/odeint/integrate/detail/integrate_const.hpp
  4. [begin_description]
  5. integrate const implementation
  6. [end_description]
  7. Copyright 2009-2012 Karsten Ahnert
  8. Copyright 2009-2012 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_CONST_HPP_INCLUDED
  14. #define BOOST_NUMERIC_ODEINT_INTEGRATE_DETAIL_INTEGRATE_CONST_HPP_INCLUDED
  15. #include <boost/range/algorithm/for_each.hpp>
  16. #include <boost/numeric/odeint/util/unwrap_reference.hpp>
  17. #include <boost/numeric/odeint/stepper/stepper_categories.hpp>
  18. #include <boost/numeric/odeint/util/unit_helper.hpp>
  19. #include <boost/numeric/odeint/iterator/const_step_time_iterator.hpp>
  20. #include <boost/numeric/odeint/iterator/integrate/detail/integrate_adaptive.hpp>
  21. #include <boost/numeric/odeint/iterator/integrate/detail/functors.hpp>
  22. #include <boost/numeric/odeint/util/detail/less_with_sign.hpp>
  23. namespace boost {
  24. namespace numeric {
  25. namespace odeint {
  26. namespace detail {
  27. // forward declaration
  28. template< class Stepper , class System , class State , class Time , class Observer >
  29. size_t integrate_adaptive(
  30. Stepper stepper , System system , State &start_state ,
  31. Time &start_time , Time end_time , Time &dt ,
  32. Observer observer , controlled_stepper_tag
  33. );
  34. template< class Stepper , class System , class State , class Time , class Observer >
  35. size_t integrate_const(
  36. Stepper stepper , System system , State &start_state ,
  37. Time start_time , Time end_time , Time dt ,
  38. Observer observer , stepper_tag
  39. )
  40. {
  41. size_t obs_calls = 0;
  42. boost::for_each( make_const_step_time_range( stepper , system , start_state ,
  43. start_time , end_time , dt ) ,
  44. // should we use traits<Stepper>::state_type here instead of State? NO!
  45. obs_caller< Observer >( obs_calls , observer ) );
  46. // step integration steps gives step+1 observer calls
  47. return obs_calls-1;
  48. }
  49. template< class Stepper , class System , class State , class Time , class Observer >
  50. size_t integrate_const(
  51. Stepper stepper , System system , State &start_state ,
  52. Time start_time , Time end_time , Time dt ,
  53. Observer observer , controlled_stepper_tag
  54. )
  55. {
  56. typename odeint::unwrap_reference< Observer >::type &obs = observer;
  57. Time time = start_time;
  58. const Time time_step = dt;
  59. int step = 0;
  60. while( less_eq_with_sign( static_cast<Time>(time+time_step) , end_time , dt ) )
  61. {
  62. obs( start_state , time );
  63. detail::integrate_adaptive( stepper , system , start_state , time , time+time_step , dt ,
  64. null_observer() , controlled_stepper_tag() );
  65. // direct computation of the time avoids error propagation happening when using time += dt
  66. // we need clumsy type analysis to get boost units working here
  67. ++step;
  68. time = start_time + static_cast< typename unit_value_type<Time>::type >(step) * time_step;
  69. }
  70. obs( start_state , time );
  71. return step;
  72. }
  73. template< class Stepper , class System , class State , class Time , class Observer >
  74. size_t integrate_const(
  75. Stepper stepper , System system , State &start_state ,
  76. Time start_time , Time end_time , Time dt ,
  77. Observer observer , dense_output_stepper_tag
  78. )
  79. {
  80. size_t obs_calls = 0;
  81. boost::for_each( make_const_step_time_range( stepper , system , start_state ,
  82. start_time , end_time , dt ) ,
  83. obs_caller< Observer >( obs_calls , observer ) );
  84. return obs_calls-1;
  85. }
  86. } } } }
  87. #endif