3 libs/numeric/odeint/test/generic_stepper.cpp
6 This file tests the generic stepper.
9 Copyright 2011 Mario Mulansky
10 Copyright 2012 Karsten Ahnert
12 Distributed under the Boost Software License, Version 1.0.
13 (See accompanying file LICENSE_1_0.txt or
14 copy at http://www.boost.org/LICENSE_1_0.txt)
17 // disable checked iterator warning for msvc
18 #include <boost/config.hpp>
20 #pragma warning(disable:4996)
23 #define BOOST_TEST_MODULE odeint_generic_stepper
28 #include <boost/test/unit_test.hpp>
30 #include <boost/numeric/odeint/stepper/explicit_generic_rk.hpp>
31 #include <boost/numeric/odeint/stepper/runge_kutta4.hpp>
32 #include <boost/numeric/odeint/stepper/runge_kutta4_classic.hpp>
34 #include <boost/array.hpp>
36 using namespace boost::unit_test
;
37 using namespace boost::numeric::odeint
;
39 namespace fusion
= boost::fusion
;
41 typedef double value_type
;
42 typedef boost::array
< value_type
, 2 > state_type
;
44 void sys( const state_type
&x
, state_type
&dxdt
, const value_type
&t
)
46 dxdt
[ 0 ] = x
[ 0 ] + 2 * x
[ 1 ];
50 typedef explicit_generic_rk
< 4 , 4 , state_type
> rk_generic_type
;
51 typedef runge_kutta4
< state_type
> rk4_generic_type
;
53 const boost::array
< double , 1 > a1
= {{ 0.5 }};
54 const boost::array
< double , 2 > a2
= {{ 0.0 , 0.5 }};
55 const boost::array
< double , 3 > a3
= {{ 0.0 , 0.0 , 1.0 }};
57 const rk_generic_type::coef_a_type a
= fusion::make_vector( a1
, a2
, a3
);
58 const rk_generic_type::coef_b_type b
= {{ 1.0/6 , 1.0/3 , 1.0/3 , 1.0/6 }};
59 const rk_generic_type::coef_c_type c
= {{ 0.0 , 0.5 , 0.5 , 1.0 }};
61 typedef runge_kutta4_classic
< state_type
> rk4_type
;
63 BOOST_AUTO_TEST_SUITE( generic_stepper_test
)
65 BOOST_AUTO_TEST_CASE( test_generic_stepper
)
67 //simultaneously test copying
68 rk_generic_type
rk_generic_( a
, b
, c
);
69 rk_generic_type rk_generic
= rk_generic_
;
71 rk4_generic_type rk4_generic_
;
72 rk4_generic_type rk4_generic
= rk4_generic_
;
74 //std::cout << stepper;
79 typedef rk_generic_type::state_type state_type
;
80 typedef rk_generic_type::value_type stepper_value_type
;
81 typedef rk_generic_type::deriv_type deriv_type
;
82 typedef rk_generic_type::time_type time_type
;
84 state_type x
= {{ 0.0 , 1.0 }};
88 rk_generic
.do_step( sys
, x
, 0.0 , 0.1 );
90 rk4_generic
.do_step( sys
, y
, 0.0 , 0.1 );
92 rk4
.do_step( sys
, z
, 0.0 , 0.1 );
94 BOOST_CHECK_NE( 0.0 , x
[0] );
95 BOOST_CHECK_NE( 1.0 , x
[1] );
96 // compare with analytic solution of above system
97 BOOST_CHECK_EQUAL( x
[0] , y
[0] );
98 BOOST_CHECK_EQUAL( x
[1] , y
[1] );
99 BOOST_CHECK_EQUAL( x
[0] , z
[0] );
100 BOOST_CHECK_EQUAL( x
[1] , z
[1] );
104 BOOST_AUTO_TEST_SUITE_END()