123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431 |
- #ifndef BOOST_NUMERIC_ODEINT_STEPPER_BASE_SYMPLECTIC_RKN_STEPPER_BASE_HPP_INCLUDED
- #define BOOST_NUMERIC_ODEINT_STEPPER_BASE_SYMPLECTIC_RKN_STEPPER_BASE_HPP_INCLUDED
- #include <array>
- #include <type_traits>
- #include <boost/numeric/odeint/util/bind.hpp>
- #include <boost/numeric/odeint/util/unwrap_reference.hpp>
- #include <boost/numeric/odeint/util/copy.hpp>
- #include <boost/numeric/odeint/util/is_pair.hpp>
- #include <boost/numeric/odeint/util/state_wrapper.hpp>
- #include <boost/numeric/odeint/util/resizer.hpp>
- #include <boost/numeric/odeint/stepper/stepper_categories.hpp>
- #include <boost/numeric/odeint/stepper/base/algebra_stepper_base.hpp>
- namespace boost {
- namespace numeric {
- namespace odeint {
- template<
- size_t NumOfStages ,
- unsigned short Order ,
- class Coor ,
- class Momentum ,
- class Value ,
- class CoorDeriv ,
- class MomentumDeriv ,
- class Time ,
- class Algebra ,
- class Operations ,
- class Resizer
- >
- class symplectic_nystroem_stepper_base : public algebra_stepper_base< Algebra , Operations >
- {
- public:
- typedef algebra_stepper_base< Algebra , Operations > algebra_stepper_base_type;
- typedef typename algebra_stepper_base_type::algebra_type algebra_type;
- typedef typename algebra_stepper_base_type::operations_type operations_type;
- const static size_t num_of_stages = NumOfStages;
- typedef Coor coor_type;
- typedef Momentum momentum_type;
- typedef std::pair< coor_type , momentum_type > state_type;
- typedef CoorDeriv coor_deriv_type;
- typedef state_wrapper< coor_deriv_type> wrapped_coor_deriv_type;
- typedef MomentumDeriv momentum_deriv_type;
- typedef state_wrapper< momentum_deriv_type > wrapped_momentum_deriv_type;
- typedef std::pair< coor_deriv_type , momentum_deriv_type > deriv_type;
- typedef Value value_type;
- typedef Time time_type;
- typedef Resizer resizer_type;
- typedef stepper_tag stepper_category;
-
- #ifndef DOXYGEN_SKIP
- typedef symplectic_nystroem_stepper_base< NumOfStages , Order , Coor , Momentum , Value ,
- CoorDeriv , MomentumDeriv , Time , Algebra , Operations , Resizer > internal_stepper_base_type;
- #endif
- typedef unsigned short order_type;
- static const order_type order_value = Order;
- typedef std::array< value_type , num_of_stages > coef_type;
- symplectic_nystroem_stepper_base( const coef_type &coef_a , const coef_type &coef_b , const algebra_type &algebra = algebra_type() )
- : algebra_stepper_base_type( algebra ) , m_coef_a( coef_a ) , m_coef_b( coef_b ) ,
- m_dqdt_resizer() , m_dpdt_resizer() , m_dqdt() , m_dpdt()
- { }
- order_type order( void ) const
- {
- return order_value;
- }
-
- template< class System , class StateInOut >
- void do_step( System system , const StateInOut &state , time_type t , time_type dt )
- {
- typedef typename odeint::unwrap_reference< System >::type system_type;
- do_step_impl( system , state , t , state , dt , typename is_pair< system_type >::type() );
- }
-
- template< class System , class StateInOut >
- void do_step( System system , StateInOut &state , time_type t , time_type dt )
- {
- typedef typename odeint::unwrap_reference< System >::type system_type;
- do_step_impl( system , state , t , state , dt , typename is_pair< system_type >::type() );
- }
-
- template< class System , class CoorInOut , class MomentumInOut >
- void do_step( System system , CoorInOut &q , MomentumInOut &p , time_type t , time_type dt )
- {
- do_step( system , std::make_pair( std::ref( q ) , std::ref( p ) ) , t , dt );
- }
-
- template< class System , class CoorInOut , class MomentumInOut >
- void do_step( System system , const CoorInOut &q , const MomentumInOut &p , time_type t , time_type dt )
- {
- do_step( system , std::make_pair( std::ref( q ) , std::ref( p ) ) , t , dt );
- }
-
- template< class System , class StateIn , class StateOut >
- void do_step( System system , const StateIn &in , time_type t , StateOut &out , time_type dt )
- {
- typedef typename odeint::unwrap_reference< System >::type system_type;
- do_step_impl( system , in , t , out , dt , typename is_pair< system_type >::type() );
- }
- template< class StateType >
- void adjust_size( const StateType &x )
- {
- resize_dqdt( x );
- resize_dpdt( x );
- }
-
- const coef_type& coef_a( void ) const { return m_coef_a; }
-
- const coef_type& coef_b( void ) const { return m_coef_b; }
- private:
-
- template< class System , class StateIn , class StateOut >
- void do_step_impl( System system , const StateIn &in , time_type /* t */ , StateOut &out , time_type dt , std::integral_constant<bool, true> )
- {
- typedef typename odeint::unwrap_reference< System >::type system_type;
- typedef typename odeint::unwrap_reference< typename system_type::first_type >::type coor_deriv_func_type;
- typedef typename odeint::unwrap_reference< typename system_type::second_type >::type momentum_deriv_func_type;
- system_type &sys = system;
- coor_deriv_func_type &coor_func = sys.first;
- momentum_deriv_func_type &momentum_func = sys.second;
- typedef typename odeint::unwrap_reference< StateIn >::type state_in_type;
- typedef typename odeint::unwrap_reference< typename state_in_type::first_type >::type coor_in_type;
- typedef typename odeint::unwrap_reference< typename state_in_type::second_type >::type momentum_in_type;
- const state_in_type &state_in = in;
- const coor_in_type &coor_in = state_in.first;
- const momentum_in_type &momentum_in = state_in.second;
- typedef typename odeint::unwrap_reference< StateOut >::type state_out_type;
- typedef typename odeint::unwrap_reference< typename state_out_type::first_type >::type coor_out_type;
- typedef typename odeint::unwrap_reference< typename state_out_type::second_type >::type momentum_out_type;
- state_out_type &state_out = out;
- coor_out_type &coor_out = state_out.first;
- momentum_out_type &momentum_out = state_out.second;
- m_dqdt_resizer.adjust_size(coor_in, [this](auto&& arg) { return this->resize_dqdt<coor_in_type>(std::forward<decltype(arg)>(arg)); });
- m_dpdt_resizer.adjust_size(momentum_in, [this](auto&& arg) { return this->resize_dpdt<momentum_in_type>(std::forward<decltype(arg)>(arg)); });
-
- for( size_t l=0 ; l<num_of_stages ; ++l )
- {
- if( l == 0 )
- {
- coor_func( momentum_in , m_dqdt.m_v );
- this->m_algebra.for_each3( coor_out , coor_in , m_dqdt.m_v ,
- typename operations_type::template scale_sum2< value_type , time_type >( 1.0 , m_coef_a[l] * dt ) );
- momentum_func( coor_out , m_dpdt.m_v );
- this->m_algebra.for_each3( momentum_out , momentum_in , m_dpdt.m_v ,
- typename operations_type::template scale_sum2< value_type , time_type >( 1.0 , m_coef_b[l] * dt ) );
- }
- else
- {
- coor_func( momentum_out , m_dqdt.m_v );
- this->m_algebra.for_each3( coor_out , coor_out , m_dqdt.m_v ,
- typename operations_type::template scale_sum2< value_type , time_type >( 1.0 , m_coef_a[l] * dt ) );
- momentum_func( coor_out , m_dpdt.m_v );
- this->m_algebra.for_each3( momentum_out , momentum_out , m_dpdt.m_v ,
- typename operations_type::template scale_sum2< value_type , time_type >( 1.0 , m_coef_b[l] * dt ) );
- }
- }
- }
-
- template< class System , class StateIn , class StateOut >
- void do_step_impl( System system , const StateIn &in , time_type /* t */ , StateOut &out , time_type dt , std::integral_constant<bool, false> )
- {
- typedef typename odeint::unwrap_reference< System >::type momentum_deriv_func_type;
- momentum_deriv_func_type &momentum_func = system;
- typedef typename odeint::unwrap_reference< StateIn >::type state_in_type;
- typedef typename odeint::unwrap_reference< typename state_in_type::first_type >::type coor_in_type;
- typedef typename odeint::unwrap_reference< typename state_in_type::second_type >::type momentum_in_type;
- const state_in_type &state_in = in;
- const coor_in_type &coor_in = state_in.first;
- const momentum_in_type &momentum_in = state_in.second;
- typedef typename odeint::unwrap_reference< StateOut >::type state_out_type;
- typedef typename odeint::unwrap_reference< typename state_out_type::first_type >::type coor_out_type;
- typedef typename odeint::unwrap_reference< typename state_out_type::second_type >::type momentum_out_type;
- state_out_type &state_out = out;
- coor_out_type &coor_out = state_out.first;
- momentum_out_type &momentum_out = state_out.second;
-
- m_dpdt_resizer.adjust_size(momentum_in, [this](auto&& arg) { return this->resize_dpdt<momentum_in_type>(std::forward<decltype(arg)>(arg)); });
-
-
- this->m_algebra.for_each3( coor_out , coor_in , momentum_in ,
- typename operations_type::template scale_sum2< value_type , time_type >( 1.0 , m_coef_a[0] * dt ) );
- momentum_func( coor_out , m_dpdt.m_v );
- this->m_algebra.for_each3( momentum_out , momentum_in , m_dpdt.m_v ,
- typename operations_type::template scale_sum2< value_type , time_type >( 1.0 , m_coef_b[0] * dt ) );
- for( size_t l=1 ; l<num_of_stages ; ++l )
- {
- this->m_algebra.for_each3( coor_out , coor_out , momentum_out ,
- typename operations_type::template scale_sum2< value_type , time_type >( 1.0 , m_coef_a[l] * dt ) );
- momentum_func( coor_out , m_dpdt.m_v );
- this->m_algebra.for_each3( momentum_out , momentum_out , m_dpdt.m_v ,
- typename operations_type::template scale_sum2< value_type , time_type >( 1.0 , m_coef_b[l] * dt ) );
- }
- }
- template< class StateIn >
- bool resize_dqdt( const StateIn &x )
- {
- return adjust_size_by_resizeability( m_dqdt , x , typename is_resizeable<coor_deriv_type>::type() );
- }
- template< class StateIn >
- bool resize_dpdt( const StateIn &x )
- {
- return adjust_size_by_resizeability( m_dpdt , x , typename is_resizeable<momentum_deriv_type>::type() );
- }
- const coef_type m_coef_a;
- const coef_type m_coef_b;
- resizer_type m_dqdt_resizer;
- resizer_type m_dpdt_resizer;
- wrapped_coor_deriv_type m_dqdt;
- wrapped_momentum_deriv_type m_dpdt;
- };
-
-
-
-
-
-
- }
- }
- }
- #endif
|