• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include <boost/config.hpp>
2 #ifdef BOOST_MSVC
3     #pragma warning(disable:4996)
4 #endif
5 
6 #define BOOST_TEST_MODULE odeint_adaptive_adams_coefficients
7 
8 #include <boost/test/unit_test.hpp>
9 
10 #include <boost/numeric/odeint/stepper/detail/adaptive_adams_coefficients.hpp>
11 
12 #include <vector>
13 
14 #include <boost/mpl/list.hpp>
15 #include <boost/mpl/size_t.hpp>
16 #include <boost/mpl/range_c.hpp>
17 
18 using namespace boost::unit_test;
19 using namespace boost::numeric::odeint;
20 
21 typedef double value_type;
22 
23 BOOST_AUTO_TEST_SUITE( adaptive_adams_coefficients_test )
24 
25 typedef boost::mpl::range_c< size_t , 2 , 10 > vector_of_steps;
BOOST_AUTO_TEST_CASE_TEMPLATE(test_step,step_type,vector_of_steps)26 BOOST_AUTO_TEST_CASE_TEMPLATE( test_step, step_type, vector_of_steps )
27 {
28     const static size_t steps = step_type::value;
29 
30     typedef std::vector<double> deriv_type;
31     typedef double time_type;
32 
33     typedef detail::adaptive_adams_coefficients<steps, deriv_type, time_type> aac_type;
34 
35     std::vector<double> deriv;
36     deriv.push_back(-1);
37 
38     time_type t = 0.0;
39     time_type dt = 0.1;
40 
41     aac_type coeff;
42     for(size_t i=0; i<steps; ++i)
43     {
44         coeff.predict(t, dt);
45         coeff.do_step(deriv);
46         coeff.confirm();
47 
48         t+= dt;
49 
50         if(coeff.m_eo < steps)
51             coeff.m_eo ++;
52     }
53 
54     std::vector<value_type> v(10);
55     v[0] = 1.0/1.0;
56     v[1] = 1.0/2.0;
57     v[2] = 5.0/12.0;
58     v[3] = 9.0/24.0;
59     v[4] = 251.0/720.0;
60     v[5] = 95.0/288.0;
61     v[6] = 19087.0/60480.0;
62     v[7] = 5257.0/17280.0;
63     v[8] = 5311869667636789.0/18014398509481984.0;
64 
65     for(size_t i=0; i<steps; ++i)
66     {
67         BOOST_CHECK_SMALL(coeff.beta[1][i] - 1.0, 1e-15);
68 
69         if(i == 0)
70             BOOST_CHECK_SMALL(coeff.phi[2][i].m_v[0] + 1, 1e-15);
71         else if (i == steps-1 && steps%2 == 1)
72             BOOST_CHECK_SMALL(coeff.phi[2][i].m_v[0] - 1, 1e-14);
73         else if (i == steps-1 && steps%2 == 0)
74             BOOST_CHECK_SMALL(coeff.phi[2][i].m_v[0] + 1, 1e-14);
75         else
76             BOOST_CHECK_SMALL(coeff.phi[2][i].m_v[0], 1e-15);
77 
78         BOOST_CHECK_SMALL(coeff.g[i] - v[i], 1e-15);
79     }
80 }
81 
BOOST_AUTO_TEST_CASE(test_copy)82 BOOST_AUTO_TEST_CASE( test_copy )
83 {
84     typedef std::vector<double> deriv_type;
85     typedef double time_type;
86 
87     typedef detail::adaptive_adams_coefficients<3, deriv_type, time_type> aac_type;
88     aac_type c1;
89 
90     deriv_type deriv(1);
91     deriv[0] = 1.0;
92 
93     time_type t = 0.0;
94     time_type dt = 0.01;
95 
96     for(size_t i=0; i<3; ++i)
97     {
98         c1.predict(t, dt);
99         c1.do_step(deriv);
100         c1.confirm();
101 
102         t+= dt;
103 
104         if(c1.m_eo < 3)
105             c1.m_eo ++;
106     }
107 
108     aac_type c2(c1);
109     BOOST_CHECK_EQUAL(c1.phi[0][0].m_v[0], c2.phi[0][0].m_v[0]);
110     BOOST_CHECK(&(c1.phi[0][0].m_v) != &(c2.phi[0][0].m_v));
111 
112     aac_type c3;
113     deriv_type *p1 = &(c3.phi[0][0].m_v);
114 
115     c3 = c1;
116     BOOST_CHECK(p1 == (&(c3.phi[0][0].m_v)));
117     BOOST_CHECK_EQUAL(c1.phi[0][0].m_v[0], c3.phi[0][0].m_v[0]);
118 }
119 
120 BOOST_AUTO_TEST_SUITE_END()