Brian Silverman | 7c33ab2 | 2018-08-04 17:14:51 -0700 | [diff] [blame^] | 1 | /* |
| 2 | [auto_generated] |
| 3 | libs/numeric/odeint/test/resizing.cpp |
| 4 | |
| 5 | [begin_description] |
| 6 | This file tests the resizing mechanism of odeint. |
| 7 | [end_description] |
| 8 | |
| 9 | Copyright 2010-2012 Karsten Ahnert |
| 10 | Copyright 2010-2012 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 | // disable checked iterator warning for msvc |
| 18 | #include <boost/config.hpp> |
| 19 | #ifdef BOOST_MSVC |
| 20 | #pragma warning(disable:4996) |
| 21 | #endif |
| 22 | |
| 23 | #define BOOST_TEST_MODULE odeint_resize |
| 24 | |
| 25 | #include <vector> |
| 26 | #include <cmath> |
| 27 | |
| 28 | #include <boost/array.hpp> |
| 29 | #include <boost/bind.hpp> |
| 30 | #include <boost/utility.hpp> |
| 31 | #include <boost/type_traits/integral_constant.hpp> |
| 32 | |
| 33 | #include <boost/test/unit_test.hpp> |
| 34 | |
| 35 | #include <boost/mpl/vector.hpp> |
| 36 | #include <boost/mpl/int.hpp> |
| 37 | #include <boost/mpl/at.hpp> |
| 38 | |
| 39 | #include <boost/numeric/odeint/stepper/euler.hpp> |
| 40 | #include <boost/numeric/odeint/stepper/runge_kutta4_classic.hpp> |
| 41 | #include <boost/numeric/odeint/stepper/runge_kutta4.hpp> |
| 42 | #include <boost/numeric/odeint/algebra/vector_space_algebra.hpp> |
| 43 | |
| 44 | #include <boost/numeric/odeint/util/resizer.hpp> |
| 45 | #include <boost/numeric/odeint/util/is_resizeable.hpp> |
| 46 | |
| 47 | #include "resizing_test_state_type.hpp" |
| 48 | |
| 49 | using namespace boost::unit_test; |
| 50 | using namespace boost::numeric::odeint; |
| 51 | |
| 52 | namespace mpl = boost::mpl; |
| 53 | |
| 54 | |
| 55 | |
| 56 | |
| 57 | |
| 58 | |
| 59 | void constant_system( const test_array_type &x , test_array_type &dxdt , double t ) { dxdt[0] = 1.0; } |
| 60 | |
| 61 | |
| 62 | BOOST_AUTO_TEST_SUITE( check_resize_test ) |
| 63 | |
| 64 | |
| 65 | typedef euler< test_array_type , double , test_array_type , double , range_algebra , default_operations , never_resizer > euler_manual_type; |
| 66 | typedef euler< test_array_type , double , test_array_type , double , range_algebra , default_operations , initially_resizer > euler_initially_type; |
| 67 | typedef euler< test_array_type , double , test_array_type , double , range_algebra , default_operations , always_resizer > euler_always_type; |
| 68 | |
| 69 | typedef runge_kutta4_classic< test_array_type , double , test_array_type , double , range_algebra , default_operations , never_resizer > rk4_manual_type; |
| 70 | typedef runge_kutta4_classic< test_array_type , double , test_array_type , double , range_algebra , default_operations , initially_resizer > rk4_initially_type; |
| 71 | typedef runge_kutta4_classic< test_array_type , double , test_array_type , double , range_algebra , default_operations , always_resizer > rk4_always_type; |
| 72 | |
| 73 | |
| 74 | typedef runge_kutta4< test_array_type , double , test_array_type , double , range_algebra , default_operations , never_resizer > rk4_gen_manual_type; |
| 75 | typedef runge_kutta4< test_array_type , double , test_array_type , double , range_algebra , default_operations , initially_resizer > rk4_gen_initially_type; |
| 76 | typedef runge_kutta4< test_array_type , double , test_array_type , double , range_algebra , default_operations , always_resizer > rk4_gen_always_type; |
| 77 | |
| 78 | |
| 79 | typedef mpl::vector< |
| 80 | mpl::vector< euler_manual_type , mpl::int_<1> , mpl::int_<0> > , |
| 81 | mpl::vector< euler_initially_type , mpl::int_<1> , mpl::int_<1> > , |
| 82 | mpl::vector< euler_always_type , mpl::int_<1> , mpl::int_<3> > , |
| 83 | mpl::vector< rk4_manual_type , mpl::int_<5> , mpl::int_<0> > , |
| 84 | mpl::vector< rk4_initially_type , mpl::int_<5> , mpl::int_<1> > , |
| 85 | mpl::vector< rk4_always_type , mpl::int_<5> , mpl::int_<3> > , |
| 86 | mpl::vector< rk4_gen_manual_type , mpl::int_<5> , mpl::int_<0> > , |
| 87 | mpl::vector< rk4_gen_initially_type , mpl::int_<5> , mpl::int_<1> > , |
| 88 | mpl::vector< rk4_gen_always_type , mpl::int_<5> , mpl::int_<3> > |
| 89 | >::type resize_check_types; |
| 90 | |
| 91 | |
| 92 | BOOST_AUTO_TEST_CASE_TEMPLATE( test_resize , T, resize_check_types ) |
| 93 | { |
| 94 | typedef typename mpl::at< T , mpl::int_< 0 > >::type stepper_type; |
| 95 | const size_t resize_calls = mpl::at< T , mpl::int_< 1 > >::type::value; |
| 96 | const size_t multiplicity = mpl::at< T , mpl::int_< 2 > >::type::value; |
| 97 | adjust_size_count = 0; |
| 98 | |
| 99 | stepper_type stepper; |
| 100 | test_array_type x; |
| 101 | stepper.do_step( constant_system , x , 0.0 , 0.1 ); |
| 102 | stepper.do_step( constant_system , x , 0.0 , 0.1 ); |
| 103 | stepper.do_step( constant_system , x , 0.0 , 0.1 ); |
| 104 | |
| 105 | BOOST_TEST_MESSAGE( "adjust_size_count : " << adjust_size_count ); |
| 106 | BOOST_CHECK_MESSAGE( adjust_size_count == resize_calls * multiplicity , "adjust_size_count : " << adjust_size_count << " expected: " << resize_calls * multiplicity ); |
| 107 | } |
| 108 | |
| 109 | |
| 110 | BOOST_AUTO_TEST_SUITE_END() |