123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246 |
- #ifndef BOOST_NUMERIC_ODEINT_STEPPER_EXPLICIT_GENERIC_RK_HPP_INCLUDED
- #define BOOST_NUMERIC_ODEINT_STEPPER_EXPLICIT_GENERIC_RK_HPP_INCLUDED
- #include <boost/array.hpp>
- #include <boost/numeric/odeint/stepper/base/explicit_stepper_base.hpp>
- #include <boost/numeric/odeint/algebra/range_algebra.hpp>
- #include <boost/numeric/odeint/algebra/default_operations.hpp>
- #include <boost/numeric/odeint/algebra/algebra_dispatcher.hpp>
- #include <boost/numeric/odeint/algebra/operations_dispatcher.hpp>
- #include <boost/numeric/odeint/stepper/detail/generic_rk_algorithm.hpp>
- #include <boost/numeric/odeint/util/state_wrapper.hpp>
- #include <boost/numeric/odeint/util/is_resizeable.hpp>
- #include <boost/numeric/odeint/util/resizer.hpp>
- namespace boost {
- namespace numeric {
- namespace odeint {
- #ifndef DOXYGEN_SKIP
- template<
- size_t StageCount,
- size_t Order,
- class State ,
- class Value = double ,
- class Deriv = State ,
- class Time = Value ,
- class Algebra = typename algebra_dispatcher< State >::algebra_type ,
- class Operations = typename operations_dispatcher< State >::operations_type ,
- class Resizer = initially_resizer
- >
- class explicit_generic_rk;
- struct stage_vector;
- template< class T , class Constant >
- struct array_wrapper
- {
- typedef const typename boost::array< T , Constant::value > type;
- };
- template< class T , size_t i >
- struct stage
- {
- T c;
- boost::array< T , i > a;
- };
- template< class T , class Constant >
- struct stage_wrapper
- {
- typedef stage< T , Constant::value > type;
- };
- #endif
- template<
- size_t StageCount,
- size_t Order,
- class State ,
- class Value ,
- class Deriv ,
- class Time ,
- class Algebra ,
- class Operations ,
- class Resizer
- >
- #ifndef DOXYGEN_SKIP
- class explicit_generic_rk : public explicit_stepper_base<
- explicit_generic_rk< StageCount , Order , State , Value , Deriv , Time , Algebra , Operations , Resizer > ,
- Order , State , Value , Deriv , Time , Algebra , Operations , Resizer >
- #else
- class explicit_generic_rk : public explicit_stepper_base
- #endif
- {
- public:
- #ifndef DOXYGEN_SKIP
- typedef explicit_stepper_base<
- explicit_generic_rk< StageCount , Order , State , Value , Deriv ,Time , Algebra , Operations , Resizer > ,
- Order , State , Value , Deriv , Time , Algebra ,
- Operations , Resizer > stepper_base_type;
- #else
- typedef explicit_stepper_base< ... > stepper_base_type;
- #endif
- typedef typename stepper_base_type::state_type state_type;
- typedef typename stepper_base_type::wrapped_state_type wrapped_state_type;
- typedef typename stepper_base_type::value_type value_type;
- typedef typename stepper_base_type::deriv_type deriv_type;
- typedef typename stepper_base_type::wrapped_deriv_type wrapped_deriv_type;
- typedef typename stepper_base_type::time_type time_type;
- typedef typename stepper_base_type::algebra_type algebra_type;
- typedef typename stepper_base_type::operations_type operations_type;
- typedef typename stepper_base_type::resizer_type resizer_type;
- #ifndef DOXYGEN_SKIP
- typedef explicit_generic_rk< StageCount , Order , State , Value , Deriv ,Time , Algebra , Operations , Resizer > stepper_type;
- #endif
- typedef detail::generic_rk_algorithm< StageCount , Value , Algebra , Operations > rk_algorithm_type;
- typedef typename rk_algorithm_type::coef_a_type coef_a_type;
- typedef typename rk_algorithm_type::coef_b_type coef_b_type;
- typedef typename rk_algorithm_type::coef_c_type coef_c_type;
- #ifndef DOXYGEN_SKIP
- static const size_t stage_count = StageCount;
- #endif
- public:
- explicit_generic_rk( const coef_a_type &a , const coef_b_type &b , const coef_c_type &c ,
- const algebra_type &algebra = algebra_type() )
- : stepper_base_type( algebra ) , m_rk_algorithm( a , b , c )
- { }
- template< class System , class StateIn , class DerivIn , class StateOut >
- void do_step_impl( System system , const StateIn &in , const DerivIn &dxdt ,
- time_type t , StateOut &out , time_type dt )
- {
- m_resizer.adjust_size( in , detail::bind( &stepper_type::template resize_impl< StateIn > , detail::ref( *this ) , detail::_1 ) );
-
- m_rk_algorithm.do_step( stepper_base_type::m_algebra , system , in , dxdt , t , out , dt , m_x_tmp.m_v , m_F );
- }
- template< class StateIn >
- void adjust_size( const StateIn &x )
- {
- resize_impl( x );
- stepper_base_type::adjust_size( x );
- }
- private:
- template< class StateIn >
- bool resize_impl( const StateIn &x )
- {
- bool resized( false );
- resized |= adjust_size_by_resizeability( m_x_tmp , x , typename is_resizeable<state_type>::type() );
- for( size_t i = 0 ; i < StageCount-1 ; ++i )
- {
- resized |= adjust_size_by_resizeability( m_F[i] , x , typename is_resizeable<deriv_type>::type() );
- }
- return resized;
- }
- rk_algorithm_type m_rk_algorithm;
- resizer_type m_resizer;
- wrapped_state_type m_x_tmp;
- wrapped_deriv_type m_F[StageCount-1];
- };
-
-
-
-
- }
- }
- }
- #endif
|