• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  [auto_generated]
3  libs/numeric/odeint/test/generic_stepper.cpp
4 
5  [begin_description]
6  This file tests the generic stepper.
7  [end_description]
8 
9  Copyright 2011 Mario Mulansky
10  Copyright 2012 Karsten Ahnert
11 
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)
15  */
16 
17 // disable checked iterator warning for msvc
18 #include <boost/config.hpp>
19 #ifdef BOOST_MSVC
20     #pragma warning(disable:4996)
21 #endif
22 
23 #define BOOST_TEST_MODULE odeint_generic_stepper
24 
25 #include <iostream>
26 #include <utility>
27 
28 #include <boost/test/unit_test.hpp>
29 
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>
33 
34 #include <boost/array.hpp>
35 
36 using namespace boost::unit_test;
37 using namespace boost::numeric::odeint;
38 
39 namespace fusion = boost::fusion;
40 
41 typedef double value_type;
42 typedef boost::array< value_type , 2 > state_type;
43 
sys(const state_type & x,state_type & dxdt,const value_type & t)44 void sys( const state_type &x , state_type &dxdt , const value_type &t )
45 {
46     dxdt[ 0 ] = x[ 0 ] + 2 * x[ 1 ];
47     dxdt[ 1 ] = x[ 1 ];
48 }
49 
50 typedef explicit_generic_rk< 4 , 4 , state_type> rk_generic_type;
51 typedef runge_kutta4< state_type > rk4_generic_type;
52 
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 }};
56 
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 }};
60 
61 typedef runge_kutta4_classic< state_type > rk4_type;
62 
63 BOOST_AUTO_TEST_SUITE( generic_stepper_test )
64 
BOOST_AUTO_TEST_CASE(test_generic_stepper)65 BOOST_AUTO_TEST_CASE( test_generic_stepper )
66 {
67     //simultaneously test copying
68     rk_generic_type rk_generic_( a , b , c );
69     rk_generic_type rk_generic = rk_generic_;
70 
71     rk4_generic_type rk4_generic_;
72     rk4_generic_type rk4_generic = rk4_generic_;
73 
74     //std::cout << stepper;
75 
76     rk4_type rk4_;
77     rk4_type rk4 = rk4_;
78 
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;
83 
84     state_type x = {{ 0.0 , 1.0 }};
85     state_type y = x;
86     state_type z = x;
87 
88     rk_generic.do_step( sys , x , 0.0 , 0.1 );
89 
90     rk4_generic.do_step( sys , y , 0.0 , 0.1 );
91 
92     rk4.do_step( sys , z , 0.0 , 0.1 );
93 
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] );
101 
102 }
103 
104 BOOST_AUTO_TEST_SUITE_END()
105