Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:42:55

0001 /*
0002  [auto_generated]
0003  boost/numeric/odeint/stepper/adams_bashforth_moulton.hpp
0004 
0005  [begin_description]
0006  Implementation of the Adams-Bashforth-Moulton method, a predictor-corrector multistep method.
0007  [end_description]
0008 
0009  Copyright 2011-2013 Karsten Ahnert
0010  Copyright 2011-2013 Mario Mulansky
0011  Copyright 2012 Christoph Koke
0012 
0013  Distributed under the Boost Software License, Version 1.0.
0014  (See accompanying file LICENSE_1_0.txt or
0015  copy at http://www.boost.org/LICENSE_1_0.txt)
0016  */
0017 
0018 
0019 #ifndef BOOST_NUMERIC_ODEINT_STEPPER_ADAMS_BASHFORTH_MOULTON_HPP_INCLUDED
0020 #define BOOST_NUMERIC_ODEINT_STEPPER_ADAMS_BASHFORTH_MOULTON_HPP_INCLUDED
0021 
0022 
0023 #include <boost/numeric/odeint/util/bind.hpp>
0024 
0025 #include <boost/numeric/odeint/stepper/stepper_categories.hpp>
0026 #include <boost/numeric/odeint/algebra/range_algebra.hpp>
0027 #include <boost/numeric/odeint/algebra/default_operations.hpp>
0028 #include <boost/numeric/odeint/algebra/algebra_dispatcher.hpp>
0029 #include <boost/numeric/odeint/algebra/operations_dispatcher.hpp>
0030 
0031 #include <boost/numeric/odeint/util/state_wrapper.hpp>
0032 #include <boost/numeric/odeint/util/resizer.hpp>
0033 
0034 #include <boost/numeric/odeint/stepper/adams_bashforth.hpp>
0035 #include <boost/numeric/odeint/stepper/adams_moulton.hpp>
0036 
0037 
0038 
0039 namespace boost {
0040 namespace numeric {
0041 namespace odeint {
0042 
0043 
0044 template<
0045 size_t Steps ,
0046 class State ,
0047 class Value = double ,
0048 class Deriv = State ,
0049 class Time = Value ,
0050 class Algebra = typename algebra_dispatcher< State >::algebra_type ,
0051 class Operations = typename operations_dispatcher< State >::operations_type ,
0052 class Resizer = initially_resizer,
0053 class InitializingStepper = runge_kutta4< State , Value , Deriv , Time , Algebra , Operations, Resizer >
0054 >
0055 class adams_bashforth_moulton
0056 {
0057 
0058 #ifndef DOXYGEN_SKIP
0059     BOOST_STATIC_ASSERT(( Steps > 0 ));
0060     BOOST_STATIC_ASSERT(( Steps < 9 ));
0061 #endif
0062 
0063 public :
0064 
0065     typedef State state_type;
0066     typedef state_wrapper< state_type > wrapped_state_type;
0067     typedef Value value_type;
0068     typedef Deriv deriv_type;
0069     typedef state_wrapper< deriv_type > wrapped_deriv_type;
0070     typedef Time time_type;
0071     typedef Algebra algebra_type;
0072     typedef Operations operations_type;
0073     typedef Resizer resizer_type;
0074     typedef stepper_tag stepper_category;
0075     typedef InitializingStepper initializing_stepper_type;
0076 
0077     static const size_t steps = Steps;
0078 #ifndef DOXYGEN_SKIP
0079     typedef adams_bashforth< steps , state_type , value_type , deriv_type , time_type , algebra_type , operations_type , resizer_type, initializing_stepper_type > adams_bashforth_type;
0080     typedef adams_moulton< steps , state_type , value_type , deriv_type , time_type , algebra_type , operations_type , resizer_type > adams_moulton_type;
0081     typedef adams_bashforth_moulton< steps , state_type , value_type , deriv_type , time_type , algebra_type , operations_type , resizer_type , initializing_stepper_type> stepper_type;
0082 #endif //DOXYGEN_SKIP
0083     typedef unsigned short order_type;
0084     static const order_type order_value = steps;
0085 
0086     /** \brief Constructs the adams_bashforth class. */
0087     adams_bashforth_moulton( void )
0088     : m_adams_bashforth() , m_adams_moulton( m_adams_bashforth.algebra() )
0089     , m_x() , m_resizer()
0090     { }
0091 
0092     adams_bashforth_moulton( const algebra_type &algebra )
0093     : m_adams_bashforth( algebra ) , m_adams_moulton( m_adams_bashforth.algebra() )
0094     , m_x() , m_resizer()    
0095     { }
0096 
0097     order_type order( void ) const { return order_value; }
0098 
0099     template< class System , class StateInOut >
0100     void do_step( System system , StateInOut &x , time_type t , time_type dt )
0101     {
0102         do_step_impl1( system , x , t , dt );
0103     }
0104 
0105     /**
0106      * \brief Second version to solve the forwarding problem, can be called with Boost.Range as StateInOut.
0107      */
0108     template< class System , class StateInOut >
0109     void do_step( System system , const StateInOut &x , time_type t , time_type dt )
0110     {
0111         do_step_impl1( system , x , t , dt );
0112     }
0113 
0114     template< class System , class StateIn , class StateOut >
0115     void do_step( System system , const StateIn &in , time_type t , const StateOut &out , time_type dt )
0116     {
0117         do_step_impl2( system , in , t , out , dt );
0118     }
0119 
0120     /**
0121      * \brief Second version to solve the forwarding problem, can be called with Boost.Range as StateOut.
0122      */
0123     template< class System , class StateIn , class StateOut >
0124     void do_step( System system , const StateIn &in , time_type t , StateOut &out , time_type dt )
0125     {
0126         do_step_impl2( system , in ,t , out , dt );
0127     }
0128 
0129 
0130     template< class StateType >
0131     void adjust_size( const StateType &x )
0132     {
0133         m_adams_bashforth.adjust_size( x );
0134         m_adams_moulton.adjust_size( x );
0135         resize_impl( x );
0136     }
0137 
0138 
0139     template< class ExplicitStepper , class System , class StateIn >
0140     void initialize( ExplicitStepper explicit_stepper , System system , StateIn &x , time_type &t , time_type dt )
0141     {
0142         m_adams_bashforth.initialize( explicit_stepper , system , x , t , dt );
0143     }
0144 
0145 
0146     template< class System , class StateIn >
0147     void initialize( System system , StateIn &x , time_type &t , time_type dt )
0148     {
0149         m_adams_bashforth.initialize( system , x , t , dt );
0150     }
0151 
0152 
0153     void reset(void)
0154     {
0155         m_adams_bashforth.reset();
0156     }
0157 
0158 
0159 
0160 private:
0161     
0162     template< typename System , typename StateInOut >
0163     void do_step_impl1( System system , StateInOut &x , time_type t , time_type dt )
0164     {
0165         if( m_adams_bashforth.is_initialized() )
0166         {
0167             m_resizer.adjust_size( x , detail::bind( &stepper_type::template resize_impl< StateInOut > , detail::ref( *this ) , detail::_1 ) );
0168             m_adams_bashforth.do_step( system , x , t , m_x.m_v , dt );
0169             m_adams_moulton.do_step( system , x , m_x.m_v , t+dt , x , dt , m_adams_bashforth.step_storage() );
0170         }
0171         else
0172         {
0173             m_adams_bashforth.do_step( system , x , t , dt );
0174         }
0175     }
0176     
0177     template< typename System , typename StateIn , typename StateInOut >
0178     void do_step_impl2( System system , StateIn const &in , time_type t , StateInOut & out , time_type dt )
0179     {
0180         if( m_adams_bashforth.is_initialized() )
0181         {
0182             m_resizer.adjust_size( in , detail::bind( &stepper_type::template resize_impl< StateInOut > , detail::ref( *this ) , detail::_1 ) );        
0183             m_adams_bashforth.do_step( system , in , t , m_x.m_v , dt );
0184             m_adams_moulton.do_step( system , in , m_x.m_v , t+dt , out , dt , m_adams_bashforth.step_storage() );
0185         }
0186         else
0187         {
0188             m_adams_bashforth.do_step( system , in , t , out , dt );
0189         }
0190     }
0191 
0192     
0193     template< class StateIn >
0194     bool resize_impl( const StateIn &x )
0195     {
0196         return adjust_size_by_resizeability( m_x , x , typename is_resizeable< state_type >::type() );
0197     }
0198 
0199     adams_bashforth_type m_adams_bashforth;
0200     adams_moulton_type m_adams_moulton;
0201     wrapped_state_type m_x;
0202     resizer_type m_resizer;
0203 };
0204 
0205 
0206 /********* DOXYGEN ********/
0207 
0208 /**
0209  * \class adams_bashforth_moulton
0210  * \brief The Adams-Bashforth-Moulton multistep algorithm.
0211  *
0212  * The Adams-Bashforth method is a multi-step predictor-corrector algorithm 
0213  * with configurable step number. The step number is specified as template 
0214  * parameter Steps and it then uses the result from the previous Steps steps. 
0215  * See also
0216  * <a href="http://en.wikipedia.org/wiki/Linear_multistep_method">en.wikipedia.org/wiki/Linear_multistep_method</a>.
0217  * Currently, a maximum of Steps=8 is supported.
0218  * The method is explicit and fulfills the Stepper concept. Step size control
0219  * or continuous output are not provided.
0220  * 
0221  * This class derives from algebra_base and inherits its interface via
0222  * CRTP (current recurring template pattern). For more details see
0223  * algebra_stepper_base.
0224  *
0225  * \tparam Steps The number of steps (maximal 8).
0226  * \tparam State The state type.
0227  * \tparam Value The value type.
0228  * \tparam Deriv The type representing the time derivative of the state.
0229  * \tparam Time The time representing the independent variable - the time.
0230  * \tparam Algebra The algebra type.
0231  * \tparam Operations The operations type.
0232  * \tparam Resizer The resizer policy type.
0233  * \tparam InitializingStepper The stepper for the first two steps.
0234  */
0235 
0236     /**
0237      * \fn adams_bashforth_moulton::adams_bashforth_moulton( const algebra_type &algebra )
0238      * \brief Constructs the adams_bashforth class. This constructor can be used as a default
0239      * constructor if the algebra has a default constructor. 
0240      * \param algebra A copy of algebra is made and stored.
0241      */
0242 
0243     /**
0244      * \fn adams_bashforth_moulton::order( void ) const
0245      * \brief Returns the order of the algorithm, which is equal to the number of steps+1.
0246      * \return order of the method.
0247      */
0248 
0249     /**
0250      * \fn adams_bashforth_moulton::do_step( System system , StateInOut &x , time_type t , time_type dt )
0251      * \brief This method performs one step. It transforms the result in-place.
0252      *
0253      * \param system The system function to solve, hence the r.h.s. of the ordinary differential equation. It must fulfill the
0254      *               Simple System concept.
0255      * \param x The state of the ODE which should be solved. After calling do_step the result is updated in x.
0256      * \param t The value of the time, at which the step should be performed.
0257      * \param dt The step size.
0258      */
0259 
0260 
0261     /**
0262      * \fn adams_bashforth_moulton::do_step( System system , const StateIn &in , time_type t , const StateOut &out , time_type dt )
0263      * \brief The method performs one step with the stepper passed by Stepper. The state of the ODE is updated out-of-place.
0264      *
0265      * \param system The system function to solve, hence the r.h.s. of the ODE. It must fulfill the
0266      *               Simple System concept.
0267      * \param in The state of the ODE which should be solved. in is not modified in this method
0268      * \param t The value of the time, at which the step should be performed.
0269      * \param out The result of the step is written in out.
0270      * \param dt The step size.
0271      */
0272 
0273     /**
0274      * \fn adams_bashforth_moulton::adjust_size( const StateType &x )
0275      * \brief Adjust the size of all temporaries in the stepper manually.
0276      * \param x A state from which the size of the temporaries to be resized is deduced.
0277      */
0278 
0279     /**
0280      * \fn adams_bashforth_moulton::initialize( ExplicitStepper explicit_stepper , System system , StateIn &x , time_type &t , time_type dt )
0281      * \brief Initialized the stepper. Does Steps-1 steps with the explicit_stepper to fill the buffer.
0282      * \note The state x and time t are updated to the values after Steps-1 initial steps.
0283      * \param explicit_stepper the stepper used to fill the buffer of previous step results
0284      * \param system The system function to solve, hence the r.h.s. of the ordinary differential equation. It must fulfill the
0285      *               Simple System concept.
0286      * \param x The initial state of the ODE which should be solved, updated after in this method.
0287      * \param t The initial time, updated in this method.
0288      * \param dt The step size.
0289      */
0290 
0291     /**
0292      * \fn adams_bashforth_moulton::initialize( System system , StateIn &x , time_type &t , time_type dt )
0293      * \brief Initialized the stepper. Does Steps-1 steps using the standard initializing stepper 
0294      * of the underlying adams_bashforth stepper.
0295      * \param system The system function to solve, hence the r.h.s. of the ordinary differential equation. It must fulfill the
0296      *               Simple System concept.
0297      * \param x The state of the ODE which should be solved. After calling do_step the result is updated in x.
0298      * \param t The value of the time, at which the step should be performed.
0299      * \param dt The step size.
0300      */
0301 
0302     /**
0303      * \fn adams_bashforth_moulton::reset( void )
0304      * \brief Resets the internal buffers of the stepper.
0305      */
0306 
0307 
0308 } // odeint
0309 } // numeric
0310 } // boost
0311 
0312 
0313 
0314 #endif // BOOST_NUMERIC_ODEINT_STEPPER_ADAMS_BASHFORTH_MOULTON_HPP_INCLUDED