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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 670 - (hide annotations)
Sat Mar 25 14:56:39 2006 UTC (13 years, 8 months ago) by robwdcock
Original Path: branches/ROBW_XPLATFORM/escript/test/DataTaggedTestCase.cpp
File size: 158653 byte(s)
+ Changed include paths to no longer require the cpp suffix (missed in earlier
  commit)
+ modified tests so they no longer install to #/lib

1 jgs 82 // $Id$
2 jgs 548
3 jgs 82 /*
4     *****************************************************************************
5     * *
6     * COPYRIGHT ACcESS - All Rights Reserved *
7     * *
8     * This software is the property of ACcESS. No part of this code *
9     * may be copied in any form or by any means without the expressed written *
10     * consent of ACcESS. Copying, use or modification of this software *
11     * by any unauthorised person is illegal unless that person has a software *
12     * license agreement with ACcESS. *
13     * *
14     *****************************************************************************
15     */
16 jgs 497
17 robwdcock 638 #include "esysUtils/EsysException.h"
18 jgs 497
19 robwdcock 670 #include "escript/DataTagged.h"
20     #include "escript/DataConstant.h"
21 jgs 497
22     #include "DataTaggedTestCase.h"
23    
24 robwdcock 670 #include "escript/BinaryOp.h"
25     #include "escript/UnaryOp.h"
26     #include "escript/FunctionSpaceFactory.h"
27     #include "escript/DataFactory.h"
28 jgs 82
29     #include <iostream>
30     #include <functional>
31     #include <algorithm>
32    
33     using namespace CppUnitTest;
34     using namespace escript;
35     using namespace esysUtils;
36     using namespace std;
37    
38     void DataTaggedTestCase::setUp() {
39     //
40     // This is called before each test is run
41    
42     }
43    
44     void DataTaggedTestCase::tearDown() {
45     //
46     // This is called after each test has been run
47    
48     }
49    
50     void DataTaggedTestCase::testReshape() {
51    
52     cout << endl;
53    
54     {
55 jgs 508
56     cout << "\tTest rank 1 reshape of default DataTagged." << endl;
57    
58     DataTagged myData;
59     myData.getPointDataView()()=1.0;
60    
61 jgs 82 DataArrayView::ShapeType shape;
62     shape.push_back(2);
63 jgs 508
64     myData.reshapeDataPoint(shape);
65    
66     for (int i=0;i<shape[0];i++) {
67     assert(myData.getDefaultValue()(i)==1);
68 jgs 82 }
69 jgs 508
70     //cout << myData.toString() << endl;
71    
72     assert(myData.getNumSamples()==1);
73     assert(myData.getNumDPPSample()==1);
74    
75     assert(myData.validSamplePointNo(0));
76     assert(myData.validSampleNo(0));
77     assert(!myData.validSamplePointNo(1));
78     assert(!myData.validSampleNo(1));
79    
80     // data-point 0 has tag number 1 by default
81     assert(myData.getTagNumber(0)==1);
82    
83     assert(!myData.isCurrentTag(1));
84    
85     assert(myData.getTagLookup().size()==0);
86    
87     assert(myData.getLength()==2);
88    
89     assert(myData.getPointOffset(0,0)==0);
90    
91     DataArrayView myDataView = myData.getDataPoint(0,0);
92     assert(!myDataView.isEmpty());
93     assert(myDataView.getOffset()==0);
94     assert(myDataView.getRank()==1);
95     assert(myDataView.noValues()==2);
96     assert(myDataView.getShape().size()==1);
97     assert(myDataView(0)==1.0);
98     assert(myDataView(1)==1.0);
99    
100     // Test non-existent tag returns the default value.
101     myDataView = myData.getDataPointByTag(1);
102     assert(!myDataView.isEmpty());
103     assert(myDataView.getOffset()==0);
104     assert(myDataView.getRank()==1);
105     assert(myDataView.noValues()==2);
106     assert(myDataView.getShape().size()==1);
107     assert(myDataView(0)==1.0);
108     assert(myDataView(1)==1.0);
109    
110     myDataView = myData.getDefaultValue();
111     assert(!myDataView.isEmpty());
112     assert(myDataView.getOffset()==0);
113     assert(myDataView.getRank()==1);
114     assert(myDataView.noValues()==2);
115     assert(myDataView.getShape().size()==1);
116     assert(myDataView(0)==1.0);
117     assert(myDataView(1)==1.0);
118    
119     // use a non-existent tag so we get a pointer to
120     // the first element of the data array
121     double* sampleData=myData.getSampleDataByTag(9);
122     for (int i=0; i<myData.getLength(); i++) {
123     assert(sampleData[i]==1.0);
124     }
125    
126 jgs 82 }
127 jgs 508
128 jgs 82 {
129 jgs 508
130     cout << "\tTest rank 2 reshape of DataTagged with one tag." << endl;
131    
132     DataTagged::TagListType keys;
133     keys.push_back(1);
134    
135     DataTagged::ValueListType values;
136    
137     DataArrayView::ShapeType viewShape;
138    
139     // default value
140     DataArrayView::ValueType viewData(1);
141     viewData[0]=1.0;
142     DataArrayView myView(viewData,viewShape);
143    
144     // value for tag "1"
145     DataArray eOne(myView);
146     eOne.getView()()=2.0;
147     values.push_back(eOne.getView());
148    
149     DataTagged myData(keys,values,myView,FunctionSpace());
150    
151 jgs 82 DataArrayView::ShapeType shape;
152     shape.push_back(2);
153     shape.push_back(5);
154 jgs 508
155     myData.reshapeDataPoint(shape);
156    
157     //cout << myData.toString() << endl;
158    
159     assert(myData.getNumSamples()==1);
160     assert(myData.getNumDPPSample()==1);
161    
162     assert(myData.validSamplePointNo(0));
163     assert(myData.validSampleNo(0));
164     assert(!myData.validSamplePointNo(1));
165     assert(!myData.validSampleNo(1));
166    
167     // data-point 0 has tag number 1 by default
168     assert(myData.getTagNumber(0)==1);
169    
170     assert(myData.isCurrentTag(1));
171    
172     assert(myData.getTagLookup().size()==1);
173    
174     assert(myData.getLength()==20);
175    
176     assert(myData.getPointOffset(0,0)==10);
177    
178     DataArrayView myDataView = myData.getDataPoint(0,0);
179     assert(!myDataView.isEmpty());
180     assert(myDataView.getOffset()==10);
181     assert(myDataView.getRank()==2);
182     assert(myDataView.noValues()==10);
183     assert(myDataView.getShape().size()==2);
184     for (int j=0;j<shape[1];j++) {
185     for (int i=0;i<shape[0];i++) {
186     assert(myDataView(i,j)==2.0);
187 jgs 82 }
188     }
189 jgs 508
190     myDataView = myData.getDataPointByTag(1);
191     assert(!myDataView.isEmpty());
192     assert(myDataView.getOffset()==10);
193     assert(myDataView.getRank()==2);
194     assert(myDataView.noValues()==10);
195     assert(myDataView.getShape().size()==2);
196     for (int j=0;j<shape[1];j++) {
197     for (int i=0;i<shape[0];i++) {
198     assert(myDataView(i,j)==2.0);
199     }
200     }
201    
202     myDataView = myData.getDefaultValue();
203     assert(!myDataView.isEmpty());
204     assert(myDataView.getOffset()==0);
205     assert(myDataView.getRank()==2);
206     assert(myDataView.noValues()==10);
207     assert(myDataView.getShape().size()==2);
208     for (int j=0;j<shape[1];j++) {
209     for (int i=0;i<shape[0];i++) {
210     assert(myDataView(i,j)==1.0);
211     }
212     }
213    
214     // use a non-existent tag so we get a pointer to
215     // the first element of the data array
216     double* sampleData=myData.getSampleDataByTag(9);
217     for (int i=0; i<myData.getLength(); i++) {
218     if (i<10) {
219     assert(sampleData[i]==1.0);
220     } else {
221     assert(sampleData[i]==2.0);
222     }
223     }
224    
225 jgs 82 }
226 jgs 508
227     {
228    
229     cout << "\tTest rank 3 reshape of DataTagged with three tags." << endl;
230    
231     DataTagged::TagListType keys;
232     keys.push_back(1);
233     keys.push_back(2);
234     keys.push_back(3);
235    
236     DataTagged::ValueListType values;
237    
238     DataArrayView::ShapeType viewShape;
239    
240     // default value
241     DataArrayView::ValueType viewData(1);
242     viewData[0]=0.0;
243     DataArrayView myView(viewData,viewShape);
244    
245     // value for tag "1"
246     DataArray eOne(myView);
247     eOne.getView()()=1.0;
248     values.push_back(eOne.getView());
249    
250     // value for tag "2"
251     DataArray eTwo(myView);
252     eTwo.getView()()=2.0;
253     values.push_back(eTwo.getView());
254    
255     // value for tag "3"
256     DataArray eThree(myView);
257     eThree.getView()()=3.0;
258     values.push_back(eThree.getView());
259    
260     DataTagged myData(keys,values,myView,FunctionSpace());
261    
262     DataArrayView::ShapeType shape;
263     shape.push_back(2);
264     shape.push_back(2);
265     shape.push_back(2);
266    
267     myData.reshapeDataPoint(shape);
268    
269     //cout << myData.toString() << endl;
270    
271     assert(myData.getNumSamples()==1);
272     assert(myData.getNumDPPSample()==1);
273    
274     assert(myData.validSamplePointNo(0));
275     assert(myData.validSampleNo(0));
276     assert(!myData.validSamplePointNo(1));
277     assert(!myData.validSampleNo(1));
278    
279     // data-point 0 has tag number 1 by default
280     assert(myData.getTagNumber(0)==1);
281    
282     assert(myData.isCurrentTag(1));
283     assert(myData.isCurrentTag(2));
284     assert(myData.isCurrentTag(3));
285    
286     assert(myData.getTagLookup().size()==3);
287    
288     assert(myData.getLength()==32);
289    
290     assert(myData.getPointOffset(0,0)==8);
291    
292     DataArrayView myDataView = myData.getDataPoint(0,0);
293     assert(!myDataView.isEmpty());
294     assert(myDataView.getOffset()==8);
295     assert(myDataView.getRank()==3);
296     assert(myDataView.noValues()==8);
297     assert(myDataView.getShape().size()==3);
298     for (int k=0;k<shape[2];k++) {
299     for (int j=0;j<shape[1];j++) {
300     for (int i=0;i<shape[0];i++) {
301     assert(myDataView(i,j,k)==1.0);
302     }
303     }
304     }
305    
306     myDataView = myData.getDataPointByTag(1);
307     assert(!myDataView.isEmpty());
308     assert(myDataView.getOffset()==8);
309     assert(myDataView.getRank()==3);
310     assert(myDataView.noValues()==8);
311     assert(myDataView.getShape().size()==3);
312     for (int k=0;k<shape[2];k++) {
313     for (int j=0;j<shape[1];j++) {
314     for (int i=0;i<shape[0];i++) {
315     assert(myDataView(i,j,k)==1.0);
316     }
317     }
318     }
319    
320     myDataView = myData.getDataPointByTag(2);
321     assert(!myDataView.isEmpty());
322     assert(myDataView.getOffset()==16);
323     assert(myDataView.getRank()==3);
324     assert(myDataView.noValues()==8);
325     assert(myDataView.getShape().size()==3);
326     for (int k=0;k<shape[2];k++) {
327     for (int j=0;j<shape[1];j++) {
328     for (int i=0;i<shape[0];i++) {
329     assert(myDataView(i,j,k)==2.0);
330     }
331     }
332     }
333    
334     myDataView = myData.getDataPointByTag(3);
335     assert(!myDataView.isEmpty());
336     assert(myDataView.getOffset()==24);
337     assert(myDataView.getRank()==3);
338     assert(myDataView.noValues()==8);
339     assert(myDataView.getShape().size()==3);
340     for (int k=0;k<shape[2];k++) {
341     for (int j=0;j<shape[1];j++) {
342     for (int i=0;i<shape[0];i++) {
343     assert(myDataView(i,j,k)==3.0);
344     }
345     }
346     }
347    
348     myDataView = myData.getDefaultValue();
349     assert(!myDataView.isEmpty());
350     assert(myDataView.getOffset()==0);
351     assert(myDataView.getRank()==3);
352     assert(myDataView.noValues()==8);
353     assert(myDataView.getShape().size()==3);
354     for (int k=0;k<shape[2];k++) {
355     for (int j=0;j<shape[1];j++) {
356     for (int i=0;i<shape[0];i++) {
357     assert(myDataView(i,j,k)==0.0);
358     }
359     }
360     }
361    
362     // use a non-existent tag so we get a pointer to
363     // the first element of the data array
364     double* sampleData=myData.getSampleDataByTag(9);
365     for (int i=0; i<myData.getLength(); i++) {
366     if (i<8) {
367     assert(sampleData[i]==0.0);
368     } else if ((i>=8) && (i<16)) {
369     assert(sampleData[i]==1.0);
370     } else if ((i>=16) && (i<24)) {
371     assert(sampleData[i]==2.0);
372     } else {
373     assert(sampleData[i]==3.0);
374     }
375     }
376    
377     }
378    
379 jgs 82 }
380    
381     void DataTaggedTestCase::testOperations() {
382    
383     cout << endl;
384    
385     {
386 jgs 506 cout << "\tTest binaryOp addition of two default DataTagged objects." << endl;
387    
388 jgs 504 DataTagged myData;
389 jgs 82 DataTagged right;
390 jgs 121
391 jgs 504 binaryOp(myData,right,plus<double>());
392    
393     //cout << myData.toString() << endl;
394    
395     assert(myData.getNumSamples()==1);
396     assert(myData.getNumDPPSample()==1);
397    
398     assert(myData.validSamplePointNo(0));
399     assert(myData.validSampleNo(0));
400     assert(!myData.validSamplePointNo(1));
401     assert(!myData.validSampleNo(1));
402    
403     // data-point 0 has tag number 1 by default
404     assert(myData.getTagNumber(0)==1);
405    
406     assert(!myData.isCurrentTag(1));
407    
408     assert(myData.getTagLookup().size()==0);
409    
410     assert(myData.getLength()==1);
411    
412     assert(myData.getPointOffset(0,0)==0);
413    
414     DataArrayView myDataView = myData.getDataPoint(0,0);
415     assert(!myDataView.isEmpty());
416     assert(myDataView.getOffset()==0);
417     assert(myDataView.getRank()==0);
418     assert(myDataView.noValues()==1);
419     assert(myDataView.getShape().size()==0);
420     assert(myDataView()==0.0);
421    
422     // Test non-existent tag returns the default value.
423     myDataView = myData.getDataPointByTag(1);
424     assert(!myDataView.isEmpty());
425     assert(myDataView.getOffset()==0);
426     assert(myDataView.getRank()==0);
427     assert(myDataView.noValues()==1);
428     assert(myDataView.getShape().size()==0);
429     assert(myDataView()==0.0);
430    
431     myDataView = myData.getDefaultValue();
432     assert(!myDataView.isEmpty());
433     assert(myDataView.getOffset()==0);
434     assert(myDataView.getRank()==0);
435     assert(myDataView.noValues()==1);
436     assert(myDataView.getShape().size()==0);
437     assert(myDataView()==0.0);
438 jgs 506
439     // use a non-existent tag so we get a pointer to
440     // the first element of the data array
441     double* sampleData=myData.getSampleDataByTag(9);
442     for (int i=0; i<myData.getLength(); i++) {
443     assert(sampleData[i]==i);
444     }
445    
446 jgs 504 }
447    
448     {
449 jgs 506 cout << "\tTest binaryOp addition of two DataTagged objects with default values only." << endl;
450    
451     DataArrayView::ShapeType viewShape;
452     viewShape.push_back(3);
453    
454     DataTagged::TagListType keys;
455    
456     DataTagged::ValueListType values;
457    
458     DataArrayView::ValueType viewData(3);
459     for (int i=0;i<viewShape[0];i++) {
460     viewData[i]=i;
461     }
462     DataArrayView myView(viewData,viewShape);
463    
464     DataTagged myData(keys,values,myView,FunctionSpace());
465     DataTagged right(keys,values,myView,FunctionSpace());
466    
467     binaryOp(myData,right,plus<double>());
468    
469     //cout << myData.toString() << endl;
470    
471     assert(myData.getNumSamples()==1);
472     assert(myData.getNumDPPSample()==1);
473    
474     assert(myData.validSamplePointNo(0));
475     assert(myData.validSampleNo(0));
476     assert(!myData.validSamplePointNo(1));
477     assert(!myData.validSampleNo(1));
478    
479     // data-point 0 has tag number 1 by default
480     assert(myData.getTagNumber(0)==1);
481    
482     assert(!myData.isCurrentTag(1));
483    
484     assert(myData.getTagLookup().size()==0);
485    
486     assert(myData.getLength()==3);
487    
488     assert(myData.getPointOffset(0,0)==0);
489    
490     DataArrayView myDataView = myData.getDefaultValue();
491     assert(!myDataView.isEmpty());
492     assert(myDataView.getOffset()==0);
493     assert(myDataView.getRank()==1);
494     assert(myDataView.noValues()==3);
495     assert(myDataView.getShape().size()==1);
496     assert(myDataView(0)==0);
497     assert(myDataView(1)==2);
498     assert(myDataView(2)==4);
499    
500     // use a non-existent tag so we get a pointer to
501     // the first element of the data array
502     double* sampleData=myData.getSampleDataByTag(9);
503     for (int i=0; i<myData.getLength(); i++) {
504     assert(sampleData[i]==i*2);
505     }
506    
507     }
508    
509     {
510     cout << "\tTest binaryOp addition of two DataTagged objects with one identical tag each." << endl;
511    
512 jgs 504 DataTagged myData;
513     DataTagged right;
514    
515 jgs 82 DataArray vOne(1.0);
516 jgs 504 myData.addTaggedValue(1,vOne.getView());
517 jgs 82 right.addTaggedValue(1,vOne.getView());
518 jgs 121
519 jgs 504 binaryOp(myData,right,plus<double>());
520    
521 jgs 506 assert(myData.getNumSamples()==1);
522     assert(myData.getNumDPPSample()==1);
523    
524     assert(myData.validSamplePointNo(0));
525     assert(myData.validSampleNo(0));
526     assert(!myData.validSamplePointNo(1));
527     assert(!myData.validSampleNo(1));
528    
529     // data-point 0 has tag number 1 by default
530     assert(myData.getTagNumber(0)==1);
531    
532     assert(myData.isCurrentTag(1));
533    
534     assert(myData.getTagLookup().size()==1);
535    
536     assert(myData.getLength()==2);
537    
538     assert(myData.getPointOffset(0,0)==1);
539    
540 jgs 504 // check result value for tag "1"
541     DataArrayView myDataView = myData.getDataPointByTag(1);
542     assert(!myDataView.isEmpty());
543     assert(myDataView.getOffset()==1);
544     assert(myDataView.getRank()==0);
545     assert(myDataView.noValues()==1);
546     assert(myDataView.getShape().size()==0);
547     assert(myDataView()==2.0);
548    
549     // check result for default value
550     myDataView = myData.getDefaultValue();
551     assert(!myDataView.isEmpty());
552     assert(myDataView.getOffset()==0);
553     assert(myDataView.getRank()==0);
554     assert(myDataView.noValues()==1);
555     assert(myDataView.getShape().size()==0);
556     assert(myDataView()==0.0);
557 jgs 506
558     // use a non-existent tag so we get a pointer to
559     // the first element of the data array
560     double* sampleData=myData.getSampleDataByTag(9);
561     for (int i=0; i<myData.getLength(); i++) {
562     assert(sampleData[i]==i*2);
563     }
564    
565 jgs 82 }
566 jgs 501
567 jgs 82 {
568 jgs 506 cout << "\tTest binaryOp addition of two DataTagged objects with one different tag each." << endl;
569    
570 jgs 504 DataTagged myData;
571     DataTagged right;
572    
573 jgs 548 // it's important that default values are different, as we need to be able to
574     // verify that the tag values in each object are being added to the correct
575     // default values - since the tag lists don't match, the default values will
576     // be used for missing tags in each object
577     myData.getDefaultValue()()=1.0;
578     right.getDefaultValue()()=2.0;
579    
580     DataArray vOne(3.0);
581     DataArray vTwo(4.0);
582 jgs 504 myData.addTaggedValue(1,vOne.getView());
583 jgs 506 right.addTaggedValue(2,vTwo.getView());
584 jgs 504
585 jgs 548 //cout << myData.toString() << endl;
586     //cout << right.toString() << endl;
587    
588 jgs 504 binaryOp(myData,right,plus<double>());
589    
590 jgs 548 //cout << myData.toString() << endl;
591    
592 jgs 506 assert(myData.getNumSamples()==1);
593     assert(myData.getNumDPPSample()==1);
594    
595     assert(myData.validSamplePointNo(0));
596     assert(myData.validSampleNo(0));
597     assert(!myData.validSamplePointNo(1));
598     assert(!myData.validSampleNo(1));
599    
600     // data-point 0 has tag number 1 by default
601     assert(myData.getTagNumber(0)==1);
602    
603     assert(myData.isCurrentTag(1));
604     assert(myData.isCurrentTag(2));
605    
606     assert(myData.getTagLookup().size()==2);
607    
608     assert(myData.getLength()==3);
609    
610     assert(myData.getPointOffset(0,0)==1);
611    
612 jgs 504 // check result value for tag "1"
613     DataArrayView myDataView = myData.getDataPointByTag(1);
614     assert(!myDataView.isEmpty());
615     assert(myDataView.getOffset()==1);
616     assert(myDataView.getRank()==0);
617     assert(myDataView.noValues()==1);
618     assert(myDataView.getShape().size()==0);
619 jgs 548 assert(myDataView()==5.0);
620 jgs 504
621     // check result value for tag "2"
622     myDataView = myData.getDataPointByTag(2);
623     assert(!myDataView.isEmpty());
624     assert(myDataView.getOffset()==2);
625     assert(myDataView.getRank()==0);
626     assert(myDataView.noValues()==1);
627     assert(myDataView.getShape().size()==0);
628 jgs 548 assert(myDataView()==5.0);
629 jgs 504
630     // check result for default value
631     myDataView = myData.getDefaultValue();
632     assert(!myDataView.isEmpty());
633     assert(myDataView.getOffset()==0);
634     assert(myDataView.getRank()==0);
635     assert(myDataView.noValues()==1);
636     assert(myDataView.getShape().size()==0);
637 jgs 548 assert(myDataView()==3.0);
638 jgs 506
639     // use a non-existent tag so we get a pointer to
640     // the first element of the data array
641     double* sampleData=myData.getSampleDataByTag(9);
642 jgs 548 assert(sampleData[0]==3);
643     assert(sampleData[1]==5);
644     assert(sampleData[2]==5);
645 jgs 506
646 jgs 82 }
647 jgs 501
648 jgs 82 {
649 jgs 506 cout << "\tTest binaryOp addition of two DataTagged objects with overlapping tag sets." << endl;
650    
651 jgs 504 DataTagged myData;
652     DataTagged right;
653    
654 jgs 548 // it's important that default values are different, as we need to be able to
655     // verify that the tag values in each object are being added to the correct
656     // default values - since the tag lists don't match, the default values will
657     // be used for missing tags in each object
658     myData.getDefaultValue()()=2.0;
659     right.getDefaultValue()()=3.0;
660    
661 jgs 504 DataArray vOne(1.0);
662     myData.addTaggedValue(1,vOne.getView());
663     myData.addTaggedValue(2,vOne.getView());
664     right.addTaggedValue(2,vOne.getView());
665     right.addTaggedValue(3,vOne.getView());
666    
667 jgs 548 //cout << myData.toString() << endl;
668     //cout << right.toString() << endl;
669    
670 jgs 504 binaryOp(myData,right,plus<double>());
671    
672 jgs 548 //cout << myData.toString() << endl;
673    
674 jgs 506 assert(myData.getNumSamples()==1);
675     assert(myData.getNumDPPSample()==1);
676    
677     assert(myData.validSamplePointNo(0));
678     assert(myData.validSampleNo(0));
679     assert(!myData.validSamplePointNo(1));
680     assert(!myData.validSampleNo(1));
681    
682     // data-point 0 has tag number 1 by default
683     assert(myData.getTagNumber(0)==1);
684    
685     assert(myData.isCurrentTag(1));
686     assert(myData.isCurrentTag(2));
687     assert(myData.isCurrentTag(3));
688    
689     assert(myData.getTagLookup().size()==3);
690    
691     assert(myData.getLength()==4);
692    
693     assert(myData.getPointOffset(0,0)==1);
694    
695 jgs 504 // check result value for tag "1"
696     DataArrayView myDataView = myData.getDataPointByTag(1);
697     assert(!myDataView.isEmpty());
698     assert(myDataView.getOffset()==1);
699     assert(myDataView.getRank()==0);
700     assert(myDataView.noValues()==1);
701     assert(myDataView.getShape().size()==0);
702 jgs 548 assert(myDataView()==4.0);
703 jgs 504
704     // check result value for tag "2"
705     myDataView = myData.getDataPointByTag(2);
706     assert(!myDataView.isEmpty());
707     assert(myDataView.getOffset()==2);
708     assert(myDataView.getRank()==0);
709     assert(myDataView.noValues()==1);
710     assert(myDataView.getShape().size()==0);
711     assert(myDataView()==2.0);
712    
713     // check result value for tag "3"
714     myDataView = myData.getDataPointByTag(3);
715     assert(!myDataView.isEmpty());
716     assert(myDataView.getOffset()==3);
717     assert(myDataView.getRank()==0);
718     assert(myDataView.noValues()==1);
719     assert(myDataView.getShape().size()==0);
720 jgs 548 assert(myDataView()==3.0);
721 jgs 504
722     // check result for default value
723     myDataView = myData.getDefaultValue();
724     assert(!myDataView.isEmpty());
725     assert(myDataView.getOffset()==0);
726     assert(myDataView.getRank()==0);
727     assert(myDataView.noValues()==1);
728     assert(myDataView.getShape().size()==0);
729 jgs 548 assert(myDataView()==5.0);
730 jgs 506
731     // use a non-existent tag so we get a pointer to
732     // the first element of the data array
733     double* sampleData=myData.getSampleDataByTag(9);
734 jgs 548 assert(sampleData[0]==5);
735     assert(sampleData[1]==4);
736     assert(sampleData[2]==2);
737     assert(sampleData[3]==3);
738 jgs 506
739 jgs 82 }
740 jgs 501
741 jgs 82 {
742 jgs 506 cout << "\tTest binaryOp multiplication of two DataTagged objects with default values only." << endl;
743 jgs 504
744 jgs 506 DataArrayView::ShapeType viewShape;
745     viewShape.push_back(3);
746    
747     DataTagged::TagListType keys;
748    
749     DataTagged::ValueListType values;
750    
751     DataArrayView::ValueType viewData(3);
752     for (int i=0;i<viewShape[0];i++) {
753     viewData[i]=i;
754     }
755     DataArrayView myView(viewData,viewShape);
756    
757     DataTagged myData(keys,values,myView,FunctionSpace());
758     DataTagged right(keys,values,myView,FunctionSpace());
759    
760     binaryOp(myData,right,multiplies<double>());
761    
762     //cout << myData.toString() << endl;
763    
764     assert(myData.getNumSamples()==1);
765     assert(myData.getNumDPPSample()==1);
766    
767     assert(myData.validSamplePointNo(0));
768     assert(myData.validSampleNo(0));
769     assert(!myData.validSamplePointNo(1));
770     assert(!myData.validSampleNo(1));
771    
772     // data-point 0 has tag number 1 by default
773     assert(myData.getTagNumber(0)==1);
774    
775     assert(!myData.isCurrentTag(1));
776    
777     assert(myData.getTagLookup().size()==0);
778    
779     assert(myData.getLength()==3);
780    
781     assert(myData.getPointOffset(0,0)==0);
782    
783     DataArrayView myDataView = myData.getDefaultValue();
784     assert(!myDataView.isEmpty());
785     assert(myDataView.getOffset()==0);
786     assert(myDataView.getRank()==1);
787     assert(myDataView.noValues()==3);
788     assert(myDataView.getShape().size()==1);
789     assert(myDataView(0)==0);
790     assert(myDataView(1)==1);
791     assert(myDataView(2)==4);
792    
793     // use a non-existent tag so we get a pointer to
794     // the first element of the data array
795     double* sampleData=myData.getSampleDataByTag(9);
796     for (int i=0; i<myData.getLength(); i++) {
797     assert(sampleData[i]==i*i);
798     }
799    
800 jgs 82 }
801 jgs 501
802 jgs 504 {
803 jgs 557
804     cout << "\tTest binaryOp multiplication of DataTagged object with a scalar." << endl;
805    
806     DataTagged myData;
807    
808     DataArray vOne(1.0);
809     DataArray vTwo(2.0);
810     myData.addTaggedValue(1,vOne.getView());
811     myData.addTaggedValue(2,vTwo.getView());
812    
813     DataArray vThree(3.0);
814     DataArrayView right=vThree.getView();
815    
816     //cout << myData.toString() << endl;
817     //cout << right.toString() << endl;
818    
819     binaryOp(myData,right,multiplies<double>());
820    
821     //cout << myData.toString() << endl;
822    
823     assert(myData.getNumSamples()==1);
824     assert(myData.getNumDPPSample()==1);
825    
826     assert(myData.validSamplePointNo(0));
827     assert(myData.validSampleNo(0));
828     assert(!myData.validSamplePointNo(1));
829     assert(!myData.validSampleNo(1));
830    
831     // data-point 0 has tag number 1 by default
832     assert(myData.getTagNumber(0)==1);
833    
834     assert(myData.isCurrentTag(1));
835     assert(myData.isCurrentTag(2));
836    
837     assert(myData.getTagLookup().size()==2);
838    
839     assert(myData.getLength()==3);
840    
841     assert(myData.getPointOffset(0,0)==1);
842    
843     // check result value for tag "1"
844     DataArrayView myDataView = myData.getDataPointByTag(1);
845     assert(!myDataView.isEmpty());
846     assert(myDataView.getOffset()==1);
847     assert(myDataView.getRank()==0);
848     assert(myDataView.noValues()==1);
849     assert(myDataView.getShape().size()==0);
850     assert(myDataView()==3.0);
851    
852     // check result value for tag "2"
853     myDataView = myData.getDataPointByTag(2);
854     assert(!myDataView.isEmpty());
855     assert(myDataView.getOffset()==2);
856     assert(myDataView.getRank()==0);
857     assert(myDataView.noValues()==1);
858     assert(myDataView.getShape().size()==0);
859     assert(myDataView()==6.0);
860    
861     // check result for default value
862     myDataView = myData.getDefaultValue();
863     assert(!myDataView.isEmpty());
864     assert(myDataView.getOffset()==0);
865     assert(myDataView.getRank()==0);
866     assert(myDataView.noValues()==1);
867     assert(myDataView.getShape().size()==0);
868     assert(myDataView()==0.0);
869    
870     // use a non-existent tag so we get a pointer to
871     // the first element of the data array
872     double* sampleData=myData.getSampleDataByTag(9);
873     assert(sampleData[0]==0);
874     assert(sampleData[1]==3);
875     assert(sampleData[2]==6);
876    
877     }
878    
879     {
880 jgs 506 cout << "\tTest binaryOp multiplication of two DataTagged objects with overlapping tag sets." << endl;
881    
882     DataTagged myData;
883     DataTagged right;
884    
885 jgs 548 // it's important that default values are different, as we need to be able to
886     // verify that the tag values in each object are being added to the correct
887     // default values - since the tag lists don't match, the default values will
888     // be used for missing tags in each object
889     myData.getDefaultValue()()=2.0;
890     right.getDefaultValue()()=3.0;
891    
892 jgs 506 DataArray vOne(1.0);
893     DataArray vTwo(2.0);
894     myData.addTaggedValue(1,vOne.getView());
895     myData.addTaggedValue(2,vOne.getView());
896     right.addTaggedValue(2,vTwo.getView());
897     right.addTaggedValue(3,vTwo.getView());
898    
899 jgs 548 //cout << myData.toString() << endl;
900     //cout << right.toString() << endl;
901    
902 jgs 506 binaryOp(myData,right,multiplies<double>());
903    
904 jgs 548 //cout << myData.toString() << endl;
905    
906 jgs 506 assert(myData.getNumSamples()==1);
907     assert(myData.getNumDPPSample()==1);
908    
909     assert(myData.validSamplePointNo(0));
910     assert(myData.validSampleNo(0));
911     assert(!myData.validSamplePointNo(1));
912     assert(!myData.validSampleNo(1));
913    
914     // data-point 0 has tag number 1 by default
915     assert(myData.getTagNumber(0)==1);
916    
917     assert(myData.isCurrentTag(1));
918     assert(myData.isCurrentTag(2));
919     assert(myData.isCurrentTag(3));
920    
921     assert(myData.getTagLookup().size()==3);
922    
923     assert(myData.getLength()==4);
924    
925     assert(myData.getPointOffset(0,0)==1);
926    
927     // check result value for tag "1"
928     DataArrayView myDataView = myData.getDataPointByTag(1);
929     assert(!myDataView.isEmpty());
930     assert(myDataView.getOffset()==1);
931     assert(myDataView.getRank()==0);
932     assert(myDataView.noValues()==1);
933     assert(myDataView.getShape().size()==0);
934 jgs 548 assert(myDataView()==3.0);
935 jgs 506
936     // check result value for tag "2"
937     myDataView = myData.getDataPointByTag(2);
938     assert(!myDataView.isEmpty());
939     assert(myDataView.getOffset()==2);
940     assert(myDataView.getRank()==0);
941     assert(myDataView.noValues()==1);
942     assert(myDataView.getShape().size()==0);
943     assert(myDataView()==2.0);
944    
945     // check result value for tag "3"
946     myDataView = myData.getDataPointByTag(3);
947     assert(!myDataView.isEmpty());
948     assert(myDataView.getOffset()==3);
949     assert(myDataView.getRank()==0);
950     assert(myDataView.noValues()==1);
951     assert(myDataView.getShape().size()==0);
952 jgs 548 assert(myDataView()==4.0);
953 jgs 506
954     // check result for default value
955     myDataView = myData.getDefaultValue();
956     assert(!myDataView.isEmpty());
957     assert(myDataView.getOffset()==0);
958     assert(myDataView.getRank()==0);
959     assert(myDataView.noValues()==1);
960     assert(myDataView.getShape().size()==0);
961 jgs 548 assert(myDataView()==6.0);
962 jgs 506
963     // use a non-existent tag so we get a pointer to
964     // the first element of the data array
965     double* sampleData=myData.getSampleDataByTag(9);
966 jgs 548 assert(sampleData[0]==6);
967     assert(sampleData[1]==3);
968     assert(sampleData[2]==2);
969     assert(sampleData[3]==4);
970 jgs 506
971 jgs 504 }
972    
973     {
974 jgs 506 cout << "\tTest unaryOp negate on default DataTagged object." << endl;
975    
976     DataTagged myData;
977    
978     unaryOp(myData,negate<double>());
979    
980     //cout << myData.toString() << endl;
981    
982     assert(myData.getNumSamples()==1);
983     assert(myData.getNumDPPSample()==1);
984    
985     assert(myData.validSamplePointNo(0));
986     assert(myData.validSampleNo(0));
987     assert(!myData.validSamplePointNo(1));
988     assert(!myData.validSampleNo(1));
989    
990     // data-point 0 has tag number 1 by default
991     assert(myData.getTagNumber(0)==1);
992    
993     assert(!myData.isCurrentTag(1));
994    
995     assert(myData.getTagLookup().size()==0);
996    
997     assert(myData.getLength()==1);
998    
999     assert(myData.getPointOffset(0,0)==0);
1000    
1001     DataArrayView myDataView = myData.getDataPoint(0,0);
1002     assert(!myDataView.isEmpty());
1003     assert(myDataView.getOffset()==0);
1004     assert(myDataView.getRank()==0);
1005     assert(myDataView.noValues()==1);
1006     assert(myDataView.getShape().size()==0);
1007     assert(myDataView()==0.0);
1008    
1009     // Test non-existent tag returns the default value.
1010     myDataView = myData.getDataPointByTag(1);
1011     assert(!myDataView.isEmpty());
1012     assert(myDataView.getOffset()==0);
1013     assert(myDataView.getRank()==0);
1014     assert(myDataView.noValues()==1);
1015     assert(myDataView.getShape().size()==0);
1016     assert(myDataView()==0.0);
1017    
1018     myDataView = myData.getDefaultValue();
1019     assert(!myDataView.isEmpty());
1020     assert(myDataView.getOffset()==0);
1021     assert(myDataView.getRank()==0);
1022     assert(myDataView.noValues()==1);
1023     assert(myDataView.getShape().size()==0);
1024     assert(myDataView()==0.0);
1025    
1026     // use a non-existent tag so we get a pointer to
1027     // the first element of the data array
1028     double* sampleData=myData.getSampleDataByTag(9);
1029     for (int i=0; i<myData.getLength(); i++) {
1030     assert(sampleData[i]==i);
1031     }
1032    
1033 jgs 504 }
1034    
1035     {
1036 jgs 506 cout << "\tTest unaryOp negate on DataTagged object with default value only." << endl;
1037    
1038     DataArrayView::ShapeType viewShape;
1039     viewShape.push_back(3);
1040    
1041     DataTagged::TagListType keys;
1042    
1043     DataTagged::ValueListType values;
1044    
1045     DataArrayView::ValueType viewData(3);
1046     for (int i=0;i<viewShape[0];i++) {
1047     viewData[i]=i;
1048     }
1049     DataArrayView myView(viewData,viewShape);
1050    
1051     DataTagged myData(keys,values,myView,FunctionSpace());
1052    
1053     unaryOp(myData,negate<double>());
1054    
1055     //cout << myData.toString() << endl;
1056    
1057     assert(myData.getNumSamples()==1);
1058     assert(myData.getNumDPPSample()==1);
1059    
1060     assert(myData.validSamplePointNo(0));
1061     assert(myData.validSampleNo(0));
1062     assert(!myData.validSamplePointNo(1));
1063     assert(!myData.validSampleNo(1));
1064    
1065     // data-point 0 has tag number 1 by default
1066     assert(myData.getTagNumber(0)==1);
1067    
1068     assert(!myData.isCurrentTag(1));
1069    
1070     assert(myData.getTagLookup().size()==0);
1071    
1072     assert(myData.getLength()==3);
1073    
1074     assert(myData.getPointOffset(0,0)==0);
1075    
1076     DataArrayView myDataView = myData.getDefaultValue();
1077     assert(!myDataView.isEmpty());
1078     assert(myDataView.getOffset()==0);
1079     assert(myDataView.getRank()==1);
1080     assert(myDataView.noValues()==3);
1081     assert(myDataView.getShape().size()==1);
1082     assert(myDataView(0)==0);
1083     assert(myDataView(1)==-1);
1084     assert(myDataView(2)==-2);
1085    
1086     // use a non-existent tag so we get a pointer to
1087     // the first element of the data array
1088     double* sampleData=myData.getSampleDataByTag(9);
1089     for (int i=0; i<myData.getLength(); i++) {
1090     assert(sampleData[i]==0-i);
1091     }
1092    
1093 jgs 504 }
1094    
1095 jgs 506 {
1096     cout << "\tTest unaryOp negate on DataTagged object with two tags." << endl;
1097    
1098     DataTagged myData;
1099    
1100     DataArray vOne(1.0);
1101     DataArray vTwo(2.0);
1102     myData.addTaggedValue(1,vOne.getView());
1103     myData.addTaggedValue(2,vTwo.getView());
1104    
1105     unaryOp(myData,negate<double>());
1106    
1107     assert(myData.getNumSamples()==1);
1108     assert(myData.getNumDPPSample()==1);
1109    
1110     assert(myData.validSamplePointNo(0));
1111     assert(myData.validSampleNo(0));
1112     assert(!myData.validSamplePointNo(1));
1113     assert(!myData.validSampleNo(1));
1114    
1115     // data-point 0 has tag number 1 by default
1116     assert(myData.getTagNumber(0)==1);
1117    
1118     assert(myData.isCurrentTag(1));
1119     assert(myData.isCurrentTag(2));
1120    
1121     assert(myData.getTagLookup().size()==2);
1122    
1123     assert(myData.getLength()==3);
1124    
1125     assert(myData.getPointOffset(0,0)==1);
1126    
1127     // check result value for tag "1"
1128     DataArrayView myDataView = myData.getDataPointByTag(1);
1129     assert(!myDataView.isEmpty());
1130     assert(myDataView.getOffset()==1);
1131     assert(myDataView.getRank()==0);
1132     assert(myDataView.noValues()==1);
1133     assert(myDataView.getShape().size()==0);
1134     assert(myDataView()==-1.0);
1135    
1136     // check result value for tag "2"
1137     myDataView = myData.getDataPointByTag(2);
1138     assert(!myDataView.isEmpty());
1139     assert(myDataView.getOffset()==2);
1140     assert(myDataView.getRank()==0);
1141     assert(myDataView.noValues()==1);
1142     assert(myDataView.getShape().size()==0);
1143     assert(myDataView()==-2.0);
1144    
1145     // check result for default value
1146     myDataView = myData.getDefaultValue();
1147     assert(!myDataView.isEmpty());
1148     assert(myDataView.getOffset()==0);
1149     assert(myDataView.getRank()==0);
1150     assert(myDataView.noValues()==1);
1151     assert(myDataView.getShape().size()==0);
1152     assert(myDataView()==0.0);
1153    
1154     // use a non-existent tag so we get a pointer to
1155     // the first element of the data array
1156     double* sampleData=myData.getSampleDataByTag(9);
1157     for (int i=0; i<myData.getLength(); i++) {
1158     assert(sampleData[i]==0-i);
1159     }
1160    
1161     }
1162    
1163 jgs 82 }
1164    
1165 jgs 501 void DataTaggedTestCase::testAddTaggedValues() {
1166    
1167     cout << endl;
1168    
1169     {
1170    
1171     cout << "\tTest adding one key with empty value list to default DataTagged." << endl;
1172     DataTagged myData;
1173    
1174     DataTagged::TagListType keys;
1175     keys.push_back(1);
1176    
1177     DataTagged::ValueListType values;
1178    
1179     myData.addTaggedValues(keys,values);
1180    
1181     assert(myData.isCurrentTag(1));
1182    
1183     assert(myData.getTagLookup().size()==1);
1184    
1185     assert(myData.getLength()==2);
1186    
1187     // data-point 0 has tag number 1 by default
1188     assert(myData.getTagNumber(0)==1);
1189    
1190     assert(myData.getPointOffset(0,0)==1);
1191    
1192     DataArrayView myDataView = myData.getDataPoint(0,0);
1193     assert(!myDataView.isEmpty());
1194     assert(myDataView.getOffset()==1);
1195     assert(myDataView.getRank()==0);
1196     assert(myDataView.noValues()==1);
1197     assert(myDataView.getShape().size()==0);
1198     assert(myDataView()==0.0);
1199    
1200     myDataView = myData.getDataPointByTag(1);
1201     assert(!myDataView.isEmpty());
1202     assert(myDataView.getOffset()==1);
1203     assert(myDataView.getRank()==0);
1204     assert(myDataView.noValues()==1);
1205     assert(myDataView.getShape().size()==0);
1206     assert(myDataView()==0.0);
1207    
1208     myDataView = myData.getDefaultValue();
1209     assert(!myDataView.isEmpty());
1210     assert(myDataView.getOffset()==0);
1211     assert(myDataView.getRank()==0);
1212     assert(myDataView.noValues()==1);
1213     assert(myDataView.getShape().size()==0);
1214     assert(myDataView()==0.0);
1215    
1216 jgs 506 // use a non-existent tag so we get a pointer to
1217     // the first element of the data array
1218     double* sampleData=myData.getSampleDataByTag(9);
1219     for (int i=0; i<myData.getLength(); i++) {
1220     assert(sampleData[i]==0);
1221     }
1222    
1223 jgs 501 }
1224    
1225     {
1226    
1227     cout << "\tTest adding one key with one value to default DataTagged." << endl;
1228     DataTagged myData;
1229    
1230     DataTagged::TagListType keys;
1231     keys.push_back(1);
1232    
1233     DataTagged::ValueListType values;
1234    
1235     DataArrayView::ShapeType viewShape;
1236     DataArrayView::ValueType viewData(1);
1237     viewData[0]=1.0;
1238     DataArrayView myView(viewData,viewShape);
1239     values.push_back(myView);
1240    
1241     myData.addTaggedValues(keys,values);
1242    
1243     assert(myData.isCurrentTag(1));
1244    
1245     assert(myData.getTagLookup().size()==1);
1246    
1247     assert(myData.getLength()==2);
1248    
1249     // data-point 0 has tag number 1 by default
1250     assert(myData.getTagNumber(0)==1);
1251    
1252     assert(myData.getPointOffset(0,0)==1);
1253    
1254     DataArrayView myDataView = myData.getDataPoint(0,0);
1255     assert(!myDataView.isEmpty());
1256     assert(myDataView.getOffset()==1);
1257     assert(myDataView.getRank()==0);
1258     assert(myDataView.noValues()==1);
1259     assert(myDataView.getShape().size()==0);
1260     assert(myDataView()==1.0);
1261    
1262     myDataView = myData.getDataPointByTag(1);
1263     assert(!myDataView.isEmpty());
1264     assert(myDataView.getOffset()==1);
1265     assert(myDataView.getRank()==0);
1266     assert(myDataView.noValues()==1);
1267     assert(myDataView.getShape().size()==0);
1268     assert(myDataView()==1.0);
1269    
1270     myDataView = myData.getDefaultValue();
1271     assert(!myDataView.isEmpty());
1272     assert(myDataView.getOffset()==0);
1273     assert(myDataView.getRank()==0);
1274     assert(myDataView.noValues()==1);
1275     assert(myDataView.getShape().size()==0);
1276     assert(myDataView()==0.0);
1277    
1278 jgs 506 // use a non-existent tag so we get a pointer to
1279     // the first element of the data array
1280     double* sampleData=myData.getSampleDataByTag(9);
1281     for (int i=0; i<myData.getLength(); i++) {
1282     assert(sampleData[i]==i);
1283     }
1284    
1285 jgs 501 }
1286    
1287     {
1288    
1289     cout << "\tTest adding three keys with one value to default DataTagged." << endl;
1290     DataTagged myData;
1291    
1292     DataTagged::TagListType keys;
1293     keys.push_back(1);
1294     keys.push_back(2);
1295     keys.push_back(3);
1296    
1297     DataTagged::ValueListType values;
1298    
1299     DataArrayView::ShapeType viewShape;
1300     DataArrayView::ValueType viewData(1);
1301     viewData[0]=1.0;
1302     DataArrayView myView(viewData,viewShape);
1303     values.push_back(myView);
1304    
1305     myData.addTaggedValues(keys,values);
1306    
1307     assert(myData.isCurrentTag(1));
1308     assert(myData.isCurrentTag(2));
1309     assert(myData.isCurrentTag(3));
1310    
1311     assert(myData.getTagLookup().size()==3);
1312    
1313     assert(myData.getLength()==4);
1314    
1315     // data-point 0 has tag number 1 by default
1316     assert(myData.getTagNumber(0)==1);
1317    
1318     assert(myData.getPointOffset(0,0)==1);
1319    
1320     DataArrayView myDataView = myData.getDataPoint(0,0);
1321     assert(!myDataView.isEmpty());
1322     assert(myDataView.getOffset()==1);
1323     assert(myDataView.getRank()==0);
1324     assert(myDataView.noValues()==1);
1325     assert(myDataView.getShape().size()==0);
1326     assert(myDataView()==1.0);
1327    
1328     myDataView = myData.getDataPointByTag(1);
1329     assert(!myDataView.isEmpty());
1330     assert(myDataView.getOffset()==1);
1331     assert(myDataView.getRank()==0);
1332     assert(myDataView.noValues()==1);
1333     assert(myDataView.getShape().size()==0);
1334     assert(myDataView()==1.0);
1335    
1336     myDataView = myData.getDataPointByTag(2);
1337     assert(!myDataView.isEmpty());
1338     assert(myDataView.getOffset()==2);
1339     assert(myDataView.getRank()==0);
1340     assert(myDataView.noValues()==1);
1341     assert(myDataView.getShape().size()==0);
1342     assert(myDataView()==1.0);
1343    
1344     myDataView = myData.getDataPointByTag(3);
1345     assert(!myDataView.isEmpty());
1346     assert(myDataView.getOffset()==3);
1347     assert(myDataView.getRank()==0);
1348     assert(myDataView.noValues()==1);
1349     assert(myDataView.getShape().size()==0);
1350     assert(myDataView()==1.0);
1351    
1352     myDataView = myData.getDefaultValue();
1353     assert(!myDataView.isEmpty());
1354     assert(myDataView.getOffset()==0);
1355     assert(myDataView.getRank()==0);
1356     assert(myDataView.noValues()==1);
1357     assert(myDataView.getShape().size()==0);
1358     assert(myDataView()==0.0);
1359    
1360 jgs 506 // use a non-existent tag so we get a pointer to
1361     // the first element of the data array
1362     double* sampleData=myData.getSampleDataByTag(9);
1363     for (int i=0; i<myData.getLength(); i++) {
1364     if (i==0) {
1365     assert(sampleData[i]==0);
1366     } else {
1367     assert(sampleData[i]==1);
1368     }
1369     }
1370    
1371 jgs 501 }
1372    
1373     {
1374    
1375     cout << "\tTest adding three keys with three values to default DataTagged." << endl;
1376     DataTagged myData;
1377    
1378     DataTagged::TagListType keys;
1379     keys.push_back(1);
1380     keys.push_back(2);
1381     keys.push_back(3);
1382    
1383     DataTagged::ValueListType values;
1384    
1385     DataArrayView::ShapeType viewShape;
1386     DataArrayView::ValueType viewData1(1);
1387     viewData1[0]=1.0;
1388     DataArrayView::ValueType viewData2(1);
1389     viewData2[0]=2.0;
1390     DataArrayView::ValueType viewData3(1);
1391     viewData3[0]=3.0;
1392     DataArrayView myView1(viewData1,viewShape);
1393     DataArrayView myView2(viewData2,viewShape);
1394     DataArrayView myView3(viewData3,viewShape);
1395     values.push_back(myView1);
1396     values.push_back(myView2);
1397     values.push_back(myView3);
1398    
1399     myData.addTaggedValues(keys,values);
1400    
1401     assert(myData.isCurrentTag(1));
1402     assert(myData.isCurrentTag(2));
1403     assert(myData.isCurrentTag(3));
1404    
1405     assert(myData.getTagLookup().size()==3);
1406    
1407     assert(myData.getLength()==4);
1408    
1409     // data-point 0 has tag number 1 by default
1410     assert(myData.getTagNumber(0)==1);
1411    
1412     assert(myData.getPointOffset(0,0)==1);
1413    
1414     DataArrayView myDataView = myData.getDataPoint(0,0);
1415     assert(!myDataView.isEmpty());
1416     assert(myDataView.getOffset()==1);
1417     assert(myDataView.getRank()==0);
1418     assert(myDataView.noValues()==1);
1419     assert(myDataView.getShape().size()==0);
1420     assert(myDataView()==1.0);
1421    
1422     myDataView = myData.getDataPointByTag(1);
1423     assert(!myDataView.isEmpty());
1424     assert(myDataView.getOffset()==1);
1425     assert(myDataView.getRank()==0);
1426     assert(myDataView.noValues()==1);
1427     assert(myDataView.getShape().size()==0);
1428     assert(myDataView()==1.0);
1429    
1430     myDataView = myData.getDataPointByTag(2);
1431     assert(!myDataView.isEmpty());
1432     assert(myDataView.getOffset()==2);
1433     assert(myDataView.getRank()==0);
1434     assert(myDataView.noValues()==1);
1435     assert(myDataView.getShape().size()==0);
1436     assert(myDataView()==2.0);
1437    
1438     myDataView = myData.getDataPointByTag(3);
1439     assert(!myDataView.isEmpty());
1440     assert(myDataView.getOffset()==3);
1441     assert(myDataView.getRank()==0);
1442     assert(myDataView.noValues()==1);
1443     assert(myDataView.getShape().size()==0);
1444     assert(myDataView()==3.0);
1445    
1446     myDataView = myData.getDefaultValue();
1447     assert(!myDataView.isEmpty());
1448     assert(myDataView.getOffset()==0);
1449     assert(myDataView.getRank()==0);
1450     assert(myDataView.noValues()==1);
1451     assert(myDataView.getShape().size()==0);
1452     assert(myDataView()==0.0);
1453    
1454 jgs 506 // use a non-existent tag so we get a pointer to
1455     // the first element of the data array
1456     double* sampleData=myData.getSampleDataByTag(9);
1457     for (int i=0; i<myData.getLength(); i++) {
1458     assert(sampleData[i]==i);
1459     }
1460    
1461 jgs 501 }
1462    
1463     {
1464    
1465     cout << "\tTest adding one key with empty value list to DataTagged with default value only." << endl;
1466    
1467     DataArrayView::ShapeType viewShape;
1468     viewShape.push_back(3);
1469    
1470     DataTagged::TagListType keys;
1471    
1472     DataTagged::ValueListType values;
1473    
1474     DataArrayView::ValueType viewData(3);
1475     for (int i=0;i<viewShape[0];i++) {
1476     viewData[i]=i;
1477     }
1478     DataArrayView myView(viewData,viewShape);
1479    
1480     DataTagged myData(keys,values,myView,FunctionSpace());
1481    
1482     keys.push_back(1);
1483     values.clear();
1484    
1485     myData.addTaggedValues(keys,values);
1486    
1487     assert(myData.isCurrentTag(1));
1488    
1489     assert(myData.getTagLookup().size()==1);
1490    
1491     assert(myData.getLength()==6);
1492    
1493     // data-point 0 has tag number 1 by default
1494     assert(myData.getTagNumber(0)==1);
1495    
1496     assert(myData.getPointOffset(0,0)==3);
1497    
1498     DataArrayView myDataView = myData.getDataPoint(0,0);
1499     assert(myDataView==myView);
1500     assert(!myDataView.isEmpty());
1501     assert(myDataView.getOffset()==3);
1502     assert(myDataView.getRank()==1);
1503     assert(myDataView.noValues()==3);
1504     assert(myDataView.getShape().size()==1);
1505     assert(myDataView(0)==0);
1506     assert(myDataView(1)==1);
1507     assert(myDataView(2)==2);
1508    
1509     myDataView = myData.getDataPointByTag(1);
1510     assert(myDataView==myView);
1511     assert(!myDataView.isEmpty());
1512     assert(myDataView.getOffset()==3);
1513     assert(myDataView.getRank()==1);
1514     assert(myDataView.noValues()==3);
1515     assert(myDataView.getShape().size()==1);
1516     assert(myDataView(0)==0);
1517     assert(myDataView(1)==1);
1518     assert(myDataView(2)==2);
1519    
1520     myDataView = myData.getDefaultValue();
1521     assert(myDataView==myView);
1522     assert(!myDataView.isEmpty());
1523     assert(myDataView.getOffset()==0);
1524     assert(myDataView.getRank()==1);
1525     assert(myDataView.noValues()==3);
1526     assert(myDataView.getShape().size()==1);
1527     assert(myDataView(0)==0);
1528     assert(myDataView(1)==1);
1529     assert(myDataView(2)==2);
1530    
1531 jgs 506 // use a non-existent tag so we get a pointer to
1532     // the first element of the data array
1533     double* sampleData=myData.getSampleDataByTag(9);
1534     for (int i=0; i<myData.getLength(); i++) {
1535     assert(sampleData[i]==i%3);
1536     }
1537    
1538 jgs 501 }
1539    
1540     {
1541    
1542     cout << "\tTest adding one key with one value to DataTagged with default value only." << endl;
1543    
1544     DataArrayView::ShapeType viewShape;
1545     viewShape.push_back(3);
1546    
1547     DataTagged::TagListType keys;
1548    
1549     DataTagged::ValueListType values;
1550    
1551     DataArrayView::ValueType viewData(3);
1552     for (int i=0;i<viewShape[0];i++) {
1553     viewData[i]=i;
1554     }
1555     DataArrayView myView(viewData,viewShape);
1556    
1557     DataTagged myData(keys,values,myView,FunctionSpace());
1558    
1559     keys.push_back(1);
1560    
1561     DataArrayView::ValueType viewData1(3);
1562     for (int i=0;i<viewShape[0];i++) {
1563 jgs 506 viewData1[i]=i+3;
1564 jgs 501 }
1565     DataArrayView myView1(viewData1,viewShape);
1566     values.push_back(myView1);
1567    
1568     myData.addTaggedValues(keys,values);
1569    
1570     assert(myData.isCurrentTag(1));
1571    
1572     assert(myData.getTagLookup().size()==1);
1573    
1574     assert(myData.getLength()==6);
1575    
1576     // data-point 0 has tag number 1 by default
1577     assert(myData.getTagNumber(0)==1);
1578    
1579     assert(myData.getPointOffset(0,0)==3);
1580    
1581     DataArrayView myDataView = myData.getDataPoint(0,0);
1582     assert(myDataView==myView1);
1583     assert(!myDataView.isEmpty());
1584     assert(myDataView.getOffset()==3);
1585     assert(myDataView.getRank()==1);
1586     assert(myDataView.noValues()==3);
1587     assert(myDataView.getShape().size()==1);
1588 jgs 506 assert(myDataView(0)==3);
1589     assert(myDataView(1)==4);
1590     assert(myDataView(2)==5);
1591 jgs 501
1592     myDataView = myData.getDataPointByTag(1);
1593     assert(myDataView==myView1);
1594     assert(!myDataView.isEmpty());
1595     assert(myDataView.getOffset()==3);
1596     assert(myDataView.getRank()==1);
1597     assert(myDataView.noValues()==3);
1598     assert(myDataView.getShape().size()==1);
1599 jgs 506 assert(myDataView(0)==3);
1600     assert(myDataView(1)==4);
1601     assert(myDataView(2)==5);
1602 jgs 501
1603     myDataView = myData.getDefaultValue();
1604     assert(myDataView==myView);
1605     assert(!myDataView.isEmpty());
1606     assert(myDataView.getOffset()==0);
1607     assert(myDataView.getRank()==1);
1608     assert(myDataView.noValues()==3);
1609     assert(myDataView.getShape().size()==1);
1610     assert(myDataView(0)==0);
1611     assert(myDataView(1)==1);
1612     assert(myDataView(2)==2);
1613    
1614 jgs 506 // use a non-existent tag so we get a pointer to
1615     // the first element of the data array
1616     double* sampleData=myData.getSampleDataByTag(9);
1617     for (int i=0; i<myData.getLength(); i++) {
1618     assert(sampleData[i]==i);
1619     }
1620    
1621 jgs 501 }
1622    
1623     {
1624    
1625     cout << "\tTest adding three keys with one value to DataTagged with default value only." << endl;
1626    
1627     DataArrayView::ShapeType viewShape;
1628     viewShape.push_back(3);
1629    
1630     DataTagged::TagListType keys;
1631    
1632     DataTagged::ValueListType values;
1633    
1634     DataArrayView::ValueType viewData(3);
1635     for (int i=0;i<viewShape[0];i++) {
1636     viewData[i]=i;
1637     }
1638     DataArrayView myView(viewData,viewShape);
1639    
1640     DataTagged myData(keys,values,myView,FunctionSpace());
1641    
1642     keys.push_back(1);
1643     keys.push_back(2);
1644     keys.push_back(3);
1645    
1646     DataArrayView::ValueType viewData1(3);
1647     for (int i=0;i<viewShape[0];i++) {
1648 jgs 506 viewData1[i]=3;
1649 jgs 501 }
1650     DataArrayView myView1(viewData1,viewShape);
1651     values.push_back(myView1);
1652    
1653     myData.addTaggedValues(keys,values);
1654    
1655     assert(myData.isCurrentTag(1));
1656     assert(myData.isCurrentTag(2));
1657     assert(myData.isCurrentTag(3));
1658    
1659     assert(myData.getTagLookup().size()==3);
1660    
1661     assert(myData.getLength()==12);
1662    
1663     // data-point 0 has tag number 1 by default
1664     assert(myData.getTagNumber(0)==1);
1665    
1666     assert(myData.getPointOffset(0,0)==3);
1667    
1668     DataArrayView myDataView = myData.getDataPoint(0,0);
1669     assert(myDataView==myView1);
1670     assert(!myDataView.isEmpty());
1671     assert(myDataView.getOffset()==3);
1672     assert(myDataView.getRank()==1);
1673     assert(myDataView.noValues()==3);
1674     assert(myDataView.getShape().size()==1);
1675 jgs 506 assert(myDataView(0)==3);
1676     assert(myDataView(1)==3);
1677 jgs 501 assert(myDataView(2)==3);
1678    
1679     myDataView = myData.getDataPointByTag(1);
1680     assert(myDataView==myView1);
1681     assert(!myDataView.isEmpty());
1682     assert(myDataView.getOffset()==3);
1683     assert(myDataView.getRank()==1);
1684     assert(myDataView.noValues()==3);
1685     assert(myDataView.getShape().size()==1);
1686 jgs 506 assert(myDataView(0)==3);
1687     assert(myDataView(1)==3);
1688 jgs 501 assert(myDataView(2)==3);
1689    
1690     myDataView = myData.getDataPointByTag(2);
1691     assert(myDataView==myView1);
1692     assert(!myDataView.isEmpty());
1693     assert(myDataView.getOffset()==6);
1694     assert(myDataView.getRank()==1);
1695     assert(myDataView.noValues()==3);
1696     assert(myDataView.getShape().size()==1);
1697 jgs 506 assert(myDataView(0)==3);
1698     assert(myDataView(1)==3);
1699 jgs 501 assert(myDataView(2)==3);
1700    
1701     myDataView = myData.getDataPointByTag(3);
1702     assert(myDataView==myView1);
1703     assert(!myDataView.isEmpty());
1704     assert(myDataView.getOffset()==9);
1705     assert(myDataView.getRank()==1);
1706     assert(myDataView.noValues()==3);
1707     assert(myDataView.getShape().size()==1);
1708 jgs 506 assert(myDataView(0)==3);
1709     assert(myDataView(1)==3);
1710 jgs 501 assert(myDataView(2)==3);
1711    
1712     myDataView = myData.getDefaultValue();
1713     assert(myDataView==myView);
1714     assert(!myDataView.isEmpty());
1715     assert(myDataView.getOffset()==0);
1716     assert(myDataView.getRank()==1);
1717     assert(myDataView.noValues()==3);
1718     assert(myDataView.getShape().size()==1);
1719     assert(myDataView(0)==0);
1720     assert(myDataView(1)==1);
1721     assert(myDataView(2)==2);
1722    
1723 jgs 506 // use a non-existent tag so we get a pointer to
1724     // the first element of the data array
1725     double* sampleData=myData.getSampleDataByTag(9);
1726     for (int i=0; i<myData.getLength(); i++) {
1727     if (i<3) {
1728     assert(sampleData[i]==i);
1729     } else {
1730     assert(sampleData[i]==3);
1731     }
1732     }
1733    
1734 jgs 501 }
1735    
1736     {
1737    
1738     cout << "\tTest adding three keys with three values to DataTagged with default value only." << endl;
1739    
1740     DataArrayView::ShapeType viewShape;
1741     viewShape.push_back(3);
1742    
1743     DataTagged::TagListType keys;
1744    
1745     DataTagged::ValueListType values;
1746    
1747     DataArrayView::ValueType viewData(3);
1748     for (int i=0;i<viewShape[0];i++) {
1749     viewData[i]=i;
1750     }
1751     DataArrayView myView(viewData,viewShape);
1752    
1753     DataTagged myData(keys,values,myView,FunctionSpace());
1754    
1755     keys.push_back(1);
1756     keys.push_back(2);
1757     keys.push_back(3);
1758    
1759     DataArrayView::ValueType viewData1(3);
1760     for (int i=0;i<viewShape[0];i++) {
1761     viewData1[i]=i+1;
1762     }
1763     DataArrayView myView1(viewData1,viewShape);
1764     values.push_back(myView1);
1765    
1766     DataArrayView::ValueType viewData2(3);
1767     for (int i=0;i<viewShape[0];i++) {
1768     viewData2[i]=i+2;
1769     }
1770     DataArrayView myView2(viewData2,viewShape);
1771     values.push_back(myView2);
1772    
1773     DataArrayView::ValueType viewData3(3);
1774     for (int i=0;i<viewShape[0];i++) {
1775     viewData3[i]=i+3;
1776     }
1777     DataArrayView myView3(viewData3,viewShape);
1778     values.push_back(myView3);
1779    
1780     myData.addTaggedValues(keys,values);
1781    
1782     assert(myData.isCurrentTag(1));
1783     assert(myData.isCurrentTag(2));
1784     assert(myData.isCurrentTag(3));
1785    
1786     assert(myData.getTagLookup().size()==3);
1787    
1788     assert(myData.getLength()==12);
1789    
1790     // data-point 0 has tag number 1 by default
1791     assert(myData.getTagNumber(0)==1);
1792    
1793     assert(myData.getPointOffset(0,0)==3);
1794    
1795     DataArrayView myDataView = myData.getDataPoint(0,0);
1796     assert(myDataView==myView1);
1797     assert(!myDataView.isEmpty());
1798     assert(myDataView.getOffset()==3);
1799     assert(myDataView.getRank()==1);
1800     assert(myDataView.noValues()==3);
1801     assert(myDataView.getShape().size()==1);
1802     assert(myDataView(0)==1);
1803     assert(myDataView(1)==2);
1804     assert(myDataView(2)==3);
1805    
1806     myDataView = myData.getDataPointByTag(1);
1807     assert(myDataView==myView1);
1808     assert(!myDataView.isEmpty());
1809     assert(myDataView.getOffset()==3);
1810     assert(myDataView.getRank()==1);
1811     assert(myDataView.noValues()==3);
1812     assert(myDataView.getShape().size()==1);
1813     assert(myDataView(0)==1);
1814     assert(myDataView(1)==2);
1815     assert(myDataView(2)==3);
1816    
1817     myDataView = myData.getDataPointByTag(2);
1818     assert(myDataView==myView2);
1819     assert(!myDataView.isEmpty());
1820     assert(myDataView.getOffset()==6);
1821     assert(myDataView.getRank()==1);
1822     assert(myDataView.noValues()==3);
1823     assert(myDataView.getShape().size()==1);
1824     assert(myDataView(0)==2);
1825     assert(myDataView(1)==3);
1826     assert(myDataView(2)==4);
1827    
1828     myDataView = myData.getDataPointByTag(3);
1829     assert(myDataView==myView3);
1830     assert(!myDataView.isEmpty());
1831     assert(myDataView.getOffset()==9);
1832     assert(myDataView.getRank()==1);
1833     assert(myDataView.noValues()==3);
1834     assert(myDataView.getShape().size()==1);
1835     assert(myDataView(0)==3);
1836     assert(myDataView(1)==4);
1837     assert(myDataView(2)==5);
1838    
1839     myDataView = myData.getDefaultValue();
1840     assert(myDataView==myView);
1841     assert(!myDataView.isEmpty());
1842     assert(myDataView.getOffset()==0);
1843     assert(myDataView.getRank()==1);
1844     assert(myDataView.noValues()==3);
1845     assert(myDataView.getShape().size()==1);
1846     assert(myDataView(0)==0);
1847     assert(myDataView(1)==1);
1848     assert(myDataView(2)==2);
1849    
1850 jgs 506 // use a non-existent tag so we get a pointer to
1851     // the first element of the data array
1852     double* sampleData=myData.getSampleDataByTag(9);
1853     for (int i=0; i<myData.getLength(); i++) {
1854     if (i<3) {
1855     assert(sampleData[i]==i);
1856 jgs 508 } else if ((i>=3) && (i<6)) {
1857 jgs 506 assert(sampleData[i]==i-2);
1858 jgs 508 } else if ((i>=6) && (i<9)) {
1859 jgs 506 assert(sampleData[i]==i-4);
1860 jgs 508 } else {
1861 jgs 506 assert(sampleData[i]==i-6);
1862     }
1863     }
1864    
1865 jgs 501 }
1866    
1867     {
1868    
1869     cout << "\tTest adding one key with empty value list to DataTagged with three tags." << endl;
1870    
1871     DataTagged::TagListType keys;
1872     keys.push_back(1);
1873     keys.push_back(2);
1874     keys.push_back(3);
1875    
1876     DataTagged::ValueListType values;
1877    
1878     DataArrayView::ShapeType viewShape;
1879     viewShape.push_back(3);
1880    
1881     // default value
1882     DataArrayView::ValueType viewData(3);
1883     for (int i=0;i<viewShape[0];i++) {
1884     viewData[i]=i;
1885     }
1886     DataArrayView myView(viewData,viewShape);
1887    
1888     // value for tag "1"
1889     DataArray eOne(myView);
1890     for (int i=0;i<eOne.getView().getShape()[0];i++) {
1891     eOne.getView()(i)=i+1.0;
1892     }
1893     values.push_back(eOne.getView());
1894    
1895     // value for tag "2"
1896     DataArray eTwo(myView);
1897     for (int i=0;i<eTwo.getView().getShape()[0];i++) {
1898     eTwo.getView()(i)=i+2.0;
1899     }
1900     values.push_back(eTwo.getView());
1901    
1902     // value for tag "3"
1903     DataArray eThree(myView);
1904     for (int i=0;i<eThree.getView().getShape()[0];i++) {
1905     eThree.getView()(i)=i+3.0;
1906     }
1907     values.push_back(eThree.getView());
1908    
1909     DataTagged myData(keys,values,myView,FunctionSpace());
1910    
1911     keys.clear();
1912     keys.push_back(4);
1913     values.clear();
1914    
1915     myData.addTaggedValues(keys,values);
1916    
1917     assert(myData.isCurrentTag(4));
1918    
1919     assert(myData.getTagLookup().size()==4);
1920    
1921     assert(myData.getLength()==15);
1922    
1923     DataArrayView myDataView = myData.getDataPointByTag(4);
1924     assert(myDataView==myView);
1925     assert(!myDataView.isEmpty());
1926     assert(myDataView.getOffset()==12);
1927     assert(myDataView.getRank()==1);
1928     assert(myDataView.noValues()==3);
1929     assert(myDataView.getShape().size()==1);
1930     assert(myDataView(0)==0);
1931     assert(myDataView(1)==1);
1932     assert(myDataView(2)==2);
1933    
1934 jgs 506 // use a non-existent tag so we get a pointer to
1935     // the first element of the data array
1936     double* sampleData=myData.getSampleDataByTag(9);
1937     for (int i=0; i<myData.getLength(); i++) {
1938     if (i<3) {
1939     assert(sampleData[i]==i);
1940 jgs 508 } else if ((i>=3) && (i<6)) {
1941 jgs 506 assert(sampleData[i]==i-2);
1942 jgs 508 } else if ((i>=6) && (i<9)) {
1943 jgs 506 assert(sampleData[i]==i-4);
1944 jgs 508 } else if ((i>=9) && (i<12)) {
1945 jgs 506 assert(sampleData[i]==i-6);
1946 jgs 508 } else {
1947 jgs 506 assert(sampleData[i]==i-12);
1948     }
1949     }
1950    
1951 jgs 501 }
1952    
1953     {
1954    
1955     cout << "\tTest adding one key with one value to DataTagged with three tags." << endl;
1956    
1957     DataTagged::TagListType keys;
1958     keys.push_back(1);
1959     keys.push_back(2);
1960     keys.push_back(3);
1961    
1962     DataTagged::ValueListType values;
1963    
1964     DataArrayView::ShapeType viewShape;
1965     viewShape.push_back(3);
1966    
1967     // default value
1968     DataArrayView::ValueType viewData(3);
1969     for (int i=0;i<viewShape[0];i++) {
1970     viewData[i]=i;
1971     }
1972     DataArrayView myView(viewData,viewShape);
1973    
1974     // value for tag "1"
1975     DataArray eOne(myView);
1976     for (int i=0;i<eOne.getView().getShape()[0];i++) {
1977     eOne.getView()(i)=i+1.0;
1978     }
1979     values.push_back(eOne.getView());
1980    
1981     // value for tag "2"
1982     DataArray eTwo(myView);
1983     for (int i=0;i<eTwo.getView().getShape()[0];i++) {
1984     eTwo.getView()(i)=i+2.0;
1985     }
1986     values.push_back(eTwo.getView());
1987    
1988     // value for tag "3"
1989     DataArray eThree(myView);
1990     for (int i=0;i<eThree.getView().getShape()[0];i++) {
1991     eThree.getView()(i)=i+3.0;
1992     }
1993     values.push_back(eThree.getView());
1994    
1995     DataTagged myData(keys,values,myView,FunctionSpace());
1996    
1997     keys.clear();
1998     keys.push_back(4);
1999    
2000     values.clear();
2001     // value for tag "4"
2002     DataArray eFour(myView);
2003     for (int i=0;i<eFour.getView().getShape()[0];i++) {
2004     eFour.getView()(i)=i+4.0;
2005     }
2006     values.push_back(eFour.getView());
2007    
2008     myData.addTaggedValues(keys,values);
2009    
2010     assert(myData.isCurrentTag(4));
2011    
2012     assert(myData.getTagLookup().size()==4);
2013    
2014     assert(myData.getLength()==15);
2015    
2016     DataArrayView myDataView = myData.getDataPointByTag(4);
2017     assert(myDataView==eFour.getView());
2018     assert(!myDataView.isEmpty());
2019     assert(myDataView.getOffset()==12);
2020     assert(myDataView.getRank()==1);
2021     assert(myDataView.noValues()==3);
2022     assert(myDataView.getShape().size()==1);
2023     assert(myDataView(0)==4);
2024     assert(myDataView(1)==5);
2025     assert(myDataView(2)==6);
2026    
2027 jgs 506 // use a non-existent tag so we get a pointer to
2028     // the first element of the data array
2029     double* sampleData=myData.getSampleDataByTag(9);
2030     for (int i=0; i<myData.getLength(); i++) {
2031     if (i<3) {
2032     assert(sampleData[i]==i);
2033 jgs 508 } else if ((i>=3) && (i<6)) {
2034 jgs 506 assert(sampleData[i]==i-2);
2035 jgs 508 } else if ((i>=6) && (i<9)) {
2036 jgs 506 assert(sampleData[i]==i-4);
2037 jgs 508 } else if ((i>=9) && (i<12)) {
2038 jgs 506 assert(sampleData[i]==i-6);
2039 jgs 508 } else {
2040 jgs 506 assert(sampleData[i]==i-8);
2041     }
2042     }
2043    
2044 jgs 501 }
2045    
2046     {
2047    
2048     cout << "\tTest adding three keys with one value to DataTagged with three tags." << endl;
2049    
2050     DataTagged::TagListType keys;
2051     keys.push_back(1);
2052     keys.push_back(2);
2053     keys.push_back(3);
2054    
2055     DataTagged::ValueListType values;
2056    
2057     DataArrayView::ShapeType viewShape;
2058     viewShape.push_back(3);
2059    
2060     // default value
2061     DataArrayView::ValueType viewData(3);
2062     for (int i=0;i<viewShape[0];i++) {
2063     viewData[i]=i;
2064     }
2065     DataArrayView myView(viewData,viewShape);
2066    
2067     // value for tag "1"
2068     DataArray eOne(myView);
2069     for (int i=0;i<eOne.getView().getShape()[0];i++) {
2070     eOne.getView()(i)=i+1.0;
2071     }
2072     values.push_back(eOne.getView());
2073    
2074     // value for tag "2"
2075     DataArray eTwo(myView);
2076     for (int i=0;i<eTwo.getView().getShape()[0];i++) {
2077     eTwo.getView()(i)=i+2.0;
2078     }
2079     values.push_back(eTwo.getView());
2080    
2081     // value for tag "3"
2082     DataArray eThree(myView);
2083     for (int i=0;i<eThree.getView().getShape()[0];i++) {
2084     eThree.getView()(i)=i+3.0;
2085     }
2086     values.push_back(eThree.getView());
2087    
2088     DataTagged myData(keys,values,myView,FunctionSpace());
2089    
2090     keys.clear();
2091     keys.push_back(4);
2092     keys.push_back(5);
2093     keys.push_back(6);
2094    
2095     values.clear();
2096     // value for tags "4", "5" and "6"
2097     DataArray eFour(myView);
2098     for (int i=0;i<eFour.getView().getShape()[0];i++) {
2099     eFour.getView()(i)=i+4.0;
2100     }
2101     values.push_back(eFour.getView());
2102    
2103     myData.addTaggedValues(keys,values);
2104    
2105     assert(myData.isCurrentTag(4));
2106     assert(myData.isCurrentTag(5));
2107     assert(myData.isCurrentTag(6));
2108    
2109     assert(myData.getTagLookup().size()==6);
2110    
2111     assert(myData.getLength()==21);
2112    
2113     DataArrayView myDataView = myData.getDataPointByTag(4);
2114     assert(myDataView==eFour.getView());
2115     assert(!myDataView.isEmpty());
2116     assert(myDataView.getOffset()==12);
2117     assert(myDataView.getRank()==1);
2118     assert(myDataView.noValues()==3);
2119     assert(myDataView.getShape().size()==1);
2120     assert(myDataView(0)==4);
2121     assert(myDataView(1)==5);
2122     assert(myDataView(2)==6);
2123    
2124     myDataView = myData.getDataPointByTag(5);
2125     assert(myDataView==eFour.getView());
2126     assert(!myDataView.isEmpty());
2127     assert(myDataView.getOffset()==15);
2128     assert(myDataView.getRank()==1);
2129     assert(myDataView.noValues()==3);
2130     assert(myDataView.getShape().size()==1);
2131     assert(myDataView(0)==4);
2132     assert(myDataView(1)==5);
2133     assert(myDataView(2)==6);
2134    
2135     myDataView = myData.getDataPointByTag(6);
2136     assert(myDataView==eFour.getView());
2137     assert(!myDataView.isEmpty());
2138     assert(myDataView.getOffset()==18);
2139     assert(myDataView.getRank()==1);
2140     assert(myDataView.noValues()==3);
2141     assert(myDataView.getShape().size()==1);
2142     assert(myDataView(0)==4);
2143     assert(myDataView(1)==5);
2144     assert(myDataView(2)==6);
2145    
2146 jgs 506 // use a non-existent tag so we get a pointer to
2147     // the first element of the data array
2148     double* sampleData=myData.getSampleDataByTag(9);
2149     for (int i=0; i<myData.getLength(); i++) {
2150     if (i<3) {
2151     assert(sampleData[i]==i);
2152 jgs 508 } else if ((i>=3) && (i<6)) {
2153 jgs 506 assert(sampleData[i]==i-2);
2154 jgs 508 } else if ((i>=6) && (i<9)) {
2155 jgs 506 assert(sampleData[i]==i-4);
2156 jgs 508 } else if ((i>=9) && (i<12)) {
2157 jgs 506 assert(sampleData[i]==i-6);
2158 jgs 508 } else if ((i>=12) && (i<15)) {
2159 jgs 506 assert(sampleData[i]==i-8);
2160 jgs 508 } else if ((i>=15) && (i<18)) {
2161 jgs 506 assert(sampleData[i]==i-11);
2162 jgs 508 } else {
2163 jgs 506 assert(sampleData[i]==i-14);
2164     }
2165     }
2166    
2167 jgs 501 }
2168    
2169     {
2170    
2171     cout << "\tTest adding three keys with three values to DataTagged with three tags." << endl;
2172    
2173     DataTagged::TagListType keys;
2174     keys.push_back(1);
2175     keys.push_back(2);
2176     keys.push_back(3);
2177    
2178     DataTagged::ValueListType values;
2179    
2180     DataArrayView::ShapeType viewShape;
2181     viewShape.push_back(3);
2182    
2183     // default value
2184     DataArrayView::ValueType viewData(3);
2185     for (int i=0;i<viewShape[0];i++) {
2186     viewData[i]=i;
2187     }
2188     DataArrayView myView(viewData,viewShape);
2189    
2190     // value for tag "1"
2191     DataArray eOne(myView);
2192     for (int i=0;i<eOne.getView().getShape()[0];i++) {
2193     eOne.getView()(i)=i+1.0;
2194     }
2195     values.push_back(eOne.getView());
2196    
2197     // value for tag "2"
2198     DataArray eTwo(myView);
2199     for (int i=0;i<eTwo.getView().getShape()[0];i++) {
2200     eTwo.getView()(i)=i+2.0;
2201     }
2202     values.push_back(eTwo.getView());
2203    
2204     // value for tag "3"
2205     DataArray eThree(myView);
2206     for (int i=0;i<eThree.getView().getShape()[0];i++) {
2207     eThree.getView()(i)=i+3.0;
2208     }
2209     values.push_back(eThree.getView());
2210    
2211     DataTagged myData(keys,values,myView,FunctionSpace());
2212    
2213     keys.clear();
2214     keys.push_back(4);
2215     keys.push_back(5);
2216     keys.push_back(6);
2217    
2218     values.clear();
2219    
2220     // value for tag "4"
2221     DataArray eFour(myView);
2222     for (int i=0;i<eFour.getView().getShape()[0];i++) {
2223     eFour.getView()(i)=i+4.0;
2224     }
2225     values.push_back(eFour.getView());
2226    
2227     // value for tag "5"
2228     DataArray eFive(myView);
2229     for (int i=0;i<eFive.getView().getShape()[0];i++) {
2230     eFive.getView()(i)=i+5.0;
2231     }
2232     values.push_back(eFive.getView());
2233    
2234     // value for tag "6"
2235     DataArray eSix(myView);
2236     for (int i=0;i<eSix.getView().getShape()[0];i++) {
2237     eSix.getView()(i)=i+6.0;
2238     }
2239     values.push_back(eSix.getView());
2240    
2241     myData.addTaggedValues(keys,values);
2242    
2243     assert(myData.isCurrentTag(4));
2244     assert(myData.isCurrentTag(5));
2245     assert(myData.isCurrentTag(6));
2246    
2247     assert(myData.getTagLookup().size()==6);
2248    
2249     assert(myData.getLength()==21);
2250    
2251     DataArrayView myDataView = myData.getDataPointByTag(4);
2252     assert(myDataView==eFour.getView());
2253     assert(!myDataView.isEmpty());
2254     assert(myDataView.getOffset()==12);
2255     assert(myDataView.getRank()==1);
2256     assert(myDataView.noValues()==3);
2257     assert(myDataView.getShape().size()==1);
2258     assert(myDataView(0)==4);
2259     assert(myDataView(1)==5);
2260     assert(myDataView(2)==6);
2261    
2262     myDataView = myData.getDataPointByTag(5);
2263     assert(myDataView==eFive.getView());
2264     assert(!myDataView.isEmpty());
2265     assert(myDataView.getOffset()==15);
2266     assert(myDataView.getRank()==1);
2267     assert(myDataView.noValues()==3);
2268     assert(myDataView.getShape().size()==1);
2269     assert(myDataView(0)==5);
2270     assert(myDataView(1)==6);
2271     assert(myDataView(2)==7);
2272    
2273     myDataView = myData.getDataPointByTag(6);
2274     assert(myDataView==eSix.getView());
2275     assert(!myDataView.isEmpty());
2276     assert(myDataView.getOffset()==18);
2277     assert(myDataView.getRank()==1);
2278     assert(myDataView.noValues()==3);
2279     assert(myDataView.getShape().size()==1);
2280     assert(myDataView(0)==6);
2281     assert(myDataView(1)==7);
2282     assert(myDataView(2)==8);
2283    
2284 jgs 506 // use a non-existent tag so we get a pointer to
2285     // the first element of the data array
2286     double* sampleData=myData.getSampleDataByTag(9);
2287     for (int i=0; i<myData.getLength(); i++) {
2288     if (i<3) {
2289     assert(sampleData[i]==i);
2290 jgs 508 } else if ((i>=3) && (i<6)) {
2291 jgs 506 assert(sampleData[i]==i-2);
2292 jgs 508 } else if ((i>=6) && (i<9)) {
2293 jgs 506 assert(sampleData[i]==i-4);
2294 jgs 508 } else if ((i>=9) && (i<12)) {
2295 jgs 506 assert(sampleData[i]==i-6);
2296 jgs 508 } else if ((i>=12) && (i<15)) {
2297 jgs 506 assert(sampleData[i]==i-8);
2298 jgs 508 } else if ((i>=15) && (i<18)) {
2299 jgs 506 assert(sampleData[i]==i-10);
2300 jgs 508 } else {
2301 jgs 506 assert(sampleData[