Imported Upstream version 1.57.0
[platform/upstream/boost.git] / libs / numeric / odeint / test / range_algebra.cpp
1 /*
2  [auto_generated]
3  libs/numeric/odeint/test/check_operations.cpp
4
5  [begin_description]
6  This file tests interaction between the algebras and the operations.
7  [end_description]
8
9  Copyright 2011-2012 Karsten Ahnert
10  Copyright 2011-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 #define BOOST_TEST_MODULE odeint_standard_algebra
18
19 #include <cmath>
20 #include <complex>
21 #include <utility>
22 #include <functional>
23 #include <boost/array.hpp>
24
25 #include <boost/test/unit_test.hpp>
26 #include <boost/test/floating_point_comparison.hpp>
27
28 #include <boost/units/systems/si/length.hpp>
29 #include <boost/units/systems/si/time.hpp>
30 #include <boost/units/systems/si/velocity.hpp>
31 #include <boost/units/systems/si/io.hpp>
32
33 #include <boost/numeric/odeint/algebra/default_operations.hpp>
34 #include <boost/numeric/odeint/algebra/range_algebra.hpp>
35 #include <boost/numeric/odeint/algebra/array_algebra.hpp>
36
37 #include <boost/mpl/list.hpp>
38
39 namespace units = boost::units;
40 namespace si = boost::units::si;
41
42 using boost::numeric::odeint::default_operations;
43 using boost::numeric::odeint::range_algebra;
44 using boost::numeric::odeint::array_algebra;
45
46
47 BOOST_AUTO_TEST_SUITE( standard_algebra_test )
48
49 typedef boost::mpl::list< range_algebra , array_algebra > algebra_types;
50 range_algebra algebra;
51
52 BOOST_AUTO_TEST_CASE_TEMPLATE( for_each2 , algebra_type , algebra_types )
53 {
54     algebra_type algebra;
55     boost::array< double , 2 > x1 = {{ 1.0 , 1.0 }} , x2 = {{ 2.0 , 2.0 }};
56     algebra.for_each2( x1 , x2 , default_operations::scale_sum1<>( 1.0 ) );
57     BOOST_CHECK_CLOSE( x1[0] , 2.0 , 1.0e-10 );
58     BOOST_CHECK_CLOSE( x1[1] , 2.0 , 1.0e-10 );
59 }
60
61
62
63 BOOST_AUTO_TEST_CASE_TEMPLATE( for_each3 , algebra_type , algebra_types )
64 {
65     algebra_type algebra;
66     boost::array< double , 2 > x1 = {{ 1.0 , 1.0 }} , x2 = {{ 2.0 , 2.0 }} , x3 = {{ 3.0 , 3.0 }};
67     algebra.for_each3( x1 , x2 , x3 , default_operations::scale_sum2<>( 1.0 , 2.0 ) );
68     BOOST_CHECK_CLOSE( x1[0] , 8.0 , 1.0e-10 );
69     BOOST_CHECK_CLOSE( x1[1] , 8.0 , 1.0e-10 );
70 }
71
72
73 BOOST_AUTO_TEST_CASE_TEMPLATE( for_each4 , algebra_type , algebra_types )
74 {
75     algebra_type algebra;
76     boost::array< double , 2 > x1 = {{ 1.0 , 1.0 }} , x2 = {{ 2.0 , 2.0 }} , x3 = {{ 3.0 , 3.0 }} , x4 = {{ 4.0 , 4.0 }};
77     algebra.for_each4( x1 , x2 , x3 , x4 , default_operations::scale_sum3<>( 1.0 , 2.0 , 3.0 ) );
78     BOOST_CHECK_CLOSE( x1[0] , 20.0 , 1.0e-10 );
79     BOOST_CHECK_CLOSE( x1[1] , 20.0 , 1.0e-10 );
80 }
81
82 BOOST_AUTO_TEST_CASE_TEMPLATE( for_each5 , algebra_type , algebra_types )
83 {
84     algebra_type algebra;
85     boost::array< double , 2 > x1 = {{ 1.0 , 1.0 }} , x2 = {{ 2.0 , 2.0 }} , x3 = {{ 3.0 , 3.0 }} , x4 = {{ 4.0 , 4.0 }} , x5 = {{ 5.0 , 5.0 }};
86     algebra.for_each5( x1 , x2 , x3 , x4 , x5 , default_operations::scale_sum4<>( 1.0 , 2.0 , 3.0 , 4.0 ) );
87     BOOST_CHECK_CLOSE( x1[0] , 40.0 , 1.0e-10 );
88     BOOST_CHECK_CLOSE( x1[1] , 40.0 , 1.0e-10 );
89 }
90
91 BOOST_AUTO_TEST_CASE_TEMPLATE( for_each6 , algebra_type , algebra_types )
92 {
93     algebra_type algebra;
94     boost::array< double , 2 > x1 = {{ 1.0 , 1.0 }} , x2 = {{ 2.0 , 2.0 }} , x3 = {{ 3.0 , 3.0 }} , x4 = {{ 4.0 , 4.0 }} , x5 = {{ 5.0 , 5.0 }} , x6 = {{ 6.0 , 6.0 }};
95     algebra.for_each6( x1 , x2 , x3 , x4 , x5 , x6 ,default_operations::scale_sum5<>( 1.0 , 2.0 , 3.0 , 4.0 , 5.0 ) );
96     BOOST_CHECK_CLOSE( x1[0] , 70.0 , 1.0e-10 );
97     BOOST_CHECK_CLOSE( x1[1] , 70.0 , 1.0e-10 );
98 }
99
100 BOOST_AUTO_TEST_CASE_TEMPLATE( for_each7 , algebra_type , algebra_types )
101 {
102     algebra_type algebra;
103     boost::array< double , 2 > x1 = {{ 1.0 , 1.0 }} , x2 = {{ 2.0 , 2.0 }} , x3 = {{ 3.0 , 3.0 }} , x4 = {{ 4.0 , 4.0 }} , x5 = {{ 5.0 , 5.0 }} , x6 = {{ 6.0 , 6.0 }} , x7 = {{ 7.0 , 7.0 }};
104     algebra.for_each7( x1 , x2 , x3 , x4 , x5 , x6 , x7 , default_operations::scale_sum6<>( 1.0 , 2.0 , 3.0 , 4.0 , 5.0 , 6.0 ) );
105     BOOST_CHECK_CLOSE( x1[0] , 112.0 , 1.0e-10 );
106     BOOST_CHECK_CLOSE( x1[1] , 112.0 , 1.0e-10 );
107 }
108
109 BOOST_AUTO_TEST_CASE_TEMPLATE( for_each8 , algebra_type , algebra_types )
110 {
111     algebra_type algebra;
112     boost::array< double , 2 > x1 = {{ 1.0 , 1.0 }} , x2 = {{ 2.0 , 2.0 }} , x3 = {{ 3.0 , 3.0 }} , x4 = {{ 4.0 , 4.0 }} , x5 = {{ 5.0 , 5.0 }} , x6 = {{ 6.0 , 6.0 }} , x7 = {{ 7.0 , 7.0 }} , x8 = {{ 8.0 , 8.0 }};
113     algebra.for_each8( x1 , x2 , x3 , x4 , x5 , x6 , x7 , x8 , default_operations::scale_sum7<>( 1.0 , 2.0 , 3.0 , 4.0 , 5.0 , 6.0 , 7.0 ) );
114     BOOST_CHECK_CLOSE( x1[0] , 168.0 , 1.0e-10 );
115     BOOST_CHECK_CLOSE( x1[1] , 168.0 , 1.0e-10 );
116 }
117
118 BOOST_AUTO_TEST_CASE_TEMPLATE( norm_inf , algebra_type , algebra_types )
119 {
120     algebra_type algebra;
121     boost::array< double , 2 > x = {{ 1.25 , 2.25 }};
122     double nrm = algebra.norm_inf( x );
123     BOOST_CHECK_CLOSE( nrm , 2.25 , 1.0e-10 );
124     BOOST_CHECK_CLOSE( x[0] , 1.25 , 1.0e-10 );
125     BOOST_CHECK_CLOSE( x[1] , 2.25 , 1.0e-10 );
126 }
127
128
129 BOOST_AUTO_TEST_CASE( for_each2_with_units )
130 {
131     range_algebra algebra;
132     typedef units::quantity< si::time , double > time_type;
133     typedef units::quantity< si::length , double > length_type;
134     typedef units::quantity< si::velocity , double > velocity_type;
135     boost::array< length_type , 2 > x1 = {{ 1.0 * si::meter , 1.0 * si::meter }};
136     boost::array< velocity_type , 2 > x2 = {{ 2.0 * si::meter / si::seconds , 2.0 * si::meter / si::seconds }};
137     algebra.for_each2( x1 , x2 , default_operations::scale_sum1< time_type >( 0.1 * si::second ) );
138     BOOST_CHECK_CLOSE( x1[0].value() , 0.2 , 1.0e-10 );
139     BOOST_CHECK_CLOSE( x1[1].value() , 0.2 , 1.0e-10 );
140 }
141
142
143 BOOST_AUTO_TEST_SUITE_END()