File: runge_kutta_controlled_concepts.cpp

package info (click to toggle)
boost1.83 1.83.0-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 545,632 kB
  • sloc: cpp: 3,857,086; xml: 125,552; ansic: 34,414; python: 25,887; asm: 5,276; sh: 4,799; ada: 1,681; makefile: 1,629; perl: 1,212; pascal: 1,139; sql: 810; yacc: 478; ruby: 102; lisp: 24; csh: 6
file content (212 lines) | stat: -rw-r--r-- 7,358 bytes parent folder | download | duplicates (12)
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
/*
 [auto_generated]
 libs/numeric/odeint/test/runge_kutta_controlled_concepts.cpp

 [begin_description]
 This file tests the Stepper concepts of odeint with all Controlled Runge-Kutta steppers. 
 It's one of the main tests of odeint.
 [end_description]

 Copyright 2012 Karsten Ahnert
 Copyright 2012-2013 Mario Mulansky

 Distributed under the Boost Software License, Version 1.0.
 (See accompanying file LICENSE_1_0.txt or
 copy at http://www.boost.org/LICENSE_1_0.txt)
 */

// disable checked iterator warning for msvc
#include <boost/config.hpp>
#ifdef BOOST_MSVC
    #pragma warning(disable:4996)
#endif

#define BOOST_TEST_MODULE odeint_runge_kutta_controlled_concepts

#include <vector>
#include <cmath>
#include <iostream>

#include <boost/numeric/odeint/config.hpp>

#include <boost/array.hpp>

#include <boost/test/unit_test.hpp>

#include <boost/ref.hpp>
#include <boost/bind.hpp>
#include <boost/utility.hpp>
#include <boost/type_traits/add_reference.hpp>

#include <boost/mpl/vector.hpp>
#include <boost/mpl/for_each.hpp>
#include <boost/mpl/insert_range.hpp>
#include <boost/mpl/end.hpp>
#include <boost/mpl/copy.hpp>
#include <boost/mpl/placeholders.hpp>
#include <boost/mpl/inserter.hpp>

#include <boost/numeric/odeint/stepper/runge_kutta_cash_karp54_classic.hpp>
#include <boost/numeric/odeint/stepper/runge_kutta_cash_karp54.hpp>
#include <boost/numeric/odeint/stepper/runge_kutta_dopri5.hpp>
#include <boost/numeric/odeint/stepper/runge_kutta_fehlberg78.hpp>
#include <boost/numeric/odeint/stepper/controlled_runge_kutta.hpp>
#include <boost/numeric/odeint/stepper/bulirsch_stoer.hpp>

#include "prepare_stepper_testing.hpp"
#include "dummy_odes.hpp"

using std::vector;

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

const double result = 2.2; // two steps

const double eps = 1.0e-14;

template< class Stepper , class System >
void check_controlled_stepper_concept( Stepper &stepper , System system , typename Stepper::state_type &x )
{
    typedef Stepper stepper_type;
    typedef typename stepper_type::deriv_type container_type;
    //typedef typename stepper_type::order_type order_type;  controlled_error_stepper don't necessarily have a order (burlish-stoer)
    typedef typename stepper_type::time_type time_type;

    time_type t = 0.0 , dt = 0.1;
    controlled_step_result step_result = stepper.try_step( system , x , t , dt );

    BOOST_CHECK_MESSAGE( step_result == success , "step result: " << step_result ); // error = 0 for constant system -> step size is always too small
}


template< class ControlledStepper , typename T >
struct perform_controlled_stepper_test
{
    typedef T vector_space_type;
    void operator()( void ) const
    {
        using std::abs;
        vector_space_type x;
        x = 2.0;
        ControlledStepper controlled_stepper;
        constant_system_functor_vector_space sys;
#ifndef _MSC_VER
        // dont run this for MSVC due to compiler bug 697006
        check_controlled_stepper_concept( controlled_stepper ,
                                          constant_system_vector_space< vector_space_type , vector_space_type , typename ControlledStepper::time_type >
                                          , x );
#else
        check_controlled_stepper_concept( controlled_stepper , boost::cref( sys ) , x );
#endif
        check_controlled_stepper_concept( controlled_stepper , boost::cref( sys ) , x );
        BOOST_CHECK( (abs( x - result )) < eps );
    }
};

