]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/numeric/odeint/test/runge_kutta_concepts.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / numeric / odeint / test / runge_kutta_concepts.cpp
1 /*
2 [auto_generated]
3 libs/numeric/odeint/test/runge_kutta_concepts.cpp
4
5 [begin_description]
6 This file tests the Stepper concepts of odeint with all Runge-Kutta steppers. It's one of the main tests
7 of odeint.
8 [end_description]
9
10 Copyright 2012 Karsten Ahnert
11 Copyright 2012-2013 Mario Mulansky
12
13 Distributed under the Boost Software License, Version 1.0.
14 (See accompanying file LICENSE_1_0.txt or
15 copy at http://www.boost.org/LICENSE_1_0.txt)
16 */
17
18 // disable checked iterator warning for msvc
19 #include <boost/config.hpp>
20 #ifdef BOOST_MSVC
21 #pragma warning(disable:4996)
22 #endif
23
24 #define BOOST_TEST_MODULE odeint_runge_kutta_concepts
25
26 #include <vector>
27 #include <cmath>
28 #include <iostream>
29
30 #include <boost/numeric/odeint/config.hpp>
31
32 #include <boost/array.hpp>
33
34 #include <boost/test/unit_test.hpp>
35
36 #include <boost/ref.hpp>
37 #include <boost/bind.hpp>
38 #include <boost/utility.hpp>
39 #include <boost/type_traits/add_reference.hpp>
40
41 #include <boost/mpl/vector.hpp>
42 #include <boost/mpl/for_each.hpp>
43 #include <boost/mpl/insert_range.hpp>
44 #include <boost/mpl/end.hpp>
45 #include <boost/mpl/copy.hpp>
46 #include <boost/mpl/placeholders.hpp>
47 #include <boost/mpl/inserter.hpp>
48
49 #include <boost/numeric/odeint/stepper/euler.hpp>
50 #include <boost/numeric/odeint/stepper/modified_midpoint.hpp>
51 #include <boost/numeric/odeint/stepper/runge_kutta4_classic.hpp>
52 #include <boost/numeric/odeint/stepper/runge_kutta4.hpp>
53 #include <boost/numeric/odeint/stepper/runge_kutta_cash_karp54_classic.hpp>
54 #include <boost/numeric/odeint/stepper/runge_kutta_cash_karp54.hpp>
55 #include <boost/numeric/odeint/stepper/runge_kutta_dopri5.hpp>
56 #include <boost/numeric/odeint/stepper/runge_kutta_fehlberg78.hpp>
57
58 #include <boost/numeric/odeint/algebra/detail/extract_value_type.hpp>
59
60 #include "prepare_stepper_testing.hpp"
61 #include "dummy_odes.hpp"
62
63 using std::vector;
64
65 using namespace boost::unit_test;
66 using namespace boost::numeric::odeint;
67 namespace mpl = boost::mpl;
68
69 const double result = 2.2;
70
71 const double eps = 1.0e-14;
72
73 template< class Stepper , class System >
74 void check_stepper_concept( Stepper &stepper , System system , typename Stepper::state_type &x )
75 {
76 typedef Stepper stepper_type;
77 typedef typename stepper_type::deriv_type container_type;
78 typedef typename stepper_type::order_type order_type;
79 typedef typename stepper_type::time_type time_type;
80
81 stepper.do_step( system , x , static_cast<time_type>(0.0) , static_cast<time_type>(0.1) );
82 }
83
84 // default case is used for vector space types like plain double
85 template< class Stepper , typename T >
86 struct perform_stepper_test
87 {
88 typedef T vector_space_type;
89 void operator()( void ) const
90 {
91 vector_space_type x;
92 x = 2.0;
93 Stepper stepper;
94 constant_system_functor_vector_space sys;
95 #ifndef _MSC_VER
96 // dont run this for MSVC due to compiler bug 697006
97 check_stepper_concept( stepper , constant_system_vector_space< vector_space_type , vector_space_type , typename Stepper::time_type > , x );
98 #else
99 check_stepper_concept( stepper , boost::cref( sys ) , x );
100 #endif
101 check_stepper_concept( stepper , boost::cref( sys ) , x );
102 std::cout << x << " ?= " << result << std::endl;
103 BOOST_CHECK( (abs( x - result )) < eps );
104 }
105 };
106
107 template< class Stepper , typename T >
108 struct perform_stepper_test< Stepper , std::vector<T> >
109 {
110 typedef std::vector<T> vector_type;
111 void operator()( void )
112 {
113 using std::abs;
114 vector_type x( 1 , static_cast<T>(2.0) );
115 Stepper stepper;
116 constant_system_functor_standard sys;
117 #ifndef _MSC_VER
118 // dont run this for MSVC due to compiler bug 697006
119 check_stepper_concept( stepper , constant_system_standard< vector_type , vector_type , typename Stepper::time_type > , x );
120 #else
121 check_stepper_concept( stepper , boost::cref( sys ) , x );
122 #endif
123 check_stepper_concept( stepper , boost::cref( sys ) , x );
124 std::cout << x[0] << " ?= " << result << std::endl;
125 BOOST_CHECK( (abs( x[0] - result )) < eps );
126 }
127 };
128
129 template< class Stepper , typename T >
130 struct perform_stepper_test< Stepper , boost::array<T,1> >
131 {
132 typedef boost::array<T,1> array_type;
133 void operator()( void )
134 {
135 using std::abs;
136 array_type x;
137 x[0] = static_cast<T>(2.0);
138 Stepper stepper;
139 constant_system_functor_standard sys;
140 #ifndef _MSC_VER
141 // dont run this for MSVC due to compiler bug 697006
142 check_stepper_concept( stepper , constant_system_standard< array_type , array_type , typename Stepper::time_type > , x );
143 #else
144 check_stepper_concept( stepper , boost::cref( sys ) , x );
145 #endif
146 check_stepper_concept( stepper , boost::cref( sys ) , x );
147 std::cout << x[0] << " ?= " << result << std::endl;
148 BOOST_CHECK( (abs( x[0] - result )) < eps );
149 }
150 };
151
152 // split stepper methods to ensure the final vector has less than 30(?) elements
153 // (stepper_methods*container_types) < 30(?)
154 template< class State > class stepper_methods1 : public mpl::vector<
155 euler< State , typename detail::extract_value_type<State>::type > ,
156 modified_midpoint< State , typename detail::extract_value_type<State>::type > ,
157 runge_kutta4< State , typename detail::extract_value_type<State>::type > ,
158 runge_kutta4_classic< State , typename detail::extract_value_type<State>::type >
159 > { };
160
161 template< class State > class stepper_methods2 : public mpl::vector<
162 runge_kutta_cash_karp54_classic< State , typename detail::extract_value_type<State>::type > ,
163 runge_kutta_cash_karp54< State , typename detail::extract_value_type<State>::type > ,
164 runge_kutta_dopri5< State , typename detail::extract_value_type<State>::type > ,
165 runge_kutta_fehlberg78< State , typename detail::extract_value_type<State>::type >
166 > { };
167
168
169
170 typedef mpl::copy
171 <
172 container_types ,
173 mpl::inserter
174 <
175 mpl::vector0<> ,
176 mpl::insert_range
177 <
178 mpl::_1 ,
179 mpl::end< mpl::_1 > ,
180 stepper_methods1< mpl::_2 >
181 >
182 >
183 >::type stepper_combinations1;
184
185 typedef mpl::copy
186 <
187 container_types ,
188 mpl::inserter
189 <
190 mpl::vector0<> ,
191 mpl::insert_range
192 <
193 mpl::_1 ,
194 mpl::end< mpl::_1 > ,
195 stepper_methods2< mpl::_2 >
196 >
197 >
198 >::type stepper_combinations2;
199
200
201 BOOST_AUTO_TEST_SUITE( runge_kutta_concept_test )
202
203 BOOST_AUTO_TEST_CASE_TEMPLATE( stepper_test1 , Stepper, stepper_combinations1 )
204 {
205 perform_stepper_test< Stepper , typename Stepper::deriv_type > tester;
206 tester();
207 }
208
209 BOOST_AUTO_TEST_CASE_TEMPLATE( stepper_test2 , Stepper, stepper_combinations2 )
210 {
211 perform_stepper_test< Stepper , typename Stepper::deriv_type > tester;
212 tester();
213 }
214
215
216 BOOST_AUTO_TEST_SUITE_END()