Chris@16: /* Chris@16: [auto_generated] Chris@16: boost/numeric/odeint/stepper/euler.hpp Chris@16: Chris@16: [begin_description] Chris@16: Implementation of the classical explicit Euler stepper. This method is really simple and should only Chris@16: be used for demonstration purposes. Chris@16: [end_description] Chris@16: Chris@101: Copyright 2010-2013 Karsten Ahnert Chris@101: Copyright 2010-2013 Mario Mulansky Chris@16: Chris@16: Distributed under the Boost Software License, Version 1.0. Chris@16: (See accompanying file LICENSE_1_0.txt or Chris@16: copy at http://www.boost.org/LICENSE_1_0.txt) Chris@16: */ Chris@16: Chris@16: Chris@16: #ifndef BOOST_NUMERIC_ODEINT_STEPPER_EULER_HPP_INCLUDED Chris@16: #define BOOST_NUMERIC_ODEINT_STEPPER_EULER_HPP_INCLUDED Chris@16: Chris@16: Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@101: #include Chris@101: #include Chris@16: Chris@16: namespace boost { Chris@16: namespace numeric { Chris@16: namespace odeint { Chris@16: Chris@16: Chris@16: template< Chris@16: class State , Chris@16: class Value = double , Chris@16: class Deriv = State , Chris@16: class Time = Value , Chris@101: class Algebra = typename algebra_dispatcher< State >::algebra_type , Chris@101: class Operations = typename operations_dispatcher< State >::operations_type , Chris@16: class Resizer = initially_resizer Chris@16: > Chris@16: #ifndef DOXYGEN_SKIP Chris@16: class euler Chris@16: : public explicit_stepper_base< Chris@16: euler< State , Value , Deriv , Time , Algebra , Operations , Resizer > , Chris@16: 1 , State , Value , Deriv , Time , Algebra , Operations , Resizer > Chris@16: #else Chris@16: class euler : public explicit_stepper_base Chris@16: #endif Chris@16: { Chris@16: public : Chris@16: Chris@16: #ifndef DOXYGEN_SKIP Chris@16: typedef explicit_stepper_base< euler< State , Value , Deriv , Time , Algebra , Operations , Resizer > , 1 , State , Value , Deriv , Time , Algebra , Operations , Resizer > stepper_base_type; Chris@16: #else Chris@16: typedef explicit_stepper_base< euler< ... > , ... > stepper_base_type; Chris@16: #endif Chris@16: typedef typename stepper_base_type::state_type state_type; Chris@16: typedef typename stepper_base_type::value_type value_type; Chris@16: typedef typename stepper_base_type::deriv_type deriv_type; Chris@16: typedef typename stepper_base_type::time_type time_type; Chris@16: typedef typename stepper_base_type::algebra_type algebra_type; Chris@16: typedef typename stepper_base_type::operations_type operations_type; Chris@16: typedef typename stepper_base_type::resizer_type resizer_type; Chris@16: Chris@16: #ifndef DOXYGEN_SKIP Chris@16: typedef typename stepper_base_type::stepper_type stepper_type; Chris@16: typedef typename stepper_base_type::wrapped_state_type wrapped_state_type; Chris@16: typedef typename stepper_base_type::wrapped_deriv_type wrapped_deriv_type; Chris@16: #endif Chris@16: Chris@16: Chris@16: euler( const algebra_type &algebra = algebra_type() ) : stepper_base_type( algebra ) Chris@16: { } Chris@16: Chris@16: template< class System , class StateIn , class DerivIn , class StateOut > Chris@101: void do_step_impl( System /* system */ , const StateIn &in , const DerivIn &dxdt , time_type /* t */ , StateOut &out , time_type dt ) Chris@16: { Chris@16: stepper_base_type::m_algebra.for_each3( out , in , dxdt , Chris@16: typename operations_type::template scale_sum2< value_type , time_type >( 1.0 , dt ) ); Chris@16: Chris@16: } Chris@16: Chris@16: template< class StateOut , class StateIn1 , class StateIn2 > Chris@101: 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 Chris@16: { Chris@16: const time_type delta = t - t_old; Chris@16: stepper_base_type::m_algebra.for_each3( x , old_state , stepper_base_type::m_dxdt.m_v , Chris@16: typename operations_type::template scale_sum2< value_type , time_type >( 1.0 , delta ) ); Chris@16: } Chris@16: Chris@16: template< class StateType > Chris@16: void adjust_size( const StateType &x ) Chris@16: { Chris@16: stepper_base_type::adjust_size( x ); Chris@16: } Chris@16: }; Chris@16: Chris@16: Chris@16: Chris@16: /********** DOXYGEN ***********/ Chris@16: Chris@16: /** Chris@16: * \class euler Chris@16: * \brief An implementation of the Euler method. Chris@16: * Chris@16: * The Euler method is a very simply solver for ordinary differential equations. This method should not be used Chris@16: * for real applications. It is only useful for demonstration purposes. Step size control is not provided but Chris@16: * trivial continuous output is available. Chris@16: * Chris@16: * This class derives from explicit_stepper_base and inherits its interface via CRTP (current recurring template pattern), Chris@16: * see explicit_stepper_base Chris@16: * Chris@16: * \tparam State The state type. Chris@16: * \tparam Value The value type. Chris@16: * \tparam Deriv The type representing the time derivative of the state. Chris@16: * \tparam Time The time representing the independent variable - the time. Chris@16: * \tparam Algebra The algebra type. Chris@16: * \tparam Operations The operations type. Chris@16: * \tparam Resizer The resizer policy type. Chris@16: */ Chris@16: Chris@16: /** Chris@16: * \fn euler::euler( const algebra_type &algebra ) Chris@16: * \brief Constructs the euler class. This constructor can be used as a default Chris@16: * constructor of the algebra has a default constructor. Chris@16: * \param algebra A copy of algebra is made and stored inside explicit_stepper_base. Chris@16: */ Chris@16: Chris@16: /** Chris@16: * \fn euler::do_step_impl( System system , const StateIn &in , const DerivIn &dxdt , time_type t , StateOut &out , time_type dt ) Chris@16: * \brief This method performs one step. The derivative `dxdt` of `in` at the time `t` is passed to the method. Chris@16: * The result is updated out of place, hence the input is in `in` and the output in `out`. Chris@16: * Access to this step functionality is provided by explicit_stepper_base and Chris@16: * `do_step_impl` should not be called directly. Chris@16: * Chris@16: * \param system The system function to solve, hence the r.h.s. of the ODE. It must fulfill the Chris@16: * Simple System concept. Chris@16: * \param in The state of the ODE which should be solved. in is not modified in this method Chris@16: * \param dxdt The derivative of x at t. Chris@16: * \param t The value of the time, at which the step should be performed. Chris@16: * \param out The result of the step is written in out. Chris@16: * \param dt The step size. Chris@16: */ Chris@16: Chris@16: Chris@16: /** Chris@16: * \fn euler::calc_state( StateOut &x , time_type t , const StateIn1 &old_state , time_type t_old , const StateIn2 ¤t_state , time_type t_new ) const Chris@16: * \brief This method is used for continuous output and it calculates the state `x` at a time `t` from the Chris@16: * knowledge of two states `old_state` and `current_state` at time points `t_old` and `t_new`. Chris@16: */ Chris@16: Chris@16: /** Chris@16: * \fn euler::adjust_size( const StateType &x ) Chris@16: * \brief Adjust the size of all temporaries in the stepper manually. Chris@16: * \param x A state from which the size of the temporaries to be resized is deduced. Chris@16: */ Chris@16: Chris@16: } // odeint Chris@16: } // numeric Chris@16: } // boost Chris@16: Chris@16: Chris@16: #endif // BOOST_NUMERIC_ODEINT_STEPPER_EULER_HPP_INCLUDED