Chris@16: /* Chris@16: [auto_generated] Chris@16: boost/numeric/odeint/stepper/rosenbrock4.hpp Chris@16: Chris@16: [begin_description] Chris@16: Implementation of the Rosenbrock 4 method for solving stiff ODEs. Note, that a Chris@16: controller and a dense-output stepper exist for this method, Chris@16: [end_description] Chris@16: Chris@101: Copyright 2011-2013 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_HPP_INCLUDED Chris@16: #define BOOST_NUMERIC_ODEINT_STEPPER_ROSENBROCK4_HPP_INCLUDED Chris@16: Chris@16: Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: Chris@16: #include Chris@16: Chris@16: #include Chris@16: #include Chris@16: #include Chris@16: Chris@16: #include 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: Chris@16: /* Chris@16: * ToDo: Chris@16: * Chris@16: * 2. Interfacing for odeint, check if controlled_error_stepper can be used Chris@16: * 3. dense output Chris@16: */ Chris@16: Chris@16: Chris@16: Chris@16: template< class Value > Chris@16: struct default_rosenbrock_coefficients Chris@16: { Chris@16: typedef Value value_type; Chris@16: typedef unsigned short order_type; Chris@16: Chris@16: default_rosenbrock_coefficients( void ) Chris@16: : gamma ( static_cast< value_type >( 0.25 ) ) , Chris@16: d1 ( static_cast< value_type >( 0.25 ) ) , Chris@16: d2 ( static_cast< value_type >( -0.1043 ) ) , Chris@16: d3 ( static_cast< value_type >( 0.1035 ) ) , Chris@16: d4 ( static_cast< value_type >( 0.3620000000000023e-01 ) ) , Chris@16: c2 ( static_cast< value_type >( 0.386 ) ) , Chris@16: c3 ( static_cast< value_type >( 0.21 ) ) , Chris@16: c4 ( static_cast< value_type >( 0.63 ) ) , Chris@16: c21 ( static_cast< value_type >( -0.5668800000000000e+01 ) ) , Chris@16: a21 ( static_cast< value_type >( 0.1544000000000000e+01 ) ) , Chris@16: c31 ( static_cast< value_type >( -0.2430093356833875e+01 ) ) , Chris@16: c32 ( static_cast< value_type >( -0.2063599157091915e+00 ) ) , Chris@16: a31 ( static_cast< value_type >( 0.9466785280815826e+00 ) ) , Chris@16: a32 ( static_cast< value_type >( 0.2557011698983284e+00 ) ) , Chris@16: c41 ( static_cast< value_type >( -0.1073529058151375e+00 ) ) , Chris@16: c42 ( static_cast< value_type >( -0.9594562251023355e+01 ) ) , Chris@16: c43 ( static_cast< value_type >( -0.2047028614809616e+02 ) ) , Chris@16: a41 ( static_cast< value_type >( 0.3314825187068521e+01 ) ) , Chris@16: a42 ( static_cast< value_type >( 0.2896124015972201e+01 ) ) , Chris@16: a43 ( static_cast< value_type >( 0.9986419139977817e+00 ) ) , Chris@16: c51 ( static_cast< value_type >( 0.7496443313967647e+01 ) ) , Chris@16: c52 ( static_cast< value_type >( -0.1024680431464352e+02 ) ) , Chris@16: c53 ( static_cast< value_type >( -0.3399990352819905e+02 ) ) , Chris@16: c54 ( static_cast< value_type >( 0.1170890893206160e+02 ) ) , Chris@16: a51 ( static_cast< value_type >( 0.1221224509226641e+01 ) ) , Chris@16: a52 ( static_cast< value_type >( 0.6019134481288629e+01 ) ) , Chris@16: a53 ( static_cast< value_type >( 0.1253708332932087e+02 ) ) , Chris@16: a54 ( static_cast< value_type >( -0.6878860361058950e+00 ) ) , Chris@16: c61 ( static_cast< value_type >( 0.8083246795921522e+01 ) ) , Chris@16: c62 ( static_cast< value_type >( -0.7981132988064893e+01 ) ) , Chris@16: c63 ( static_cast< value_type >( -0.3152159432874371e+02 ) ) , Chris@16: c64 ( static_cast< value_type >( 0.1631930543123136e+02 ) ) , Chris@16: c65 ( static_cast< value_type >( -0.6058818238834054e+01 ) ) , Chris@16: d21 ( static_cast< value_type >( 0.1012623508344586e+02 ) ) , Chris@16: d22 ( static_cast< value_type >( -0.7487995877610167e+01 ) ) , Chris@16: d23 ( static_cast< value_type >( -0.3480091861555747e+02 ) ) , Chris@16: d24 ( static_cast< value_type >( -0.7992771707568823e+01 ) ) , Chris@16: d25 ( static_cast< value_type >( 0.1025137723295662e+01 ) ) , Chris@16: d31 ( static_cast< value_type >( -0.6762803392801253e+00 ) ) , Chris@16: d32 ( static_cast< value_type >( 0.6087714651680015e+01 ) ) , Chris@16: d33 ( static_cast< value_type >( 0.1643084320892478e+02 ) ) , Chris@16: d34 ( static_cast< value_type >( 0.2476722511418386e+02 ) ) , Chris@16: d35 ( static_cast< value_type >( -0.6594389125716872e+01 ) ) Chris@16: {} Chris@16: Chris@16: const value_type gamma; Chris@16: const value_type d1 , d2 , d3 , d4; Chris@16: const value_type c2 , c3 , c4; Chris@16: const value_type c21 ; Chris@16: const value_type a21; Chris@16: const value_type c31 , c32; Chris@16: const value_type a31 , a32; Chris@16: const value_type c41 , c42 , c43; Chris@16: const value_type a41 , a42 , a43; Chris@16: const value_type c51 , c52 , c53 , c54; Chris@16: const value_type a51 , a52 , a53 , a54; Chris@16: const value_type c61 , c62 , c63 , c64 , c65; Chris@16: const value_type d21 , d22 , d23 , d24 , d25; Chris@16: const value_type d31 , d32 , d33 , d34 , d35; Chris@16: Chris@16: static const order_type stepper_order = 4; Chris@16: static const order_type error_order = 3; Chris@16: }; Chris@16: Chris@16: Chris@16: Chris@16: template< class Value , class Coefficients = default_rosenbrock_coefficients< Value > , class Resizer = initially_resizer > Chris@16: class rosenbrock4 Chris@16: { Chris@16: private: Chris@16: Chris@16: public: Chris@16: Chris@16: typedef Value value_type; Chris@16: typedef boost::numeric::ublas::vector< value_type > state_type; Chris@16: typedef state_type deriv_type; Chris@16: typedef value_type time_type; Chris@16: typedef boost::numeric::ublas::matrix< value_type > matrix_type; Chris@16: typedef boost::numeric::ublas::permutation_matrix< size_t > pmatrix_type; Chris@16: typedef Resizer resizer_type; Chris@16: typedef Coefficients rosenbrock_coefficients; Chris@16: typedef stepper_tag stepper_category; Chris@16: typedef unsigned short order_type; Chris@16: Chris@16: typedef state_wrapper< state_type > wrapped_state_type; Chris@16: typedef state_wrapper< deriv_type > wrapped_deriv_type; Chris@16: typedef state_wrapper< matrix_type > wrapped_matrix_type; Chris@16: typedef state_wrapper< pmatrix_type > wrapped_pmatrix_type; Chris@16: Chris@16: typedef rosenbrock4< Value , Coefficients , Resizer > stepper_type; Chris@16: Chris@16: const static order_type stepper_order = rosenbrock_coefficients::stepper_order; Chris@16: const static order_type error_order = rosenbrock_coefficients::error_order; Chris@16: Chris@16: rosenbrock4( void ) Chris@16: : m_resizer() , m_x_err_resizer() , Chris@16: m_jac() , m_pm() , Chris@16: m_dfdt() , m_dxdt() , m_dxdtnew() , Chris@16: m_g1() , m_g2() , m_g3() , m_g4() , m_g5() , Chris@16: m_cont3() , m_cont4() , m_xtmp() , m_x_err() , Chris@16: m_coef() Chris@16: { } Chris@16: Chris@16: Chris@16: order_type order() const { return stepper_order; } Chris@16: Chris@16: template< class System > Chris@16: void do_step( System system , const state_type &x , time_type t , state_type &xout , time_type dt , state_type &xerr ) Chris@16: { Chris@16: // get the system and jacobi function Chris@16: typedef typename odeint::unwrap_reference< System >::type system_type; Chris@16: typedef typename odeint::unwrap_reference< typename system_type::first_type >::type deriv_func_type; Chris@16: typedef typename odeint::unwrap_reference< typename system_type::second_type >::type jacobi_func_type; Chris@16: system_type &sys = system; Chris@16: deriv_func_type &deriv_func = sys.first; Chris@16: jacobi_func_type &jacobi_func = sys.second; Chris@16: Chris@16: const size_t n = x.size(); Chris@16: Chris@16: m_resizer.adjust_size( x , detail::bind( &stepper_type::template resize_impl , detail::ref( *this ) , detail::_1 ) ); Chris@16: Chris@16: for( size_t i=0 ; i( n ); Chris@16: boost::numeric::ublas::lu_factorize( m_jac.m_v , m_pm.m_v ); Chris@16: Chris@16: for( size_t i=0 ; i Chris@16: void do_step( System system , state_type &x , time_type t , time_type dt , state_type &xerr ) Chris@16: { Chris@16: do_step( system , x , t , x , dt , xerr ); Chris@16: } Chris@16: Chris@16: /* Chris@16: * do_step without error output - just calls above functions with and neglects the error estimate Chris@16: */ Chris@16: template< class System > Chris@16: void do_step( System system , const state_type &x , time_type t , state_type &xout , time_type dt ) Chris@16: { Chris@16: m_x_err_resizer.adjust_size( x , detail::bind( &stepper_type::template resize_x_err , detail::ref( *this ) , detail::_1 ) ); Chris@16: do_step( system , x , t , xout , dt , m_x_err.m_v ); Chris@16: } Chris@16: Chris@16: template< class System > Chris@16: void do_step( System system , state_type &x , time_type t , time_type dt ) Chris@16: { Chris@16: m_x_err_resizer.adjust_size( x , detail::bind( &stepper_type::template resize_x_err , detail::ref( *this ) , detail::_1 ) ); Chris@16: do_step( system , x , t , dt , m_x_err.m_v ); Chris@16: } Chris@16: Chris@16: void prepare_dense_output() Chris@16: { Chris@16: const size_t n = m_g1.m_v.size(); Chris@16: for( size_t i=0 ; i Chris@16: void adjust_size( const StateType &x ) Chris@16: { Chris@16: resize_impl( x ); Chris@16: resize_x_err( x ); Chris@16: } Chris@16: Chris@16: Chris@16: protected: 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_dxdt , x , typename is_resizeable::type() ); Chris@16: resized |= adjust_size_by_resizeability( m_dfdt , x , typename is_resizeable::type() ); Chris@16: resized |= adjust_size_by_resizeability( m_dxdtnew , x , typename is_resizeable::type() ); Chris@16: resized |= adjust_size_by_resizeability( m_xtmp , x , typename is_resizeable::type() ); Chris@16: resized |= adjust_size_by_resizeability( m_g1 , x , typename is_resizeable::type() ); Chris@16: resized |= adjust_size_by_resizeability( m_g2 , x , typename is_resizeable::type() ); Chris@16: resized |= adjust_size_by_resizeability( m_g3 , x , typename is_resizeable::type() ); Chris@16: resized |= adjust_size_by_resizeability( m_g4 , x , typename is_resizeable::type() ); Chris@16: resized |= adjust_size_by_resizeability( m_g5 , x , typename is_resizeable::type() ); Chris@16: resized |= adjust_size_by_resizeability( m_cont3 , x , typename is_resizeable::type() ); Chris@16: resized |= adjust_size_by_resizeability( m_cont4 , x , typename is_resizeable::type() ); Chris@16: resized |= adjust_size_by_resizeability( m_jac , x , typename is_resizeable::type() ); Chris@16: resized |= adjust_size_by_resizeability( m_pm , x , typename is_resizeable::type() ); Chris@16: return resized; Chris@16: } Chris@16: Chris@16: template< class StateIn > Chris@16: bool resize_x_err( const StateIn &x ) Chris@16: { Chris@16: return adjust_size_by_resizeability( m_x_err , x , typename is_resizeable::type() ); Chris@16: } Chris@16: Chris@16: private: Chris@16: Chris@16: Chris@16: resizer_type m_resizer; Chris@16: resizer_type m_x_err_resizer; Chris@16: Chris@16: wrapped_matrix_type m_jac; Chris@16: wrapped_pmatrix_type m_pm; Chris@16: wrapped_deriv_type m_dfdt , m_dxdt , m_dxdtnew; Chris@16: wrapped_state_type m_g1 , m_g2 , m_g3 , m_g4 , m_g5; Chris@16: wrapped_state_type m_cont3 , m_cont4; Chris@16: wrapped_state_type m_xtmp; Chris@16: wrapped_state_type m_x_err; Chris@16: Chris@16: const rosenbrock_coefficients m_coef; Chris@16: }; Chris@16: Chris@16: Chris@16: } // namespace odeint Chris@16: } // namespace numeric Chris@16: } // namespace boost Chris@16: Chris@16: #endif // BOOST_NUMERIC_ODEINT_STEPPER_ROSENBROCK4_HPP_INCLUDED