15 |
|
|
16 |
#include "DataTestCase.h" |
#include "DataTestCase.h" |
17 |
|
|
|
#include "Data.h" |
|
18 |
#include "FunctionSpace.h" |
#include "FunctionSpace.h" |
19 |
#include "EsysException.h" |
#include "EsysException.h" |
20 |
|
|
21 |
|
#include "Data.h" |
22 |
|
|
23 |
#include <iostream> |
#include <iostream> |
24 |
#include <math.h> |
#include <math.h> |
25 |
|
|
43 |
cout << endl; |
cout << endl; |
44 |
|
|
45 |
{ |
{ |
46 |
|
|
47 |
|
cout << "\tTest get-slicing DataConstant" << endl; |
48 |
|
|
49 |
DataArrayView::ShapeType viewShape; |
DataArrayView::ShapeType viewShape; |
|
// |
|
|
// weak tests for slicing DataConstant |
|
|
cout << "\tTest slicing DataConstant" << endl; |
|
50 |
viewShape.push_back(2); |
viewShape.push_back(2); |
51 |
viewShape.push_back(3); |
viewShape.push_back(3); |
52 |
Data temp(1.3,viewShape,FunctionSpace(),false); |
Data data(1.3,viewShape,FunctionSpace(),false); |
53 |
|
|
54 |
|
//cout << data.toString() << endl; |
55 |
|
|
56 |
DataArrayView::RegionType region; |
DataArrayView::RegionType region; |
57 |
region.push_back(DataArrayView::RegionType::value_type(0,0)); |
region.push_back(DataArrayView::RegionType::value_type(0,0)); |
58 |
region.push_back(DataArrayView::RegionType::value_type(0,0)); |
region.push_back(DataArrayView::RegionType::value_type(0,0)); |
59 |
Data slice(temp.getSlice(region)); |
|
60 |
assert(slice.getDataPointRank()==0); |
Data slice1(data.getSlice(region)); |
61 |
assert(slice.getDataPoint(0,0)()==1.3); |
|
62 |
// |
//cout << slice1.toString() << endl; |
63 |
// try the same but this time to produce a matrix containing one value |
|
64 |
|
assert(slice1.getDataPointRank()==0); |
65 |
|
assert(slice1.getDataPoint(0,0)()==1.3); |
66 |
|
|
67 |
region.clear(); |
region.clear(); |
68 |
region.push_back(DataArrayView::RegionType::value_type(0,1)); |
region.push_back(DataArrayView::RegionType::value_type(0,1)); |
69 |
region.push_back(DataArrayView::RegionType::value_type(0,1)); |
region.push_back(DataArrayView::RegionType::value_type(0,1)); |
70 |
slice=temp.getSlice(region); |
|
71 |
assert(slice.getDataPointRank()==2); |
Data slice2(data.getSlice(region)); |
72 |
assert(slice.getDataPoint(0,0)(0,0)==1.3); |
|
73 |
|
//cout << slice2.toString() << endl; |
74 |
|
|
75 |
|
assert(slice2.getDataPointRank()==2); |
76 |
|
assert(slice2.getDataPoint(0,0)(0,0)==1.3); |
77 |
|
|
78 |
|
region.clear(); |
79 |
|
region.push_back(DataArrayView::RegionType::value_type(0,1)); |
80 |
|
region.push_back(DataArrayView::RegionType::value_type(0,2)); |
81 |
|
|
82 |
|
Data slice3(data.getSlice(region)); |
83 |
|
|
84 |
|
//cout << slice3.toString() << endl; |
85 |
|
|
86 |
|
assert(slice3.getDataPointRank()==2); |
87 |
|
assert(slice3.getDataPoint(0,0)(0,0)==1.3); |
88 |
|
assert(slice3.getDataPoint(0,0)(0,1)==1.3); |
89 |
|
|
90 |
} |
} |
91 |
|
|
92 |
{ |
{ |
93 |
|
|
94 |
|
cout << "\tTest set-slicing DataConstant" << endl; |
95 |
|
|
96 |
DataArrayView::ShapeType viewShape; |
DataArrayView::ShapeType viewShape; |
97 |
|
Data source(10.0,viewShape,FunctionSpace(),false); |
98 |
|
|
99 |
|
//cout << source.toString() << endl; |
100 |
|
|
101 |
|
viewShape.push_back(2); |
102 |
|
viewShape.push_back(3); |
103 |
|
Data target(1.3,viewShape,FunctionSpace(),false); |
104 |
|
|
105 |
|
//cout << target.toString() << endl; |
106 |
|
|
107 |
|
DataArrayView::RegionType region; |
108 |
|
region.push_back(DataArrayView::RegionType::value_type(0,0)); |
109 |
|
region.push_back(DataArrayView::RegionType::value_type(0,0)); |
110 |
|
|
111 |
|
target.setSlice(source,region); |
112 |
|
|
113 |
|
//cout << target.toString() << endl; |
114 |
|
|
115 |
|
assert(target.getDataPoint(0,0)(0,0)==source.getDataPoint(0,0)()); |
116 |
|
|
117 |
|
} |
118 |
|
|
119 |
|
{ |
120 |
|
|
121 |
|
cout << "\tTest get-slicing DataTagged" << endl; |
122 |
|
|
123 |
// |
// |
124 |
// weak tests for slicing DataExpanded |
// create a DataTagged with a default value only |
125 |
cout << "\tTest slicing DataExpanded" << endl; |
|
126 |
|
DataArrayView::ShapeType viewShape; |
127 |
viewShape.push_back(2); |
viewShape.push_back(2); |
128 |
viewShape.push_back(3); |
viewShape.push_back(3); |
129 |
Data temp(1.3,viewShape,FunctionSpace(),true); |
Data data(1.3,viewShape,FunctionSpace(),false); |
130 |
temp.getDataPoint(0,0)(0,0)=0.0; |
data.tag(); |
131 |
temp.getDataPoint(0,0)(1,1)=1.0; |
data.getDataPoint(0,0)(0,0)=1.0; |
132 |
|
data.getDataPoint(0,0)(1,1)=2.0; |
133 |
|
|
134 |
|
//cout << data.toString() << endl; |
135 |
|
|
136 |
|
// |
137 |
|
// create a scalar slice |
138 |
|
|
139 |
DataArrayView::RegionType region; |
DataArrayView::RegionType region; |
140 |
region.push_back(DataArrayView::RegionType::value_type(0,0)); |
region.push_back(DataArrayView::RegionType::value_type(0,0)); |
141 |
region.push_back(DataArrayView::RegionType::value_type(0,0)); |
region.push_back(DataArrayView::RegionType::value_type(0,0)); |
142 |
Data slice(temp.getSlice(region)); |
|
143 |
assert(slice.getDataPointRank()==0); |
Data slice1(data.getSlice(region)); |
144 |
assert(slice.getDataPoint(0,0)()==0.0); |
|
145 |
|
//cout << slice1.toString() << endl; |
146 |
|
|
147 |
|
assert(slice1.isTagged()); |
148 |
|
assert(slice1.getDataPointRank()==0); |
149 |
|
assert(slice1.getDataPoint(0,0)()==1.0); |
150 |
|
|
151 |
// |
// |
152 |
// try the same but this time to produce a matrix containing one value |
// create a rank 2 slice with one value |
153 |
|
|
154 |
region.clear(); |
region.clear(); |
155 |
region.push_back(DataArrayView::RegionType::value_type(0,1)); |
region.push_back(DataArrayView::RegionType::value_type(0,1)); |
156 |
region.push_back(DataArrayView::RegionType::value_type(0,1)); |
region.push_back(DataArrayView::RegionType::value_type(0,1)); |
157 |
slice=temp.getSlice(region); |
|
158 |
assert(slice.getDataPointRank()==2); |
Data slice2(data.getSlice(region)); |
159 |
assert(slice.getDataPoint(0,0)(0,0)==0.0); |
|
160 |
|
//cout << slice2.toString() << endl; |
161 |
|
|
162 |
|
assert(slice2.isTagged()); |
163 |
|
assert(slice2.getDataPointRank()==2); |
164 |
|
assert(slice2.getDataPoint(0,0)(0,0)==1.0); |
165 |
|
|
166 |
|
// |
167 |
|
// create a rank 2 slice with four values |
168 |
|
|
169 |
region.clear(); |
region.clear(); |
170 |
region.push_back(DataArrayView::RegionType::value_type(0,2)); |
region.push_back(DataArrayView::RegionType::value_type(0,2)); |
171 |
region.push_back(DataArrayView::RegionType::value_type(0,2)); |
region.push_back(DataArrayView::RegionType::value_type(0,2)); |
172 |
slice=temp.getSlice(region); |
|
173 |
assert(slice.getDataPoint(0,0)(0,0)==0.0); |
Data slice3(data.getSlice(region)); |
174 |
assert(slice.getDataPoint(0,0)(1,1)==1.0); |
|
175 |
|
//cout << slice3.toString() << endl; |
176 |
|
|
177 |
|
assert(slice3.isTagged()); |
178 |
|
assert(slice3.getDataPointRank()==2); |
179 |
|
assert(slice3.getDataPoint(0,0)(0,0)==1.0); |
180 |
|
assert(slice3.getDataPoint(0,0)(0,1)==1.3); |
181 |
|
assert(slice3.getDataPoint(0,0)(1,0)==1.3); |
182 |
|
assert(slice3.getDataPoint(0,0)(1,1)==2.0); |
183 |
|
|
184 |
|
// |
185 |
|
// add a value for tag "1" |
186 |
|
|
187 |
|
DataArrayView::ValueType viewData(6); |
188 |
|
for (int i=0;i<viewData.size();i++) { |
189 |
|
viewData[i]=i; |
190 |
|
} |
191 |
|
DataArrayView dataView(viewData,viewShape); |
192 |
|
|
193 |
|
data.setTaggedValueFromCPP(1, dataView); |
194 |
|
|
195 |
|
// |
196 |
|
// create a full slice |
197 |
|
|
198 |
|
region.clear(); |
199 |
|
region.push_back(DataArrayView::RegionType::value_type(0,2)); |
200 |
|
region.push_back(DataArrayView::RegionType::value_type(0,3)); |
201 |
|
|
202 |
|
Data slice4(data.getSlice(region)); |
203 |
|
|
204 |
|
//cout << slice4.toString() << endl; |
205 |
|
|
206 |
|
assert(slice4.isTagged()); |
207 |
|
assert(slice4.getDataPointRank()==2); |
208 |
|
assert(slice4.getDataPoint(0,0)(0,0)==0); |
209 |
|
assert(slice4.getDataPoint(0,0)(0,1)==2); |
210 |
|
assert(slice4.getDataPoint(0,0)(0,2)==4); |
211 |
|
assert(slice4.getDataPoint(0,0)(1,0)==1); |
212 |
|
assert(slice4.getDataPoint(0,0)(1,1)==3); |
213 |
|
assert(slice4.getDataPoint(0,0)(1,2)==5); |
214 |
|
|
215 |
} |
} |
216 |
|
|
217 |
{ |
{ |
218 |
|
|
219 |
|
cout << "\tTest set-slicing DataTagged" << endl; |
220 |
|
|
221 |
|
// |
222 |
|
// create a DataTagged with a scalar default value only |
223 |
|
|
224 |
DataArrayView::ShapeType viewShape; |
DataArrayView::ShapeType viewShape; |
225 |
|
Data source(10.0,viewShape,FunctionSpace(),false); |
226 |
|
source.tag(); |
227 |
|
|
228 |
|
//cout << source.toString() << endl; |
229 |
|
|
230 |
// |
// |
231 |
// weak tests for slicing DataTagged |
// create a DataTagged with a rank 2 default value only |
232 |
cout << "\tTest slicing DataTagged" << endl; |
|
233 |
viewShape.push_back(2); |
viewShape.push_back(2); |
234 |
viewShape.push_back(3); |
viewShape.push_back(3); |
235 |
Data temp(1.3,viewShape,FunctionSpace(),false); |
Data target(1.3,viewShape,FunctionSpace(),false); |
236 |
|
target.tag(); |
237 |
|
|
238 |
|
//cout << target.toString() << endl; |
239 |
|
|
240 |
// |
// |
241 |
// convert the data to tagged |
// set a slice in target from source |
242 |
temp.tag(); |
|
243 |
|
DataArrayView::RegionType region; |
244 |
|
region.push_back(DataArrayView::RegionType::value_type(1,1)); |
245 |
|
region.push_back(DataArrayView::RegionType::value_type(1,1)); |
246 |
|
|
247 |
|
target.setSlice(source,region); |
248 |
|
|
249 |
|
//cout << target.toString() << endl; |
250 |
|
|
251 |
|
assert(target.isTagged()); |
252 |
|
assert(target.getDataPointRank()==2); |
253 |
|
assert(target.getDataPoint(0,0)(0,0)==1.3); |
254 |
|
assert(target.getDataPoint(0,0)(0,1)==1.3); |
255 |
|
assert(target.getDataPoint(0,0)(0,2)==1.3); |
256 |
|
assert(target.getDataPoint(0,0)(1,0)==1.3); |
257 |
|
assert(target.getDataPoint(0,0)(1,1)==source.getDataPoint(0,0)()); |
258 |
|
assert(target.getDataPoint(0,0)(1,2)==1.3); |
259 |
|
|
260 |
|
// |
261 |
|
// add a value for tag "1" |
262 |
|
|
263 |
|
DataArrayView::ValueType viewData(6); |
264 |
|
for (int i=0;i<viewData.size();i++) { |
265 |
|
viewData[i]=i; |
266 |
|
} |
267 |
|
DataArrayView dataView(viewData,viewShape); |
268 |
|
|
269 |
|
target.setTaggedValueFromCPP(1, dataView); |
270 |
|
|
271 |
|
// |
272 |
|
// set a slice in target from source |
273 |
|
|
274 |
|
region.clear(); |
275 |
|
region.push_back(DataArrayView::RegionType::value_type(0,0)); |
276 |
|
region.push_back(DataArrayView::RegionType::value_type(1,1)); |
277 |
|
|
278 |
|
target.setSlice(source,region); |
279 |
|
|
280 |
|
//cout << target.toString() << endl; |
281 |
|
|
282 |
|
assert(target.isTagged()); |
283 |
|
assert(target.getDataPointRank()==2); |
284 |
|
assert(target.getDataPoint(0,0)(0,0)==0); |
285 |
|
assert(target.getDataPoint(0,0)(0,1)==source.getDataPoint(0,0)()); |
286 |
|
assert(target.getDataPoint(0,0)(0,2)==4); |
287 |
|
assert(target.getDataPoint(0,0)(1,0)==1); |
288 |
|
assert(target.getDataPoint(0,0)(1,1)==3); |
289 |
|
assert(target.getDataPoint(0,0)(1,2)==5); |
290 |
|
|
291 |
|
} |
292 |
|
|
293 |
|
{ |
294 |
|
|
295 |
|
cout << "\tTest get-slicing DataExpanded" << endl; |
296 |
|
|
297 |
|
DataArrayView::ShapeType viewShape; |
298 |
|
viewShape.push_back(2); |
299 |
|
viewShape.push_back(3); |
300 |
|
Data temp(1.3,viewShape,FunctionSpace(),true); |
301 |
|
|
302 |
temp.getDataPoint(0,0)(0,0)=0.0; |
temp.getDataPoint(0,0)(0,0)=0.0; |
303 |
temp.getDataPoint(0,0)(1,1)=1.0; |
temp.getDataPoint(0,0)(1,1)=1.0; |
304 |
|
|
305 |
DataArrayView::RegionType region; |
DataArrayView::RegionType region; |
306 |
region.push_back(DataArrayView::RegionType::value_type(0,0)); |
region.push_back(DataArrayView::RegionType::value_type(0,0)); |
307 |
region.push_back(DataArrayView::RegionType::value_type(0,0)); |
region.push_back(DataArrayView::RegionType::value_type(0,0)); |
308 |
|
|
309 |
Data slice(temp.getSlice(region)); |
Data slice(temp.getSlice(region)); |
310 |
|
|
311 |
assert(slice.getDataPointRank()==0); |
assert(slice.getDataPointRank()==0); |
312 |
assert(slice.getDataPoint(0,0)()==0.0); |
assert(slice.getDataPoint(0,0)()==0.0); |
313 |
// |
|
|
// try the same but this time to produce a matrix containing one value |
|
314 |
region.clear(); |
region.clear(); |
315 |
region.push_back(DataArrayView::RegionType::value_type(0,1)); |
region.push_back(DataArrayView::RegionType::value_type(0,1)); |
316 |
region.push_back(DataArrayView::RegionType::value_type(0,1)); |
region.push_back(DataArrayView::RegionType::value_type(0,1)); |
317 |
|
|
318 |
slice=temp.getSlice(region); |
slice=temp.getSlice(region); |
319 |
|
|
320 |
assert(slice.getDataPointRank()==2); |
assert(slice.getDataPointRank()==2); |
321 |
assert(slice.getDataPoint(0,0)(0,0)==0.0); |
assert(slice.getDataPoint(0,0)(0,0)==0.0); |
322 |
|
|
323 |
region.clear(); |
region.clear(); |
324 |
region.push_back(DataArrayView::RegionType::value_type(0,2)); |
region.push_back(DataArrayView::RegionType::value_type(0,2)); |
325 |
region.push_back(DataArrayView::RegionType::value_type(0,2)); |
region.push_back(DataArrayView::RegionType::value_type(0,2)); |
326 |
|
|
327 |
slice=temp.getSlice(region); |
slice=temp.getSlice(region); |
328 |
|
|
329 |
assert(slice.getDataPoint(0,0)(0,0)==0.0); |
assert(slice.getDataPoint(0,0)(0,0)==0.0); |
330 |
assert(slice.getDataPoint(0,0)(1,1)==1.0); |
assert(slice.getDataPoint(0,0)(1,1)==1.0); |
|
} |
|
331 |
|
|
|
{ |
|
|
DataArrayView::ShapeType viewShape; |
|
|
Data source(10.0,viewShape,FunctionSpace(),false); |
|
|
// |
|
|
// weak tests for setting a slice of DataConstant |
|
|
cout << "\tTest slicing DataConstant" << endl; |
|
|
viewShape.push_back(2); |
|
|
viewShape.push_back(3); |
|
|
Data target(1.3,viewShape,FunctionSpace(),false); |
|
|
DataArrayView::RegionType region; |
|
|
region.push_back(DataArrayView::RegionType::value_type(0,0)); |
|
|
region.push_back(DataArrayView::RegionType::value_type(0,0)); |
|
|
target.setSlice(source,region); |
|
|
assert(target.getDataPoint(0,0)(0,0)==source.getDataPoint(0,0)()); |
|
332 |
} |
} |
333 |
|
|
334 |
{ |
{ |
335 |
|
|
336 |
|
cout << "\tTest set-slicing DataExpanded" << endl; |
337 |
|
|
338 |
DataArrayView::ShapeType viewShape; |
DataArrayView::ShapeType viewShape; |
339 |
Data source(10.0,viewShape,FunctionSpace(),true); |
Data source(10.0,viewShape,FunctionSpace(),true); |
340 |
// |
|
|
// weak tests for setting a slice of DataExpanded |
|
341 |
viewShape.push_back(2); |
viewShape.push_back(2); |
342 |
viewShape.push_back(3); |
viewShape.push_back(3); |
343 |
Data target(1.3,viewShape,FunctionSpace(),true); |
Data target(1.3,viewShape,FunctionSpace(),true); |
|
DataArrayView::RegionType region; |
|
|
region.push_back(DataArrayView::RegionType::value_type(0,0)); |
|
|
region.push_back(DataArrayView::RegionType::value_type(0,0)); |
|
|
target.setSlice(source,region); |
|
|
assert(target.getDataPoint(0,0)(0,0)==source.getDataPoint(0,0)()); |
|
|
} |
|
344 |
|
|
|
{ |
|
|
DataArrayView::ShapeType viewShape; |
|
|
Data source(10.0,viewShape,FunctionSpace(),false); |
|
|
source.tag(); |
|
|
// |
|
|
// weak tests for slicing DataTagged |
|
|
cout << "\tTest slicing DataTagged" << endl; |
|
|
viewShape.push_back(2); |
|
|
viewShape.push_back(3); |
|
|
Data target(1.3,viewShape,FunctionSpace(),false); |
|
|
// |
|
|
// convert the data to tagged |
|
|
target.tag(); |
|
345 |
DataArrayView::RegionType region; |
DataArrayView::RegionType region; |
346 |
region.push_back(DataArrayView::RegionType::value_type(0,0)); |
region.push_back(DataArrayView::RegionType::value_type(0,0)); |
347 |
region.push_back(DataArrayView::RegionType::value_type(0,0)); |
region.push_back(DataArrayView::RegionType::value_type(0,0)); |
348 |
|
|
349 |
target.setSlice(source,region); |
target.setSlice(source,region); |
350 |
|
|
351 |
assert(target.getDataPoint(0,0)(0,0)==source.getDataPoint(0,0)()); |
assert(target.getDataPoint(0,0)(0,0)==source.getDataPoint(0,0)()); |
352 |
|
|
353 |
} |
} |
354 |
|
|
355 |
} |
} |