Brian Silverman | 7c33ab2 | 2018-08-04 17:14:51 -0700 | [diff] [blame^] | 1 | /* |
| 2 | [auto_generated] |
| 3 | libs/numeric/odeint/test/integrators_symplectic.cpp |
| 4 | |
| 5 | [begin_description] |
| 6 | tba. |
| 7 | [end_description] |
| 8 | |
| 9 | Copyright 2009-2013 Karsten Ahnert |
| 10 | Copyright 2009-2013 Mario Mulansky |
| 11 | |
| 12 | Distributed under the Boost Software License, Version 1.0. |
| 13 | (See accompanying file LICENSE_1_0.txt or |
| 14 | copy at http://www.boost.org/LICENSE_1_0.txt) |
| 15 | */ |
| 16 | |
| 17 | #include <boost/config.hpp> |
| 18 | #ifdef BOOST_MSVC |
| 19 | #pragma warning(disable:4996) |
| 20 | #endif |
| 21 | |
| 22 | #define BOOST_TEST_MODULE odeint_iterators_symplectic |
| 23 | |
| 24 | #define BOOST_FUSION_INVOKE_MAX_ARITY 15 |
| 25 | #define BOOST_RESULT_OF_NUM_ARGS 15 |
| 26 | #define FUSION_MAX_VECTOR_SIZE 15 |
| 27 | |
| 28 | #include <cmath> |
| 29 | |
| 30 | #include <boost/test/unit_test.hpp> |
| 31 | |
| 32 | #ifndef ODEINT_INTEGRATE_ITERATOR |
| 33 | #include <boost/numeric/odeint/integrate/integrate_const.hpp> |
| 34 | #else |
| 35 | #include <boost/numeric/odeint/iterator/integrate/integrate_const.hpp> |
| 36 | #endif |
| 37 | #include <boost/numeric/odeint/stepper/symplectic_euler.hpp> |
| 38 | #include <boost/numeric/odeint/stepper/symplectic_rkn_sb3a_mclachlan.hpp> |
| 39 | #include <boost/numeric/odeint/stepper/symplectic_rkn_sb3a_m4_mclachlan.hpp> |
| 40 | |
| 41 | using namespace boost::unit_test; |
| 42 | using namespace boost::numeric::odeint; |
| 43 | namespace mpl = boost::mpl; |
| 44 | namespace fusion = boost::fusion; |
| 45 | |
| 46 | typedef std::vector<double> container_type; |
| 47 | |
| 48 | struct harm_osc { |
| 49 | void operator()( const container_type &q , container_type &dpdt ) |
| 50 | { |
| 51 | dpdt[0] = -q[0]; |
| 52 | } |
| 53 | }; |
| 54 | |
| 55 | class complete_steppers : public mpl::vector< |
| 56 | symplectic_euler< container_type > |
| 57 | , symplectic_rkn_sb3a_mclachlan< container_type > |
| 58 | , symplectic_rkn_sb3a_m4_mclachlan< container_type > |
| 59 | > {}; |
| 60 | |
| 61 | BOOST_AUTO_TEST_SUITE( symplectic_steppers_test ) |
| 62 | |
| 63 | |
| 64 | BOOST_AUTO_TEST_CASE_TEMPLATE( test_integrate_const , Stepper , complete_steppers ) |
| 65 | { |
| 66 | container_type q( 1 , 1.0 ) , p( 1 , 0.0 ); |
| 67 | size_t steps = integrate_const( Stepper() , harm_osc() , |
| 68 | std::make_pair( boost::ref(q) , boost::ref(p) ) , |
| 69 | 0.0 , 1.0 , 0.1 ); |
| 70 | BOOST_CHECK( steps == 10 ); |
| 71 | BOOST_CHECK_CLOSE( q[0] , std::cos(1.0) , 100*std::pow( 0.1 , Stepper::order_value ) ); |
| 72 | } |
| 73 | |
| 74 | BOOST_AUTO_TEST_SUITE_END() |