runge_kutta4.hpp 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. /*
  2. [auto_generated]
  3. boost/numeric/odeint/stepper/runge_kutta4.hpp
  4. [begin_description]
  5. Implementation of the classical Runge-Kutta stepper with the generic stepper.
  6. [end_description]
  7. Copyright 2011-2013 Mario Mulansky
  8. Copyright 2011-2013 Karsten Ahnert
  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_STEPPER_RUNGE_KUTTA4_HPP_INCLUDED
  14. #define BOOST_NUMERIC_ODEINT_STEPPER_RUNGE_KUTTA4_HPP_INCLUDED
  15. #include <boost/fusion/container/vector.hpp>
  16. #include <boost/fusion/container/generation/make_vector.hpp>
  17. #include <boost/numeric/odeint/stepper/explicit_generic_rk.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/array.hpp>
  23. #include <boost/numeric/odeint/util/resizer.hpp>
  24. namespace boost {
  25. namespace numeric {
  26. namespace odeint {
  27. #ifndef DOXYGEN_SKIP
  28. template< class Value = double >
  29. struct rk4_coefficients_a1 : boost::array< Value , 1 >
  30. {
  31. rk4_coefficients_a1( void )
  32. {
  33. (*this)[0] = static_cast< Value >( 1 ) / static_cast< Value >( 2 );
  34. }
  35. };
  36. template< class Value = double >
  37. struct rk4_coefficients_a2 : boost::array< Value , 2 >
  38. {
  39. rk4_coefficients_a2( void )
  40. {
  41. (*this)[0] = static_cast<Value>(0);
  42. (*this)[1] = static_cast< Value >( 1 ) / static_cast< Value >( 2 );
  43. }
  44. };
  45. template< class Value = double >
  46. struct rk4_coefficients_a3 : boost::array< Value , 3 >
  47. {
  48. rk4_coefficients_a3( void )
  49. {
  50. (*this)[0] = static_cast<Value>(0);
  51. (*this)[1] = static_cast<Value>(0);
  52. (*this)[2] = static_cast<Value>(1);
  53. }
  54. };
  55. template< class Value = double >
  56. struct rk4_coefficients_b : boost::array< Value , 4 >
  57. {
  58. rk4_coefficients_b( void )
  59. {
  60. (*this)[0] = static_cast<Value>(1)/static_cast<Value>(6);
  61. (*this)[1] = static_cast<Value>(1)/static_cast<Value>(3);
  62. (*this)[2] = static_cast<Value>(1)/static_cast<Value>(3);
  63. (*this)[3] = static_cast<Value>(1)/static_cast<Value>(6);
  64. }
  65. };
  66. template< class Value = double >
  67. struct rk4_coefficients_c : boost::array< Value , 4 >
  68. {
  69. rk4_coefficients_c( void )
  70. {
  71. (*this)[0] = static_cast<Value>(0);
  72. (*this)[1] = static_cast< Value >( 1 ) / static_cast< Value >( 2 );
  73. (*this)[2] = static_cast< Value >( 1 ) / static_cast< Value >( 2 );
  74. (*this)[3] = static_cast<Value>(1);
  75. }
  76. };
  77. #endif
  78. template<
  79. class State ,
  80. class Value = double ,
  81. class Deriv = State ,
  82. class Time = Value ,
  83. class Algebra = typename algebra_dispatcher< State >::algebra_type ,
  84. class Operations = typename operations_dispatcher< State >::operations_type ,
  85. class Resizer = initially_resizer
  86. >
  87. #ifndef DOXYGEN_SKIP
  88. class runge_kutta4 : public explicit_generic_rk< 4 , 4 , State , Value , Deriv , Time ,
  89. Algebra , Operations , Resizer >
  90. #else
  91. class runge_kutta4 : public explicit_generic_rk
  92. #endif
  93. {
  94. public:
  95. #ifndef DOXYGEN_SKIP
  96. typedef explicit_generic_rk< 4 , 4 , State , Value , Deriv , Time ,
  97. Algebra , Operations , Resizer > stepper_base_type;
  98. #endif
  99. typedef typename stepper_base_type::state_type state_type;
  100. typedef typename stepper_base_type::value_type value_type;
  101. typedef typename stepper_base_type::deriv_type deriv_type;
  102. typedef typename stepper_base_type::time_type time_type;
  103. typedef typename stepper_base_type::algebra_type algebra_type;
  104. typedef typename stepper_base_type::operations_type operations_type;
  105. typedef typename stepper_base_type::resizer_type resizer_type;
  106. #ifndef DOXYGEN_SKIP
  107. typedef typename stepper_base_type::wrapped_state_type wrapped_state_type;
  108. typedef typename stepper_base_type::wrapped_deriv_type wrapped_deriv_type;
  109. typedef typename stepper_base_type::stepper_type stepper_type;
  110. #endif
  111. runge_kutta4( const algebra_type &algebra = algebra_type() ) : stepper_base_type(
  112. boost::fusion::make_vector( rk4_coefficients_a1<Value>() , rk4_coefficients_a2<Value>() , rk4_coefficients_a3<Value>() ) ,
  113. rk4_coefficients_b<Value>() , rk4_coefficients_c<Value>() , algebra )
  114. { }
  115. };
  116. /**
  117. * \class runge_kutta4
  118. * \brief The classical Runge-Kutta stepper of fourth order.
  119. *
  120. * The Runge-Kutta method of fourth order is one standard method for
  121. * solving ordinary differential equations and is widely used, see also
  122. * <a href="http://en.wikipedia.org/wiki/Runge%E2%80%93Kutta_methods">en.wikipedia.org/wiki/Runge-Kutta_methods</a>
  123. * The method is explicit and fulfills the Stepper concept. Step size control
  124. * or continuous output are not provided.
  125. *
  126. * This class derives from explicit_stepper_base and inherits its interface via CRTP (current recurring template pattern).
  127. * Furthermore, it derivs from explicit_generic_rk which is a generic Runge-Kutta algorithm. For more details see
  128. * explicit_stepper_base and explicit_generic_rk.
  129. *
  130. * \tparam State The state type.
  131. * \tparam Value The value type.
  132. * \tparam Deriv The type representing the time derivative of the state.
  133. * \tparam Time The time representing the independent variable - the time.
  134. * \tparam Algebra The algebra type.
  135. * \tparam Operations The operations type.
  136. * \tparam Resizer The resizer policy type.
  137. */
  138. /**
  139. * \fn runge_kutta4::runge_kutta4( const algebra_type &algebra = algebra_type() )
  140. * \brief Constructs the runge_kutta4 class. This constructor can be used as a default
  141. * constructor if the algebra has a default constructor.
  142. * \param algebra A copy of algebra is made and stored inside explicit_stepper_base.
  143. */
  144. }
  145. }
  146. }
  147. #endif // BOOST_NUMERIC_ODEINT_STEPPER_RUNGE_KUTTA4_HPP_INCLUDED