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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

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

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

Added FunctionSpace::getListOfTagsSTL.

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

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

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


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