adams_moulton.hpp 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. /*
  2. [auto_generated]
  3. boost/numeric/odeint/stepper/adams_moulton.hpp
  4. [begin_description]
  5. Implementation of the Adams-Moulton method. This is method is not a real stepper, it is more a helper class
  6. which computes the corrector step in the Adams-Bashforth-Moulton method.
  7. [end_description]
  8. Copyright 2011-2012 Karsten Ahnert
  9. Copyright 2011-2013 Mario Mulansky
  10. Copyright 2012 Christoph Koke
  11. Distributed under the Boost Software License, Version 1.0.
  12. (See accompanying file LICENSE_1_0.txt or
  13. copy at http://www.boost.org/LICENSE_1_0.txt)
  14. */
  15. #ifndef BOOST_NUMERIC_ODEINT_STEPPER_ADAMS_MOULTON_HPP_INCLUDED
  16. #define BOOST_NUMERIC_ODEINT_STEPPER_ADAMS_MOULTON_HPP_INCLUDED
  17. #include <boost/numeric/odeint/util/bind.hpp>
  18. #include <boost/numeric/odeint/algebra/range_algebra.hpp>
  19. #include <boost/numeric/odeint/algebra/default_operations.hpp>
  20. #include <boost/numeric/odeint/algebra/algebra_dispatcher.hpp>
  21. #include <boost/numeric/odeint/algebra/operations_dispatcher.hpp>
  22. #include <boost/numeric/odeint/util/state_wrapper.hpp>
  23. #include <boost/numeric/odeint/util/is_resizeable.hpp>
  24. #include <boost/numeric/odeint/util/resizer.hpp>
  25. #include <boost/numeric/odeint/stepper/stepper_categories.hpp>
  26. #include <boost/numeric/odeint/stepper/runge_kutta4_classic.hpp>
  27. #include <boost/numeric/odeint/stepper/detail/adams_moulton_call_algebra.hpp>
  28. #include <boost/numeric/odeint/stepper/detail/adams_moulton_coefficients.hpp>
  29. #include <boost/numeric/odeint/stepper/detail/rotating_buffer.hpp>
  30. namespace boost {
  31. namespace numeric {
  32. namespace odeint {
  33. /*
  34. * Static implicit Adams-Moulton multistep-solver without step size control and without dense output.
  35. */
  36. template<
  37. size_t Steps ,
  38. class State ,
  39. class Value = double ,
  40. class Deriv = State ,
  41. class Time = Value ,
  42. class Algebra = typename algebra_dispatcher< State >::algebra_type ,
  43. class Operations = typename operations_dispatcher< State >::operations_type ,
  44. class Resizer = initially_resizer
  45. >
  46. class adams_moulton
  47. {
  48. private:
  49. public :
  50. typedef State state_type;
  51. typedef state_wrapper< state_type > wrapped_state_type;
  52. typedef Value value_type;
  53. typedef Deriv deriv_type;
  54. typedef state_wrapper< deriv_type > wrapped_deriv_type;
  55. typedef Time time_type;
  56. typedef Algebra algebra_type;
  57. typedef Operations operations_type;
  58. typedef Resizer resizer_type;
  59. typedef stepper_tag stepper_category;
  60. typedef adams_moulton< Steps , State , Value , Deriv , Time , Algebra , Operations , Resizer > stepper_type;
  61. static const size_t steps = Steps;
  62. typedef unsigned short order_type;
  63. static const order_type order_value = steps + 1;
  64. typedef detail::rotating_buffer< wrapped_deriv_type , steps > step_storage_type;
  65. adams_moulton( )
  66. : m_coefficients() , m_dxdt() , m_resizer() ,
  67. m_algebra_instance() , m_algebra( m_algebra_instance )
  68. { }
  69. adams_moulton( algebra_type &algebra )
  70. : m_coefficients() , m_dxdt() , m_resizer() ,
  71. m_algebra_instance() , m_algebra( algebra )
  72. { }
  73. adams_moulton& operator=( const adams_moulton &stepper )
  74. {
  75. m_dxdt = stepper.m_dxdt;
  76. m_resizer = stepper.m_resizer;
  77. m_algebra = stepper.m_algebra;
  78. return *this;
  79. }
  80. order_type order( void ) const { return order_value; }
  81. /*
  82. * Version 1 : do_step( system , x , t , dt , buf );
  83. *
  84. * solves the forwarding problem
  85. */
  86. template< class System , class StateInOut , class StateIn , class ABBuf >
  87. void do_step( System system , StateInOut &x , StateIn const & pred , time_type t , time_type dt , const ABBuf &buf )
  88. {
  89. do_step( system , x , pred , t , x , dt , buf );
  90. }
  91. template< class System , class StateInOut , class StateIn , class ABBuf >
  92. void do_step( System system , const StateInOut &x , StateIn const & pred , time_type t , time_type dt , const ABBuf &buf )
  93. {
  94. do_step( system , x , pred , t , x , dt , buf );
  95. }
  96. /*
  97. * Version 2 : do_step( system , in , t , out , dt , buf );
  98. *
  99. * solves the forwarding problem
  100. */
  101. template< class System , class StateIn , class PredIn , class StateOut , class ABBuf >
  102. void do_step( System system , const StateIn &in , const PredIn &pred , time_type t , StateOut &out , time_type dt , const ABBuf &buf )
  103. {
  104. do_step_impl( system , in , pred , t , out , dt , buf );
  105. }
  106. template< class System , class StateIn , class PredIn , class StateOut , class ABBuf >
  107. void do_step( System system , const StateIn &in , const PredIn &pred , time_type t , const StateOut &out , time_type dt , const ABBuf &buf )
  108. {
  109. do_step_impl( system , in , pred , t , out , dt , buf );
  110. }
  111. template< class StateType >
  112. void adjust_size( const StateType &x )
  113. {
  114. resize_impl( x );
  115. }
  116. algebra_type& algebra()
  117. { return m_algebra; }
  118. const algebra_type& algebra() const
  119. { return m_algebra; }
  120. private:
  121. template< class System , class StateIn , class PredIn , class StateOut , class ABBuf >
  122. void do_step_impl( System system , const StateIn &in , const PredIn &pred , time_type t , StateOut &out , time_type dt , const ABBuf &buf )
  123. {
  124. typename odeint::unwrap_reference< System >::type &sys = system;
  125. m_resizer.adjust_size( in , detail::bind( &stepper_type::template resize_impl<StateIn> , detail::ref( *this ) , detail::_1 ) );
  126. sys( pred , m_dxdt.m_v , t );
  127. detail::adams_moulton_call_algebra< steps , algebra_type , operations_type >()( m_algebra , in , out , m_dxdt.m_v , buf , m_coefficients , dt );
  128. }
  129. template< class StateIn >
  130. bool resize_impl( const StateIn &x )
  131. {
  132. return adjust_size_by_resizeability( m_dxdt , x , typename is_resizeable<deriv_type>::type() );
  133. }
  134. const detail::adams_moulton_coefficients< value_type , steps > m_coefficients;
  135. wrapped_deriv_type m_dxdt;
  136. resizer_type m_resizer;
  137. protected:
  138. algebra_type m_algebra_instance;
  139. algebra_type &m_algebra;
  140. };
  141. } // odeint
  142. } // numeric
  143. } // boost
  144. #endif // BOOST_NUMERIC_ODEINT_STEPPER_ADAMS_MOULTON_HPP_INCLUDED