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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3259 - (hide annotations)
Mon Oct 11 01:48:14 2010 UTC (9 years, 3 months ago) by jfenwick
File size: 147396 byte(s)
Merging dudley and scons updates from branches

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