integrators_symplectic.cpp 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /*
  2. [auto_generated]
  3. libs/numeric/odeint/test/integrators_symplectic.cpp
  4. [begin_description]
  5. tba.
  6. [end_description]
  7. Copyright 2009-2013 Karsten Ahnert
  8. Copyright 2009-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_iterators_symplectic
  18. #define BOOST_FUSION_INVOKE_MAX_ARITY 15
  19. #define BOOST_RESULT_OF_NUM_ARGS 15
  20. #define FUSION_MAX_VECTOR_SIZE 15
  21. #include <cmath>
  22. #include <boost/test/unit_test.hpp>
  23. #ifndef ODEINT_INTEGRATE_ITERATOR
  24. #include <boost/numeric/odeint/integrate/integrate_const.hpp>
  25. #else
  26. #include <boost/numeric/odeint/iterator/integrate/integrate_const.hpp>
  27. #endif
  28. #include <boost/numeric/odeint/stepper/symplectic_euler.hpp>
  29. #include <boost/numeric/odeint/stepper/symplectic_rkn_sb3a_mclachlan.hpp>
  30. #include <boost/numeric/odeint/stepper/symplectic_rkn_sb3a_m4_mclachlan.hpp>
  31. using namespace boost::unit_test;
  32. using namespace boost::numeric::odeint;
  33. namespace mpl = boost::mpl;
  34. namespace fusion = boost::fusion;
  35. typedef std::vector<double> container_type;
  36. struct harm_osc {
  37. void operator()( const container_type &q , container_type &dpdt )
  38. {
  39. dpdt[0] = -q[0];
  40. }
  41. };
  42. class complete_steppers : public mpl::vector<
  43. symplectic_euler< container_type >
  44. , symplectic_rkn_sb3a_mclachlan< container_type >
  45. , symplectic_rkn_sb3a_m4_mclachlan< container_type >
  46. > {};
  47. BOOST_AUTO_TEST_SUITE( symplectic_steppers_test )
  48. BOOST_AUTO_TEST_CASE_TEMPLATE( test_integrate_const , Stepper , complete_steppers )
  49. {
  50. container_type q( 1 , 1.0 ) , p( 1 , 0.0 );
  51. size_t steps = integrate_const( Stepper() , harm_osc() ,
  52. std::make_pair( boost::ref(q) , boost::ref(p) ) ,
  53. 0.0 , 1.0 , 0.1 );
  54. BOOST_CHECK( steps == 10 );
  55. BOOST_CHECK_CLOSE( q[0] , std::cos(1.0) , 100*std::pow( 0.1 , Stepper::order_value ) );
  56. }
  57. BOOST_AUTO_TEST_SUITE_END()