/[escript]/branches/arrayview_from_1695_trunk/escript/test/DataTaggedTestCase.cpp
ViewVC logotype

Contents of /branches/arrayview_from_1695_trunk/escript/test/DataTaggedTestCase.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1781 - (show annotations)
Thu Sep 11 05:03:14 2008 UTC (10 years, 11 months ago) by jfenwick
File size: 143803 byte(s)
Branch commit

Merged changes from trunk version 1695 up to and including version 1779.


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