resizing.cpp 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /*
  2. [auto_generated]
  3. libs/numeric/odeint/test/resizing.cpp
  4. [begin_description]
  5. This file tests the resizing mechanism of odeint.
  6. [end_description]
  7. Copyright 2010-2012 Karsten Ahnert
  8. Copyright 2010-2012 Mario Mulansky
  9. Distributed under the Boost Software License, Version 1.0.
  10. (See accompanying file LICENSE_1_0.txt or
  11. copy at http://www.boost.org/LICENSE_1_0.txt)
  12. */
  13. // disable checked iterator warning for msvc
  14. #include <boost/config.hpp>
  15. #ifdef BOOST_MSVC
  16. #pragma warning(disable:4996)
  17. #endif
  18. #define BOOST_TEST_MODULE odeint_resize
  19. #include <vector>
  20. #include <cmath>
  21. #include <boost/array.hpp>
  22. #include <boost/bind.hpp>
  23. #include <boost/utility.hpp>
  24. #include <boost/type_traits/integral_constant.hpp>
  25. #include <boost/test/unit_test.hpp>
  26. #include <boost/mpl/vector.hpp>
  27. #include <boost/mpl/int.hpp>
  28. #include <boost/mpl/at.hpp>
  29. #include <boost/numeric/odeint/stepper/euler.hpp>
  30. #include <boost/numeric/odeint/stepper/runge_kutta4_classic.hpp>
  31. #include <boost/numeric/odeint/stepper/runge_kutta4.hpp>
  32. #include <boost/numeric/odeint/algebra/vector_space_algebra.hpp>
  33. #include <boost/numeric/odeint/util/resizer.hpp>
  34. #include <boost/numeric/odeint/util/is_resizeable.hpp>
  35. #include "resizing_test_state_type.hpp"
  36. using namespace boost::unit_test;
  37. using namespace boost::numeric::odeint;
  38. namespace mpl = boost::mpl;
  39. void constant_system( const test_array_type &x , test_array_type &dxdt , double t ) { dxdt[0] = 1.0; }
  40. BOOST_AUTO_TEST_SUITE( check_resize_test )
  41. typedef euler< test_array_type , double , test_array_type , double , range_algebra , default_operations , never_resizer > euler_manual_type;
  42. typedef euler< test_array_type , double , test_array_type , double , range_algebra , default_operations , initially_resizer > euler_initially_type;
  43. typedef euler< test_array_type , double , test_array_type , double , range_algebra , default_operations , always_resizer > euler_always_type;
  44. typedef runge_kutta4_classic< test_array_type , double , test_array_type , double , range_algebra , default_operations , never_resizer > rk4_manual_type;
  45. typedef runge_kutta4_classic< test_array_type , double , test_array_type , double , range_algebra , default_operations , initially_resizer > rk4_initially_type;
  46. typedef runge_kutta4_classic< test_array_type , double , test_array_type , double , range_algebra , default_operations , always_resizer > rk4_always_type;
  47. typedef runge_kutta4< test_array_type , double , test_array_type , double , range_algebra , default_operations , never_resizer > rk4_gen_manual_type;
  48. typedef runge_kutta4< test_array_type , double , test_array_type , double , range_algebra , default_operations , initially_resizer > rk4_gen_initially_type;
  49. typedef runge_kutta4< test_array_type , double , test_array_type , double , range_algebra , default_operations , always_resizer > rk4_gen_always_type;
  50. typedef mpl::vector<
  51. mpl::vector< euler_manual_type , mpl::int_<1> , mpl::int_<0> > ,
  52. mpl::vector< euler_initially_type , mpl::int_<1> , mpl::int_<1> > ,
  53. mpl::vector< euler_always_type , mpl::int_<1> , mpl::int_<3> > ,
  54. mpl::vector< rk4_manual_type , mpl::int_<5> , mpl::int_<0> > ,
  55. mpl::vector< rk4_initially_type , mpl::int_<5> , mpl::int_<1> > ,
  56. mpl::vector< rk4_always_type , mpl::int_<5> , mpl::int_<3> > ,
  57. mpl::vector< rk4_gen_manual_type , mpl::int_<5> , mpl::int_<0> > ,
  58. mpl::vector< rk4_gen_initially_type , mpl::int_<5> , mpl::int_<1> > ,
  59. mpl::vector< rk4_gen_always_type , mpl::int_<5> , mpl::int_<3> >
  60. >::type resize_check_types;
  61. BOOST_AUTO_TEST_CASE_TEMPLATE( test_resize , T, resize_check_types )
  62. {
  63. typedef typename mpl::at< T , mpl::int_< 0 > >::type stepper_type;
  64. const size_t resize_calls = mpl::at< T , mpl::int_< 1 > >::type::value;
  65. const size_t multiplicity = mpl::at< T , mpl::int_< 2 > >::type::value;
  66. adjust_size_count = 0;
  67. stepper_type stepper;
  68. test_array_type x;
  69. stepper.do_step( constant_system , x , 0.0 , 0.1 );
  70. stepper.do_step( constant_system , x , 0.0 , 0.1 );
  71. stepper.do_step( constant_system , x , 0.0 , 0.1 );
  72. BOOST_TEST_MESSAGE( "adjust_size_count : " << adjust_size_count );
  73. BOOST_CHECK_MESSAGE( adjust_size_count == resize_calls * multiplicity , "adjust_size_count : " << adjust_size_count << " expected: " << resize_calls * multiplicity );
  74. }
  75. BOOST_AUTO_TEST_SUITE_END()