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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1811 - (show annotations)
Thu Sep 25 23:11:13 2008 UTC (11 years, 1 month ago) by ksteube
File size: 146616 byte(s)
Copyright updated in all files

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