]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/numeric/odeint/test/numeric/rosenbrock.cpp
1 /* Boost numeric test of the rosenbrock4 stepper test file
3 Copyright 2012 Karsten Ahnert
4 Copyright 2012 Mario Mulansky
6 Distributed under the Boost Software License, Version 1.0.
7 (See accompanying file LICENSE_1_0.txt or
8 copy at http://www.boost.org/LICENSE_1_0.txt)
11 // disable checked iterator warning for msvc
12 #include <boost/config.hpp>
14 #pragma warning(disable:4996)
17 #define BOOST_TEST_MODULE numeric_rosenbrock
22 #include <boost/array.hpp>
24 #include <boost/test/unit_test.hpp>
26 #include <boost/numeric/odeint/stepper/rosenbrock4.hpp>
27 #include <boost/numeric/ublas/vector.hpp>
28 #include <boost/numeric/ublas/matrix.hpp>
30 using namespace boost::unit_test
;
31 using namespace boost::numeric::odeint
;
33 typedef double value_type
;
34 typedef boost::numeric::ublas::vector
< value_type
> state_type
;
35 typedef boost::numeric::ublas::matrix
< value_type
> matrix_type
;
37 // harmonic oscillator, analytic solution x[0] = sin( t )
40 void operator()( const state_type
&x
, state_type
&dxdt
, const value_type
&t
) const
49 void operator()( const state_type
&x
, matrix_type
&jacobi
, const value_type
&t
, state_type
&dfdt
) const
61 BOOST_AUTO_TEST_SUITE( numeric_rosenbrock4
)
63 BOOST_AUTO_TEST_CASE( rosenbrock4_numeric_test
)
65 typedef rosenbrock4
< value_type
> stepper_type
;
68 const int o
= stepper
.order()+1;
70 state_type
x0( 2 ) , x1( 2 );
71 x0(0) = 0.0; x0(1) = 1.0;
75 stepper
.do_step( std::make_pair( sys() , jacobi() ) , x0
, 0.0 , x1
, dt
);
76 const double f
= 2.0 * std::abs( std::sin(dt
) - x1(0) ) / std::pow( dt
, o
);
78 std::cout
<< o
<< " , " << f
<< std::endl
;
80 while( f
*std::pow( dt
, o
) > 1E-16 )
82 stepper
.do_step( std::make_pair( sys() , jacobi() ) , x0
, 0.0 , x1
, dt
);
83 std::cout
<< "Testing dt=" << dt
<< std::endl
;
84 BOOST_CHECK_SMALL( std::abs( std::sin(dt
) - x1(0) ) , f
*std::pow( dt
, o
) );
89 BOOST_AUTO_TEST_SUITE_END()