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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4286 - (show annotations)
Thu Mar 7 04:28:11 2013 UTC (6 years, 5 months ago) by caltinay
File size: 157167 byte(s)
Assorted spelling fixes.

1
2 /*****************************************************************************
3 *
4 * Copyright (c) 2003-2013 by University of Queensland
5 * http://www.uq.edu.au
6 *
7 * Primary Business: Queensland, Australia
8 * Licensed under the Open Software License version 3.0
9 * http://www.opensource.org/licenses/osl-3.0.php
10 *
11 * Development until 2012 by Earth Systems Science Computational Center (ESSCC)
12 * Development since 2012 by School of Earth Sciences
13 *
14 *****************************************************************************/
15
16
17 #include "DataTaggedTestCase.h"
18
19 #include "esysUtils/EsysException.h"
20
21 #include "escript/BinaryOp.h"
22 #include "escript/DataConstant.h"
23 #include "escript/DataFactory.h"
24 #include "escript/DataTagged.h"
25 #include "escript/DataTypes.h"
26 #include "escript/DataVector.h"
27 #include "escript/FunctionSpace.h"
28 #include "escript/FunctionSpaceFactory.h"
29 #include "escript/UnaryOp.h"
30
31 #include <cppunit/TestCaller.h>
32 #include <iostream>
33 #include <functional>
34 #include <algorithm>
35
36
37 using namespace CppUnit;
38 using namespace escript;
39 using namespace esysUtils;
40 using namespace std;
41 using namespace escript::DataTypes;
42
43 // 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 namespace {
78
79 ValueType::const_reference
80 getRefRO(DataTagged& data,int offset, int i, int j, int k)
81 {
82 return data.getVectorRO()[offset+getRelIndex(data.getShape(),i,j,k)];
83 }
84
85 ValueType::const_reference
86 getRefRO(DataTagged& data,int offset, int i, int j, int k, int l)
87 {
88 return data.getVectorRO()[offset+getRelIndex(data.getShape(),i,j,k,l)];
89 }
90
91 ValueType::const_reference
92 getRefRO(DataTagged& data,int offset, int i, int j)
93 {
94 return data.getVectorRO()[offset+getRelIndex(data.getShape(),i,j)];
95 }
96
97 ValueType::const_reference
98 getRefRO(const DataTagged& data,int offset, int i)
99 {
100 return data.getVectorRO()[offset+getRelIndex(data.getShape(),i)];
101 }
102
103 }
104
105 void DataTaggedTestCase::testOperations() {
106
107 cout << endl;
108
109 {
110 cout << "\tTest binaryOp addition of two default DataTagged objects." << endl;
111
112 DataTagged myData;
113 DataTagged right;
114
115 binaryOp(myData,right,plus<double>());
116
117 //cout << myData.toString() << endl;
118
119 CPPUNIT_ASSERT(myData.getNumSamples()==1);
120 CPPUNIT_ASSERT(myData.getNumDPPSample()==1);
121
122 CPPUNIT_ASSERT(myData.validSamplePointNo(0));
123 CPPUNIT_ASSERT(myData.validSampleNo(0));
124 CPPUNIT_ASSERT(!myData.validSamplePointNo(1));
125 CPPUNIT_ASSERT(!myData.validSampleNo(1));
126
127 // data-point 0 has tag number 1 by default
128 CPPUNIT_ASSERT(myData.getTagNumber(0)==1);
129
130 CPPUNIT_ASSERT(!myData.isCurrentTag(1));
131
132 CPPUNIT_ASSERT(myData.getTagLookup().size()==0);
133
134 CPPUNIT_ASSERT(myData.getLength()==1);
135
136 CPPUNIT_ASSERT(myData.getPointOffset(0,0)==0);
137
138 // DataArrayView myDataView = myData.getDataPoint(0,0);
139 // CPPUNIT_ASSERT(!myDataView.isEmpty());
140 CPPUNIT_ASSERT(myData.getPointOffset(0,0)==0);
141 CPPUNIT_ASSERT(myData.getRank()==0);
142 CPPUNIT_ASSERT(myData.getNoValues()==1);
143 CPPUNIT_ASSERT(myData.getShape().size()==0);
144 CPPUNIT_ASSERT(myData.getDataAtOffsetRW(0)==0.0);
145
146 // Test non-existent tag returns the default value.
147 // myDataView = myData.getDataPointByTag(1);
148 // CPPUNIT_ASSERT(!myDataView.isEmpty());
149 CPPUNIT_ASSERT(myData.getOffsetForTag(1)==0);
150 CPPUNIT_ASSERT(myData.getRank()==0);
151 CPPUNIT_ASSERT(myData.getNoValues()==1);
152 CPPUNIT_ASSERT(myData.getShape().size()==0);
153 CPPUNIT_ASSERT(myData.getDataAtOffsetRW(0)==0.0);
154
155 // myDataView = myData.getDefaultValue();
156 // CPPUNIT_ASSERT(!myDataView.isEmpty());
157 CPPUNIT_ASSERT(myData.getDefaultOffset()==0);
158 // CPPUNIT_ASSERT(myDataView.getRank()==0); // there is no point in testing this again
159 // CPPUNIT_ASSERT(myDataView.noValues()==1); // since we are not building DataArrayViews
160 // CPPUNIT_ASSERT(myDataView.getShape().size()==0);
161 // CPPUNIT_ASSERT(myDataView()==0.0);
162
163 // use a non-existent tag so we get a pointer to
164 // the first element of the data array
165 double* sampleData=myData.getSampleDataByTag(9);
166 for (int i=0; i<myData.getLength(); i++) {
167 CPPUNIT_ASSERT(sampleData[i]==i);
168 }
169
170 }
171
172 {
173 cout << "\tTest binaryOp addition of two DataTagged objects with default values only." << endl;
174
175 DataTypes::ShapeType viewShape;
176 viewShape.push_back(3);
177
178 // DataTagged::TagListType keys;
179 //
180 // DataTagged::ValueListType values;
181
182 DataTypes::ValueType viewData(3);
183 for (int i=0;i<viewShape[0];i++) {
184 viewData[i]=i;
185 }
186
187 // DataTagged myData(keys,values,myView,FunctionSpace());
188 // DataTagged right(keys,values,myView,FunctionSpace());
189 DataTagged myData(FunctionSpace(),viewShape,viewData);
190 DataTagged right(FunctionSpace(),viewShape,viewData);
191
192
193 binaryOp(myData,right,plus<double>());
194
195 //cout << myData.toString() << endl;
196
197 CPPUNIT_ASSERT(myData.getNumSamples()==1);
198 CPPUNIT_ASSERT(myData.getNumDPPSample()==1);
199
200 CPPUNIT_ASSERT(myData.validSamplePointNo(0));
201 CPPUNIT_ASSERT(myData.validSampleNo(0));
202 CPPUNIT_ASSERT(!myData.validSamplePointNo(1));
203 CPPUNIT_ASSERT(!myData.validSampleNo(1));
204
205 // data-point 0 has tag number 1 by default
206 CPPUNIT_ASSERT(myData.getTagNumber(0)==1);
207
208 CPPUNIT_ASSERT(!myData.isCurrentTag(1));
209
210 CPPUNIT_ASSERT(myData.getTagLookup().size()==0);
211
212 CPPUNIT_ASSERT(myData.getLength()==3);
213
214 CPPUNIT_ASSERT(myData.getPointOffset(0,0)==0);
215
216 CPPUNIT_ASSERT(myData.getRank()==1);
217 CPPUNIT_ASSERT(myData.getNoValues()==3);
218 CPPUNIT_ASSERT(myData.getShape().size()==1);
219
220
221 int offset=myData.getDefaultOffset();
222 // DataArrayView myDataView = myData.getDefaultValue();
223 CPPUNIT_ASSERT(offset==0);
224 CPPUNIT_ASSERT(getRefRO(myData,offset,0)==0);
225 CPPUNIT_ASSERT(getRefRO(myData,offset,1)==2);
226 CPPUNIT_ASSERT(getRefRO(myData,offset,2)==4);
227
228 // use a non-existent tag so we get a pointer to
229 // the first element of the data array
230 double* sampleData=myData.getSampleDataByTag(9);
231 for (int i=0; i<myData.getLength(); i++) {
232 CPPUNIT_ASSERT(sampleData[i]==i*2);
233 }
234
235 }
236
237 {
238 cout << "\tTest binaryOp addition of two DataTagged objects with one identical tag each." << endl;
239
240 DataTagged myData;
241 DataTagged right;
242
243 DataVector vOneData(1, 1.0 ,1);
244 // create a view with an empty shape, a scalar.
245 // DataArrayView vOneView(vOneData,DataTypes::ShapeType());
246
247 myData.addTaggedValue(1,DataTypes::scalarShape,vOneData);
248 right.addTaggedValue(1,DataTypes::scalarShape,vOneData);
249
250 binaryOp(myData,right,plus<double>());
251
252 CPPUNIT_ASSERT(myData.getNumSamples()==1);
253 CPPUNIT_ASSERT(myData.getNumDPPSample()==1);
254
255 CPPUNIT_ASSERT(myData.validSamplePointNo(0));
256 CPPUNIT_ASSERT(myData.validSampleNo(0));
257 CPPUNIT_ASSERT(!myData.validSamplePointNo(1));
258 CPPUNIT_ASSERT(!myData.validSampleNo(1));
259
260 // data-point 0 has tag number 1 by default
261 CPPUNIT_ASSERT(myData.getTagNumber(0)==1);
262
263 CPPUNIT_ASSERT(myData.isCurrentTag(1));
264
265 CPPUNIT_ASSERT(myData.getTagLookup().size()==1);
266
267 CPPUNIT_ASSERT(myData.getLength()==2);
268
269 CPPUNIT_ASSERT(myData.getPointOffset(0,0)==1);
270
271
272 CPPUNIT_ASSERT(myData.getRank()==0);
273 CPPUNIT_ASSERT(myData.getNoValues()==1);
274 CPPUNIT_ASSERT(myData.getShape().size()==0);
275
276
277
278 // check result value for tag "1"
279 // DataArrayView myDataView = myData.getDataPointByTag(1);
280 int offset=myData.getOffsetForTag(1);
281 CPPUNIT_ASSERT(offset==1);
282 CPPUNIT_ASSERT(myData.getVectorRO()[offset]==2.0);
283
284 // check result for default value
285 // myDataView = myData.getDefaultValue();
286 offset=myData.getDefaultOffset();
287 CPPUNIT_ASSERT(offset==0);
288 CPPUNIT_ASSERT(myData.getVectorRO()[offset]==0.0);
289
290 // use a non-existent tag so we get a pointer to
291 // the first element of the data array
292 double* sampleData=myData.getSampleDataByTag(9);
293 for (int i=0; i<myData.getLength(); i++) {
294 CPPUNIT_ASSERT(sampleData[i]==i*2);
295 }
296
297 }
298
299 {
300 cout << "\tTest binaryOp addition of two DataTagged objects with one different tag each." << endl;
301
302 DataTagged myData;
303 DataTagged right;
304
305 // it's important that default values are different, as we need to be able to
306 // verify that the tag values in each object are being added to the correct
307 // default values - since the tag lists don't match, the default values will
308 // be used for missing tags in each object
309 // myData.getDefaultValue()()=1.0;
310 // right.getDefaultValue()()=2.0;
311 myData.getVectorRW()[myData.getDefaultOffset()]=1.0;
312 right.getVectorRW()[right.getDefaultOffset()]=2.0;
313
314 DataVector vOneData(1, 3.0 ,1);
315 // create a view with an empty shape, a scalar.
316 // DataArrayView vOneView(vOneData,DataTypes::ShapeType());
317
318 DataVector vTwoData(1, 4.0 ,1);
319 // create a view with an empty shape, a scalar.
320 // DataArrayView vTwoView(vTwoData,DataTypes::ShapeType());
321
322 myData.addTaggedValue(1,DataTypes::scalarShape,vOneData);
323 right.addTaggedValue(2,DataTypes::scalarShape,vTwoData);
324
325 //cout << myData.toString() << endl;
326 //cout << right.toString() << endl;
327
328 binaryOp(myData,right,plus<double>());
329
330 //cout << myData.toString() << endl;
331
332 CPPUNIT_ASSERT(myData.getNumSamples()==1);
333 CPPUNIT_ASSERT(myData.getNumDPPSample()==1);
334
335 CPPUNIT_ASSERT(myData.validSamplePointNo(0));
336 CPPUNIT_ASSERT(myData.validSampleNo(0));
337 CPPUNIT_ASSERT(!myData.validSamplePointNo(1));
338 CPPUNIT_ASSERT(!myData.validSampleNo(1));
339
340 // data-point 0 has tag number 1 by default
341 CPPUNIT_ASSERT(myData.getTagNumber(0)==1);
342
343 CPPUNIT_ASSERT(myData.isCurrentTag(1));
344 CPPUNIT_ASSERT(myData.isCurrentTag(2));
345
346 CPPUNIT_ASSERT(myData.getTagLookup().size()==2);
347
348 CPPUNIT_ASSERT(myData.getLength()==3);
349
350 CPPUNIT_ASSERT(myData.getPointOffset(0,0)==1);
351
352 CPPUNIT_ASSERT(myData.getRank()==0);
353 CPPUNIT_ASSERT(myData.getNoValues()==1);
354 CPPUNIT_ASSERT(myData.getShape().size()==0);
355
356
357 // check result value for tag "1"
358 // DataArrayView myDataView = myData.getDataPointByTag(1);
359 int offset=myData.getOffsetForTag(1);
360 CPPUNIT_ASSERT(offset==1);
361 CPPUNIT_ASSERT(myData.getDataAtOffsetRO(offset)==5.0);
362
363 // check result value for tag "2"
364 // myDataView = myData.getDataPointByTag(2);
365 offset=myData.getOffsetForTag(2);
366 CPPUNIT_ASSERT(offset==2);
367 CPPUNIT_ASSERT(myData.getDataAtOffsetRO(offset)==5.0);
368
369 // check result for default value
370 // myDataView = myData.getDefaultValue();
371 offset=myData.getDefaultOffset();
372 CPPUNIT_ASSERT(offset==0);
373 CPPUNIT_ASSERT(myData.getDataAtOffsetRO(offset)==3.0);
374
375 // use a non-existent tag so we get a pointer to
376 // the first element of the data array
377 double* sampleData=myData.getSampleDataByTag(9);
378 CPPUNIT_ASSERT(sampleData[0]==3);
379 CPPUNIT_ASSERT(sampleData[1]==5);
380 CPPUNIT_ASSERT(sampleData[2]==5);
381
382 }
383
384 {
385 cout << "\tTest binaryOp addition of two DataTagged objects with overlapping tag sets." << endl;
386
387 DataTagged myData;
388 DataTagged right;
389
390 // it's important that default values are different, as we need to be able to
391 // verify that the tag values in each object are being added to the correct
392 // default values - since the tag lists don't match, the default values will
393 // be used for missing tags in each object
394 /* myData.getDefaultValue()()=2.0;
395 right.getDefaultValue()()=3.0;*/
396 myData.getVectorRW()[myData.getDefaultOffset()]=2.0;
397 right.getVectorRW()[right.getDefaultOffset()]=3.0;
398
399
400 DataVector vOneData(1, 1.0 ,1);
401 // create a view with an empty shape, a scalar.
402 // DataArrayView vOneView(vOneData,DataTypes::ShapeType());
403
404 myData.addTaggedValue(1,DataTypes::scalarShape,vOneData);
405 myData.addTaggedValue(2,DataTypes::scalarShape,vOneData);
406 right.addTaggedValue(2,DataTypes::scalarShape,vOneData);
407 right.addTaggedValue(3,DataTypes::scalarShape,vOneData);
408
409 //cout << myData.toString() << endl;
410 //cout << right.toString() << endl;
411
412 binaryOp(myData,right,plus<double>());
413
414 //cout << myData.toString() << endl;
415
416 CPPUNIT_ASSERT(myData.getNumSamples()==1);
417 CPPUNIT_ASSERT(myData.getNumDPPSample()==1);
418
419 CPPUNIT_ASSERT(myData.validSamplePointNo(0));
420 CPPUNIT_ASSERT(myData.validSampleNo(0));
421 CPPUNIT_ASSERT(!myData.validSamplePointNo(1));
422 CPPUNIT_ASSERT(!myData.validSampleNo(1));
423
424 // data-point 0 has tag number 1 by default
425 CPPUNIT_ASSERT(myData.getTagNumber(0)==1);
426
427 CPPUNIT_ASSERT(myData.isCurrentTag(1));
428 CPPUNIT_ASSERT(myData.isCurrentTag(2));
429 CPPUNIT_ASSERT(myData.isCurrentTag(3));
430
431 CPPUNIT_ASSERT(myData.getTagLookup().size()==3);
432
433 CPPUNIT_ASSERT(myData.getLength()==4);
434
435 CPPUNIT_ASSERT(myData.getPointOffset(0,0)==1);
436
437 CPPUNIT_ASSERT(myData.getRank()==0);
438 CPPUNIT_ASSERT(myData.getNoValues()==1);
439 CPPUNIT_ASSERT(myData.getShape().size()==0);
440
441
442 // check result value for tag "1"
443 // DataArrayView myDataView = myData.getDataPointByTag(1);
444 int offset=myData.getOffsetForTag(1);
445 CPPUNIT_ASSERT(offset==1);
446 CPPUNIT_ASSERT(myData.getDataAtOffsetRO(offset)==4.0);
447
448 // check result value for tag "2"
449 // myDataView = myData.getDataPointByTag(2);
450 offset=myData.getOffsetForTag(2);
451 CPPUNIT_ASSERT(offset==2);
452 CPPUNIT_ASSERT(myData.getDataAtOffsetRO(offset)==2.0);
453
454 // check result value for tag "3"
455 // myDataView = myData.getDataPointByTag(3);
456 offset=myData.getOffsetForTag(3);
457 CPPUNIT_ASSERT(offset==3);
458 CPPUNIT_ASSERT(myData.getDataAtOffsetRO(offset)==3.0);
459
460 // check result for default value
461 // myDataView = myData.getDefaultValue();
462 offset=myData.getDefaultOffset();
463 CPPUNIT_ASSERT(offset==0);
464 CPPUNIT_ASSERT(myData.getDataAtOffsetRO(offset)==5.0);
465
466 // use a non-existent tag so we get a pointer to
467 // the first element of the data array
468 double* sampleData=myData.getSampleDataByTag(9);
469 CPPUNIT_ASSERT(sampleData[0]==5);
470 CPPUNIT_ASSERT(sampleData[1]==4);
471 CPPUNIT_ASSERT(sampleData[2]==2);
472 CPPUNIT_ASSERT(sampleData[3]==3);
473
474 }
475
476 {
477 cout << "\tTest binaryOp multiplication of two DataTagged objects with default values only." << endl;
478
479 DataTypes::ShapeType viewShape;
480 viewShape.push_back(3);
481
482 // DataTagged::TagListType keys;
483
484 // DataTagged::ValueListType values;
485
486 DataTypes::ValueType viewData(3);
487 for (int i=0;i<viewShape[0];i++) {
488 viewData[i]=i;
489 }
490 // DataArrayView myView(viewData,viewShape);
491
492 DataTagged myData(FunctionSpace(),viewShape,viewData);
493 DataTagged right(FunctionSpace(),viewShape,viewData);
494
495 binaryOp(myData,right,multiplies<double>());
496
497 //cout << myData.toString() << endl;
498
499 CPPUNIT_ASSERT(myData.getNumSamples()==1);
500 CPPUNIT_ASSERT(myData.getNumDPPSample()==1);
501
502 CPPUNIT_ASSERT(myData.validSamplePointNo(0));
503 CPPUNIT_ASSERT(myData.validSampleNo(0));
504 CPPUNIT_ASSERT(!myData.validSamplePointNo(1));
505 CPPUNIT_ASSERT(!myData.validSampleNo(1));
506
507 // data-point 0 has tag number 1 by default
508 CPPUNIT_ASSERT(myData.getTagNumber(0)==1);
509
510 CPPUNIT_ASSERT(!myData.isCurrentTag(1));
511
512 CPPUNIT_ASSERT(myData.getTagLookup().size()==0);
513
514 CPPUNIT_ASSERT(myData.getLength()==3);
515
516 CPPUNIT_ASSERT(myData.getPointOffset(0,0)==0);
517
518 CPPUNIT_ASSERT(myData.getRank()==1);
519 CPPUNIT_ASSERT(myData.getNoValues()==3);
520 CPPUNIT_ASSERT(myData.getShape().size()==1);
521
522
523 // DataArrayView myDataView = myData.getDefaultValue();
524 int offset=myData.getDefaultOffset();
525 CPPUNIT_ASSERT(offset==0);
526 CPPUNIT_ASSERT(getRefRO(myData,offset,0)==0);
527 CPPUNIT_ASSERT(getRefRO(myData,offset,1)==1);
528 CPPUNIT_ASSERT(getRefRO(myData,offset,2)==4);
529
530 // use a non-existent tag so we get a pointer to
531 // the first element of the data array
532 double* sampleData=myData.getSampleDataByTag(9);
533 for (int i=0; i<myData.getLength(); i++) {
534 CPPUNIT_ASSERT(sampleData[i]==i*i);
535 }
536
537 }
538
539 {
540
541 cout << "\tTest binaryOp multiplication of DataTagged object with a scalar." << endl;
542
543 DataTagged myData;
544
545 DataVector vOneData(1, 1.0 ,1);
546 // create a view with an empty shape, a scalar.
547 // DataArrayView vOneView(vOneData,DataTypes::ShapeType());
548
549 DataVector vTwoData(1, 2.0 ,1);
550 // create a view with an empty shape, a scalar.
551 // DataArrayView vTwoView(vTwoData,DataTypes::ShapeType());
552
553 myData.addTaggedValue(1,DataTypes::scalarShape,vOneData);
554 myData.addTaggedValue(2,DataTypes::scalarShape,vTwoData);
555
556 DataVector vThreeData(1, 3.0 ,1);
557 // create a view with an empty shape, a scalar.
558 // DataArrayView vThreeView(vThreeData,DataTypes::ShapeType());
559
560 // DataArrayView right=vThreeView;
561
562 //cout << myData.toString() << endl;
563 //cout << right.toString() << endl;
564
565 binaryOp(myData,vThreeData, DataTypes::scalarShape,multiplies<double>());
566
567 //cout << myData.toString() << endl;
568
569 CPPUNIT_ASSERT(myData.getNumSamples()==1);
570 CPPUNIT_ASSERT(myData.getNumDPPSample()==1);
571
572 CPPUNIT_ASSERT(myData.validSamplePointNo(0));
573 CPPUNIT_ASSERT(myData.validSampleNo(0));
574 CPPUNIT_ASSERT(!myData.validSamplePointNo(1));
575 CPPUNIT_ASSERT(!myData.validSampleNo(1));
576
577 // data-point 0 has tag number 1 by default
578 CPPUNIT_ASSERT(myData.getTagNumber(0)==1);
579
580 CPPUNIT_ASSERT(myData.isCurrentTag(1));
581 CPPUNIT_ASSERT(myData.isCurrentTag(2));
582
583 CPPUNIT_ASSERT(myData.getTagLookup().size()==2);
584
585 CPPUNIT_ASSERT(myData.getLength()==3);
586
587 CPPUNIT_ASSERT(myData.getPointOffset(0,0)==1);
588
589 CPPUNIT_ASSERT(myData.getRank()==0);
590 CPPUNIT_ASSERT(myData.getNoValues()==1);
591 CPPUNIT_ASSERT(myData.getShape().size()==0);
592
593 // check result value for tag "1"
594 // DataArrayView myDataView = myData.getDataPointByTag(1);
595 int offset=myData.getOffsetForTag(1);
596 CPPUNIT_ASSERT(offset==1);
597 CPPUNIT_ASSERT(myData.getDataAtOffsetRO(offset)==3.0);
598
599 // check result value for tag "2"
600 // myDataView = myData.getDataPointByTag(2);
601 offset=myData.getOffsetForTag(2);
602 CPPUNIT_ASSERT(offset==2);
603 CPPUNIT_ASSERT(myData.getDataAtOffsetRO(offset)==6.0);
604
605 // check result for default value
606 // myDataView = myData.getDefaultValue();
607 offset=myData.getDefaultOffset();
608 CPPUNIT_ASSERT(offset==0);
609 CPPUNIT_ASSERT(myData.getDataAtOffsetRO(offset)==0.0);
610
611 // use a non-existent tag so we get a pointer to
612 // the first element of the data array
613 double* sampleData=myData.getSampleDataByTag(9);
614 CPPUNIT_ASSERT(sampleData[0]==0);
615 CPPUNIT_ASSERT(sampleData[1]==3);
616 CPPUNIT_ASSERT(sampleData[2]==6);
617
618 }
619
620 {
621 cout << "\tTest binaryOp multiplication of two DataTagged objects with overlapping tag sets." << endl;
622
623 DataTagged myData;
624 DataTagged right;
625
626 // it's important that default values are different, as we need to be able to
627 // verify that the tag values in each object are being added to the correct
628 // default values - since the tag lists don't match, the default values will
629 // be used for missing tags in each object
630 // myData.getDefaultValue()()=2.0;
631 // right.getDefaultValue()()=3.0;
632 myData.getVectorRW()[myData.getDefaultOffset()]=2.0;
633 right.getVectorRW()[right.getDefaultOffset()]=3.0;
634
635 DataVector vOneData(1, 1.0 ,1);
636 // create a view with an empty shape, a scalar.
637 // DataArrayView vOneView(vOneData,DataTypes::ShapeType());
638
639 DataVector vTwoData(1, 2.0 ,1);
640 // create a view with an empty shape, a scalar.
641 // DataArrayView vTwoView(vTwoData,DataTypes::ShapeType());
642
643 myData.addTaggedValue(1,DataTypes::scalarShape,vOneData);
644 myData.addTaggedValue(2,DataTypes::scalarShape,vOneData);
645 right.addTaggedValue(2,DataTypes::scalarShape,vTwoData);
646 right.addTaggedValue(3,DataTypes::scalarShape,vTwoData);
647
648 //cout << myData.toString() << endl;
649 //cout << right.toString() << endl;
650
651 binaryOp(myData,right,multiplies<double>());
652
653 //cout << myData.toString() << endl;
654
655 CPPUNIT_ASSERT(myData.getNumSamples()==1);
656 CPPUNIT_ASSERT(myData.getNumDPPSample()==1);
657
658 CPPUNIT_ASSERT(myData.validSamplePointNo(0));
659 CPPUNIT_ASSERT(myData.validSampleNo(0));
660 CPPUNIT_ASSERT(!myData.validSamplePointNo(1));
661 CPPUNIT_ASSERT(!myData.validSampleNo(1));
662
663 // data-point 0 has tag number 1 by default
664 CPPUNIT_ASSERT(myData.getTagNumber(0)==1);
665
666 CPPUNIT_ASSERT(myData.isCurrentTag(1));
667 CPPUNIT_ASSERT(myData.isCurrentTag(2));
668 CPPUNIT_ASSERT(myData.isCurrentTag(3));
669
670 CPPUNIT_ASSERT(myData.getTagLookup().size()==3);
671
672 CPPUNIT_ASSERT(myData.getLength()==4);
673
674 CPPUNIT_ASSERT(myData.getPointOffset(0,0)==1);
675
676 CPPUNIT_ASSERT(myData.getRank()==0);
677 CPPUNIT_ASSERT(myData.getNoValues()==1);
678 CPPUNIT_ASSERT(myData.getShape().size()==0);
679
680
681 // check result value for tag "1"
682 // DataArrayView myDataView = myData.getDataPointByTag(1);
683 int offset=myData.getOffsetForTag(1);
684 CPPUNIT_ASSERT(offset==1);
685 CPPUNIT_ASSERT(myData.getDataAtOffsetRO(offset)==3.0);
686
687 // check result value for tag "2"
688 // myDataView = myData.getDataPointByTag(2);
689 offset=myData.getOffsetForTag(2);
690 CPPUNIT_ASSERT(offset==2);
691 CPPUNIT_ASSERT(myData.getDataAtOffsetRO(offset)==2.0);
692
693 // check result value for tag "3"
694 // myDataView = myData.getDataPointByTag(3);
695 offset=myData.getOffsetForTag(3);
696 CPPUNIT_ASSERT(offset==3);
697 CPPUNIT_ASSERT(myData.getDataAtOffsetRO(offset)==4.0);
698
699 // check result for default value
700 // myDataView = myData.getDefaultValue();
701 offset=myData.getDefaultOffset();
702 CPPUNIT_ASSERT(offset==0);
703 CPPUNIT_ASSERT(myData.getDataAtOffsetRO(offset)==6.0);
704
705 // use a non-existent tag so we get a pointer to
706 // the first element of the data array
707 double* sampleData=myData.getSampleDataByTag(9);
708 CPPUNIT_ASSERT(sampleData[0]==6);
709 CPPUNIT_ASSERT(sampleData[1]==3);
710 CPPUNIT_ASSERT(sampleData[2]==2);
711 CPPUNIT_ASSERT(sampleData[3]==4);
712
713 }
714
715 {
716 cout << "\tTest unaryOp negate on default DataTagged object." << endl;
717
718 DataTagged myData;
719
720 unaryOp(myData,negate<double>());
721
722 //cout << myData.toString() << endl;
723
724 CPPUNIT_ASSERT(myData.getNumSamples()==1);
725 CPPUNIT_ASSERT(myData.getNumDPPSample()==1);
726
727 CPPUNIT_ASSERT(myData.validSamplePointNo(0));
728 CPPUNIT_ASSERT(myData.validSampleNo(0));
729 CPPUNIT_ASSERT(!myData.validSamplePointNo(1));
730 CPPUNIT_ASSERT(!myData.validSampleNo(1));
731
732 // data-point 0 has tag number 1 by default
733 CPPUNIT_ASSERT(myData.getTagNumber(0)==1);
734
735 CPPUNIT_ASSERT(!myData.isCurrentTag(1));
736
737 CPPUNIT_ASSERT(myData.getTagLookup().size()==0);
738
739 CPPUNIT_ASSERT(myData.getLength()==1);
740
741 CPPUNIT_ASSERT(myData.getPointOffset(0,0)==0);
742
743 CPPUNIT_ASSERT(myData.getRank()==0);
744 CPPUNIT_ASSERT(myData.getNoValues()==1);
745 CPPUNIT_ASSERT(myData.getShape().size()==0);
746
747
748 // DataArrayView myDataView = myData.getDataPoint(0,0);
749 int offset=myData.getPointOffset(0,0);
750 CPPUNIT_ASSERT(offset==0);
751 CPPUNIT_ASSERT(myData.getDataAtOffsetRO(offset)==0.0);
752
753 // Test non-existent tag returns the default value.
754 // myDataView = myData.getDataPointByTag(1);
755 offset=myData.getOffsetForTag(1);
756 CPPUNIT_ASSERT(offset==0);
757 CPPUNIT_ASSERT(myData.getDataAtOffsetRO(offset)==0.0);
758
759 // myDataView = myData.getDefaultValue();
760 offset=myData.getDefaultOffset();
761 CPPUNIT_ASSERT(offset==0);
762 CPPUNIT_ASSERT(myData.getDataAtOffsetRO(offset)==0.0);
763
764 // use a non-existent tag so we get a pointer to
765 // the first element of the data array
766 double* sampleData=myData.getSampleDataByTag(9);
767 for (int i=0; i<myData.getLength(); i++) {
768 CPPUNIT_ASSERT(sampleData[i]==i);
769 }
770
771 }
772
773 {
774 cout << "\tTest unaryOp negate on DataTagged object with default value only." << endl;
775
776 DataTypes::ShapeType viewShape;
777 viewShape.push_back(3);
778
779 // DataTagged::TagListType keys;
780
781 // DataTagged::ValueListType values;
782
783 DataTypes::ValueType viewData(3);
784 for (int i=0;i<viewShape[0];i++) {
785 viewData[i]=i;
786 }
787 // DataArrayView myView(viewData,viewShape);
788
789 DataTagged myData(FunctionSpace(),viewShape,viewData);
790
791 unaryOp(myData,negate<double>());
792
793 //cout << myData.toString() << endl;
794
795 CPPUNIT_ASSERT(myData.getNumSamples()==1);
796 CPPUNIT_ASSERT(myData.getNumDPPSample()==1);
797
798 CPPUNIT_ASSERT(myData.validSamplePointNo(0));
799 CPPUNIT_ASSERT(myData.validSampleNo(0));
800 CPPUNIT_ASSERT(!myData.validSamplePointNo(1));
801 CPPUNIT_ASSERT(!myData.validSampleNo(1));
802
803 // data-point 0 has tag number 1 by default
804 CPPUNIT_ASSERT(myData.getTagNumber(0)==1);
805
806 CPPUNIT_ASSERT(!myData.isCurrentTag(1));
807
808 CPPUNIT_ASSERT(myData.getTagLookup().size()==0);
809
810 CPPUNIT_ASSERT(myData.getLength()==3);
811
812 CPPUNIT_ASSERT(myData.getPointOffset(0,0)==0);
813
814 CPPUNIT_ASSERT(myData.getRank()==1);
815 CPPUNIT_ASSERT(myData.getNoValues()==3);
816 CPPUNIT_ASSERT(myData.getShape().size()==1);
817
818
819 int offset=myData.getDefaultOffset();
820 // DataArrayView myDataView = myData.getDefaultValue();
821 CPPUNIT_ASSERT(offset==0);
822 CPPUNIT_ASSERT(getRefRO(myData,offset,0)==0);
823 CPPUNIT_ASSERT(getRefRO(myData,offset,1)==-1);
824 CPPUNIT_ASSERT(getRefRO(myData,offset,2)==-2);
825
826 // use a non-existent tag so we get a pointer to
827 // the first element of the data array
828 double* sampleData=myData.getSampleDataByTag(9);
829 for (int i=0; i<myData.getLength(); i++) {
830 CPPUNIT_ASSERT(sampleData[i]==0-i);
831 }
832
833 }
834
835 {
836 cout << "\tTest unnaryOp negate on DataTagged object with two tags." << endl;
837
838 DataTagged myData;
839
840 DataVector vOneData(1, 1.0 ,1);
841 // create a view with an empty shape, a scalar.
842 // DataArrayView vOneView(vOneData,DataTypes::ShapeType());
843
844 DataVector vTwoData(1, 2.0 ,1);
845 // create a view with an empty shape, a scalar.
846 // DataArrayView vTwoView(vTwoData,DataTypes::ShapeType());
847
848 myData.addTaggedValue(1,DataTypes::scalarShape,vOneData);
849 myData.addTaggedValue(2,DataTypes::scalarShape,vTwoData);
850
851 unaryOp(myData,negate<double>());
852
853 CPPUNIT_ASSERT(myData.getNumSamples()==1);
854 CPPUNIT_ASSERT(myData.getNumDPPSample()==1);
855
856 CPPUNIT_ASSERT(myData.validSamplePointNo(0));
857 CPPUNIT_ASSERT(myData.validSampleNo(0));
858 CPPUNIT_ASSERT(!myData.validSamplePointNo(1));
859 CPPUNIT_ASSERT(!myData.validSampleNo(1));
860
861 // data-point 0 has tag number 1 by default
862 CPPUNIT_ASSERT(myData.getTagNumber(0)==1);
863
864 CPPUNIT_ASSERT(myData.isCurrentTag(1));
865 CPPUNIT_ASSERT(myData.isCurrentTag(2));
866
867 CPPUNIT_ASSERT(myData.getTagLookup().size()==2);
868
869 CPPUNIT_ASSERT(myData.getLength()==3);
870
871 CPPUNIT_ASSERT(myData.getPointOffset(0,0)==1);
872
873 CPPUNIT_ASSERT(myData.getRank()==0);
874 CPPUNIT_ASSERT(myData.getNoValues()==1);
875 CPPUNIT_ASSERT(myData.getShape().size()==0);
876
877
878 // check result value for tag "1"
879 // DataArrayView myDataView = myData.getDataPointByTag(1);
880 int offset=myData.getOffsetForTag(1);
881 CPPUNIT_ASSERT(offset==1);
882 CPPUNIT_ASSERT(myData.getDataAtOffsetRO(offset)==-1.0);
883
884 // check result value for tag "2"
885 // myDataView = myData.getDataPointByTag(2);
886 offset=myData.getOffsetForTag(2);
887 CPPUNIT_ASSERT(offset==2);
888 CPPUNIT_ASSERT(myData.getDataAtOffsetRO(offset)==-2.0);
889
890 // check result for default value
891 // myDataView = myData.getDefaultValue();
892 offset=myData.getDefaultOffset();
893 CPPUNIT_ASSERT(offset==0);
894 CPPUNIT_ASSERT(myData.getDataAtOffsetRO(offset)==0.0);
895
896 // use a non-existent tag so we get a pointer to
897 // the first element of the data array
898 double* sampleData=myData.getSampleDataByTag(9);
899 for (int i=0; i<myData.getLength(); i++) {
900 CPPUNIT_ASSERT(sampleData[i]==0-i);
901 }
902
903 }
904
905 }
906
907 void DataTaggedTestCase::testAddTaggedValues() {
908
909 cout << endl;
910
911 {
912
913 cout << "\tTest adding one key with empty value list to default DataTagged." << endl;
914 DataTagged myData;
915
916 DataTagged::TagListType keys;
917 keys.push_back(1);
918
919 DataTagged::ValueBatchType values;
920
921 myData.addTaggedValues(keys,values,DataTypes::scalarShape);
922
923 CPPUNIT_ASSERT(myData.isCurrentTag(1));
924
925 CPPUNIT_ASSERT(myData.getTagLookup().size()==1);
926
927 CPPUNIT_ASSERT(myData.getLength()==2);
928
929 // data-point 0 has tag number 1 by default
930 CPPUNIT_ASSERT(myData.getTagNumber(0)==1);
931
932 CPPUNIT_ASSERT(myData.getPointOffset(0,0)==1);
933
934 CPPUNIT_ASSERT(myData.getRank()==0);
935 CPPUNIT_ASSERT(myData.getNoValues()==1);
936 CPPUNIT_ASSERT(myData.getShape().size()==0);
937
938
939 // DataArrayView myDataView = myData.getDataPoint(0,0);
940 int offset=myData.getPointOffset(0,0);
941 CPPUNIT_ASSERT(offset==1);
942 CPPUNIT_ASSERT(myData.getDataAtOffsetRO(offset)==0.0);
943
944 // myDataView = myData.getDataPointByTag(1);
945 offset=myData.getOffsetForTag(1);
946 CPPUNIT_ASSERT(offset==1);
947 CPPUNIT_ASSERT(myData.getDataAtOffsetRO(offset)==0.0);
948
949 // myDataView = myData.getDefaultValue();
950 offset=myData.getDefaultOffset();
951 CPPUNIT_ASSERT(offset==0);
952 CPPUNIT_ASSERT(myData.getDataAtOffsetRO(offset)==0.0);
953
954 // use a non-existent tag so we get a pointer to
955 // the first element of the data array
956 double* sampleData=myData.getSampleDataByTag(9);
957 for (int i=0; i<myData.getLength(); i++) {
958 CPPUNIT_ASSERT(sampleData[i]==0);
959 }
960
961 }
962
963 {
964
965 cout << "\tTest adding one key with one value to default DataTagged." << endl;
966 DataTagged myData;
967
968 DataTagged::TagListType keys;
969 keys.push_back(1);
970
971 DataTagged::ValueBatchType values;
972
973 DataTypes::ShapeType viewShape;
974 /* DataTypes::ValueType viewData(1);
975 viewData[0]=1.0;*/
976 // DataArrayView myView(viewData,viewShape);
977 values.push_back(1.0);
978
979 myData.addTaggedValues(keys,values,viewShape);
980
981 CPPUNIT_ASSERT(myData.isCurrentTag(1));
982
983 CPPUNIT_ASSERT(myData.getTagLookup().size()==1);
984
985 CPPUNIT_ASSERT(myData.getLength()==2);
986
987 // data-point 0 has tag number 1 by default
988 CPPUNIT_ASSERT(myData.getTagNumber(0)==1);
989
990 CPPUNIT_ASSERT(myData.getPointOffset(0,0)==1);
991
992 CPPUNIT_ASSERT(myData.getRank()==0);
993 CPPUNIT_ASSERT(myData.getNoValues()==1);
994 CPPUNIT_ASSERT(myData.getShape().size()==0);
995
996
997 // DataArrayView myDataView = myData.getDataPoint(0,0);
998 int offset=myData.getPointOffset(0,0);
999 CPPUNIT_ASSERT(offset==1);
1000 CPPUNIT_ASSERT(myData.getDataAtOffsetRO(offset)==1.0);
1001
1002 // myDataView = myData.getDataPointByTag(1);
1003 offset=myData.getOffsetForTag(1);
1004 CPPUNIT_ASSERT(offset==1);
1005 CPPUNIT_ASSERT(myData.getDataAtOffsetRO(offset)==1.0);
1006
1007 // myDataView = myData.getDefaultValue();
1008 offset=myData.getDefaultOffset();
1009 CPPUNIT_ASSERT(offset==0);
1010 CPPUNIT_ASSERT(myData.getDataAtOffsetRO(offset)==0.0);
1011
1012 // use a non-existent tag so we get a pointer to
1013 // the first element of the data array
1014 double* sampleData=myData.getSampleDataByTag(9);
1015 for (int i=0; i<myData.getLength(); i++) {
1016 CPPUNIT_ASSERT(sampleData[i]==i);
1017 }
1018
1019 }
1020
1021 {
1022
1023 cout << "\tTest adding three keys with one value to default DataTagged." << endl;
1024 DataTagged myData;
1025
1026 DataTagged::TagListType keys;
1027 keys.push_back(1);
1028 keys.push_back(2);
1029 keys.push_back(3);
1030
1031 DataTagged::ValueBatchType values;
1032
1033 DataTypes::ShapeType viewShape;
1034 /* DataTypes::ValueType viewData(1);
1035 viewData[0]=1.0;
1036 DataArrayView myView(viewData,viewShape);*/
1037 values.push_back(1.0);
1038
1039 myData.addTaggedValues(keys,values,viewShape);
1040
1041 CPPUNIT_ASSERT(myData.isCurrentTag(1));
1042 CPPUNIT_ASSERT(myData.isCurrentTag(2));
1043 CPPUNIT_ASSERT(myData.isCurrentTag(3));
1044
1045 CPPUNIT_ASSERT(myData.getTagLookup().size()==3);
1046
1047 CPPUNIT_ASSERT(myData.getLength()==4);
1048
1049 // data-point 0 has tag number 1 by default
1050 CPPUNIT_ASSERT(myData.getTagNumber(0)==1);
1051
1052 CPPUNIT_ASSERT(myData.getPointOffset(0,0)==1);
1053
1054 CPPUNIT_ASSERT(myData.getRank()==0);
1055 CPPUNIT_ASSERT(myData.getNoValues()==1);
1056 CPPUNIT_ASSERT(myData.getShape().size()==0);
1057
1058
1059 // DataArrayView myDataView = myData.getDataPoint(0,0);
1060 int offset=myData.getPointOffset(0,0);
1061 CPPUNIT_ASSERT(offset==1);
1062 CPPUNIT_ASSERT(myData.getDataAtOffsetRO(offset)==1.0);
1063
1064 // myDataView = myData.getDataPointByTag(1);
1065 offset=myData.getOffsetForTag(1);
1066 CPPUNIT_ASSERT(offset==1);
1067 CPPUNIT_ASSERT(myData.getDataAtOffsetRO(offset)==1.0);
1068
1069 // myDataView = myData.getDataPointByTag(2);
1070 offset=myData.getOffsetForTag(2);
1071 CPPUNIT_ASSERT(offset==2);
1072 CPPUNIT_ASSERT(myData.getDataAtOffsetRO(offset)==1.0);
1073
1074 // myDataView = myData.getDataPointByTag(3);
1075 offset=myData.getOffsetForTag(3);
1076 CPPUNIT_ASSERT(offset==3);
1077 CPPUNIT_ASSERT(myData.getDataAtOffsetRO(offset)==1.0);
1078
1079 // myDataView = myData.getDefaultValue();
1080 offset=myData.getDefaultOffset();
1081 CPPUNIT_ASSERT(offset==0);
1082 CPPUNIT_ASSERT(myData.getDataAtOffsetRO(offset)==0.0);
1083
1084 // use a non-existent tag so we get a pointer to
1085 // the first element of the data array
1086 double* sampleData=myData.getSampleDataByTag(9);
1087 for (int i=0; i<myData.getLength(); i++) {
1088 if (i==0) {
1089 CPPUNIT_ASSERT(sampleData[i]==0);
1090 } else {
1091 CPPUNIT_ASSERT(sampleData[i]==1);
1092 }
1093 }
1094
1095 }
1096
1097 {
1098
1099 cout << "\tTest adding three keys with three values to default DataTagged." << endl;
1100 DataTagged myData;
1101
1102 DataTagged::TagListType keys;
1103 keys.push_back(1);
1104 keys.push_back(2);
1105 keys.push_back(3);
1106
1107 DataTagged::ValueBatchType values;
1108
1109 DataTypes::ShapeType viewShape;
1110 /* DataTypes::ValueType viewData1(1);
1111 viewData1[0]=1.0;
1112 DataTypes::ValueType viewData2(1);
1113 viewData2[0]=2.0;
1114 DataTypes::ValueType viewData3(1);
1115 viewData3[0]=3.0;
1116 DataArrayView myView1(viewData1,viewShape);
1117 DataArrayView myView2(viewData2,viewShape);
1118 DataArrayView myView3(viewData3,viewShape);*/
1119 values.push_back(1.0);
1120 values.push_back(2.0);
1121 values.push_back(3.0);
1122
1123 myData.addTaggedValues(keys,values,viewShape);
1124
1125 CPPUNIT_ASSERT(myData.isCurrentTag(1));
1126 CPPUNIT_ASSERT(myData.isCurrentTag(2));
1127 CPPUNIT_ASSERT(myData.isCurrentTag(3));
1128
1129 CPPUNIT_ASSERT(myData.getTagLookup().size()==3);
1130
1131 CPPUNIT_ASSERT(myData.getLength()==4);
1132
1133 // data-point 0 has tag number 1 by default
1134 CPPUNIT_ASSERT(myData.getTagNumber(0)==1);
1135
1136 CPPUNIT_ASSERT(myData.getPointOffset(0,0)==1);
1137
1138 CPPUNIT_ASSERT(myData.getRank()==0);
1139 CPPUNIT_ASSERT(myData.getNoValues()==1);
1140 CPPUNIT_ASSERT(myData.getShape().size()==0);
1141
1142
1143 // DataArrayView myDataView = myData.getDataPoint(0,0);
1144 int offset=myData.getPointOffset(0,0);
1145 CPPUNIT_ASSERT(offset==1);
1146 CPPUNIT_ASSERT(myData.getDataAtOffsetRO(offset)==1.0);
1147
1148 // myDataView = myData.getDataPointByTag(1);
1149 offset=myData.getOffsetForTag(1);
1150 CPPUNIT_ASSERT(offset==1);
1151 CPPUNIT_ASSERT(myData.getDataAtOffsetRO(offset)==1.0);
1152
1153 // myDataView = myData.getDataPointByTag(2);
1154 offset=myData.getOffsetForTag(2);
1155 CPPUNIT_ASSERT(offset==2);
1156 CPPUNIT_ASSERT(myData.getDataAtOffsetRO(offset)==2.0);
1157
1158 // myDataView = myData.getDataPointByTag(3);
1159 offset=myData.getOffsetForTag(3);
1160 CPPUNIT_ASSERT(offset==3);
1161 CPPUNIT_ASSERT(myData.getDataAtOffsetRO(offset)==3.0);
1162
1163 // myDataView = myData.getDefaultValue();
1164 offset=myData.getDefaultOffset();
1165 CPPUNIT_ASSERT(offset==0);
1166 CPPUNIT_ASSERT(myData.getDataAtOffsetRO(offset)==0.0);
1167
1168 // use a non-existent tag so we get a pointer to
1169 // the first element of the data array
1170 double* sampleData=myData.getSampleDataByTag(9);
1171 for (int i=0; i<myData.getLength(); i++) {
1172 CPPUNIT_ASSERT(sampleData[i]==i);
1173 }
1174
1175 }
1176
1177 {
1178
1179 cout << "\tTest adding one key with empty value list to DataTagged with default value only." << endl;
1180
1181 DataTypes::ShapeType viewShape;
1182 viewShape.push_back(3);
1183
1184 DataTagged::TagListType keys;
1185
1186 DataTagged::ValueBatchType values;
1187
1188 DataTypes::ValueType viewData(3);
1189 for (int i=0;i<viewShape[0];i++) {
1190 viewData[i]=i;
1191 }
1192
1193 DataTagged myData(FunctionSpace(),viewShape,viewData);
1194
1195 keys.push_back(1);
1196 values.clear();
1197
1198 myData.addTaggedValues(keys,values,viewShape);
1199
1200 CPPUNIT_ASSERT(myData.isCurrentTag(1));
1201
1202 CPPUNIT_ASSERT(myData.getTagLookup().size()==1);
1203
1204 CPPUNIT_ASSERT(myData.getLength()==6);
1205
1206 // data-point 0 has tag number 1 by default
1207 CPPUNIT_ASSERT(myData.getTagNumber(0)==1);
1208
1209 CPPUNIT_ASSERT(myData.getPointOffset(0,0)==3);
1210
1211 CPPUNIT_ASSERT(myData.getRank()==1);
1212 CPPUNIT_ASSERT(myData.getNoValues()==3);
1213 CPPUNIT_ASSERT(myData.getShape().size()==1);
1214
1215
1216 // DataArrayView myDataView = myData.getDataPoint(0,0);
1217 int offset=myData.getPointOffset(0,0);
1218 CPPUNIT_ASSERT(offset==3);
1219 CPPUNIT_ASSERT(getRefRO(myData,offset,0)==0);
1220 CPPUNIT_ASSERT(getRefRO(myData,offset,1)==1);
1221 CPPUNIT_ASSERT(getRefRO(myData,offset,2)==2);
1222
1223 // myDataView = myData.getDataPointByTag(1);
1224 offset=myData.getOffsetForTag(1);
1225 CPPUNIT_ASSERT(offset==3);
1226 CPPUNIT_ASSERT(getRefRO(myData,offset,0)==0);
1227 CPPUNIT_ASSERT(getRefRO(myData,offset,1)==1);
1228 CPPUNIT_ASSERT(getRefRO(myData,offset,2)==2);
1229
1230 // myDataView = myData.getDefaultValue();
1231 offset=myData.getDefaultOffset();
1232 CPPUNIT_ASSERT(offset==0);
1233 CPPUNIT_ASSERT(getRefRO(myData,offset,0)==0);
1234 CPPUNIT_ASSERT(getRefRO(myData,offset,1)==1);
1235 CPPUNIT_ASSERT(getRefRO(myData,offset,2)==2);
1236
1237 // use a non-existent tag so we get a pointer to
1238 // the first element of the data array
1239 double* sampleData=myData.getSampleDataByTag(9);
1240 for (int i=0; i<myData.getLength(); i++) {
1241 CPPUNIT_ASSERT(sampleData[i]==i%3);
1242 }
1243
1244 }
1245
1246 {
1247
1248 cout << "\tTest adding one key with one value to DataTagged with default value only." << endl;
1249
1250 DataTypes::ShapeType viewShape;
1251 viewShape.push_back(3);
1252
1253 DataTagged::TagListType keys;
1254
1255 DataTagged::ValueBatchType values;
1256
1257 DataTypes::ValueType viewData(3);
1258 for (int i=0;i<viewShape[0];i++) {
1259 viewData[i]=i;
1260 }
1261 // DataArrayView myView(viewData,viewShape);
1262
1263 DataTagged myData(FunctionSpace(),viewShape,viewData);
1264
1265 keys.push_back(1);
1266
1267 // DataTypes::ValueType viewData1(3);
1268 for (int i=0;i<viewShape[0];i++) {
1269 // viewData1[i]=i+3;
1270 values.push_back(i+3);
1271 }
1272 // DataArrayView myView1(viewData1,viewShape);
1273 // values.push_back(myView1);
1274
1275 myData.addTaggedValues(keys,values,viewShape);
1276
1277 CPPUNIT_ASSERT(myData.isCurrentTag(1));
1278
1279 CPPUNIT_ASSERT(myData.getTagLookup().size()==1);
1280
1281 CPPUNIT_ASSERT(myData.getLength()==6);
1282
1283 // data-point 0 has tag number 1 by default
1284 CPPUNIT_ASSERT(myData.getTagNumber(0)==1);
1285
1286 CPPUNIT_ASSERT(myData.getPointOffset(0,0)==3);
1287
1288 CPPUNIT_ASSERT(myData.getRank()==1);
1289 CPPUNIT_ASSERT(myData.getNoValues()==3);
1290 CPPUNIT_ASSERT(myData.getShape().size()==1);
1291
1292
1293 int offset=myData.getPointOffset(0,0);
1294 // DataArrayView myDataView = myData.getDataPoint(0,0);
1295 CPPUNIT_ASSERT(offset==3);
1296 CPPUNIT_ASSERT(getRefRO(myData,offset,0)==3);
1297 CPPUNIT_ASSERT(getRefRO(myData,offset,1)==4);
1298 CPPUNIT_ASSERT(getRefRO(myData,offset,2)==5);
1299
1300 // myDataView = myData.getDataPointByTag(1);
1301 offset=myData.getOffsetForTag(1);
1302 CPPUNIT_ASSERT(offset==3);
1303 CPPUNIT_ASSERT(getRefRO(myData,offset,0)==3);
1304 CPPUNIT_ASSERT(getRefRO(myData,offset,1)==4);
1305 CPPUNIT_ASSERT(getRefRO(myData,offset,2)==5);
1306
1307 // myDataView = myData.getDefaultValue();
1308 offset=myData.getDefaultOffset();
1309 CPPUNIT_ASSERT(offset==0);
1310 CPPUNIT_ASSERT(getRefRO(myData,offset,0)==0);
1311 CPPUNIT_ASSERT(getRefRO(myData,offset,1)==1);
1312 CPPUNIT_ASSERT(getRefRO(myData,offset,2)==2);
1313
1314 // use a non-existent tag so we get a pointer to
1315 // the first element of the data array
1316 double* sampleData=myData.getSampleDataByTag(9);
1317 for (int i=0; i<myData.getLength(); i++) {
1318 CPPUNIT_ASSERT(sampleData[i]==i);
1319 }
1320
1321 }
1322
1323 {
1324
1325 cout << "\tTest adding three keys with one value to DataTagged with default value only." << endl;
1326
1327 DataTypes::ShapeType viewShape;
1328 viewShape.push_back(3);
1329
1330 DataTagged::TagListType keys;
1331
1332 DataTagged::ValueBatchType values;
1333
1334 DataTypes::ValueType viewData(3);
1335 for (int i=0;i<viewShape[0];i++) {
1336 viewData[i]=i;
1337 }
1338 // DataArrayView myView(viewData,viewShape);
1339
1340 DataTagged myData(FunctionSpace(),viewShape,viewData);
1341
1342 keys.push_back(1);
1343 keys.push_back(2);
1344 keys.push_back(3);
1345
1346 // DataTypes::ValueType viewData1(3);
1347 for (int i=0;i<viewShape[0];i++) {
1348 // viewData1[i]=3;
1349 values.push_back(3);
1350 }
1351 // DataArrayView myView1(viewData1,viewShape);
1352 // values.push_back(myView1);
1353
1354 myData.addTaggedValues(keys,values,viewShape);
1355
1356 CPPUNIT_ASSERT(myData.isCurrentTag(1));
1357 CPPUNIT_ASSERT(myData.isCurrentTag(2));
1358 CPPUNIT_ASSERT(myData.isCurrentTag(3));
1359
1360 CPPUNIT_ASSERT(myData.getTagLookup().size()==3);
1361
1362 CPPUNIT_ASSERT(myData.getLength()==12);
1363
1364 // data-point 0 has tag number 1 by default
1365 CPPUNIT_ASSERT(myData.getTagNumber(0)==1);
1366
1367 CPPUNIT_ASSERT(myData.getPointOffset(0,0)==3);
1368
1369 CPPUNIT_ASSERT(myData.getRank()==1);
1370 CPPUNIT_ASSERT(myData.getNoValues()==3);
1371 CPPUNIT_ASSERT(myData.getShape().size()==1);
1372
1373 // DataArrayView myDataView = myData.getDataPoint(0,0);
1374 int offset=myData.getPointOffset(0,0);
1375 CPPUNIT_ASSERT(offset==3);
1376 CPPUNIT_ASSERT(getRefRO(myData,offset,0)==3);
1377 CPPUNIT_ASSERT(getRefRO(myData,offset,1)==3);
1378 CPPUNIT_ASSERT(getRefRO(myData,offset,2)==3);
1379
1380 // myDataView = myData.getDataPointByTag(1);
1381 offset=myData.getOffsetForTag(1);
1382 CPPUNIT_ASSERT(offset==3);
1383 CPPUNIT_ASSERT(getRefRO(myData,offset,0)==3);
1384 CPPUNIT_ASSERT(getRefRO(myData,offset,1)==3);
1385 CPPUNIT_ASSERT(getRefRO(myData,offset,2)==3);
1386
1387 // myDataView = myData.getDataPointByTag(2);
1388 offset=myData.getOffsetForTag(2);
1389 CPPUNIT_ASSERT(offset==6);
1390 CPPUNIT_ASSERT(getRefRO(myData,offset,0)==3);
1391 CPPUNIT_ASSERT(getRefRO(myData,offset,1)==3);
1392 CPPUNIT_ASSERT(getRefRO(myData,offset,2)==3);
1393
1394 // myDataView = myData.getDataPointByTag(3);
1395 offset=myData.getOffsetForTag(3);
1396 CPPUNIT_ASSERT(offset==9);
1397 CPPUNIT_ASSERT(getRefRO(myData,offset,0)==3);
1398 CPPUNIT_ASSERT(getRefRO(myData,offset,1)==3);
1399 CPPUNIT_ASSERT(getRefRO(myData,offset,2)==3);
1400
1401 // myDataView = myData.getDefaultValue();
1402 offset=myData.getDefaultOffset();
1403 CPPUNIT_ASSERT(offset==0);
1404 CPPUNIT_ASSERT(getRefRO(myData,offset,0)==0);
1405 CPPUNIT_ASSERT(getRefRO(myData,offset,1)==1);
1406 CPPUNIT_ASSERT(getRefRO(myData,offset,2)==2);
1407
1408 // use a non-existent tag so we get a pointer to
1409 // the first element of the data array
1410 double* sampleData=myData.getSampleDataByTag(9);
1411 for (int i=0; i<myData.getLength(); i++) {
1412 if (i<3) {
1413 CPPUNIT_ASSERT(sampleData[i]==i);
1414 } else {
1415 CPPUNIT_ASSERT(sampleData[i]==3);
1416 }
1417 }
1418
1419 }
1420
1421 {
1422
1423 cout << "\tTest adding three keys with three values to DataTagged with default value only." << endl;
1424
1425 DataTypes::ShapeType viewShape;
1426 viewShape.push_back(3);
1427
1428 DataTagged::TagListType keys;
1429
1430 DataTagged::ValueBatchType values;
1431
1432 DataTypes::ValueType viewData(3);
1433 for (int i=0;i<viewShape[0];i++) {
1434 viewData[i]=i;
1435 }
1436 // DataArrayView myView(viewData,viewShape);
1437
1438 DataTagged myData(FunctionSpace(),viewShape,viewData);
1439
1440 keys.push_back(1);
1441 keys.push_back(2);
1442 keys.push_back(3);
1443
1444 // DataTypes::ValueType viewData1(3);
1445 for (int i=0;i<viewShape[0];i++) {
1446 // viewData1[i]=i+1;
1447 values.push_back(i+1);
1448 }
1449 // DataArrayView myView1(viewData1,viewShape);
1450 // values.push_back(myView1);
1451
1452 // DataTypes::ValueType viewData2(3);
1453 for (int i=0;i<viewShape[0];i++) {
1454 // viewData2[i]=i+2;
1455 values.push_back(i+2);
1456 }
1457 // DataArrayView myView2(viewData2,viewShape);
1458 // values.push_back(myView2);
1459
1460 // DataTypes::ValueType viewData3(3);
1461 for (int i=0;i<viewShape[0];i++) {
1462 // viewData3[i]=i+3;
1463 values.push_back(i+3);
1464 }
1465 // DataArrayView myView3(viewData3,viewShape);
1466 // values.push_back(myView3);
1467
1468 myData.addTaggedValues(keys,values,viewShape);
1469
1470 CPPUNIT_ASSERT(myData.isCurrentTag(1));
1471 CPPUNIT_ASSERT(myData.isCurrentTag(2));
1472 CPPUNIT_ASSERT(myData.isCurrentTag(3));
1473
1474 CPPUNIT_ASSERT(myData.getTagLookup().size()==3);
1475
1476 CPPUNIT_ASSERT(myData.getLength()==12);
1477
1478 // data-point 0 has tag number 1 by default
1479 CPPUNIT_ASSERT(myData.getTagNumber(0)==1);
1480
1481 CPPUNIT_ASSERT(myData.getPointOffset(0,0)==3);
1482
1483 CPPUNIT_ASSERT(myData.getRank()==1);
1484 CPPUNIT_ASSERT(myData.getNoValues()==3);
1485 CPPUNIT_ASSERT(myData.getShape().size()==1);
1486
1487
1488 // DataArrayView myDataView = myData.getDataPoint(0,0);
1489 int offset=myData.getPointOffset(0,0);
1490 CPPUNIT_ASSERT(offset==3);
1491 CPPUNIT_ASSERT(getRefRO(myData,offset,0)==1);
1492 CPPUNIT_ASSERT(getRefRO(myData,offset,1)==2);
1493 CPPUNIT_ASSERT(getRefRO(myData,offset,2)==3);
1494
1495 // myDataView = myData.getDataPointByTag(1);
1496 offset=myData.getOffsetForTag(1);
1497 CPPUNIT_ASSERT(offset==3);
1498 CPPUNIT_ASSERT(getRefRO(myData,offset,0)==1);
1499 CPPUNIT_ASSERT(getRefRO(myData,offset,1)==2);
1500 CPPUNIT_ASSERT(getRefRO(myData,offset,2)==3);
1501
1502 // myDataView = myData.getDataPointByTag(2);
1503 offset=myData.getOffsetForTag(2);
1504 CPPUNIT_ASSERT(offset==6);
1505 CPPUNIT_ASSERT(getRefRO(myData,offset,0)==2);
1506 CPPUNIT_ASSERT(getRefRO(myData,offset,1)==3);
1507 CPPUNIT_ASSERT(getRefRO(myData,offset,2)==4);
1508
1509 // myDataView = myData.getDataPointByTag(3);
1510 offset=myData.getOffsetForTag(3);
1511 CPPUNIT_ASSERT(offset==9);
1512 CPPUNIT_ASSERT(getRefRO(myData,offset,0)==3);
1513 CPPUNIT_ASSERT(getRefRO(myData,offset,1)==4);
1514 CPPUNIT_ASSERT(getRefRO(myData,offset,2)==5);
1515
1516 // myDataView = myData.getDefaultValue();
1517 offset=myData.getDefaultOffset();
1518 CPPUNIT_ASSERT(offset==0);
1519 CPPUNIT_ASSERT(getRefRO(myData,offset,0)==0);
1520 CPPUNIT_ASSERT(getRefRO(myData,offset,1)==1);
1521 CPPUNIT_ASSERT(getRefRO(myData,offset,2)==2);
1522
1523 // use a non-existent tag so we get a pointer to
1524 // the first element of the data array
1525 double* sampleData=myData.getSampleDataByTag(9);
1526 for (int i=0; i<myData.getLength(); i++) {
1527 if (i<3) {
1528 CPPUNIT_ASSERT(sampleData[i]==i);
1529 } else if ((i>=3) && (i<6)) {
1530 CPPUNIT_ASSERT(sampleData[i]==i-2);
1531 } else if ((i>=6) && (i<9)) {
1532 CPPUNIT_ASSERT(sampleData[i]==i-4);
1533 } else {
1534 CPPUNIT_ASSERT(sampleData[i]==i-6);
1535 }
1536 }
1537
1538 }
1539
1540 {
1541
1542 cout << "\tTest adding one key with empty value list to DataTagged with three tags." << endl;
1543
1544 DataTagged::TagListType keys;
1545 keys.push_back(1);
1546 keys.push_back(2);
1547 keys.push_back(3);
1548
1549 DataTagged::ValueBatchType values;
1550
1551 DataTypes::ShapeType viewShape;
1552 viewShape.push_back(3);
1553
1554 // default value
1555 DataTypes::ValueType viewData(3*4);
1556 for (int i=0;i<viewShape[0];i++) {
1557 viewData[i]=i;
1558 }
1559 // DataArrayView myView(viewData,viewShape);
1560
1561 // value for tag "1"
1562 // DataTypes::ValueType eOneData(viewData);
1563 // DataArrayView eOneView(eOneData, viewShape);
1564 for (int i=0;i<viewShape[0];i++) {
1565 // eOneView(i)=i+1.0;
1566 viewData[viewShape[0]+i]=i+1.0;
1567 }
1568 // values.push_back(eOneView);
1569
1570 // value for tag "2"
1571 // DataTypes::ValueType eTwoData(viewData);
1572 // DataArrayView eTwoView(eTwoData, viewShape);
1573 for (int i=0;i<viewShape[0];i++) {
1574 // eTwoView(i)=i+2.0;
1575 viewData[2*viewShape[0]+i]=i+2.0;
1576 }
1577 // values.push_back(eTwoView);
1578
1579 // value for tag "3"
1580 // DataTypes::ValueType eThreeData(viewData);
1581 // DataArrayView eThreeView(eThreeData, viewShape);
1582 for (int i=0;i<viewShape[0];i++) {
1583 // eThreeView(i)=i+3.0;
1584 viewData[3*viewShape[0]+i]=i+3.0;
1585 }
1586 // values.push_back(eThreeView);
1587
1588 DataTagged myData(FunctionSpace(),viewShape,keys,viewData);
1589
1590 keys.clear();
1591 keys.push_back(4);
1592 values.clear();
1593
1594 myData.addTaggedValues(keys,values,viewShape);
1595
1596 CPPUNIT_ASSERT(myData.isCurrentTag(4));
1597
1598 CPPUNIT_ASSERT(myData.getTagLookup().size()==4);
1599
1600 CPPUNIT_ASSERT(myData.getLength()==15);
1601
1602 CPPUNIT_ASSERT(myData.getRank()==1);
1603 CPPUNIT_ASSERT(myData.getNoValues()==3);
1604 CPPUNIT_ASSERT(myData.getShape().size()==1);
1605
1606 // DataArrayView myDataView = myData.getDataPointByTag(4);
1607 int offset=myData.getOffsetForTag(4);
1608 CPPUNIT_ASSERT(offset==12);
1609 CPPUNIT_ASSERT(getRefRO(myData,offset,0)==0);
1610 CPPUNIT_ASSERT(getRefRO(myData,offset,1)==1);
1611 CPPUNIT_ASSERT(getRefRO(myData,offset,2)==2);
1612
1613 // use a non-existent tag so we get a pointer to
1614 // the first element of the data array
1615 double* sampleData=myData.getSampleDataByTag(9);
1616 for (int i=0; i<myData.getLength(); i++) {
1617 if (i<3) {
1618 CPPUNIT_ASSERT(sampleData[i]==i);
1619 } else if ((i>=3) && (i<6)) {
1620 CPPUNIT_ASSERT(sampleData[i]==i-2);
1621 } else if ((i>=6) && (i<9)) {
1622 CPPUNIT_ASSERT(sampleData[i]==i-4);
1623 } else if ((i>=9) && (i<12)) {
1624 CPPUNIT_ASSERT(sampleData[i]==i-6);
1625 } else {
1626 CPPUNIT_ASSERT(sampleData[i]==i-12);
1627 }
1628 }
1629
1630 }
1631
1632 {
1633
1634 cout << "\tTest adding one key with one value to DataTagged with three tags." << endl;
1635
1636 DataTagged::TagListType keys;
1637 keys.push_back(1);
1638 keys.push_back(2);
1639 keys.push_back(3);
1640
1641 DataTagged::ValueBatchType values;
1642
1643 DataTypes::ShapeType viewShape;
1644 viewShape.push_back(3);
1645
1646 // default value
1647 DataTypes::ValueType viewData(3*4);
1648 for (int i=0;i<viewShape[0];i++) {
1649 viewData[i]=i;
1650 }
1651 // DataArrayView myView(viewData,viewShape);
1652
1653 // value for tag "1"
1654 // DataTypes::ValueType eOneData(viewData);
1655 // DataArrayView eOneView(eOneData, viewShape);
1656 for (int i=0;i<viewShape[0];i++) {
1657 // eOneView(i)=i+1.0;
1658 viewData[viewShape[0]+i]=i+1.0;
1659 }
1660 // values.push_back(eOneView);
1661
1662 // value for tag "2"
1663 // DataTypes::ValueType eTwoData(viewData);
1664 // DataArrayView eTwoView(eTwoData, viewShape);
1665 for (int i=0;i<viewShape[0];i++) {
1666 // eTwoView(i)=i+2.0;
1667 viewData[2*viewShape[0]+i]=i+2.0;
1668 }
1669 // values.push_back(eTwoView);
1670
1671 // value for tag "3"
1672 // DataTypes::ValueType eThreeData(viewData);
1673 // DataArrayView eThreeView(eThreeData, viewShape);
1674 for (int i=0;i<viewShape[0];i++) {
1675 // eThreeView(i)=i+3.0;
1676 viewData[3*viewShape[0]+i]=i+3.0;
1677 }
1678 // values.push_back(eThreeView);
1679
1680 DataTagged myData(FunctionSpace(),viewShape,keys,viewData);
1681
1682 keys.clear();
1683 keys.push_back(4);
1684
1685 values.clear();
1686 // value for tag "4"
1687 // DataTypes::ValueType eFourData(viewData);
1688 // DataArrayView eFourView(eFourData, viewShape);
1689 for (int i=0;i<viewShape[0];i++) {
1690 values.push_back(i+4.0);
1691 }
1692 // values.push_back(eFourView);
1693
1694 myData.addTaggedValues(keys,values,viewShape);
1695
1696 CPPUNIT_ASSERT(myData.isCurrentTag(4));
1697
1698 CPPUNIT_ASSERT(myData.getTagLookup().size()==4);
1699
1700 CPPUNIT_ASSERT(myData.getLength()==15);
1701
1702 CPPUNIT_ASSERT(myData.getRank()==1);
1703 CPPUNIT_ASSERT(myData.getNoValues()==3);
1704 CPPUNIT_ASSERT(myData.getShape().size()==1);
1705
1706
1707 // DataArrayView myDataView = myData.getDataPointByTag(4);
1708 int offset=myData.getOffsetForTag(4);
1709 CPPUNIT_ASSERT(offset==12);
1710 CPPUNIT_ASSERT(getRefRO(myData,offset,0)==4);
1711 CPPUNIT_ASSERT(getRefRO(myData,offset,1)==5);
1712 CPPUNIT_ASSERT(getRefRO(myData,offset,2)==6);
1713
1714 // use a non-existent tag so we get a pointer to
1715 // the first element of the data array
1716 double* sampleData=myData.getSampleDataByTag(9);
1717 for (int i=0; i<myData.getLength(); i++) {
1718 if (i<3) {
1719 CPPUNIT_ASSERT(sampleData[i]==i);
1720 } else if ((i>=3) && (i<6)) {
1721 CPPUNIT_ASSERT(sampleData[i]==i-2);
1722 } else if ((i>=6) && (i<9)) {
1723 CPPUNIT_ASSERT(sampleData[i]==i-4);
1724 } else if ((i>=9) && (i<12)) {
1725 CPPUNIT_ASSERT(sampleData[i]==i-6);
1726 } else {
1727 CPPUNIT_ASSERT(sampleData[i]==i-8);
1728 }
1729 }
1730
1731 }
1732
1733 {
1734
1735 cout << "\tTest adding three keys with one value to DataTagged with three tags." << endl;
1736
1737 DataTagged::TagListType keys;
1738 keys.push_back(1);
1739 keys.push_back(2);
1740 keys.push_back(3);
1741
1742 DataTagged::ValueBatchType values;
1743
1744 DataTypes::ShapeType viewShape;
1745 viewShape.push_back(3);
1746
1747 // default value
1748 DataTypes::ValueType viewData(3*4);
1749 for (int i=0;i<viewShape[0];i++) {
1750 viewData[i]=i;
1751 }
1752 // DataArrayView myView(viewData,viewShape);
1753
1754 // value for tag "1"
1755 // DataTypes::ValueType eOneData(viewData);
1756 // DataArrayView eOneView(eOneData, viewShape);
1757 for (int i=0;i<viewShape[0];i++) {
1758 viewData[viewShape[0]+i]=i+1.0;
1759 }
1760 // values.push_back(eOneView);
1761
1762 // value for tag "2"
1763 // DataTypes::ValueType eTwoData(viewData);
1764 // DataArrayView eTwoView(eTwoData, viewShape);
1765 for (int i=0;i<viewShape[0];i++) {
1766 // eTwoView(i)=i+2.0;
1767 viewData[2*viewShape[0]+i]=i+2.0;
1768 }
1769 // values.push_back(eTwoView);
1770
1771 // value for tag "3"
1772 // DataTypes::ValueType eThreeData(viewData);
1773 // DataArrayView eThreeView(eThreeData, viewShape);
1774 for (int i=0;i<viewShape[0];i++) {
1775 // eThreeView(i)=i+3.0;
1776 viewData[3*viewShape[0]+i]=i+3.0;
1777 }
1778 // values.push_back(eThreeView);
1779
1780 DataTagged myData(FunctionSpace(),viewShape,keys,viewData);
1781
1782 keys.clear();
1783 keys.push_back(4);
1784 keys.push_back(5);
1785 keys.push_back(6);
1786
1787 values.clear();
1788 // value for tags "4", "5" and "6"
1789 // DataTypes::ValueType eFourData(viewData);
1790 // DataArrayView eFourView(eFourData, viewShape);
1791 for (int i=0;i<viewShape[0];i++) {
1792 // eFourView(i)=i+4.0;
1793 values.push_back(i+4.0);
1794 }
1795 // values.push_back(eFourView);
1796
1797 myData.addTaggedValues(keys,values,viewShape);
1798
1799 CPPUNIT_ASSERT(myData.isCurrentTag(4));
1800 CPPUNIT_ASSERT(myData.isCurrentTag(5));
1801 CPPUNIT_ASSERT(myData.isCurrentTag(6));
1802
1803 CPPUNIT_ASSERT(myData.getTagLookup().size()==6);
1804
1805 CPPUNIT_ASSERT(myData.getLength()==21);
1806
1807 CPPUNIT_ASSERT(myData.getRank()==1);
1808 CPPUNIT_ASSERT(myData.getNoValues()==3);
1809 CPPUNIT_ASSERT(myData.getShape().size()==1);
1810
1811 // DataArrayView myDataView = myData.getDataPointByTag(4);
1812 int offset=myData.getOffsetForTag(4);
1813 CPPUNIT_ASSERT(offset==12);
1814 CPPUNIT_ASSERT(getRefRO(myData,offset,0)==4);
1815 CPPUNIT_ASSERT(getRefRO(myData,offset,1)==5);
1816 CPPUNIT_ASSERT(getRefRO(myData,offset,2)==6);
1817
1818 // myDataView = myData.getDataPointByTag(5);
1819 offset=myData.getOffsetForTag(5);
1820 CPPUNIT_ASSERT(offset==15);
1821 CPPUNIT_ASSERT(getRefRO(myData,offset,0)==4);
1822 CPPUNIT_ASSERT(getRefRO(myData,offset,1)==5);
1823 CPPUNIT_ASSERT(getRefRO(myData,offset,2)==6);
1824
1825 // myDataView = myData.getDataPointByTag(6);
1826 offset=myData.getOffsetForTag(6);
1827 CPPUNIT_ASSERT(offset==18);
1828 CPPUNIT_ASSERT(getRefRO(myData,offset,0)==4);
1829 CPPUNIT_ASSERT(getRefRO(myData,offset,1)==5);
1830 CPPUNIT_ASSERT(getRefRO(myData,offset,2)==6);
1831
1832 // use a non-existent tag so we get a pointer to
1833 // the first element of the data array
1834 double* sampleData=myData.getSampleDataByTag(9);
1835 for (int i=0; i<myData.getLength(); i++) {
1836 if (i<3) {
1837 CPPUNIT_ASSERT(sampleData[i]==i);
1838 } else if ((i>=3) && (i<6)) {
1839 CPPUNIT_ASSERT(sampleData[i]==i-2);
1840 } else if ((i>=6) && (i<9)) {
1841 CPPUNIT_ASSERT(sampleData[i]==i-4);
1842 } else if ((i>=9) && (i<12)) {
1843 CPPUNIT_ASSERT(sampleData[i]==i-6);
1844 } else if ((i>=12) && (i<15)) {
1845 CPPUNIT_ASSERT(sampleData[i]==i-8);
1846 } else if ((i>=15) && (i<18)) {
1847 CPPUNIT_ASSERT(sampleData[i]==i-11);
1848 } else {
1849 CPPUNIT_ASSERT(sampleData[i]==i-14);
1850 }
1851 }
1852
1853 }
1854
1855 {
1856
1857 cout << "\tTest adding three keys with three values to DataTagged with three tags." << endl;
1858
1859 DataTagged::TagListType keys;
1860 keys.push_back(1);
1861 keys.push_back(2);
1862 keys.push_back(3);
1863
1864 DataTagged::ValueBatchType values;
1865
1866 DataTypes::ShapeType viewShape;
1867 viewShape.push_back(3);
1868
1869 // default value
1870 DataTypes::ValueType viewData(3*4);
1871 for (int i=0;i<viewShape[0];i++) {
1872 viewData[i]=i;
1873 }
1874 // DataArrayView myView(viewData,viewShape);
1875
1876 // value for tag "1"
1877 // DataTypes::ValueType eOneData(viewData);
1878 // DataArrayView eOneView(eOneData, viewShape);
1879 for (int i=0;i<viewShape[0];i++) {
1880 viewData[viewShape[0]+i]=i+1.0;
1881 }
1882 // values.push_back(eOneView);
1883
1884 // value for tag "2"
1885 // DataTypes::ValueType eTwoData(viewData);
1886 // DataArrayView eTwoView(eTwoData, viewShape);
1887 for (int i=0;i<viewShape[0];i++) {
1888 // eTwoView(i)=i+2.0;
1889 viewData[2*viewShape[0]+i]=i+2.0;
1890 }
1891 // values.push_back(eTwoView);
1892
1893 // value for tag "3"
1894 // DataTypes::ValueType eThreeData(viewData);
1895 // DataArrayView eThreeView(eThreeData, viewShape);
1896 for (int i=0;i<viewShape[0];i++) {
1897 viewData[3*viewShape[0]+i]=i+3.0;
1898 }
1899 // values.push_back(eThreeView);
1900
1901 DataTagged myData(FunctionSpace(),viewShape,keys,viewData);
1902
1903 keys.clear();
1904 keys.push_back(4);
1905 keys.push_back(5);
1906 keys.push_back(6);
1907
1908 values.clear();
1909
1910 // value for tag "4"
1911 // DataTypes::ValueType eFourData(viewData);
1912 // DataArrayView eFourView(eFourData, viewShape);
1913 for (int i=0;i<viewShape[0];i++) {
1914 values.push_back(i+4.0);
1915 }
1916 // values.push_back(eFourView);
1917
1918 // value for tag "5"
1919 // DataTypes::ValueType eFiveData(viewData);
1920 // DataArrayView eFiveView(eFiveData, viewShape);
1921 for (int i=0;i<viewShape[0];i++) {
1922 values.push_back(i+5.0);
1923 }
1924 // values.push_back(eFiveView);
1925
1926 // value for tag "6"
1927 // DataTypes::ValueType eSixData(viewData);
1928 // DataArrayView eSixView(eSixData, viewShape);
1929 for (int i=0;i<viewShape[0];i++) {
1930 // eSixView(i)=i+6.0;
1931 values.push_back(i+6.0);
1932 }
1933 // values.push_back(eSixView);
1934
1935 myData.addTaggedValues(keys,values,viewShape);
1936
1937 CPPUNIT_ASSERT(myData.isCurrentTag(4));
1938 CPPUNIT_ASSERT(myData.isCurrentTag(5));
1939 CPPUNIT_ASSERT(myData.isCurrentTag(6));
1940
1941 CPPUNIT_ASSERT(myData.getTagLookup().size()==6);
1942
1943 CPPUNIT_ASSERT(myData.getLength()==21);
1944
1945 CPPUNIT_ASSERT(myData.getRank()==1);
1946 CPPUNIT_ASSERT(myData.getNoValues()==3);
1947 CPPUNIT_ASSERT(myData.getShape().size()==1);
1948
1949 // DataArrayView myDataView = myData.getDataPointByTag(4);
1950 int offset=myData.getOffsetForTag(4);
1951 CPPUNIT_ASSERT(offset==12);
1952 CPPUNIT_ASSERT(getRefRO(myData,offset,0)==4);
1953 CPPUNIT_ASSERT(getRefRO(myData,offset,1)==5);
1954 CPPUNIT_ASSERT(getRefRO(myData,offset,2)==6);
1955
1956 // myDataView = myData.getDataPointByTag(5);
1957 offset=myData.getOffsetForTag(5);
1958 CPPUNIT_ASSERT(offset==15);
1959 CPPUNIT_ASSERT(getRefRO(myData,offset,0)==5);
1960 CPPUNIT_ASSERT(getRefRO(myData,offset,1)==6);
1961 CPPUNIT_ASSERT(getRefRO(myData,offset,2)==7);
1962
1963 // myDataView = myData.getDataPointByTag(6);
1964 offset=myData.getOffsetForTag(6);
1965 CPPUNIT_ASSERT(offset==18);
1966 CPPUNIT_ASSERT(getRefRO(myData,offset,0)==6);
1967 CPPUNIT_ASSERT(getRefRO(myData,offset,1)==7);
1968 CPPUNIT_ASSERT(getRefRO(myData,offset,2)==8);
1969
1970 // use a non-existent tag so we get a pointer to
1971 // the first element of the data array
1972 double* sampleData=myData.getSampleDataByTag(9);
1973 for (int i=0; i<myData.getLength(); i++) {
1974 if (i<3) {
1975 CPPUNIT_ASSERT(sampleData[i]==i);
1976 } else if ((i>=3) && (i<6)) {
1977 CPPUNIT_ASSERT(sampleData[i]==i-2);
1978 } else if ((i>=6) && (i<9)) {
1979 CPPUNIT_ASSERT(sampleData[i]==i-4);
1980 } else if ((i>=9) && (i<12)) {
1981 CPPUNIT_ASSERT(sampleData[i]==i-6);
1982 } else if ((i>=12) && (i<15)) {
1983 CPPUNIT_ASSERT(sampleData[i]==i-8);
1984 } else if ((i>=15) && (i<18)) {
1985 CPPUNIT_ASSERT(sampleData[i]==i-10);
1986 } else {
1987 CPPUNIT_ASSERT(sampleData[i]==i-12);
1988 }
1989 }
1990
1991 }
1992
1993 }
1994
1995 void DataTaggedTestCase::testSetTaggedValue() {
1996
1997 cout << endl;
1998
1999 {
2000
2001 cout << "\tTest setting key in DataTagged with three tags." << endl;
2002
2003 DataTagged::TagListType keys;
2004 keys.push_back(1);
2005 keys.push_back(2);
2006 keys.push_back(3);
2007
2008 DataTagged::ValueBatchType values;
2009
2010 DataTypes::ShapeType viewShape;
2011 viewShape.push_back(3);
2012
2013 // default value
2014 DataTypes::ValueType viewData(3*4);
2015 for (int i=0;i<viewShape[0];i++) {
2016 viewData[i]=i;
2017 }
2018 // DataArrayView myView(viewData,viewShape);
2019
2020 // value for tag "1"
2021 // DataTypes::ValueType eOneData(viewData);
2022 // DataArrayView eOneView(eOneData, viewShape);
2023 for (int i=0;i<viewShape[0];i++) {
2024 viewData[viewShape[0]+i]=i+1.0;
2025 }
2026 // values.push_back(eOneView);
2027
2028 // value for tag "2"
2029 // DataTypes::ValueType eTwoData(viewData);
2030 // DataArrayView eTwoView(eTwoData, viewShape);
2031 for (int i=0;i<viewShape[0];i++) {
2032 // eTwoView(i)=i+2.0;
2033 viewData[2*viewShape[0]+i]=i+2.0;
2034 }
2035 // values.push_back(eTwoView);
2036
2037 // value for tag "3"
2038 // DataTypes::ValueType eThreeData(viewData);
2039 // DataArrayView eThreeView(eThreeData, viewShape);
2040 for (int i=0;i<viewShape[0];i++) {
2041 // eThreeView(i)=i+3.0;
2042 viewData[3*viewShape[0]+i]=i+3.0;
2043 }
2044 // values.push_back(eThreeView);
2045
2046 DataTagged myData(FunctionSpace(),viewShape,keys,viewData);
2047
2048 // new value for tag "2"
2049 ValueType tmp(viewShape[0]);
2050 for (int i=0;i<viewShape[0];i++) {
2051 tmp[i]=i+5.0;
2052 }
2053
2054 myData.setTaggedValue(2,viewShape,tmp);
2055
2056 CPPUNIT_ASSERT(myData.isCurrentTag(2));
2057
2058 CPPUNIT_ASSERT(myData.getTagLookup().size()==3);
2059
2060 CPPUNIT_ASSERT(myData.getLength()==12);
2061
2062 CPPUNIT_ASSERT(myData.getRank()==1);
2063 CPPUNIT_ASSERT(myData.getNoValues()==3);
2064 CPPUNIT_ASSERT(myData.getShape().size()==1);
2065 // DataArrayView myDataView = myData.getDataPointByTag(2);
2066 int offset=myData.getOffsetForTag(2);
2067 CPPUNIT_ASSERT(offset==6);
2068 CPPUNIT_ASSERT(getRefRO(myData,offset,0)==5);
2069 CPPUNIT_ASSERT(getRefRO(myData,offset,1)==6);
2070 CPPUNIT_ASSERT(getRefRO(myData,offset,2)==7);
2071
2072 // use a non-existent tag so we get a pointer to
2073 // the first element of the data array
2074 double* sampleData=myData.getSampleDataByTag(9);
2075 for (int i=0; i<myData.getLength(); i++) {
2076 if (i<3) {
2077 CPPUNIT_ASSERT(sampleData[i]==i);
2078 } else if ((i>=3) && (i<6)) {
2079 CPPUNIT_ASSERT(sampleData[i]==i-2);
2080 } else if ((i>=6) && (i<9)) {
2081 CPPUNIT_ASSERT(sampleData[i]==i-1);
2082 } else {
2083 CPPUNIT_ASSERT(sampleData[i]==i-6);
2084 }
2085 }
2086
2087 }
2088
2089 }
2090
2091 void DataTaggedTestCase::testAll() {
2092
2093 cout << endl;
2094
2095 {
2096
2097 cout << "\tTest default DataTagged." << endl;
2098 DataTagged myData;
2099
2100 //cout << myData.toString() << endl;
2101
2102 CPPUNIT_ASSERT(myData.getNumSamples()==1);
2103 CPPUNIT_ASSERT(myData.getNumDPPSample()==1);
2104
2105 CPPUNIT_ASSERT(myData.validSamplePointNo(0));
2106 CPPUNIT_ASSERT(myData.validSampleNo(0));
2107 CPPUNIT_ASSERT(!myData.validSamplePointNo(1));
2108 CPPUNIT_ASSERT(!myData.validSampleNo(1));
2109
2110 // data-point 0 has tag number 1 by default
2111 CPPUNIT_ASSERT(myData.getTagNumber(0)==1);
2112
2113 CPPUNIT_ASSERT(!myData.isCurrentTag(1));
2114
2115 CPPUNIT_ASSERT(myData.getTagLookup().size()==0);
2116
2117 CPPUNIT_ASSERT(myData.getLength()==1);
2118
2119 CPPUNIT_ASSERT(myData.getPointOffset(0,0)==0);
2120
2121 CPPUNIT_ASSERT(myData.getRank()==0);
2122 CPPUNIT_ASSERT(myData.getNoValues()==1);
2123 CPPUNIT_ASSERT(myData.getShape().size()==0);
2124
2125
2126 // DataArrayView myDataView = myData.getDataPoint(0,0);
2127 int offset=myData.getPointOffset(0,0);
2128 CPPUNIT_ASSERT(offset==0);
2129 CPPUNIT_ASSERT(myData.getDataAtOffsetRO(offset)==0.0);
2130
2131 // Test non-existent tag returns the default value.
2132 // myDataView = myData.getDataPointByTag(1);
2133 offset=myData.getOffsetForTag(1);
2134 CPPUNIT_ASSERT(offset==0);
2135 CPPUNIT_ASSERT(myData.getDataAtOffsetRO(offset)==0.0);
2136
2137 // myDataView = myData.getDefaultValue();
2138 offset=myData.getDefaultOffset();
2139 CPPUNIT_ASSERT(offset==0);
2140 CPPUNIT_ASSERT(myData.getDataAtOffsetRO(offset)==0.0);
2141
2142 // use a non-existent tag so we get a pointer to
2143 // the first element of the data array
2144 const double* sampleData=myData.getSampleDataByTag(9);
2145 for (int i=0; i<myData.getLength(); i++) {
2146 CPPUNIT_ASSERT(sampleData[i]==i);
2147 }
2148 sampleData=myData.getSampleDataRO(0);
2149 for (unsigned int i=0; i<myData.getNoValues(); i++) {
2150 CPPUNIT_ASSERT(sampleData[i]==i);
2151 }
2152
2153 }
2154
2155 {
2156
2157 cout << "\tTest DataTagged with default value only." << endl;
2158
2159 DataTypes::ShapeType viewShape;
2160 viewShape.push_back(3);
2161
2162 DataTagged::TagListType keys;
2163
2164 DataTagged::ValueBatchType values;
2165
2166 DataTypes::ValueType viewData(3);
2167 for (int i=0;i<viewShape[0];i++) {
2168 viewData[i]=i;
2169 }
2170 // DataArrayView myView(viewData,viewShape);
2171 DataTagged myData(FunctionSpace(),viewShape, viewData);
2172 //cout << myData.toString() << endl;
2173
2174 CPPUNIT_ASSERT(myData.getNumSamples()==1);
2175 CPPUNIT_ASSERT(myData.getNumDPPSample()==1);
2176
2177 CPPUNIT_ASSERT(myData.validSamplePointNo(0));
2178 CPPUNIT_ASSERT(myData.validSampleNo(0));
2179 CPPUNIT_ASSERT(!myData.validSamplePointNo(1));
2180 CPPUNIT_ASSERT(!myData.validSampleNo(1));
2181
2182 // data-point 0 has tag number 1 by default
2183 CPPUNIT_ASSERT(myData.getTagNumber(0)==1);
2184
2185 CPPUNIT_ASSERT(!myData.isCurrentTag(1));
2186
2187 CPPUNIT_ASSERT(myData.getTagLookup().size()==0);
2188
2189 CPPUNIT_ASSERT(myData.getLength()==3);
2190
2191 CPPUNIT_ASSERT(myData.getPointOffset(0,0)==0);
2192
2193 CPPUNIT_ASSERT(myData.getRank()==1);
2194 CPPUNIT_ASSERT(myData.getNoValues()==3);
2195 CPPUNIT_ASSERT(myData.getShape().size()==1);
2196
2197 // DataArrayView myDataView = myData.getDataPoint(0,0);
2198 int offset=myData.getPointOffset(0,0);
2199 CPPUNIT_ASSERT(offset==0);
2200 CPPUNIT_ASSERT(getRefRO(myData,offset,0)==0);
2201 CPPUNIT_ASSERT(getRefRO(myData,offset,1)==1);
2202 CPPUNIT_ASSERT(getRefRO(myData,offset,2)==2);
2203
2204 // Test non-existent tag returns the default value.
2205 // myDataView = myData.getDataPointByTag(1);
2206 offset=myData.getOffsetForTag(1);
2207 CPPUNIT_ASSERT(offset==0);
2208 CPPUNIT_ASSERT(getRefRO(myData,offset,0)==0);
2209 CPPUNIT_ASSERT(getRefRO(myData,offset,1)==1);
2210 CPPUNIT_ASSERT(getRefRO(myData,offset,2)==2);
2211
2212 // myDataView = myData.getDefaultValue();
2213 offset=myData.getDefaultOffset();
2214 CPPUNIT_ASSERT(offset==0);
2215 CPPUNIT_ASSERT(getRefRO(myData,offset,0)==0);
2216 CPPUNIT_ASSERT(getRefRO(myData,offset,1)==1);
2217 CPPUNIT_ASSERT(getRefRO(myData,offset,2)==2);
2218
2219 // use a non-existent tag so we get a pointer to
2220 // the first element of the data array
2221 double* sampleData=myData.getSampleDataByTag(9);
2222 for (int i=0; i<myData.getLength(); i++) {
2223 CPPUNIT_ASSERT(sampleData[i]==i);
2224 }
2225 sampleData=myData.getSampleDataByTag(0);
2226 for (unsigned int i=0; i<myData.getNoValues(); i++) {
2227 CPPUNIT_ASSERT(sampleData[i]==i);
2228 }
2229
2230 }
2231
2232 {
2233
2234 cout << "\tTest DataTagged with one tag." << endl;
2235
2236 // the one data-point has tag value "1"
2237
2238 DataTagged::TagListType keys;
2239 keys.push_back(1);
2240
2241 DataTagged::ValueBatchType values;
2242
2243 DataTypes::ShapeType viewShape;
2244 viewShape.push_back(3);
2245
2246 // default value
2247 DataTypes::ValueType viewData(3*2);
2248 for (int i=0;i<viewShape[0];i++) {
2249 viewData[i]=i;
2250 }
2251 // DataArrayView myView(viewData,viewShape);
2252
2253 // value for tag "1"
2254 // DataTypes::ValueType eOneData(viewData);
2255 // DataArrayView eOneView(eOneData, viewShape);
2256 for (int i=0;i<viewShape[0];i++) {
2257 // eOneView(i)=i+1.0;
2258 viewData[viewShape[0]+i]=i+1.0;
2259 }
2260 // values.push_back(eOneView);
2261 DataTagged myData(FunctionSpace(),viewShape,keys,viewData);
2262
2263 //cout << myData.toString() << endl;
2264
2265 CPPUNIT_ASSERT(myData.getNumSamples()==1);
2266 CPPUNIT_ASSERT(myData.getNumDPPSample()==1);
2267
2268 CPPUNIT_ASSERT(myData.validSamplePointNo(0));
2269 CPPUNIT_ASSERT(myData.validSampleNo(0));
2270 CPPUNIT_ASSERT(!myData.validSamplePointNo(1));
2271 CPPUNIT_ASSERT(!myData.validSampleNo(1));
2272
2273 // data-point 0 has tag number 1 by default
2274 CPPUNIT_ASSERT(myData.getTagNumber(0)==1);
2275
2276 CPPUNIT_ASSERT(!myData.isCurrentTag(0));
2277 CPPUNIT_ASSERT(myData.isCurrentTag(1));
2278
2279 CPPUNIT_ASSERT(myData.getTagLookup().size()==1);
2280
2281 CPPUNIT_ASSERT(myData.getLength()==6);
2282
2283 CPPUNIT_ASSERT(myData.getPointOffset(0,0)==3);
2284
2285 CPPUNIT_ASSERT(myData.getRank()==1);
2286 CPPUNIT_ASSERT(myData.getNoValues()==3);
2287 CPPUNIT_ASSERT(myData.getShape().size()==1);
2288
2289
2290 int offset=myData.getPointOffset(0,0);
2291 // DataArrayView myDataView = myData.getDataPoint(0,0);
2292 CPPUNIT_ASSERT(offset==3);
2293 CPPUNIT_ASSERT(getRefRO(myData,offset,0)==1);
2294 CPPUNIT_ASSERT(getRefRO(myData,offset,1)==2);
2295 CPPUNIT_ASSERT(getRefRO(myData,offset,2)==3);
2296
2297 // myDataView = myData.getDataPointByTag(1);
2298 offset=myData.getOffsetForTag(1);
2299 CPPUNIT_ASSERT(offset==3);
2300 CPPUNIT_ASSERT(getRefRO(myData,offset,0)==1);
2301 CPPUNIT_ASSERT(getRefRO(myData,offset,1)==2);
2302 CPPUNIT_ASSERT(getRefRO(myData,offset,2)==3);
2303
2304 // Test non-existent tag returns the default value.
2305 // myDataView = myData.getDataPointByTag(9);
2306 offset=myData.getOffsetForTag(9);
2307 CPPUNIT_ASSERT(offset==0);
2308 CPPUNIT_ASSERT(getRefRO(myData,offset,0)==0);
2309 CPPUNIT_ASSERT(getRefRO(myData,offset,1)==1);
2310 CPPUNIT_ASSERT(getRefRO(myData,offset,2)==2);
2311
2312 // myDataView = myData.getDefaultValue();
2313 offset=myData.getDefaultOffset();
2314 CPPUNIT_ASSERT(offset==0);
2315 CPPUNIT_ASSERT(getRefRO(myData,offset,0)==0);
2316 CPPUNIT_ASSERT(getRefRO(myData,offset,1)==1);
2317 CPPUNIT_ASSERT(getRefRO(myData,offset,2)==2);
2318
2319 // use a non-existent tag so we get a pointer to
2320 // the first element of the data array
2321 const double* sampleData=myData.getSampleDataByTag(9);
2322 for (int i=0; i<myData.getLength(); i++) {
2323 if (i<3) {
2324 CPPUNIT_ASSERT(sampleData[i]==i);
2325 } else {
2326 CPPUNIT_ASSERT(sampleData[i]==i-2);
2327 }
2328 }
2329 sampleData=myData.getSampleDataRO(0);
2330 for (unsigned int i=0; i<myData.getNoValues(); i++) {
2331 CPPUNIT_ASSERT(sampleData[i]==i+1);
2332 }
2333
2334 }
2335
2336 {
2337
2338 cout << "\tTest DataTagged with multiple tags." << endl;
2339
2340 // the one data-point has tag value "1"
2341
2342 DataTagged::TagListType keys;
2343 keys.push_back(1);
2344 keys.push_back(2);
2345 keys.push_back(3);
2346
2347 DataTagged::ValueBatchType values;
2348
2349 DataTypes::ShapeType viewShape;
2350 viewShape.push_back(3);
2351
2352 // default value
2353 DataTypes::ValueType viewData(3*4);
2354 for (int i=0;i<viewShape[0];i++) {
2355 viewData[i]=i;
2356 }
2357 // DataArrayView myView(viewData,viewShape);
2358
2359 // value for tag "1"
2360 // DataTypes::ValueType eOneData(viewData);
2361 // DataArrayView eOneView(eOneData, viewShape);
2362 for (int i=0;i<viewShape[0];i++) {
2363 /* eOneView(i)=i+1.0;*/
2364 viewData[viewShape[0]+i]=i+1.0;
2365 }
2366 // values.push_back(eOneView);
2367
2368 // value for tag "2"
2369 // DataTypes::ValueType eTwoData(viewData);
2370 // DataArrayView eTwoView(eTwoData, viewShape);
2371 for (int i=0;i<viewShape[0];i++) {
2372 viewData[2*viewShape[0]+i]=i+2.0;
2373 }
2374 // values.push_back(eTwoView);
2375
2376 // value for tag "3"
2377 // DataTypes::ValueType eThreeData(viewData);
2378 // DataArrayView eThreeView(eThreeData, viewShape);
2379 for (int i=0;i<viewShape[0];i++) {
2380 /* eThreeView(i)=i+3.0;*/
2381 viewData[3*viewShape[0]+i]=i+3.0;
2382 }
2383 // values.push_back(eThreeView);
2384
2385 DataTagged myData(FunctionSpace(),viewShape,keys,viewData);
2386
2387 //cout << myData.toString() << endl;
2388
2389 CPPUNIT_ASSERT(myData.getNumSamples()==1);
2390 CPPUNIT_ASSERT(myData.getNumDPPSample()==1);
2391
2392 CPPUNIT_ASSERT(myData.validSamplePointNo(0));
2393 CPPUNIT_ASSERT(myData.validSampleNo(0));
2394 CPPUNIT_ASSERT(!myData.validSamplePointNo(1));
2395 CPPUNIT_ASSERT(!myData.validSampleNo(1));
2396
2397 // data-point 0 has tag number 1 by default
2398 CPPUNIT_ASSERT(myData.getTagNumber(0)==1);
2399
2400 CPPUNIT_ASSERT(!myData.isCurrentTag(0));
2401 CPPUNIT_ASSERT(myData.isCurrentTag(1));
2402 CPPUNIT_ASSERT(myData.isCurrentTag(2));
2403 CPPUNIT_ASSERT(myData.isCurrentTag(3));
2404
2405 CPPUNIT_ASSERT(myData.getTagLookup().size()==3);
2406
2407 CPPUNIT_ASSERT(myData.getLength()==12);
2408
2409 CPPUNIT_ASSERT(myData.getPointOffset(0,0)==3);
2410
2411 CPPUNIT_ASSERT(myData.getRank()==1);
2412 CPPUNIT_ASSERT(myData.getNoValues()==3);
2413 CPPUNIT_ASSERT(myData.getShape().size()==1);
2414
2415
2416 int offset=myData.getPointOffset(0,0);
2417 // DataArrayView myDataView = myData.getDataPoint(0,0);
2418 CPPUNIT_ASSERT(offset==3);
2419 CPPUNIT_ASSERT(getRefRO(myData,offset,0)==1);
2420 CPPUNIT_ASSERT(getRefRO(myData,offset,1)==2);
2421 CPPUNIT_ASSERT(getRefRO(myData,offset,2)==3);
2422
2423 // myDataView = myData.getDataPointByTag(1);
2424 offset=myData.getOffsetForTag(1);
2425 CPPUNIT_ASSERT(offset==3);
2426 CPPUNIT_ASSERT(getRefRO(myData,offset,0)==1);
2427 CPPUNIT_ASSERT(getRefRO(myData,offset,1)==2);
2428 CPPUNIT_ASSERT(getRefRO(myData,offset,2)==3);
2429
2430 // Test non-existent tag returns the default value.
2431 // myDataView = myData.getDataPointByTag(0);
2432 offset=myData.getOffsetForTag(0);
2433 CPPUNIT_ASSERT(offset==0);
2434 CPPUNIT_ASSERT(getRefRO(myData,offset,0)==0);
2435 CPPUNIT_ASSERT(getRefRO(myData,offset,1)==1);
2436 CPPUNIT_ASSERT(getRefRO(myData,offset,2)==2);
2437
2438 // myDataView = myData.getDefaultValue();
2439 offset=myData.getDefaultOffset();
2440 CPPUNIT_ASSERT(offset==0);
2441 CPPUNIT_ASSERT(getRefRO(myData,offset,0)==0);
2442 CPPUNIT_ASSERT(getRefRO(myData,offset,1)==1);
2443 CPPUNIT_ASSERT(getRefRO(myData,offset,2)==2);
2444
2445 // Test data-points held for remaining tags
2446 // myDataView = myData.getDataPointByTag(2);
2447 offset=myData.getOffsetForTag(2);
2448 CPPUNIT_ASSERT(offset==6);
2449 CPPUNIT_ASSERT(getRefRO(myData,offset,0)==2);
2450 CPPUNIT_ASSERT(getRefRO(myData,offset,1)==3);
2451 CPPUNIT_ASSERT(getRefRO(myData,offset,2)==4);
2452
2453 // myDataView = myData.getDataPointByTag(3);
2454 offset=myData.getOffsetForTag(3);
2455 CPPUNIT_ASSERT(offset==9);
2456 CPPUNIT_ASSERT(getRefRO(myData,offset,0)==3);
2457 CPPUNIT_ASSERT(getRefRO(myData,offset,1)==4);
2458 CPPUNIT_ASSERT(getRefRO(myData,offset,2)==5);
2459
2460 // use a non-existent tag so we get a pointer to
2461 // the first element of the data array
2462 const double* sampleData=myData.getSampleDataByTag(9);
2463 for (int i=0; i<myData.getLength(); i++) {
2464 if (i<3) {
2465 CPPUNIT_ASSERT(sampleData[i]==i);
2466 } else if ((i>=3) && (i<6)) {
2467 CPPUNIT_ASSERT(sampleData[i]==i-2);
2468 } else if ((i>=6) && (i<9)) {
2469 CPPUNIT_ASSERT(sampleData[i]==i-4);
2470 } else {
2471 CPPUNIT_ASSERT(sampleData[i]==i-6);
2472 }
2473 }
2474 sampleData=myData.getSampleDataRO(0);
2475 for (unsigned int i=0; i<myData.getNoValues(); i++) {
2476 CPPUNIT_ASSERT(sampleData[i]==i+1);
2477 }
2478
2479 }
2480
2481 }
2482
2483 void DataTaggedTestCase::testCopyConstructors() {
2484
2485 cout << endl;
2486
2487 {
2488
2489 cout << "\tTest DataTagged copy constructor for DataTagged with multiple tags." << endl;
2490
2491 // the one data-point has tag value "1"
2492
2493 DataTagged::TagListType keys;
2494 keys.push_back(1);
2495 keys.push_back(2);
2496 keys.push_back(3);
2497
2498 DataTagged::ValueBatchType values;
2499
2500 DataTypes::ShapeType viewShape;
2501 viewShape.push_back(3);
2502
2503 // default value
2504 DataTypes::ValueType viewData(3*4);
2505 for (int i=0;i<viewShape[0];i++) {
2506 viewData[i]=i;
2507 }
2508 // DataArrayView myView(viewData,viewShape);
2509
2510 // value for tag "1"
2511 // DataTypes::ValueType eOneData(viewData);
2512 // DataArrayView eOneView(eOneData, viewShape);
2513 for (int i=0;i<viewShape[0];i++) {
2514 viewData[viewShape[0]+i]=i+1.0;
2515 }
2516 // values.push_back(eOneView);
2517
2518 // value for tag "2"
2519 // DataTypes::ValueType eTwoData(viewData);
2520 // DataArrayView eTwoView(eTwoData, viewShape);
2521 for (int i=0;i<viewShape[0];i++) {
2522 // eTwoView(i)=i+2.0;
2523 viewData[2*viewShape[0]+i]=i+2.0;
2524 }
2525 // values.push_back(eTwoView);
2526
2527 // value for tag "3"
2528 // DataTypes::ValueType eThreeData(viewData);
2529 // DataArrayView eThreeView(eThreeData, viewShape);
2530 for (int i=0;i<viewShape[0];i++) {
2531 // eThreeView(i)=i+3.0;
2532 viewData[3*viewShape[0]+i]=i+3.0;
2533 }
2534 // values.push_back(eThreeView);
2535
2536 DataTagged myData(FunctionSpace(),viewShape,keys,viewData);
2537
2538 DataTagged myDataCopy(myData);
2539
2540 //cout << myDataCopy.toString() << endl;
2541
2542 CPPUNIT_ASSERT(myDataCopy.getNumSamples()==1);
2543 CPPUNIT_ASSERT(myDataCopy.getNumDPPSample()==1);
2544
2545 CPPUNIT_ASSERT(myDataCopy.validSamplePointNo(0));
2546 CPPUNIT_ASSERT(myDataCopy.validSampleNo(0));
2547 CPPUNIT_ASSERT(!myDataCopy.validSamplePointNo(1));
2548 CPPUNIT_ASSERT(!myDataCopy.validSampleNo(1));
2549
2550 // data-point 0 has tag number 1 by default
2551 CPPUNIT_ASSERT(myDataCopy.getTagNumber(0)==1);
2552
2553 CPPUNIT_ASSERT(!myDataCopy.isCurrentTag(0));
2554 CPPUNIT_ASSERT(myDataCopy.isCurrentTag(1));
2555 CPPUNIT_ASSERT(myDataCopy.isCurrentTag(2));
2556 CPPUNIT_ASSERT(myDataCopy.isCurrentTag(3));
2557
2558 CPPUNIT_ASSERT(myDataCopy.getTagLookup().size()==3);
2559
2560 CPPUNIT_ASSERT(myDataCopy.getLength()==12);
2561
2562 CPPUNIT_ASSERT(myDataCopy.getPointOffset(0,0)==3);
2563
2564 CPPUNIT_ASSERT(myDataCopy.getRank()==1);
2565 CPPUNIT_ASSERT(myDataCopy.getNoValues()==3);
2566 CPPUNIT_ASSERT(myDataCopy.getShape().size()==1);
2567
2568 int offset=myDataCopy.getPointOffset(0,0);
2569 // DataArrayView myDataView = myDataCopy.getDataPoint(0,0);
2570 CPPUNIT_ASSERT(offset==3);
2571 CPPUNIT_ASSERT(getRefRO(myDataCopy,offset,0)==1);
2572 CPPUNIT_ASSERT(getRefRO(myDataCopy,offset,1)==2);
2573 CPPUNIT_ASSERT(getRefRO(myDataCopy,offset,2)==3);
2574
2575 // myDataView = myDataCopy.getDataPointByTag(1);
2576 offset=myDataCopy.getOffsetForTag(1);
2577 CPPUNIT_ASSERT(offset==3);
2578 CPPUNIT_ASSERT(getRefRO(myDataCopy,offset,0)==1);
2579 CPPUNIT_ASSERT(getRefRO(myDataCopy,offset,1)==2);
2580 CPPUNIT_ASSERT(getRefRO(myDataCopy,offset,2)==3);
2581
2582 // Test non-existent tag returns the default value.
2583 // myDataView = myDataCopy.getDataPointByTag(0);
2584 offset=myDataCopy.getOffsetForTag(0);
2585 CPPUNIT_ASSERT(offset==0);
2586 CPPUNIT_ASSERT(getRefRO(myDataCopy,offset,0)==0);
2587 CPPUNIT_ASSERT(getRefRO(myDataCopy,offset,1)==1);
2588 CPPUNIT_ASSERT(getRefRO(myDataCopy,offset,2)==2);
2589
2590 //myDataView = myDataCopy.getDefaultValue();
2591 offset=myDataCopy.getDefaultOffset();
2592 CPPUNIT_ASSERT(offset==0);
2593 CPPUNIT_ASSERT(getRefRO(myDataCopy,offset,0)==0);
2594 CPPUNIT_ASSERT(getRefRO(myDataCopy,offset,1)==1);
2595 CPPUNIT_ASSERT(getRefRO(myDataCopy,offset,2)==2);
2596
2597 // Test data-points held for remaining tags
2598 // myDataView = myDataCopy.getDataPointByTag(2);
2599 offset=myDataCopy.getOffsetForTag(2);
2600 CPPUNIT_ASSERT(offset==6);
2601 CPPUNIT_ASSERT(getRefRO(myDataCopy,offset,0)==2);
2602 CPPUNIT_ASSERT(getRefRO(myDataCopy,offset,1)==3);
2603 CPPUNIT_ASSERT(getRefRO(myDataCopy,offset,2)==4);
2604
2605 // myDataView = myDataCopy.getDataPointByTag(3);
2606 offset=myDataCopy.getOffsetForTag(3);
2607 CPPUNIT_ASSERT(offset==9);
2608 CPPUNIT_ASSERT(getRefRO(myDataCopy,offset,0)==3);
2609 CPPUNIT_ASSERT(getRefRO(myDataCopy,offset,1)==4);
2610 CPPUNIT_ASSERT(getRefRO(myDataCopy,offset,2)==5);
2611
2612 // use a non-existent tag so we get a pointer to
2613 // the first element of the data array
2614 double* sampleData=myDataCopy.getSampleDataByTag(9);
2615 for (int i=0; i<myData.getLength(); i++) {
2616 if (i<3) {
2617 CPPUNIT_ASSERT(sampleData[i]==i);
2618 } else if ((i>=3) && (i<6)) {
2619 CPPUNIT_ASSERT(sampleData[i]==i-2);
2620 } else if ((i>=6) && (i<9)) {
2621 CPPUNIT_ASSERT(sampleData[i]==i-4);
2622 } else {
2623 CPPUNIT_ASSERT(sampleData[i]==i-6);
2624 }
2625 }
2626
2627 }
2628
2629 {
2630
2631 cout << "\tTest DataTagged copy constructor for DataConstant." << endl;
2632
2633 // Create a DataConstant
2634 DataTypes::ShapeType shape;
2635 DataTypes::ValueType data(DataTypes::noValues(shape),0);
2636 // DataArrayView pointData(data,shape);
2637 data[0]=1.0;
2638 DataConstant myConstantData(FunctionSpace(),shape,data);
2639
2640 // use this DataConstant to initialise a DataTagged
2641 DataTagged myData(myConstantData);
2642
2643 //cout << myData.toString() << endl;
2644
2645 CPPUNIT_ASSERT(myData.getNumSamples()==1);
2646 CPPUNIT_ASSERT(myData.getNumDPPSample()==1);
2647
2648 CPPUNIT_ASSERT(myData.validSamplePointNo(0));
2649 CPPUNIT_ASSERT(myData.validSampleNo(0));
2650 CPPUNIT_ASSERT(!myData.validSamplePointNo(1));
2651 CPPUNIT_ASSERT(!myData.validSampleNo(1));
2652
2653 // data-point 0 has tag number 1 by default
2654 CPPUNIT_ASSERT(myData.getTagNumber(0)==1);
2655
2656 CPPUNIT_ASSERT(!myData.isCurrentTag(1));
2657
2658 CPPUNIT_ASSERT(myData.getTagLookup().size()==0);
2659
2660 CPPUNIT_ASSERT(myData.getLength()==1);
2661
2662 CPPUNIT_ASSERT(myData.getPointOffset(0,0)==0);
2663
2664 CPPUNIT_ASSERT(myData.getRank()==0);
2665 CPPUNIT_ASSERT(myData.getNoValues()==1);
2666 CPPUNIT_ASSERT(myData.getShape().size()==0);
2667
2668
2669 // DataArrayView myDataView = myData.getDataPoint(0,0);
2670 int offset=myData.getPointOffset(0,0);
2671 CPPUNIT_ASSERT(offset==0);
2672 CPPUNIT_ASSERT(myData.getDataAtOffsetRO(offset)==1.0);
2673
2674 // Test non-existent tag returns the default value.
2675 // myDataView = myData.getDataPointByTag(1);
2676 offset=myData.getOffsetForTag(1);
2677 CPPUNIT_ASSERT(offset==0);
2678 CPPUNIT_ASSERT(myData.getDataAtOffsetRO(offset)==1.0);
2679
2680 // myDataView = myData.getDefaultValue();
2681 offset=myData.getDefaultOffset();
2682 CPPUNIT_ASSERT(offset==0);
2683 CPPUNIT_ASSERT(myData.getDataAtOffsetRO(offset)==1.0);
2684
2685 // use a non-existent tag so we get a pointer to
2686 // the first element of the data array
2687 double* sampleData=myData.getSampleDataByTag(9);
2688 for (int i=0; i<myData.getLength(); i++) {
2689 CPPUNIT_ASSERT(sampleData[i]==i+1);
2690 }
2691
2692 }
2693
2694 }
2695
2696 void DataTaggedTestCase::testGetSlice() {
2697
2698 cout << endl;
2699
2700 {
2701
2702 cout << "\tTest slicing default DataTagged." << endl;
2703
2704 DataTagged myData;
2705
2706 DataTypes::RegionType region;
2707
2708 DataAbstract* slicedDefault = myData.getSlice(region);
2709
2710 // cout << slicedDefault->toString() << endl;
2711
2712 const DataTagged* myDataSliced=dynamic_cast<const DataTagged*>(slicedDefault);
2713
2714 CPPUNIT_ASSERT(myDataSliced->getTagLookup().size()==0);
2715
2716 CPPUNIT_ASSERT(myDataSliced->getLength()==1);
2717
2718 // DataArrayView myDataView = myDataSliced->getDefaultValue();
2719 int offset=myDataSliced->getDefaultOffset();
2720 CPPUNIT_ASSERT(offset==0);
2721 CPPUNIT_ASSERT(myDataSliced->getRank()==0);
2722 CPPUNIT_ASSERT(myDataSliced->getNoValues()==1);
2723 CPPUNIT_ASSERT(myDataSliced->getShape().size()==0);
2724 CPPUNIT_ASSERT(myDataSliced->getVectorRO()[0]==0.0);
2725
2726 delete slicedDefault;
2727 }
2728
2729 {
2730
2731 cout << "\tTest slicing DataTagged with rank 1 default value only." << endl;
2732
2733 DataTypes::ShapeType viewShape;
2734 viewShape.push_back(3);
2735
2736 DataTagged::TagListType keys;
2737
2738 DataTagged::ValueBatchType values;
2739
2740 DataTypes::ValueType viewData(3);
2741 for (int i=0;i<viewShape[0];i++) {
2742 viewData[i]=i;
2743 }
2744 // DataArrayView myView(viewData,viewShape);
2745
2746 DataTagged myData(FunctionSpace(),viewShape,viewData);
2747
2748 // full slice
2749
2750 std::pair<int, int> region_element;
2751 region_element.first=0;
2752 region_element.second=3;
2753 DataTypes::RegionType region;
2754 region.push_back(region_element);
2755
2756 DataAbstract* slicedDefault = myData.getSlice(region);
2757
2758 //cout << slicedDefault->toString() << endl;
2759
2760 const DataTagged* myDataSliced=dynamic_cast<const DataTagged*>(slicedDefault);
2761
2762 CPPUNIT_ASSERT(myDataSliced->getTagLookup().size()==0);
2763
2764 CPPUNIT_ASSERT(myDataSliced->getLength()==3);
2765
2766 CPPUNIT_ASSERT(myDataSliced->getRank()==1);
2767 CPPUNIT_ASSERT(myDataSliced->getNoValues()==3);
2768 CPPUNIT_ASSERT(myDataSliced->getShape().size()==1);
2769
2770 // DataArrayView myDataView = myDataSliced->getDefaultValue();
2771 int offset=myDataSliced->getDefaultOffset();
2772 CPPUNIT_ASSERT(offset==0);
2773
2774 CPPUNIT_ASSERT(getRefRO(*myDataSliced,offset,0)==0.0);
2775 CPPUNIT_ASSERT(getRefRO(*myDataSliced,offset,1)==1.0);
2776 CPPUNIT_ASSERT(getRefRO(*myDataSliced,offset,2)==2.0);
2777
2778 // scalar slice
2779
2780 region.clear();
2781 region_element.first=0;
2782 region_element.second=0;
2783 region.push_back(region_element);
2784
2785 delete slicedDefault;
2786
2787 slicedDefault = myData.getSlice(region);
2788
2789 //cout << slicedDefault->toString() << endl;
2790
2791 myDataSliced=dynamic_cast<const DataTagged*>(slicedDefault);
2792
2793 CPPUNIT_ASSERT(myDataSliced->getTagLookup().size()==0);
2794
2795 CPPUNIT_ASSERT(myDataSliced->getLength()==1);
2796
2797 // myDataView = myDataSliced->getDefaultValue();
2798 offset=myDataSliced->getDefaultOffset();
2799 CPPUNIT_ASSERT(offset==0);
2800 CPPUNIT_ASSERT(myDataSliced->getRank()==0);
2801 CPPUNIT_ASSERT(myDataSliced->getNoValues()==1);
2802 CPPUNIT_ASSERT(myDataSliced->getShape().size()==0);
2803 CPPUNIT_ASSERT(myDataSliced->getVectorRO()[0]==0.0);
2804
2805 delete slicedDefault;
2806 }
2807
2808 {
2809
2810 cout << "\tTest slicing DataTagged with rank 3 default value only." << endl;
2811
2812 DataTypes::ShapeType viewShape;
2813 viewShape.push_back(3);
2814 viewShape.push_back(3);
2815 viewShape.push_back(3);
2816
2817 DataTagged::TagListType keys;
2818
2819 DataTagged::ValueBatchType values;
2820
2821 DataTypes::ValueType viewData(27);
2822 for (int i=0;i<viewData.size();i++) {
2823 viewData[i]=i;
2824 }
2825 // DataArrayView myView(viewData,viewShape);
2826
2827 DataTagged myData(FunctionSpace(),viewShape,viewData);
2828
2829 //cout << myData.toString() << endl;
2830
2831 // full slice
2832
2833 std::pair<int, int> region_element;
2834 region_element.first=0;
2835 region_element.second=3;
2836 DataTypes::RegionType region;
2837 region.push_back(region_element);
2838 region.push_back(region_element);
2839 region.push_back(region_element);
2840
2841 DataAbstract* slicedDefault = myData.getSlice(region);
2842
2843 //cout << slicedDefault->toString() << endl;
2844
2845 const DataTagged* myDataSliced=dynamic_cast<const DataTagged*>(slicedDefault);
2846
2847 CPPUNIT_ASSERT(myDataSliced->getTagLookup().size()==0);
2848
2849 CPPUNIT_ASSERT(myDataSliced->getLength()==27);
2850
2851 // DataArrayView myDataView = myDataSliced->getDefaultValue();
2852 int offset=myDataSliced->getDefaultOffset();
2853 CPPUNIT_ASSERT(offset==0);
2854 CPPUNIT_ASSERT(myDataSliced->getRank()==3);
2855 CPPUNIT_ASSERT(myDataSliced->getNoValues()==27);
2856 CPPUNIT_ASSERT(myDataSliced->getShape().size()==3);
2857
2858 // rank 1 slice
2859
2860 region.clear();
2861 region.push_back(region_element);
2862 region_element.second=0;
2863 region.push_back(region_element);
2864 region.push_back(region_element);
2865
2866 delete slicedDefault;
2867
2868 slicedDefault = myData.getSlice(region);
2869
2870 //cout << slicedDefault->toString() << endl;
2871
2872 myDataSliced=dynamic_cast<const DataTagged*>(slicedDefault);
2873
2874 CPPUNIT_ASSERT(myDataSliced->getTagLookup().size()==0);
2875
2876 CPPUNIT_ASSERT(myDataSliced->getLength()==3);
2877
2878 CPPUNIT_ASSERT(myDataSliced->getRank()==1);
2879 CPPUNIT_ASSERT(myDataSliced->getNoValues()==3);
2880 CPPUNIT_ASSERT(myDataSliced->getShape().size()==1);
2881
2882 // myDataView = myDataSliced->getDefaultValue();
2883 offset=myDataSliced->getDefaultOffset();
2884 CPPUNIT_ASSERT(offset==0);
2885 CPPUNIT_ASSERT(getRefRO(*myDataSliced,offset,0)==0.0);
2886 CPPUNIT_ASSERT(getRefRO(*myDataSliced,offset,1)==1.0);
2887 CPPUNIT_ASSERT(getRefRO(*myDataSliced,offset,2)==2.0);
2888
2889 // scalar slice
2890
2891 region.clear();
2892 region_element.first=2;
2893 region_element.second=2;
2894 region.push_back(region_element);
2895 region.push_back(region_element);
2896 region.push_back(region_element);
2897
2898 delete slicedDefault;
2899
2900 slicedDefault = myData.getSlice(region);
2901
2902 //cout << slicedDefault->toString() << endl;
2903
2904 myDataSliced=dynamic_cast<const DataTagged*>(slicedDefault);
2905
2906 CPPUNIT_ASSERT(myDataSliced->getTagLookup().size()==0);
2907
2908 CPPUNIT_ASSERT(myDataSliced->getLength()==1);
2909
2910 CPPUNIT_ASSERT(myDataSliced->getRank()==0);
2911 CPPUNIT_ASSERT(myDataSliced->getNoValues()==1);
2912 CPPUNIT_ASSERT(myDataSliced->getShape().size()==0);
2913
2914
2915 // myDataView = myDataSliced->getDefaultValue();
2916 offset=myDataSliced->getDefaultOffset();
2917 CPPUNIT_ASSERT(offset==0);
2918 CPPUNIT_ASSERT(myDataSliced->getVectorRO()[0]==26);
2919 delete slicedDefault;
2920 }
2921
2922 {
2923
2924 cout << "\tTest slicing DataTagged with scalar values and one tag." << endl;
2925
2926 DataTagged::TagListType keys;
2927 keys.push_back(1);
2928
2929 DataTagged::ValueBatchType values;
2930
2931 DataTypes::ShapeType viewShape;
2932
2933 // default value
2934 DataTypes::ValueType viewData(1*2);
2935 viewData[0]=0.0;
2936 // DataArrayView myView(viewData,viewShape);
2937
2938 // value for tag "1"
2939 // DataTypes::ValueType eOneData(viewData);
2940 // DataArrayView eOneView(eOneData, viewShape);
2941 viewData[1]=1.0;
2942 // values.push_back(eOneView);
2943
2944 DataTagged myData(FunctionSpace(),viewShape,keys, viewData);
2945
2946 //cout << myData.toString() << endl;
2947
2948 // full slice
2949
2950 DataTypes::RegionType region;
2951
2952 DataAbstract* slicedDefault = myData.getSlice(region);
2953
2954 //cout << slicedDefault->toString() << endl;
2955
2956 const DataTagged* myDataSliced=dynamic_cast<const DataTagged*>(slicedDefault);
2957
2958 CPPUNIT_ASSERT(myDataSliced->getTagLookup().size()==1);
2959
2960 CPPUNIT_ASSERT(myDataSliced->getLength()==2);
2961
2962 // DataArrayView myDataView = myDataSliced->getDefaultValue();
2963 int offset=myDataSliced->getDefaultOffset();
2964 CPPUNIT_ASSERT(offset==0);
2965 CPPUNIT_ASSERT(myDataSliced->getRank()==0);
2966 CPPUNIT_ASSERT(myDataSliced->getNoValues()==1);
2967 CPPUNIT_ASSERT(myDataSliced->getShape().size()==0);
2968 CPPUNIT_ASSERT(myDataSliced->getVectorRO()[offset]==0);
2969
2970 // myDataView = myDataSliced->getDataPointByTag(1);
2971 offset=myDataSliced->getOffsetForTag(1);
2972 CPPUNIT_ASSERT(offset==1);
2973 CPPUNIT_ASSERT(myDataSliced->getVectorRO()[offset]==1);
2974
2975 delete slicedDefault;
2976
2977 }
2978
2979 {
2980
2981 cout << "\tTest slicing DataTagged with rank 1 values and one tag." << endl;
2982
2983 DataTypes::ShapeType viewShape;
2984 viewShape.push_back(3);
2985
2986 DataTagged::TagListType keys;
2987 keys.push_back(1);
2988
2989 DataTagged::ValueBatchType values;
2990
2991 // default value
2992 DataTypes::ValueType viewData(3*2);
2993 for (int i=0;i<viewShape[0];i++) {
2994 viewData[i]=i;
2995 }
2996 // DataArrayView myView(viewData,viewShape);
2997
2998 // value for tag "1"
2999 // DataTypes::ValueType eOneData(viewData);
3000 // DataArrayView eOneView(eOneData, viewShape);
3001 for (int i=0;i<viewShape[0];i++) {
3002 // eOneView(i)=i+3.0;
3003 viewData[viewShape[0]+i]=i+3.0;
3004 }
3005 // values.push_back(eOneView);
3006
3007 DataTagged myData(FunctionSpace(),viewShape,keys,viewData);
3008
3009 //cout << myData.toString() << endl;
3010
3011 // full slice
3012
3013 std::pair<int, int> region_element;
3014 region_element.first=0;
3015 region_element.second=3;
3016 DataTypes::RegionType region;
3017 region.push_back(region_element);
3018
3019 DataAbstract* slicedDefault = myData.getSlice(region);
3020
3021 //cout << slicedDefault->toString() << endl;
3022
3023 const DataTagged* myDataSliced=dynamic_cast<const DataTagged*>(slicedDefault);
3024
3025 CPPUNIT_ASSERT(myDataSliced->getTagLookup().size()==1);
3026
3027 CPPUNIT_ASSERT(myDataSliced->getLength()==6);
3028 CPPUNIT_ASSERT(myDataSliced->getRank()==1);
3029 CPPUNIT_ASSERT(myDataSliced->getNoValues()==3);
3030 CPPUNIT_ASSERT(myDataSliced->getShape().size()==1);
3031 // DataArrayView myDataView = myDataSliced->getDefaultValue();
3032 int offset=myDataSliced->getDefaultOffset();
3033 CPPUNIT_ASSERT(offset==0);
3034 CPPUNIT_ASSERT(getRefRO(*myDataSliced,offset,0)==0);
3035 CPPUNIT_ASSERT(getRefRO(*myDataSliced,offset,1)==1);
3036 CPPUNIT_ASSERT(getRefRO(*myDataSliced,offset,2)==2);
3037
3038 // myDataView = myDataSliced->getDataPointByTag(1);
3039 offset=myDataSliced->getOffsetForTag(1);
3040 CPPUNIT_ASSERT(offset==3);
3041 CPPUNIT_ASSERT(getRefRO(*myDataSliced,offset,0)==3);
3042 CPPUNIT_ASSERT(getRefRO(*myDataSliced,offset,1)==4);
3043 CPPUNIT_ASSERT(getRefRO(*myDataSliced,offset,2)==5);
3044
3045 // scalar slice
3046
3047 region_element.first=1;
3048 region_element.second=1;
3049 region.clear();
3050 region.push_back(region_element);
3051
3052 delete slicedDefault;
3053
3054 slicedDefault = myData.getSlice(region);
3055
3056 //cout << slicedDefault->toString() << endl;
3057
3058 myDataSliced=dynamic_cast<const DataTagged*>(slicedDefault);
3059
3060 CPPUNIT_ASSERT(myDataSliced->getTagLookup().size()==1);
3061
3062 CPPUNIT_ASSERT(myDataSliced->getLength()==2);
3063
3064 CPPUNIT_ASSERT(myDataSliced->getRank()==0);
3065 CPPUNIT_ASSERT(myDataSliced->getNoValues()==1);
3066 CPPUNIT_ASSERT(myDataSliced->getShape().size()==0);
3067
3068
3069 // myDataView = myDataSliced->getDefaultValue();
3070 offset=myDataSliced->getDefaultOffset();
3071 CPPUNIT_ASSERT(offset==0);
3072 CPPUNIT_ASSERT(myDataSliced->getVectorRO()[offset]==1);
3073
3074 // myDataView = myDataSliced->getDataPointByTag(1);
3075 offset=myDataSliced->getOffsetForTag(1);
3076 CPPUNIT_ASSERT(offset==1);
3077 CPPUNIT_ASSERT(myDataSliced->getVectorRO()[offset]==4);
3078 delete slicedDefault;
3079
3080 }
3081
3082 {
3083
3084 cout << "\tTest slicing DataTagged with rank 3 values and one tag." << endl;
3085 DataTypes::ShapeType viewShape;
3086 viewShape.push_back(3);
3087 viewShape.push_back(3);
3088 viewShape.push_back(3);
3089
3090 DataTagged::TagListType keys;
3091 keys.push_back(1);
3092
3093 DataTagged::ValueBatchType values;
3094
3095 // default value
3096 DataTypes::ValueType viewData(27*2);
3097 for (int i=0;i<noValues(viewShape);i++) {
3098 viewData[i]=i;
3099 }
3100 // DataArrayView myView(viewData,viewShape);
3101
3102 // value for tag "1"
3103 // DataTypes::ValueType viewData1(27);
3104 for (int i=0;i<noValues(viewShape);i++) {
3105 viewData[noValues(viewShape)+i]=i+27.0;
3106 }
3107 // DataArrayView myView1(viewData1,viewShape);
3108 // values.push_back(myView1);
3109
3110 DataTagged myData(FunctionSpace(),viewShape,keys,viewData);
3111
3112 //cout << myData.toString() << endl;
3113
3114 // full slice
3115
3116 std::pair<int, int> region_element;
3117 region_element.first=0;
3118 region_element.second=3;
3119 DataTypes::RegionType region;
3120 region.push_back(region_element);
3121 region.push_back(region_element);
3122 region.push_back(region_element);
3123
3124 DataAbstract* slicedDefault = myData.getSlice(region);
3125
3126 //cout << slicedDefault->toString() << endl;
3127
3128 const DataTagged* myDataSliced=dynamic_cast<const DataTagged*>(slicedDefault);
3129
3130 CPPUNIT_ASSERT(myDataSliced->getTagLookup().size()==1);
3131
3132 CPPUNIT_ASSERT(myDataSliced->getLength()==54);
3133
3134 CPPUNIT_ASSERT(myDataSliced->getRank()==3);
3135 CPPUNIT_ASSERT(myDataSliced->getNoValues()==27);
3136 CPPUNIT_ASSERT(myDataSliced->getShape().size()==3);
3137
3138 // DataArrayView myDataView = myDataSliced->getDefaultValue();
3139 int offset=myDataSliced->getDefaultOffset();
3140 CPPUNIT_ASSERT(offset==0);
3141
3142 // myDataView = myDataSliced->getDataPointByTag(1);
3143 offset=myDataSliced->getOffsetForTag(1);
3144 CPPUNIT_ASSERT(offset==27);
3145
3146