runge_kutta_dopri5.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /*
  2. [auto_generated]
  3. libs/numeric/odeint/test_external/eigen/runge_kutta_dopri5.cpp
  4. [begin_description]
  5. tba.
  6. [end_description]
  7. Copyright 2013 Karsten Ahnert
  8. Copyright 2013 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. #include <boost/config.hpp>
  14. #ifdef BOOST_MSVC
  15. #pragma warning(disable:4996)
  16. #endif
  17. #define BOOST_TEST_MODULE odeint_eigen_runge_kutta4
  18. #include <boost/test/unit_test.hpp>
  19. #include <boost/numeric/odeint/algebra/vector_space_algebra.hpp>
  20. #include <boost/numeric/odeint/stepper/runge_kutta_dopri5.hpp>
  21. #include <boost/numeric/odeint/stepper/runge_kutta4.hpp>
  22. #include <boost/numeric/odeint/stepper/controlled_runge_kutta.hpp>
  23. #include <boost/numeric/odeint/stepper/dense_output_runge_kutta.hpp>
  24. // #include <boost/numeric/odeint/external/eigen/eigen_resize.hpp>
  25. #include <boost/numeric/odeint/external/eigen/eigen_algebra.hpp>
  26. using namespace boost::unit_test;
  27. using namespace boost::numeric::odeint;
  28. struct sys
  29. {
  30. template< class State , class Deriv >
  31. void operator()( const State &x , Deriv &dxdt , double t ) const
  32. {
  33. dxdt[0] = 1.0;
  34. }
  35. };
  36. template< class State >
  37. struct stepper
  38. {
  39. typedef runge_kutta_dopri5< State , double , State , double , vector_space_algebra > type;
  40. };
  41. template< class State >
  42. struct controlled_stepper
  43. {
  44. typedef controlled_runge_kutta< typename stepper< State >::type > type;
  45. };
  46. template< class State >
  47. struct dense_output_stepper
  48. {
  49. typedef dense_output_runge_kutta< typename controlled_stepper< State >::type > type;
  50. };
  51. BOOST_AUTO_TEST_SUITE( eigen_runge_kutta_dopri5 )
  52. BOOST_AUTO_TEST_CASE( compile_time_matrix )
  53. {
  54. typedef Eigen::Matrix< double , 1 , 1 > state_type;
  55. state_type x;
  56. x[0] = 10.0;
  57. double t = 0.0 , dt = 0.1 ;
  58. // dense_output_stepper< state_type >::type s;
  59. // s.initialize( x , t , dt );
  60. // controlled_stepper< state_type >::type s;
  61. // s.try_step( sys() , x , t , dt );
  62. stepper< state_type >::type s;
  63. s.do_step( sys() , x , t , dt );
  64. // runge_kutta4< state_type , double , state_type , double , vector_space_algebra > rk4;
  65. // rk4.do_step( sys() , x , 0.0 , 0.1 );
  66. // BOOST_CHECK_CLOSE( x[0] , 10.1 , 1.0e-13 );
  67. }
  68. BOOST_AUTO_TEST_CASE( runtime_matrix )
  69. {
  70. typedef Eigen::Matrix< double , Eigen::Dynamic , 1 > state_type;
  71. state_type x( 1 );
  72. x[0] = 10.0;
  73. // runge_kutta4< state_type , double , state_type , double , vector_space_algebra > rk4;
  74. // rk4.do_step( sys() , x , 0.0 , 0.1 );
  75. // BOOST_CHECK_CLOSE( x[0] , 10.1 , 1.0e-13 );
  76. }
  77. BOOST_AUTO_TEST_CASE( compile_time_array )
  78. {
  79. typedef Eigen::Array< double , 1 , 1 > state_type;
  80. state_type x;
  81. x[0] = 10.0;
  82. // runge_kutta4< state_type , double , state_type , double , vector_space_algebra > rk4;
  83. // rk4.do_step( sys() , x , 0.0 , 0.1 );
  84. // BOOST_CHECK_CLOSE( x[0] , 10.1 , 1.0e-13 );
  85. }
  86. BOOST_AUTO_TEST_CASE( runtime_array )
  87. {
  88. typedef Eigen::Array< double , Eigen::Dynamic , 1 > state_type;
  89. state_type x( 1 );
  90. x[0] = 10.0;
  91. // runge_kutta4< state_type , double , state_type , double , vector_space_algebra > rk4;
  92. // rk4.do_step( sys() , x , 0.0 , 0.1 );
  93. // BOOST_CHECK_CLOSE( x[0] , 10.1 , 1.0e-13 );
  94. }
  95. BOOST_AUTO_TEST_SUITE_END()