1 |
ksteube |
1312 |
|
2 |
|
|
/******************************************************* |
3 |
ksteube |
1811 |
* |
4 |
jfenwick |
2881 |
* Copyright (c) 2003-2010 by University of Queensland |
5 |
ksteube |
1811 |
* Earth Systems Science Computational Center (ESSCC) |
6 |
|
|
* http://www.uq.edu.au/esscc |
7 |
|
|
* |
8 |
|
|
* Primary Business: Queensland, Australia |
9 |
|
|
* Licensed under the Open Software License version 3.0 |
10 |
|
|
* http://www.opensource.org/licenses/osl-3.0.php |
11 |
|
|
* |
12 |
|
|
*******************************************************/ |
13 |
ksteube |
1312 |
|
14 |
ksteube |
1811 |
|
15 |
robwdcock |
670 |
#include "escript/FunctionSpace.h" |
16 |
|
|
#include "escript/DataExpanded.h" |
17 |
robwdcock |
638 |
#include "esysUtils/EsysException.h" |
18 |
jgs |
82 |
#include "DataExpandedTestCase.h" |
19 |
jfenwick |
2005 |
#include "escript/DataReady.h" |
20 |
jgs |
82 |
|
21 |
|
|
#include <iostream> |
22 |
|
|
|
23 |
|
|
using namespace CppUnitTest; |
24 |
|
|
using namespace escript; |
25 |
|
|
using namespace std; |
26 |
|
|
using namespace esysUtils; |
27 |
jfenwick |
1796 |
using namespace escript::DataTypes; |
28 |
jgs |
82 |
|
29 |
|
|
void DataExpandedTestCase::setUp() { |
30 |
|
|
// |
31 |
|
|
// This is called before each test is run |
32 |
|
|
|
33 |
|
|
} |
34 |
|
|
|
35 |
|
|
void DataExpandedTestCase::tearDown() { |
36 |
|
|
// |
37 |
|
|
// This is called after each test has been run |
38 |
|
|
|
39 |
|
|
} |
40 |
|
|
|
41 |
jfenwick |
1796 |
namespace |
42 |
|
|
{ |
43 |
|
|
|
44 |
jfenwick |
2271 |
ValueType::const_reference |
45 |
|
|
getRefRO(DataReady& data,int i, int j) |
46 |
jfenwick |
1796 |
{ |
47 |
jfenwick |
2271 |
return data.getVectorRO()[getRelIndex(data.getShape(),i,j)]; |
48 |
jfenwick |
1796 |
} |
49 |
|
|
|
50 |
jfenwick |
2271 |
ValueType::const_reference |
51 |
|
|
getRefRO(DataReady& data,int i, int j,int k) |
52 |
jfenwick |
1796 |
{ |
53 |
jfenwick |
2271 |
return data.getVectorRO()[getRelIndex(data.getShape(),i,j,k)]; |
54 |
jfenwick |
1796 |
} |
55 |
|
|
|
56 |
|
|
ValueType::reference |
57 |
|
|
getDRef(ValueType& data,const ShapeType& shape,int i, int j) |
58 |
|
|
{ |
59 |
|
|
return data[getRelIndex(shape,i,j)]; |
60 |
|
|
} |
61 |
|
|
|
62 |
|
|
ValueType::reference |
63 |
|
|
getDRef(ValueType& data,const ShapeType& shape,int i, int j, int k) |
64 |
|
|
{ |
65 |
|
|
return data[getRelIndex(shape,i,j,k)]; |
66 |
|
|
} |
67 |
|
|
|
68 |
jfenwick |
2005 |
DataReady_ptr |
69 |
|
|
resolveAndDelete(DataAbstract* p) |
70 |
|
|
{ |
71 |
|
|
DataReady_ptr p2=p->resolve(); |
72 |
|
|
if (p!=p2.get()) |
73 |
|
|
{ |
74 |
|
|
delete p; |
75 |
|
|
} |
76 |
|
|
return p2; |
77 |
jfenwick |
1796 |
} |
78 |
|
|
|
79 |
jfenwick |
2005 |
} |
80 |
jfenwick |
1796 |
|
81 |
jfenwick |
2005 |
|
82 |
jgs |
102 |
void DataExpandedTestCase::testAll() { |
83 |
|
|
|
84 |
|
|
cout << endl; |
85 |
|
|
|
86 |
|
|
// |
87 |
|
|
// Create a rank 1 pointData |
88 |
jfenwick |
1796 |
DataTypes::ShapeType shape; |
89 |
jgs |
102 |
shape.push_back(3); |
90 |
jfenwick |
1796 |
DataTypes::ValueType data(DataTypes::noValues(shape),0); |
91 |
|
|
// DataArrayView pointData(data,shape); |
92 |
jgs |
102 |
|
93 |
|
|
// |
94 |
|
|
// Assign an arbitrary value |
95 |
jfenwick |
1796 |
data[0]=0.0; |
96 |
|
|
data[1]=1.0; |
97 |
|
|
data[2]=2.0; |
98 |
jgs |
102 |
|
99 |
|
|
// |
100 |
|
|
// Test constructor |
101 |
|
|
cout << "\tTest DataExpanded constructor." << endl; |
102 |
jfenwick |
1796 |
DataExpanded testData(FunctionSpace(), shape, data); |
103 |
jgs |
102 |
|
104 |
jfenwick |
1796 |
// cout << "\tTest getLength." << endl; |
105 |
|
|
// assert(testData.getLength()==pointData.getNoValues()); |
106 |
jgs |
102 |
|
107 |
jfenwick |
1796 |
cout << "\tTest getDataAtOffset." << endl; |
108 |
|
|
for (int i=0;i<testData.getShape()[0];i++) { |
109 |
jfenwick |
2271 |
assert(testData.getDataAtOffsetRO(i)==data[i]); |
110 |
jgs |
102 |
} |
111 |
|
|
|
112 |
|
|
cout << "\tVerify data point attributes." << endl; |
113 |
jfenwick |
1796 |
// DataArrayView dataView=testData.getPointDataView(); |
114 |
|
|
assert(testData.getRank()==shape.size()); |
115 |
|
|
assert(testData.getNoValues()==shape[0]*1); |
116 |
|
|
assert(testData.getShape()[0]==shape[0]); |
117 |
jgs |
117 |
assert(testData.getNumDPPSample()==1); |
118 |
|
|
assert(testData.getNumSamples()==1); |
119 |
|
|
assert(testData.validSamplePointNo(testData.getNumDPPSample()-1)); |
120 |
|
|
assert(testData.validSampleNo(testData.getNumSamples()-1)); |
121 |
jgs |
102 |
|
122 |
|
|
// |
123 |
jgs |
119 |
// Test alternative constructor |
124 |
|
|
cout << "\tTest DataExpanded alternative constructor." << endl; |
125 |
|
|
data[0]=0.0; |
126 |
|
|
data[1]=1.0; |
127 |
|
|
data[2]=2.0; |
128 |
phornby |
152 |
FunctionSpace tmp_fns; |
129 |
|
|
DataExpanded testData1(tmp_fns,shape,data); |
130 |
jgs |
119 |
|
131 |
jfenwick |
1796 |
// cout << "\tTest getLength." << endl; |
132 |
|
|
// assert(testData1.getLength()==pointData.noValues()); |
133 |
jgs |
119 |
|
134 |
jfenwick |
1796 |
// cout << "\tTest getPointDataView." << endl; |
135 |
|
|
// for (int i=0;i<testData1.getPointDataView().getShape()[0];i++) { |
136 |
|
|
// assert(testData1.getPointDataView()(i)==pointData(i)); |
137 |
|
|
// } |
138 |
jgs |
119 |
|
139 |
|
|
cout << "\tVerify data point attributes." << endl; |
140 |
jfenwick |
1796 |
// dataView=testData1.getPointDataView(); |
141 |
|
|
assert(testData1.getRank()==shape.size()); |
142 |
|
|
assert(testData1.getNoValues()==shape[0]*1); |
143 |
|
|
assert(testData1.getShape()[0]==shape[0]); |
144 |
|
|
assert(testData1.getNumDPPSample()==1); |
145 |
|
|
assert(testData1.getNumSamples()==1); |
146 |
|
|
assert(testData1.validSamplePointNo(testData1.getNumDPPSample()-1)); |
147 |
|
|
assert(testData1.validSampleNo(testData1.getNumSamples()-1)); |
148 |
jgs |
119 |
|
149 |
|
|
// |
150 |
jgs |
102 |
// Test copy constructor |
151 |
|
|
cout << "\tTest DataExpanded copy constructor." << endl; |
152 |
|
|
DataExpanded testData2(testData); |
153 |
|
|
|
154 |
|
|
cout << "\tTest getLength." << endl; |
155 |
jfenwick |
1796 |
assert(testData2.getLength()==data.size()); |
156 |
jgs |
102 |
|
157 |
|
|
cout << "\tTest getPointDataView." << endl; |
158 |
jfenwick |
1796 |
for (int i=0;i<testData2.getShape()[0];i++) { |
159 |
jfenwick |
2271 |
assert(testData2.getDataAtOffsetRO(i)==data[i]); |
160 |
jgs |
102 |
} |
161 |
|
|
|
162 |
|
|
cout << "\tVerify data point attributes." << endl; |
163 |
jfenwick |
1796 |
// dataView=testData2.getPointDataView(); |
164 |
|
|
assert(testData2.getRank()==shape.size()); |
165 |
|
|
assert(testData2.getNoValues()==shape[0]*1); |
166 |
|
|
assert(testData2.getShape()[0]==shape[0]); |
167 |
jgs |
117 |
assert(testData2.getNumDPPSample()==1); |
168 |
|
|
assert(testData2.getNumSamples()==1); |
169 |
|
|
assert(testData2.validSamplePointNo(testData2.getNumDPPSample()-1)); |
170 |
|
|
assert(testData2.validSampleNo(testData2.getNumSamples()-1)); |
171 |
jgs |
102 |
|
172 |
|
|
} |
173 |
|
|
|
174 |
jgs |
82 |
|
175 |
jgs |
102 |
void DataExpandedTestCase::testSlicing() { |
176 |
jgs |
82 |
|
177 |
|
|
cout << endl; |
178 |
|
|
|
179 |
|
|
// |
180 |
jgs |
102 |
// Create a rank 1 pointData |
181 |
jfenwick |
1796 |
DataTypes::ShapeType shape; |
182 |
jgs |
82 |
shape.push_back(3); |
183 |
jfenwick |
1796 |
DataTypes::ValueType data(DataTypes::noValues(shape),0); |
184 |
|
|
// DataArrayView pointData(data,shape); |
185 |
jgs |
82 |
|
186 |
|
|
// |
187 |
jgs |
102 |
// Assign an arbitrary value |
188 |
jfenwick |
1796 |
data[0]=0.0; |
189 |
|
|
data[1]=1.0; |
190 |
|
|
data[2]=2.0; |
191 |
jgs |
82 |
|
192 |
jgs |
102 |
// |
193 |
|
|
// Create object to test |
194 |
|
|
cout << "\tCreate rank 1 DataExpanded object." << endl; |
195 |
jfenwick |
1796 |
DataExpanded testData(FunctionSpace(),shape,data); |
196 |
jgs |
82 |
|
197 |
jgs |
102 |
cout << "\tTest slicing (whole object)." << endl; |
198 |
jfenwick |
1796 |
DataTypes::RegionType region; |
199 |
|
|
region.push_back(DataTypes::RegionType::value_type(0,shape[0])); |
200 |
jgs |
149 |
|
201 |
jfenwick |
2005 |
DataReady_ptr testData2=resolveAndDelete(testData.getSlice(region)); |
202 |
jgs |
102 |
|
203 |
jgs |
82 |
// |
204 |
jgs |
102 |
// Verify data values |
205 |
|
|
cout << "\tVerify data point values." << endl; |
206 |
jfenwick |
1796 |
for (int i=0;i<testData2->getShape()[0];i++) { |
207 |
jfenwick |
2271 |
assert(testData2->getDataAtOffsetRO(i)==data[region[0].first+i]); |
208 |
jgs |
102 |
} |
209 |
|
|
} |
210 |
|
|
|
211 |
|
|
void DataExpandedTestCase::testSlicing2() { |
212 |
|
|
|
213 |
|
|
cout << endl; |
214 |
|
|
|
215 |
|
|
// |
216 |
|
|
// Create a rank 2 pointData |
217 |
jfenwick |
1796 |
DataTypes::ShapeType shape; |
218 |
jgs |
102 |
shape.push_back(3); |
219 |
|
|
shape.push_back(3); |
220 |
jfenwick |
1796 |
DataTypes::ValueType data(DataTypes::noValues(shape),0); |
221 |
|
|
// DataArrayView pointData(data,shape); |
222 |
jgs |
102 |
|
223 |
|
|
// |
224 |
|
|
// Assign an arbitrary value |
225 |
jfenwick |
1796 |
getDRef(data,shape,0,0)=0.0; |
226 |
|
|
getDRef(data,shape,1,0)=1.0; |
227 |
|
|
getDRef(data,shape,2,0)=2.0; |
228 |
|
|
getDRef(data,shape,0,1)=3.0; |
229 |
|
|
getDRef(data,shape,1,1)=4.0; |
230 |
|
|
getDRef(data,shape,2,1)=5.0; |
231 |
|
|
getDRef(data,shape,0,2)=6.0; |
232 |
|
|
getDRef(data,shape,1,2)=7.0; |
233 |
|
|
getDRef(data,shape,2,2)=8.0; |
234 |
jgs |
102 |
|
235 |
|
|
// |
236 |
|
|
// Create object to test |
237 |
|
|
cout << "\tCreate rank 2 DataExpanded object." << endl; |
238 |
jfenwick |
1796 |
DataExpanded testData(FunctionSpace(),shape,data); |
239 |
jgs |
82 |
|
240 |
jgs |
102 |
cout << "\tTest slicing (part object)." << endl; |
241 |
jfenwick |
1796 |
DataTypes::RegionType region; |
242 |
|
|
region.push_back(DataTypes::RegionType::value_type(0,2)); |
243 |
|
|
region.push_back(DataTypes::RegionType::value_type(0,2)); |
244 |
jfenwick |
2005 |
|
245 |
|
|
DataReady_ptr testData2=resolveAndDelete(testData.getSlice(region)); |
246 |
jgs |
82 |
|
247 |
jgs |
102 |
// |
248 |
|
|
// Verify data values |
249 |
|
|
cout << "\tVerify data point values." << endl; |
250 |
jfenwick |
1796 |
for (int j=0;j<testData2->getShape()[1];j++) { |
251 |
|
|
for (int i=0;i<testData2->getShape()[0];i++) { |
252 |
jfenwick |
2271 |
assert(getRefRO(*testData2,i,j)==data[getRelIndex(shape,region[0].first+i,region[1].first+j)]); |
253 |
jgs |
102 |
} |
254 |
|
|
} |
255 |
jgs |
82 |
|
256 |
jgs |
102 |
cout << "\tVerify data point attributes." << endl; |
257 |
jfenwick |
1796 |
// DataArrayView dataView=testData2->getPointDataView(); |
258 |
|
|
assert(testData2->getRank()==region.size()); |
259 |
|
|
assert(testData2->getNoValues()==(region[0].second-region[0].first)*(region[1].second-region[1].first)); |
260 |
|
|
assert(testData2->getShape()[0]==(region[0].second-region[0].first)); |
261 |
|
|
assert(testData2->getShape()[1]==(region[1].second-region[1].first)); |
262 |
jgs |
82 |
|
263 |
jgs |
102 |
cout << "\tTest slicing (part object)." << endl; |
264 |
jfenwick |
1796 |
DataTypes::RegionType region2; |
265 |
|
|
region2.push_back(DataTypes::RegionType::value_type(1,3)); |
266 |
|
|
region2.push_back(DataTypes::RegionType::value_type(1,3)); |
267 |
jfenwick |
2005 |
DataReady_ptr testData3=resolveAndDelete(testData.getSlice(region2)); |
268 |
jgs |
102 |
// |
269 |
|
|
// Verify data values |
270 |
|
|
cout << "\tVerify data point values." << endl; |
271 |
jfenwick |
1796 |
for (int j=0;j<testData3->getShape()[1];j++) { |
272 |
|
|
for (int i=0;i<testData3->getShape()[0];i++) { |
273 |
jfenwick |
2271 |
assert(getRefRO(*testData3,i,j)==getDRef(data,shape,region2[0].first+i,region2[1].first+j)); |
274 |
jgs |
102 |
} |
275 |
|
|
} |
276 |
|
|
|
277 |
|
|
cout << "\tVerify data point attributes." << endl; |
278 |
jfenwick |
1796 |
// dataView=testData3->getPointDataView(); |
279 |
|
|
assert(testData3->getRank()==region2.size()); |
280 |
|
|
assert(testData3->getNoValues()==(region2[0].second-region2[0].first)*(region2[1].second-region2[1].first)); |
281 |
|
|
assert(testData3->getShape()[0]==(region2[0].second-region2[0].first)); |
282 |
|
|
assert(testData3->getShape()[1]==(region2[1].second-region2[1].first)); |
283 |
jgs |
102 |
|
284 |
jfenwick |
2005 |
// delete testData2; |
285 |
|
|
// delete testData3; |
286 |
jgs |
149 |
|
287 |
jgs |
82 |
} |
288 |
|
|
|
289 |
jgs |
102 |
void DataExpandedTestCase::testSlicing3() { |
290 |
|
|
|
291 |
|
|
cout << endl; |
292 |
|
|
|
293 |
|
|
// |
294 |
|
|
// Create a rank 3 pointData |
295 |
jfenwick |
1796 |
DataTypes::ShapeType shape; |
296 |
jgs |
102 |
shape.push_back(3); |
297 |
|
|
shape.push_back(3); |
298 |
|
|
shape.push_back(3); |
299 |
jfenwick |
1796 |
DataTypes::ValueType data(DataTypes::noValues(shape),0); |
300 |
|
|
// DataArrayView pointData(data,shape); |
301 |
jgs |
102 |
|
302 |
|
|
// |
303 |
|
|
// Assign an arbitrary value |
304 |
jfenwick |
1796 |
getDRef(data,shape,0,0,0)=0.0; |
305 |
|
|
getDRef(data,shape,1,0,0)=1.0; |
306 |
|
|
getDRef(data,shape,2,0,0)=2.0; |
307 |
|
|
getDRef(data,shape,0,1,0)=3.0; |
308 |
|
|
getDRef(data,shape,1,1,0)=4.0; |
309 |
|
|
getDRef(data,shape,2,1,0)=5.0; |
310 |
|
|
getDRef(data,shape,0,2,0)=6.0; |
311 |
|
|
getDRef(data,shape,1,2,0)=7.0; |
312 |
|
|
getDRef(data,shape,2,2,0)=8.0; |
313 |
jgs |
102 |
|
314 |
jfenwick |
1796 |
getDRef(data,shape,0,0,1)=9.0; |
315 |
|
|
getDRef(data,shape,1,0,1)=10.0; |
316 |
|
|
getDRef(data,shape,2,0,1)=11.0; |
317 |
|
|
getDRef(data,shape,0,1,1)=12.0; |
318 |
|
|
getDRef(data,shape,1,1,1)=13.0; |
319 |
|
|
getDRef(data,shape,2,1,1)=14.0; |
320 |
|
|
getDRef(data,shape,0,2,1)=15.0; |
321 |
|
|
getDRef(data,shape,1,2,1)=16.0; |
322 |
|
|
getDRef(data,shape,2,2,1)=17.0; |
323 |
jgs |
102 |
|
324 |
jfenwick |
1796 |
getDRef(data,shape,0,0,2)=18.0; |
325 |
|
|
getDRef(data,shape,1,0,2)=19.0; |
326 |
|
|
getDRef(data,shape,2,0,2)=20.0; |
327 |
|
|
getDRef(data,shape,0,1,2)=21.0; |
328 |
|
|
getDRef(data,shape,1,1,2)=22.0; |
329 |
|
|
getDRef(data,shape,2,1,2)=23.0; |
330 |
|
|
getDRef(data,shape,0,2,2)=24.0; |
331 |
|
|
getDRef(data,shape,1,2,2)=25.0; |
332 |
|
|
getDRef(data,shape,2,2,2)=26.0; |
333 |
jgs |
102 |
|
334 |
|
|
// |
335 |
|
|
// Create object to test |
336 |
|
|
cout << "\tCreate rank 3 DataExpanded object." << endl; |
337 |
jfenwick |
1796 |
DataExpanded testData(FunctionSpace(),shape,data); |
338 |
jgs |
102 |
|
339 |
|
|
cout << "\tTest slicing (part object)." << endl; |
340 |
jfenwick |
1796 |
DataTypes::RegionType region; |
341 |
|
|
region.push_back(DataTypes::RegionType::value_type(0,2)); |
342 |
|
|
region.push_back(DataTypes::RegionType::value_type(0,2)); |
343 |
|
|
region.push_back(DataTypes::RegionType::value_type(0,2)); |
344 |
jfenwick |
2005 |
DataReady_ptr testData2=resolveAndDelete(testData.getSlice(region)); |
345 |
jgs |
102 |
|
346 |
|
|
// |
347 |
|
|
// Verify data values |
348 |
|
|
cout << "\tVerify data point values." << endl; |
349 |
jfenwick |
1796 |
for (int k=0;k<testData2->getShape()[2];k++) { |
350 |
|
|
for (int j=0;j<testData2->getShape()[1];j++) { |
351 |
|
|
for (int i=0;i<testData2->getShape()[0];i++) { |
352 |
jfenwick |
2271 |
assert(getRefRO(*testData2,i,j,k)==getDRef(data,shape,region[0].first+i, |
353 |
jgs |
102 |
region[1].first+j, |
354 |
|
|
region[2].first+k)); |
355 |
|
|
} |
356 |
|
|
} |
357 |
|
|
} |
358 |
|
|
|
359 |
|
|
cout << "\tVerify data point attributes." << endl; |
360 |
jfenwick |
1796 |
// DataArrayView dataView=testData2->getPointDataView(); |
361 |
|
|
assert(testData2->getRank()==region.size()); |
362 |
|
|
assert(testData2->getNoValues()==(region[0].second-region[0].first) |
363 |
jgs |
102 |
*(region[1].second-region[1].first) |
364 |
|
|
*(region[2].second-region[2].first)); |
365 |
jfenwick |
1796 |
assert(testData2->getShape()[0]==(region[0].second-region[0].first)); |
366 |
|
|
assert(testData2->getShape()[1]==(region[1].second-region[1].first)); |
367 |
|
|
assert(testData2->getShape()[2]==(region[2].second-region[2].first)); |
368 |
jgs |
102 |
|
369 |
|
|
cout << "\tTest slicing (part object)." << endl; |
370 |
jfenwick |
1796 |
DataTypes::RegionType region2; |
371 |
|
|
region2.push_back(DataTypes::RegionType::value_type(1,3)); |
372 |
|
|
region2.push_back(DataTypes::RegionType::value_type(1,3)); |
373 |
|
|
region2.push_back(DataTypes::RegionType::value_type(1,3)); |
374 |
jfenwick |
2005 |
DataReady_ptr testData3=resolveAndDelete(testData.getSlice(region2)); |
375 |
jgs |
102 |
|
376 |
|
|
// |
377 |
|
|
// Verify data values |
378 |
|
|
cout << "\tVerify data point values." << endl; |
379 |
jfenwick |
1796 |
for (int k=0;k<testData3->getShape()[2];k++) { |
380 |
|
|
for (int j=0;j<testData3->getShape()[1];j++) { |
381 |
|
|
for (int i=0;i<testData3->getShape()[0];i++) { |
382 |
jfenwick |
2271 |
assert(getRefRO(*testData3,i,j,k)==getDRef(data,shape,region2[0].first+i, |
383 |
jgs |
102 |
region2[1].first+j, |
384 |
|
|
region2[2].first+k)); |
385 |
|
|
} |
386 |
|
|
} |
387 |
|
|
} |
388 |
|
|
|
389 |
|
|
cout << "\tVerify data point attributes." << endl; |
390 |
jfenwick |
1796 |
// dataView=testData2->getPointDataView(); |
391 |
|
|
assert(testData2->getRank()==region.size()); |
392 |
|
|
assert(testData2->getNoValues()==(region[0].second-region[0].first) |
393 |
jgs |
102 |
*(region[1].second-region[1].first) |
394 |
|
|
*(region[2].second-region[2].first)); |
395 |
jfenwick |
1796 |
assert(testData2->getShape()[0]==(region[0].second-region[0].first)); |
396 |
|
|
assert(testData2->getShape()[1]==(region[1].second-region[1].first)); |
397 |
|
|
assert(testData2->getShape()[2]==(region[2].second-region[2].first)); |
398 |
jgs |
102 |
|
399 |
jfenwick |
2005 |
// delete testData2; |
400 |
|
|
// delete testData3; |
401 |
jgs |
149 |
|
402 |
jgs |
102 |
} |
403 |
|
|
|
404 |
|
|
|
405 |
|
|
void DataExpandedTestCase::testSliceSetting() { |
406 |
|
|
|
407 |
|
|
cout << endl; |
408 |
|
|
|
409 |
|
|
// |
410 |
|
|
// Create a rank 2 pointData |
411 |
jfenwick |
1796 |
DataTypes::ShapeType shape; |
412 |
jgs |
102 |
shape.push_back(2); |
413 |
|
|
shape.push_back(2); |
414 |
jfenwick |
1796 |
DataTypes::ValueType data(DataTypes::noValues(shape),0); |
415 |
|
|
// DataArrayView pointData(data,shape); |
416 |
jgs |
102 |
|
417 |
|
|
// |
418 |
|
|
// Assign an arbitrary value |
419 |
jfenwick |
1796 |
data[getRelIndex(shape,0,0)]=0.0; |
420 |
|
|
data[getRelIndex(shape,0,1)]=1.0; |
421 |
|
|
data[getRelIndex(shape,1,0)]=2.0; |
422 |
|
|
data[getRelIndex(shape,1,1)]=3.0; |
423 |
jgs |
102 |
|
424 |
|
|
// |
425 |
|
|
// Create object to test |
426 |
|
|
cout << "\tCreate rank 2 DataExpanded object." << endl; |
427 |
jfenwick |
1796 |
DataExpanded testData(FunctionSpace(),shape,data); |
428 |
jgs |
102 |
|
429 |
|
|
// |
430 |
|
|
// Create another rank 2 pointData |
431 |
jfenwick |
1796 |
DataTypes::ShapeType shape2; |
432 |
jgs |
102 |
shape2.push_back(3); |
433 |
|
|
shape2.push_back(3); |
434 |
jfenwick |
1796 |
DataTypes::ValueType data2(DataTypes::noValues(shape2),0); |
435 |
|
|
// DataArrayView pointData2(data2,shape2); |
436 |
jgs |
102 |
|
437 |
|
|
// |
438 |
|
|
// Assign an arbitrary value |
439 |
jfenwick |
1796 |
data2[getRelIndex(shape2,0,0)]=0.1; |
440 |
|
|
data2[getRelIndex(shape2,0,1)]=1.1; |
441 |
|
|
data2[getRelIndex(shape2,0,2)]=2.1; |
442 |
|
|
data2[getRelIndex(shape2,1,0)]=3.1; |
443 |
|
|
data2[getRelIndex(shape2,1,1)]=4.1; |
444 |
|
|
data2[getRelIndex(shape2,1,2)]=5.1; |
445 |
|
|
data2[getRelIndex(shape2,2,0)]=6.1; |
446 |
|
|
data2[getRelIndex(shape2,2,1)]=7.1; |
447 |
|
|
data2[getRelIndex(shape2,2,2)]=8.1; |
448 |
jgs |
102 |
|
449 |
|
|
// |
450 |
|
|
// Create object to test |
451 |
|
|
cout << "\tCreate second rank 2 DataExpanded object." << endl; |
452 |
jfenwick |
1796 |
DataExpanded testData2(FunctionSpace(),shape2,data2); |
453 |
jgs |
102 |
|
454 |
|
|
cout << "\tTest slice setting (1)." << endl; |
455 |
|
|
|
456 |
jfenwick |
1796 |
DataTypes::RegionType region; |
457 |
|
|
region.push_back(DataTypes::RegionType::value_type(0,2)); |
458 |
|
|
region.push_back(DataTypes::RegionType::value_type(0,2)); |
459 |
jgs |
102 |
|
460 |
jfenwick |
1796 |
DataTypes::RegionType region2; |
461 |
|
|
region2.push_back(DataTypes::RegionType::value_type(1,3)); |
462 |
|
|
region2.push_back(DataTypes::RegionType::value_type(1,3)); |
463 |
jgs |
102 |
|
464 |
|
|
DataAbstract* testData3=testData.getSlice(region); |
465 |
|
|
|
466 |
|
|
testData2.setSlice(testData3,region2); |
467 |
|
|
// |
468 |
|
|
// Verify data values |
469 |
|
|
cout << "\tVerify data point values." << endl; |
470 |
|
|
for (int j=region2[1].first;j<region2[1].second;j++) { |
471 |
|
|
for (int i=region2[0].first;i<region2[0].second;i++) { |
472 |
jfenwick |
2271 |
assert(getRefRO(testData2,i,j)==data[getRelIndex(shape,i-(region[0].second-1),j-(region[1].second-1))]); |
473 |
jgs |
102 |
} |
474 |
|
|
} |
475 |
|
|
|
476 |
jgs |
149 |
delete testData3; |
477 |
|
|
|
478 |
jgs |
102 |
} |
479 |
|
|
|
480 |
|
|
void DataExpandedTestCase::testSliceSetting2() { |
481 |
|
|
|
482 |
|
|
cout << endl; |
483 |
|
|
|
484 |
|
|
// |
485 |
|
|
// Create a rank 0 pointData |
486 |
jfenwick |
1796 |
DataTypes::ShapeType shape; |
487 |
|
|
DataTypes::ValueType data(DataTypes::noValues(shape),0); |
488 |
|
|
// DataArrayView pointData(data,shape); |
489 |
jgs |
102 |
|
490 |
|
|
// |
491 |
|
|
// Assign an arbitrary value |
492 |
jfenwick |
1796 |
data[0]=0.0; |
493 |
jgs |
102 |
|
494 |
|
|
// |
495 |
|
|
// Create object to test |
496 |
|
|
cout << "\tCreate rank 0 DataExpanded object." << endl; |
497 |
jfenwick |
1796 |
DataExpanded testData(FunctionSpace(),shape,data); |
498 |
jgs |
102 |
|
499 |
|
|
// |
500 |
|
|
// Create a rank 2 pointData |
501 |
jfenwick |
1796 |
DataTypes::ShapeType shape2; |
502 |
jgs |
102 |
shape2.push_back(3); |
503 |
|
|
shape2.push_back(3); |
504 |
jfenwick |
1796 |
DataTypes::ValueType data2(DataTypes::noValues(shape2),0); |
505 |
|
|
// DataArrayView pointData2(data2,shape2); |
506 |
jgs |
102 |
|
507 |
|
|
// |
508 |
|
|
// Assign an arbitrary value |
509 |
jfenwick |
1796 |
data2[getRelIndex(shape2,0,0)]=0.1; |
510 |
|
|
data2[getRelIndex(shape2,0,1)]=1.1; |
511 |
|
|
data2[getRelIndex(shape2,0,2)]=2.1; |
512 |
|
|
data2[getRelIndex(shape2,1,0)]=3.1; |
513 |
|
|
data2[getRelIndex(shape2,1,1)]=4.1; |
514 |
|
|
data2[getRelIndex(shape2,1,2)]=5.1; |
515 |
|
|
data2[getRelIndex(shape2,2,0)]=6.1; |
516 |
|
|
data2[getRelIndex(shape2,2,1)]=7.1; |
517 |
|
|
data2[getRelIndex(shape2,2,2)]=8.1; |
518 |
jgs |
102 |
|
519 |
|
|
// |
520 |
|
|
// Create object to test |
521 |
|
|
cout << "\tCreate rank 2 DataExpanded object." << endl; |
522 |
jfenwick |
1796 |
DataExpanded testData2(FunctionSpace(),shape2, data2); |
523 |
jgs |
102 |
|
524 |
|
|
cout << "\tTest slice setting (1)." << endl; |
525 |
|
|
|
526 |
jfenwick |
1796 |
DataTypes::RegionType region; |
527 |
jgs |
102 |
|
528 |
jfenwick |
1796 |
DataTypes::RegionType region2; |
529 |
|
|
region2.push_back(DataTypes::RegionType::value_type(1,1)); |
530 |
|
|
region2.push_back(DataTypes::RegionType::value_type(1,1)); |
531 |
jgs |
102 |
|
532 |
|
|
DataAbstract* testData3=testData.getSlice(region); |
533 |
|
|
|
534 |
|
|
testData2.setSlice(testData3,region2); |
535 |
|
|
|
536 |
|
|
// |
537 |
|
|
// Verify data values |
538 |
|
|
cout << "\tVerify data point values." << endl; |
539 |
|
|
for (int j=region2[1].first;j<region2[1].second;j++) { |
540 |
|
|
for (int i=region2[0].first;i<region2[0].second;i++) { |
541 |
jfenwick |
2271 |
assert(getRefRO(testData2,i,j)==data[0]); |
542 |
jgs |
102 |
} |
543 |
|
|
} |
544 |
|
|
|
545 |
jgs |
149 |
delete testData3; |
546 |
|
|
|
547 |
jgs |
102 |
} |
548 |
|
|
|
549 |
jgs |
110 |
|
550 |
jfenwick |
1796 |
|
551 |
|
|
|
552 |
|
|
|
553 |
jgs |
82 |
TestSuite* DataExpandedTestCase::suite () |
554 |
|
|
{ |
555 |
|
|
// |
556 |
jgs |
102 |
// Create the suite of tests to perform. |
557 |
jgs |
82 |
TestSuite *testSuite = new TestSuite ("DataExpandedTestCase"); |
558 |
|
|
testSuite->addTest (new TestCaller< DataExpandedTestCase>("testAll",&DataExpandedTestCase::testAll)); |
559 |
jgs |
102 |
testSuite->addTest (new TestCaller< DataExpandedTestCase>("testSlicing",&DataExpandedTestCase::testSlicing)); |
560 |
|
|
testSuite->addTest (new TestCaller< DataExpandedTestCase>("testSlicing2",&DataExpandedTestCase::testSlicing2)); |
561 |
|
|
testSuite->addTest (new TestCaller< DataExpandedTestCase>("testSlicing3",&DataExpandedTestCase::testSlicing3)); |
562 |
|
|
testSuite->addTest (new TestCaller< DataExpandedTestCase>("testSliceSetting",&DataExpandedTestCase::testSliceSetting)); |
563 |
|
|
testSuite->addTest (new TestCaller< DataExpandedTestCase>("testSliceSetting2",&DataExpandedTestCase::testSliceSetting2)); |
564 |
jgs |
82 |
return testSuite; |
565 |
|
|
} |