/[escript]/trunk/escript/test/DataTaggedTestCase.cpp
ViewVC logotype

Contents of /trunk/escript/test/DataTaggedTestCase.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3597 - (show annotations)
Thu Sep 15 06:03:17 2011 UTC (8 years, 2 months ago) by caltinay
File size: 157144 byte(s)
Switching to external cppunit:
-removed tools/CppUnitTest
-updated scons script and files
-updated tests to changed API
-updated readme

Bumped scons options file version to 201. Additions:
-cppunit*
-boomeramg*
-vsl_random


1
2 /*******************************************************
3 *
4 * Copyright (c) 2003-2010 by University of Queensland
5 * 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
14
15 #include "DataTaggedTestCase.h"
16
17 #include "esysUtils/EsysException.h"
18
19 #include "escript/BinaryOp.h"
20 #include "escript/DataConstant.h"
21 #include "escript/DataFactory.h"
22 #include "escript/DataTagged.h"
23 #include "escript/DataTypes.h"
24 #include "escript/DataVector.h"
25 #include "escript/FunctionSpace.h"
26 #include "escript/FunctionSpaceFactory.h"
27 #include "escript/UnaryOp.h"
28
29 #include <cppunit/TestCaller.h>
30 #include <iostream>
31 #include <functional>
32 #include <algorithm>
33
34
35 using namespace CppUnit;
36 using namespace escript;
37 using namespace esysUtils;
38 using namespace std;
39 using namespace escript::DataTypes;
40
41 // namespace {
42 // std::string constr(FunctionSpace& fs)
43 // {
44 //
45 // try
46 // {
47 // int t[1];
48 // DataTagged dt(fs,DataTypes::scalarShape,t,DataTypes::ValueType());
49 //
50 // return "DataTagged(const FunctionSpace& what, const DataTypes::ShapeType &shape, const int tags[], const ValueType& data) was supposed to throw.";
51 // } catch (DataException d){}
52 // try
53 // {
54 // DataTagged t(fs,DataTypes::scalarShape,DataTagged::TagListType(),DataTypes::ValueType());
55 // return "DataTagged(const FunctionSpace& what, const DataTypes::ShapeType &shape, const TagListType& tags, const ValueType& data) was supposed to throw.";
56 // } catch (DataException d){}
57 // try
58 // {
59 // DataTagged t(fs,DataTypes::scalarShape,DataTypes::ValueType());
60 // return " DataTagged(const FunctionSpace& what, const DataTypes::ShapeType& shape, const DataTypes::ValueType& defaultvalue, const DataTagged* tagsource=0) was supposed to throw.";
61 // } catch (DataException d){}
62 // try
63 // {
64 // DataTypes::ValueType viewData1(1);
65 // viewData1[0]=0.0;
66 // DataConstant c(fs,DataTypes::scalarShape, viewData1);
67 // DataTagged t(c);
68 // return "DataTagged(const DataConstant& other) was supposed to throw.";
69 // } catch (DataException d){}
70 //
71 // }
72 //
73 // }
74
75 namespace {
76
77 ValueType::const_reference
78 getRefRO(DataTagged& data,int offset, int i, int j, int k)
79 {
80 return data.getVectorRO()[offset+getRelIndex(data.getShape(),i,j,k)];
81 }
82
83 ValueType::const_reference
84 getRefRO(DataTagged& data,int offset, int i, int j, int k, int l)
85 {
86 return data.getVectorRO()[offset+getRelIndex(data.getShape(),i,j,k,l)];
87 }
88
89 ValueType::const_reference
90 getRefRO(DataTagged& data,int offset, int i, int j)
91 {
92 return data.getVectorRO()[offset+getRelIndex(data.getShape(),i,j)];
93 }
94
95 ValueType::const_reference
96 getRefRO(const DataTagged& data,int offset, int i)
97 {
98 return data.getVectorRO()[offset+getRelIndex(data.getShape(),i)];
99 }
100
101 }
102
103 void DataTaggedTestCase::testOperations() {
104
105 cout << endl;
106
107 {
108 cout << "\tTest binaryOp addition of two default DataTagged objects." << endl;
109
110 DataTagged myData;
111 DataTagged right;
112
113 binaryOp(myData,right,plus<double>());
114
115 //cout << myData.toString() << endl;
116
117 CPPUNIT_ASSERT(myData.getNumSamples()==1);
118 CPPUNIT_ASSERT(myData.getNumDPPSample()==1);
119
120 CPPUNIT_ASSERT(myData.validSamplePointNo(0));
121 CPPUNIT_ASSERT(myData.validSampleNo(0));
122 CPPUNIT_ASSERT(!myData.validSamplePointNo(1));
123 CPPUNIT_ASSERT(!myData.validSampleNo(1));
124
125 // data-point 0 has tag number 1 by default
126 CPPUNIT_ASSERT(myData.getTagNumber(0)==1);
127
128 CPPUNIT_ASSERT(!myData.isCurrentTag(1));
129
130 CPPUNIT_ASSERT(myData.getTagLookup().size()==0);
131
132 CPPUNIT_ASSERT(myData.getLength()==1);
133
134 CPPUNIT_ASSERT(myData.getPointOffset(0,0)==0);
135
136 // DataArrayView myDataView = myData.getDataPoint(0,0);
137 // CPPUNIT_ASSERT(!myDataView.isEmpty());
138 CPPUNIT_ASSERT(myData.getPointOffset(0,0)==0);
139 CPPUNIT_ASSERT(myData.getRank()==0);
140 CPPUNIT_ASSERT(myData.getNoValues()==1);
141 CPPUNIT_ASSERT(myData.getShape().size()==0);
142 CPPUNIT_ASSERT(myData.getDataAtOffsetRW(0)==0.0);
143
144 // Test non-existent tag returns the default value.
145 // myDataView = myData.getDataPointByTag(1);
146 // CPPUNIT_ASSERT(!myDataView.isEmpty());
147 CPPUNIT_ASSERT(myData.getOffsetForTag(1)==0);
148 CPPUNIT_ASSERT(myData.getRank()==0);
149 CPPUNIT_ASSERT(myData.getNoValues()==1);
150 CPPUNIT_ASSERT(myData.getShape().size()==0);
151 CPPUNIT_ASSERT(myData.getDataAtOffsetRW(0)==0.0);
152
153 // myDataView = myData.getDefaultValue();
154 // CPPUNIT_ASSERT(!myDataView.isEmpty());
155 CPPUNIT_ASSERT(myData.getDefaultOffset()==0);
156 // CPPUNIT_ASSERT(myDataView.getRank()==0); // there is no point in testing this again
157 // CPPUNIT_ASSERT(myDataView.noValues()==1); // since we are not building DataArrayViews
158 // CPPUNIT_ASSERT(myDataView.getShape().size()==0);
159 // CPPUNIT_ASSERT(myDataView()==0.0);
160
161 // use a non-existent tag so we get a pointer to
162 // the first element of the data array
163 double* sampleData=myData.getSampleDataByTag(9);
164 for (int i=0; i<myData.getLength(); i++) {
165 CPPUNIT_ASSERT(sampleData[i]==i);
166 }
167
168 }
169
170 {
171 cout << "\tTest binaryOp addition of two DataTagged objects with default values only." << endl;
172
173 DataTypes::ShapeType viewShape;
174 viewShape.push_back(3);
175
176 // DataTagged::TagListType keys;
177 //
178 // DataTagged::ValueListType values;
179
180 DataTypes::ValueType viewData(3);
181 for (int i=0;i<viewShape[0];i++) {
182 viewData[i]=i;
183 }
184
185 // DataTagged myData(keys,values,myView,FunctionSpace());
186 // DataTagged right(keys,values,myView,FunctionSpace());
187 DataTagged myData(FunctionSpace(),viewShape,viewData);
188 DataTagged right(FunctionSpace(),viewShape,viewData);
189
190
191 binaryOp(myData,right,plus<double>());
192
193 //cout << myData.toString() << endl;
194
195 CPPUNIT_ASSERT(myData.getNumSamples()==1);
196 CPPUNIT_ASSERT(myData.getNumDPPSample()==1);
197
198 CPPUNIT_ASSERT(myData.validSamplePointNo(0));
199 CPPUNIT_ASSERT(myData.validSampleNo(0));
200 CPPUNIT_ASSERT(!myData.validSamplePointNo(1));
201 CPPUNIT_ASSERT(!myData.validSampleNo(1));
202
203 // data-point 0 has tag number 1 by default
204 CPPUNIT_ASSERT(myData.getTagNumber(0)==1);
205
206 CPPUNIT_ASSERT(!myData.isCurrentTag(1));
207
208 CPPUNIT_ASSERT(myData.getTagLookup().size()==0);
209
210 CPPUNIT_ASSERT(myData.getLength()==3);
211
212 CPPUNIT_ASSERT(myData.getPointOffset(0,0)==0);
213
214 CPPUNIT_ASSERT(myData.getRank()==1);
215 CPPUNIT_ASSERT(myData.getNoValues()==3);
216 CPPUNIT_ASSERT(myData.getShape().size()==1);
217
218
219 int offset=myData.getDefaultOffset();
220 // DataArrayView myDataView = myData.getDefaultValue();
221 CPPUNIT_ASSERT(offset==0);
222 CPPUNIT_ASSERT(getRefRO(myData,offset,0)==0);
223 CPPUNIT_ASSERT(getRefRO(myData,offset,1)==2);
224 CPPUNIT_ASSERT(getRefRO(myData,offset,2)==4);
225
226 // use a non-existent tag so we get a pointer to
227 // the first element of the data array
228 double* sampleData=myData.getSampleDataByTag(9);
229 for (int i=0; i<myData.getLength(); i++) {
230 CPPUNIT_ASSERT(sampleData[i]==i*2);
231 }
232
233 }
234
235 {
236 cout << "\tTest binaryOp addition of two DataTagged objects with one identical tag each." << endl;
237
238 DataTagged myData;
239 DataTagged right;
240
241 DataVector vOneData(1, 1.0 ,1);
242 // create a view with an empty shape, a scalar.
243 // DataArrayView vOneView(vOneData,DataTypes::ShapeType());
244
245 myData.addTaggedValue(1,DataTypes::scalarShape,vOneData);
246 right.addTaggedValue(1,DataTypes::scalarShape,vOneData);
247
248 binaryOp(myData,right,plus<double>());
249
250 CPPUNIT_ASSERT(myData.getNumSamples()==1);
251 CPPUNIT_ASSERT(myData.getNumDPPSample()==1);
252
253 CPPUNIT_ASSERT(myData.validSamplePointNo(0));
254 CPPUNIT_ASSERT(myData.validSampleNo(0));
255 CPPUNIT_ASSERT(!myData.validSamplePointNo(1));
256 CPPUNIT_ASSERT(!myData.validSampleNo(1));
257
258 // data-point 0 has tag number 1 by default
259 CPPUNIT_ASSERT(myData.getTagNumber(0)==1);
260
261 CPPUNIT_ASSERT(myData.isCurrentTag(1));
262
263 CPPUNIT_ASSERT(myData.getTagLookup().size()==1);
264
265 CPPUNIT_ASSERT(myData.getLength()==2);
266
267 CPPUNIT_ASSERT(myData.getPointOffset(0,0)==1);
268
269
270 CPPUNIT_ASSERT(myData.getRank()==0);
271 CPPUNIT_ASSERT(myData.getNoValues()==1);
272 CPPUNIT_ASSERT(myData.getShape().size()==0);
273
274
275
276 // check result value for tag "1"
277 // DataArrayView myDataView = myData.getDataPointByTag(1);
278 int offset=myData.getOffsetForTag(1);
279 CPPUNIT_ASSERT(offset==1);
280 CPPUNIT_ASSERT(myData.getVectorRO()[offset]==2.0);
281
282 // check result for default value
283 // myDataView = myData.getDefaultValue();
284 offset=myData.getDefaultOffset();
285 CPPUNIT_ASSERT(offset==0);
286 CPPUNIT_ASSERT(myData.getVectorRO()[offset]==0.0);
287
288 // use a non-existent tag so we get a pointer to
289 // the first element of the data array
290 double* sampleData=myData.getSampleDataByTag(9);
291 for (int i=0; i<myData.getLength(); i++) {
292 CPPUNIT_ASSERT(sampleData[i]==i*2);
293 }
294
295 }
296
297 {
298 cout << "\tTest binaryOp addition of two DataTagged objects with one different tag each." << endl;
299
300 DataTagged myData;
301 DataTagged right;
302
303 // it's important that default values are different, as we need to be able to
304 // verify that the tag values in each object are being added to the correct
305 // default values - since the tag lists don't match, the default values will
306 // be used for missing tags in each object
307 // myData.getDefaultValue()()=1.0;
308 // right.getDefaultValue()()=2.0;
309 myData.getVectorRW()[myData.getDefaultOffset()]=1.0;
310 right.getVectorRW()[right.getDefaultOffset()]=2.0;
311
312 DataVector vOneData(1, 3.0 ,1);
313 // create a view with an empty shape, a scalar.
314 // DataArrayView vOneView(vOneData,DataTypes::ShapeType());
315
316 DataVector vTwoData(1, 4.0 ,1);
317 // create a view with an empty shape, a scalar.
318 // DataArrayView vTwoView(vTwoData,DataTypes::ShapeType());
319
320 myData.addTaggedValue(1,DataTypes::scalarShape,vOneData);
321 right.addTaggedValue(2,DataTypes::scalarShape,vTwoData);
322
323 //cout << myData.toString() << endl;
324 //cout << right.toString() << endl;
325
326 binaryOp(myData,right,plus<double>());
327
328 //cout << myData.toString() << endl;
329
330 CPPUNIT_ASSERT(myData.getNumSamples()==1);
331 CPPUNIT_ASSERT(myData.getNumDPPSample()==1);
332
333 CPPUNIT_ASSERT(myData.validSamplePointNo(0));
334 CPPUNIT_ASSERT(myData.validSampleNo(0));
335 CPPUNIT_ASSERT(!myData.validSamplePointNo(1));
336 CPPUNIT_ASSERT(!myData.validSampleNo(1));
337
338 // data-point 0 has tag number 1 by default
339 CPPUNIT_ASSERT(myData.getTagNumber(0)==1);
340
341 CPPUNIT_ASSERT(myData.isCurrentTag(1));
342 CPPUNIT_ASSERT(myData.isCurrentTag(2));
343
344 CPPUNIT_ASSERT(myData.getTagLookup().size()==2);
345
346 CPPUNIT_ASSERT(myData.getLength()==3);
347
348 CPPUNIT_ASSERT(myData.getPointOffset(0,0)==1);
349
350 CPPUNIT_ASSERT(myData.getRank()==0);
351 CPPUNIT_ASSERT(myData.getNoValues()==1);
352 CPPUNIT_ASSERT(myData.getShape().size()==0);
353
354
355 // check result value for tag "1"
356 // DataArrayView myDataView = myData.getDataPointByTag(1);
357 int offset=myData.getOffsetForTag(1);
358 CPPUNIT_ASSERT(offset==1);
359 CPPUNIT_ASSERT(myData.getDataAtOffsetRO(offset)==5.0);
360
361 // check result value for tag "2"
362 // myDataView = myData.getDataPointByTag(2);
363 offset=myData.getOffsetForTag(2);
364 CPPUNIT_ASSERT(offset==2);
365 CPPUNIT_ASSERT(myData.getDataAtOffsetRO(offset)==5.0);
366
367 // check result for default value
368 // myDataView = myData.getDefaultValue();
369 offset=myData.getDefaultOffset();
370 CPPUNIT_ASSERT(offset==0);
371 CPPUNIT_ASSERT(myData.getDataAtOffsetRO(offset)==3.0);
372
373 // use a non-existent tag so we get a pointer to
374 // the first element of the data array
375 double* sampleData=myData.getSampleDataByTag(9);
376 CPPUNIT_ASSERT(sampleData[0]==3);
377 CPPUNIT_ASSERT(sampleData[1]==5);
378 CPPUNIT_ASSERT(sampleData[2]==5);
379
380 }
381
382 {
383 cout << "\tTest binaryOp addition of two DataTagged objects with overlapping tag sets." << endl;
384
385 DataTagged myData;
386 DataTagged right;
387
388 // it's important that default values are different, as we need to be able to
389 // verify that the tag values in each object are being added to the correct
390 // default values - since the tag lists don't match, the default values will
391 // be used for missing tags in each object
392 /* myData.getDefaultValue()()=2.0;
393 right.getDefaultValue()()=3.0;*/
394 myData.getVectorRW()[myData.getDefaultOffset()]=2.0;
395 right.getVectorRW()[right.getDefaultOffset()]=3.0;
396
397
398 DataVector vOneData(1, 1.0 ,1);
399 // create a view with an empty shape, a scalar.
400 // DataArrayView vOneView(vOneData,DataTypes::ShapeType());
401
402 myData.addTaggedValue(1,DataTypes::scalarShape,vOneData);
403 myData.addTaggedValue(2,DataTypes::scalarShape,vOneData);
404 right.addTaggedValue(2,DataTypes::scalarShape,vOneData);
405 right.addTaggedValue(3,DataTypes::scalarShape,vOneData);
406
407 //cout << myData.toString() << endl;
408 //cout << right.toString() << endl;
409
410 binaryOp(myData,right,plus<double>());
411
412 //cout << myData.toString() << endl;
413
414 CPPUNIT_ASSERT(myData.getNumSamples()==1);
415 CPPUNIT_ASSERT(myData.getNumDPPSample()==1);
416
417 CPPUNIT_ASSERT(myData.validSamplePointNo(0));
418 CPPUNIT_ASSERT(myData.validSampleNo(0));
419 CPPUNIT_ASSERT(!myData.validSamplePointNo(1));
420 CPPUNIT_ASSERT(!myData.validSampleNo(1));
421
422 // data-point 0 has tag number 1 by default
423 CPPUNIT_ASSERT(myData.getTagNumber(0)==1);
424
425 CPPUNIT_ASSERT(myData.isCurrentTag(1));
426 CPPUNIT_ASSERT(myData.isCurrentTag(2));
427 CPPUNIT_ASSERT(myData.isCurrentTag(3));
428
429 CPPUNIT_ASSERT(myData.getTagLookup().size()==3);
430
431 CPPUNIT_ASSERT(myData.getLength()==4);
432
433 CPPUNIT_ASSERT(myData.getPointOffset(0,0)==1);
434
435 CPPUNIT_ASSERT(myData.getRank()==0);
436 CPPUNIT_ASSERT(myData.getNoValues()==1);
437 CPPUNIT_ASSERT(myData.getShape().size()==0);
438
439
440 // check result value for tag "1"
441 // DataArrayView myDataView = myData.getDataPointByTag(1);
442 int offset=myData.getOffsetForTag(1);
443 CPPUNIT_ASSERT(offset==1);
444 CPPUNIT_ASSERT(myData.getDataAtOffsetRO(offset)==4.0);
445
446 // check result value for tag "2"
447 // myDataView = myData.getDataPointByTag(2);
448 offset=myData.getOffsetForTag(2);
449 CPPUNIT_ASSERT(offset==2);
450 CPPUNIT_ASSERT(myData.getDataAtOffsetRO(offset)==2.0);
451
452 // check result value for tag "3"
453 // myDataView = myData.getDataPointByTag(3);
454 offset=myData.getOffsetForTag(3);
455 CPPUNIT_ASSERT(offset==3);
456 CPPUNIT_ASSERT(myData.getDataAtOffsetRO(offset)==3.0);
457
458 // check result for default value
459 // myDataView = myData.getDefaultValue();
460 offset=myData.getDefaultOffset();
461 CPPUNIT_ASSERT(offset==0);
462 CPPUNIT_ASSERT(myData.getDataAtOffsetRO(offset)==5.0);
463
464 // use a non-existent tag so we get a pointer to
465 // the first element of the data array
466 double* sampleData=myData.getSampleDataByTag(9);
467 CPPUNIT_ASSERT(sampleData[0]==5);
468 CPPUNIT_ASSERT(sampleData[1]==4);
469 CPPUNIT_ASSERT(sampleData[2]==2);
470 CPPUNIT_ASSERT(sampleData[3]==3);
471
472 }
473
474 {
475 cout << "\tTest binaryOp multiplication of two DataTagged objects with default values only." << endl;
476
477 DataTypes::ShapeType viewShape;
478 viewShape.push_back(3);
479
480 // DataTagged::TagListType keys;
481
482 // DataTagged::ValueListType values;
483
484 DataTypes::ValueType viewData(3);
485 for (int i=0;i<viewShape[0];i++) {
486 viewData[i]=i;
487 }
488 // DataArrayView myView(viewData,viewShape);
489
490 DataTagged myData(FunctionSpace(),viewShape,viewData);
491 DataTagged right(FunctionSpace(),viewShape,viewData);
492
493 binaryOp(myData,right,multiplies<double>());
494
495 //cout << myData.toString() << endl;
496
497 CPPUNIT_ASSERT(myData.getNumSamples()==1);
498 CPPUNIT_ASSERT(myData.getNumDPPSample()==1);
499
500 CPPUNIT_ASSERT(myData.validSamplePointNo(0));
501 CPPUNIT_ASSERT(myData.validSampleNo(0));
502 CPPUNIT_ASSERT(!myData.validSamplePointNo(1));
503 CPPUNIT_ASSERT(!myData.validSampleNo(1));
504
505 // data-point 0 has tag number 1 by default
506 CPPUNIT_ASSERT(myData.getTagNumber(0)==1);
507
508 CPPUNIT_ASSERT(!myData.isCurrentTag(1));
509
510 CPPUNIT_ASSERT(myData.getTagLookup().size()==0);
511
512 CPPUNIT_ASSERT(myData.getLength()==3);
513
514 CPPUNIT_ASSERT(myData.getPointOffset(0,0)==0);
515
516 CPPUNIT_ASSERT(myData.getRank()==1);
517 CPPUNIT_ASSERT(myData.getNoValues()==3);
518 CPPUNIT_ASSERT(myData.getShape().size()==1);
519
520
521 // DataArrayView myDataView = myData.getDefaultValue();
522 int offset=myData.getDefaultOffset();
523 CPPUNIT_ASSERT(offset==0);
524 CPPUNIT_ASSERT(getRefRO(myData,offset,0)==0);
525 CPPUNIT_ASSERT(getRefRO(myData,offset,1)==1);
526 CPPUNIT_ASSERT(getRefRO(myData,offset,2)==4);
527
528 // use a non-existent tag so we get a pointer to
529 // the first element of the data array
530 double* sampleData=myData.getSampleDataByTag(9);
531 for (int i=0; i<myData.getLength(); i++) {
532 CPPUNIT_ASSERT(sampleData[i]==i*i);
533 }
534
535 }
536
537 {
538
539 cout << "\tTest binaryOp multiplication of DataTagged object with a scalar." << endl;
540
541 DataTagged myData;
542
543 DataVector vOneData(1, 1.0 ,1);
544 // create a view with an empty shape, a scalar.
545 // DataArrayView vOneView(vOneData,DataTypes::ShapeType());
546
547 DataVector vTwoData(1, 2.0 ,1);
548 // create a view with an empty shape, a scalar.
549 // DataArrayView vTwoView(vTwoData,DataTypes::ShapeType());
550
551 myData.addTaggedValue(1,DataTypes::scalarShape,vOneData);
552 myData.addTaggedValue(2,DataTypes::scalarShape,vTwoData);
553
554 DataVector vThreeData(1, 3.0 ,1);
555 // create a view with an empty shape, a scalar.
556 // DataArrayView vThreeView(vThreeData,DataTypes::ShapeType());
557
558 // DataArrayView right=vThreeView;
559
560 //cout << myData.toString() << endl;
561 //cout << right.toString() << endl;
562
563 binaryOp(myData,vThreeData, DataTypes::scalarShape,multiplies<double>());
564
565 //cout << myData.toString() << endl;
566
567 CPPUNIT_ASSERT(myData.getNumSamples()==1);
568 CPPUNIT_ASSERT(myData.getNumDPPSample()==1);
569
570 CPPUNIT_ASSERT(myData.validSamplePointNo(0));
571 CPPUNIT_ASSERT(myData.validSampleNo(0));
572 CPPUNIT_ASSERT(!myData.validSamplePointNo(1));
573 CPPUNIT_ASSERT(!myData.validSampleNo(1));
574
575 // data-point 0 has tag number 1 by default
576 CPPUNIT_ASSERT(myData.getTagNumber(0)==1);
577
578 CPPUNIT_ASSERT(myData.isCurrentTag(1));
579 CPPUNIT_ASSERT(myData.isCurrentTag(2));
580
581 CPPUNIT_ASSERT(myData.getTagLookup().size()==2);
582
583 CPPUNIT_ASSERT(myData.getLength()==3);
584
585 CPPUNIT_ASSERT(myData.getPointOffset(0,0)==1);
586
587 CPPUNIT_ASSERT(myData.getRank()==0);
588 CPPUNIT_ASSERT(myData.getNoValues()==1);
589 CPPUNIT_ASSERT(myData.getShape().size()==0);
590
591 // check result value for tag "1"
592 // DataArrayView myDataView = myData.getDataPointByTag(1);
593 int offset=myData.getOffsetForTag(1);
594 CPPUNIT_ASSERT(offset==1);
595 CPPUNIT_ASSERT(myData.getDataAtOffsetRO(offset)==3.0);
596
597 // check result value for tag "2"
598 // myDataView = myData.getDataPointByTag(2);
599 offset=myData.getOffsetForTag(2);
600 CPPUNIT_ASSERT(offset==2);
601 CPPUNIT_ASSERT(myData.getDataAtOffsetRO(offset)==6.0);
602
603 // check result for default value
604 // myDataView = myData.getDefaultValue();
605 offset=myData.getDefaultOffset();
606 CPPUNIT_ASSERT(offset==0);
607 CPPUNIT_ASSERT(myData.getDataAtOffsetRO(offset)==0.0);
608
609 // use a non-existent tag so we get a pointer to
610 // the first element of the data array
611 double* sampleData=myData.getSampleDataByTag(9);
612 CPPUNIT_ASSERT(sampleData[0]==0);
613 CPPUNIT_ASSERT(sampleData[1]==3);
614 CPPUNIT_ASSERT(sampleData[2]==6);
615
616 }
617
618 {
619 cout << "\tTest binaryOp multiplication of two DataTagged objects with overlapping tag sets." << endl;
620
621 DataTagged myData;
622 DataTagged right;
623
624 // it's important that default values are different, as we need to be able to
625 // verify that the tag values in each object are being added to the correct
626 // default values - since the tag lists don't match, the default values will
627 // be used for missing tags in each object
628 // myData.getDefaultValue()()=2.0;
629 // right.getDefaultValue()()=3.0;
630 myData.getVectorRW()[myData.getDefaultOffset()]=2.0;
631 right.getVectorRW()[right.getDefaultOffset()]=3.0;
632
633 DataVector vOneData(1, 1.0 ,1);
634 // create a view with an empty shape, a scalar.
635 // DataArrayView vOneView(vOneData,DataTypes::ShapeType());
636
637 DataVector vTwoData(1, 2.0 ,1);
638 // create a view with an empty shape, a scalar.
639 // DataArrayView vTwoView(vTwoData,DataTypes::ShapeType());
640
641 myData.addTaggedValue(1,DataTypes::scalarShape,vOneData);
642 myData.addTaggedValue(2,DataTypes::scalarShape,vOneData);
643 right.addTaggedValue(2,DataTypes::scalarShape,vTwoData);
644 right.addTaggedValue(3,DataTypes::scalarShape,vTwoData);
645
646 //cout << myData.toString() << endl;
647 //cout << right.toString() << endl;
648
649 binaryOp(myData,right,multiplies<double>());
650
651 //cout << myData.toString() << endl;
652
653 CPPUNIT_ASSERT(myData.getNumSamples()==1);
654 CPPUNIT_ASSERT(myData.getNumDPPSample()==1);
655
656 CPPUNIT_ASSERT(myData.validSamplePointNo(0));
657 CPPUNIT_ASSERT(myData.validSampleNo(0));
658 CPPUNIT_ASSERT(!myData.validSamplePointNo(1));
659 CPPUNIT_ASSERT(!myData.validSampleNo(1));
660
661 // data-point 0 has tag number 1 by default
662 CPPUNIT_ASSERT(myData.getTagNumber(0)==1);
663
664 CPPUNIT_ASSERT(myData.isCurrentTag(1));
665 CPPUNIT_ASSERT(myData.isCurrentTag(2));
666 CPPUNIT_ASSERT(myData.isCurrentTag(3));
667
668 CPPUNIT_ASSERT(myData.getTagLookup().size()==3);
669
670 CPPUNIT_ASSERT(myData.getLength()==4);
671
672 CPPUNIT_ASSERT(myData.getPointOffset(0,0)==1);
673
674 CPPUNIT_ASSERT(myData.getRank()==0);
675 CPPUNIT_ASSERT(myData.getNoValues()==1);
676 CPPUNIT_ASSERT(myData.getShape().size()==0);
677
678
679 // check result value for tag "1"
680 // DataArrayView myDataView = myData.getDataPointByTag(1);
681 int offset=myData.getOffsetForTag(1);
682 CPPUNIT_ASSERT(offset==1);
683 CPPUNIT_ASSERT(myData.getDataAtOffsetRO(offset)==3.0);
684
685 // check result value for tag "2"
686 // myDataView = myData.getDataPointByTag(2);
687 offset=myData.getOffsetForTag(2);
688 CPPUNIT_ASSERT(offset==2);
689 CPPUNIT_ASSERT(myData.getDataAtOffsetRO(offset)==2.0);
690
691 // check result value for tag "3"
692 // myDataView = myData.getDataPointByTag(3);
693 offset=myData.getOffsetForTag(3);
694 CPPUNIT_ASSERT(offset==3);
695 CPPUNIT_ASSERT(myData.getDataAtOffsetRO(offset)==4.0);
696
697 // check result for default value
698 // myDataView = myData.getDefaultValue();
699 offset=myData.getDefaultOffset();
700 CPPUNIT_ASSERT(offset==0);
701 CPPUNIT_ASSERT(myData.getDataAtOffsetRO(offset)==6.0);
702
703 // use a non-existent tag so we get a pointer to
704 // the first element of the data array
705 double* sampleData=myData.getSampleDataByTag(9);
706 CPPUNIT_ASSERT(sampleData[0]==6);
707 CPPUNIT_ASSERT(sampleData[1]==3);
708 CPPUNIT_ASSERT(sampleData[2]==2);
709 CPPUNIT_ASSERT(sampleData[3]==4);
710
711 }
712
713 {
714 cout << "\tTest unaryOp negate on default DataTagged object." << endl;
715
716 DataTagged myData;
717
718 unaryOp(myData,negate<double>());
719
720 //cout << myData.toString() << endl;
721
722 CPPUNIT_ASSERT(myData.getNumSamples()==1);
723 CPPUNIT_ASSERT(myData.getNumDPPSample()==1);
724
725 CPPUNIT_ASSERT(myData.validSamplePointNo(0));
726 CPPUNIT_ASSERT(myData.validSampleNo(0));
727 CPPUNIT_ASSERT(!myData.validSamplePointNo(1));
728 CPPUNIT_ASSERT(!myData.validSampleNo(1));
729
730 // data-point 0 has tag number 1 by default
731 CPPUNIT_ASSERT(myData.getTagNumber(0)==1);
732
733 CPPUNIT_ASSERT(!myData.isCurrentTag(1));
734
735 CPPUNIT_ASSERT(myData.getTagLookup().size()==0);
736
737 CPPUNIT_ASSERT(myData.getLength()==1);
738
739 CPPUNIT_ASSERT(myData.getPointOffset(0,0)==0);
740
741 CPPUNIT_ASSERT(myData.getRank()==0);
742 CPPUNIT_ASSERT(myData.getNoValues()==1);
743 CPPUNIT_ASSERT(myData.getShape().size()==0);
744
745
746 // DataArrayView myDataView = myData.getDataPoint(0,0);
747 int offset=myData.getPointOffset(0,0);
748 CPPUNIT_ASSERT(offset==0);
749 CPPUNIT_ASSERT(myData.getDataAtOffsetRO(offset)==0.0);
750
751 // Test non-existent tag returns the default value.
752 // myDataView = myData.getDataPointByTag(1);
753 offset=myData.getOffsetForTag(1);
754 CPPUNIT_ASSERT(offset==0);
755 CPPUNIT_ASSERT(myData.getDataAtOffsetRO(offset)==0.0);
756
757 // myDataView = myData.getDefaultValue();
758 offset=myData.getDefaultOffset();
759 CPPUNIT_ASSERT(offset==0);
760 CPPUNIT_ASSERT(myData.getDataAtOffsetRO(offset)==0.0);
761
762 // use a non-existent tag so we get a pointer to
763 // the first element of the data array
764 double* sampleData=myData.getSampleDataByTag(9);
765 for (int i=0; i<myData.getLength(); i++) {
766 CPPUNIT_ASSERT(sampleData[i]==i);
767 }
768
769 }
770
771 {
772 cout << "\tTest unaryOp negate on DataTagged object with default value only." << endl;
773
774 DataTypes::ShapeType viewShape;
775 viewShape.push_back(3);
776
777 // DataTagged::TagListType keys;
778
779 // DataTagged::ValueListType values;
780
781 DataTypes::ValueType viewData(3);
782 for (int i=0;i<viewShape[0];i++) {
783 viewData[i]=i;
784 }
785 // DataArrayView myView(viewData,viewShape);
786
787 DataTagged myData(FunctionSpace(),viewShape,viewData);
788
789 unaryOp(myData,negate<double>());
790
791 //cout << myData.toString() << endl;
792
793 CPPUNIT_ASSERT(myData.getNumSamples()==1);
794 CPPUNIT_ASSERT(myData.getNumDPPSample()==1);
795
796 CPPUNIT_ASSERT(myData.validSamplePointNo(0));
797 CPPUNIT_ASSERT(myData.validSampleNo(0));
798 CPPUNIT_ASSERT(!myData.validSamplePointNo(1));
799 CPPUNIT_ASSERT(!myData.validSampleNo(1));
800
801 // data-point 0 has tag number 1 by default
802 CPPUNIT_ASSERT(myData.getTagNumber(0)==1);
803
804 CPPUNIT_ASSERT(!myData.isCurrentTag(1));
805
806 CPPUNIT_ASSERT(myData.getTagLookup().size()==0);
807
808 CPPUNIT_ASSERT(myData.getLength()==3);
809
810 CPPUNIT_ASSERT(myData.getPointOffset(0,0)==0);
811
812 CPPUNIT_ASSERT(myData.getRank()==1);
813 CPPUNIT_ASSERT(myData.getNoValues()==3);
814 CPPUNIT_ASSERT(myData.getShape().size()==1);
815
816
817 int offset=myData.getDefaultOffset();
818 // DataArrayView myDataView = myData.getDefaultValue();
819 CPPUNIT_ASSERT(offset==0);
820 CPPUNIT_ASSERT(getRefRO(myData,offset,0)==0);
821 CPPUNIT_ASSERT(getRefRO(myData,offset,1)==-1);
822 CPPUNIT_ASSERT(getRefRO(myData,offset,2)==-2);
823
824 // use a non-existent tag so we get a pointer to
825 // the first element of the data array
826 double* sampleData=myData.getSampleDataByTag(9);
827 for (int i=0; i<myData.getLength(); i++) {
828 CPPUNIT_ASSERT(sampleData[i]==0-i);
829 }
830
831 }
832
833 {
834 cout << "\tTest unnaryOp negate on DataTagged object with two tags." << endl;
835
836 DataTagged myData;
837
838 DataVector vOneData(1, 1.0 ,1);
839 // create a view with an empty shape, a scalar.
840 // DataArrayView vOneView(vOneData,DataTypes::ShapeType());
841
842 DataVector vTwoData(1, 2.0 ,1);
843 // create a view with an empty shape, a scalar.
844 // DataArrayView vTwoView(vTwoData,DataTypes::ShapeType());
845
846 myData.addTaggedValue(1,DataTypes::scalarShape,vOneData);
847 myData.addTaggedValue(2,DataTypes::scalarShape,vTwoData);
848
849 unaryOp(myData,negate<double>());
850
851 CPPUNIT_ASSERT(myData.getNumSamples()==1);
852 CPPUNIT_ASSERT(myData.getNumDPPSample()==1);
853
854 CPPUNIT_ASSERT(myData.validSamplePointNo(0));
855 CPPUNIT_ASSERT(myData.validSampleNo(0));
856 CPPUNIT_ASSERT(!myData.validSamplePointNo(1));
857 CPPUNIT_ASSERT(!myData.validSampleNo(1));
858
859 // data-point 0 has tag number 1 by default
860 CPPUNIT_ASSERT(myData.getTagNumber(0)==1);
861
862 CPPUNIT_ASSERT(myData.isCurrentTag(1));
863 CPPUNIT_ASSERT(myData.isCurrentTag(2));
864
865 CPPUNIT_ASSERT(myData.getTagLookup().size()==2);
866
867 CPPUNIT_ASSERT(myData.getLength()==3);
868
869 CPPUNIT_ASSERT(myData.getPointOffset(0,0)==1);
870
871 CPPUNIT_ASSERT(myData.getRank()==0);
872 CPPUNIT_ASSERT(myData.getNoValues()==1);
873 CPPUNIT_ASSERT(myData.getShape().size()==0);
874
875
876 // check result value for tag "1"
877 // DataArrayView myDataView = myData.getDataPointByTag(1);
878 int offset=myData.getOffsetForTag(1);
879 CPPUNIT_ASSERT(offset==1);
880 CPPUNIT_ASSERT(myData.getDataAtOffsetRO(offset)==-1.0);
881
882 // check result value for tag "2"
883 // myDataView = myData.getDataPointByTag(2);
884 offset=myData.getOffsetForTag(2);
885 CPPUNIT_ASSERT(offset==2);
886 CPPUNIT_ASSERT(myData.getDataAtOffsetRO(offset)==-2.0);
887
888 // check result for default value
889 // myDataView = myData.getDefaultValue();
890 offset=myData.getDefaultOffset();
891 CPPUNIT_ASSERT(offset==0);
892 CPPUNIT_ASSERT(myData.getDataAtOffsetRO(offset)==0.0);
893
894 // use a non-existent tag so we get a pointer to
895 // the first element of the data array
896 double* sampleData=myData.getSampleDataByTag(9);
897 for (int i=0; i<myData.getLength(); i++) {
898 CPPUNIT_ASSERT(sampleData[i]==0-i);
899 }
900
901 }
902
903 }
904
905 void DataTaggedTestCase::testAddTaggedValues() {
906
907 cout << endl;
908
909 {
910
911 cout << "\tTest adding one key with empty value list to default DataTagged." << endl;
912 DataTagged myData;
913
914 DataTagged::TagListType keys;
915 keys.push_back(1);
916
917 DataTagged::ValueBatchType values;
918
919 myData.addTaggedValues(keys,values,DataTypes::scalarShape);
920
921 CPPUNIT_ASSERT(myData.isCurrentTag(1));
922
923 CPPUNIT_ASSERT(myData.getTagLookup().size()==1);
924
925 CPPUNIT_ASSERT(myData.getLength()==2);
926
927 // data-point 0 has tag number 1 by default
928 CPPUNIT_ASSERT(myData.getTagNumber(0)==1);
929
930 CPPUNIT_ASSERT(myData.getPointOffset(0,0)==1);
931
932 CPPUNIT_ASSERT(myData.getRank()==0);
933 CPPUNIT_ASSERT(myData.getNoValues()==1);
934 CPPUNIT_ASSERT(myData.getShape().size()==0);
935
936
937 // DataArrayView myDataView = myData.getDataPoint(0,0);
938 int offset=myData.getPointOffset(0,0);
939 CPPUNIT_ASSERT(offset==1);
940 CPPUNIT_ASSERT(myData.getDataAtOffsetRO(offset)==0.0);
941
942 // myDataView = myData.getDataPointByTag(1);
943 offset=myData.getOffsetForTag(1);
944 CPPUNIT_ASSERT(offset==1);
945 CPPUNIT_ASSERT(myData.getDataAtOffsetRO(offset)==0.0);
946
947 // myDataView = myData.getDefaultValue();
948 offset=myData.getDefaultOffset();
949 CPPUNIT_ASSERT(offset==0);
950 CPPUNIT_ASSERT(myData.getDataAtOffsetRO(offset)==0.0);
951
952 // use a non-existent tag so we get a pointer to
953 // the first element of the data array
954 double* sampleData=myData.getSampleDataByTag(9);
955 for (int i=0; i<myData.getLength(); i++) {
956 CPPUNIT_ASSERT(sampleData[i]==0);
957 }
958
959 }
960
961 {
962
963 cout << "\tTest adding one key with one value to default DataTagged." << endl;
964 DataTagged myData;
965
966 DataTagged::TagListType keys;
967 keys.push_back(1);
968
969 DataTagged::ValueBatchType values;
970
971 DataTypes::ShapeType viewShape;
972 /* DataTypes::ValueType viewData(1);
973 viewData[0]=1.0;*/
974 // DataArrayView myView(viewData,viewShape);
975 values.push_back(1.0);
976
977 myData.addTaggedValues(keys,values,viewShape);
978
979 CPPUNIT_ASSERT(myData.isCurrentTag(1));
980
981 CPPUNIT_ASSERT(myData.getTagLookup().size()==1);
982
983 CPPUNIT_ASSERT(myData.getLength()==2);
984
985 // data-point 0 has tag number 1 by default
986 CPPUNIT_ASSERT(myData.getTagNumber(0)==1);
987
988 CPPUNIT_ASSERT(myData.getPointOffset(0,0)==1);
989
990 CPPUNIT_ASSERT(myData.getRank()==0);
991 CPPUNIT_ASSERT(myData.getNoValues()==1);
992 CPPUNIT_ASSERT(myData.getShape().size()==0);
993
994
995 // DataArrayView myDataView = myData.getDataPoint(0,0);
996 int offset=myData.getPointOffset(0,0);
997 CPPUNIT_ASSERT(offset==1);
998 CPPUNIT_ASSERT(myData.getDataAtOffsetRO(offset)==1.0);
999
1000 // myDataView = myData.getDataPointByTag(1);
1001 offset=myData.getOffsetForTag(1);
1002 CPPUNIT_ASSERT(offset==1);
1003 CPPUNIT_ASSERT(myData.getDataAtOffsetRO(offset)==1.0);
1004
1005 // myDataView = myData.getDefaultValue();
1006 offset=myData.getDefaultOffset();
1007 CPPUNIT_ASSERT(offset==0);
1008 CPPUNIT_ASSERT(myData.getDataAtOffsetRO(offset)==0.0);
1009
1010 // use a non-existent tag so we get a pointer to
1011 // the first element of the data array
1012 double* sampleData=myData.getSampleDataByTag(9);
1013 for (int i=0; i<myData.getLength(); i++) {
1014 CPPUNIT_ASSERT(sampleData[i]==i);
1015 }
1016
1017 }
1018
1019 {
1020
1021 cout << "\tTest adding three keys with one value to default DataTagged." << endl;
1022 DataTagged myData;
1023
1024 DataTagged::TagListType keys;
1025 keys.push_back(1);
1026 keys.push_back(2);
1027 keys.push_back(3);
1028
1029 DataTagged::ValueBatchType values;
1030
1031 DataTypes::ShapeType viewShape;
1032 /* DataTypes::ValueType viewData(1);
1033 viewData[0]=1.0;
1034 DataArrayView myView(viewData,viewShape);*/
1035 values.push_back(1.0);
1036
1037 myData.addTaggedValues(keys,values,viewShape);
1038
1039 CPPUNIT_ASSERT(myData.isCurrentTag(1));
1040 CPPUNIT_ASSERT(myData.isCurrentTag(2));
1041 CPPUNIT_ASSERT(myData.isCurrentTag(3));
1042
1043 CPPUNIT_ASSERT(myData.getTagLookup().size()==3);
1044
1045 CPPUNIT_ASSERT(myData.getLength()==4);
1046
1047 // data-point 0 has tag number 1 by default
1048 CPPUNIT_ASSERT(myData.getTagNumber(0)==1);
1049
1050 CPPUNIT_ASSERT(myData.getPointOffset(0,0)==1);
1051
1052 CPPUNIT_ASSERT(myData.getRank()==0);
1053 CPPUNIT_ASSERT(myData.getNoValues()==1);
1054 CPPUNIT_ASSERT(myData.getShape().size()==0);
1055
1056
1057 // DataArrayView myDataView = myData.getDataPoint(0,0);
1058 int offset=myData.getPointOffset(0,0);
1059 CPPUNIT_ASSERT(offset==1);
1060 CPPUNIT_ASSERT(myData.getDataAtOffsetRO(offset)==1.0);
1061
1062 // myDataView = myData.getDataPointByTag(1);
1063 offset=myData.getOffsetForTag(1);
1064 CPPUNIT_ASSERT(offset==1);
1065 CPPUNIT_ASSERT(myData.getDataAtOffsetRO(offset)==1.0);
1066
1067 // myDataView = myData.getDataPointByTag(2);
1068 offset=myData.getOffsetForTag(2);
1069 CPPUNIT_ASSERT(offset==2);
1070 CPPUNIT_ASSERT(myData.getDataAtOffsetRO(offset)==1.0);
1071
1072 // myDataView = myData.getDataPointByTag(3);
1073 offset=myData.getOffsetForTag(3);
1074 CPPUNIT_ASSERT(offset==3);
1075 CPPUNIT_ASSERT(myData.getDataAtOffsetRO(offset)==1.0);
1076
1077 // myDataView = myData.getDefaultValue();
1078 offset=myData.getDefaultOffset();
1079 CPPUNIT_ASSERT(offset==0);
1080 CPPUNIT_ASSERT(myData.getDataAtOffsetRO(offset)==0.0);
1081
1082 // use a non-existent tag so we get a pointer to
1083 // the first element of the data array
1084 double* sampleData=myData.getSampleDataByTag(9);
1085 for (int i=0; i<myData.getLength(); i++) {
1086 if (i==0) {
1087 CPPUNIT_ASSERT(sampleData[i]==0);
1088 } else {
1089 CPPUNIT_ASSERT(sampleData[i]==1);
1090 }
1091 }
1092
1093 }
1094
1095 {
1096
1097 cout << "\tTest adding three keys with three values to default DataTagged." << endl;
1098 DataTagged myData;
1099
1100 DataTagged::TagListType keys;
1101 keys.push_back(1);
1102 keys.push_back(2);
1103 keys.push_back(3);
1104
1105 DataTagged::ValueBatchType values;
1106
1107 DataTypes::ShapeType viewShape;
1108 /* DataTypes::ValueType viewData1(1);
1109 viewData1[0]=1.0;
1110 DataTypes::ValueType viewData2(1);
1111 viewData2[0]=2.0;
1112 DataTypes::ValueType viewData3(1);
1113 viewData3[0]=3.0;
1114 DataArrayView myView1(viewData1,viewShape);
1115 DataArrayView myView2(viewData2,viewShape);
1116 DataArrayView myView3(viewData3,viewShape);*/
1117 values.push_back(1.0);
1118 values.push_back(2.0);
1119 values.push_back(3.0);
1120
1121 myData.addTaggedValues(keys,values,viewShape);
1122
1123 CPPUNIT_ASSERT(myData.isCurrentTag(1));
1124 CPPUNIT_ASSERT(myData.isCurrentTag(2));
1125 CPPUNIT_ASSERT(myData.isCurrentTag(3));
1126
1127 CPPUNIT_ASSERT(myData.getTagLookup().size()==3);
1128
1129 CPPUNIT_ASSERT(myData.getLength()==4);
1130
1131 // data-point 0 has tag number 1 by default
1132 CPPUNIT_ASSERT(myData.getTagNumber(0)==1);
1133
1134 CPPUNIT_ASSERT(myData.getPointOffset(0,0)==1);
1135
1136 CPPUNIT_ASSERT(myData.getRank()==0);
1137 CPPUNIT_ASSERT(myData.getNoValues()==1);
1138 CPPUNIT_ASSERT(myData.getShape().size()==0);
1139
1140
1141 // DataArrayView myDataView = myData.getDataPoint(0,0);
1142 int offset=myData.getPointOffset(0,0);
1143 CPPUNIT_ASSERT(offset==1);
1144 CPPUNIT_ASSERT(myData.getDataAtOffsetRO(offset)==1.0);
1145
1146 // myDataView = myData.getDataPointByTag(1);
1147 offset=myData.getOffsetForTag(1);
1148 CPPUNIT_ASSERT(offset==1);
1149 CPPUNIT_ASSERT(myData.getDataAtOffsetRO(offset)==1.0);
1150
1151 // myDataView = myData.getDataPointByTag(2);
1152 offset=myData.getOffsetForTag(2);
1153 CPPUNIT_ASSERT(offset==2);
1154 CPPUNIT_ASSERT(myData.getDataAtOffsetRO(offset)==2.0);
1155
1156 // myDataView = myData.getDataPointByTag(3);
1157 offset=myData.getOffsetForTag(3);
1158 CPPUNIT_ASSERT(offset==3);
1159 CPPUNIT_ASSERT(myData.getDataAtOffsetRO(offset)==3.0);
1160
1161 // myDataView = myData.getDefaultValue();
1162 offset=myData.getDefaultOffset();
1163 CPPUNIT_ASSERT(offset==0);
1164 CPPUNIT_ASSERT(myData.getDataAtOffsetRO(offset)==0.0);
1165
1166 // use a non-existent tag so we get a pointer to
1167 // the first element of the data array
1168 double* sampleData=myData.getSampleDataByTag(9);
1169 for (int i=0; i<myData.getLength(); i++) {
1170 CPPUNIT_ASSERT(sampleData[i]==i);
1171 }
1172
1173 }
1174
1175 {
1176
1177 cout << "\tTest adding one key with empty value list to DataTagged with default value only." << endl;
1178
1179 DataTypes::ShapeType viewShape;
1180 viewShape.push_back(3);
1181
1182 DataTagged::TagListType keys;
1183
1184 DataTagged::ValueBatchType values;
1185
1186 DataTypes::ValueType viewData(3);
1187 for (int i=0;i<viewShape[0];i++) {
1188 viewData[i]=i;
1189 }
1190
1191 DataTagged myData(FunctionSpace(),viewShape,viewData);
1192
1193 keys.push_back(1);
1194 values.clear();
1195
1196 myData.addTaggedValues(keys,values,viewShape);
1197
1198 CPPUNIT_ASSERT(myData.isCurrentTag(1));
1199
1200 CPPUNIT_ASSERT(myData.getTagLookup().size()==1);
1201
1202 CPPUNIT_ASSERT(myData.getLength()==6);
1203
1204 // data-point 0 has tag number 1 by default
1205 CPPUNIT_ASSERT(myData.getTagNumber(0)==1);
1206
1207 CPPUNIT_ASSERT(myData.getPointOffset(0,0)==3);
1208
1209 CPPUNIT_ASSERT(myData.getRank()==1);
1210 CPPUNIT_ASSERT(myData.getNoValues()==3);
1211 CPPUNIT_ASSERT(myData.getShape().size()==1);
1212
1213
1214 // DataArrayView myDataView = myData.getDataPoint(0,0);
1215 int offset=myData.getPointOffset(0,0);
1216 CPPUNIT_ASSERT(offset==3);
1217 CPPUNIT_ASSERT(getRefRO(myData,offset,0)==0);
1218 CPPUNIT_ASSERT(getRefRO(myData,offset,1)==1);
1219 CPPUNIT_ASSERT(getRefRO(myData,offset,2)==2);
1220
1221 // myDataView = myData.getDataPointByTag(1);
1222 offset=myData.getOffsetForTag(1);
1223 CPPUNIT_ASSERT(offset==3);
1224 CPPUNIT_ASSERT(getRefRO(myData,offset,0)==0);
1225 CPPUNIT_ASSERT(getRefRO(myData,offset,1)==1);
1226 CPPUNIT_ASSERT(getRefRO(myData,offset,2)==2);
1227
1228 // myDataView = myData.getDefaultValue();
1229 offset=myData.getDefaultOffset();
1230 CPPUNIT_ASSERT(offset==0);
1231 CPPUNIT_ASSERT(getRefRO(myData,offset,0)==0);
1232 CPPUNIT_ASSERT(getRefRO(myData,offset,1)==1);
1233 CPPUNIT_ASSERT(getRefRO(myData,offset,2)==2);
1234
1235 // use a non-existent tag so we get a pointer to
1236 // the first element of the data array
1237 double* sampleData=myData.getSampleDataByTag(9);
1238 for (int i=0; i<myData.getLength(); i++) {
1239 CPPUNIT_ASSERT(sampleData[i]==i%3);
1240 }
1241
1242 }
1243
1244 {
1245
1246 cout << "\tTest adding one key with one value to DataTagged with default value only." << endl;
1247
1248 DataTypes::ShapeType viewShape;
1249 viewShape.push_back(3);
1250
1251 DataTagged::TagListType keys;
1252
1253 DataTagged::ValueBatchType values;
1254
1255 DataTypes::ValueType viewData(3);
1256 for (int i=0;i<viewShape[0];i++) {
1257 viewData[i]=i;
1258 }
1259 // DataArrayView myView(viewData,viewShape);
1260
1261 DataTagged myData(FunctionSpace(),viewShape,viewData);
1262
1263 keys.push_back(1);
1264
1265 // DataTypes::ValueType viewData1(3);
1266 for (int i=0;i<viewShape[0];i++) {
1267 // viewData1[i]=i+3;
1268 values.push_back(i+3);
1269 }
1270 // DataArrayView myView1(viewData1,viewShape);
1271 // values.push_back(myView1);
1272
1273 myData.addTaggedValues(keys,values,viewShape);
1274
1275 CPPUNIT_ASSERT(myData.isCurrentTag(1));
1276
1277 CPPUNIT_ASSERT(myData.getTagLookup().size()==1);
1278
1279 CPPUNIT_ASSERT(myData.getLength()==6);
1280
1281 // data-point 0 has tag number 1 by default
1282 CPPUNIT_ASSERT(myData.getTagNumber(0)==1);
1283
1284 CPPUNIT_ASSERT(myData.getPointOffset(0,0)==3);
1285
1286 CPPUNIT_ASSERT(myData.getRank()==1);
1287 CPPUNIT_ASSERT(myData.getNoValues()==3);
1288 CPPUNIT_ASSERT(myData.getShape().size()==1);
1289
1290
1291 int offset=myData.getPointOffset(0,0);
1292 // DataArrayView myDataView = myData.getDataPoint(0,0);
1293 CPPUNIT_ASSERT(offset==3);
1294 CPPUNIT_ASSERT(getRefRO(myData,offset,0)==3);
1295 CPPUNIT_ASSERT(getRefRO(myData,offset,1)==4);
1296 CPPUNIT_ASSERT(getRefRO(myData,offset,2)==5);
1297
1298 // myDataView = myData.getDataPointByTag(1);
1299 offset=myData.getOffsetForTag(1);
1300 CPPUNIT_ASSERT(offset==3);
1301 CPPUNIT_ASSERT(getRefRO(myData,offset,0)==3);
1302 CPPUNIT_ASSERT(getRefRO(myData,offset,1)==4);
1303 CPPUNIT_ASSERT(getRefRO(myData,offset,2)==5);
1304
1305 // myDataView = myData.getDefaultValue();
1306 offset=myData.getDefaultOffset();
1307 CPPUNIT_ASSERT(offset==0);
1308 CPPUNIT_ASSERT(getRefRO(myData,offset,0)==0);
1309 CPPUNIT_ASSERT(getRefRO(myData,offset,1)==1);
1310 CPPUNIT_ASSERT(getRefRO(myData,offset,2)==2);
1311
1312 // use a non-existent tag so we get a pointer to
1313 // the first element of the data array
1314 double* sampleData=myData.getSampleDataByTag(9);
1315 for (int i=0; i<myData.getLength(); i++) {
1316 CPPUNIT_ASSERT(sampleData[i]==i);
1317 }
1318
1319 }
1320
1321 {
1322
1323 cout << "\tTest adding three keys with one value to DataTagged with default value only." << endl;
1324
1325 DataTypes::ShapeType viewShape;
1326 viewShape.push_back(3);
1327
1328 DataTagged::TagListType keys;
1329
1330 DataTagged::ValueBatchType values;
1331
1332 DataTypes::ValueType viewData(3);
1333 for (int i=0;i<viewShape[0];i++) {
1334 viewData[i]=i;
1335 }
1336 // DataArrayView myView(viewData,viewShape);
1337
1338 DataTagged myData(FunctionSpace(),viewShape,viewData);
1339
1340 keys.push_back(1);
1341 keys.push_back(2);
1342 keys.push_back(3);
1343
1344 // DataTypes::ValueType viewData1(3);
1345 for (int i=0;i<viewShape[0];i++) {
1346 // viewData1[i]=3;
1347 values.push_back(3);
1348 }
1349 // DataArrayView myView1(viewData1,viewShape);
1350 // values.push_back(myView1);
1351
1352 myData.addTaggedValues(keys,values,viewShape);
1353
1354 CPPUNIT_ASSERT(myData.isCurrentTag(1));
1355 CPPUNIT_ASSERT(myData.isCurrentTag(2));
1356 CPPUNIT_ASSERT(myData.isCurrentTag(3));
1357
1358 CPPUNIT_ASSERT(myData.getTagLookup().size()==3);
1359
1360 CPPUNIT_ASSERT(myData.getLength()==12);
1361
1362 // data-point 0 has tag number 1 by default
1363 CPPUNIT_ASSERT(myData.getTagNumber(0)==1);
1364
1365 CPPUNIT_ASSERT(myData.getPointOffset(0,0)==3);
1366
1367 CPPUNIT_ASSERT(myData.getRank()==1);
1368 CPPUNIT_ASSERT(myData.getNoValues()==3);
1369 CPPUNIT_ASSERT(myData.getShape().size()==1);
1370
1371 // DataArrayView myDataView = myData.getDataPoint(0,0);
1372 int offset=myData.getPointOffset(0,0);
1373 CPPUNIT_ASSERT(offset==3);
1374 CPPUNIT_ASSERT(getRefRO(myData,offset,0)==3);
1375 CPPUNIT_ASSERT(getRefRO(myData,offset,1)==3);
1376 CPPUNIT_ASSERT(getRefRO(myData,offset,2)==3);
1377
1378 // myDataView = myData.getDataPointByTag(1);
1379 offset=myData.getOffsetForTag(1);
1380 CPPUNIT_ASSERT(offset==3);
1381 CPPUNIT_ASSERT(getRefRO(myData,offset,0)==3);
1382 CPPUNIT_ASSERT(getRefRO(myData,offset,1)==3);
1383 CPPUNIT_ASSERT(getRefRO(myData,offset,2)==3);
1384
1385 // myDataView = myData.getDataPointByTag(2);
1386 offset=myData.getOffsetForTag(2);
1387 CPPUNIT_ASSERT(offset==6);
1388 CPPUNIT_ASSERT(getRefRO(myData,offset,0)==3);
1389 CPPUNIT_ASSERT(getRefRO(myData,offset,1)==3);
1390 CPPUNIT_ASSERT(getRefRO(myData,offset,2)==3);
1391
1392 // myDataView = myData.getDataPointByTag(3);
1393 offset=myData.getOffsetForTag(3);
1394 CPPUNIT_ASSERT(offset==9);
1395 CPPUNIT_ASSERT(getRefRO(myData,offset,0)==3);
1396 CPPUNIT_ASSERT(getRefRO(myData,offset,1)==3);
1397 CPPUNIT_ASSERT(getRefRO(myData,offset,2)==3);
1398
1399 // myDataView = myData.getDefaultValue();
1400 offset=myData.getDefaultOffset();
1401 CPPUNIT_ASSERT(offset==0);
1402 CPPUNIT_ASSERT(getRefRO(myData,offset,0)==0);
1403 CPPUNIT_ASSERT(getRefRO(myData,offset,1)==1);
1404 CPPUNIT_ASSERT(getRefRO(myData,offset,2)==2);
1405
1406 // use a non-existent tag so we get a pointer to
1407 // the first element of the data array
1408 double* sampleData=myData.getSampleDataByTag(9);
1409 for (int i=0; i<myData.getLength(); i++) {
1410 if (i<3) {
1411 CPPUNIT_ASSERT(sampleData[i]==i);
1412 } else {
1413 CPPUNIT_ASSERT(sampleData[i]==3);
1414 }
1415 }
1416
1417 }
1418
1419 {
1420
1421 cout << "\tTest adding three keys with three values to DataTagged with default value only." << endl;
1422
1423 DataTypes::ShapeType viewShape;
1424 viewShape.push_back(3);
1425
1426 DataTagged::TagListType keys;
1427
1428 DataTagged::ValueBatchType values;
1429
1430 DataTypes::ValueType viewData(3);
1431 for (int i=0;i<viewShape[0];i++) {
1432 viewData[i]=i;
1433 }
1434 // DataArrayView myView(viewData,viewShape);
1435
1436 DataTagged myData(FunctionSpace(),viewShape,viewData);
1437
1438 keys.push_back(1);
1439 keys.push_back(2);
1440 keys.push_back(3);
1441
1442 // DataTypes::ValueType viewData1(3);
1443 for (int i=0;i<viewShape[0];i++) {
1444 // viewData1[i]=i+1;
1445 values.push_back(i+1);
1446 }
1447 // DataArrayView myView1(viewData1,viewShape);
1448 // values.push_back(myView1);
1449
1450 // DataTypes::ValueType viewData2(3);
1451 for (int i=0;i<viewShape[0];i++) {
1452 // viewData2[i]=i+2;
1453 values.push_back(i+2);
1454 }
1455 // DataArrayView myView2(viewData2,viewShape);
1456 // values.push_back(myView2);
1457
1458 // DataTypes::ValueType viewData3(3);
1459 for (int i=0;i<viewShape[0];i++) {
1460 // viewData3[i]=i+3;
1461 values.push_back(i+3);
1462 }
1463 // DataArrayView myView3(viewData3,viewShape);
1464 // values.push_back(myView3);
1465
1466 myData.addTaggedValues(keys,values,viewShape);
1467
1468 CPPUNIT_ASSERT(myData.isCurrentTag(1));
1469 CPPUNIT_ASSERT(myData.isCurrentTag(2));
1470 CPPUNIT_ASSERT(myData.isCurrentTag(3));
1471
1472 CPPUNIT_ASSERT(myData.getTagLookup().size()==3);
1473
1474 CPPUNIT_ASSERT(myData.getLength()==12);
1475
1476 // data-point 0 has tag number 1 by default
1477 CPPUNIT_ASSERT(myData.getTagNumber(0)==1);
1478
1479 CPPUNIT_ASSERT(myData.getPointOffset(0,0)==3);
1480
1481 CPPUNIT_ASSERT(myData.getRank()==1);
1482 CPPUNIT_ASSERT(myData.getNoValues()==3);
1483 CPPUNIT_ASSERT(myData.getShape().size()==1);
1484
1485
1486 // DataArrayView myDataView = myData.getDataPoint(0,0);
1487 int offset=myData.getPointOffset(0,0);
1488 CPPUNIT_ASSERT(offset==3);
1489 CPPUNIT_ASSERT(getRefRO(myData,offset,0)==1);
1490 CPPUNIT_ASSERT(getRefRO(myData,offset,1)==2);
1491 CPPUNIT_ASSERT(getRefRO(myData,offset,2)==3);
1492
1493 // myDataView = myData.getDataPointByTag(1);
1494 offset=myData.getOffsetForTag(1);
1495 CPPUNIT_ASSERT(offset==3);
1496 CPPUNIT_ASSERT(getRefRO(myData,offset,0)==1);
1497 CPPUNIT_ASSERT(getRefRO(myData,offset,1)==2);
1498 CPPUNIT_ASSERT(getRefRO(myData,offset,2)==3);
1499
1500 // myDataView = myData.getDataPointByTag(2);
1501 offset=myData.getOffsetForTag(2);
1502 CPPUNIT_ASSERT(offset==6);
1503 CPPUNIT_ASSERT(getRefRO(myData,offset,0)==2);
1504 CPPUNIT_ASSERT(getRefRO(myData,offset,1)==3);
1505 CPPUNIT_ASSERT(getRefRO(myData,offset,2)==4);
1506
1507 // myDataView = myData.getDataPointByTag(3);
1508 offset=myData.getOffsetForTag(3);
1509 CPPUNIT_ASSERT(offset==9);
1510 CPPUNIT_ASSERT(getRefRO(myData,offset,0)==3);
1511 CPPUNIT_ASSERT(getRefRO(myData,offset,1)==4);
1512 CPPUNIT_ASSERT(getRefRO(myData,offset,2)==5);
1513
1514 // myDataView = myData.getDefaultValue();
1515 offset=myData.getDefaultOffset();
1516 CPPUNIT_ASSERT(offset==0);
1517 CPPUNIT_ASSERT(getRefRO(myData,offset,0)==0);
1518 CPPUNIT_ASSERT(getRefRO(myData,offset,1)==1);
1519 CPPUNIT_ASSERT(getRefRO(myData,offset,2)==2);
1520
1521 // use a non-existent tag so we get a pointer to
1522 // the first element of the data array
1523 double* sampleData=myData.getSampleDataByTag(9);
1524 for (int i=0; i<myData.getLength(); i++) {
1525 if (i<3) {
1526 CPPUNIT_ASSERT(sampleData[i]==i);
1527 } else if ((i>=3) && (i<6)) {
1528 CPPUNIT_ASSERT(sampleData[i]==i-2);
1529 } else if ((i>=6) && (i<9)) {
1530 CPPUNIT_ASSERT(sampleData[i]==i-4);
1531 } else {
1532 CPPUNIT_ASSERT(sampleData[i]==i-6);
1533 }
1534 }
1535
1536 }
1537
1538 {
1539
1540 cout << "\tTest adding one key with empty value list to DataTagged with three tags." << endl;
1541
1542 DataTagged::TagListType keys;
1543 keys.push_back(1);
1544 keys.push_back(2);
1545 keys.push_back(3);
1546
1547 DataTagged::ValueBatchType values;
1548
1549 DataTypes::ShapeType viewShape;
1550 viewShape.push_back(3);
1551
1552 // default value
1553 DataTypes::ValueType viewData(3*4);
1554 for (int i=0;i<viewShape[0];i++) {
1555 viewData[i]=i;
1556 }
1557 // DataArrayView myView(viewData,viewShape);
1558
1559 // value for tag "1"
1560 // DataTypes::ValueType eOneData(viewData);
1561 // DataArrayView eOneView(eOneData, viewShape);
1562 for (int i=0;i<viewShape[0];i++) {
1563 // eOneView(i)=i+1.0;
1564 viewData[viewShape[0]+i]=i+1.0;
1565 }
1566 // values.push_back(eOneView);
1567
1568 // value for tag "2"
1569 // DataTypes::ValueType eTwoData(viewData);
1570 // DataArrayView eTwoView(eTwoData, viewShape);
1571 for (int i=0;i<viewShape[0];i++) {
1572 // eTwoView(i)=i+2.0;
1573 viewData[2*viewShape[0]+i]=i+2.0;
1574 }
1575 // values.push_back(eTwoView);
1576
1577 // value for tag "3"
1578 // DataTypes::ValueType eThreeData(viewData);
1579 // DataArrayView eThreeView(eThreeData, viewShape);
1580 for (int i=0;i<viewShape[0];i++) {
1581 // eThreeView(i)=i+3.0;
1582 viewData[3*viewShape[0]+i]=i+3.0;
1583 }
1584 // values.push_back(eThreeView);
1585
1586 DataTagged myData(FunctionSpace(),viewShape,keys,viewData);
1587
1588 keys.clear();
1589 keys.push_back(4);
1590 values.clear();
1591
1592 myData.addTaggedValues(keys,values,viewShape);
1593
1594 CPPUNIT_ASSERT(myData.isCurrentTag(4));
1595
1596 CPPUNIT_ASSERT(myData.getTagLookup().size()==4);
1597
1598 CPPUNIT_ASSERT(myData.getLength()==15);
1599
1600 CPPUNIT_ASSERT(myData.getRank()==1);
1601 CPPUNIT_ASSERT(myData.getNoValues()==3);
1602 CPPUNIT_ASSERT(myData.getShape().size()==1);
1603
1604 // DataArrayView myDataView = myData.getDataPointByTag(4);
1605 int offset=myData.getOffsetForTag(4);
1606 CPPUNIT_ASSERT(offset==12);
1607 CPPUNIT_ASSERT(getRefRO(myData,offset,0)==0);
1608 CPPUNIT_ASSERT(getRefRO(myData,offset,1)==1);
1609 CPPUNIT_ASSERT(getRefRO(myData,offset,2)==2);
1610
1611 // use a non-existent tag so we get a pointer to
1612 // the first element of the data array
1613 double* sampleData=myData.getSampleDataByTag(9);
1614 for (int i=0; i<myData.getLength(); i++) {
1615 if (i<3) {
1616 CPPUNIT_ASSERT(sampleData[i]==i);
1617 } else if ((i>=3) && (i<6)) {
1618 CPPUNIT_ASSERT(sampleData[i]==i-2);
1619 } else if ((i>=6) && (i<9)) {
1620 CPPUNIT_ASSERT(sampleData[i]==i-4);
1621 } else if ((i>=9) && (i<12)) {
1622 CPPUNIT_ASSERT(sampleData[i]==i-6);
1623 } else {
1624 CPPUNIT_ASSERT(sampleData[i]==i-12);
1625 }
1626 }
1627
1628 }
1629
1630 {
1631
1632 cout << "\tTest adding one key with one value to DataTagged with three tags." << endl;
1633
1634 DataTagged::TagListType keys;
1635 keys.push_back(1);
1636 keys.push_back(2);
1637 keys.push_back(3);
1638
1639 DataTagged::ValueBatchType values;
1640
1641 DataTypes::ShapeType viewShape;
1642 viewShape.push_back(3);
1643
1644 // default value
1645 DataTypes::ValueType viewData(3*4);
1646 for (int i=0;i<viewShape[0];i++) {
1647 viewData[i]=i;
1648 }
1649 // DataArrayView myView(viewData,viewShape);
1650
1651 // value for tag "1"
1652 // DataTypes::ValueType eOneData(viewData);
1653 // DataArrayView eOneView(eOneData, viewShape);
1654 for (int i=0;i<viewShape[0];i++) {
1655 // eOneView(i)=i+1.0;
1656 viewData[viewShape[0]+i]=i+1.0;
1657 }
1658 // values.push_back(eOneView);
1659
1660 // value for tag "2"
1661 // DataTypes::ValueType eTwoData(viewData);
1662 // DataArrayView eTwoView(eTwoData, viewShape);
1663 for (int i=0;i<viewShape[0];i++) {
1664 // eTwoView(i)=i+2.0;
1665 viewData[2*viewShape[0]+i]=i+2.0;
1666 }
1667 // values.push_back(eTwoView);
1668
1669 // value for tag "3"
1670 // DataTypes::ValueType eThreeData(viewData);
1671 // DataArrayView eThreeView(eThreeData, viewShape);
1672 for (int i=0;i<viewShape[0];i++) {
1673 // eThreeView(i)=i+3.0;
1674 viewData[3*viewShape[0]+i]=i+3.0;
1675 }
1676 // values.push_back(eThreeView);
1677
1678 DataTagged myData(FunctionSpace(),viewShape,keys,viewData);
1679
1680 keys.clear();
1681 keys.push_back(4);
1682
1683 values.clear();
1684 // value for tag "4"
1685 // DataTypes::ValueType eFourData(viewData);
1686 // DataArrayView eFourView(eFourData, viewShape);
1687 for (int i=0;i<viewShape[0];i++) {
1688 values.push_back(i+4.0);
1689 }
1690 // values.push_back(eFourView);
1691
1692 myData.addTaggedValues(keys,values,viewShape);
1693
1694 CPPUNIT_ASSERT(myData.isCurrentTag(4));
1695
1696 CPPUNIT_ASSERT(myData.getTagLookup().size()==4);
1697
1698 CPPUNIT_ASSERT(myData.getLength()==15);
1699
1700 CPPUNIT_ASSERT(myData.getRank()==1);
1701 CPPUNIT_ASSERT(myData.getNoValues()==3);
1702 CPPUNIT_ASSERT(myData.getShape().size()==1);
1703
1704
1705 // DataArrayView myDataView = myData.getDataPointByTag(4);
1706 int offset=myData.getOffsetForTag(4);
1707 CPPUNIT_ASSERT(offset==12);
1708 CPPUNIT_ASSERT(getRefRO(myData,offset,0)==4);
1709 CPPUNIT_ASSERT(getRefRO(myData,offset,1)==5);
1710 CPPUNIT_ASSERT(getRefRO(myData,offset,2)==6);
1711
1712 // use a non-existent tag so we get a pointer to
1713 // the first element of the data array
1714 double* sampleData=myData.getSampleDataByTag(9);
1715 for (int i=0; i<myData.getLength(); i++) {
1716 if (i<3) {
1717 CPPUNIT_ASSERT(sampleData[i]==i);
1718 } else if ((i>=3) && (i<6)) {
1719 CPPUNIT_ASSERT(sampleData[i]==i-2);
1720 } else if ((i>=6) && (i<9)) {
1721 CPPUNIT_ASSERT(sampleData[i]==i-4);
1722 } else if ((i>=9) && (i<12)) {
1723 CPPUNIT_ASSERT(sampleData[i]==i-6);
1724 } else {
1725 CPPUNIT_ASSERT(sampleData[i]==i-8);
1726 }
1727 }
1728
1729 }
1730
1731 {
1732
1733 cout << "\tTest adding three keys with one value to DataTagged with three tags." << endl;
1734
1735 DataTagged::TagListType keys;
1736 keys.push_back(1);
1737 keys.push_back(2);
1738 keys.push_back(3);
1739
1740 DataTagged::ValueBatchType values;
1741
1742 DataTypes::ShapeType viewShape;
1743 viewShape.push_back(3);
1744
1745 // default value
1746 DataTypes::ValueType viewData(3*4);
1747 for (int i=0;i<viewShape[0];i++) {
1748 viewData[i]=i;
1749 }
1750 // DataArrayView myView(viewData,viewShape);
1751
1752 // value for tag "1"
1753 // DataTypes::ValueType eOneData(viewData);
1754 // DataArrayView eOneView(eOneData, viewShape);
1755 for (int i=0;i<viewShape[0];i++) {
1756 viewData[viewShape[0]+i]=i+1.0;
1757 }
1758 // values.push_back(eOneView);
1759
1760 // value for tag "2"
1761 // DataTypes::ValueType eTwoData(viewData);
1762 // DataArrayView eTwoView(eTwoData, viewShape);
1763 for (int i=0;i<viewShape[0];i++) {
1764 // eTwoView(i)=i+2.0;
1765 viewData[2*viewShape[0]+i]=i+2.0;
1766 }
1767 // values.push_back(eTwoView);
1768
1769 // value for tag "3"
1770 // DataTypes::ValueType eThreeData(viewData);
1771 // DataArrayView eThreeView(eThreeData, viewShape);
1772 for (int i=0;i<viewShape[0];i++) {
1773 // eThreeView(i)=i+3.0;
1774 viewData[3*viewShape[0]+i]=i+3.0;
1775 }
1776 // values.push_back(eThreeView);
1777
1778 DataTagged myData(FunctionSpace(),viewShape,keys,viewData);
1779
1780 keys.clear();
1781 keys.push_back(4);
1782 keys.push_back(5);
1783 keys.push_back(6);
1784
1785 values.clear();
1786 // value for tags "4", "5" and "6"
1787 // DataTypes::ValueType eFourData(viewData);
1788 // DataArrayView eFourView(eFourData, viewShape);
1789 for (int i=0;i<viewShape[0];i++) {
1790 // eFourView(i)=i+4.0;
1791 values.push_back(i+4.0);
1792 }
1793 // values.push_back(eFourView);
1794
1795 myData.addTaggedValues(keys,values,viewShape);
1796
1797 CPPUNIT_ASSERT(myData.isCurrentTag(4));
1798 CPPUNIT_ASSERT(myData.isCurrentTag(5));
1799 CPPUNIT_ASSERT(myData.isCurrentTag(6));
1800
1801 CPPUNIT_ASSERT(myData.getTagLookup().size()==6);
1802
1803 CPPUNIT_ASSERT(myData.getLength()==21);
1804
1805 CPPUNIT_ASSERT(myData.getRank()==1);
1806 CPPUNIT_ASSERT(myData.getNoValues()==3);
1807 CPPUNIT_ASSERT(myData.getShape().size()==1);
1808
1809 // DataArrayView myDataView = myData.getDataPointByTag(4);
1810 int offset=myData.getOffsetForTag(4);
1811 CPPUNIT_ASSERT(offset==12);
1812 CPPUNIT_ASSERT(getRefRO(myData,offset,0)==4);
1813 CPPUNIT_ASSERT(getRefRO(myData,offset,1)==5);
1814 CPPUNIT_ASSERT(getRefRO(myData,offset,2)==6);
1815
1816 // myDataView = myData.getDataPointByTag(5);
1817 offset=myData.getOffsetForTag(5);
1818 CPPUNIT_ASSERT(offset==15);
1819 CPPUNIT_ASSERT(getRefRO(myData,offset,0)==4);
1820 CPPUNIT_ASSERT(getRefRO(myData,offset,1)==5);
1821 CPPUNIT_ASSERT(getRefRO(myData,offset,2)==6);
1822
1823 // myDataView = myData.getDataPointByTag(6);
1824 offset=myData.getOffsetForTag(6);
1825 CPPUNIT_ASSERT(offset==18);
1826 CPPUNIT_ASSERT(getRefRO(myData,offset,0)==4);
1827 CPPUNIT_ASSERT(getRefRO(myData,offset,1)==5);
1828 CPPUNIT_ASSERT(getRefRO(myData,offset,2)==6);
1829
1830 // use a non-existent tag so we get a pointer to
1831 // the first element of the data array
1832 double* sampleData=myData.getSampleDataByTag(9);
1833 for (int i=0; i<myData.getLength(); i++) {
1834 if (i<3) {
1835 CPPUNIT_ASSERT(sampleData[i]==i);
1836 } else if ((i>=3) && (i<6)) {
1837 CPPUNIT_ASSERT(sampleData[i]==i-2);
1838 } else if ((i>=6) && (i<9)) {
1839 CPPUNIT_ASSERT(sampleData[i]==i-4);
1840 } else if ((i>=9) && (i<12)) {
1841 CPPUNIT_ASSERT(sampleData[i]==i-6);
1842 } else if ((i>=12) && (i<15)) {
1843 CPPUNIT_ASSERT(sampleData[i]==i-8);
1844 } else if ((i>=15) && (i<18)) {
1845 CPPUNIT_ASSERT(sampleData[i]==i-11);
1846 } else {
1847 CPPUNIT_ASSERT(sampleData[i]==i-14);
1848 }
1849 }
1850
1851 }
1852
1853 {
1854
1855 cout << "\tTest adding three keys with three values to DataTagged with three tags." << endl;
1856
1857 DataTagged::TagListType keys;
1858 keys.push_back(1);
1859 keys.push_back(2);
1860 keys.push_back(3);
1861
1862 DataTagged::ValueBatchType values;
1863
1864 DataTypes::ShapeType viewShape;
1865 viewShape.push_back(3);
1866
1867 // default value
1868 DataTypes::ValueType viewData(3*4);
1869 for (int i=0;i<viewShape[0];i++) {
1870 viewData[i]=i;
1871 }
1872 // DataArrayView myView(viewData,viewShape);
1873
1874 // value for tag "1"
1875 // DataTypes::ValueType eOneData(viewData);
1876 // DataArrayView eOneView(eOneData, viewShape);
1877 for (int i=0;i<viewShape[0];i++) {
1878 viewData[viewShape[0]+i]=i+1.0;
1879 }
1880 // values.push_back(eOneView);
1881
1882 // value for tag "2"
1883 // DataTypes::ValueType eTwoData(viewData);
1884 // DataArrayView eTwoView(eTwoData, viewShape);
1885 for (int i=0;i<viewShape[0];i++) {
1886 // eTwoView(i)=i+2.0;
1887 viewData[2*viewShape[0]+i]=i+2.0;
1888 }
1889 // values.push_back(eTwoView);
1890
1891 // value for tag "3"
1892 // DataTypes::ValueType eThreeData(viewData);
1893 // DataArrayView eThreeView(eThreeData, viewShape);
1894 for (int i=0;i<viewShape[0];i++) {
1895 viewData[3*viewShape[0]+i]=i+3.0;
1896 }
1897 // values.push_back(eThreeView);
1898
1899 DataTagged myData(FunctionSpace(),viewShape,keys,viewData);
1900
1901 keys.clear();
1902 keys.push_back(4);
1903 keys.push_back(5);
1904 keys.push_back(6);
1905
1906 values.clear();
1907
1908 // value for tag "4"
1909 // DataTypes::ValueType eFourData(viewData);
1910 // DataArrayView eFourView(eFourData, viewShape);
1911 for (int i=0;i<viewShape[0];i++) {
1912 values.push_back(i+4.0);
1913 }
1914 // values.push_back(eFourView);
1915
1916 // value for tag "5"
1917 // DataTypes::ValueType eFiveData(viewData);
1918 // DataArrayView eFiveView(eFiveData, viewShape);
1919 for (int i=0;i<viewShape[0];i++) {
1920 values.push_back(i+5.0);
1921 }
1922 // values.push_back(eFiveView);
1923
1924 // value for tag "6"
1925 // DataTypes::ValueType eSixData(viewData);
1926 // DataArrayView eSixView(eSixData, viewShape);
1927 for (int i=0;i<viewShape[0];i++) {
1928 // eSixView(i)=i+6.0;
1929 values.push_back(i+6.0);
1930 }
1931 // values.push_back(eSixView);
1932
1933 myData.addTaggedValues(keys,values,viewShape);
1934
1935 CPPUNIT_ASSERT(myData.isCurrentTag(4));
1936 CPPUNIT_ASSERT(myData.isCurrentTag(5));
1937 CPPUNIT_ASSERT(myData.isCurrentTag(6));
1938
1939 CPPUNIT_ASSERT(myData.getTagLookup().size()==6);
1940
1941 CPPUNIT_ASSERT(myData.getLength()==21);
1942
1943 CPPUNIT_ASSERT(myData.getRank()==1);
1944 CPPUNIT_ASSERT(myData.getNoValues()==3);
1945 CPPUNIT_ASSERT(myData.getShape().size()==1);
1946
1947 // DataArrayView myDataView = myData.getDataPointByTag(4);
1948 int offset=myData.getOffsetForTag(4);
1949 CPPUNIT_ASSERT(offset==12);
1950 CPPUNIT_ASSERT(getRefRO(myData,offset,0)==4);
1951 CPPUNIT_ASSERT(getRefRO(myData,offset,1)==5);
1952 CPPUNIT_ASSERT(getRefRO(myData,offset,2)==6);
1953
1954 // myDataView = myData.getDataPointByTag(5);
1955 offset=myData.getOffsetForTag(5);
1956 CPPUNIT_ASSERT(offset==15);
1957 CPPUNIT_ASSERT(getRefRO(myData,offset,0)==5);
1958 CPPUNIT_ASSERT(getRefRO(myData,offset,1)==6);
1959 CPPUNIT_ASSERT(getRefRO(myData,offset,2)==7);
1960
1961 // myDataView = myData.getDataPointByTag(6);
1962 offset=myData.getOffsetForTag(6);
1963 CPPUNIT_ASSERT(offset==18);
1964 CPPUNIT_ASSERT(getRefRO(myData,offset,0)==6);
1965 CPPUNIT_ASSERT(getRefRO(myData,offset,1)==7);
1966 CPPUNIT_ASSERT(getRefRO(myData,offset,2)==8);
1967
1968 // use a non-existent tag so we get a pointer to
1969 // the first element of the data array
1970 double* sampleData=myData.getSampleDataByTag(9);
1971 for (int i=0; i<myData.getLength(); i++) {
1972 if (i<3) {
1973 CPPUNIT_ASSERT(sampleData[i]==i);
1974 } else if ((i>=3) && (i<6)) {
1975 CPPUNIT_ASSERT(sampleData[i]==i-2);
1976 } else if ((i>=6) && (i<9)) {
1977 CPPUNIT_ASSERT(sampleData[i]==i-4);
1978 } else if ((i>=9) && (i<12)) {
1979 CPPUNIT_ASSERT(sampleData[i]==i-6);
1980 } else if ((i>=12) && (i<15)) {
1981 CPPUNIT_ASSERT(sampleData[i]==i-8);
1982 } else if ((i>=15) && (i<18)) {
1983 CPPUNIT_ASSERT(sampleData[i]==i-10);
1984 } else {
1985 CPPUNIT_ASSERT(sampleData[i]==i-12);
1986 }
1987 }
1988
1989 }
1990
1991 }
1992
1993 void DataTaggedTestCase::testSetTaggedValue() {
1994
1995 cout << endl;
1996
1997 {
1998
1999 cout << "\tTest setting key in DataTagged with three tags." << endl;
2000
2001 DataTagged::TagListType keys;
2002 keys.push_back(1);
2003 keys.push_back(2);
2004 keys.push_back(3);
2005
2006 DataTagged::ValueBatchType values;
2007
2008 DataTypes::ShapeType viewShape;
2009 viewShape.push_back(3);
2010
2011 // default value
2012 DataTypes::ValueType viewData(3*4);
2013 for (int i=0;i<viewShape[0];i++) {
2014 viewData[i]=i;
2015 }
2016 // DataArrayView myView(viewData,viewShape);
2017
2018 // value for tag "1"
2019 // DataTypes::ValueType eOneData(viewData);
2020 // DataArrayView eOneView(eOneData, viewShape);
2021 for (int i=0;i<viewShape[0];i++) {
2022 viewData[viewShape[0]+i]=i+1.0;
2023 }
2024 // values.push_back(eOneView);
2025
2026 // value for tag "2"
2027 // DataTypes::ValueType eTwoData(viewData);
2028 // DataArrayView eTwoView(eTwoData, viewShape);
2029 for (int i=0;i<viewShape[0];i++) {
2030 // eTwoView(i)=i+2.0;
2031 viewData[2*viewShape[0]+i]=i+2.0;
2032 }
2033 // values.push_back(eTwoView);
2034
2035 // value for tag "3"
2036 // DataTypes::ValueType eThreeData(viewData);
2037 // DataArrayView eThreeView(eThreeData, viewShape);
2038 for (int i=0;i<viewShape[0];i++) {
2039 // eThreeView(i)=i+3.0;
2040 viewData[3*viewShape[0]+i]=i+3.0;
2041 }
2042 // values.push_back(eThreeView);
2043
2044 DataTagged myData(FunctionSpace(),viewShape,keys,viewData);
2045
2046 // new value for tag "2"
2047 ValueType tmp(viewShape[0]);
2048 for (int i=0;i<viewShape[0];i++) {
2049 tmp[i]=i+5.0;
2050 }
2051
2052 myData.setTaggedValue(2,viewShape,tmp);
2053
2054 CPPUNIT_ASSERT(myData.isCurrentTag(2));
2055
2056 CPPUNIT_ASSERT(myData.getTagLookup().size()==3);
2057
2058 CPPUNIT_ASSERT(myData.getLength()==12);
2059
2060 CPPUNIT_ASSERT(myData.getRank()==1);
2061 CPPUNIT_ASSERT(myData.getNoValues()==3);
2062 CPPUNIT_ASSERT(myData.getShape().size()==1);
2063 // DataArrayView myDataView = myData.getDataPointByTag(2);
2064 int offset=myData.getOffsetForTag(2);
2065 CPPUNIT_ASSERT(offset==6);
2066 CPPUNIT_ASSERT(getRefRO(myData,offset,0)==5);
2067 CPPUNIT_ASSERT(getRefRO(myData,offset,1)==6);
2068 CPPUNIT_ASSERT(getRefRO(myData,offset,2)==7);
2069
2070 // use a non-existent tag so we get a pointer to
2071 // the first element of the data array
2072 double* sampleData=myData.getSampleDataByTag(9);
2073 for (int i=0; i<myData.getLength(); i++) {
2074 if (i<3) {
2075 CPPUNIT_ASSERT(sampleData[i]==i);
2076 } else if ((i>=3) && (i<6)) {
2077 CPPUNIT_ASSERT(sampleData[i]==i-2);
2078 } else if ((i>=6) && (i<9)) {
2079 CPPUNIT_ASSERT(sampleData[i]==i-1);
2080 } else {
2081 CPPUNIT_ASSERT(sampleData[i]==i-6);
2082 }
2083 }
2084
2085 }
2086
2087 }
2088
2089 void DataTaggedTestCase::testAll() {
2090
2091 cout << endl;
2092
2093 {
2094
2095 cout << "\tTest default DataTagged." << endl;
2096 DataTagged myData;
2097
2098 //cout << myData.toString() << endl;
2099
2100 CPPUNIT_ASSERT(myData.getNumSamples()==1);
2101 CPPUNIT_ASSERT(myData.getNumDPPSample()==1);
2102
2103 CPPUNIT_ASSERT(myData.validSamplePointNo(0));
2104 CPPUNIT_ASSERT(myData.validSampleNo(0));
2105 CPPUNIT_ASSERT(!myData.validSamplePointNo(1));
2106 CPPUNIT_ASSERT(!myData.validSampleNo(1));
2107
2108 // data-point 0 has tag number 1 by default
2109 CPPUNIT_ASSERT(myData.getTagNumber(0)==1);
2110
2111 CPPUNIT_ASSERT(!myData.isCurrentTag(1));
2112
2113 CPPUNIT_ASSERT(myData.getTagLookup().size()==0);
2114
2115 CPPUNIT_ASSERT(myData.getLength()==1);
2116
2117 CPPUNIT_ASSERT(myData.getPointOffset(0,0)==0);
2118
2119 CPPUNIT_ASSERT(myData.getRank()==0);
2120 CPPUNIT_ASSERT(myData.getNoValues()==1);
2121 CPPUNIT_ASSERT(myData.getShape().size()==0);
2122
2123
2124 // DataArrayView myDataView = myData.getDataPoint(0,0);
2125 int offset=myData.getPointOffset(0,0);
2126 CPPUNIT_ASSERT(offset==0);
2127 CPPUNIT_ASSERT(myData.getDataAtOffsetRO(offset)==0.0);
2128
2129 // Test non-existent tag returns the default value.
2130 // myDataView = myData.getDataPointByTag(1);
2131 offset=myData.getOffsetForTag(1);
2132 CPPUNIT_ASSERT(offset==0);
2133 CPPUNIT_ASSERT(myData.getDataAtOffsetRO(offset)==0.0);
2134
2135 // myDataView = myData.getDefaultValue();
2136 offset=myData.getDefaultOffset();
2137 CPPUNIT_ASSERT(offset==0);
2138 CPPUNIT_ASSERT(myData.getDataAtOffsetRO(offset)==0.0);
2139
2140 // use a non-existent tag so we get a pointer to
2141 // the first element of the data array
2142 const double* sampleData=myData.getSampleDataByTag(9);
2143 for (int i=0; i<myData.getLength(); i++) {
2144 CPPUNIT_ASSERT(sampleData[i]==i);
2145 }
2146 sampleData=myData.getSampleDataRO(0);
2147 for (unsigned int i=0; i<myData.getNoValues(); i++) {
2148 CPPUNIT_ASSERT(sampleData[i]==i);
2149 }
2150
2151 }
2152
2153 {
2154
2155 cout << "\tTest DataTagged with default value only." << endl;
2156
2157 DataTypes::ShapeType viewShape;
2158 viewShape.push_back(3);
2159
2160 DataTagged::TagListType keys;
2161
2162 DataTagged::ValueBatchType values;
2163
2164 DataTypes::ValueType viewData(3);
2165 for (int i=0;i<viewShape[0];i++) {
2166 viewData[i]=i;
2167 }
2168 // DataArrayView myView(viewData,viewShape);
2169 DataTagged myData(FunctionSpace(),viewShape, viewData);
2170 //cout << myData.toString() << endl;
2171
2172 CPPUNIT_ASSERT(myData.getNumSamples()==1);
2173 CPPUNIT_ASSERT(myData.getNumDPPSample()==1);
2174
2175 CPPUNIT_ASSERT(myData.validSamplePointNo(0));
2176 CPPUNIT_ASSERT(myData.validSampleNo(0));
2177 CPPUNIT_ASSERT(!myData.validSamplePointNo(1));
2178 CPPUNIT_ASSERT(!myData.validSampleNo(1));
2179
2180 // data-point 0 has tag number 1 by default
2181 CPPUNIT_ASSERT(myData.getTagNumber(0)==1);
2182
2183 CPPUNIT_ASSERT(!myData.isCurrentTag(1));
2184
2185 CPPUNIT_ASSERT(myData.getTagLookup().size()==0);
2186
2187 CPPUNIT_ASSERT(myData.getLength()==3);
2188
2189 CPPUNIT_ASSERT(myData.getPointOffset(0,0)==0);
2190
2191 CPPUNIT_ASSERT(myData.getRank()==1);
2192 CPPUNIT_ASSERT(myData.getNoValues()==3);
2193 CPPUNIT_ASSERT(myData.getShape().size()==1);
2194
2195 // DataArrayView myDataView = myData.getDataPoint(0,0);
2196 int offset=myData.getPointOffset(0,0);
2197 CPPUNIT_ASSERT(offset==0);
2198 CPPUNIT_ASSERT(getRefRO(myData,offset,0)==0);
2199 CPPUNIT_ASSERT(getRefRO(myData,offset,1)==1);
2200 CPPUNIT_ASSERT(getRefRO(myData,offset,2)==2);
2201
2202 // Test non-existent tag returns the default value.
2203 // myDataView = myData.getDataPointByTag(1);
2204 offset=myData.getOffsetForTag(1);
2205 CPPUNIT_ASSERT(offset==0);
2206 CPPUNIT_ASSERT(getRefRO(myData,offset,0)==0);
2207 CPPUNIT_ASSERT(getRefRO(myData,offset,1)==1);
2208 CPPUNIT_ASSERT(getRefRO(myData,offset,2)==2);
2209
2210 // myDataView = myData.getDefaultValue();
2211 offset=myData.getDefaultOffset();
2212 CPPUNIT_ASSERT(offset==0);
2213 CPPUNIT_ASSERT(getRefRO(myData,offset,0)==0);
2214 CPPUNIT_ASSERT(getRefRO(myData,offset,1)==1);
2215 CPPUNIT_ASSERT(getRefRO(myData,offset,2)==2);
2216
2217 // use a non-existent tag so we get a pointer to
2218 // the first element of the data array
2219 double* sampleData=myData.getSampleDataByTag(9);
2220 for (int i=0; i<myData.getLength(); i++) {
2221 CPPUNIT_ASSERT(sampleData[i]==i);
2222 }
2223 sampleData=myData.getSampleDataByTag(0);
2224 for (unsigned int i=0; i<myData.getNoValues(); i++) {
2225 CPPUNIT_ASSERT(sampleData[i]==i);
2226 }
2227
2228 }
2229
2230 {
2231
2232 cout << "\tTest DataTagged with one tag." << endl;
2233
2234 // the one data-point has tag value "1"
2235
2236 DataTagged::TagListType keys;
2237 keys.push_back(1);
2238
2239 DataTagged::ValueBatchType values;
2240
2241 DataTypes::ShapeType viewShape;
2242 viewShape.push_back(3);
2243
2244 // default value
2245 DataTypes::ValueType viewData(3*2);
2246 for (int i=0;i<viewShape[0];i++) {
2247 viewData[i]=i;
2248 }
2249 // DataArrayView myView(viewData,viewShape);
2250
2251 // value for tag "1"
2252 // DataTypes::ValueType eOneData(viewData);
2253 // DataArrayView eOneView(eOneData, viewShape);
2254 for (int i=0;i<viewShape[0];i++) {
2255 // eOneView(i)=i+1.0;
2256 viewData[viewShape[0]+i]=i+1.0;
2257 }
2258 // values.push_back(eOneView);
2259 DataTagged myData(FunctionSpace(),viewShape,keys,viewData);
2260
2261 //cout << myData.toString() << endl;
2262
2263 CPPUNIT_ASSERT(myData.getNumSamples()==1);
2264 CPPUNIT_ASSERT(myData.getNumDPPSample()==1);
2265
2266 CPPUNIT_ASSERT(myData.validSamplePointNo(0));
2267 CPPUNIT_ASSERT(myData.validSampleNo(0));
2268 CPPUNIT_ASSERT(!myData.validSamplePointNo(1));
2269 CPPUNIT_ASSERT(!myData.validSampleNo(1));
2270
2271 // data-point 0 has tag number 1 by default
2272 CPPUNIT_ASSERT(myData.getTagNumber(0)==1);
2273
2274 CPPUNIT_ASSERT(!myData.isCurrentTag(0));
2275 CPPUNIT_ASSERT(myData.isCurrentTag(1));
2276
2277 CPPUNIT_ASSERT(myData.getTagLookup().size()==1);
2278
2279 CPPUNIT_ASSERT(myData.getLength()==6);
2280
2281 CPPUNIT_ASSERT(myData.getPointOffset(0,0)==3);
2282
2283 CPPUNIT_ASSERT(myData.getRank()==1);
2284 CPPUNIT_ASSERT(myData.getNoValues()==3);
2285 CPPUNIT_ASSERT(myData.getShape().size()==1);
2286
2287
2288 int offset=myData.getPointOffset(0,0);
2289 // DataArrayView myDataView = myData.getDataPoint(0,0);
2290 CPPUNIT_ASSERT(offset==3);
2291 CPPUNIT_ASSERT(getRefRO(myData,offset,0)==1);
2292 CPPUNIT_ASSERT(getRefRO(myData,offset,1)==2);
2293 CPPUNIT_ASSERT(getRefRO(myData,offset,2)==3);
2294
2295 // myDataView = myData.getDataPointByTag(1);
2296 offset=myData.getOffsetForTag(1);
2297 CPPUNIT_ASSERT(offset==3);
2298 CPPUNIT_ASSERT(getRefRO(myData,offset,0)==1);
2299 CPPUNIT_ASSERT(getRefRO(myData,offset,1)==2);
2300 CPPUNIT_ASSERT(getRefRO(myData,offset,2)==3);
2301
2302 // Test non-existent tag returns the default value.
2303 // myDataView = myData.getDataPointByTag(9);
2304 offset=myData.getOffsetForTag(9);
2305 CPPUNIT_ASSERT(offset==0);
2306 CPPUNIT_ASSERT(getRefRO(myData,offset,0)==0);
2307 CPPUNIT_ASSERT(getRefRO(myData,offset,1)==1);
2308 CPPUNIT_ASSERT(getRefRO(myData,offset,2)==2);
2309
2310 // myDataView = myData.getDefaultValue();
2311 offset=myData.getDefaultOffset();
2312 CPPUNIT_ASSERT(offset==0);
2313 CPPUNIT_ASSERT(getRefRO(myData,offset,0)==0);
2314 CPPUNIT_ASSERT(getRefRO(myData,offset,1)==1);
2315 CPPUNIT_ASSERT(getRefRO(myData,offset,2)==2);
2316
2317 // use a non-existent tag so we get a pointer to
2318 // the first element of the data array
2319 const double* sampleData=myData.getSampleDataByTag(9);
2320 for (int i=0; i<myData.getLength(); i++) {
2321 if (i<3) {
2322 CPPUNIT_ASSERT(sampleData[i]==i);
2323 } else {
2324 CPPUNIT_ASSERT(sampleData[i]==i-2);
2325 }
2326 }
2327 sampleData=myData.getSampleDataRO(0);
2328 for (unsigned int i=0; i<myData.getNoValues(); i++) {
2329 CPPUNIT_ASSERT(sampleData[i]==i+1);
2330 }
2331
2332 }
2333
2334 {
2335
2336 cout << "\tTest DataTagged with multiple tags." << endl;
2337
2338 // the one data-point has tag value "1"
2339
2340 DataTagged::TagListType keys;
2341 keys.push_back(1);
2342 keys.push_back(2);
2343 keys.push_back(3);
2344
2345 DataTagged::ValueBatchType values;
2346
2347 DataTypes::ShapeType viewShape;
2348 viewShape.push_back(3);
2349
2350 // default value
2351 DataTypes::ValueType viewData(3*4);
2352 for (int i=0;i<viewShape[0];i++) {
2353 viewData[i]=i;
2354 }
2355 // DataArrayView myView(viewData,viewShape);
2356
2357 // value for tag "1"
2358 // DataTypes::ValueType eOneData(viewData);
2359 // DataArrayView eOneView(eOneData, viewShape);
2360 for (int i=0;i<viewShape[0];i++) {
2361 /* eOneView(i)=i+1.0;*/
2362 viewData[viewShape[0]+i]=i+1.0;
2363 }
2364 // values.push_back(eOneView);
2365
2366 // value for tag "2"
2367 // DataTypes::ValueType eTwoData(viewData);
2368 // DataArrayView eTwoView(eTwoData, viewShape);
2369 for (int i=0;i<viewShape[0];i++) {
2370 viewData[2*viewShape[0]+i]=i+2.0;
2371 }
2372 // values.push_back(eTwoView);
2373
2374 // value for tag "3"
2375 // DataTypes::ValueType eThreeData(viewData);
2376 // DataArrayView eThreeView(eThreeData, viewShape);
2377 for (int i=0;i<viewShape[0];i++) {
2378 /* eThreeView(i)=i+3.0;*/
2379 viewData[3*viewShape[0]+i]=i+3.0;
2380 }
2381 // values.push_back(eThreeView);
2382
2383 DataTagged myData(FunctionSpace(),viewShape,keys,viewData);
2384
2385 //cout << myData.toString() << endl;
2386
2387 CPPUNIT_ASSERT(myData.getNumSamples()==1);
2388 CPPUNIT_ASSERT(myData.getNumDPPSample()==1);
2389
2390 CPPUNIT_ASSERT(myData.validSamplePointNo(0));
2391 CPPUNIT_ASSERT(myData.validSampleNo(0));
2392 CPPUNIT_ASSERT(!myData.validSamplePointNo(1));
2393 CPPUNIT_ASSERT(!myData.validSampleNo(1));
2394
2395 // data-point 0 has tag number 1 by default
2396 CPPUNIT_ASSERT(myData.getTagNumber(0)==1);
2397
2398 CPPUNIT_ASSERT(!myData.isCurrentTag(0));
2399 CPPUNIT_ASSERT(myData.isCurrentTag(1));
2400 CPPUNIT_ASSERT(myData.isCurrentTag(2));
2401 CPPUNIT_ASSERT(myData.isCurrentTag(3));
2402
2403 CPPUNIT_ASSERT(myData.getTagLookup().size()==3);
2404
2405 CPPUNIT_ASSERT(myData.getLength()==12);
2406
2407 CPPUNIT_ASSERT(myData.getPointOffset(0,0)==3);
2408
2409 CPPUNIT_ASSERT(myData.getRank()==1);
2410 CPPUNIT_ASSERT(myData.getNoValues()==3);
2411 CPPUNIT_ASSERT(myData.getShape().size()==1);
2412
2413
2414 int offset=myData.getPointOffset(0,0);
2415 // DataArrayView myDataView = myData.getDataPoint(0,0);
2416 CPPUNIT_ASSERT(offset==3);
2417 CPPUNIT_ASSERT(getRefRO(myData,offset,0)==1);
2418 CPPUNIT_ASSERT(getRefRO(myData,offset,1)==2);
2419 CPPUNIT_ASSERT(getRefRO(myData,offset,2)==3);
2420
2421 // myDataView = myData.getDataPointByTag(1);
2422 offset=myData.getOffsetForTag(1);
2423 CPPUNIT_ASSERT(offset==3);
2424 CPPUNIT_ASSERT(getRefRO(myData,offset,0)==1);
2425 CPPUNIT_ASSERT(getRefRO(myData,offset,1)==2);
2426 CPPUNIT_ASSERT(getRefRO(myData,offset,2)==3);
2427
2428 // Test non-existent tag returns the default value.
2429 // myDataView = myData.getDataPointByTag(0);
2430 offset=myData.getOffsetForTag(0);
2431 CPPUNIT_ASSERT(offset==0);
2432 CPPUNIT_ASSERT(getRefRO(myData,offset,0)==0);
2433 CPPUNIT_ASSERT(getRefRO(myData,offset,1)==1);
2434 CPPUNIT_ASSERT(getRefRO(myData,offset,2)==2);
2435
2436 // myDataView = myData.getDefaultValue();
2437 offset=myData.getDefaultOffset();
2438 CPPUNIT_ASSERT(offset==0);
2439 CPPUNIT_ASSERT(getRefRO(myData,offset,0)==0);
2440 CPPUNIT_ASSERT(getRefRO(myData,offset,1)==1);
2441 CPPUNIT_ASSERT(getRefRO(myData,offset,2)==2);
2442
2443 // Test data-points held for remaining tags
2444 // myDataView = myData.getDataPointByTag(2);
2445 offset=myData.getOffsetForTag(2);
2446 CPPUNIT_ASSERT(offset==6);
2447 CPPUNIT_ASSERT(getRefRO(myData,offset,0)==2);
2448 CPPUNIT_ASSERT(getRefRO(myData,offset,1)==3);
2449 CPPUNIT_ASSERT(getRefRO(myData,offset,2)==4);
2450
2451 // myDataView = myData.getDataPointByTag(3);
2452 offset=myData.getOffsetForTag(3);
2453 CPPUNIT_ASSERT(offset==9);
2454 CPPUNIT_ASSERT(getRefRO(myData,offset,0)==3);
2455 CPPUNIT_ASSERT(getRefRO(myData,offset,1)==4);
2456 CPPUNIT_ASSERT(getRefRO(myData,offset,2)==5);
2457
2458 // use a non-existent tag so we get a pointer to
2459 // the first element of the data array
2460 const double* sampleData=myData.getSampleDataByTag(9);
2461 for (int i=0; i<myData.getLength(); i++) {
2462 if (i<3) {
2463 CPPUNIT_ASSERT(sampleData[i]==i);
2464 } else if ((i>=3) && (i<6)) {
2465 CPPUNIT_ASSERT(sampleData[i]==i-2);
2466 } else if ((i>=6) && (i<9)) {
2467 CPPUNIT_ASSERT(sampleData[i]==i-4);
2468 } else {
2469 CPPUNIT_ASSERT(sampleData[i]==i-6);
2470 }
2471 }
2472 sampleData=myData.getSampleDataRO(0);
2473 for (unsigned int i=0; i<myData.getNoValues(); i++) {
2474 CPPUNIT_ASSERT(sampleData[i]==i+1);
2475 }
2476
2477 }
2478
2479 }
2480
2481 void DataTaggedTestCase::testCopyConstructors() {
2482
2483 cout << endl;
2484
2485 {
2486
2487 cout << "\tTest DataTagged copy constructor for DataTagged with multiple tags." << endl;
2488
2489 // the one data-point has tag value "1"
2490
2491 DataTagged::TagListType keys;
2492 keys.push_back(1);
2493 keys.push_back(2);
2494 keys.push_back(3);
2495
2496 DataTagged::ValueBatchType values;
2497
2498 DataTypes::ShapeType viewShape;
2499 viewShape.push_back(3);
2500
2501 // default value
2502 DataTypes::ValueType viewData(3*4);
2503 for (int i=0;i<viewShape[0];i++) {
2504 viewData[i]=i;
2505 }
2506 // DataArrayView myView(viewData,viewShape);
2507
2508 // value for tag "1"
2509 // DataTypes::ValueType eOneData(viewData);
2510 // DataArrayView eOneView(eOneData, viewShape);
2511 for (int i=0;i<viewShape[0];i++) {
2512 viewData[viewShape[0]+i]=i+1.0;
2513 }
2514 // values.push_back(eOneView);
2515
2516 // value for tag "2"
2517 // DataTypes::ValueType eTwoData(viewData);
2518 // DataArrayView eTwoView(eTwoData, viewShape);
2519 for (int i=0;i<viewShape[0];i++) {
2520 // eTwoView(i)=i+2.0;
2521 viewData[2*viewShape[0]+i]=i+2.0;
2522 }
2523 // values.push_back(eTwoView);
2524
2525 // value for tag "3"
2526 // DataTypes::ValueType eThreeData(viewData);
2527 // DataArrayView eThreeView(eThreeData, viewShape);
2528 for (int i=0;i<viewShape[0];i++) {
2529 // eThreeView(i)=i+3.0;
2530 viewData[3*viewShape[0]+i]=i+3.0;
2531 }
2532 // values.push_back(eThreeView);
2533
2534 DataTagged myData(FunctionSpace(),viewShape,keys,viewData);
2535
2536 DataTagged myDataCopy(myData);
2537
2538 //cout << myDataCopy.toString() << endl;
2539
2540 CPPUNIT_ASSERT(myDataCopy.getNumSamples()==1);
2541 CPPUNIT_ASSERT(myDataCopy.getNumDPPSample()==1);
2542
2543 CPPUNIT_ASSERT(myDataCopy.validSamplePointNo(0));
2544 CPPUNIT_ASSERT(myDataCopy.validSampleNo(0));
2545 CPPUNIT_ASSERT(!myDataCopy.validSamplePointNo(1));
2546 CPPUNIT_ASSERT(!myDataCopy.validSampleNo(1));
2547
2548 // data-point 0 has tag number 1 by default
2549 CPPUNIT_ASSERT(myDataCopy.getTagNumber(0)==1);
2550
2551 CPPUNIT_ASSERT(!myDataCopy.isCurrentTag(0));
2552 CPPUNIT_ASSERT(myDataCopy.isCurrentTag(1));
2553 CPPUNIT_ASSERT(myDataCopy.isCurrentTag(2));
2554 CPPUNIT_ASSERT(myDataCopy.isCurrentTag(3));
2555
2556 CPPUNIT_ASSERT(myDataCopy.getTagLookup().size()==3);
2557
2558 CPPUNIT_ASSERT(myDataCopy.getLength()==12);
2559
2560 CPPUNIT_ASSERT(myDataCopy.getPointOffset(0,0)==3);
2561
2562 CPPUNIT_ASSERT(myDataCopy.getRank()==1);
2563 CPPUNIT_ASSERT(myDataCopy.getNoValues()==3);
2564 CPPUNIT_ASSERT(myDataCopy.getShape().size()==1);
2565
2566 int offset=myDataCopy.getPointOffset(0,0);
2567 // DataArrayView myDataView = myDataCopy.getDataPoint(0,0);
2568 CPPUNIT_ASSERT(offset==3);
2569 CPPUNIT_ASSERT(getRefRO(myDataCopy,offset,0)==1);
2570 CPPUNIT_ASSERT(getRefRO(myDataCopy,offset,1)==2);
2571 CPPUNIT_ASSERT(getRefRO(myDataCopy,offset,2)==3);
2572
2573 // myDataView = myDataCopy.getDataPointByTag(1);
2574 offset=myDataCopy.getOffsetForTag(1);
2575 CPPUNIT_ASSERT(offset==3);
2576 CPPUNIT_ASSERT(getRefRO(myDataCopy,offset,0)==1);
2577 CPPUNIT_ASSERT(getRefRO(myDataCopy,offset,1)==2);
2578 CPPUNIT_ASSERT(getRefRO(myDataCopy,offset,2)==3);
2579
2580 // Test non-existent tag returns the default value.
2581 // myDataView = myDataCopy.getDataPointByTag(0);
2582 offset=myDataCopy.getOffsetForTag(0);
2583 CPPUNIT_ASSERT(offset==0);
2584 CPPUNIT_ASSERT(getRefRO(myDataCopy,offset,0)==0);
2585 CPPUNIT_ASSERT(getRefRO(myDataCopy,offset,1)==1);
2586 CPPUNIT_ASSERT(getRefRO(myDataCopy,offset,2)==2);
2587
2588 //myDataView = myDataCopy.getDefaultValue();
2589 offset=myDataCopy.getDefaultOffset();
2590 CPPUNIT_ASSERT(offset==0);
2591 CPPUNIT_ASSERT(getRefRO(myDataCopy,offset,0)==0);
2592 CPPUNIT_ASSERT(getRefRO(myDataCopy,offset,1)==1);
2593 CPPUNIT_ASSERT(getRefRO(myDataCopy,offset,2)==2);
2594
2595 // Test data-points held for remaining tags
2596 // myDataView = myDataCopy.getDataPointByTag(2);
2597 offset=myDataCopy.getOffsetForTag(2);
2598 CPPUNIT_ASSERT(offset==6);
2599 CPPUNIT_ASSERT(getRefRO(myDataCopy,offset,0)==2);
2600 CPPUNIT_ASSERT(getRefRO(myDataCopy,offset,1)==3);
2601 CPPUNIT_ASSERT(getRefRO(myDataCopy,offset,2)==4);
2602
2603 // myDataView = myDataCopy.getDataPointByTag(3);
2604 offset=myDataCopy.getOffsetForTag(3);
2605 CPPUNIT_ASSERT(offset==9);
2606 CPPUNIT_ASSERT(getRefRO(myDataCopy,offset,0)==3);
2607 CPPUNIT_ASSERT(getRefRO(myDataCopy,offset,1)==4);
2608 CPPUNIT_ASSERT(getRefRO(myDataCopy,offset,2)==5);
2609
2610 // use a non-existent tag so we get a pointer to
2611 // the first element of the data array
2612 double* sampleData=myDataCopy.getSampleDataByTag(9);
2613 for (int i=0; i<myData.getLength(); i++) {
2614 if (i<3) {
2615 CPPUNIT_ASSERT(sampleData[i]==i);
2616 } else if ((i>=3) && (i<6)) {
2617 CPPUNIT_ASSERT(sampleData[i]==i-2);
2618 } else if ((i>=6) && (i<9)) {
2619 CPPUNIT_ASSERT(sampleData[i]==i-4);
2620 } else {
2621 CPPUNIT_ASSERT(sampleData[i]==i-6);
2622 }
2623 }
2624
2625 }
2626
2627 {
2628
2629 cout << "\tTest DataTagged copy constructor for DataConstant." << endl;
2630
2631 // Create a DataConstant
2632 DataTypes::ShapeType shape;
2633 DataTypes::ValueType data(DataTypes::noValues(shape),0);
2634 // DataArrayView pointData(data,shape);
2635 data[0]=1.0;
2636 DataConstant myConstantData(FunctionSpace(),shape,data);
2637
2638 // use this DataConstant to initialise a DataTagged
2639 DataTagged myData(myConstantData);
2640
2641 //cout << myData.toString() << endl;
2642
2643 CPPUNIT_ASSERT(myData.getNumSamples()==1);
2644 CPPUNIT_ASSERT(myData.getNumDPPSample()==1);
2645
2646 CPPUNIT_ASSERT(myData.validSamplePointNo(0));
2647 CPPUNIT_ASSERT(myData.validSampleNo(0));
2648 CPPUNIT_ASSERT(!myData.validSamplePointNo(1));
2649 CPPUNIT_ASSERT(!myData.validSampleNo(1));
2650
2651 // data-point 0 has tag number 1 by default
2652 CPPUNIT_ASSERT(myData.getTagNumber(0)==1);
2653
2654 CPPUNIT_ASSERT(!myData.isCurrentTag(1));
2655
2656 CPPUNIT_ASSERT(myData.getTagLookup().size()==0);
2657
2658 CPPUNIT_ASSERT(myData.getLength()==1);
2659
2660 CPPUNIT_ASSERT(myData.getPointOffset(0,0)==0);
2661
2662 CPPUNIT_ASSERT(myData.getRank()==0);
2663 CPPUNIT_ASSERT(myData.getNoValues()==1);
2664 CPPUNIT_ASSERT(myData.getShape().size()==0);
2665
2666
2667 // DataArrayView myDataView = myData.getDataPoint(0,0);
2668 int offset=myData.getPointOffset(0,0);
2669 CPPUNIT_ASSERT(offset==0);
2670 CPPUNIT_ASSERT(myData.getDataAtOffsetRO(offset)==1.0);
2671
2672 // Test non-existent tag returns the default value.
2673 // myDataView = myData.getDataPointByTag(1);
2674 offset=myData.getOffsetForTag(1);
2675 CPPUNIT_ASSERT(offset==0);
2676 CPPUNIT_ASSERT(myData.getDataAtOffsetRO(offset)==1.0);
2677
2678 // myDataView = myData.getDefaultValue();
2679 offset=myData.getDefaultOffset();
2680 CPPUNIT_ASSERT(offset==0);
2681 CPPUNIT_ASSERT(myData.getDataAtOffsetRO(offset)==1.0);
2682
2683 // use a non-existent tag so we get a pointer to
2684 // the first element of the data array
2685 double* sampleData=myData.getSampleDataByTag(9);
2686 for (int i=0; i<myData.getLength(); i++) {
2687 CPPUNIT_ASSERT(sampleData[i]==i+1);
2688 }
2689
2690 }
2691
2692 }
2693
2694 void DataTaggedTestCase::testGetSlice() {
2695
2696 cout << endl;
2697
2698 {
2699
2700 cout << "\tTest slicing default DataTagged." << endl;
2701
2702 DataTagged myData;
2703
2704 DataTypes::RegionType region;
2705
2706 DataAbstract* slicedDefault = myData.getSlice(region);
2707
2708 // cout << slicedDefault->toString() << endl;
2709
2710 const DataTagged* myDataSliced=dynamic_cast<const DataTagged*>(slicedDefault);
2711
2712 CPPUNIT_ASSERT(myDataSliced->getTagLookup().size()==0);
2713
2714 CPPUNIT_ASSERT(myDataSliced->getLength()==1);
2715
2716 // DataArrayView myDataView = myDataSliced->getDefaultValue();
2717 int offset=myDataSliced->getDefaultOffset();
2718 CPPUNIT_ASSERT(offset==0);
2719 CPPUNIT_ASSERT(myDataSliced->getRank()==0);
2720 CPPUNIT_ASSERT(myDataSliced->getNoValues()==1);
2721 CPPUNIT_ASSERT(myDataSliced->getShape().size()==0);
2722 CPPUNIT_ASSERT(myDataSliced->getVectorRO()[0]==0.0);
2723
2724 delete slicedDefault;
2725 }
2726
2727 {
2728
2729 cout << "\tTest slicing DataTagged with rank 1 default value only." << endl;
2730
2731 DataTypes::ShapeType viewShape;
2732 viewShape.push_back(3);
2733
2734 DataTagged::TagListType keys;
2735
2736 DataTagged::ValueBatchType values;
2737
2738 DataTypes::ValueType viewData(3);
2739 for (int i=0;i<viewShape[0];i++) {
2740 viewData[i]=i;
2741 }
2742 // DataArrayView myView(viewData,viewShape);
2743
2744 DataTagged myData(FunctionSpace(),viewShape,viewData);
2745
2746 // full slice
2747
2748 std::pair<int, int> region_element;
2749 region_element.first=0;
2750 region_element.second=3;
2751 DataTypes::RegionType region;
2752 region.push_back(region_element);
2753
2754 DataAbstract* slicedDefault = myData.getSlice(region);
2755
2756 //cout << slicedDefault->toString() << endl;
2757
2758 const DataTagged* myDataSliced=dynamic_cast<const DataTagged*>(slicedDefault);
2759
2760 CPPUNIT_ASSERT(myDataSliced->getTagLookup().size()==0);
2761
2762 CPPUNIT_ASSERT(myDataSliced->getLength()==3);
2763
2764 CPPUNIT_ASSERT(myDataSliced->getRank()==1);
2765 CPPUNIT_ASSERT(myDataSliced->getNoValues()==3);
2766 CPPUNIT_ASSERT(myDataSliced->getShape().size()==1);
2767
2768 // DataArrayView myDataView = myDataSliced->getDefaultValue();
2769 int offset=myDataSliced->getDefaultOffset();
2770 CPPUNIT_ASSERT(offset==0);
2771
2772 CPPUNIT_ASSERT(getRefRO(*myDataSliced,offset,0)==0.0);
2773 CPPUNIT_ASSERT(getRefRO(*myDataSliced,offset,1)==1.0);
2774 CPPUNIT_ASSERT(getRefRO(*myDataSliced,offset,2)==2.0);
2775
2776 // scalar slice
2777
2778 region.clear();
2779 region_element.first=0;
2780 region_element.second=0;
2781 region.push_back(region_element);
2782
2783 delete slicedDefault;
2784
2785 slicedDefault = myData.getSlice(region);
2786
2787 //cout << slicedDefault->toString() << endl;
2788
2789 myDataSliced=dynamic_cast<const DataTagged*>(slicedDefault);
2790
2791 CPPUNIT_ASSERT(myDataSliced->getTagLookup().size()==0);
2792
2793 CPPUNIT_ASSERT(myDataSliced->getLength()==1);
2794
2795 // myDataView = myDataSliced->getDefaultValue();
2796 offset=myDataSliced->getDefaultOffset();
2797 CPPUNIT_ASSERT(offset==0);
2798 CPPUNIT_ASSERT(myDataSliced->getRank()==0);
2799 CPPUNIT_ASSERT(myDataSliced->getNoValues()==1);
2800 CPPUNIT_ASSERT(myDataSliced->getShape().size()==0);
2801 CPPUNIT_ASSERT(myDataSliced->getVectorRO()[0]==0.0);
2802
2803 delete slicedDefault;
2804 }
2805
2806 {
2807
2808 cout << "\tTest slicing DataTagged with rank 3 default value only." << endl;
2809
2810 DataTypes::ShapeType viewShape;
2811 viewShape.push_back(3);
2812 viewShape.push_back(3);
2813 viewShape.push_back(3);
2814
2815 DataTagged::TagListType keys;
2816
2817 DataTagged::ValueBatchType values;
2818
2819 DataTypes::ValueType viewData(27);
2820 for (int i=0;i<viewData.size();i++) {
2821 viewData[i]=i;
2822 }
2823 // DataArrayView myView(viewData,viewShape);
2824
2825 DataTagged myData(FunctionSpace(),viewShape,viewData);
2826
2827 //cout << myData.toString() << endl;
2828
2829 // full slice
2830
2831 std::pair<int, int> region_element;
2832 region_element.first=0;
2833 region_element.second=3;
2834 DataTypes::RegionType region;
2835 region.push_back(region_element);
2836 region.push_back(region_element);
2837 region.push_back(region_element);
2838
2839 DataAbstract* slicedDefault = myData.getSlice(region);
2840
2841 //cout << slicedDefault->toString() << endl;
2842
2843 const DataTagged* myDataSliced=dynamic_cast<const DataTagged*>(slicedDefault);
2844
2845 CPPUNIT_ASSERT(myDataSliced->getTagLookup().size()==0);
2846
2847 CPPUNIT_ASSERT(myDataSliced->getLength()==27);
2848
2849 // DataArrayView myDataView = myDataSliced->getDefaultValue();
2850 int offset=myDataSliced->getDefaultOffset();
2851 CPPUNIT_ASSERT(offset==0);
2852 CPPUNIT_ASSERT(myDataSliced->getRank()==3);
2853 CPPUNIT_ASSERT(myDataSliced->getNoValues()==27);
2854 CPPUNIT_ASSERT(myDataSliced->getShape().size()==3);
2855
2856 // rank 1 slice
2857
2858 region.clear();
2859 region.push_back(region_element);
2860 region_element.second=0;
2861 region.push_back(region_element);
2862 region.push_back(region_element);
2863
2864 delete slicedDefault;
2865
2866 slicedDefault = myData.getSlice(region);
2867
2868 //cout << slicedDefault->toString() << endl;
2869
2870 myDataSliced=dynamic_cast<const DataTagged*>(slicedDefault);
2871
2872 CPPUNIT_ASSERT(myDataSliced->getTagLookup().size()==0);
2873
2874 CPPUNIT_ASSERT(myDataSliced->getLength()==3);
2875
2876 CPPUNIT_ASSERT(myDataSliced->getRank()==1);
2877 CPPUNIT_ASSERT(myDataSliced->getNoValues()==3);
2878 CPPUNIT_ASSERT(myDataSliced->getShape().size()==1);
2879
2880 // myDataView = myDataSliced->getDefaultValue();
2881 offset=myDataSliced->getDefaultOffset();
2882 CPPUNIT_ASSERT(offset==0);
2883 CPPUNIT_ASSERT(getRefRO(*myDataSliced,offset,0)==0.0);
2884 CPPUNIT_ASSERT(getRefRO(*myDataSliced,offset,1)==1.0);
2885 CPPUNIT_ASSERT(getRefRO(*myDataSliced,offset,2)==2.0);
2886
2887 // scalar slice
2888
2889 region.clear();
2890 region_element.first=2;
2891 region_element.second=2;
2892 region.push_back(region_element);
2893 region.push_back(region_element);
2894 region.push_back(region_element);
2895
2896 delete slicedDefault;
2897
2898 slicedDefault = myData.getSlice(region);
2899
2900 //cout << slicedDefault->toString() << endl;
2901
2902 myDataSliced=dynamic_cast<const DataTagged*>(slicedDefault);
2903
2904 CPPUNIT_ASSERT(myDataSliced->getTagLookup().size()==0);
2905
2906 CPPUNIT_ASSERT(myDataSliced->getLength()==1);
2907
2908 CPPUNIT_ASSERT(myDataSliced->getRank()==0);
2909 CPPUNIT_ASSERT(myDataSliced->getNoValues()==1);
2910 CPPUNIT_ASSERT(myDataSliced->getShape().size()==0);
2911
2912
2913 // myDataView = myDataSliced->getDefaultValue();
2914 offset=myDataSliced->getDefaultOffset();
2915 CPPUNIT_ASSERT(offset==0);
2916 CPPUNIT_ASSERT(myDataSliced->getVectorRO()[0]==26);
2917 delete slicedDefault;
2918 }
2919
2920 {
2921
2922 cout << "\tTest slicing DataTagged with scalar values and one tag." << endl;
2923
2924 DataTagged::TagListType keys;
2925 keys.push_back(1);
2926
2927 DataTagged::ValueBatchType values;
2928
2929 DataTypes::ShapeType viewShape;
2930
2931 // default value
2932 DataTypes::ValueType viewData(1*2);
2933 viewData[0]=0.0;
2934 // DataArrayView myView(viewData,viewShape);
2935
2936 // value for tag "1"
2937 // DataTypes::ValueType eOneData(viewData);
2938 // DataArrayView eOneView(eOneData, viewShape);
2939 viewData[1]=1.0;
2940 // values.push_back(eOneView);
2941
2942 DataTagged myData(FunctionSpace(),viewShape,keys, viewData);
2943
2944 //cout << myData.toString() << endl;
2945
2946 // full slice
2947
2948 DataTypes::RegionType region;
2949
2950 DataAbstract* slicedDefault = myData.getSlice(region);
2951
2952 //cout << slicedDefault->toString() << endl;
2953
2954 const DataTagged* myDataSliced=dynamic_cast<const DataTagged*>(slicedDefault);
2955
2956 CPPUNIT_ASSERT(myDataSliced->getTagLookup().size()==1);
2957
2958 CPPUNIT_ASSERT(myDataSliced->getLength()==2);
2959
2960 // DataArrayView myDataView = myDataSliced->getDefaultValue();
2961 int offset=myDataSliced->getDefaultOffset();
2962 CPPUNIT_ASSERT(offset==0);
2963 CPPUNIT_ASSERT(myDataSliced->getRank()==0);
2964 CPPUNIT_ASSERT(myDataSliced->getNoValues()==1);
2965 CPPUNIT_ASSERT(myDataSliced->getShape().size()==0);
2966 CPPUNIT_ASSERT(myDataSliced->getVectorRO()[offset]==0);
2967
2968 // myDataView = myDataSliced->getDataPointByTag(1);
2969 offset=myDataSliced->getOffsetForTag(1);
2970 CPPUNIT_ASSERT(offset==1);
2971 CPPUNIT_ASSERT(myDataSliced->getVectorRO()[offset]==1);
2972
2973 delete slicedDefault;
2974
2975 }
2976
2977 {
2978
2979 cout << "\tTest slicing DataTagged with rank 1 values and one tag." << endl;
2980
2981 DataTypes::ShapeType viewShape;
2982 viewShape.push_back(3);
2983
2984 DataTagged::TagListType keys;
2985 keys.push_back(1);
2986
2987 DataTagged::ValueBatchType values;
2988
2989 // default value
2990 DataTypes::ValueType viewData(3*2);
2991 for (int i=0;i<viewShape[0];i++) {
2992 viewData[i]=i;
2993 }
2994 // DataArrayView myView(viewData,viewShape);
2995
2996 // value for tag "1"
2997 // DataTypes::ValueType eOneData(viewData);
2998 // DataArrayView eOneView(eOneData, viewShape);
2999 for (int i=0;i<viewShape[0];i++) {
3000 // eOneView(i)=i+3.0;
3001 viewData[viewShape[0]+i]=i+3.0;
3002 }
3003 // values.push_back(eOneView);
3004
3005 DataTagged myData(FunctionSpace(),viewShape,keys,viewData);
3006
3007 //cout << myData.toString() << endl;
3008
3009 // full slice
3010
3011 std::pair<int, int> region_element;
3012 region_element.first=0;
3013 region_element.second=3;
3014 DataTypes::RegionType region;
3015 region.push_back(region_element);
3016
3017 DataAbstract* slicedDefault = myData.getSlice(region);
3018
3019 //cout << slicedDefault->toString() << endl;
3020
3021 const DataTagged* myDataSliced=dynamic_cast<const DataTagged*>(slicedDefault);
3022
3023 CPPUNIT_ASSERT(myDataSliced->getTagLookup().size()==1);
3024
3025 CPPUNIT_ASSERT(myDataSliced->getLength()==6);
3026 CPPUNIT_ASSERT(myDataSliced->getRank()==1);
3027 CPPUNIT_ASSERT(myDataSliced->getNoValues()==3);
3028 CPPUNIT_ASSERT(myDataSliced->getShape().size()==1);
3029 // DataArrayView myDataView = myDataSliced->getDefaultValue();
3030 int offset=myDataSliced->getDefaultOffset();
3031 CPPUNIT_ASSERT(offset==0);
3032 CPPUNIT_ASSERT(getRefRO(*myDataSliced,offset,0)==0);
3033 CPPUNIT_ASSERT(getRefRO(*myDataSliced,offset,1)==1);
3034 CPPUNIT_ASSERT(getRefRO(*myDataSliced,offset,2)==2);
3035
3036 // myDataView = myDataSliced->getDataPointByTag(1);
3037 offset=myDataSliced->getOffsetForTag(1);
3038 CPPUNIT_ASSERT(offset==3);
3039 CPPUNIT_ASSERT(getRefRO(*myDataSliced,offset,0)==3);
3040 CPPUNIT_ASSERT(getRefRO(*myDataSliced,offset,1)==4);
3041 CPPUNIT_ASSERT(getRefRO(*myDataSliced,offset,2)==5);
3042
3043 // scalar slice
3044
3045 region_element.first=1;
3046 region_element.second=1;
3047 region.clear();
3048 region.push_back(region_element);
3049
3050 delete slicedDefault;
3051
3052 slicedDefault = myData.getSlice(region);
3053
3054 //cout << slicedDefault->toString() << endl;
3055
3056 myDataSliced=dynamic_cast<const DataTagged*>(slicedDefault);
3057
3058 CPPUNIT_ASSERT(myDataSliced->getTagLookup().size()==1);
3059
3060 CPPUNIT_ASSERT(myDataSliced->getLength()==2);
3061
3062 CPPUNIT_ASSERT(myDataSliced->getRank()==0);
3063 CPPUNIT_ASSERT(myDataSliced->getNoValues()==1);
3064 CPPUNIT_ASSERT(myDataSliced->getShape().size()==0);
3065
3066
3067 // myDataView = myDataSliced->getDefaultValue();
3068 offset=myDataSliced->getDefaultOffset();
3069 CPPUNIT_ASSERT(offset==0);
3070 CPPUNIT_ASSERT(myDataSliced->getVectorRO()[offset]==1);
3071
3072 // myDataView = myDataSliced->getDataPointByTag(1);
3073 offset=myDataSliced->getOffsetForTag(1);
3074 CPPUNIT_ASSERT(offset==1);
3075 CPPUNIT_ASSERT(myDataSliced->getVectorRO()[offset]==4);
3076 delete slicedDefault;
3077
3078 }
3079
3080 {
3081
3082 cout << "\tTest slicing DataTagged with rank 3 values and one tag." << endl;
3083 DataTypes::ShapeType viewShape;
3084 viewShape.push_back(3);
3085 viewShape.push_back(3);
3086 viewShape.push_back(3);
3087
3088 DataTagged::TagListType keys;
3089 keys.push_back(1);
3090
3091 DataTagged::ValueBatchType values;
3092
3093 // default value
3094 DataTypes::ValueType viewData(27*2);
3095 for (int i=0;i<noValues(viewShape);i++) {
3096 viewData[i]=i;
3097 }
3098 // DataArrayView myView(viewData,viewShape);
3099
3100 // value for tag "1"
3101 // DataTypes::ValueType viewData1(27);
3102 for (int i=0;i<noValues(viewShape);i++) {
3103 viewData[noValues(viewShape)+i]=i+27.0;
3104 }
3105 // DataArrayView myView1(viewData1,viewShape);
3106 // values.push_back(myView1);
3107
3108 DataTagged myData(FunctionSpace(),viewShape,keys,viewData);
3109
3110 //cout << myData.toString() << endl;
3111
3112 // full slice
3113
3114 std::pair<int, int> region_element;
3115 region_element.first=0;
3116 region_element.second=3;
3117 DataTypes::RegionType region;
3118 region.push_back(region_element);
3119 region.push_back(region_element);
3120 region.push_back(region_element);
3121
3122 DataAbstract* slicedDefault = myData.getSlice(region);
3123
3124 //cout << slicedDefault->toString() << endl;
3125
3126 const DataTagged* myDataSliced=dynamic_cast<const DataTagged*>(slicedDefault);
3127
3128 CPPUNIT_ASSERT(myDataSliced->getTagLookup().size()==1);
3129
3130 CPPUNIT_ASSERT(myDataSliced->getLength()==54);
3131
3132 CPPUNIT_ASSERT(myDataSliced->getRank()==3);
3133 CPPUNIT_ASSERT(myDataSliced->getNoValues()==27);
3134 CPPUNIT_ASSERT(myDataSliced->getShape().size()==3);
3135
3136 // DataArrayView myDataView = myDataSliced->getDefaultValue();
3137 int offset=myDataSliced->getDefaultOffset();
3138 CPPUNIT_ASSERT(offset==0);
3139
3140 // myDataView = myDataSliced->getDataPointByTag(1);
3141 offset=myDataSliced->getOffsetForTag(1);
3142 CPPUNIT_ASSERT(offset==27);
3143
3144 // rank 1 slice
3145