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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3259 - (show annotations)
Mon Oct 11 01:48:14 2010 UTC (8 years, 11 months ago) by jfenwick
File size: 147396 byte(s)
Merging dudley and scons updates from branches

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