3 boost/numeric/odeint/stepper/explicit_generic_rk.hpp
6 Implementation of the generic Runge-Kutta steppers. This is the base class for many Runge-Kutta steppers.
9 Copyright 2011-2013 Mario Mulansky
10 Copyright 2011-2013 Karsten Ahnert
11 Copyright 2012 Christoph Koke
13 Distributed under the Boost Software License, Version 1.0.
14 (See accompanying file LICENSE_1_0.txt or
15 copy at http://www.boost.org/LICENSE_1_0.txt)
19 #ifndef BOOST_NUMERIC_ODEINT_STEPPER_EXPLICIT_GENERIC_RK_HPP_INCLUDED
20 #define BOOST_NUMERIC_ODEINT_STEPPER_EXPLICIT_GENERIC_RK_HPP_INCLUDED
23 #include <boost/array.hpp>
26 #include <boost/numeric/odeint/stepper/base/explicit_stepper_base.hpp>
27 #include <boost/numeric/odeint/algebra/range_algebra.hpp>
28 #include <boost/numeric/odeint/algebra/default_operations.hpp>
29 #include <boost/numeric/odeint/algebra/algebra_dispatcher.hpp>
30 #include <boost/numeric/odeint/algebra/operations_dispatcher.hpp>
31 #include <boost/numeric/odeint/stepper/detail/generic_rk_algorithm.hpp>
33 #include <boost/numeric/odeint/util/state_wrapper.hpp>
34 #include <boost/numeric/odeint/util/is_resizeable.hpp>
35 #include <boost/numeric/odeint/util/resizer.hpp>
41 //forward declarations
48 class Value = double ,
51 class Algebra = typename algebra_dispatcher< State >::algebra_type ,
52 class Operations = typename operations_dispatcher< State >::operations_type ,
53 class Resizer = initially_resizer
55 class explicit_generic_rk;
60 template< class T , class Constant >
63 typedef const typename boost::array< T , Constant::value > type;
66 template< class T , size_t i >
70 boost::array< T , i > a;
74 template< class T , class Constant >
77 typedef stage< T , Constant::value > type;
94 class explicit_generic_rk : public explicit_stepper_base<
95 explicit_generic_rk< StageCount , Order , State , Value , Deriv , Time , Algebra , Operations , Resizer > ,
96 Order , State , Value , Deriv , Time , Algebra , Operations , Resizer >
98 class explicit_generic_rk : public explicit_stepper_base
105 typedef explicit_stepper_base<
106 explicit_generic_rk< StageCount , Order , State , Value , Deriv ,Time , Algebra , Operations , Resizer > ,
107 Order , State , Value , Deriv , Time , Algebra ,
108 Operations , Resizer > stepper_base_type;
110 typedef explicit_stepper_base< ... > stepper_base_type;
113 typedef typename stepper_base_type::state_type state_type;
114 typedef typename stepper_base_type::wrapped_state_type wrapped_state_type;
115 typedef typename stepper_base_type::value_type value_type;
116 typedef typename stepper_base_type::deriv_type deriv_type;
117 typedef typename stepper_base_type::wrapped_deriv_type wrapped_deriv_type;
118 typedef typename stepper_base_type::time_type time_type;
119 typedef typename stepper_base_type::algebra_type algebra_type;
120 typedef typename stepper_base_type::operations_type operations_type;
121 typedef typename stepper_base_type::resizer_type resizer_type;
124 typedef explicit_generic_rk< StageCount , Order , State , Value , Deriv ,Time , Algebra , Operations , Resizer > stepper_type;
127 typedef detail::generic_rk_algorithm< StageCount , Value , Algebra , Operations > rk_algorithm_type;
129 typedef typename rk_algorithm_type::coef_a_type coef_a_type;
130 typedef typename rk_algorithm_type::coef_b_type coef_b_type;
131 typedef typename rk_algorithm_type::coef_c_type coef_c_type;
134 static const size_t stage_count = StageCount;
139 explicit_generic_rk( const coef_a_type &a , const coef_b_type &b , const coef_c_type &c ,
140 const algebra_type &algebra = algebra_type() )
141 : stepper_base_type( algebra ) , m_rk_algorithm( a , b , c )
145 template< class System , class StateIn , class DerivIn , class StateOut >
146 void do_step_impl( System system , const StateIn &in , const DerivIn &dxdt ,
147 time_type t , StateOut &out , time_type dt )
149 m_resizer.adjust_size( in , detail::bind( &stepper_type::template resize_impl< StateIn > , detail::ref( *this ) , detail::_1 ) );
151 // actual calculation done in generic_rk.hpp
152 m_rk_algorithm.do_step( stepper_base_type::m_algebra , system , in , dxdt , t , out , dt , m_x_tmp.m_v , m_F );
155 template< class StateIn >
156 void adjust_size( const StateIn &x )
159 stepper_base_type::adjust_size( x );
164 template< class StateIn >
165 bool resize_impl( const StateIn &x )
167 bool resized( false );
168 resized |= adjust_size_by_resizeability( m_x_tmp , x , typename is_resizeable<state_type>::type() );
169 for( size_t i = 0 ; i < StageCount-1 ; ++i )
171 resized |= adjust_size_by_resizeability( m_F[i] , x , typename is_resizeable<deriv_type>::type() );
177 rk_algorithm_type m_rk_algorithm;
179 resizer_type m_resizer;
181 wrapped_state_type m_x_tmp;
182 wrapped_deriv_type m_F[StageCount-1];
188 /*********** DOXYGEN *************/
191 * \class explicit_generic_rk
192 * \brief A generic implementation of explicit Runge-Kutta algorithms. This class is as a base class
193 * for all explicit Runge-Kutta steppers.
195 * This class implements the explicit Runge-Kutta algorithms without error estimation in a generic way.
196 * The Butcher tableau is passed to the stepper which constructs the stepper scheme with the help of a
197 * template-metaprogramming algorithm. ToDo : Add example!
199 * This class derives explicit_stepper_base which provides the stepper interface.
201 * \tparam StageCount The number of stages of the Runge-Kutta algorithm.
202 * \tparam Order The order of the stepper.
203 * \tparam State The type representing the state of the ODE.
204 * \tparam Value The floating point type which is used in the computations.
205 * \tparam Time The type representing the independent variable - the time - of the ODE.
206 * \tparam Algebra The algebra type.
207 * \tparam Operations The operations type.
208 * \tparam Resizer The resizer policy type.
212 * \fn explicit_generic_rk::explicit_generic_rk( const coef_a_type &a , const coef_b_type &b , const coef_c_type &c , const algebra_type &algebra )
213 * \brief Constructs the explicit_generic_rk class. See examples section for details on the coefficients.
214 * \param a Triangular matrix of parameters b in the Butcher tableau.
215 * \param b Last row of the butcher tableau.
216 * \param c Parameters to calculate the time points in the Butcher tableau.
217 * \param algebra A copy of algebra is made and stored inside explicit_stepper_base.
221 * \fn explicit_generic_rk::do_step_impl( System system , const StateIn &in , const DerivIn &dxdt , time_type t , StateOut &out , time_type dt )
222 * \brief This method performs one step. The derivative `dxdt` of `in` at the time `t` is passed to the method.
223 * The result is updated out of place, hence the input is in `in` and the output in `out`.
224 * Access to this step functionality is provided by explicit_stepper_base and
225 * `do_step_impl` should not be called directly.
227 * \param system The system function to solve, hence the r.h.s. of the ODE. It must fulfill the
228 * Simple System concept.
229 * \param in The state of the ODE which should be solved. in is not modified in this method
230 * \param dxdt The derivative of x at t.
231 * \param t The value of the time, at which the step should be performed.
232 * \param out The result of the step is written in out.
233 * \param dt The step size.
238 * \fn explicit_generic_rk::adjust_size( const StateIn &x )
239 * \brief Adjust the size of all temporaries in the stepper manually.
240 * \param x A state from which the size of the temporaries to be resized is deduced.
246 #endif // BOOST_NUMERIC_ODEINT_STEPPER_EXPLICIT_GENERIC_RK_HPP_INCLUDED