Chris@16: /* Chris@16: [auto_generated] Chris@16: boost/numeric/odeint/stepper/rosenbrock4_dense_output.hpp Chris@16: Chris@16: [begin_description] Chris@16: Dense output for Rosenbrock 4. Chris@16: [end_description] Chris@16: Chris@101: Copyright 2011-2012 Karsten Ahnert Chris@101: Copyright 2011-2012 Mario Mulansky Chris@101: Copyright 2012 Christoph Koke Chris@16: Chris@16: Distributed under the Boost Software License, Version 1.0. Chris@16: (See accompanying file LICENSE_1_0.txt or Chris@16: copy at http://www.boost.org/LICENSE_1_0.txt) Chris@16: */ Chris@16: Chris@16: Chris@16: #ifndef BOOST_NUMERIC_ODEINT_STEPPER_ROSENBROCK4_DENSE_OUTPUT_HPP_INCLUDED Chris@16: #define BOOST_NUMERIC_ODEINT_STEPPER_ROSENBROCK4_DENSE_OUTPUT_HPP_INCLUDED Chris@16: Chris@16: Chris@16: #include Chris@16: Chris@16: #include Chris@16: Chris@16: #include Chris@16: #include Chris@16: Chris@16: Chris@16: namespace boost { Chris@16: namespace numeric { Chris@16: namespace odeint { Chris@16: Chris@16: template< class ControlledStepper > Chris@16: class rosenbrock4_dense_output Chris@16: { Chris@16: Chris@16: public: Chris@16: Chris@16: typedef ControlledStepper controlled_stepper_type; Chris@16: typedef typename controlled_stepper_type::stepper_type stepper_type; Chris@16: typedef typename stepper_type::value_type value_type; Chris@16: typedef typename stepper_type::state_type state_type; Chris@16: typedef typename stepper_type::wrapped_state_type wrapped_state_type; Chris@16: typedef typename stepper_type::time_type time_type; Chris@16: typedef typename stepper_type::deriv_type deriv_type; Chris@16: typedef typename stepper_type::wrapped_deriv_type wrapped_deriv_type; Chris@16: typedef typename stepper_type::resizer_type resizer_type; Chris@16: typedef dense_output_stepper_tag stepper_category; Chris@16: Chris@16: typedef rosenbrock4_dense_output< ControlledStepper > dense_output_stepper_type; Chris@16: Chris@16: rosenbrock4_dense_output( const controlled_stepper_type &stepper = controlled_stepper_type() ) Chris@16: : m_stepper( stepper ) , Chris@16: m_x1() , m_x2() , Chris@16: m_current_state_x1( true ) , Chris@16: m_t() , m_t_old() , m_dt() Chris@16: { Chris@16: } Chris@16: Chris@16: Chris@16: Chris@16: template< class StateType > Chris@16: void initialize( const StateType &x0 , time_type t0 , time_type dt0 ) Chris@16: { Chris@16: m_resizer.adjust_size( x0 , detail::bind( &dense_output_stepper_type::template resize_impl< StateType > , detail::ref( *this ) , detail::_1 ) ); Chris@16: get_current_state() = x0; Chris@16: m_t = t0; Chris@16: m_dt = dt0; Chris@16: } Chris@16: Chris@16: template< class System > Chris@16: std::pair< time_type , time_type > do_step( System system ) Chris@16: { Chris@16: const size_t max_count = 1000; Chris@16: Chris@16: controlled_step_result res = fail; Chris@16: m_t_old = m_t; Chris@16: size_t count = 0; Chris@16: do Chris@16: { Chris@16: res = m_stepper.try_step( system , get_current_state() , m_t , get_old_state() , m_dt ); Chris@16: if( count++ == max_count ) Chris@16: throw std::overflow_error( "rosenbrock4 : too much iterations!"); Chris@16: } Chris@16: while( res == fail ); Chris@16: m_stepper.stepper().prepare_dense_output(); Chris@16: this->toggle_current_state(); Chris@16: return std::make_pair( m_t_old , m_t ); Chris@16: } Chris@16: Chris@16: Chris@16: /* Chris@16: * The two overloads are needed in order to solve the forwarding problem. Chris@16: */ Chris@16: template< class StateOut > Chris@16: void calc_state( time_type t , StateOut &x ) Chris@16: { Chris@16: m_stepper.stepper().calc_state( t , x , get_old_state() , m_t_old , get_current_state() , m_t ); Chris@16: } Chris@16: Chris@16: template< class StateOut > Chris@16: void calc_state( time_type t , const StateOut &x ) Chris@16: { Chris@16: m_stepper.stepper().calc_state( t , x , get_old_state() , m_t_old , get_current_state() , m_t ); Chris@16: } Chris@16: Chris@16: Chris@16: template< class StateType > Chris@16: void adjust_size( const StateType &x ) Chris@16: { Chris@16: m_stepper.adjust_size( x ); Chris@16: resize_impl( x ); Chris@16: } Chris@16: Chris@16: Chris@16: Chris@16: Chris@16: const state_type& current_state( void ) const Chris@16: { Chris@16: return get_current_state(); Chris@16: } Chris@16: Chris@16: time_type current_time( void ) const Chris@16: { Chris@16: return m_t; Chris@16: } Chris@16: Chris@16: const state_type& previous_state( void ) const Chris@16: { Chris@16: return get_old_state(); Chris@16: } Chris@16: Chris@16: time_type previous_time( void ) const Chris@16: { Chris@16: return m_t_old; Chris@16: } Chris@16: Chris@16: time_type current_time_step( void ) const Chris@16: { Chris@16: return m_dt; Chris@16: } Chris@16: Chris@16: Chris@16: Chris@16: Chris@16: private: Chris@16: Chris@16: state_type& get_current_state( void ) Chris@16: { Chris@16: return m_current_state_x1 ? m_x1.m_v : m_x2.m_v ; Chris@16: } Chris@16: Chris@16: const state_type& get_current_state( void ) const Chris@16: { Chris@16: return m_current_state_x1 ? m_x1.m_v : m_x2.m_v ; Chris@16: } Chris@16: Chris@16: state_type& get_old_state( void ) Chris@16: { Chris@16: return m_current_state_x1 ? m_x2.m_v : m_x1.m_v ; Chris@16: } Chris@16: Chris@16: const state_type& get_old_state( void ) const Chris@16: { Chris@16: return m_current_state_x1 ? m_x2.m_v : m_x1.m_v ; Chris@16: } Chris@16: Chris@16: void toggle_current_state( void ) Chris@16: { Chris@16: m_current_state_x1 = ! m_current_state_x1; Chris@16: } Chris@16: Chris@16: Chris@16: template< class StateIn > Chris@16: bool resize_impl( const StateIn &x ) Chris@16: { Chris@16: bool resized = false; Chris@16: resized |= adjust_size_by_resizeability( m_x1 , x , typename is_resizeable::type() ); Chris@16: resized |= adjust_size_by_resizeability( m_x2 , x , typename is_resizeable::type() ); Chris@16: return resized; Chris@16: } Chris@16: Chris@16: Chris@16: controlled_stepper_type m_stepper; Chris@16: resizer_type m_resizer; Chris@16: wrapped_state_type m_x1 , m_x2; Chris@16: bool m_current_state_x1; Chris@16: time_type m_t , m_t_old , m_dt; Chris@16: }; Chris@16: Chris@16: Chris@16: Chris@16: } // namespace odeint Chris@16: } // namespace numeric Chris@16: } // namespace boost Chris@16: Chris@16: Chris@16: #endif // BOOST_NUMERIC_ODEINT_STEPPER_ROSENBROCK4_DENSE_OUTPUT_HPP_INCLUDED