euler.hpp 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. /*
  2. [auto_generated]
  3. boost/numeric/odeint/stepper/euler.hpp
  4. [begin_description]
  5. Implementation of the classical explicit Euler stepper. This method is really simple and should only
  6. be used for demonstration purposes.
  7. [end_description]
  8. Copyright 2010-2013 Karsten Ahnert
  9. Copyright 2010-2013 Mario Mulansky
  10. Distributed under the Boost Software License, Version 1.0.
  11. (See accompanying file LICENSE_1_0.txt or
  12. copy at http://www.boost.org/LICENSE_1_0.txt)
  13. */
  14. #ifndef BOOST_NUMERIC_ODEINT_STEPPER_EULER_HPP_INCLUDED
  15. #define BOOST_NUMERIC_ODEINT_STEPPER_EULER_HPP_INCLUDED
  16. #include <boost/numeric/odeint/stepper/base/explicit_stepper_base.hpp>
  17. #include <boost/numeric/odeint/util/resizer.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. namespace boost {
  23. namespace numeric {
  24. namespace odeint {
  25. template<
  26. class State ,
  27. class Value = double ,
  28. class Deriv = State ,
  29. class Time = Value ,
  30. class Algebra = typename algebra_dispatcher< State >::algebra_type ,
  31. class Operations = typename operations_dispatcher< State >::operations_type ,
  32. class Resizer = initially_resizer
  33. >
  34. #ifndef DOXYGEN_SKIP
  35. class euler
  36. : public explicit_stepper_base<
  37. euler< State , Value , Deriv , Time , Algebra , Operations , Resizer > ,
  38. 1 , State , Value , Deriv , Time , Algebra , Operations , Resizer >
  39. #else
  40. class euler : public explicit_stepper_base
  41. #endif
  42. {
  43. public :
  44. #ifndef DOXYGEN_SKIP
  45. typedef explicit_stepper_base< euler< State , Value , Deriv , Time , Algebra , Operations , Resizer > , 1 , State , Value , Deriv , Time , Algebra , Operations , Resizer > stepper_base_type;
  46. #else
  47. typedef explicit_stepper_base< euler< ... > , ... > stepper_base_type;
  48. #endif
  49. typedef typename stepper_base_type::state_type state_type;
  50. typedef typename stepper_base_type::value_type value_type;
  51. typedef typename stepper_base_type::deriv_type deriv_type;
  52. typedef typename stepper_base_type::time_type time_type;
  53. typedef typename stepper_base_type::algebra_type algebra_type;
  54. typedef typename stepper_base_type::operations_type operations_type;
  55. typedef typename stepper_base_type::resizer_type resizer_type;
  56. #ifndef DOXYGEN_SKIP
  57. typedef typename stepper_base_type::stepper_type stepper_type;
  58. typedef typename stepper_base_type::wrapped_state_type wrapped_state_type;
  59. typedef typename stepper_base_type::wrapped_deriv_type wrapped_deriv_type;
  60. #endif
  61. euler( const algebra_type &algebra = algebra_type() ) : stepper_base_type( algebra )
  62. { }
  63. template< class System , class StateIn , class DerivIn , class StateOut >
  64. void do_step_impl( System /* system */ , const StateIn &in , const DerivIn &dxdt , time_type /* t */ , StateOut &out , time_type dt )
  65. {
  66. stepper_base_type::m_algebra.for_each3( out , in , dxdt ,
  67. typename operations_type::template scale_sum2< value_type , time_type >( 1.0 , dt ) );
  68. }
  69. template< class StateOut , class StateIn1 , class StateIn2 >
  70. void calc_state( StateOut &x , time_type t , const StateIn1 &old_state , time_type t_old , const StateIn2 & /*current_state*/ , time_type /* t_new */ ) const
  71. {
  72. const time_type delta = t - t_old;
  73. stepper_base_type::m_algebra.for_each3( x , old_state , stepper_base_type::m_dxdt.m_v ,
  74. typename operations_type::template scale_sum2< value_type , time_type >( 1.0 , delta ) );
  75. }
  76. template< class StateType >
  77. void adjust_size( const StateType &x )
  78. {
  79. stepper_base_type::adjust_size( x );
  80. }
  81. };
  82. /********** DOXYGEN ***********/
  83. /**
  84. * \class euler
  85. * \brief An implementation of the Euler method.
  86. *
  87. * The Euler method is a very simply solver for ordinary differential equations. This method should not be used
  88. * for real applications. It is only useful for demonstration purposes. Step size control is not provided but
  89. * trivial continuous output is available.
  90. *
  91. * This class derives from explicit_stepper_base and inherits its interface via CRTP (current recurring template pattern),
  92. * see explicit_stepper_base
  93. *
  94. * \tparam State The state type.
  95. * \tparam Value The value type.
  96. * \tparam Deriv The type representing the time derivative of the state.
  97. * \tparam Time The time representing the independent variable - the time.
  98. * \tparam Algebra The algebra type.
  99. * \tparam Operations The operations type.
  100. * \tparam Resizer The resizer policy type.
  101. */
  102. /**
  103. * \fn euler::euler( const algebra_type &algebra )
  104. * \brief Constructs the euler class. This constructor can be used as a default
  105. * constructor of the algebra has a default constructor.
  106. * \param algebra A copy of algebra is made and stored inside explicit_stepper_base.
  107. */
  108. /**
  109. * \fn euler::do_step_impl( System system , const StateIn &in , const DerivIn &dxdt , time_type t , StateOut &out , time_type dt )
  110. * \brief This method performs one step. The derivative `dxdt` of `in` at the time `t` is passed to the method.
  111. * The result is updated out of place, hence the input is in `in` and the output in `out`.
  112. * Access to this step functionality is provided by explicit_stepper_base and
  113. * `do_step_impl` should not be called directly.
  114. *
  115. * \param system The system function to solve, hence the r.h.s. of the ODE. It must fulfill the
  116. * Simple System concept.
  117. * \param in The state of the ODE which should be solved. in is not modified in this method
  118. * \param dxdt The derivative of x at t.
  119. * \param t The value of the time, at which the step should be performed.
  120. * \param out The result of the step is written in out.
  121. * \param dt The step size.
  122. */
  123. /**
  124. * \fn euler::calc_state( StateOut &x , time_type t , const StateIn1 &old_state , time_type t_old , const StateIn2 &current_state , time_type t_new ) const
  125. * \brief This method is used for continuous output and it calculates the state `x` at a time `t` from the
  126. * knowledge of two states `old_state` and `current_state` at time points `t_old` and `t_new`.
  127. */
  128. /**
  129. * \fn euler::adjust_size( const StateType &x )
  130. * \brief Adjust the size of all temporaries in the stepper manually.
  131. * \param x A state from which the size of the temporaries to be resized is deduced.
  132. */
  133. } // odeint
  134. } // numeric
  135. } // boost
  136. #endif // BOOST_NUMERIC_ODEINT_STEPPER_EULER_HPP_INCLUDED