template< class ControlledStepper , typename T >
struct perform_controlled_stepper_test< ControlledStepper , std::vector<T> >
{
    typedef std::vector<T> vector_type;
    void operator()( void )
    {
        using std::abs;
        vector_type x( 1 , 2.0 );
        ControlledStepper controlled_stepper;
        constant_system_functor_standard sys;
#ifndef _MSC_VER
        // dont run this for MSVC due to compiler bug 697006

        check_controlled_stepper_concept( controlled_stepper ,
                                          constant_system_standard< vector_type , vector_type , typename ControlledStepper::time_type > ,
                                          x );
#else
        check_controlled_stepper_concept( controlled_stepper , boost::cref( sys ) , x );
#endif
        check_controlled_stepper_concept( controlled_stepper , boost::cref( sys ) , x );
        BOOST_CHECK( (abs( x[0] - result )) < eps );
    }
};


template< class ControlledStepper >
struct perform_controlled_stepper_test< ControlledStepper , vector_space_type >
{
    void operator()( void ) const
    {
        using std::abs;
        vector_space_type x;
        x = 2.0;
        ControlledStepper controlled_stepper;
        constant_system_functor_vector_space sys;
#ifndef _MSC_VER
        // dont run this for MSVC due to compiler bug 697006
        check_controlled_stepper_concept( controlled_stepper , 
                                          constant_system_vector_space< vector_space_type , vector_space_type , typename ControlledStepper::time_type >
                                          , x );
#else
        check_controlled_stepper_concept( controlled_stepper , boost::cref( sys ) , x );
#endif
        check_controlled_stepper_concept( controlled_stepper , boost::cref( sys ) , x );
        BOOST_CHECK( (abs( x - result )) < eps );
    }
};

template< class ControlledStepper , typename T >
struct perform_controlled_stepper_test< ControlledStepper , boost::array<T,1> >
{
    typedef boost::array<T,1> array_type;
    void operator()( void )
    {
        using std::abs;
        array_type x;
        x[0] = 2.0;
        ControlledStepper controlled_stepper;
        constant_system_functor_standard sys;
#ifndef _MSC_VER
        // dont run this for MSVC due to compiler bug 697006
        check_controlled_stepper_concept( controlled_stepper , constant_system_standard< array_type , array_type , typename ControlledStepper::time_type > , x );
#else
        check_controlled_stepper_concept( controlled_stepper , boost::cref( sys ) , x );
#endif
        check_controlled_stepper_concept( controlled_stepper , boost::cref( sys ) , x );
        BOOST_CHECK( (abs( x[0] - result )) < eps );
    }
};


template< class State > class controlled_stepper_methods : public mpl::vector<
    controlled_runge_kutta< runge_kutta_cash_karp54_classic< State , typename detail::extract_value_type<State>::type > > ,
    controlled_runge_kutta< runge_kutta_dopri5< State , typename detail::extract_value_type<State>::type > > ,
    controlled_runge_kutta< runge_kutta_fehlberg78< State , typename detail::extract_value_type<State>::type > > ,
    bulirsch_stoer< State , typename detail::extract_value_type<State>::type >
    > { };

typedef mpl::copy
<
    container_types ,
    mpl::inserter
    <
        mpl::vector0<> ,
        mpl::insert_range
        <
            mpl::_1 ,
            mpl::end< mpl::_1 > ,
            controlled_stepper_methods< mpl::_2 >
            >
        >
    >::type all_controlled_stepper_methods;




BOOST_AUTO_TEST_SUITE( controlled_runge_kutta_concept_test )

BOOST_AUTO_TEST_CASE_TEMPLATE( controlled_stepper_test , ControlledStepper , all_controlled_stepper_methods )
{
    perform_controlled_stepper_test< ControlledStepper , typename ControlledStepper::state_type > tester;
    tester();
}

BOOST_AUTO_TEST_SUITE_END()