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 <array>
33
34#include <boost/test/unit_test.hpp>
35
36#include <boost/ref.hpp>
37#include <boost/utility.hpp>
38#include <boost/type_traits/add_reference.hpp>
39
40#include <boost/mpl/vector.hpp>
41#include <boost/mpl/for_each.hpp>
42#include <boost/mpl/insert_range.hpp>
43#include <boost/mpl/end.hpp>
44#include <boost/mpl/copy.hpp>
45#include <boost/mpl/placeholders.hpp>
46#include <boost/mpl/inserter.hpp>
47
48#include <boost/numeric/odeint/stepper/runge_kutta_cash_karp54_classic.hpp>
49#include <boost/numeric/odeint/stepper/runge_kutta_cash_karp54.hpp>
50#include <boost/numeric/odeint/stepper/runge_kutta_dopri5.hpp>
51#include <boost/numeric/odeint/stepper/runge_kutta_fehlberg78.hpp>
52
53#include "prepare_stepper_testing.hpp"
54#include "dummy_odes.hpp"
55
56using std::vector;
57
58using namespace boost::unit_test;
59using namespace boost::numeric::odeint;
60namespace mpl = boost::mpl;
61
62const double result = 2.4; // four steps total...
63
64const double eps = 1.0e-14;
65
66template< class Stepper , class System >
67void check_error_stepper_concept( Stepper &stepper , System system , typename Stepper::state_type &x , typename Stepper::state_type &xerr )
68{
69 typedef Stepper stepper_type;
70 typedef typename stepper_type::deriv_type container_type;
71 typedef typename stepper_type::order_type order_type;
72 typedef typename stepper_type::time_type time_type;
73
74 stepper.do_step( system , x , static_cast<time_type>(0.0) , static_cast<time_type>(0.1) );
75 stepper.do_step( system , x , static_cast<time_type>(0.0) , static_cast<time_type>(0.1) , xerr );
76}
77
78// default case is used for vector space types like plain double
79template< class Stepper , typename T >
80struct perform_error_stepper_test
81{
82 typedef T vector_space_type;
83 void operator()( void ) const
84 {
85 using std::abs;
86 vector_space_type x , xerr;
87 x = 2.0;
88 Stepper stepper;
89 constant_system_functor_vector_space sys;
90#ifndef _MSC_VER
91 // dont run this for MSVC due to compiler bug 697006
92 check_error_stepper_concept( stepper ,
93 constant_system_vector_space< vector_space_type , vector_space_type , typename Stepper::time_type > ,
94 x ,
95 xerr );
96#else
97 check_error_stepper_concept( stepper , boost::cref( sys ) , x , xerr );
98#endif
99 check_error_stepper_concept( stepper , boost::cref( t: sys ) , x , xerr );
100
101 BOOST_CHECK_MESSAGE( (abs( x - result )) < eps , x );
102 }
103};
104
105template< class Stepper , typename T >
106struct perform_error_stepper_test< Stepper , std::vector<T> >
107{
108 typedef std::vector<T> vector_type;
109 void operator()( void )
110 {
111 using std::abs;
112 vector_type x( 1 , 2.0 ) , xerr( 1 );
113 Stepper stepper;
114 constant_system_functor_standard sys;
115#ifndef _MSC_VER
116 // dont run this for MSVC due to compiler bug 697006
117 check_error_stepper_concept( stepper , constant_system_standard< vector_type , vector_type , typename Stepper::time_type > , x , xerr );
118#else
119 check_error_stepper_concept( stepper , boost::cref( sys ) , x , xerr );
120#endif
121 check_error_stepper_concept( stepper , boost::cref( t: sys ) , x , xerr );
122 BOOST_CHECK( (abs( x[0] - result )) < eps );
123 }
124};
125
126
127template< class Stepper , typename T >
128struct perform_error_stepper_test< Stepper , std::array<T,1> >
129{
130 typedef std::array<T,1> array_type;
131 void operator()( void )
132 {
133 using std::abs;
134 array_type x , xerr;
135 x[0] = 2.0;
136 Stepper stepper;
137 constant_system_functor_standard sys;
138#ifndef _MSC_VER
139 // dont run this for MSVC due to compiler bug 697006
140 check_error_stepper_concept( stepper , constant_system_standard< array_type , array_type , typename Stepper::time_type > , x , xerr );
141#else
142 check_error_stepper_concept( stepper , boost::cref( sys ) , x , xerr );
143#endif
144 check_error_stepper_concept( stepper , boost::cref( t: sys ) , x , xerr );
145 BOOST_CHECK( (abs( x[0] - result )) < eps );
146 }
147};
148
149template< class State > class error_stepper_methods : public mpl::vector<
150 runge_kutta_cash_karp54_classic< State , typename detail::extract_value_type<State>::type > ,
151 runge_kutta_cash_karp54< State , typename detail::extract_value_type<State>::type > ,
152 runge_kutta_dopri5< State , typename detail::extract_value_type<State>::type > ,
153 runge_kutta_fehlberg78< State , typename detail::extract_value_type<State>::type >
154 > { };
155
156
157typedef mpl::copy
158<
159 container_types ,
160 mpl::inserter
161 <
162 mpl::vector0<> ,
163 mpl::insert_range
164 <
165 mpl::_1 ,
166 mpl::end< mpl::_1 > ,
167 error_stepper_methods< mpl::_2 >
168 >
169 >
170 >::type all_error_stepper_methods;
171
172
173BOOST_AUTO_TEST_SUITE( runge_kutta_error_concept_test )
174
175BOOST_AUTO_TEST_CASE_TEMPLATE( error_stepper_test , Stepper , all_error_stepper_methods )
176{
177 perform_error_stepper_test< Stepper , typename Stepper::state_type > tester;
178 tester();
179}
180
181BOOST_AUTO_TEST_SUITE_END()
182

source code of boost/libs/numeric/odeint/test/runge_kutta_error_concepts.cpp