/[escript]/branches/escript3047_with_pastix2995/escript/test/DataAlgorithmAdapterTestCase.cpp
ViewVC logotype

Annotation of /branches/escript3047_with_pastix2995/escript/test/DataAlgorithmAdapterTestCase.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1387 - (hide annotations)
Fri Jan 11 07:45:26 2008 UTC (11 years, 11 months ago) by trankine
Original Path: temp/escript/test/DataAlgorithmAdapterTestCase.cpp
File size: 8236 byte(s)
Restore the trunk that existed before the windows changes were committed to the (now moved to branches) old trunk.
1 ksteube 1312
2     /* $Id$ */
3    
4     /*******************************************************
5     *
6     * Copyright 2003-2007 by ACceSS MNRF
7     * Copyright 2007 by University of Queensland
8     *
9     * http://esscc.uq.edu.au
10     * Primary Business: Queensland, Australia
11     * Licensed under the Open Software License version 3.0
12     * http://www.opensource.org/licenses/osl-3.0.php
13     *
14     *******************************************************/
15    
16 phornby 1026 #if (defined _WIN32) && (defined __INTEL_COMPILER)
17 woo409 757 #include <mathimf.h>
18     #else
19     #include <math.h>
20     #endif
21 jgs 113
22 robwdcock 670 #include "escript/DataExpanded.h"
23     #include "escript/DataArrayView.h"
24     #include "escript/DataAlgorithm.h"
25 jgs 82 #include "DataAlgorithmAdapterTestCase.h"
26    
27     #include <iostream>
28     #include <algorithm>
29     #include <limits>
30    
31     using namespace CppUnitTest;
32     using namespace std;
33     using namespace escript;
34    
35     void DataAlgorithmAdapterTestCase::setUp() {
36     //
37     // This is called before each test is run
38    
39     }
40    
41     void DataAlgorithmAdapterTestCase::tearDown() {
42     //
43     // This is called after each test has been run
44    
45     }
46    
47     void DataAlgorithmAdapterTestCase::testAll() {
48 jgs 102
49 jgs 82 cout << endl;
50 jgs 102
51 jgs 108 cout << "\tTesting FMax." << endl;
52 jgs 106
53 jgs 108 FMax fmax;
54 gross 713 assert(std::abs(fmax(5,6)-6)<=REL_TOL*6);
55     assert(std::abs(fmax(5,-6)-5)<=REL_TOL*5);
56     assert(std::abs(fmax(0,0)-0)<=REL_TOL*0);
57     assert(std::abs(fmax(15,-96)-15)<=REL_TOL*15);
58 jgs 108
59     DataAlgorithmAdapter<FMax> sup(numeric_limits<double>::max()*-1);
60 jgs 106 sup.resetResult();
61 jgs 108 sup(-1);
62     sup(-2);
63     sup(-14);
64 jgs 106 sup(3);
65 gross 713 assert(std::abs(sup.getResult()-3)<=REL_TOL*3);
66 jgs 102
67     cout << "\tTesting AbsMax." << endl;
68 jgs 108
69     AbsMax absmax;
70 gross 713 assert(std::abs(absmax(5,6)-6)<=REL_TOL*6);
71     assert(std::abs(absmax(5,-6)-6)<=REL_TOL*6);
72     assert(std::abs(absmax(0,0)-0)<=REL_TOL*6);
73     assert(std::abs(absmax(15,-96)-96)<=REL_TOL*6);
74 jgs 108
75 jgs 102 DataAlgorithmAdapter<AbsMax> Lsup(0);
76 jgs 106 Lsup.resetResult();
77 jgs 82 Lsup(-2);
78     Lsup(2);
79     Lsup(5);
80 jgs 102 Lsup(-10);
81 gross 713 assert(std::abs(Lsup.getResult()-10)<=REL_TOL*10);
82 jgs 102
83     cout << "\tTesting FMin." << endl;
84 jgs 108
85     FMin fmin;
86 gross 713 assert(std::abs(fmin(5,6)-5)<=REL_TOL*5);
87     assert(std::abs(fmin(5,-6)-(-6))<=REL_TOL*6);
88     assert(std::abs(fmin(0,0)-0)<=REL_TOL*0);
89     assert(std::abs(fmin(15,-96)-(-96))<=REL_TOL*96);
90 jgs 108
91 jgs 82 DataAlgorithmAdapter<FMin> inf(numeric_limits<double>::max());
92 jgs 106 inf.resetResult();
93 jgs 82 inf(1);
94 jgs 102 inf(12);
95 jgs 82 inf(2);
96 jgs 102 inf(99);
97 gross 713 assert(std::abs(inf.getResult()-1)<=REL_TOL*1);
98 jgs 102
99 jgs 106 cout << "\tTesting Length." << endl;
100 jgs 108
101     Length lngth;
102 gross 713 assert(std::abs(lngth(5,6)-std::sqrt(61.0))<=REL_TOL*std::sqrt(61.0));
103     assert(std::abs(lngth(5,-6)-std::sqrt(61.0))<=REL_TOL*std::sqrt(61.0));
104     assert(std::abs(lngth(0,0)-std::sqrt(0.0))<=REL_TOL*std::sqrt(61.0));
105     assert(std::abs(lngth(15,-96)-std::sqrt(9441.0))<=REL_TOL*std::sqrt(61.0));
106 jgs 108
107 jgs 106 DataAlgorithmAdapter<Length> length(0);
108     length.resetResult();
109     length(2);
110     length(4);
111     length(6);
112     length(8);
113 gross 713 assert(std::abs(length.getResult()-std::sqrt(120.0))<=REL_TOL*std::sqrt(120.0));
114 jgs 106 length.resetResult();
115     length(1.5);
116     length(2.5);
117     length(3.5);
118     length(4.5);
119 gross 713 assert(std::abs(length.getResult()-std::sqrt(41.0))<=REL_TOL*std::sqrt(41.0));
120 jgs 102
121 jgs 106 cout << "\tTesting Trace." << endl;
122 jgs 108
123     Trace trce;
124 gross 713 assert(std::abs(trce(5,6)-11)<=REL_TOL*11);
125     assert(std::abs(trce(5,-6)-(-1))<=REL_TOL*1);
126     assert(std::abs(trce(0,0)-0)<=REL_TOL*0);
127     assert(std::abs(trce(15,-96)-(-81))<=REL_TOL*81);
128 jgs 108
129 jgs 106 DataAlgorithmAdapter<Trace> trace(0);
130     trace.resetResult();
131     trace(1);
132     trace(2);
133     trace(3);
134     trace(4);
135     trace(5);
136 gross 713 assert(std::abs(trace.getResult()-15)<=REL_TOL*15);
137 jgs 106 trace.resetResult();
138     trace(1.5);
139     trace(2.5);
140     trace(3.5);
141     trace(4.5);
142     trace(5.5);
143 gross 713 assert(std::abs(trace.getResult()-17.5)<=REL_TOL*17.5);
144 jgs 106
145 jgs 82 }
146    
147 jgs 113 void DataAlgorithmAdapterTestCase::testAlgorithm() {
148    
149 jgs 561 cout << endl;
150    
151 jgs 113 {
152    
153 jgs 561 cout << "\tTest algorithm on Data objects with a single rank 2 data-point." << endl;
154    
155 jgs 113 // define the shape for the DataArrayView
156     DataArrayView::ShapeType shape;
157     shape.push_back(2);
158     shape.push_back(3);
159    
160     // allocate the data for the DataArrayView
161     DataArrayView::ValueType dataArray(DataArrayView::noValues(shape),0);
162    
163     // construct DataArrayView
164     DataArrayView dataView(dataArray,shape);
165    
166     // assign values to the data point
167     for (int i=0;i<shape[0];i++) {
168     for (int j=0;j<shape[1];j++) {
169     dataView(i,j)=dataView.index(i,j);
170     }
171     }
172    
173     // create a few Data objects from the created DataArrayView
174     DataExpanded dataExp(dataView,FunctionSpace());
175     DataConstant dataCon(dataView,FunctionSpace());
176     DataTagged dataTag(dataCon);
177    
178     // test algorithm on DataExpanded
179 jgs 147 FMin fmin_func;
180 gross 713 assert(std::abs(escript::algorithm(dataExp,fmin_func,numeric_limits<double>::max())-0)<=REL_TOL*0);
181 jgs 147 FMax fmax_func;
182 gross 713 assert(std::abs(escript::algorithm(dataExp,fmax_func,numeric_limits<double>::max()*-1)-5)<=REL_TOL*5);
183 jgs 113
184     // test algorithm on DataTagged
185 gross 713 assert(std::abs(escript::algorithm(dataTag,fmin_func,numeric_limits<double>::max())-0)<=REL_TOL*0);
186     assert(std::abs(escript::algorithm(dataTag,fmax_func,numeric_limits<double>::max()*-1)-5)<=REL_TOL*5);
187 jgs 113
188     // test algorithm on DataConstant
189 gross 713 assert(std::abs(escript::algorithm(dataCon,fmin_func,numeric_limits<double>::max())-0)<=REL_TOL*0);
190     assert(std::abs(escript::algorithm(dataCon,fmax_func,numeric_limits<double>::max()*-1)-5)<=REL_TOL*5);
191 jgs 113
192     }
193    
194     }
195    
196     void DataAlgorithmAdapterTestCase::testDpAlgorithm() {
197    
198 jgs 561 cout << endl;
199    
200 jgs 113 {
201    
202 jgs 561 cout << "\tTest dp_algorithm on Data objects with a single rank 2 data-point." << endl;
203    
204 jgs 113 // define the shapes for the DataArrayViews
205     DataArrayView::ShapeType shape;
206     shape.push_back(2);
207     shape.push_back(3);
208     DataArrayView::ShapeType shape2;
209    
210     // allocate the data for the DataArrayViews
211     DataArrayView::ValueType dataArray(DataArrayView::noValues(shape),0);
212     DataArrayView::ValueType dataArray2(DataArrayView::noValues(shape2),0);
213    
214     // construct DataArrayViews
215     DataArrayView dataView(dataArray,shape);
216     DataArrayView dataView2(dataArray2,shape2);
217    
218     // assign values to the data point
219     for (int i=0;i<shape[0];i++) {
220     for (int j=0;j<shape[1];j++) {
221     dataView(i,j)=dataView.index(i,j);
222     }
223     }
224    
225     // create a few Data objects from the created DataArrayViews
226     DataExpanded dataExp(dataView,FunctionSpace());
227     DataConstant dataCon(dataView,FunctionSpace());
228     DataTagged dataTag(dataCon);
229    
230     // and create Data objects to receive the results of the dp_algorithm calls
231     DataExpanded dataExp2(dataView2,FunctionSpace());
232     DataConstant dataCon2(dataView2,FunctionSpace());
233     DataTagged dataTag2(dataCon2);
234    
235     // test dp_algorithm on DataExpanded
236 jgs 147 FMin fmin_func;
237     escript::dp_algorithm(dataExp,dataExp2,fmin_func,numeric_limits<double>::max());
238 gross 713 assert(std::abs(dataExp2.getDataPoint(0,0)()-0)<=REL_TOL*0);
239 jgs 147 FMax fmax_func;
240     escript::dp_algorithm(dataExp,dataExp2,fmax_func,numeric_limits<double>::max()*-1);
241 gross 713 assert(std::abs(dataExp2.getDataPoint(0,0)()-5)<=REL_TOL*5);
242 jgs 113
243     // test dp_algorithm on DataTagged
244 jgs 147 escript::dp_algorithm(dataTag,dataTag2,fmin_func,numeric_limits<double>::max());
245 gross 713 assert(std::abs(dataTag2.getDataPoint(0,0)()-0)<=REL_TOL*0);
246 jgs 147 escript::dp_algorithm(dataTag,dataTag2,fmax_func,numeric_limits<double>::max()*-1);
247 gross 713 assert(std::abs(dataTag2.getDataPoint(0,0)()-5)<=REL_TOL*5);
248 jgs 113
249     // test dp_algorithm on DataConstant
250 jgs 147 escript::dp_algorithm(dataCon,dataCon2,fmin_func,numeric_limits<double>::max());
251 gross 713 assert(std::abs(dataCon2.getDataPoint(0,0)()-0)<=REL_TOL*0);
252 jgs 147 escript::dp_algorithm(dataCon,dataCon2,fmax_func,numeric_limits<double>::max()*-1);
253 gross 713 assert(std::abs(dataCon2.getDataPoint(0,0)()-5)<=REL_TOL*5);
254 jgs 113
255     }
256    
257     }
258    
259 jgs 82 TestSuite* DataAlgorithmAdapterTestCase::suite ()
260     {
261     //
262     // create the suite of tests to perform.
263     TestSuite *testSuite = new TestSuite ("DataAlgorithmAdapterTestCase");
264    
265     testSuite->addTest (new TestCaller< DataAlgorithmAdapterTestCase>("testAll",&DataAlgorithmAdapterTestCase::testAll));
266 jgs 113 testSuite->addTest (new TestCaller<DataAlgorithmAdapterTestCase>("testAlgorithm",&DataAlgorithmAdapterTestCase::testAlgorithm));
267     testSuite->addTest (new TestCaller<DataAlgorithmAdapterTestCase>("testDpAlgorithm",&DataAlgorithmAdapterTestCase::testDpAlgorithm));
268 jgs 82 return testSuite;
269     }

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.26