3 libs/numeric/odeint/test/runge_kutta_concepts.cpp
6 This file tests the Stepper concepts of odeint with all Runge-Kutta steppers. It's one of the main tests
10 Copyright 2012 Karsten Ahnert
11 Copyright 2012-2013 Mario Mulansky
13 Distributed under the Boost Software License, Version 1.0.
14 (See accompanying file LICENSE_1_0.txt or
15 copy at http://www.boost.org/LICENSE_1_0.txt)
18 // disable checked iterator warning for msvc
19 #include <boost/config.hpp>
21 #pragma warning(disable:4996)
24 #define BOOST_TEST_MODULE odeint_runge_kutta_concepts
30 #include <boost/numeric/odeint/config.hpp>
32 #include <boost/array.hpp>
34 #include <boost/test/unit_test.hpp>
36 #include <boost/ref.hpp>
37 #include <boost/bind.hpp>
38 #include <boost/utility.hpp>
39 #include <boost/type_traits/add_reference.hpp>
41 #include <boost/mpl/vector.hpp>
42 #include <boost/mpl/for_each.hpp>
43 #include <boost/mpl/insert_range.hpp>
44 #include <boost/mpl/end.hpp>
45 #include <boost/mpl/copy.hpp>
46 #include <boost/mpl/placeholders.hpp>
47 #include <boost/mpl/inserter.hpp>
49 #include <boost/numeric/odeint/stepper/euler.hpp>
50 #include <boost/numeric/odeint/stepper/modified_midpoint.hpp>
51 #include <boost/numeric/odeint/stepper/runge_kutta4_classic.hpp>
52 #include <boost/numeric/odeint/stepper/runge_kutta4.hpp>
53 #include <boost/numeric/odeint/stepper/runge_kutta_cash_karp54_classic.hpp>
54 #include <boost/numeric/odeint/stepper/runge_kutta_cash_karp54.hpp>
55 #include <boost/numeric/odeint/stepper/runge_kutta_dopri5.hpp>
56 #include <boost/numeric/odeint/stepper/runge_kutta_fehlberg78.hpp>
58 #include <boost/numeric/odeint/algebra/detail/extract_value_type.hpp>
60 #include "prepare_stepper_testing.hpp"
61 #include "dummy_odes.hpp"
65 using namespace boost::unit_test
;
66 using namespace boost::numeric::odeint
;
67 namespace mpl
= boost::mpl
;
69 const double result
= 2.2;
71 const double eps
= 1.0e-14;
73 template< class Stepper
, class System
>
74 void check_stepper_concept( Stepper
&stepper
, System system
, typename
Stepper::state_type
&x
)
76 typedef Stepper stepper_type
;
77 typedef typename
stepper_type::deriv_type container_type
;
78 typedef typename
stepper_type::order_type order_type
;
79 typedef typename
stepper_type::time_type time_type
;
81 stepper
.do_step( system
, x
, static_cast<time_type
>(0.0) , static_cast<time_type
>(0.1) );
84 // default case is used for vector space types like plain double
85 template< class Stepper
, typename T
>
86 struct perform_stepper_test
88 typedef T vector_space_type
;
89 void operator()( void ) const
94 constant_system_functor_vector_space sys
;
96 // dont run this for MSVC due to compiler bug 697006
97 check_stepper_concept( stepper
, constant_system_vector_space
< vector_space_type
, vector_space_type
, typename
Stepper::time_type
> , x
);
99 check_stepper_concept( stepper
, boost::cref( sys
) , x
);
101 check_stepper_concept( stepper
, boost::cref( sys
) , x
);
102 std::cout
<< x
<< " ?= " << result
<< std::endl
;
103 BOOST_CHECK( (abs( x
- result
)) < eps
);
107 template< class Stepper
, typename T
>
108 struct perform_stepper_test
< Stepper
, std::vector
<T
> >
110 typedef std::vector
<T
> vector_type
;
111 void operator()( void )
114 vector_type
x( 1 , static_cast<T
>(2.0) );
116 constant_system_functor_standard sys
;
118 // dont run this for MSVC due to compiler bug 697006
119 check_stepper_concept( stepper
, constant_system_standard
< vector_type
, vector_type
, typename
Stepper::time_type
> , x
);
121 check_stepper_concept( stepper
, boost::cref( sys
) , x
);
123 check_stepper_concept( stepper
, boost::cref( sys
) , x
);
124 std::cout
<< x
[0] << " ?= " << result
<< std::endl
;
125 BOOST_CHECK( (abs( x
[0] - result
)) < eps
);
129 template< class Stepper
, typename T
>
130 struct perform_stepper_test
< Stepper
, boost::array
<T
,1> >
132 typedef boost::array
<T
,1> array_type
;
133 void operator()( void )
137 x
[0] = static_cast<T
>(2.0);
139 constant_system_functor_standard sys
;
141 // dont run this for MSVC due to compiler bug 697006
142 check_stepper_concept( stepper
, constant_system_standard
< array_type
, array_type
, typename
Stepper::time_type
> , x
);
144 check_stepper_concept( stepper
, boost::cref( sys
) , x
);
146 check_stepper_concept( stepper
, boost::cref( sys
) , x
);
147 std::cout
<< x
[0] << " ?= " << result
<< std::endl
;
148 BOOST_CHECK( (abs( x
[0] - result
)) < eps
);
152 // split stepper methods to ensure the final vector has less than 30(?) elements
153 // (stepper_methods*container_types) < 30(?)
154 template< class State
> class stepper_methods1
: public mpl::vector
<
155 euler
< State
, typename
detail::extract_value_type
<State
>::type
> ,
156 modified_midpoint
< State
, typename
detail::extract_value_type
<State
>::type
> ,
157 runge_kutta4
< State
, typename
detail::extract_value_type
<State
>::type
> ,
158 runge_kutta4_classic
< State
, typename
detail::extract_value_type
<State
>::type
>
161 template< class State
> class stepper_methods2
: public mpl::vector
<
162 runge_kutta_cash_karp54_classic
< State
, typename
detail::extract_value_type
<State
>::type
> ,
163 runge_kutta_cash_karp54
< State
, typename
detail::extract_value_type
<State
>::type
> ,
164 runge_kutta_dopri5
< State
, typename
detail::extract_value_type
<State
>::type
> ,
165 runge_kutta_fehlberg78
< State
, typename
detail::extract_value_type
<State
>::type
>
179 mpl::end
< mpl::_1
> ,
180 stepper_methods1
< mpl::_2
>
183 >::type stepper_combinations1
;
194 mpl::end
< mpl::_1
> ,
195 stepper_methods2
< mpl::_2
>
198 >::type stepper_combinations2
;
201 BOOST_AUTO_TEST_SUITE( runge_kutta_concept_test
)
203 BOOST_AUTO_TEST_CASE_TEMPLATE( stepper_test1
, Stepper
, stepper_combinations1
)
205 perform_stepper_test
< Stepper
, typename
Stepper::deriv_type
> tester
;
209 BOOST_AUTO_TEST_CASE_TEMPLATE( stepper_test2
, Stepper
, stepper_combinations2
)
211 perform_stepper_test
< Stepper
, typename
Stepper::deriv_type
> tester
;
216 BOOST_AUTO_TEST_SUITE_END()