Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-07-05 08:40:09

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