1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
|
/*
[auto_generated]
libs/numeric/odeint/test/stepper_with_units.cpp
[begin_description]
This file tests if the steppers play well with Boost.Units.
[end_description]
Copyright 2011-2012 Karsten Ahnert
Copyright 2011-2013 Mario Mulansky
Distributed under the Boost Software License, Version 1.0.
(See accompanying file LICENSE_1_0.txt or
copy at http://www.boost.org/LICENSE_1_0.txt)
*/
#define BOOST_TEST_MODULE odeint_stepper_with_units
// the runge-kutta 78 stepper invoked with boost units requires increased fusion macro variables!
// note that by default the rk78 + units test case is disabled as it requires enormous memory when compiling (5 GB)
#define BOOST_FUSION_INVOKE_MAX_ARITY 15
#define BOOST_RESULT_OF_NUM_ARGS 15
#include <boost/numeric/odeint/config.hpp>
#include <boost/test/unit_test.hpp>
#include <boost/units/systems/si/length.hpp>
#include <boost/units/systems/si/time.hpp>
#include <boost/units/systems/si/velocity.hpp>
#include <boost/units/systems/si/acceleration.hpp>
#include <boost/units/systems/si/io.hpp>
#include <boost/fusion/container.hpp>
#include <boost/mpl/vector.hpp>
#include <boost/numeric/odeint/stepper/euler.hpp>
#include <boost/numeric/odeint/stepper/runge_kutta4.hpp>
#include <boost/numeric/odeint/stepper/runge_kutta4_classic.hpp>
#include <boost/numeric/odeint/stepper/runge_kutta_cash_karp54.hpp>
#include <boost/numeric/odeint/stepper/runge_kutta_cash_karp54_classic.hpp>
#include <boost/numeric/odeint/stepper/runge_kutta_dopri5.hpp>
#include <boost/numeric/odeint/stepper/runge_kutta_fehlberg78.hpp>
#include <boost/numeric/odeint/stepper/controlled_runge_kutta.hpp>
#include <boost/numeric/odeint/stepper/dense_output_runge_kutta.hpp>
#include <boost/numeric/odeint/stepper/bulirsch_stoer.hpp>
#include <boost/numeric/odeint/stepper/bulirsch_stoer_dense_out.hpp>
#include <boost/numeric/odeint/algebra/fusion_algebra.hpp>
#include <boost/numeric/odeint/algebra/fusion_algebra_dispatcher.hpp>
using namespace boost::numeric::odeint;
using namespace boost::unit_test;
namespace mpl = boost::mpl;
namespace fusion = boost::fusion;
namespace units = boost::units;
namespace si = boost::units::si;
typedef double value_type;
typedef units::quantity< si::time , value_type > time_type;
typedef units::quantity< si::length , value_type > length_type;
typedef units::quantity< si::velocity , value_type > velocity_type;
typedef units::quantity< si::acceleration , value_type > acceleration_type;
typedef fusion::vector< length_type , velocity_type > state_type;
typedef fusion::vector< velocity_type , acceleration_type > deriv_type;
void oscillator( const state_type &x , deriv_type &dxdt , time_type t )
{
const units::quantity< si::frequency , value_type > omega = 1.0 * si::hertz;
fusion::at_c< 0 >( dxdt ) = fusion::at_c< 1 >( x );
fusion::at_c< 1 >( dxdt ) = - omega * omega * fusion::at_c< 0 >( x );
}
template< class Stepper >
void check_stepper( Stepper &stepper )
{
typedef Stepper stepper_type;
typedef typename stepper_type::state_type state_type;
typedef typename stepper_type::value_type value_type;
typedef typename stepper_type::deriv_type deriv_type;
typedef typename stepper_type::time_type time_type;
typedef typename stepper_type::order_type order_type;
typedef typename stepper_type::algebra_type algebra_type;
typedef typename stepper_type::operations_type operations_type;
const time_type t( 0.0 * si::second );
time_type dt( 0.1 * si::second );
state_type x( 1.0 * si::meter , 0.0 * si::meter_per_second );
// test call method one
stepper.do_step( oscillator , x , t , dt );
// test call method two
stepper.do_step( oscillator , x , t , x , dt );
// test call method three
deriv_type dxdt;
oscillator( x , dxdt , t );
stepper.do_step( oscillator , x , dxdt , t , dt );
// test call method four
oscillator( x , dxdt , t );
stepper.do_step( oscillator , x , dxdt , t , x , dt );
}
template< class Stepper >
void check_fsal_stepper( Stepper &stepper )
{
typedef Stepper stepper_type;
typedef typename stepper_type::state_type state_type;
typedef typename stepper_type::value_type value_type;
typedef typename stepper_type::deriv_type deriv_type;
typedef typename stepper_type::time_type time_type;
typedef typename stepper_type::order_type order_type;
typedef typename stepper_type::algebra_type algebra_type;
typedef typename stepper_type::operations_type operations_type;
const time_type t( 0.0 * si::second );
time_type dt( 0.1 * si::second );
state_type x( 1.0 * si::meter , 0.0 * si::meter_per_second );
// test call method one
stepper.do_step( oscillator , x , t , dt );
// test call method two
stepper.do_step( oscillator , x , t , x , dt );
// test call method three
deriv_type dxdt;
oscillator( x , dxdt , t );
stepper.do_step( oscillator , x , dxdt , t , dt );
// test call method four
stepper.do_step( oscillator , x , dxdt , t , x , dxdt , dt );
}
template< class Stepper >
void check_error_stepper( Stepper &stepper )
{
typedef Stepper stepper_type;
typedef typename stepper_type::state_type state_type;
typedef typename stepper_type::value_type value_type;
typedef typename stepper_type::deriv_type deriv_type;
typedef typename stepper_type::time_type time_type;
typedef typename stepper_type::order_type order_type;
typedef typename stepper_type::algebra_type algebra_type;
typedef typename stepper_type::operations_type operations_type;
const time_type t( 0.0 * si::second );
time_type dt( 0.1 * si::second );
state_type x( 1.0 * si::meter , 0.0 * si::meter_per_second ) , xerr;
// test call method one
stepper.do_step( oscillator , x , t , dt , xerr );
// test call method two
stepper.do_step( oscillator , x , t , x , dt , xerr );
// test call method three
deriv_type dxdt;
oscillator( x , dxdt , t );
stepper.do_step( oscillator , x , dxdt , t , dt , xerr );
// test call method four
stepper.do_step( oscillator , x , dxdt , t , x , dt , xerr );
}
template< class Stepper >
void check_fsal_error_stepper( Stepper &stepper )
{
typedef Stepper stepper_type;
typedef typename stepper_type::state_type state_type;
typedef typename stepper_type::value_type value_type;
typedef typename stepper_type::deriv_type deriv_type;
typedef typename stepper_type::time_type time_type;
typedef typename stepper_type::order_type order_type;
typedef typename stepper_type::algebra_type algebra_type;
typedef typename stepper_type::operations_type operations_type;
const time_type t( 0.0 * si::second );
time_type dt( 0.1 * si::second );
state_type x( 1.0 * si::meter , 0.0 * si::meter_per_second ) , xerr;
// test call method one
stepper.do_step( oscillator , x , t , dt , xerr );
// test call method two
stepper.do_step( oscillator , x , t , x , dt , xerr );
// test call method three
deriv_type dxdt;
oscillator( x , dxdt , t );
stepper.do_step( oscillator , x , dxdt , t , dt , xerr );
// test call method four
stepper.do_step( oscillator , x , dxdt , t , x , dxdt , dt , xerr );
}
template< class Stepper >
void check_controlled_stepper( Stepper &stepper )
{
typedef Stepper stepper_type;
typedef typename stepper_type::state_type state_type;
typedef typename stepper_type::value_type value_type;
typedef typename stepper_type::deriv_type deriv_type;
typedef typename stepper_type::time_type time_type;
time_type t( 0.0 * si::second );
time_type dt( 0.1 * si::second );
state_type x( 1.0 * si::meter , 0.0 * si::meter_per_second );
// test call method one
stepper.try_step( oscillator , x , t , dt );
}
template< class Stepper >
void check_dense_output_stepper( Stepper &stepper )
{
typedef Stepper stepper_type;
typedef typename stepper_type::state_type state_type;
typedef typename stepper_type::value_type value_type;
typedef typename stepper_type::deriv_type deriv_type;
typedef typename stepper_type::time_type time_type;
// typedef typename stepper_type::order_type order_type;
time_type t( 0.0 * si::second );
time_type dt( 0.1 * si::second );
state_type x( 1.0 * si::meter , 0.0 * si::meter_per_second ) , x2;
stepper.initialize( x , t , dt );
stepper.do_step( oscillator );
stepper.calc_state( dt / 2.0 , x2 );
}
class stepper_types : public mpl::vector
<
euler< state_type , value_type , deriv_type , time_type >,
runge_kutta4< state_type , value_type , deriv_type , time_type > ,
runge_kutta4_classic< state_type , value_type , deriv_type , time_type > ,
runge_kutta_cash_karp54< state_type , value_type , deriv_type , time_type >,
runge_kutta_cash_karp54_classic< state_type , value_type , deriv_type , time_type >
// don't run rk78 test - gcc requires > 5GB RAM to compile this
//, runge_kutta_fehlberg78< state_type , value_type , deriv_type , time_type >
> { };
class fsal_stepper_types : public mpl::vector
<
runge_kutta_dopri5< state_type , value_type , deriv_type , time_type >
> { };
class error_stepper_types : public mpl::vector
<
runge_kutta_cash_karp54_classic< state_type , value_type , deriv_type , time_type >
//, runge_kutta_fehlberg78< state_type , value_type , deriv_type , time_type >
> { };
class fsal_error_stepper_types : public mpl::vector
<
runge_kutta_dopri5< state_type , value_type , deriv_type , time_type >
> { };
class controlled_stepper_types : public mpl::vector
<
controlled_runge_kutta< runge_kutta_cash_karp54_classic< state_type , value_type , deriv_type , time_type > > ,
controlled_runge_kutta< runge_kutta_dopri5< state_type , value_type , deriv_type , time_type > >
, bulirsch_stoer< state_type , value_type , deriv_type , time_type >
// rk78 with units needs up to 3GB memory to compile - disable testing...
//, controlled_runge_kutta< runge_kutta_fehlberg78< state_type , value_type , deriv_type , time_type > >
> { };
class dense_output_stepper_types : public mpl::vector
<
dense_output_runge_kutta< euler< state_type , value_type , deriv_type , time_type > > ,
dense_output_runge_kutta<
controlled_runge_kutta< runge_kutta_dopri5< state_type , value_type , deriv_type , time_type > > >
//, bulirsch_stoer_dense_out< state_type , value_type , deriv_type , time_type >
> { };
BOOST_AUTO_TEST_SUITE( stepper_with_units )
BOOST_AUTO_TEST_CASE_TEMPLATE( stepper_test , Stepper , stepper_types )
{
Stepper stepper;
check_stepper( stepper );
}
BOOST_AUTO_TEST_CASE_TEMPLATE( fsl_stepper_test , Stepper , fsal_stepper_types )
{
Stepper stepper;
check_fsal_stepper( stepper );
}
BOOST_AUTO_TEST_CASE_TEMPLATE( error_stepper_test , Stepper , error_stepper_types )
{
Stepper stepper;
check_error_stepper( stepper );
}
BOOST_AUTO_TEST_CASE_TEMPLATE( fsal_error_stepper_test , Stepper , fsal_error_stepper_types )
{
Stepper stepper;
check_fsal_error_stepper( stepper );
}
BOOST_AUTO_TEST_CASE_TEMPLATE( controlled_stepper_test , Stepper , controlled_stepper_types )
{
Stepper stepper;
check_controlled_stepper( stepper );
}
BOOST_AUTO_TEST_CASE_TEMPLATE( dense_ouput_test , Stepper , dense_output_stepper_types )
{
Stepper stepper;
check_dense_output_stepper( stepper );
}
BOOST_AUTO_TEST_SUITE_END()
|