• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  [auto_generated]
3  libs/numeric/odeint/test/runge_kutta_error_concepts.cpp
4 
5  [begin_description]
6  This file tests the Stepper concepts of odeint with all Runge-Kutta Error steppers.
7  It's one of the main tests of odeint.
8  [end_description]
9 
10  Copyright 2012 Karsten Ahnert
11  Copyright 2012-2013 Mario Mulansky
12 
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)
16  */
17 
18 // disable checked iterator warning for msvc
19 #include <boost/config.hpp>
20 #ifdef BOOST_MSVC
21     #pragma warning(disable:4996)
22 #endif
23 
24 #define BOOST_TEST_MODULE odeint_runge_kutta_error_concepts
25 
26 #include <vector>
27 #include <cmath>
28 #include <iostream>
29 
30 #include <boost/numeric/odeint/config.hpp>
31 
32 #include <boost/array.hpp>
33 
34 #include <boost/test/unit_test.hpp>
35 
36 #include <boost/ref.hpp>
37 #include <boost/bind.hpp>
38 #include <boost/utility.hpp>
39 #include <boost/type_traits/add_reference.hpp>
40 
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>
48 
49 #include <boost/numeric/odeint/stepper/runge_kutta_cash_karp54_classic.hpp>
50 #include <boost/numeric/odeint/stepper/runge_kutta_cash_karp54.hpp>
51 #include <boost/numeric/odeint/stepper/runge_kutta_dopri5.hpp>
52 #include <boost/numeric/odeint/stepper/runge_kutta_fehlberg78.hpp>
53 
54 #include "prepare_stepper_testing.hpp"
55 #include "dummy_odes.hpp"
56 
57 using std::vector;
58 
59 using namespace boost::unit_test;
60 using namespace boost::numeric::odeint;
61 namespace mpl = boost::mpl;
62 
63 const double result = 2.4; // four steps total...
64 
65 const double eps = 1.0e-14;
66 
67 template< class Stepper , class System >
check_error_stepper_concept(Stepper & stepper,System system,typename Stepper::state_type & x,typename Stepper::state_type & xerr)68 void check_error_stepper_concept( Stepper &stepper , System system , typename Stepper::state_type &x , typename Stepper::state_type &xerr )
69 {
70     typedef Stepper stepper_type;
71     typedef typename stepper_type::deriv_type container_type;
72     typedef typename stepper_type::order_type order_type;
73     typedef typename stepper_type::time_type time_type;
74 
75     stepper.do_step( system , x , static_cast<time_type>(0.0) , static_cast<time_type>(0.1) );
76     stepper.do_step( system , x , static_cast<time_type>(0.0) , static_cast<time_type>(0.1) , xerr );
77 }
78 
79 // default case is used for vector space types like plain double
80 template< class Stepper , typename T >
81 struct perform_error_stepper_test
82 {
83     typedef T vector_space_type;
operator ()perform_error_stepper_test84     void operator()( void ) const
85     {
86         using std::abs;
87         vector_space_type x , xerr;
88         x = 2.0;
89         Stepper stepper;
90         constant_system_functor_vector_space sys;
91 #ifndef _MSC_VER
92         // dont run this for MSVC due to compiler bug 697006
93         check_error_stepper_concept( stepper ,
94                                      constant_system_vector_space< vector_space_type , vector_space_type , typename Stepper::time_type > ,
95                                      x ,
96                                      xerr );
97 #else
98         check_error_stepper_concept( stepper , boost::cref( sys ) , x , xerr );
99 #endif
100         check_error_stepper_concept( stepper , boost::cref( sys ) , x , xerr );
101 
102         BOOST_CHECK_MESSAGE( (abs( x - result )) < eps , x );
103     }
104 };
105 
106 template< class Stepper , typename T >
107 struct perform_error_stepper_test< Stepper , std::vector<T> >
108 {
109     typedef std::vector<T> vector_type;
operator ()perform_error_stepper_test110     void operator()( void )
111     {
112         using std::abs;
113         vector_type x( 1 , 2.0 ) , xerr( 1 );
114         Stepper stepper;
115         constant_system_functor_standard sys;
116 #ifndef _MSC_VER
117         // dont run this for MSVC due to compiler bug 697006
118         check_error_stepper_concept( stepper , constant_system_standard< vector_type , vector_type , typename Stepper::time_type > , x , xerr );
119 #else
120         check_error_stepper_concept( stepper , boost::cref( sys ) , x , xerr );
121 #endif
122         check_error_stepper_concept( stepper , boost::cref( sys ) , x , xerr );
123         BOOST_CHECK( (abs( x[0] - result )) < eps );
124     }
125 };
126 
127 
128 template< class Stepper , typename T >
129 struct perform_error_stepper_test< Stepper , boost::array<T,1> >
130 {
131     typedef boost::array<T,1> array_type;
operator ()perform_error_stepper_test132     void operator()( void )
133     {
134         using std::abs;
135         array_type x , xerr;
136         x[0] = 2.0;
137         Stepper stepper;
138         constant_system_functor_standard sys;
139 #ifndef _MSC_VER
140         // dont run this for MSVC due to compiler bug 697006
141         check_error_stepper_concept( stepper , constant_system_standard< array_type , array_type , typename Stepper::time_type > , x , xerr );
142 #else
143         check_error_stepper_concept( stepper , boost::cref( sys ) , x , xerr );
144 #endif
145         check_error_stepper_concept( stepper , boost::cref( sys ) , x , xerr );
146         BOOST_CHECK( (abs( x[0] - result )) < eps );
147     }
148 };
149 
150 template< class State > class error_stepper_methods : public mpl::vector<
151     runge_kutta_cash_karp54_classic< State , typename detail::extract_value_type<State>::type > ,
152     runge_kutta_cash_karp54< State , typename detail::extract_value_type<State>::type > ,
153     runge_kutta_dopri5< State , typename detail::extract_value_type<State>::type > ,
154     runge_kutta_fehlberg78< State , typename detail::extract_value_type<State>::type >
155     > { };
156 
157 
158 typedef mpl::copy
159 <
160     container_types ,
161     mpl::inserter
162     <
163         mpl::vector0<> ,
164         mpl::insert_range
165         <
166             mpl::_1 ,
167             mpl::end< mpl::_1 > ,
168             error_stepper_methods< mpl::_2 >
169             >
170         >
171     >::type all_error_stepper_methods;
172 
173 
174 BOOST_AUTO_TEST_SUITE( runge_kutta_error_concept_test )
175 
BOOST_AUTO_TEST_CASE_TEMPLATE(error_stepper_test,Stepper,all_error_stepper_methods)176 BOOST_AUTO_TEST_CASE_TEMPLATE( error_stepper_test , Stepper , all_error_stepper_methods )
177 {
178     perform_error_stepper_test< Stepper , typename Stepper::state_type > tester;
179     tester();
180 }
181 
182 BOOST_AUTO_TEST_SUITE_END()
183