3 libs/numeric/odeint/test/adams_moulton.cpp
6 This file tests the use of the Adams-Moulton stepper.
9 Copyright 2011-2012 Karsten Ahnert
10 Copyright 2011-2012 Mario Mulansky
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_adams_moulton
22 #include <boost/array.hpp>
24 #include <boost/test/unit_test.hpp>
26 #include <boost/mpl/list.hpp>
27 #include <boost/mpl/size_t.hpp>
28 #include <boost/mpl/range_c.hpp>
31 #include <boost/numeric/odeint/stepper/detail/adams_moulton_coefficients.hpp>
32 #include <boost/numeric/odeint/stepper/detail/rotating_buffer.hpp>
33 #include <boost/numeric/odeint/stepper/adams_moulton.hpp>
35 using namespace boost::unit_test;
36 using namespace boost::numeric::odeint;
38 typedef double value_type;
42 template< class State , class Deriv , class Value >
43 void operator()( const State &_x , Deriv &_dxdt , const Value &dt ) const
45 const value_type sigma = 10.0;
46 const value_type R = 28.0;
47 const value_type b = 8.0 / 3.0;
49 typename boost::range_iterator< const State >::type x = boost::begin( _x );
50 typename boost::range_iterator< Deriv >::type dxdt = boost::begin( _dxdt );
52 dxdt[0] = sigma * ( x[1] - x[0] );
53 dxdt[1] = R * x[0] - x[1] - x[0] * x[2];
54 dxdt[2] = x[0]*x[1] - b * x[2];
58 BOOST_AUTO_TEST_SUITE( adams_moulton_test )
60 BOOST_AUTO_TEST_CASE( test_adams_moulton_coefficients )
62 detail::adams_moulton_coefficients< value_type , 1 > c1;
63 detail::adams_moulton_coefficients< value_type , 2 > c2;
64 detail::adams_moulton_coefficients< value_type , 3 > c3;
65 detail::adams_moulton_coefficients< value_type , 4 > c4;
66 detail::adams_moulton_coefficients< value_type , 5 > c5;
67 detail::adams_moulton_coefficients< value_type , 6 > c6;
68 detail::adams_moulton_coefficients< value_type , 7 > c7;
69 detail::adams_moulton_coefficients< value_type , 8 > c8;
72 typedef boost::mpl::range_c< size_t , 1 , 6 > vector_of_steps;
74 BOOST_AUTO_TEST_CASE_TEMPLATE( test_init_and_steps , step_type , vector_of_steps )
76 const static size_t steps = step_type::value;
77 typedef boost::array< value_type , 3 > state_type;
79 adams_moulton< steps , state_type > stepper;
80 // state_type x = {{ 10.0 , 10.0 , 10.0 }};
81 // const value_type dt = 0.01;
82 // value_type t = 0.0;
84 // stepper.do_step( lorenz() , x , t , dt );
87 BOOST_AUTO_TEST_CASE( test_instantiation )
89 typedef boost::array< double , 3 > state_type;
90 adams_moulton< 1 , state_type > s1;
91 adams_moulton< 2 , state_type > s2;
92 adams_moulton< 3 , state_type > s3;
93 adams_moulton< 4 , state_type > s4;
94 adams_moulton< 5 , state_type > s5;
95 adams_moulton< 6 , state_type > s6;
96 adams_moulton< 7 , state_type > s7;
97 adams_moulton< 8 , state_type > s8;
99 // state_type x = {{ 10.0 , 10.0 , 10.0 }};
100 // value_type t = 0.0 , dt = 0.01;
104 BOOST_AUTO_TEST_SUITE_END()