Back to home page

EIC code displayed by LXR

 
 

    


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

0001 /*
0002  [auto_generated]
0003  boost/numeric/odeint/stepper/explicit_error_generic_rk.hpp
0004 
0005  [begin_description]
0006  Implementation of the generic Runge Kutta error stepper. Base class for many RK error steppers.
0007  [end_description]
0008 
0009  Copyright 2011-2013 Mario Mulansky
0010  Copyright 2011-2013 Karsten Ahnert
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_EXPLICIT_ERROR_GENERIC_RK_HPP_INCLUDED
0020 #define BOOST_NUMERIC_ODEINT_STEPPER_EXPLICIT_ERROR_GENERIC_RK_HPP_INCLUDED
0021 
0022 #include <boost/numeric/odeint/stepper/base/explicit_error_stepper_base.hpp>
0023 
0024 #include <boost/numeric/odeint/algebra/default_operations.hpp>
0025 #include <boost/numeric/odeint/algebra/range_algebra.hpp>
0026 #include <boost/numeric/odeint/algebra/algebra_dispatcher.hpp>
0027 #include <boost/numeric/odeint/algebra/operations_dispatcher.hpp>
0028 #include <boost/numeric/odeint/stepper/detail/generic_rk_algorithm.hpp>
0029 #include <boost/numeric/odeint/stepper/detail/generic_rk_call_algebra.hpp>
0030 #include <boost/numeric/odeint/stepper/detail/generic_rk_operations.hpp>
0031 
0032 #include <boost/numeric/odeint/util/state_wrapper.hpp>
0033 #include <boost/numeric/odeint/util/is_resizeable.hpp>
0034 #include <boost/numeric/odeint/util/resizer.hpp>
0035 
0036 
0037 
0038 namespace boost {
0039 namespace numeric {
0040 namespace odeint {
0041 
0042 
0043 template<
0044 size_t StageCount,
0045 size_t Order,
0046 size_t StepperOrder ,
0047 size_t ErrorOrder ,
0048 class State ,
0049 class Value = double ,
0050 class Deriv = State ,
0051 class Time = Value ,
0052 class Algebra = typename algebra_dispatcher< State >::algebra_type ,
0053 class Operations = typename operations_dispatcher< State >::operations_type ,
0054 class Resizer = initially_resizer
0055 >
0056 #ifndef DOXYGEN_SKIP
0057 class explicit_error_generic_rk
0058 : public explicit_error_stepper_base<
0059   explicit_error_generic_rk< StageCount , Order , StepperOrder , ErrorOrder , State ,
0060   Value , Deriv , Time , Algebra , Operations , Resizer > ,
0061   Order , StepperOrder , ErrorOrder , State , Value , Deriv , Time , Algebra ,
0062   Operations , Resizer >
0063 #else
0064 class explicit_error_generic_rk : public explicit_error_stepper_base
0065 #endif
0066 {
0067 
0068 public:
0069 #ifndef DOXYGEN_SKIP
0070     typedef explicit_error_stepper_base<
0071             explicit_error_generic_rk< StageCount , Order , StepperOrder , ErrorOrder , State ,
0072             Value , Deriv , Time , Algebra , Operations , Resizer > ,
0073             Order , StepperOrder , ErrorOrder , State , Value , Deriv , Time , Algebra ,
0074             Operations , Resizer > stepper_base_type;
0075 #else
0076     typedef explicit_stepper_base< ... > stepper_base_type;
0077 #endif
0078     typedef typename stepper_base_type::state_type state_type;
0079     typedef typename stepper_base_type::wrapped_state_type wrapped_state_type;
0080     typedef typename stepper_base_type::value_type value_type;
0081     typedef typename stepper_base_type::deriv_type deriv_type;
0082     typedef typename stepper_base_type::wrapped_deriv_type wrapped_deriv_type;
0083     typedef typename stepper_base_type::time_type time_type;
0084     typedef typename stepper_base_type::algebra_type algebra_type;
0085     typedef typename stepper_base_type::operations_type operations_type;
0086     typedef typename stepper_base_type::resizer_type resizer_type;
0087 #ifndef DOXYGEN_SKIP
0088     typedef explicit_error_generic_rk< StageCount , Order , StepperOrder , ErrorOrder , State ,
0089             Value , Deriv , Time , Algebra , Operations , Resizer > stepper_type;
0090 #endif
0091     typedef detail::generic_rk_algorithm< StageCount , Value , Algebra , Operations > rk_algorithm_type;
0092 
0093     typedef typename rk_algorithm_type::coef_a_type coef_a_type;
0094     typedef typename rk_algorithm_type::coef_b_type coef_b_type;
0095     typedef typename rk_algorithm_type::coef_c_type coef_c_type;
0096 
0097     static const size_t stage_count = StageCount;
0098 
0099 private:
0100 
0101 
0102 public:
0103 
0104     // we use an explicit_generic_rk to do the normal rk step
0105     // and add a separate calculation of the error estimate afterwards
0106     explicit_error_generic_rk( const coef_a_type &a ,
0107             const coef_b_type &b ,
0108             const coef_b_type &b2 ,
0109             const coef_c_type &c ,
0110             const algebra_type &algebra = algebra_type() )
0111     : stepper_base_type( algebra ) , m_rk_algorithm( a , b , c ) , m_b2( b2 )
0112     { }
0113 
0114 
0115     template< class System , class StateIn , class DerivIn , class StateOut , class Err >
0116     void do_step_impl( System system , const StateIn &in , const DerivIn &dxdt ,
0117             time_type t , StateOut &out , time_type dt , Err &xerr )
0118     {
0119         // normal step
0120         do_step_impl( system , in , dxdt , t , out , dt );
0121 
0122         // additionally, perform the error calculation
0123         detail::template generic_rk_call_algebra< StageCount , algebra_type >()( stepper_base_type::m_algebra ,
0124                 xerr , dxdt , m_F , detail::generic_rk_scale_sum_err< StageCount , operations_type , value_type , time_type >( m_b2 , dt) );
0125     }
0126 
0127 
0128     template< class System , class StateIn , class DerivIn , class StateOut >
0129     void do_step_impl( System system , const StateIn &in , const DerivIn &dxdt ,
0130             time_type t , StateOut &out , time_type dt )
0131     {
0132         m_resizer.adjust_size( in , detail::bind( &stepper_type::template resize_impl< StateIn > , detail::ref( *this ) , detail::_1 ) );
0133 
0134         // actual calculation done in generic_rk.hpp
0135         m_rk_algorithm.do_step( stepper_base_type::m_algebra , system , in , dxdt , t , out , dt , m_x_tmp.m_v , m_F );
0136     }
0137 
0138 
0139     template< class StateIn >
0140     void adjust_size( const StateIn &x )
0141     {
0142         resize_impl( x );
0143         stepper_base_type::adjust_size( x );
0144     }
0145 
0146 
0147 private:
0148 
0149     template< class StateIn >
0150     bool resize_impl( const StateIn &x )
0151     {
0152         bool resized( false );
0153         resized |= adjust_size_by_resizeability( m_x_tmp , x , typename is_resizeable<state_type>::type() );
0154         for( size_t i = 0 ; i < StageCount-1 ; ++i )
0155         {
0156             resized |= adjust_size_by_resizeability( m_F[i] , x , typename is_resizeable<deriv_type>::type() );
0157         }
0158         return resized;
0159     }
0160 
0161 
0162     rk_algorithm_type m_rk_algorithm;
0163     coef_b_type m_b2;
0164 
0165     resizer_type m_resizer;
0166 
0167     wrapped_state_type m_x_tmp;
0168     wrapped_deriv_type m_F[StageCount-1];
0169 
0170 };
0171 
0172 
0173 /********* DOXYGEN *********/
0174 
0175 /**
0176  * \class explicit_error_generic_rk
0177  * \brief A generic implementation of explicit Runge-Kutta algorithms with error estimation. This class is as a
0178  * base class for all explicit Runge-Kutta steppers with error estimation.
0179  *
0180  * This class implements the explicit Runge-Kutta algorithms with error estimation in a generic way.
0181  * The Butcher tableau is passed to the stepper which constructs the stepper scheme with the help of a
0182  * template-metaprogramming algorithm. ToDo : Add example!
0183  * 
0184  * This class derives explicit_error_stepper_base which provides the stepper interface.
0185  *
0186  * \tparam StageCount The number of stages of the Runge-Kutta algorithm.
0187  * \tparam Order The order of a stepper if the stepper is used without error estimation.
0188  * \tparam StepperOrder The order of a step if the stepper is used with error estimation. Usually Order and StepperOrder have 
0189  * the same value.
0190  * \tparam ErrorOrder The order of the error step if the stepper is used with error estimation.
0191  * \tparam State The type representing the state of the ODE.
0192  * \tparam Value The floating point type which is used in the computations.
0193  * \tparam Time The type representing the independent variable - the time - of the ODE.
0194  * \tparam Algebra The algebra type.
0195  * \tparam Operations The operations type.
0196  * \tparam Resizer The resizer policy type.
0197  */
0198 
0199 
0200     /**
0201      * \fn explicit_error_generic_rk::explicit_error_generic_rk( const coef_a_type &a , const coef_b_type &b , const coef_b_type &b2 , const coef_c_type &c , const algebra_type &algebra )
0202      * \brief Constructs the explicit_error_generik_rk class with the given parameters a, b, b2 and c. See examples section for details on the coefficients.
0203      *
0204      * \param a Triangular matrix of parameters b in the Butcher tableau.
0205      * \param b Last row of the butcher tableau.
0206      * \param b2 Parameters for lower-order evaluation to estimate the error.
0207      * \param c Parameters to calculate the time points in the Butcher tableau.
0208      * \param algebra A copy of algebra is made and stored inside explicit_stepper_base.
0209      */
0210 
0211 
0212     /**
0213      * \fn explicit_error_generic_rk::do_step_impl( System system , const StateIn &in , const DerivIn &dxdt , time_type t , StateOut &out , time_type dt , Err &xerr )
0214      * \brief This method performs one step. The derivative `dxdt` of `in` at the time `t` is passed to the method.
0215      * The result is updated out-of-place, hence the input is in `in` and the output in `out`. Futhermore, an
0216      * estimation of the error is stored in `xerr`. `do_step_impl` is used by explicit_error_stepper_base.
0217      *
0218      * \param system The system function to solve, hence the r.h.s. of the ODE. It must fulfill the
0219      *               Simple System concept.
0220      * \param in The state of the ODE which should be solved. in is not modified in this method
0221      * \param dxdt The derivative of x at t.
0222      * \param t The value of the time, at which the step should be performed.
0223      * \param out The result of the step is written in out.
0224      * \param dt The step size.
0225      * \param xerr The result of the error estimation is written in xerr.
0226      */
0227 
0228     /**
0229      * \fn explicit_error_generic_rk::do_step_impl( System system , const StateIn &in , const DerivIn &dxdt , time_type t , StateOut &out , time_type dt )
0230      * \brief This method performs one step. The derivative `dxdt` of `in` at the time `t` is passed to the method.
0231      * The result is updated out-of-place, hence the input is in `in` and the output in `out`.
0232      * Access to this step functionality is provided by explicit_stepper_base and 
0233      * `do_step_impl` should not be called directly.
0234      *
0235      * \param system The system function to solve, hence the r.h.s. of the ODE. It must fulfill the
0236      *               Simple System concept.
0237      * \param in The state of the ODE which should be solved. in is not modified in this method
0238      * \param dxdt The derivative of x at t.
0239      * \param t The value of the time, at which the step should be performed.
0240      * \param out The result of the step is written in out.
0241      * \param dt The step size.
0242      */
0243 
0244     /**
0245      * \fn explicit_error_generic_rk::adjust_size( const StateIn &x )
0246      * \brief Adjust the size of all temporaries in the stepper manually.
0247      * \param x A state from which the size of the temporaries to be resized is deduced.
0248      */
0249 
0250 }
0251 }
0252 }
0253 
0254 
0255 #endif // BOOST_NUMERIC_ODEINT_STEPPER_EXPLICIT_ERROR_GENERIC_RK_HPP_INCLUDED