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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 548 - (hide annotations)
Tue Feb 21 23:52:41 2006 UTC (13 years, 9 months ago) by jgs
Original Path: trunk/escript/test/DataTagged/DataTaggedTestCase.cpp
File size: 156375 byte(s)
modify tests for binary operations and setSlice to ensure situations where two DataTaggeds with mismatched tag sets are tested correctly
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     #include "EsysException.h"
18    
19 jgs 474 #include "DataTagged.h"
20 jgs 503 #include "DataConstant.h"
21 jgs 497
22     #include "DataTaggedTestCase.h"
23    
24 jgs 474 #include "BinaryOp.h"
25     #include "UnaryOp.h"
26     #include "FunctionSpaceFactory.h"
27     #include "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 506 cout << "\tTest binaryOp multiplication of two DataTagged objects with overlapping tag sets." << endl;
804    
805     DataTagged myData;
806     DataTagged right;
807    
808 jgs 548 // it's important that default values are different, as we need to be able to
809     // verify that the tag values in each object are being added to the correct
810     // default values - since the tag lists don't match, the default values will
811     // be used for missing tags in each object
812     myData.getDefaultValue()()=2.0;
813     right.getDefaultValue()()=3.0;
814    
815 jgs 506 DataArray vOne(1.0);
816     DataArray vTwo(2.0);
817     myData.addTaggedValue(1,vOne.getView());
818     myData.addTaggedValue(2,vOne.getView());
819     right.addTaggedValue(2,vTwo.getView());
820     right.addTaggedValue(3,vTwo.getView());
821    
822 jgs 548 //cout << myData.toString() << endl;
823     //cout << right.toString() << endl;
824    
825 jgs 506 binaryOp(myData,right,multiplies<double>());
826    
827 jgs 548 //cout << myData.toString() << endl;
828    
829 jgs 506 assert(myData.getNumSamples()==1);
830     assert(myData.getNumDPPSample()==1);
831    
832     assert(myData.validSamplePointNo(0));
833     assert(myData.validSampleNo(0));
834     assert(!myData.validSamplePointNo(1));
835     assert(!myData.validSampleNo(1));
836    
837     // data-point 0 has tag number 1 by default
838     assert(myData.getTagNumber(0)==1);
839    
840     assert(myData.isCurrentTag(1));
841     assert(myData.isCurrentTag(2));
842     assert(myData.isCurrentTag(3));
843    
844     assert(myData.getTagLookup().size()==3);
845    
846     assert(myData.getLength()==4);
847    
848     assert(myData.getPointOffset(0,0)==1);
849    
850     // check result value for tag "1"
851     DataArrayView myDataView = myData.getDataPointByTag(1);
852     assert(!myDataView.isEmpty());
853     assert(myDataView.getOffset()==1);
854     assert(myDataView.getRank()==0);
855     assert(myDataView.noValues()==1);
856     assert(myDataView.getShape().size()==0);
857 jgs 548 assert(myDataView()==3.0);
858 jgs 506
859     // check result value for tag "2"
860     myDataView = myData.getDataPointByTag(2);
861     assert(!myDataView.isEmpty());
862     assert(myDataView.getOffset()==2);
863     assert(myDataView.getRank()==0);
864     assert(myDataView.noValues()==1);
865     assert(myDataView.getShape().size()==0);
866     assert(myDataView()==2.0);
867    
868     // check result value for tag "3"
869     myDataView = myData.getDataPointByTag(3);
870     assert(!myDataView.isEmpty());
871     assert(myDataView.getOffset()==3);
872     assert(myDataView.getRank()==0);
873     assert(myDataView.noValues()==1);
874     assert(myDataView.getShape().size()==0);
875 jgs 548 assert(myDataView()==4.0);
876 jgs 506
877     // check result for default value
878     myDataView = myData.getDefaultValue();
879     assert(!myDataView.isEmpty());
880     assert(myDataView.getOffset()==0);
881     assert(myDataView.getRank()==0);
882     assert(myDataView.noValues()==1);
883     assert(myDataView.getShape().size()==0);
884 jgs 548 assert(myDataView()==6.0);
885 jgs 506
886     // use a non-existent tag so we get a pointer to
887     // the first element of the data array
888     double* sampleData=myData.getSampleDataByTag(9);
889 jgs 548 assert(sampleData[0]==6);
890     assert(sampleData[1]==3);
891     assert(sampleData[2]==2);
892     assert(sampleData[3]==4);
893 jgs 506
894 jgs 504 }
895    
896     {
897 jgs 506 cout << "\tTest unaryOp negate on default DataTagged object." << endl;
898    
899     DataTagged myData;
900    
901     unaryOp(myData,negate<double>());
902    
903     //cout << myData.toString() << endl;
904    
905     assert(myData.getNumSamples()==1);
906     assert(myData.getNumDPPSample()==1);
907    
908     assert(myData.validSamplePointNo(0));
909     assert(myData.validSampleNo(0));
910     assert(!myData.validSamplePointNo(1));
911     assert(!myData.validSampleNo(1));
912    
913     // data-point 0 has tag number 1 by default
914     assert(myData.getTagNumber(0)==1);
915    
916     assert(!myData.isCurrentTag(1));
917    
918     assert(myData.getTagLookup().size()==0);
919    
920     assert(myData.getLength()==1);
921    
922     assert(myData.getPointOffset(0,0)==0);
923    
924     DataArrayView myDataView = myData.getDataPoint(0,0);
925     assert(!myDataView.isEmpty());
926     assert(myDataView.getOffset()==0);
927     assert(myDataView.getRank()==0);
928     assert(myDataView.noValues()==1);
929     assert(myDataView.getShape().size()==0);
930     assert(myDataView()==0.0);
931    
932     // Test non-existent tag returns the default value.
933     myDataView = myData.getDataPointByTag(1);
934     assert(!myDataView.isEmpty());
935     assert(myDataView.getOffset()==0);
936     assert(myDataView.getRank()==0);
937     assert(myDataView.noValues()==1);
938     assert(myDataView.getShape().size()==0);
939     assert(myDataView()==0.0);
940    
941     myDataView = myData.getDefaultValue();
942     assert(!myDataView.isEmpty());
943     assert(myDataView.getOffset()==0);
944     assert(myDataView.getRank()==0);
945     assert(myDataView.noValues()==1);
946     assert(myDataView.getShape().size()==0);
947     assert(myDataView()==0.0);
948    
949     // use a non-existent tag so we get a pointer to
950     // the first element of the data array
951     double* sampleData=myData.getSampleDataByTag(9);
952     for (int i=0; i<myData.getLength(); i++) {
953     assert(sampleData[i]==i);
954     }
955    
956 jgs 504 }
957    
958     {
959 jgs 506 cout << "\tTest unaryOp negate on DataTagged object with default value only." << endl;
960    
961     DataArrayView::ShapeType viewShape;
962     viewShape.push_back(3);
963    
964     DataTagged::TagListType keys;
965    
966     DataTagged::ValueListType values;
967    
968     DataArrayView::ValueType viewData(3);
969     for (int i=0;i<viewShape[0];i++) {
970     viewData[i]=i;
971     }
972     DataArrayView myView(viewData,viewShape);
973    
974     DataTagged myData(keys,values,myView,FunctionSpace());
975    
976     unaryOp(myData,negate<double>());
977    
978     //cout << myData.toString() << endl;
979    
980     assert(myData.getNumSamples()==1);
981     assert(myData.getNumDPPSample()==1);
982    
983     assert(myData.validSamplePointNo(0));
984     assert(myData.validSampleNo(0));
985     assert(!myData.validSamplePointNo(1));
986     assert(!myData.validSampleNo(1));
987    
988     // data-point 0 has tag number 1 by default
989     assert(myData.getTagNumber(0)==1);
990    
991     assert(!myData.isCurrentTag(1));
992    
993     assert(myData.getTagLookup().size()==0);
994    
995     assert(myData.getLength()==3);
996    
997     assert(myData.getPointOffset(0,0)==0);
998    
999     DataArrayView myDataView = myData.getDefaultValue();
1000     assert(!myDataView.isEmpty());
1001     assert(myDataView.getOffset()==0);
1002     assert(myDataView.getRank()==1);
1003     assert(myDataView.noValues()==3);
1004     assert(myDataView.getShape().size()==1);
1005     assert(myDataView(0)==0);
1006     assert(myDataView(1)==-1);
1007     assert(myDataView(2)==-2);
1008    
1009     // use a non-existent tag so we get a pointer to
1010     // the first element of the data array
1011     double* sampleData=myData.getSampleDataByTag(9);
1012     for (int i=0; i<myData.getLength(); i++) {
1013     assert(sampleData[i]==0-i);
1014     }
1015    
1016 jgs 504 }
1017    
1018 jgs 506 {
1019     cout << "\tTest unaryOp negate on DataTagged object with two tags." << endl;
1020    
1021     DataTagged myData;
1022    
1023     DataArray vOne(1.0);
1024     DataArray vTwo(2.0);
1025     myData.addTaggedValue(1,vOne.getView());
1026     myData.addTaggedValue(2,vTwo.getView());
1027    
1028     unaryOp(myData,negate<double>());
1029    
1030     assert(myData.getNumSamples()==1);
1031     assert(myData.getNumDPPSample()==1);
1032    
1033     assert(myData.validSamplePointNo(0));
1034     assert(myData.validSampleNo(0));
1035     assert(!myData.validSamplePointNo(1));
1036     assert(!myData.validSampleNo(1));
1037    
1038     // data-point 0 has tag number 1 by default
1039     assert(myData.getTagNumber(0)==1);
1040    
1041     assert(myData.isCurrentTag(1));
1042     assert(myData.isCurrentTag(2));
1043    
1044     assert(myData.getTagLookup().size()==2);
1045    
1046     assert(myData.getLength()==3);
1047    
1048     assert(myData.getPointOffset(0,0)==1);
1049    
1050     // check result value for tag "1"
1051     DataArrayView myDataView = myData.getDataPointByTag(1);
1052     assert(!myDataView.isEmpty());
1053     assert(myDataView.getOffset()==1);
1054     assert(myDataView.getRank()==0);
1055     assert(myDataView.noValues()==1);
1056     assert(myDataView.getShape().size()==0);
1057     assert(myDataView()==-1.0);
1058    
1059     // check result value for tag "2"
1060     myDataView = myData.getDataPointByTag(2);
1061     assert(!myDataView.isEmpty());
1062     assert(myDataView.getOffset()==2);
1063     assert(myDataView.getRank()==0);
1064     assert(myDataView.noValues()==1);
1065     assert(myDataView.getShape().size()==0);
1066     assert(myDataView()==-2.0);
1067    
1068     // check result for default value
1069     myDataView = myData.getDefaultValue();
1070     assert(!myDataView.isEmpty());
1071     assert(myDataView.getOffset()==0);
1072     assert(myDataView.getRank()==0);
1073     assert(myDataView.noValues()==1);
1074     assert(myDataView.getShape().size()==0);
1075     assert(myDataView()==0.0);
1076    
1077     // use a non-existent tag so we get a pointer to
1078     // the first element of the data array
1079     double* sampleData=myData.getSampleDataByTag(9);
1080     for (int i=0; i<myData.getLength(); i++) {
1081     assert(sampleData[i]==0-i);
1082     }
1083    
1084     }
1085    
1086 jgs 82 }
1087    
1088 jgs 501 void DataTaggedTestCase::testAddTaggedValues() {
1089    
1090     cout << endl;
1091    
1092     {
1093    
1094     cout << "\tTest adding one key with empty value list to default DataTagged." << endl;
1095     DataTagged myData;
1096    
1097     DataTagged::TagListType keys;
1098     keys.push_back(1);
1099    
1100     DataTagged::ValueListType values;
1101    
1102     myData.addTaggedValues(keys,values);
1103    
1104     assert(myData.isCurrentTag(1));
1105    
1106     assert(myData.getTagLookup().size()==1);
1107    
1108     assert(myData.getLength()==2);
1109    
1110     // data-point 0 has tag number 1 by default
1111     assert(myData.getTagNumber(0)==1);
1112    
1113     assert(myData.getPointOffset(0,0)==1);
1114    
1115     DataArrayView myDataView = myData.getDataPoint(0,0);
1116     assert(!myDataView.isEmpty());
1117     assert(myDataView.getOffset()==1);
1118     assert(myDataView.getRank()==0);
1119     assert(myDataView.noValues()==1);
1120     assert(myDataView.getShape().size()==0);
1121     assert(myDataView()==0.0);
1122    
1123     myDataView = myData.getDataPointByTag(1);
1124     assert(!myDataView.isEmpty());
1125     assert(myDataView.getOffset()==1);
1126     assert(myDataView.getRank()==0);
1127     assert(myDataView.noValues()==1);
1128     assert(myDataView.getShape().size()==0);
1129     assert(myDataView()==0.0);
1130    
1131     myDataView = myData.getDefaultValue();
1132     assert(!myDataView.isEmpty());
1133     assert(myDataView.getOffset()==0);
1134     assert(myDataView.getRank()==0);
1135     assert(myDataView.noValues()==1);
1136     assert(myDataView.getShape().size()==0);
1137     assert(myDataView()==0.0);
1138    
1139 jgs 506 // use a non-existent tag so we get a pointer to
1140     // the first element of the data array
1141     double* sampleData=myData.getSampleDataByTag(9);
1142     for (int i=0; i<myData.getLength(); i++) {
1143     assert(sampleData[i]==0);
1144     }
1145    
1146 jgs 501 }
1147    
1148     {
1149    
1150     cout << "\tTest adding one key with one value to default DataTagged." << endl;
1151     DataTagged myData;
1152    
1153     DataTagged::TagListType keys;
1154     keys.push_back(1);
1155    
1156     DataTagged::ValueListType values;
1157    
1158     DataArrayView::ShapeType viewShape;
1159     DataArrayView::ValueType viewData(1);
1160     viewData[0]=1.0;
1161     DataArrayView myView(viewData,viewShape);
1162     values.push_back(myView);
1163    
1164     myData.addTaggedValues(keys,values);
1165    
1166     assert(myData.isCurrentTag(1));
1167    
1168     assert(myData.getTagLookup().size()==1);
1169    
1170     assert(myData.getLength()==2);
1171    
1172     // data-point 0 has tag number 1 by default
1173     assert(myData.getTagNumber(0)==1);
1174    
1175     assert(myData.getPointOffset(0,0)==1);
1176    
1177     DataArrayView myDataView = myData.getDataPoint(0,0);
1178     assert(!myDataView.isEmpty());
1179     assert(myDataView.getOffset()==1);
1180     assert(myDataView.getRank()==0);
1181     assert(myDataView.noValues()==1);
1182     assert(myDataView.getShape().size()==0);
1183     assert(myDataView()==1.0);
1184    
1185     myDataView = myData.getDataPointByTag(1);
1186     assert(!myDataView.isEmpty());
1187     assert(myDataView.getOffset()==1);
1188     assert(myDataView.getRank()==0);
1189     assert(myDataView.noValues()==1);
1190     assert(myDataView.getShape().size()==0);
1191     assert(myDataView()==1.0);
1192    
1193     myDataView = myData.getDefaultValue();
1194     assert(!myDataView.isEmpty());
1195     assert(myDataView.getOffset()==0);
1196     assert(myDataView.getRank()==0);
1197     assert(myDataView.noValues()==1);
1198     assert(myDataView.getShape().size()==0);
1199     assert(myDataView()==0.0);
1200    
1201 jgs 506 // use a non-existent tag so we get a pointer to
1202     // the first element of the data array
1203     double* sampleData=myData.getSampleDataByTag(9);
1204     for (int i=0; i<myData.getLength(); i++) {
1205     assert(sampleData[i]==i);
1206     }
1207    
1208 jgs 501 }
1209    
1210     {
1211    
1212     cout << "\tTest adding three keys with one value to default DataTagged." << endl;
1213     DataTagged myData;
1214    
1215     DataTagged::TagListType keys;
1216     keys.push_back(1);
1217     keys.push_back(2);
1218     keys.push_back(3);
1219    
1220     DataTagged::ValueListType values;
1221    
1222     DataArrayView::ShapeType viewShape;
1223     DataArrayView::ValueType viewData(1);
1224     viewData[0]=1.0;
1225     DataArrayView myView(viewData,viewShape);
1226     values.push_back(myView);
1227    
1228     myData.addTaggedValues(keys,values);
1229    
1230     assert(myData.isCurrentTag(1));
1231     assert(myData.isCurrentTag(2));
1232     assert(myData.isCurrentTag(3));
1233    
1234     assert(myData.getTagLookup().size()==3);
1235    
1236     assert(myData.getLength()==4);
1237    
1238     // data-point 0 has tag number 1 by default
1239     assert(myData.getTagNumber(0)==1);
1240    
1241     assert(myData.getPointOffset(0,0)==1);
1242    
1243     DataArrayView myDataView = myData.getDataPoint(0,0);
1244     assert(!myDataView.isEmpty());
1245     assert(myDataView.getOffset()==1);
1246     assert(myDataView.getRank()==0);
1247     assert(myDataView.noValues()==1);
1248     assert(myDataView.getShape().size()==0);
1249     assert(myDataView()==1.0);
1250    
1251     myDataView = myData.getDataPointByTag(1);
1252     assert(!myDataView.isEmpty());
1253     assert(myDataView.getOffset()==1);
1254     assert(myDataView.getRank()==0);
1255     assert(myDataView.noValues()==1);
1256     assert(myDataView.getShape().size()==0);
1257     assert(myDataView()==1.0);
1258    
1259     myDataView = myData.getDataPointByTag(2);
1260     assert(!myDataView.isEmpty());
1261     assert(myDataView.getOffset()==2);
1262     assert(myDataView.getRank()==0);
1263     assert(myDataView.noValues()==1);
1264     assert(myDataView.getShape().size()==0);
1265     assert(myDataView()==1.0);
1266    
1267     myDataView = myData.getDataPointByTag(3);
1268     assert(!myDataView.isEmpty());
1269     assert(myDataView.getOffset()==3);
1270     assert(myDataView.getRank()==0);
1271     assert(myDataView.noValues()==1);
1272     assert(myDataView.getShape().size()==0);
1273     assert(myDataView()==1.0);
1274    
1275     myDataView = myData.getDefaultValue();
1276     assert(!myDataView.isEmpty());
1277     assert(myDataView.getOffset()==0);
1278     assert(myDataView.getRank()==0);
1279     assert(myDataView.noValues()==1);
1280     assert(myDataView.getShape().size()==0);
1281     assert(myDataView()==0.0);
1282    
1283 jgs 506 // use a non-existent tag so we get a pointer to
1284     // the first element of the data array
1285     double* sampleData=myData.getSampleDataByTag(9);
1286     for (int i=0; i<myData.getLength(); i++) {
1287     if (i==0) {
1288     assert(sampleData[i]==0);
1289     } else {
1290     assert(sampleData[i]==1);
1291     }
1292     }
1293    
1294 jgs 501 }
1295    
1296     {
1297    
1298     cout << "\tTest adding three keys with three values to default DataTagged." << endl;
1299     DataTagged myData;
1300    
1301     DataTagged::TagListType keys;
1302     keys.push_back(1);
1303     keys.push_back(2);
1304     keys.push_back(3);
1305    
1306     DataTagged::ValueListType values;
1307    
1308     DataArrayView::ShapeType viewShape;
1309     DataArrayView::ValueType viewData1(1);
1310     viewData1[0]=1.0;
1311     DataArrayView::ValueType viewData2(1);
1312     viewData2[0]=2.0;
1313     DataArrayView::ValueType viewData3(1);
1314     viewData3[0]=3.0;
1315     DataArrayView myView1(viewData1,viewShape);
1316     DataArrayView myView2(viewData2,viewShape);
1317     DataArrayView myView3(viewData3,viewShape);
1318     values.push_back(myView1);
1319     values.push_back(myView2);
1320     values.push_back(myView3);
1321    
1322     myData.addTaggedValues(keys,values);
1323    
1324     assert(myData.isCurrentTag(1));
1325     assert(myData.isCurrentTag(2));
1326     assert(myData.isCurrentTag(3));
1327    
1328     assert(myData.getTagLookup().size()==3);
1329    
1330     assert(myData.getLength()==4);
1331    
1332     // data-point 0 has tag number 1 by default
1333     assert(myData.getTagNumber(0)==1);
1334    
1335     assert(myData.getPointOffset(0,0)==1);
1336    
1337     DataArrayView myDataView = myData.getDataPoint(0,0);
1338     assert(!myDataView.isEmpty());
1339     assert(myDataView.getOffset()==1);
1340     assert(myDataView.getRank()==0);
1341     assert(myDataView.noValues()==1);
1342     assert(myDataView.getShape().size()==0);
1343     assert(myDataView()==1.0);
1344    
1345     myDataView = myData.getDataPointByTag(1);
1346     assert(!myDataView.isEmpty());
1347     assert(myDataView.getOffset()==1);
1348     assert(myDataView.getRank()==0);
1349     assert(myDataView.noValues()==1);
1350     assert(myDataView.getShape().size()==0);
1351     assert(myDataView()==1.0);
1352    
1353     myDataView = myData.getDataPointByTag(2);
1354     assert(!myDataView.isEmpty());
1355     assert(myDataView.getOffset()==2);
1356     assert(myDataView.getRank()==0);
1357     assert(myDataView.noValues()==1);
1358     assert(myDataView.getShape().size()==0);
1359     assert(myDataView()==2.0);
1360    
1361     myDataView = myData.getDataPointByTag(3);
1362     assert(!myDataView.isEmpty());
1363     assert(myDataView.getOffset()==3);
1364     assert(myDataView.getRank()==0);
1365     assert(myDataView.noValues()==1);
1366     assert(myDataView.getShape().size()==0);
1367     assert(myDataView()==3.0);
1368    
1369     myDataView = myData.getDefaultValue();
1370     assert(!myDataView.isEmpty());
1371     assert(myDataView.getOffset()==0);
1372     assert(myDataView.getRank()==0);
1373     assert(myDataView.noValues()==1);
1374     assert(myDataView.getShape().size()==0);
1375     assert(myDataView()==0.0);
1376    
1377 jgs 506 // use a non-existent tag so we get a pointer to
1378     // the first element of the data array
1379     double* sampleData=myData.getSampleDataByTag(9);
1380     for (int i=0; i<myData.getLength(); i++) {
1381     assert(sampleData[i]==i);
1382     }
1383    
1384 jgs 501 }
1385    
1386     {
1387    
1388     cout << "\tTest adding one key with empty value list to DataTagged with default value only." << endl;
1389    
1390     DataArrayView::ShapeType viewShape;
1391     viewShape.push_back(3);
1392    
1393     DataTagged::TagListType keys;
1394    
1395     DataTagged::ValueListType values;
1396    
1397     DataArrayView::ValueType viewData(3);
1398     for (int i=0;i<viewShape[0];i++) {
1399     viewData[i]=i;
1400     }
1401     DataArrayView myView(viewData,viewShape);
1402    
1403     DataTagged myData(keys,values,myView,FunctionSpace());
1404    
1405     keys.push_back(1);
1406     values.clear();
1407    
1408     myData.addTaggedValues(keys,values);
1409    
1410     assert(myData.isCurrentTag(1));
1411    
1412     assert(myData.getTagLookup().size()==1);
1413    
1414     assert(myData.getLength()==6);
1415    
1416     // data-point 0 has tag number 1 by default
1417     assert(myData.getTagNumber(0)==1);
1418    
1419     assert(myData.getPointOffset(0,0)==3);
1420    
1421     DataArrayView myDataView = myData.getDataPoint(0,0);
1422     assert(myDataView==myView);
1423     assert(!myDataView.isEmpty());
1424     assert(myDataView.getOffset()==3);
1425     assert(myDataView.getRank()==1);
1426     assert(myDataView.noValues()==3);
1427     assert(myDataView.getShape().size()==1);
1428     assert(myDataView(0)==0);
1429     assert(myDataView(1)==1);
1430     assert(myDataView(2)==2);
1431    
1432     myDataView = myData.getDataPointByTag(1);
1433     assert(myDataView==myView);
1434     assert(!myDataView.isEmpty());
1435     assert(myDataView.getOffset()==3);
1436     assert(myDataView.getRank()==1);
1437     assert(myDataView.noValues()==3);
1438     assert(myDataView.getShape().size()==1);
1439     assert(myDataView(0)==0);
1440     assert(myDataView(1)==1);
1441     assert(myDataView(2)==2);
1442    
1443     myDataView = myData.getDefaultValue();
1444     assert(myDataView==myView);
1445     assert(!myDataView.isEmpty());
1446     assert(myDataView.getOffset()==0);
1447     assert(myDataView.getRank()==1);
1448     assert(myDataView.noValues()==3);
1449     assert(myDataView.getShape().size()==1);
1450     assert(myDataView(0)==0);
1451     assert(myDataView(1)==1);
1452     assert(myDataView(2)==2);
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%3);
1459     }
1460    
1461 jgs 501 }
1462    
1463     {
1464    
1465     cout << "\tTest adding one key with one value 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    
1484     DataArrayView::ValueType viewData1(3);
1485     for (int i=0;i<viewShape[0];i++) {
1486 jgs 506 viewData1[i]=i+3;
1487 jgs 501 }
1488     DataArrayView myView1(viewData1,viewShape);
1489     values.push_back(myView1);
1490    
1491     myData.addTaggedValues(keys,values);
1492    
1493     assert(myData.isCurrentTag(1));
1494    
1495     assert(myData.getTagLookup().size()==1);
1496    
1497     assert(myData.getLength()==6);
1498    
1499     // data-point 0 has tag number 1 by default
1500     assert(myData.getTagNumber(0)==1);
1501    
1502     assert(myData.getPointOffset(0,0)==3);
1503    
1504     DataArrayView myDataView = myData.getDataPoint(0,0);
1505     assert(myDataView==myView1);
1506     assert(!myDataView.isEmpty());
1507     assert(myDataView.getOffset()==3);
1508     assert(myDataView.getRank()==1);
1509     assert(myDataView.noValues()==3);
1510     assert(myDataView.getShape().size()==1);
1511 jgs 506 assert(myDataView(0)==3);
1512     assert(myDataView(1)==4);
1513     assert(myDataView(2)==5);
1514 jgs 501
1515     myDataView = myData.getDataPointByTag(1);
1516     assert(myDataView==myView1);
1517     assert(!myDataView.isEmpty());
1518     assert(myDataView.getOffset()==3);
1519     assert(myDataView.getRank()==1);
1520     assert(myDataView.noValues()==3);
1521     assert(myDataView.getShape().size()==1);
1522 jgs 506 assert(myDataView(0)==3);
1523     assert(myDataView(1)==4);
1524     assert(myDataView(2)==5);
1525 jgs 501
1526     myDataView = myData.getDefaultValue();
1527     assert(myDataView==myView);
1528     assert(!myDataView.isEmpty());
1529     assert(myDataView.getOffset()==0);
1530     assert(myDataView.getRank()==1);
1531     assert(myDataView.noValues()==3);
1532     assert(myDataView.getShape().size()==1);
1533     assert(myDataView(0)==0);
1534     assert(myDataView(1)==1);
1535     assert(myDataView(2)==2);
1536    
1537 jgs 506 // use a non-existent tag so we get a pointer to
1538     // the first element of the data array
1539     double* sampleData=myData.getSampleDataByTag(9);
1540     for (int i=0; i<myData.getLength(); i++) {
1541     assert(sampleData[i]==i);
1542     }
1543    
1544 jgs 501 }
1545    
1546     {
1547    
1548     cout << "\tTest adding three keys with one value to DataTagged with default value only." << endl;
1549    
1550     DataArrayView::ShapeType viewShape;
1551     viewShape.push_back(3);
1552    
1553     DataTagged::TagListType keys;
1554    
1555     DataTagged::ValueListType values;
1556    
1557     DataArrayView::ValueType viewData(3);
1558     for (int i=0;i<viewShape[0];i++) {
1559     viewData[i]=i;
1560     }
1561     DataArrayView myView(viewData,viewShape);
1562    
1563     DataTagged myData(keys,values,myView,FunctionSpace());
1564    
1565     keys.push_back(1);
1566     keys.push_back(2);
1567     keys.push_back(3);
1568    
1569     DataArrayView::ValueType viewData1(3);
1570     for (int i=0;i<viewShape[0];i++) {
1571 jgs 506 viewData1[i]=3;
1572 jgs 501 }
1573     DataArrayView myView1(viewData1,viewShape);
1574     values.push_back(myView1);
1575    
1576     myData.addTaggedValues(keys,values);
1577    
1578     assert(myData.isCurrentTag(1));
1579     assert(myData.isCurrentTag(2));
1580     assert(myData.isCurrentTag(3));
1581    
1582     assert(myData.getTagLookup().size()==3);
1583    
1584     assert(myData.getLength()==12);
1585    
1586     // data-point 0 has tag number 1 by default
1587     assert(myData.getTagNumber(0)==1);
1588    
1589     assert(myData.getPointOffset(0,0)==3);
1590    
1591     DataArrayView myDataView = myData.getDataPoint(0,0);
1592     assert(myDataView==myView1);
1593     assert(!myDataView.isEmpty());
1594     assert(myDataView.getOffset()==3);
1595     assert(myDataView.getRank()==1);
1596     assert(myDataView.noValues()==3);
1597     assert(myDataView.getShape().size()==1);
1598 jgs 506 assert(myDataView(0)==3);
1599     assert(myDataView(1)==3);
1600 jgs 501 assert(myDataView(2)==3);
1601    
1602     myDataView = myData.getDataPointByTag(1);
1603     assert(myDataView==myView1);
1604     assert(!myDataView.isEmpty());
1605     assert(myDataView.getOffset()==3);
1606     assert(myDataView.getRank()==1);
1607     assert(myDataView.noValues()==3);
1608     assert(myDataView.getShape().size()==1);
1609 jgs 506 assert(myDataView(0)==3);
1610     assert(myDataView(1)==3);
1611 jgs 501 assert(myDataView(2)==3);
1612    
1613     myDataView = myData.getDataPointByTag(2);
1614     assert(myDataView==myView1);
1615     assert(!myDataView.isEmpty());
1616     assert(myDataView.getOffset()==6);
1617     assert(myDataView.getRank()==1);
1618     assert(myDataView.noValues()==3);
1619     assert(myDataView.getShape().size()==1);
1620 jgs 506 assert(myDataView(0)==3);
1621     assert(myDataView(1)==3);
1622 jgs 501 assert(myDataView(2)==3);
1623    
1624     myDataView = myData.getDataPointByTag(3);
1625     assert(myDataView==myView1);
1626     assert(!myDataView.isEmpty());
1627     assert(myDataView.getOffset()==9);
1628     assert(myDataView.getRank()==1);
1629     assert(myDataView.noValues()==3);
1630     assert(myDataView.getShape().size()==1);
1631 jgs 506 assert(myDataView(0)==3);
1632     assert(myDataView(1)==3);
1633 jgs 501 assert(myDataView(2)==3);
1634    
1635     myDataView = myData.getDefaultValue();
1636     assert(myDataView==myView);
1637     assert(!myDataView.isEmpty());
1638     assert(myDataView.getOffset()==0);
1639     assert(myDataView.getRank()==1);
1640     assert(myDataView.noValues()==3);
1641     assert(myDataView.getShape().size()==1);
1642     assert(myDataView(0)==0);
1643     assert(myDataView(1)==1);
1644     assert(myDataView(2)==2);
1645    
1646 jgs 506 // use a non-existent tag so we get a pointer to
1647     // the first element of the data array
1648     double* sampleData=myData.getSampleDataByTag(9);
1649     for (int i=0; i<myData.getLength(); i++) {
1650     if (i<3) {
1651     assert(sampleData[i]==i);
1652     } else {
1653     assert(sampleData[i]==3);
1654     }
1655     }
1656    
1657 jgs 501 }
1658    
1659     {
1660    
1661     cout << "\tTest adding three keys with three values to DataTagged with default value only." << endl;
1662    
1663     DataArrayView::ShapeType viewShape;
1664     viewShape.push_back(3);
1665    
1666     DataTagged::TagListType keys;
1667    
1668     DataTagged::ValueListType values;
1669    
1670     DataArrayView::ValueType viewData(3);
1671     for (int i=0;i<viewShape[0];i++) {
1672     viewData[i]=i;
1673     }
1674     DataArrayView myView(viewData,viewShape);
1675    
1676     DataTagged myData(keys,values,myView,FunctionSpace());
1677    
1678     keys.push_back(1);
1679     keys.push_back(2);
1680     keys.push_back(3);
1681    
1682     DataArrayView::ValueType viewData1(3);
1683     for (int i=0;i<viewShape[0];i++) {
1684     viewData1[i]=i+1;
1685     }
1686     DataArrayView myView1(viewData1,viewShape);
1687     values.push_back(myView1);
1688    
1689     DataArrayView::ValueType viewData2(3);
1690     for (int i=0;i<viewShape[0];i++) {
1691     viewData2[i]=i+2;
1692     }
1693     DataArrayView myView2(viewData2,viewShape);
1694     values.push_back(myView2);
1695    
1696     DataArrayView::ValueType viewData3(3);
1697     for (int i=0;i<viewShape[0];i++) {
1698     viewData3[i]=i+3;
1699     }
1700     DataArrayView myView3(viewData3,viewShape);
1701     values.push_back(myView3);
1702    
1703     myData.addTaggedValues(keys,values);
1704    
1705     assert(myData.isCurrentTag(1));
1706     assert(myData.isCurrentTag(2));
1707     assert(myData.isCurrentTag(3));
1708    
1709     assert(myData.getTagLookup().size()==3);
1710    
1711     assert(myData.getLength()==12);
1712    
1713     // data-point 0 has tag number 1 by default
1714     assert(myData.getTagNumber(0)==1);
1715    
1716     assert(myData.getPointOffset(0,0)==3);
1717    
1718     DataArrayView myDataView = myData.getDataPoint(0,0);
1719     assert(myDataView==myView1);
1720     assert(!myDataView.isEmpty());
1721     assert(myDataView.getOffset()==3);
1722     assert(myDataView.getRank()==1);
1723     assert(myDataView.noValues()==3);
1724     assert(myDataView.getShape().size()==1);
1725     assert(myDataView(0)==1);
1726     assert(myDataView(1)==2);
1727     assert(myDataView(2)==3);
1728    
1729     myDataView = myData.getDataPointByTag(1);
1730     assert(myDataView==myView1);
1731     assert(!myDataView.isEmpty());
1732     assert(myDataView.getOffset()==3);
1733     assert(myDataView.getRank()==1);
1734     assert(myDataView.noValues()==3);
1735     assert(myDataView.getShape().size()==1);
1736     assert(myDataView(0)==1);
1737     assert(myDataView(1)==2);
1738     assert(myDataView(2)==3);
1739    
1740     myDataView = myData.getDataPointByTag(2);
1741     assert(myDataView==myView2);
1742     assert(!myDataView.isEmpty());
1743     assert(myDataView.getOffset()==6);
1744     assert(myDataView.getRank()==1);
1745     assert(myDataView.noValues()==3);
1746     assert(myDataView.getShape().size()==1);
1747     assert(myDataView(0)==2);
1748     assert(myDataView(1)==3);
1749     assert(myDataView(2)==4);
1750    
1751     myDataView = myData.getDataPointByTag(3);
1752     assert(myDataView==myView3);
1753     assert(!myDataView.isEmpty());
1754     assert(myDataView.getOffset()==9);
1755     assert(myDataView.getRank()==1);
1756     assert(myDataView.noValues()==3);
1757     assert(myDataView.getShape().size()==1);
1758     assert(myDataView(0)==3);
1759     assert(myDataView(1)==4);
1760     assert(myDataView(2)==5);
1761    
1762     myDataView = myData.getDefaultValue();
1763     assert(myDataView==myView);
1764     assert(!myDataView.isEmpty());
1765     assert(myDataView.getOffset()==0);
1766     assert(myDataView.getRank()==1);
1767     assert(myDataView.noValues()==3);
1768     assert(myDataView.getShape().size()==1);
1769     assert(myDataView(0)==0);
1770     assert(myDataView(1)==1);
1771     assert(myDataView(2)==2);
1772    
1773 jgs 506 // use a non-existent tag so we get a pointer to
1774     // the first element of the data array
1775     double* sampleData=myData.getSampleDataByTag(9);
1776     for (int i=0; i<myData.getLength(); i++) {
1777     if (i<3) {
1778     assert(sampleData[i]==i);
1779 jgs 508 } else if ((i>=3) && (i<6)) {
1780 jgs 506 assert(sampleData[i]==i-2);
1781 jgs 508 } else if ((i>=6) && (i<9)) {
1782 jgs 506 assert(sampleData[i]==i-4);
1783 jgs 508 } else {
1784 jgs 506 assert(sampleData[i]==i-6);
1785     }
1786     }
1787    
1788 jgs 501 }
1789    
1790     {
1791    
1792     cout << "\tTest adding one key with empty value list to DataTagged with three tags." << endl;
1793    
1794     DataTagged::TagListType keys;
1795     keys.push_back(1);
1796     keys.push_back(2);
1797     keys.push_back(3);
1798    
1799     DataTagged::ValueListType values;
1800    
1801     DataArrayView::ShapeType viewShape;
1802     viewShape.push_back(3);
1803    
1804     // default value
1805     DataArrayView::ValueType viewData(3);
1806     for (int i=0;i<viewShape[0];i++) {
1807     viewData[i]=i;
1808     }
1809     DataArrayView myView(viewData,viewShape);
1810    
1811     // value for tag "1"
1812     DataArray eOne(myView);
1813     for (int i=0;i<eOne.getView().getShape()[0];i++) {
1814     eOne.getView()(i)=i+1.0;
1815     }
1816     values.push_back(eOne.getView());
1817    
1818     // value for tag "2"
1819     DataArray eTwo(myView);
1820     for (int i=0;i<eTwo.getView().getShape()[0];i++) {
1821     eTwo.getView()(i)=i+2.0;
1822     }
1823     values.push_back(eTwo.getView());
1824    
1825     // value for tag "3"
1826     DataArray eThree(myView);
1827     for (int i=0;i<eThree.getView().getShape()[0];i++) {
1828     eThree.getView()(i)=i+3.0;
1829     }
1830     values.push_back(eThree.getView());
1831    
1832     DataTagged myData(keys,values,myView,FunctionSpace());
1833    
1834     keys.clear();
1835     keys.push_back(4);
1836     values.clear();
1837    
1838     myData.addTaggedValues(keys,values);
1839    
1840     assert(myData.isCurrentTag(4));
1841    
1842     assert(myData.getTagLookup().size()==4);
1843    
1844     assert(myData.getLength()==15);
1845    
1846     DataArrayView myDataView = myData.getDataPointByTag(4);
1847     assert(myDataView==myView);
1848     assert(!myDataView.isEmpty());
1849     assert(myDataView.getOffset()==12);
1850     assert(myDataView.getRank()==1);
1851     assert(myDataView.noValues()==3);
1852     assert(myDataView.getShape().size()==1);
1853     assert(myDataView(0)==0);
1854     assert(myDataView(1)==1);
1855     assert(myDataView(2)==2);
1856    
1857 jgs 506 // use a non-existent tag so we get a pointer to
1858     // the first element of the data array
1859     double* sampleData=myData.getSampleDataByTag(9);
1860     for (int i=0; i<myData.getLength(); i++) {
1861     if (i<3) {
1862     assert(sampleData[i]==i);
1863 jgs 508 } else if ((i>=3) && (i<6)) {
1864 jgs 506 assert(sampleData[i]==i-2);
1865 jgs 508 } else if ((i>=6) && (i<9)) {
1866 jgs 506 assert(sampleData[i]==i-4);
1867 jgs 508 } else if ((i>=9) && (i<12)) {
1868 jgs 506 assert(sampleData[i]==i-6);
1869 jgs 508 } else {
1870 jgs 506 assert(sampleData[i]==i-12);
1871     }
1872     }
1873    
1874 jgs 501 }
1875    
1876     {
1877    
1878     cout << "\tTest adding one key with one value to DataTagged with three tags." << endl;
1879    
1880     DataTagged::TagListType keys;
1881     keys.push_back(1);
1882     keys.push_back(2);
1883     keys.push_back(3);
1884    
1885     DataTagged::ValueListType values;
1886    
1887     DataArrayView::ShapeType viewShape;
1888     viewShape.push_back(3);
1889    
1890     // default value
1891     DataArrayView::ValueType viewData(3);
1892     for (int i=0;i<viewShape[0];i++) {
1893     viewData[i]=i;
1894     }
1895     DataArrayView myView(viewData,viewShape);
1896    
1897     // value for tag "1"
1898     DataArray eOne(myView);
1899     for (int i=0;i<eOne.getView().getShape()[0];i++) {
1900     eOne.getView()(i)=i+1.0;
1901     }
1902     values.push_back(eOne.getView());
1903    
1904     // value for tag "2"
1905     DataArray eTwo(myView);
1906     for (int i=0;i<eTwo.getView().getShape()[0];i++) {
1907     eTwo.getView()(i)=i+2.0;
1908     }
1909     values.push_back(eTwo.getView());
1910    
1911     // value for tag "3"
1912     DataArray eThree(myView);
1913     for (int i=0;i<eThree.getView().getShape()[0];i++) {
1914     eThree.getView()(i)=i+3.0;
1915     }
1916     values.push_back(eThree.getView());
1917    
1918     DataTagged myData(keys,values,myView,FunctionSpace());
1919    
1920     keys.clear();
1921     keys.push_back(4);
1922    
1923     values.clear();
1924     // value for tag "4"
1925     DataArray eFour(myView);
1926     for (int i=0;i<eFour.getView().getShape()[0];i++) {
1927     eFour.getView()(i)=i+4.0;
1928     }
1929     values.push_back(eFour.getView());
1930    
1931     myData.addTaggedValues(keys,values);
1932    
1933     assert(myData.isCurrentTag(4));
1934    
1935     assert(myData.getTagLookup().size()==4);
1936    
1937     assert(myData.getLength()==15);
1938    
1939     DataArrayView myDataView = myData.getDataPointByTag(4);
1940     assert(myDataView==eFour.getView());
1941     assert(!myDataView.isEmpty());
1942     assert(myDataView.getOffset()==12);
1943     assert(myDataView.getRank()==1);
1944     assert(myDataView.noValues()==3);
1945     assert(myDataView.getShape().size()==1);
1946     assert(myDataView(0)==4);
1947     assert(myDataView(1)==5);
1948     assert(myDataView(2)==6);
1949    
1950 jgs 506 // use a non-existent tag so we get a pointer to
1951     // the first element of the data array
1952     double* sampleData=myData.getSampleDataByTag(9);
1953     for (int i=0; i<myData.getLength(); i++) {
1954     if (i<3) {
1955     assert(sampleData[i]==i);
1956 jgs 508 } else if ((i>=3) && (i<6)) {
1957 jgs 506 assert(sampleData[i]==i-2);
1958 jgs 508 } else if ((i>=6) && (i<9)) {
1959 jgs 506 assert(sampleData[i]==i-4);
1960 jgs 508 } else if ((i>=9) && (i<12)) {
1961 jgs 506 assert(sampleData[i]==i-6);
1962 jgs 508 } else {
1963 jgs 506 assert(sampleData[i]==i-8);
1964     }
1965     }
1966    
1967 jgs 501 }
1968    
1969     {
1970    
1971     cout << "\tTest adding three keys with one value to DataTagged with three tags." << endl;
1972    
1973     DataTagged::TagListType keys;
1974     keys.push_back(1);
1975     keys.push_back(2);
1976     keys.push_back(3);
1977    
1978     DataTagged::ValueListType values;
1979    
1980     DataArrayView::ShapeType viewShape;
1981     viewShape.push_back(3);
1982    
1983     // default value
1984     DataArrayView::ValueType viewData(3);
1985     for (int i=0;i<viewShape[0];i++) {
1986     viewData[i]=i;
1987     }
1988     DataArrayView myView(viewData,viewShape);
1989    
1990     // value for tag "1"
1991     DataArray eOne(myView);
1992     for (int i=0;i<eOne.getView().getShape()[0];i++) {
1993     eOne.getView()(i)=i+1.0;
1994     }
1995     values.push_back(eOne.getView());
1996    
1997     // value for tag "2"
1998     DataArray eTwo(myView);
1999     for (int i=0;i<eTwo.getView().getShape()[0];i++) {
2000     eTwo.getView()(i)=i+2.0;
2001     }
2002     values.push_back(eTwo.getView());
2003    
2004     // value for tag "3"
2005     DataArray eThree(myView);
2006     for (int i=0;i<eThree.getView().getShape()[0];i++) {
2007     eThree.getView()(i)=i+3.0;
2008     }
2009     values.push_back(eThree.getView());
2010    
2011     DataTagged myData(keys,values,myView,FunctionSpace());
2012    
2013     keys.clear();
2014     keys.push_back(4);
2015     keys.push_back(5);
2016     keys.push_back(6);
2017    
2018     values.clear();
2019     // value for tags "4", "5" and "6"
2020     DataArray eFour(myView);
2021     for (int i=0;i<eFour.getView().getShape()[0];i++) {
2022     eFour.getView()(i)=i+4.0;
2023     }
2024     values.push_back(eFour.getView());
2025    
2026     myData.addTaggedValues(keys,values);
2027    
2028     assert(myData.isCurrentTag(4));
2029     assert(myData.isCurrentTag(5));
2030     assert(myData.isCurrentTag(6));
2031    
2032     assert(myData.getTagLookup().size()==6);
2033    
2034     assert(myData.getLength()==21);
2035    
2036     DataArrayView myDataView = myData.getDataPointByTag(4);
2037     assert(myDataView==eFour.getView());
2038     assert(!myDataView.isEmpty());
2039     assert(myDataView.getOffset()==12);
2040     assert(myDataView.getRank()==1);
2041     assert(myDataView.noValues()==3);
2042     assert(myDataView.getShape().size()==1);
2043     assert(myDataView(0)==4);
2044     assert(myDataView(1)==5);
2045     assert(myDataView(2)==6);
2046    
2047     myDataView = myData.getDataPointByTag(5);
2048     assert(myDataView==eFour.getView());
2049     assert(!myDataView.isEmpty());
2050     assert(myDataView.getOffset()==15);
2051     assert(myDataView.getRank()==1);
2052     assert(myDataView.noValues()==3);
2053     assert(myDataView.getShape().size()==1);
2054     assert(myDataView(0)==4);
2055     assert(myDataView(1)==5);
2056     assert(myDataView(2)==6);
2057    
2058     myDataView = myData.getDataPointByTag(6);
2059     assert(myDataView==eFour.getView());
2060     assert(!myDataView.isEmpty());
2061     assert(myDataView.getOffset()==18);
2062     assert(myDataView.getRank()==1);
2063     assert(myDataView.noValues()==3);
2064     assert(myDataView.getShape().size()==1);
2065     assert(myDataView(0)==4);
2066     assert(myDataView(1)==5);
2067     assert(myDataView(2)==6);
2068    
2069 jgs 506 // use a non-existent tag so we get a pointer to
2070     // the first element of the data array
2071     double* sampleData=myData.getSampleDataByTag(9);
2072     for (int i=0; i<myData.getLength(); i++) {
2073     if (i<3) {
2074     assert(sampleData[i]==i);
2075 jgs 508 } else if ((i>=3) && (i<6)) {
2076 jgs 506 assert(sampleData[i]==i-2);
2077 jgs 508 } else if ((i>=6) && (i<9)) {
2078 jgs 506 assert(sampleData[i]==i-4);
2079 jgs 508 } else if ((i>=9) && (i<12)) {
2080 jgs 506 assert(sampleData[i]==i-6);
2081 jgs 508 } else if ((i>=12) && (i<15)) {
2082 jgs 506 assert(sampleData[i]==i-8);
2083 jgs 508 } else if ((i>=15) && (i<18)) {
2084 jgs 506 assert(sampleData[i]==i-11);
2085 jgs 508 } else {
2086 jgs 506 assert(sampleData[i]==i-14);
2087     }
2088     }
2089    
2090 jgs 501 }
2091    
2092     {
2093    
2094     cout << "\tTest adding three keys with three values to DataTagged with three tags." << endl;
2095    
2096     DataTagged::TagListType keys;
2097     keys.push_back(1);
2098     keys.push_back(2);
2099     keys.push_back(3);
2100    
2101     DataTagged::ValueListType values;
2102    
2103     DataArrayView::ShapeType viewShape;
2104     viewShape.push_back(3);
2105    
2106     // default value
2107     DataArrayView::ValueType viewData(3);
2108     for (int i=0;i<viewShape[0];i++) {
2109     viewData[i]=i;
2110     }
2111     DataArrayView myView(viewData,viewShape);
2112    
2113     // value for tag "1"
2114     DataArray eOne(myView);
2115     for (int i=0;i<eOne.getView().getShape()[0];i++) {
2116     eOne.getView()(i)=i+1.0;
2117     }
2118     values.push_back(eOne.getView());
2119    
2120     // value for tag "2"
2121     DataArray eTwo(myView);
2122     for (int i=0;i<eTwo.getView().getShape()[0];i++) {
2123     eTwo.getView()(i)=i+2.0;
2124     }
2125     values.push_back(eTwo.getView());
2126    
2127     // value for tag "3"
2128     DataArray eThree(myView);
2129     for (int i=0;i<eThree.getView().getShape()[0];i++) {
2130     eThree.getView()(i)=i+3.0;
2131     }
2132     values.push_back(eThree.getView());
2133    
2134     DataTagged myData(keys,values,myView,FunctionSpace());
2135    
2136     keys.clear();
2137     keys.push_back(4);
2138     keys.push_back(5);
2139     keys.push_back(6);
2140    
2141     values.clear();
2142    
2143     // value for tag "4"
2144     DataArray eFour(myView);
2145     for (int i=0;i<eFour.getView().getShape()[0];i++) {
2146     eFour.getView()(i)=i+4.0;
2147     }
2148     values.push_back(eFour.getView());
2149    
2150     // value for tag "5"
2151     DataArray eFive(myView);
2152     for (int i=0;i<eFive.getView().getShape()[0];i++) {
2153     eFive.getView()(i)=i+5.0;
2154     }
2155     values.push_back(eFive.getView());
2156    
2157     // value for tag "6"
2158     DataArray eSix(myView);
2159     for (int i=0;i<eSix.getView().getShape()[0];i++) {
2160     eSix.getView()(i)=i+6.0;
2161     }
2162     values.push_back(eSix.getView());
2163    
2164     myData.addTaggedValues(keys,values);
2165    
2166     assert(myData.isCurrentTag(4));
2167     assert(myData.isCurrentTag(5));
2168     assert(myData.isCurrentTag(6));
2169    
2170     assert(myData.getTagLookup().size()==6);
2171    
2172     assert(myData.getLength()==21);
2173    
2174     DataArrayView myDataView = myData.getDataPointByTag(4);
2175     assert(myDataView==eFour.getView());
2176     assert(!myDataView.isEmpty());
2177     assert(myDataView.getOffset()==12);
2178     assert(myDataView.getRank()==1);
2179     assert(myDataView.noValues()==3);
2180     assert(myDataView.getShape().size()==1);
2181     assert(myDataView(0)==4);
2182     assert(myDataView(1)==5);
2183     assert(myDataView(2)==6);
2184    
2185     myDataView = myData.getDataPointByTag(5);
2186     assert(myDataView==eFive.getView());
2187     assert(!myDataView.isEmpty());
2188     assert(myDataView.getOffset()==15);
2189     assert(myDataView.getRank()==1);
2190     assert(myDataView.noValues()==3);
2191     assert(myDataView.getShape().size()==1);
2192     assert(myDataView(0)==5);
2193     assert(myDataView(1)==6);
2194     assert(myDataView(2)==7);
2195    
2196     myDataView = myData.getDataPointByTag(6);
2197     assert(myDataView==eSix.getView());
2198     assert(!myDataView.isEmpty());
2199     assert(myDataView.getOffset()==18);
2200     assert(myDataView.getRank()==1);
2201     assert(myDataView.noValues()==3);
2202     assert(myDataView.getShape().size()==1);
2203     assert(myDataView(0)==6);
2204     assert(myDataView(1)==7);
2205     assert(myDataView(2)==8);
2206    
2207 jgs 506 // use a non-existent tag so we get a pointer to
2208     // the first element of the data array
2209     double* sampleData=myData.getSampleDataByTag(9);
2210     for (int i=0; i<myData.getLength(); i++) {
2211     if (i<3) {
2212     assert(sampleData[i]==i);
2213 jgs 508 } else if ((i>=3) && (i<6)) {
2214 jgs 506 assert(sampleData[i]==i-2);
2215 jgs 508 } else if ((i>=6) && (i<9)) {
2216 jgs 506 assert(sampleData[i]==i-4);
2217 jgs 508 } else if ((i>=9) && (i<12)) {
2218 jgs 506 assert(sampleData[i]==i-6);
2219 jgs 508 } else if ((i>=12) && (i<15)) {
2220 jgs 506 assert(sampleData[i]==i-8);
2221 jgs 508 } else if ((i>=15) && (i<18)) {
2222 jgs 506 assert(sampleData[i]==i-10);
2223 jgs 508 } else {
2224 jgs 506 assert(sampleData[i]==i-12);
2225     }
2226     }
2227    
2228 jgs 501 }
2229    
2230     }
2231    
2232 jgs 502 void DataTaggedTestCase::testSetTaggedValue() {
2233    
2234     cout << endl;
2235    
2236     {
2237    
2238     cout << "\tTest setting key in DataTagged with three tags." << endl;
2239    
2240     DataTagged::TagListType keys;
2241     keys.push_back(1);
2242     keys.push_back(2);
2243     keys.push_back(3);
2244    
2245     DataTagged::ValueListType values;
2246    
2247     DataArrayView::ShapeType viewShape;
2248     viewShape.push_back(3);
2249    
2250     // default value
2251     DataArrayView::ValueType viewData(3);
2252     for (int i=0;i<viewShape[0];i++) {
2253     viewData[i]=i;
2254     }
2255     DataArrayView myView(viewData,viewShape);
2256    
2257     // value for tag "1"
2258     DataArray eOne(myView);
2259     for (int i=0;i<eOne.getView().getShape()[0];i++) {
2260     eOne.getView()(i)=i+1.0;
2261     }
2262     values.push_back(eOne.getView());
2263    
2264     // value for tag "2"
2265     DataArray eTwo(myView);
2266     for (int i=0;i<eTwo.getView().getShape()[0];i++) {
2267     eTwo.getView()(i)=i+2.0;
2268     }
2269     values.push_back(eTwo.getView());
2270    
2271     // value for tag "3"
2272     DataArray eThree(myView);
2273     for (int i=0;i<eThree.getView().getShape()[0];i++) {
2274     eThree.getView()(i)=i+3.0;
2275     }
2276     values.push_back(eThree.getView());
2277    
2278     DataTagged myData(keys,values,myView,FunctionSpace());
2279    
2280     // new value for tag "2"
2281     for (int i=0;i<eTwo.getView().getShape()[0];i++) {
2282     eTwo.getView()(i)=i+5.0;
2283     }
2284    
2285     myData.setTaggedValue(2,eTwo.getView());
2286    
2287     assert(myData.isCurrentTag(2));
2288    
2289     assert(myData.getTagLookup().size()==3);
2290    
2291     assert(myData.getLength()==12);
2292    
2293     DataArrayView myDataView = myData.getDataPointByTag(2);
2294     assert(myDataView==eTwo.getView());
2295     assert(!myDataView.isEmpty());
2296     assert(myDataView.getOffset()==6);
2297     assert(myDataView.getRank()==1);
2298     assert(myDataView.noValues()==3);
2299     assert(myDataView.getShape().size()==1);
2300     assert(myDataView(0)==5);
2301     assert(myDataView(1)==