1 /* Boost numeric test of the adams-bashforth-moulton steppers test file
2
3 Copyright 2013 Karsten Ahnert
4 Copyright 2013-2015 Mario Mulansky
5
6 Distributed under the Boost Software License, Version 1.0.
7 (See accompanying file LICENSE_1_0.txt or
8 copy at http://www.boost.org/LICENSE_1_0.txt)
9 */
10
11 // disable checked iterator warning for msvc
12 #include <boost/config.hpp>
13 #ifdef BOOST_MSVC
14 #pragma warning(disable:4996)
15 #endif
16
17 #define BOOST_TEST_MODULE numeric_adams_bashforth_moulton
18
19 #include <iostream>
20 #include <cmath>
21
22 #include <boost/test/unit_test.hpp>
23
24 #include <boost/mpl/vector.hpp>
25
26 #include <boost/numeric/odeint.hpp>
27
28 using namespace boost::unit_test;
29 using namespace boost::numeric::odeint;
30 namespace mpl = boost::mpl;
31
32 typedef double value_type;
33
34 typedef value_type state_type;
35
36
37 // simple time-dependent rhs, analytic solution x = 0.5*t^2
38 struct simple_rhs
39 {
operator ()simple_rhs40 void operator()( const state_type& x , state_type &dxdt , const double t ) const
41 {
42 dxdt = t;
43 }
44 };
45
46 BOOST_AUTO_TEST_SUITE( numeric_abm_time_dependent_test )
47
48
49 /* generic test for all adams bashforth moulton steppers */
50 template< class Stepper >
51 struct perform_abm_time_dependent_test
52 {
operator ()perform_abm_time_dependent_test53 void operator()( void )
54 {
55 Stepper stepper;
56 const int o = stepper.order()+1; //order of the error is order of approximation + 1
57
58 const state_type x0 = 0.0;
59 state_type x1 = x0;
60 double t = 0.0;
61 double dt = 0.1;
62 const int steps = 10;
63
64 integrate_n_steps( boost::ref(stepper) , simple_rhs(), x1 , t , dt , steps );
65 BOOST_CHECK_LT( std::abs( 0.5 - x1 ) , std::pow( dt , o ) );
66 }
67 };
68
69 typedef mpl::vector<
70 adams_bashforth_moulton< 2 , state_type > ,
71 adams_bashforth_moulton< 3 , state_type > ,
72 adams_bashforth_moulton< 4 , state_type > ,
73 adams_bashforth_moulton< 5 , state_type > ,
74 adams_bashforth_moulton< 6 , state_type > ,
75 adams_bashforth_moulton< 7 , state_type > ,
76 adams_bashforth_moulton< 8 , state_type >
77 > adams_bashforth_moulton_steppers;
78
BOOST_AUTO_TEST_CASE_TEMPLATE(abm_time_dependent_test,Stepper,adams_bashforth_moulton_steppers)79 BOOST_AUTO_TEST_CASE_TEMPLATE( abm_time_dependent_test , Stepper, adams_bashforth_moulton_steppers )
80 {
81 perform_abm_time_dependent_test< Stepper > tester;
82 tester();
83 }
84
85 BOOST_AUTO_TEST_SUITE_END()
86