]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/numeric/odeint/test/euler_stepper.cpp
3 libs/numeric/odeint/test/euler_stepper.cpp
6 This file tests explicit Euler stepper.
9 Copyright 2011 Mario Mulansky
10 Copyright 2012 Karsten Ahnert
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)
18 #define BOOST_TEST_MODULE odeint_explicit_euler
20 #include <boost/test/unit_test.hpp>
26 #include <boost/numeric/odeint/stepper/euler.hpp>
27 #include <boost/numeric/odeint/algebra/range_algebra.hpp>
29 using namespace boost::unit_test
;
30 using namespace boost::numeric::odeint
;
32 // test with own vector implementation
34 class my_vec
: public std::vector
< double > {
38 my_vec() : std::vector
< double >()
41 my_vec( const my_vec
&x
) : std::vector
< double >( x
)
46 : std::vector
< double >( dim
)
56 struct is_resizeable
< my_vec
>
58 //struct type : public boost::true_type { };
59 typedef boost::true_type type
;
60 const static bool value
= type::value
;
64 typedef double value_type
;
65 //typedef std::vector< value_type > state_type;
66 typedef my_vec state_type
;
68 /* use functors, because functions don't work with msvc 10, I guess this is a bug */
71 void operator()( const state_type
&x
, state_type
&dxdt
, const value_type t
) const
73 std::cout
<< "sys start " << dxdt
.size() << std::endl
;
74 dxdt
[0] = x
[0] + 2 * x
[1];
76 std::cout
<< "sys done" << std::endl
;
81 BOOST_AUTO_TEST_SUITE( explicit_euler_test
)
83 BOOST_AUTO_TEST_CASE( test_euler
)
85 range_algebra algebra
;
86 euler
< state_type
> stepper( algebra
);
88 x
[0] = 0.0; x
[1] = 1.0;
90 std::cout
<< "initialized" << std::endl
;
92 const value_type eps
= 1E-12;
93 const value_type dt
= 0.1;
95 stepper
.do_step( sys() , x
, 0.0 , dt
);
99 // compare with analytic solution of above system
100 BOOST_CHECK_MESSAGE( abs( x
[0] - 2.0*1.0*dt
) < eps
, x
[0] - 2.0*1.0*dt
);
101 BOOST_CHECK_MESSAGE( abs( x
[1] - (1.0 + dt
) ) < eps
, x
[1] - (1.0+dt
) );
105 BOOST_AUTO_TEST_SUITE_END()