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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1802 - (show annotations)
Tue Sep 23 01:03:29 2008 UTC (11 years, 1 month ago) by jfenwick
File size: 146651 byte(s)
Added canTag methods to FunctionSpace and AbstractDomain (and its 
offspring).
This checks to see if the domain supports tags for the given type of 
function space.

Constructors for DataTagged now throw exceptions if you attempt to make 
a DataTagged with a FunctionSpace which does not support tags.
To allow the default constructor to work, NullDomain has a single 
functioncode which "supports" tagging.

Fixed a bug in DataTagged::toString and DataTypes::pointToString.

Added FunctionSpace::getListOfTagsSTL.

algorithm(DataTagged, BinaryFunction) in DataAlgorithm now only 
processes tags known to be in use.
This fixes mantis issue #0000186.

Added comment to Data.h intro warning about holding references if the 
underlying DataAbstract changes.

_python_ unit tests have been updated to test TaggedData with invalid 
FunctionSpaces and to give the correct answers to Lsup etc.


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