runge_kutta4.cpp 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*
  2. [auto_generated]
  3. libs/numeric/odeint/test_external/eigen/runge_kutta4.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_kutta4.hpp>
  21. #include <boost/numeric/odeint/external/eigen/eigen_resize.hpp>
  22. using namespace boost::unit_test;
  23. using namespace boost::numeric::odeint;
  24. struct sys
  25. {
  26. template< class State , class Deriv >
  27. void operator()( const State &x , Deriv &dxdt , double t ) const
  28. {
  29. dxdt[0] = 1.0;
  30. }
  31. };
  32. BOOST_AUTO_TEST_SUITE( eigen_runge_kutta4 )
  33. BOOST_AUTO_TEST_CASE( compile_time_matrix )
  34. {
  35. typedef Eigen::Matrix< double , 1 , 1 > state_type;
  36. state_type x;
  37. x[0] = 10.0;
  38. runge_kutta4< state_type , double , state_type , double , vector_space_algebra > rk4;
  39. rk4.do_step( sys() , x , 0.0 , 0.1 );
  40. BOOST_CHECK_CLOSE( x[0] , 10.1 , 1.0e-13 );
  41. }
  42. BOOST_AUTO_TEST_CASE( runtime_matrix )
  43. {
  44. typedef Eigen::Matrix< double , Eigen::Dynamic , 1 > state_type;
  45. state_type x( 1 );
  46. x[0] = 10.0;
  47. runge_kutta4< state_type , double , state_type , double , vector_space_algebra > rk4;
  48. rk4.do_step( sys() , x , 0.0 , 0.1 );
  49. BOOST_CHECK_CLOSE( x[0] , 10.1 , 1.0e-13 );
  50. }
  51. BOOST_AUTO_TEST_CASE( compile_time_array )
  52. {
  53. typedef Eigen::Array< double , 1 , 1 > state_type;
  54. state_type x;
  55. x[0] = 10.0;
  56. runge_kutta4< state_type , double , state_type , double , vector_space_algebra > rk4;
  57. rk4.do_step( sys() , x , 0.0 , 0.1 );
  58. BOOST_CHECK_CLOSE( x[0] , 10.1 , 1.0e-13 );
  59. }
  60. BOOST_AUTO_TEST_CASE( runtime_array )
  61. {
  62. typedef Eigen::Array< double , Eigen::Dynamic , 1 > state_type;
  63. state_type x( 1 );
  64. x[0] = 10.0;
  65. runge_kutta4< state_type , double , state_type , double , vector_space_algebra > rk4;
  66. rk4.do_step( sys() , x , 0.0 , 0.1 );
  67. BOOST_CHECK_CLOSE( x[0] , 10.1 , 1.0e-13 );
  68. }
  69. BOOST_AUTO_TEST_SUITE_END()