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

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

Parent Directory Parent Directory | Revision Log Revision Log


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