adams_moulton.cpp 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*
  2. [auto_generated]
  3. libs/numeric/odeint/test/adams_moulton.cpp
  4. [begin_description]
  5. This file tests the use of the Adams-Moulton stepper.
  6. [end_description]
  7. Copyright 2011-2012 Karsten Ahnert
  8. Copyright 2011-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. #define BOOST_TEST_MODULE odeint_adams_moulton
  14. #include <utility>
  15. #include <boost/array.hpp>
  16. #include <boost/test/unit_test.hpp>
  17. #include <boost/mpl/list.hpp>
  18. #include <boost/mpl/size_t.hpp>
  19. #include <boost/mpl/range_c.hpp>
  20. #include <boost/numeric/odeint/stepper/detail/adams_moulton_coefficients.hpp>
  21. #include <boost/numeric/odeint/stepper/detail/rotating_buffer.hpp>
  22. #include <boost/numeric/odeint/stepper/adams_moulton.hpp>
  23. using namespace boost::unit_test;
  24. using namespace boost::numeric::odeint;
  25. typedef double value_type;
  26. struct lorenz
  27. {
  28. template< class State , class Deriv , class Value >
  29. void operator()( const State &_x , Deriv &_dxdt , const Value &dt ) const
  30. {
  31. const value_type sigma = 10.0;
  32. const value_type R = 28.0;
  33. const value_type b = 8.0 / 3.0;
  34. typename boost::range_iterator< const State >::type x = boost::begin( _x );
  35. typename boost::range_iterator< Deriv >::type dxdt = boost::begin( _dxdt );
  36. dxdt[0] = sigma * ( x[1] - x[0] );
  37. dxdt[1] = R * x[0] - x[1] - x[0] * x[2];
  38. dxdt[2] = x[0]*x[1] - b * x[2];
  39. }
  40. };
  41. BOOST_AUTO_TEST_SUITE( adams_moulton_test )
  42. BOOST_AUTO_TEST_CASE( test_adams_moulton_coefficients )
  43. {
  44. detail::adams_moulton_coefficients< value_type , 1 > c1;
  45. detail::adams_moulton_coefficients< value_type , 2 > c2;
  46. detail::adams_moulton_coefficients< value_type , 3 > c3;
  47. detail::adams_moulton_coefficients< value_type , 4 > c4;
  48. detail::adams_moulton_coefficients< value_type , 5 > c5;
  49. detail::adams_moulton_coefficients< value_type , 6 > c6;
  50. detail::adams_moulton_coefficients< value_type , 7 > c7;
  51. detail::adams_moulton_coefficients< value_type , 8 > c8;
  52. }
  53. typedef boost::mpl::range_c< size_t , 1 , 6 > vector_of_steps;
  54. BOOST_AUTO_TEST_CASE_TEMPLATE( test_init_and_steps , step_type , vector_of_steps )
  55. {
  56. const static size_t steps = step_type::value;
  57. typedef boost::array< value_type , 3 > state_type;
  58. adams_moulton< steps , state_type > stepper;
  59. // state_type x = {{ 10.0 , 10.0 , 10.0 }};
  60. // const value_type dt = 0.01;
  61. // value_type t = 0.0;
  62. // stepper.do_step( lorenz() , x , t , dt );
  63. }
  64. BOOST_AUTO_TEST_CASE( test_instantiation )
  65. {
  66. typedef boost::array< double , 3 > state_type;
  67. adams_moulton< 1 , state_type > s1;
  68. adams_moulton< 2 , state_type > s2;
  69. adams_moulton< 3 , state_type > s3;
  70. adams_moulton< 4 , state_type > s4;
  71. adams_moulton< 5 , state_type > s5;
  72. adams_moulton< 6 , state_type > s6;
  73. adams_moulton< 7 , state_type > s7;
  74. adams_moulton< 8 , state_type > s8;
  75. // state_type x = {{ 10.0 , 10.0 , 10.0 }};
  76. // value_type t = 0.0 , dt = 0.01;
  77. }
  78. BOOST_AUTO_TEST_SUITE_END()