File: adaptive_adams_coefficients.cpp

package info (click to toggle)
boost1.88 1.88.0-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 576,932 kB
  • sloc: cpp: 4,149,234; xml: 136,789; ansic: 35,092; python: 33,910; asm: 5,698; sh: 4,604; ada: 1,681; makefile: 1,633; pascal: 1,139; perl: 1,124; sql: 640; yacc: 478; ruby: 271; java: 77; lisp: 24; csh: 6
file content (120 lines) | stat: -rw-r--r-- 2,903 bytes parent folder | download | duplicates (11)
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
#include <boost/config.hpp>
#ifdef BOOST_MSVC
    #pragma warning(disable:4996)
#endif

#define BOOST_TEST_MODULE odeint_adaptive_adams_coefficients

#include <boost/test/unit_test.hpp>

#include <boost/numeric/odeint/stepper/detail/adaptive_adams_coefficients.hpp>

#include <vector>

#include <boost/mpl/list.hpp>
#include <boost/mpl/size_t.hpp>
#include <boost/mpl/range_c.hpp>

using namespace boost::unit_test;
using namespace boost::numeric::odeint;

typedef double value_type;

BOOST_AUTO_TEST_SUITE( adaptive_adams_coefficients_test )

typedef boost::mpl::range_c< size_t , 2 , 10 > vector_of_steps;
BOOST_AUTO_TEST_CASE_TEMPLATE( test_step, step_type, vector_of_steps )
{
    const static size_t steps = step_type::value;

    typedef std::vector<double> deriv_type;
    typedef double time_type;

    typedef detail::adaptive_adams_coefficients<steps, deriv_type, time_type> aac_type;

    std::vector<double> deriv;
    deriv.push_back(-1);

    time_type t = 0.0;
    time_type dt = 0.1;

    aac_type coeff;
    for(size_t i=0; i<steps; ++i)
    {
        coeff.predict(t, dt);
        coeff.do_step(deriv);
        coeff.confirm();

        t+= dt;

        if(coeff.m_eo < steps)
            coeff.m_eo ++;
    }

    std::vector<value_type> v(10);
    v[0] = 1.0/1.0;
    v[1] = 1.0/2.0;
    v[2] = 5.0/12.0;
    v[3] = 9.0/24.0;
    v[4] = 251.0/720.0;
    v[5] = 95.0/288.0;
    v[6] = 19087.0/60480.0;
    v[7] = 5257.0/17280.0;
    v[8] = 5311869667636789.0/18014398509481984.0;

    for(size_t i=0; i<steps; ++i)
    {
        BOOST_CHECK_SMALL(coeff.beta[1][i] - 1.0, 1e-15);

        if(i == 0)
            BOOST_CHECK_SMALL(coeff.phi[2][i].m_v[0] + 1, 1e-15);
        else if (i == steps-1 && steps%2 == 1)
            BOOST_CHECK_SMALL(coeff.phi[2][i].m_v[0] - 1, 1e-14);
        else if (i == steps-1 && steps%2 == 0)
            BOOST_CHECK_SMALL(coeff.phi[2][i].m_v[0] + 1, 1e-14);
        else
            BOOST_CHECK_SMALL(coeff.phi[2][i].m_v[0], 1e-15);

        BOOST_CHECK_SMALL(coeff.g[i] - v[i], 1e-15);
    }
}

BOOST_AUTO_TEST_CASE( test_copy )
{
    typedef std::vector<double> deriv_type;
    typedef double time_type;

    typedef detail::adaptive_adams_coefficients<3, deriv_type, time_type> aac_type;
    aac_type c1;

    deriv_type deriv(1);
    deriv[0] = 1.0;

    time_type t = 0.0;
    time_type dt = 0.01;

    for(size_t i=0; i<3; ++i)
    {
        c1.predict(t, dt);
        c1.do_step(deriv);
        c1.confirm();

        t+= dt;

        if(c1.m_eo < 3)
            c1.m_eo ++;
    }

    aac_type c2(c1);
    BOOST_CHECK_EQUAL(c1.phi[0][0].m_v[0], c2.phi[0][0].m_v[0]);
    BOOST_CHECK(&(c1.phi[0][0].m_v) != &(c2.phi[0][0].m_v));

    aac_type c3;
    deriv_type *p1 = &(c3.phi[0][0].m_v);

    c3 = c1;
    BOOST_CHECK(p1 == (&(c3.phi[0][0].m_v)));
    BOOST_CHECK_EQUAL(c1.phi[0][0].m_v[0], c3.phi[0][0].m_v[0]);
}

BOOST_AUTO_TEST_SUITE_END()