Chris@16
|
1 /*
|
Chris@16
|
2 [auto_generated]
|
Chris@16
|
3 boost/numeric/odeint/stepper/explicit_generic_rk.hpp
|
Chris@16
|
4
|
Chris@16
|
5 [begin_description]
|
Chris@16
|
6 Implementation of the generic Runge-Kutta steppers. This is the base class for many Runge-Kutta steppers.
|
Chris@16
|
7 [end_description]
|
Chris@16
|
8
|
Chris@101
|
9 Copyright 2011-2013 Mario Mulansky
|
Chris@101
|
10 Copyright 2011-2013 Karsten Ahnert
|
Chris@101
|
11 Copyright 2012 Christoph Koke
|
Chris@16
|
12
|
Chris@16
|
13 Distributed under the Boost Software License, Version 1.0.
|
Chris@16
|
14 (See accompanying file LICENSE_1_0.txt or
|
Chris@16
|
15 copy at http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
16 */
|
Chris@16
|
17
|
Chris@16
|
18
|
Chris@16
|
19 #ifndef BOOST_NUMERIC_ODEINT_STEPPER_EXPLICIT_GENERIC_RK_HPP_INCLUDED
|
Chris@16
|
20 #define BOOST_NUMERIC_ODEINT_STEPPER_EXPLICIT_GENERIC_RK_HPP_INCLUDED
|
Chris@16
|
21
|
Chris@16
|
22
|
Chris@16
|
23 #include <boost/array.hpp>
|
Chris@16
|
24
|
Chris@16
|
25
|
Chris@16
|
26 #include <boost/numeric/odeint/stepper/base/explicit_stepper_base.hpp>
|
Chris@16
|
27 #include <boost/numeric/odeint/algebra/range_algebra.hpp>
|
Chris@16
|
28 #include <boost/numeric/odeint/algebra/default_operations.hpp>
|
Chris@101
|
29 #include <boost/numeric/odeint/algebra/algebra_dispatcher.hpp>
|
Chris@101
|
30 #include <boost/numeric/odeint/algebra/operations_dispatcher.hpp>
|
Chris@16
|
31 #include <boost/numeric/odeint/stepper/detail/generic_rk_algorithm.hpp>
|
Chris@16
|
32
|
Chris@16
|
33 #include <boost/numeric/odeint/util/state_wrapper.hpp>
|
Chris@16
|
34 #include <boost/numeric/odeint/util/is_resizeable.hpp>
|
Chris@16
|
35 #include <boost/numeric/odeint/util/resizer.hpp>
|
Chris@16
|
36
|
Chris@16
|
37 namespace boost {
|
Chris@16
|
38 namespace numeric {
|
Chris@16
|
39 namespace odeint {
|
Chris@16
|
40
|
Chris@16
|
41 //forward declarations
|
Chris@16
|
42
|
Chris@16
|
43 #ifndef DOXYGEN_SKIP
|
Chris@16
|
44 template<
|
Chris@16
|
45 size_t StageCount,
|
Chris@16
|
46 size_t Order,
|
Chris@16
|
47 class State ,
|
Chris@16
|
48 class Value = double ,
|
Chris@16
|
49 class Deriv = State ,
|
Chris@16
|
50 class Time = Value ,
|
Chris@101
|
51 class Algebra = typename algebra_dispatcher< State >::algebra_type ,
|
Chris@101
|
52 class Operations = typename operations_dispatcher< State >::operations_type ,
|
Chris@16
|
53 class Resizer = initially_resizer
|
Chris@16
|
54 >
|
Chris@16
|
55 class explicit_generic_rk;
|
Chris@16
|
56
|
Chris@16
|
57
|
Chris@16
|
58 struct stage_vector;
|
Chris@16
|
59
|
Chris@16
|
60 template< class T , class Constant >
|
Chris@16
|
61 struct array_wrapper
|
Chris@16
|
62 {
|
Chris@16
|
63 typedef const typename boost::array< T , Constant::value > type;
|
Chris@16
|
64 };
|
Chris@16
|
65
|
Chris@16
|
66 template< class T , size_t i >
|
Chris@16
|
67 struct stage
|
Chris@16
|
68 {
|
Chris@16
|
69 T c;
|
Chris@16
|
70 boost::array< T , i > a;
|
Chris@16
|
71 };
|
Chris@16
|
72
|
Chris@16
|
73
|
Chris@16
|
74 template< class T , class Constant >
|
Chris@16
|
75 struct stage_wrapper
|
Chris@16
|
76 {
|
Chris@16
|
77 typedef stage< T , Constant::value > type;
|
Chris@16
|
78 };
|
Chris@16
|
79 #endif
|
Chris@16
|
80
|
Chris@16
|
81
|
Chris@16
|
82 template<
|
Chris@16
|
83 size_t StageCount,
|
Chris@16
|
84 size_t Order,
|
Chris@16
|
85 class State ,
|
Chris@16
|
86 class Value ,
|
Chris@16
|
87 class Deriv ,
|
Chris@16
|
88 class Time ,
|
Chris@16
|
89 class Algebra ,
|
Chris@16
|
90 class Operations ,
|
Chris@16
|
91 class Resizer
|
Chris@16
|
92 >
|
Chris@16
|
93 #ifndef DOXYGEN_SKIP
|
Chris@16
|
94 class explicit_generic_rk : public explicit_stepper_base<
|
Chris@16
|
95 explicit_generic_rk< StageCount , Order , State , Value , Deriv , Time , Algebra , Operations , Resizer > ,
|
Chris@16
|
96 Order , State , Value , Deriv , Time , Algebra , Operations , Resizer >
|
Chris@16
|
97 #else
|
Chris@16
|
98 class explicit_generic_rk : public explicit_stepper_base
|
Chris@16
|
99 #endif
|
Chris@16
|
100 {
|
Chris@16
|
101
|
Chris@16
|
102 public:
|
Chris@16
|
103
|
Chris@16
|
104 #ifndef DOXYGEN_SKIP
|
Chris@16
|
105 typedef explicit_stepper_base<
|
Chris@16
|
106 explicit_generic_rk< StageCount , Order , State , Value , Deriv ,Time , Algebra , Operations , Resizer > ,
|
Chris@16
|
107 Order , State , Value , Deriv , Time , Algebra ,
|
Chris@16
|
108 Operations , Resizer > stepper_base_type;
|
Chris@16
|
109 #else
|
Chris@16
|
110 typedef explicit_stepper_base< ... > stepper_base_type;
|
Chris@16
|
111 #endif
|
Chris@16
|
112
|
Chris@16
|
113 typedef typename stepper_base_type::state_type state_type;
|
Chris@16
|
114 typedef typename stepper_base_type::wrapped_state_type wrapped_state_type;
|
Chris@16
|
115 typedef typename stepper_base_type::value_type value_type;
|
Chris@16
|
116 typedef typename stepper_base_type::deriv_type deriv_type;
|
Chris@16
|
117 typedef typename stepper_base_type::wrapped_deriv_type wrapped_deriv_type;
|
Chris@16
|
118 typedef typename stepper_base_type::time_type time_type;
|
Chris@16
|
119 typedef typename stepper_base_type::algebra_type algebra_type;
|
Chris@16
|
120 typedef typename stepper_base_type::operations_type operations_type;
|
Chris@16
|
121 typedef typename stepper_base_type::resizer_type resizer_type;
|
Chris@16
|
122
|
Chris@16
|
123 #ifndef DOXYGEN_SKIP
|
Chris@16
|
124 typedef explicit_generic_rk< StageCount , Order , State , Value , Deriv ,Time , Algebra , Operations , Resizer > stepper_type;
|
Chris@16
|
125 #endif
|
Chris@16
|
126
|
Chris@16
|
127 typedef detail::generic_rk_algorithm< StageCount , Value , Algebra , Operations > rk_algorithm_type;
|
Chris@16
|
128
|
Chris@16
|
129 typedef typename rk_algorithm_type::coef_a_type coef_a_type;
|
Chris@16
|
130 typedef typename rk_algorithm_type::coef_b_type coef_b_type;
|
Chris@16
|
131 typedef typename rk_algorithm_type::coef_c_type coef_c_type;
|
Chris@16
|
132
|
Chris@16
|
133 #ifndef DOXYGEN_SKIP
|
Chris@16
|
134 static const size_t stage_count = StageCount;
|
Chris@16
|
135 #endif
|
Chris@16
|
136
|
Chris@16
|
137 public:
|
Chris@16
|
138
|
Chris@16
|
139 explicit_generic_rk( const coef_a_type &a , const coef_b_type &b , const coef_c_type &c ,
|
Chris@16
|
140 const algebra_type &algebra = algebra_type() )
|
Chris@16
|
141 : stepper_base_type( algebra ) , m_rk_algorithm( a , b , c )
|
Chris@16
|
142 { }
|
Chris@16
|
143
|
Chris@16
|
144
|
Chris@16
|
145 template< class System , class StateIn , class DerivIn , class StateOut >
|
Chris@16
|
146 void do_step_impl( System system , const StateIn &in , const DerivIn &dxdt ,
|
Chris@16
|
147 time_type t , StateOut &out , time_type dt )
|
Chris@16
|
148 {
|
Chris@16
|
149 m_resizer.adjust_size( in , detail::bind( &stepper_type::template resize_impl< StateIn > , detail::ref( *this ) , detail::_1 ) );
|
Chris@16
|
150
|
Chris@16
|
151 // actual calculation done in generic_rk.hpp
|
Chris@16
|
152 m_rk_algorithm.do_step( stepper_base_type::m_algebra , system , in , dxdt , t , out , dt , m_x_tmp.m_v , m_F );
|
Chris@16
|
153 }
|
Chris@16
|
154
|
Chris@16
|
155 template< class StateIn >
|
Chris@16
|
156 void adjust_size( const StateIn &x )
|
Chris@16
|
157 {
|
Chris@16
|
158 resize_impl( x );
|
Chris@16
|
159 stepper_base_type::adjust_size( x );
|
Chris@16
|
160 }
|
Chris@16
|
161
|
Chris@16
|
162 private:
|
Chris@16
|
163
|
Chris@16
|
164 template< class StateIn >
|
Chris@16
|
165 bool resize_impl( const StateIn &x )
|
Chris@16
|
166 {
|
Chris@16
|
167 bool resized( false );
|
Chris@16
|
168 resized |= adjust_size_by_resizeability( m_x_tmp , x , typename is_resizeable<state_type>::type() );
|
Chris@16
|
169 for( size_t i = 0 ; i < StageCount-1 ; ++i )
|
Chris@16
|
170 {
|
Chris@16
|
171 resized |= adjust_size_by_resizeability( m_F[i] , x , typename is_resizeable<deriv_type>::type() );
|
Chris@16
|
172 }
|
Chris@16
|
173 return resized;
|
Chris@16
|
174 }
|
Chris@16
|
175
|
Chris@16
|
176
|
Chris@16
|
177 rk_algorithm_type m_rk_algorithm;
|
Chris@16
|
178
|
Chris@16
|
179 resizer_type m_resizer;
|
Chris@16
|
180
|
Chris@16
|
181 wrapped_state_type m_x_tmp;
|
Chris@16
|
182 wrapped_deriv_type m_F[StageCount-1];
|
Chris@16
|
183
|
Chris@16
|
184 };
|
Chris@16
|
185
|
Chris@16
|
186
|
Chris@16
|
187
|
Chris@16
|
188 /*********** DOXYGEN *************/
|
Chris@16
|
189
|
Chris@16
|
190 /**
|
Chris@16
|
191 * \class explicit_generic_rk
|
Chris@16
|
192 * \brief A generic implementation of explicit Runge-Kutta algorithms. This class is as a base class
|
Chris@16
|
193 * for all explicit Runge-Kutta steppers.
|
Chris@16
|
194 *
|
Chris@16
|
195 * This class implements the explicit Runge-Kutta algorithms without error estimation in a generic way.
|
Chris@16
|
196 * The Butcher tableau is passed to the stepper which constructs the stepper scheme with the help of a
|
Chris@16
|
197 * template-metaprogramming algorithm. ToDo : Add example!
|
Chris@16
|
198 *
|
Chris@16
|
199 * This class derives explicit_stepper_base which provides the stepper interface.
|
Chris@16
|
200 *
|
Chris@16
|
201 * \tparam StageCount The number of stages of the Runge-Kutta algorithm.
|
Chris@16
|
202 * \tparam Order The order of the stepper.
|
Chris@16
|
203 * \tparam State The type representing the state of the ODE.
|
Chris@16
|
204 * \tparam Value The floating point type which is used in the computations.
|
Chris@16
|
205 * \tparam Time The type representing the independent variable - the time - of the ODE.
|
Chris@16
|
206 * \tparam Algebra The algebra type.
|
Chris@16
|
207 * \tparam Operations The operations type.
|
Chris@16
|
208 * \tparam Resizer The resizer policy type.
|
Chris@16
|
209 */
|
Chris@16
|
210
|
Chris@16
|
211 /**
|
Chris@16
|
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 )
|
Chris@16
|
213 * \brief Constructs the explicit_generic_rk class. See examples section for details on the coefficients.
|
Chris@16
|
214 * \param a Triangular matrix of parameters b in the Butcher tableau.
|
Chris@16
|
215 * \param b Last row of the butcher tableau.
|
Chris@16
|
216 * \param c Parameters to calculate the time points in the Butcher tableau.
|
Chris@16
|
217 * \param algebra A copy of algebra is made and stored inside explicit_stepper_base.
|
Chris@16
|
218 */
|
Chris@16
|
219
|
Chris@16
|
220 /**
|
Chris@16
|
221 * \fn explicit_generic_rk::do_step_impl( System system , const StateIn &in , const DerivIn &dxdt , time_type t , StateOut &out , time_type dt )
|
Chris@16
|
222 * \brief This method performs one step. The derivative `dxdt` of `in` at the time `t` is passed to the method.
|
Chris@16
|
223 * The result is updated out of place, hence the input is in `in` and the output in `out`.
|
Chris@16
|
224 * Access to this step functionality is provided by explicit_stepper_base and
|
Chris@16
|
225 * `do_step_impl` should not be called directly.
|
Chris@16
|
226 *
|
Chris@16
|
227 * \param system The system function to solve, hence the r.h.s. of the ODE. It must fulfill the
|
Chris@16
|
228 * Simple System concept.
|
Chris@16
|
229 * \param in The state of the ODE which should be solved. in is not modified in this method
|
Chris@16
|
230 * \param dxdt The derivative of x at t.
|
Chris@16
|
231 * \param t The value of the time, at which the step should be performed.
|
Chris@16
|
232 * \param out The result of the step is written in out.
|
Chris@16
|
233 * \param dt The step size.
|
Chris@16
|
234 */
|
Chris@16
|
235
|
Chris@16
|
236
|
Chris@16
|
237 /**
|
Chris@16
|
238 * \fn explicit_generic_rk::adjust_size( const StateIn &x )
|
Chris@16
|
239 * \brief Adjust the size of all temporaries in the stepper manually.
|
Chris@16
|
240 * \param x A state from which the size of the temporaries to be resized is deduced.
|
Chris@16
|
241 */
|
Chris@16
|
242
|
Chris@16
|
243 }
|
Chris@16
|
244 }
|
Chris@16
|
245 }
|
Chris@16
|
246 #endif // BOOST_NUMERIC_ODEINT_STEPPER_EXPLICIT_GENERIC_RK_HPP_INCLUDED
|