runge_kutta4.hpp 5.5 KB

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