123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314 |
- #ifndef BOOST_NUMERIC_ODEINT_STEPPER_ADAMS_BASHFORTH_MOULTON_HPP_INCLUDED
- #define BOOST_NUMERIC_ODEINT_STEPPER_ADAMS_BASHFORTH_MOULTON_HPP_INCLUDED
- #include <boost/numeric/odeint/util/bind.hpp>
- #include <boost/numeric/odeint/stepper/stepper_categories.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/util/state_wrapper.hpp>
- #include <boost/numeric/odeint/util/resizer.hpp>
- #include <boost/numeric/odeint/stepper/adams_bashforth.hpp>
- #include <boost/numeric/odeint/stepper/adams_moulton.hpp>
- namespace boost {
- namespace numeric {
- namespace odeint {
- template<
- size_t Steps ,
- 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 InitializingStepper = runge_kutta4< State , Value , Deriv , Time , Algebra , Operations, Resizer >
- >
- class adams_bashforth_moulton
- {
- #ifndef DOXYGEN_SKIP
- BOOST_STATIC_ASSERT(( Steps > 0 ));
- BOOST_STATIC_ASSERT(( Steps < 9 ));
- #endif
- public :
- typedef State state_type;
- typedef state_wrapper< state_type > wrapped_state_type;
- typedef Value value_type;
- typedef Deriv deriv_type;
- typedef state_wrapper< deriv_type > wrapped_deriv_type;
- typedef Time time_type;
- typedef Algebra algebra_type;
- typedef Operations operations_type;
- typedef Resizer resizer_type;
- typedef stepper_tag stepper_category;
- typedef InitializingStepper initializing_stepper_type;
- static const size_t steps = Steps;
- #ifndef DOXYGEN_SKIP
- typedef adams_bashforth< steps , state_type , value_type , deriv_type , time_type , algebra_type , operations_type , resizer_type, initializing_stepper_type > adams_bashforth_type;
- typedef adams_moulton< steps , state_type , value_type , deriv_type , time_type , algebra_type , operations_type , resizer_type > adams_moulton_type;
- typedef adams_bashforth_moulton< steps , state_type , value_type , deriv_type , time_type , algebra_type , operations_type , resizer_type , initializing_stepper_type> stepper_type;
- #endif
- typedef unsigned short order_type;
- static const order_type order_value = steps;
-
- adams_bashforth_moulton( void )
- : m_adams_bashforth() , m_adams_moulton( m_adams_bashforth.algebra() )
- , m_x() , m_resizer()
- { }
- adams_bashforth_moulton( const algebra_type &algebra )
- : m_adams_bashforth( algebra ) , m_adams_moulton( m_adams_bashforth.algebra() )
- , m_x() , m_resizer()
- { }
- order_type order( void ) const { return order_value; }
- template< class System , class StateInOut >
- void do_step( System system , StateInOut &x , time_type t , time_type dt )
- {
- do_step_impl1( system , x , t , dt );
- }
-
- template< class System , class StateInOut >
- void do_step( System system , const StateInOut &x , time_type t , time_type dt )
- {
- do_step_impl1( system , x , t , dt );
- }
- template< class System , class StateIn , class StateOut >
- void do_step( System system , const StateIn &in , time_type t , const StateOut &out , time_type dt )
- {
- do_step_impl2( system , in , t , out , dt );
- }
-
- template< class System , class StateIn , class StateOut >
- void do_step( System system , const StateIn &in , time_type t , StateOut &out , time_type dt )
- {
- do_step_impl2( system , in ,t , out , dt );
- }
- template< class StateType >
- void adjust_size( const StateType &x )
- {
- m_adams_bashforth.adjust_size( x );
- m_adams_moulton.adjust_size( x );
- resize_impl( x );
- }
- template< class ExplicitStepper , class System , class StateIn >
- void initialize( ExplicitStepper explicit_stepper , System system , StateIn &x , time_type &t , time_type dt )
- {
- m_adams_bashforth.initialize( explicit_stepper , system , x , t , dt );
- }
- template< class System , class StateIn >
- void initialize( System system , StateIn &x , time_type &t , time_type dt )
- {
- m_adams_bashforth.initialize( system , x , t , dt );
- }
- void reset(void)
- {
- m_adams_bashforth.reset();
- }
- private:
-
- template< typename System , typename StateInOut >
- void do_step_impl1( System system , StateInOut &x , time_type t , time_type dt )
- {
- if( m_adams_bashforth.is_initialized() )
- {
- m_resizer.adjust_size( x , detail::bind( &stepper_type::template resize_impl< StateInOut > , detail::ref( *this ) , detail::_1 ) );
- m_adams_bashforth.do_step( system , x , t , m_x.m_v , dt );
- m_adams_moulton.do_step( system , x , m_x.m_v , t+dt , x , dt , m_adams_bashforth.step_storage() );
- }
- else
- {
- m_adams_bashforth.do_step( system , x , t , dt );
- }
- }
-
- template< typename System , typename StateIn , typename StateInOut >
- void do_step_impl2( System system , StateIn const &in , time_type t , StateInOut & out , time_type dt )
- {
- if( m_adams_bashforth.is_initialized() )
- {
- m_resizer.adjust_size( in , detail::bind( &stepper_type::template resize_impl< StateInOut > , detail::ref( *this ) , detail::_1 ) );
- m_adams_bashforth.do_step( system , in , t , m_x.m_v , dt );
- m_adams_moulton.do_step( system , in , m_x.m_v , t+dt , out , dt , m_adams_bashforth.step_storage() );
- }
- else
- {
- m_adams_bashforth.do_step( system , in , t , out , dt );
- }
- }
-
- template< class StateIn >
- bool resize_impl( const StateIn &x )
- {
- return adjust_size_by_resizeability( m_x , x , typename is_resizeable< state_type >::type() );
- }
- adams_bashforth_type m_adams_bashforth;
- adams_moulton_type m_adams_moulton;
- wrapped_state_type m_x;
- resizer_type m_resizer;
- };
-
-
-
-
-
-
-
-
- }
- }
- }
- #endif
|