]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/numeric/odeint/test/integrate_stepper_refs.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / numeric / odeint / test / integrate_stepper_refs.cpp
1 /*
2 [auto_generated]
3 libs/numeric/odeint/test/integrate_stepper_refs.cpp
4
5 [begin_description]
6 Tests the integrate functions with boost::ref( stepper)
7 [end_description]
8
9 Copyright 2009-2013 Karsten Ahnert
10 Copyright 2009-2013 Mario Mulansky
11
12 Distributed under the Boost Software License, Version 1.0.
13 (See accompanying file LICENSE_1_0.txt or
14 copy at http://www.boost.org/LICENSE_1_0.txt)
15 */
16
17
18 #define BOOST_TEST_MODULE odeint_integrate_stepper_refs
19
20 #include <vector>
21 #include <cmath>
22 #include <iostream>
23
24 #include <boost/numeric/odeint/config.hpp>
25
26 #include <boost/noncopyable.hpp>
27 #include <boost/test/unit_test.hpp>
28 #include <boost/iterator/counting_iterator.hpp>
29
30 #include <boost/mpl/vector.hpp>
31
32 #include <boost/numeric/odeint/integrate/integrate_const.hpp>
33 #include <boost/numeric/odeint/integrate/integrate_adaptive.hpp>
34 #include <boost/numeric/odeint/integrate/integrate_times.hpp>
35 #include <boost/numeric/odeint/integrate/integrate_n_steps.hpp>
36 #include <boost/numeric/odeint/stepper/controlled_step_result.hpp>
37
38
39 using namespace boost::unit_test;
40 using namespace boost::numeric::odeint;
41 namespace mpl = boost::mpl;
42
43 typedef double value_type;
44 typedef std::vector< value_type > state_type;
45
46 // minimal non-copyable basic stepper
47 template<
48 class State
49 >
50 class simple_stepper_nc : boost::noncopyable
51 {
52 public :
53 typedef State state_type;
54 typedef double value_type;
55 typedef state_type deriv_type;
56 typedef double time_type;
57 typedef size_t order_type;
58 typedef stepper_tag stepper_category;
59
60 template< class System >
61 void do_step( System system , state_type &in , time_type t , time_type dt )
62 {
63 // empty
64
65 }
66 };
67
68 // minimal non-copyable controlled stepper
69 template<
70 class State
71 >
72 class controlled_stepper_nc : boost::noncopyable
73 {
74 public :
75 typedef State state_type;
76 typedef double value_type;
77 typedef state_type deriv_type;
78 typedef double time_type;
79 typedef size_t order_type;
80 typedef controlled_stepper_tag stepper_category;
81
82 template< class System >
83 controlled_step_result try_step( System system , state_type &in , time_type &t , time_type &dt )
84 {
85 std::cout << "dense out stepper: " << t << " , " << dt << std::endl;
86 t += dt;
87 return success;
88 }
89 };
90
91 // minimal non-copyable dense_output stepper
92 template<
93 class State
94 >
95 class dense_out_stepper_nc : boost::noncopyable
96 {
97 public :
98 typedef State state_type;
99 typedef double value_type;
100 typedef state_type deriv_type;
101 typedef double time_type;
102 typedef size_t order_type;
103 typedef dense_output_stepper_tag stepper_category;
104
105 void initialize( const state_type &x0 , const time_type t0 , const time_type dt0 )
106 {
107 m_x = x0;
108 m_t = t0;
109 m_dt = dt0;
110 std::cout << "initialize: " << m_t << " , " << m_dt << std::endl;
111 }
112
113 template< class System >
114 void do_step( System system )
115 {
116 std::cout << "dense out stepper: " << m_t << " , " << m_dt << std::endl;
117 m_t += m_dt;
118 }
119
120 void calc_state( const time_type t_inter , state_type &x )
121 {
122 x = m_x;
123 }
124
125 const state_type& current_state() const
126 { return m_x; }
127
128 time_type current_time() const
129 { return m_t; }
130
131 time_type current_time_step() const
132 { return m_dt; }
133
134
135 private :
136 time_type m_t;
137 time_type m_dt;
138 state_type m_x;
139 };
140
141
142 void lorenz( const state_type &x , state_type &dxdt , const value_type t )
143 {
144 //const value_type sigma( 10.0 );
145 const value_type R( 28.0 );
146 const value_type b( value_type( 8.0 ) / value_type( 3.0 ) );
147
148 // first component trivial
149 dxdt[0] = 1.0; //sigma * ( x[1] - x[0] );
150 dxdt[1] = R * x[0] - x[1] - x[0] * x[2];
151 dxdt[2] = -b * x[2] + x[0] * x[1];
152 }
153
154 struct push_back_time
155 {
156 std::vector< double >& m_times;
157
158 state_type& m_x;
159
160 push_back_time( std::vector< double > &times , state_type &x )
161 : m_times( times ) , m_x( x ) { }
162
163 void operator()( const state_type &x , double t )
164 {
165 m_times.push_back( t );
166 boost::numeric::odeint::copy( x , m_x );
167 }
168 };
169
170 template< class Stepper >
171 struct perform_integrate_const_test
172 {
173 void operator()()
174 {
175 state_type x( 3 , 10.0 ) , x_end( 3 );
176
177 std::vector< value_type > times;
178
179 Stepper stepper;
180
181 integrate_const( boost::ref(stepper) , lorenz , x , 0.0 , 1.0 ,
182 0.1, push_back_time( times , x_end ) );
183 }
184 };
185
186 template< class Stepper >
187 struct perform_integrate_adaptive_test
188 {
189 void operator()()
190 {
191 state_type x( 3 , 10.0 ) , x_end( 3 );
192
193 std::vector< value_type > times;
194
195 Stepper stepper;
196
197 integrate_adaptive( boost::ref(stepper) , lorenz , x , 0.0 , 1.0 ,
198 0.1, push_back_time( times , x_end ) );
199 }
200 };
201
202 template< class Stepper >
203 struct perform_integrate_n_steps_test
204 {
205 void operator()()
206 {
207 state_type x( 3 , 10.0 ) , x_end( 3 );
208
209 std::vector< value_type > times;
210
211 Stepper stepper;
212
213 integrate_n_steps( boost::ref(stepper) , lorenz , x , 0.0 , 0.1 ,
214 10 , push_back_time( times , x_end ) );
215 }
216 };
217
218 template< class Stepper >
219 struct perform_integrate_times_test
220 {
221 void operator()()
222 {
223 state_type x( 3 , 10.0 ) , x_end( 3 );
224
225 std::vector< value_type > times;
226
227 Stepper stepper;
228
229 integrate_times( boost::ref(stepper) , lorenz , x ,
230 boost::counting_iterator<int>(0) , boost::counting_iterator<int>(10) , 0.1 ,
231 push_back_time( times , x_end ) );
232 }
233 };
234
235 class stepper_methods : public mpl::vector<
236 simple_stepper_nc< state_type > ,
237 controlled_stepper_nc< state_type >,
238 dense_out_stepper_nc< state_type > > { };
239
240 BOOST_AUTO_TEST_SUITE( integrate_stepper_refs )
241
242 BOOST_AUTO_TEST_CASE_TEMPLATE( integrate_const_test_case , Stepper, stepper_methods )
243 {
244 std::cout << "integrate const" << std::endl;
245 perform_integrate_const_test< Stepper > tester;
246 tester();
247 }
248
249
250 BOOST_AUTO_TEST_CASE_TEMPLATE( integrate_adaptive_test_case , Stepper, stepper_methods )
251 {
252 std::cout << "integrate adaptive" << std::endl;
253 perform_integrate_adaptive_test< Stepper > tester;
254 tester();
255 }
256
257 BOOST_AUTO_TEST_CASE_TEMPLATE( integrate_n_steps_test_case , Stepper, stepper_methods )
258 {
259 std::cout << "integrate n steps" << std::endl;
260 perform_integrate_n_steps_test< Stepper > tester;
261 tester();
262 }
263
264 BOOST_AUTO_TEST_CASE_TEMPLATE( integrate_times_test_case , Stepper, stepper_methods )
265 {
266 std::cout << "integrate times" << std::endl;
267 perform_integrate_times_test< Stepper > tester;
268 tester();
269 }
270
271 BOOST_AUTO_TEST_SUITE_END()