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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2105 - (hide annotations)
Fri Nov 28 01:52:12 2008 UTC (10 years, 10 months ago) by jfenwick
File size: 34569 byte(s)
Data::copySelf() now returns an object instead of a pointer.
Fixed a bug in copyFromArray relating to expanded data.
1 ksteube 1312
2     /*******************************************************
3 ksteube 1811 *
4     * Copyright (c) 2003-2008 by University of Queensland
5     * Earth Systems Science Computational Center (ESSCC)
6     * http://www.uq.edu.au/esscc
7     *
8     * Primary Business: Queensland, Australia
9     * Licensed under the Open Software License version 3.0
10     * http://www.opensource.org/licenses/osl-3.0.php
11     *
12     *******************************************************/
13 ksteube 1312
14 ksteube 1811
15 woo409 757 #include <iostream>
16 phornby 2051 #if defined (_WIN32) && defined (__INTEL_COMPILER)
17 woo409 757 #include <mathimf.h>
18     #else
19     #include <math.h>
20     #endif
21 jgs 511
22     #include "DataTestCase.h"
23    
24 robwdcock 670 #include "escript/FunctionSpace.h"
25 robwdcock 638 #include "esysUtils/EsysException.h"
26 jgs 82
27 robwdcock 670 #include "escript/Data.h"
28 jfenwick 2005 #include "escript/DataLazy.h"
29 jgs 537
30 jgs 82
31     using namespace std;
32     using namespace CppUnitTest;
33     using namespace escript;
34     using namespace esysUtils;
35 jfenwick 1796 using namespace escript::DataTypes;
36 jgs 82
37     void DataTestCase::setUp() {
38     //
39     // This is called before each test is run
40     }
41    
42     void DataTestCase::tearDown() {
43     //
44     // This is called after each test has been run
45     }
46    
47 jfenwick 1796
48    
49     namespace
50     {
51    
52     inline
53     DataTypes::ValueType::reference
54     getRef(Data& d,int s1, int p1, int x, int y)
55     {
56     return d.getDataAtOffset(d.getDataOffset(s1,p1)+getRelIndex(d.getDataPointShape(),x,y));
57     }
58    
59     inline
60     DataTypes::ValueType::reference
61     getRef(Data& d, int x, int y)
62     {
63     return d.getDataAtOffset(getRelIndex(d.getDataPointShape(),x,y));
64     }
65    
66     }
67    
68 jfenwick 2005
69     void DataTestCase::testCopyingWorker(bool delayed)
70 jfenwick 1799 {
71 jfenwick 2005
72 jfenwick 1799 using namespace escript::DataTypes;
73     cout << endl;
74 jfenwick 2005
75     DataTypes::ShapeType shape;
76     shape.push_back(2);
77     shape.push_back(3);
78     DataTypes::ValueType data(DataTypes::noValues(shape),1);
79     const int NUMDATS=3;
80     Data* dats[NUMDATS];
81     const char* strs[]={"DataConstant", "DataTagged", "DataExpanded"};
82     dats[0]=new Data(new DataConstant(FunctionSpace(),shape,data));
83     dats[1]=new Data(new DataTagged(FunctionSpace(),shape,data));
84     dats[2]=new Data(new DataExpanded(FunctionSpace(),shape,data));
85     if (delayed)
86 jfenwick 1799 {
87 jfenwick 2005 dats[0]->delaySelf();
88     dats[1]->delaySelf();
89     dats[2]->delaySelf();
90 jfenwick 1799 }
91    
92 jfenwick 2005 for (int k=0;k<NUMDATS;++k)
93 jfenwick 1799 {
94 jfenwick 2005 cout << "\tTest deep copy " << strs[k] << endl;
95     Data* d=dats[k];
96 jfenwick 2105 Data deep=d->copySelf(); // test self copy
97 jfenwick 2005 if (delayed)
98 jfenwick 1799 {
99 jfenwick 2105 assert(deep.isLazy());
100 jfenwick 1799 }
101     for (int i=0;i<DataTypes::noValues(shape);++i)
102     {
103 jfenwick 2105 if (d->getDataAtOffset(i)!=deep.getDataAtOffset(i))
104 jfenwick 1799 assert(false);
105     }
106 jfenwick 2005 if (delayed)
107 jfenwick 1799 {
108 jfenwick 2005 d->delaySelf();
109 jfenwick 1799 }
110 jfenwick 2005 d->setToZero();
111     if (delayed)
112 jfenwick 1799 {
113 jfenwick 2005 assert(d->isLazy());
114 jfenwick 1799 }
115     for (int i=0;i<DataTypes::noValues(shape);++i)
116     {
117 jfenwick 2105 if (d->getDataAtOffset(i)==deep.getDataAtOffset(i))
118 jfenwick 1799 assert(false);
119     }
120 jfenwick 2005 if (delayed)
121 jfenwick 1799 {
122 jfenwick 2005 d->delaySelf();
123 jfenwick 2105 deep.delaySelf();
124 jfenwick 1799 }
125 jfenwick 2105 d->copy(deep); // test copy from object
126 jfenwick 2005 if (delayed)
127     {
128     assert(d->isLazy());
129     }
130 jfenwick 1799 for (int i=0;i<DataTypes::noValues(shape);++i)
131     {
132 jfenwick 2105 if (d->getDataAtOffset(i)!=deep.getDataAtOffset(i))
133 jfenwick 1799 assert(false);
134     }
135 jfenwick 2005 d->setToZero();
136 jfenwick 1799 for (int i=0;i<DataTypes::noValues(shape);++i)
137     {
138 jfenwick 2105 if (d->getDataAtOffset(i)==deep.getDataAtOffset(i))
139 jfenwick 1799 assert(false);
140     }
141 jfenwick 2005 delete dats[k];
142 jfenwick 1799 }
143    
144    
145 jgs 82
146    
147 jgs 537
148    
149 jfenwick 2005 }
150 jgs 537
151    
152 jfenwick 2005 void DataTestCase::testSlicingWorker(bool delayed)
153     {
154 jgs 537
155 jfenwick 2005 using namespace escript::DataTypes;
156     cout << endl;
157     {
158     DataTypes::ShapeType viewShape;
159     viewShape.push_back(2);
160     viewShape.push_back(3);
161 jgs 537
162 jfenwick 2005 const int NUMDATS=3;
163     const char* strs[]={"DataConstant", "DataTagged","DataExpanded"};
164     bool tags[]={false,true,false}; // is the slice of this data supposed to be tagged
165     Data* dats[NUMDATS];
166     for (int k=0;k<NUMDATS;++k)
167     {
168     dats[k]=new Data(1.3, viewShape);
169     }
170     dats[1]->tag();
171     dats[2]->expand();
172     for (int k=0;k<NUMDATS;++k)
173     {
174     Data* temp=dats[k];
175     dats[k]=new Data(dats[k]->delay());
176     delete temp;
177     }
178     for (int k=0;k<NUMDATS;++k)
179     {
180     cout << "\t\tTest get-slicing " << strs[k] << endl;
181     dats[k]->getDataAtOffset(dats[k]->getDataOffset(0,0)+getRelIndex(viewShape,0,0))=1.0;
182     dats[k]->getDataAtOffset(dats[k]->getDataOffset(0,0)+getRelIndex(viewShape,1,1))=2.0;
183 jgs 537
184 jfenwick 2005 DataTypes::RegionType region;
185     region.push_back(DataTypes::RegionType::value_type(0,0));
186     region.push_back(DataTypes::RegionType::value_type(0,0));
187 jgs 537
188 jfenwick 2005 Data slice1(dats[k]->getSlice(region));
189 jgs 537
190 jfenwick 2005 if (tags[k]) {assert(slice1.isTagged());}
191     assert(slice1.getDataPointRank()==0);
192     assert(slice1.getDataPoint(0,0)==1.0);
193 jgs 537
194 jfenwick 2005 //
195     // create a rank 2 slice with one value
196    
197     region.clear();
198     region.push_back(DataTypes::RegionType::value_type(0,1));
199     region.push_back(DataTypes::RegionType::value_type(0,1));
200    
201     Data slice2(dats[k]->getSlice(region));
202    
203     //cout << slice2.toString() << endl;
204    
205     if (tags[k]) {assert(slice2.isTagged());}
206     assert(slice2.getDataPointRank()==2);
207    
208     assert(slice2.getDataAtOffset(slice2.getDataOffset(0,0)+getRelIndex(slice2.getDataPointShape(),0,0))==1.0);
209 jgs 537
210 jfenwick 2005 //
211     // create a rank 2 slice with four values
212    
213     region.clear();
214     region.push_back(DataTypes::RegionType::value_type(0,2));
215     region.push_back(DataTypes::RegionType::value_type(0,2));
216    
217     Data slice3(dats[k]->getSlice(region));
218    
219     //cout << slice3.toString() << endl;
220    
221     if (tags[k]) {assert(slice3.isTagged());}
222     assert(slice3.getDataPointRank()==2);
223     assert(getRef(slice3,0,0,0,0)==1.0);
224     assert(getRef(slice3,0,0,0,1)==1.3);
225     assert(getRef(slice3,0,0,1,0)==1.3);
226     assert(getRef(slice3,0,0,1,1)==2.0);
227     }
228 jgs 537
229 jfenwick 2005 // now some extra tests for tagged data (dats[1])
230 jgs 537
231 jfenwick 2005 //
232     // add a value for tag "1"
233 jgs 537
234 jfenwick 2005 DataTypes::ValueType viewData(6);
235     for (int i=0;i<viewData.size();i++) {
236     viewData[i]=i;
237     }
238     dats[1]->setTaggedValueFromCPP(1, viewShape, viewData);
239 jgs 537
240 jfenwick 2005 //
241     // create a full slice
242 jgs 537
243 jfenwick 2005 DataTypes::RegionType region;
244     region.push_back(DataTypes::RegionType::value_type(0,2));
245     region.push_back(DataTypes::RegionType::value_type(0,3));
246 jgs 82
247 jfenwick 2005 Data slice4(dats[1]->getSlice(region));
248 jgs 537
249 jfenwick 2005 assert(slice4.isTagged());
250     assert(slice4.getDataPointRank()==2);
251     assert(getRef(slice4,0,0,0,0)==0);
252     assert(getRef(slice4,0,0,0,1)==2);
253     assert(getRef(slice4,0,0,0,2)==4);
254     assert(getRef(slice4,0,0,1,0)==1);
255     assert(getRef(slice4,0,0,1,1)==3);
256     assert(getRef(slice4,0,0,1,2)==5);
257 jgs 537
258 jfenwick 2005 for (int k=0;k<NUMDATS;++k)
259     {
260     delete dats[k];
261     }
262     }
263 jgs 537
264 jfenwick 2005 {
265     DataTypes::ShapeType viewShape;
266     viewShape.push_back(2);
267     viewShape.push_back(3);
268 jgs 537
269 jfenwick 2005 const int NUMDATS=3;
270     const char* strs[]={"DataConstant", "DataTagged","DataExpanded"};
271     Data* dats[NUMDATS];
272     Data* src[NUMDATS];
273     for (int k=0;k<NUMDATS;++k)
274     {
275     dats[k]=new Data(1.3, viewShape);
276     src[k]=new Data(10,DataTypes::scalarShape);
277 jgs 537 }
278 jfenwick 2005 dats[1]->tag();
279     src[1]->tag();
280     dats[2]->expand();
281     src[2]->expand();
282     if (delayed)
283 jgs 537 {
284 jfenwick 2005 for(int k=0;k<NUMDATS;++k)
285     {
286     if (delayed)
287     {
288     Data* temp=dats[k];
289     dats[k]=new Data(dats[k]->delay()); // coz delay returns an object not a pointer
290     delete temp;
291     temp=src[k];
292     src[k]=new Data(src[k]->delay());
293     delete temp;
294     }
295 jgs 537 }
296 jgs 82 }
297 jfenwick 2005 for (int k=0;k<NUMDATS;++k)
298 jgs 82 {
299 jfenwick 2005 cout << "\t\tTest set-slicing " << strs[k] << endl;
300     Data target(1.3,viewShape);
301     if (k==2) {target.expand();}
302     DataTypes::RegionType region;
303     region.push_back(DataTypes::RegionType::value_type(1,1));
304     region.push_back(DataTypes::RegionType::value_type(1,1));
305     target.setSlice(*(src[k]),region);
306     assert(getRef(target,0,0,1,1)==src[k]->getDataPoint(0,0));
307     }
308    
309     // some extra tests on tagged data
310 jgs 537
311 jfenwick 2005 //
312     // add a value for tag "1" to target
313 jgs 537
314 jfenwick 2005 DataTypes::ValueType viewData(6);
315     for (int i=0;i<viewData.size();i++) {
316     viewData[i]=i;
317     }
318 jgs 537
319 jfenwick 2005 Data target(1.3,viewShape,FunctionSpace(),false);
320     target.tag();
321     target.setTaggedValueFromCPP(1, viewShape, viewData);
322 jgs 537
323 jgs 549 //cout << "target:\n" << target.toString() << endl;
324 jgs 537
325 jgs 82 //
326 jgs 537 // set a slice in target from source
327    
328 jfenwick 2005 DataTypes::RegionType region;
329     region.push_back(DataTypes::RegionType::value_type(0,0));
330     region.push_back(DataTypes::RegionType::value_type(1,1));
331 jgs 537
332 jfenwick 2005 target.setSlice(*src[1],region);
333 jgs 537
334 jfenwick 2005 assert(target.isTagged());
335     assert(target.getDataPointRank()==2);
336     assert(getRef(target,0,0,0,0)==0);
337     assert(getRef(target,0,0,0,1)==src[1]->getDataPoint(0,0));
338     assert(getRef(target,0,0,0,2)==4);
339     assert(getRef(target,0,0,1,0)==1);
340     assert(getRef(target,0,0,1,1)==3);
341     assert(getRef(target,0,0,1,2)==5);
342 jgs 537
343 jfenwick 2005 //
344     // add a value for tag "2" to source
345 jgs 537
346 jfenwick 2005 DataTypes::ShapeType viewShape2;
347     DataTypes::ValueType viewData2(1);
348     viewData2[0]=6;
349     src[1]->setTaggedValueFromCPP(2, viewShape2, viewData2);
350 jgs 537
351 jfenwick 2005 region.clear();
352     region.push_back(DataTypes::RegionType::value_type(0,0));
353     region.push_back(DataTypes::RegionType::value_type(1,1));
354 jgs 537
355 jfenwick 2005 target.setSlice(*src[1],region);
356 jgs 549
357 jfenwick 2005 assert(target.isTagged());
358     assert(target.getDataPointRank()==2);
359 jgs 537
360 jgs 549 // use a non-existant tag so we get a pointer to the default value
361     // ie: the first element in the data array
362 jfenwick 2005 DataAbstract::ValueType::value_type* targetData=target.getSampleDataByTag(9);
363     for (int i=0; i<target.getLength(); i++) {
364 jgs 549 assert(targetData[i]>=0);
365 jgs 537 }
366 jfenwick 2005 assert(targetData[0]==1.3);
367     assert(targetData[1]==1.3);
368     assert(targetData[2]==10);
369     assert(targetData[3]==1.3);
370     assert(targetData[4]==1.3);
371     assert(targetData[5]==1.3);
372     assert(targetData[6]==0);
373     assert(targetData[7]==1);
374     assert(targetData[8]==10);
375     assert(targetData[9]==3);
376     assert(targetData[10]==4);
377     assert(targetData[11]==5);
378     assert(targetData[12]==1.3);
379     assert(targetData[13]==1.3);
380     assert(targetData[14]==6);
381     assert(targetData[15]==1.3);
382     assert(targetData[16]==1.3);
383     assert(targetData[17]==1.3);
384 jgs 537
385 jfenwick 2005
386     for (int k=0;k<NUMDATS;++k)
387 jgs 537 {
388 jfenwick 2005 delete dats[k];
389     delete src[k];
390 jgs 82 }
391    
392 jfenwick 2005 }
393 jgs 82
394 jfenwick 2005 }
395 jgs 537
396 jfenwick 2005 // This is to test new copy routines, existing tests should remain where they are
397     void DataTestCase::testCopying()
398     {
399     cout << "\n\tReadyData." << endl;
400     testCopyingWorker(false);
401     cout << "\n\tLazyData." << endl;
402     testCopyingWorker(true);
403 jgs 82 }
404    
405 jfenwick 2005 void DataTestCase::testSlicing() {
406     cout << "\n\tReadyData." << endl;
407     testSlicingWorker(false);
408     cout << "\n\tLazyData." << endl;
409     testSlicingWorker(true);
410 jgs 82 }
411    
412 jfenwick 2005 void DataTestCase::testSome() {
413 jgs 82
414     cout << endl;
415    
416 jfenwick 2005 cout << "\tCreate a Data object." << endl;
417 jgs 82
418 jfenwick 1796 DataTypes::ShapeType viewShape;
419 jgs 82 viewShape.push_back(3);
420 jfenwick 1796 DataTypes::ValueType viewData(3);
421 jgs 82 for (int i=0;i<viewShape[0];++i) {
422 jgs 121 viewData[i]=i;
423 jgs 82 }
424    
425     bool expanded=true;
426 jfenwick 1796 Data exData(viewData,viewShape,FunctionSpace(),expanded);
427     Data cData(viewData,viewShape);
428 jgs 82 Data result;
429 jgs 123
430 jgs 82 assert(exData.isExpanded());
431     assert(cData.isConstant());
432     assert(result.isEmpty());
433    
434     cout << "\tTest some basic operations" << endl;
435     result=exData*cData;
436     assert(result.isExpanded());
437    
438 jgs 538 assert(result.Lsup()==4);
439     assert(result.sup()==4);
440     assert(result.inf()==0);
441    
442     result=exData+cData;
443     result=exData-cData;
444     result=exData/cData;
445    
446     cout << "\tExercise wherePositive method" << endl;
447     assert(!exData.wherePositive().isEmpty());
448    
449     cout << "\tExercise copyWithMask method" << endl;
450     exData.copyWithMask(result, exData.wherePositive());
451     assert(!exData.wherePositive().isEmpty());
452    
453 jgs 82 }
454    
455 jfenwick 2005
456    
457     // This method tests to see if resolve() produces results of the correct type
458     void DataTestCase::testResolveType()
459     {
460     cout << endl;
461     cout << "\tTesting resolve()\n";
462     DataTypes::ShapeType viewShape;
463     viewShape.push_back(2);
464     viewShape.push_back(3);
465     viewShape.push_back(4);
466     DataTypes::ValueType viewData(2*3*4);
467     for (int i=0;i<DataTypes::noValues(viewShape);++i) {
468     viewData[i]=i;
469     }
470     Data c1(viewData,viewShape);
471     Data t1(viewData,viewShape);
472     Data e1(viewData,viewShape);
473     t1.tag();
474     e1.expand();
475     c1.delaySelf();
476     t1.delaySelf();
477     e1.delaySelf();
478     Data d1=c1+c1;
479     assert(d1.isLazy());
480     assert((d1.resolve(),d1.isConstant()));
481     d1=c1+t1;
482     assert(d1.isLazy());
483     assert((d1.resolve(),d1.isTagged()));
484     d1=t1+c1;
485     assert(d1.isLazy());
486     assert((d1.resolve(),d1.isTagged()));
487     d1=t1+t1;
488     assert(d1.isLazy());
489     assert((d1.resolve(),d1.isTagged()));
490     d1=c1+e1;
491     assert(d1.isLazy());
492     assert((d1.resolve(),d1.isExpanded()));
493     d1=e1+c1;
494     assert(d1.isLazy());
495     assert((d1.resolve(),d1.isExpanded()));
496     d1=e1+t1;
497     assert(d1.isLazy());
498     assert((d1.resolve(),d1.isExpanded()));
499     d1=t1+e1;
500     assert(d1.isLazy());
501     assert((d1.resolve(),d1.isExpanded()));
502     d1=e1+e1;
503     assert(d1.isLazy());
504     assert((d1.resolve(),d1.isExpanded()));
505     cout << "\tTesting tag()\n";
506     c1.tag();
507     assert(c1.isTagged());
508     t1.tag();
509     assert(t1.isTagged());
510     try
511     {
512     e1.tag();
513     assert(false); // this should have thrown
514     } catch(...) {}
515     cout << "\tTesting expand()\n";
516     Data c2(viewData,viewShape);
517     Data t2(viewData,viewShape);
518     Data e2(viewData,viewShape);
519     t2.tag();
520     e2.expand();
521     c2.delaySelf();
522     t2.delaySelf();
523     e2.delaySelf();
524     c2.expand();
525     assert(c2.isExpanded());
526     t2.expand();
527     assert(t2.isExpanded());
528     e2.expand();
529     assert(e2.isExpanded());
530     }
531    
532 jgs 82 void DataTestCase::testDataConstant() {
533    
534     cout << endl;
535    
536 jfenwick 2005 cout << "\tCreate a DataConstant object." << endl;
537 jgs 82
538 jfenwick 1796 DataTypes::ShapeType viewShape;
539 jgs 82 viewShape.push_back(2);
540     viewShape.push_back(3);
541     viewShape.push_back(4);
542 jfenwick 1796 DataTypes::ValueType viewData(2*3*4);
543     for (int i=0;i<DataTypes::noValues(viewShape);++i) {
544 jgs 121 viewData[i]=i;
545 jgs 82 }
546    
547 jfenwick 1796 Data left(viewData,viewShape);
548     Data right(viewData,viewShape);
549 jgs 82 Data result;
550    
551     cout << "\tTest some basic operations" << endl;
552    
553     result=left-right;
554    
555     assert(left.isConstant());
556     assert(right.isConstant());
557     assert(result.isConstant());
558    
559     result=left+right;
560    
561     assert(left.isConstant());
562     assert(right.isConstant());
563     assert(result.isConstant());
564    
565     assert(!result.isExpanded());
566     assert(!result.isTagged());
567    
568     }
569    
570     void DataTestCase::testDataTagged() {
571    
572     cout << endl;
573    
574 jgs 539 {
575 jgs 82
576 jgs 539 cout << "\tCreate a DataTagged object with a default value only." << endl;
577 jgs 511
578 jfenwick 1796 DataTypes::ShapeType viewShape;
579 jgs 539 viewShape.push_back(3);
580 jgs 82
581 jfenwick 1796 DataTypes::ValueType viewData(3);
582 jgs 539 for (int i=0;i<viewShape[0];i++) {
583     viewData[i]=i;
584     }
585 jfenwick 1796 int arr[1]={1}; // iso c++ does not like empty arrays
586     DataTagged* dt=new DataTagged(FunctionSpace(),viewShape,arr,viewData);
587     Data myData(dt);
588 jgs 511
589 jgs 539 assert(!myData.isEmpty());
590     assert(myData.isTagged());
591     assert(myData.getTagNumber(0)==1);
592     assert(myData.getDataPointRank()==1);
593     assert(myData.getLength()==3);
594 jfenwick 1796
595     assert(myData.getNoValues()==3);
596     assert(myData.getDataAtOffset(0)==0.0);
597     assert(myData.getDataAtOffset(1)==1.0);
598     assert(myData.getDataAtOffset(2)==2.0);
599 jgs 82
600 jgs 539 double* sampleData=myData.getSampleData(0);
601 jfenwick 1796 for (int i=0; i<myData.getNoValues(); i++) {
602 jgs 539 assert(sampleData[i]==i);
603     }
604     // use a non-existent tag so we get a pointer to
605     // the first element of the data array
606     sampleData=myData.getSampleDataByTag(9);
607     for (int i=0; i<myData.getLength(); i++) {
608     assert(sampleData[i]==i);
609     }
610 jgs 511
611 jgs 539 cout << "\tTest setting of a tag and associated value." << endl;
612 jgs 511
613 jgs 539 // value for tag "1"
614 jfenwick 1796 DataTypes::ValueType eTwoData(viewData);
615     // DataArrayView eTwoView(eTwoData, viewShape);
616     for (int i=0;i<viewShape[0];i++) {
617     eTwoData[i]=i+2.0;
618 jgs 539 }
619    
620 jfenwick 1796 myData.setTaggedValueFromCPP(1,viewShape, eTwoData);
621 jgs 539
622     assert(myData.getLength()==6);
623    
624 jfenwick 1796 int offset=myData.getDataOffset(0,0);
625     assert(offset==3);
626     assert(myData.getDataPointRank()==1);
627     assert(myData.getNoValues()==3);
628 jgs 539
629 jfenwick 1796 assert(myData.getDataAtOffset(offset+0)==2);
630     assert(myData.getDataAtOffset(offset+1)==3);
631     assert(myData.getDataAtOffset(offset+2)==4);
632    
633 jgs 539 sampleData=myData.getSampleDataByTag(1);
634 jfenwick 1796 for (int i=0; i<myData.getNoValues(); i++) {
635 jgs 539 assert(sampleData[i]==i+2);
636     }
637    
638 jgs 511 }
639    
640 jgs 539 {
641 jgs 511
642 jgs 539 cout << "\tCreate a DataTagged object via tag() method." << endl;
643 jgs 511
644 jfenwick 1796 DataTypes::ShapeType viewShape;
645 jgs 539 viewShape.push_back(2);
646     viewShape.push_back(3);
647     Data myData(1.3,viewShape,FunctionSpace(),false);
648     myData.tag();
649 jgs 511
650 jgs 539 assert(!myData.isEmpty());
651     assert(myData.isTagged());
652     assert(myData.getTagNumber(0)==1);
653     assert(myData.getDataPointRank()==2);
654     assert(myData.getLength()==6);
655    
656     // check default value
657 jfenwick 1796 assert(!myData.isEmpty());
658     assert(myData.getDataPointRank()==2);
659     assert(myData.getNoValues()==6);
660     assert(myData.getDataPointShape().size()==2);
661     assert(getRef(myData,0,0)==1.3);
662     assert(getRef(myData,0,1)==1.3);
663     assert(getRef(myData,0,2)==1.3);
664     assert(getRef(myData,1,0)==1.3);
665     assert(getRef(myData,1,1)==1.3);
666     assert(getRef(myData,1,2)==1.3);
667 jgs 539
668     // check value for data-point (0,0).
669 jfenwick 1796 // myDataView = myData.getDataPoint(0,0);
670     assert(!myData.isEmpty());
671     // assert(myDataView.getOffset()==0);
672     assert(myData.getDataPointRank()==2);
673     assert(myData.getNoValues()==6);
674     assert(myData.getDataPointShape().size()==2);
675     assert(getRef(myData,0,0)==1.3);
676     assert(getRef(myData,0,1)==1.3);
677     assert(getRef(myData,0,2)==1.3);
678     assert(getRef(myData,1,0)==1.3);
679     assert(getRef(myData,1,1)==1.3);
680     assert(getRef(myData,1,2)==1.3);
681 jgs 539
682 jgs 511 }
683    
684 jgs 82 }
685    
686 jgs 538 void DataTestCase::testDataTaggedExceptions() {
687    
688     cout << endl;
689    
690     cout << "\tTest DataTagged exceptions." << endl;
691    
692     Data myData;
693    
694     try {
695     myData.getSampleDataByTag(0);;
696     assert(false);
697     }
698 phornby 1455 catch (EsysException&) {
699 jgs 538 //cout << e.what() << endl;
700     assert(true);
701     }
702    
703     try {
704 jfenwick 1796 myData.setTaggedValueFromCPP(0,DataTypes::ShapeType(), DataTypes::ValueType());;
705 jgs 538 assert(false);
706     }
707 phornby 1455 catch (EsysException&) {
708 jgs 538 //cout << e.what() << endl;
709     assert(true);
710     }
711    
712     }
713    
714 jgs 82 void DataTestCase::testConstructors() {
715    
716     cout << endl;
717    
718 jfenwick 1796 DataTypes::ShapeType viewShape;
719 jgs 82 {
720     cout << "\tCreate an Empty Data object" << endl;
721     Data temp(1.3,viewShape,FunctionSpace(),false);
722     }
723     {
724     cout << "\tCreate a rank 2 Data object" << endl;
725     viewShape.push_back(2);
726     viewShape.push_back(3);
727     Data temp(1.3,viewShape,FunctionSpace(),false);
728     }
729     }
730    
731 jgs 113
732 jfenwick 2005 void DataTestCase::testOperations()
733     {
734    
735 jgs 82 cout << endl;
736    
737 jfenwick 2005 // define the shape for the test data
738 jfenwick 1796 DataTypes::ShapeType shape;
739 jgs 113 shape.push_back(2);
740     shape.push_back(3);
741 jgs 82
742 jfenwick 2005 // allocate the data
743 jfenwick 1796 DataTypes::ValueType data(DataTypes::noValues(shape),0);
744 jgs 82
745 jgs 113 // assign values to the data
746     for (int i=0;i<shape[0];i++) {
747     for (int j=0;j<shape[1];j++) {
748 jfenwick 1796 data[getRelIndex(shape,i,j)]=getRelIndex(shape,i,j);
749 jgs 113 }
750     }
751    
752 jfenwick 2005
753    
754     Data dats[]={Data(data,shape,FunctionSpace(),false),
755     Data(data,shape,FunctionSpace(),false),
756     Data(data,shape,FunctionSpace(),true),
757     Data(data,shape,FunctionSpace(),false),
758     Data(data,shape,FunctionSpace(),false),
759     Data(data,shape,FunctionSpace(),true)};
760     const int NUMDATS=6;
761     const int LAZY=3; // where do the lazy objects start?
762    
763     // Data baseEx(data,shape,FunctionSpace(),true);
764     // Data baseCon(data,shape,FunctionSpace(),false);
765     // Data baseTag(data,shape,FunctionSpace(),false);
766     Data& baseCon=dats[0];
767     Data& baseTag=dats[1];
768     Data& baseEx=dats[2];
769 jgs 563 baseTag.tag();
770 jfenwick 2005 dats[4].tag();
771     dats[3].delaySelf();
772     dats[4].delaySelf();
773     dats[5].delaySelf();
774 jgs 113
775 jgs 563 assert(baseEx.isExpanded());
776     assert(baseCon.isConstant());
777     assert(baseTag.isTagged());
778    
779 jfenwick 2005 Data results[NUMDATS];
780 jfenwick 2037 // Data& resultEx=results[0];
781     // Data& resultCon=results[1];
782     // Data& resultTag=results[2];
783 jgs 563
784 jfenwick 2005 // create 0 <= smalldata <= 1 for testing trig functions
785    
786     DataTypes::ValueType smalldata(DataTypes::noValues(shape),0);
787    
788     // assign values to the data
789     for (int i=0;i<shape[0];i++) {
790     for (int j=0;j<shape[1];j++) {
791     smalldata[getRelIndex(shape,i,j)]=(i==0 && j==0)?0:1.0/(getRelIndex(shape,i,j)+1);
792     }
793     }
794     Data sdats[]={Data(smalldata,shape,FunctionSpace(),false),
795     Data(smalldata,shape,FunctionSpace(),false),
796     Data(smalldata,shape,FunctionSpace(),true),
797     Data(smalldata,shape,FunctionSpace(),false),
798     Data(smalldata,shape,FunctionSpace(),false),
799     Data(smalldata,shape,FunctionSpace(),true)};
800     sdats[1].tag();
801     sdats[4].tag();
802     sdats[3].delaySelf();
803     sdats[4].delaySelf();
804     sdats[5].delaySelf();
805    
806    
807    
808 jgs 113 // test unary operations
809    
810 gross 713 double tmp;
811 jgs 113 cout << "\tTest Data::pow." << endl;
812     Data power(3.0,shape,FunctionSpace(),true);
813 jfenwick 2005 for (int z=0;z<NUMDATS;++z)
814     {
815     results[z].copy(dats[z].powD(power));
816     if (z>=LAZY)
817     {
818     assert(results[z].isLazy());
819     }
820     }
821 jgs 113 for (int i=0;i<shape[0];i++) {
822     for (int j=0;j<shape[1];j++) {
823 jfenwick 1796 tmp=pow((double)data[getRelIndex(shape,i,j)],(double)3.0);
824 jfenwick 2005 for (int z=0;z<NUMDATS;++z)
825     {
826     assert(std::abs(getRef(results[z],i,j) - tmp) <= REL_TOL*std::abs(tmp));
827     }
828 jgs 113 }
829     }
830 jgs 82
831 jgs 113 cout << "\tTest Data::sin." << endl;
832 jfenwick 2005 for (int z=0;z<NUMDATS;++z)
833     {
834     results[z].copy(dats[z].sin());
835     if (z>=LAZY)
836     {
837     assert(results[z].isLazy());
838     }
839     }
840 gross 713 for (int i=0;i<shape[0];i++) {
841     for (int j=0;j<shape[1];j++) {
842 jfenwick 1796 tmp=sin((double)data[getRelIndex(shape,i,j)]);
843 jfenwick 2005 for (int z=0;z<NUMDATS;++z)
844     {
845     assert(std::abs(getRef(results[z],i,j) - tmp) <= REL_TOL*std::abs(tmp));
846     }
847 gross 713 }
848     }
849 jgs 102
850 jgs 113 cout << "\tTest Data::cos." << endl;
851 jfenwick 2005 for (int z=0;z<NUMDATS;++z)
852     {
853     results[z].copy(dats[z].cos());
854     if (z>=LAZY)
855     {
856     assert(results[z].isLazy());
857     }
858     }
859 gross 713 for (int i=0;i<shape[0];i++) {
860     for (int j=0;j<shape[1];j++) {
861 jfenwick 1796 tmp=cos((double)data[getRelIndex(shape,i,j)]);
862 jfenwick 2005 for (int z=0;z<NUMDATS;++z)
863     {
864     assert(std::abs(getRef(results[z],i,j) - tmp) <= REL_TOL*std::abs(tmp));
865     }
866 gross 713 }
867     }
868 jgs 102
869 jgs 113 cout << "\tTest Data::tan." << endl;
870 jfenwick 2005 for (int z=0;z<NUMDATS;++z)
871     {
872     results[z].copy(dats[z].tan());
873     if (z>=LAZY)
874     {
875     assert(results[z].isLazy());
876     }
877     }
878 gross 713 for (int i=0;i<shape[0];i++) {
879     for (int j=0;j<shape[1];j++) {
880 jfenwick 1796 tmp=tan((double)data[getRelIndex(shape,i,j)]);
881 jfenwick 2005 for (int z=0;z<NUMDATS;++z)
882     {
883     assert(std::abs(getRef(results[z],i,j) - tmp) <= REL_TOL*std::abs(tmp));
884     }
885 gross 713 }
886     }
887 jgs 102
888 jgs 150 cout << "\tTest Data::asin." << endl;
889 jfenwick 2005 for (int z=0;z<NUMDATS;++z)
890     {
891     results[z].copy(sdats[z].asin());
892     if (z>=LAZY)
893     {
894     assert(results[z].isLazy());
895     }
896     }
897     for (int i=0;i<shape[0];i++) {
898     for (int j=0;j<shape[1];j++) {
899     tmp=asin((double)smalldata[getRelIndex(shape,i,j)]);
900     for (int z=0;z<NUMDATS;++z)
901     {
902     assert(std::abs(getRef(results[z],i,j) - tmp) <= REL_TOL*std::abs(tmp));
903     }
904     }
905     }
906 jgs 150
907     cout << "\tTest Data::acos." << endl;
908 jfenwick 2005 for (int z=0;z<NUMDATS;++z)
909     {
910     results[z].copy(sdats[z].acos());
911     if (z>=LAZY)
912     {
913     assert(results[z].isLazy());
914     }
915     }
916     for (int i=0;i<shape[0];i++) {
917     for (int j=0;j<shape[1];j++) {
918     tmp=acos((double)smalldata[getRelIndex(shape,i,j)]);
919     for (int z=0;z<NUMDATS;++z)
920     {
921     assert(std::abs(getRef(results[z],i,j) - tmp) <= REL_TOL*std::abs(tmp));
922     }
923     }
924     }
925 jgs 150
926     cout << "\tTest Data::atan." << endl;
927 jfenwick 2005 for (int z=0;z<NUMDATS;++z)
928     {
929     results[z].copy(sdats[z].atan());
930     if (z>=LAZY)
931     {
932     assert(results[z].isLazy());
933     }
934     }
935 gross 713 for (int i=0;i<shape[0];i++) {
936     for (int j=0;j<shape[1];j++) {
937 jfenwick 2005 tmp=atan((double)smalldata[getRelIndex(shape,i,j)]);
938     for (int z=0;z<NUMDATS;++z)
939     {
940     assert(std::abs(getRef(results[z],i,j) - tmp) <= REL_TOL*std::abs(tmp));
941     }
942 gross 713 }
943     }
944 jgs 150
945     cout << "\tTest Data::sinh." << endl;
946 jfenwick 2005 for (int z=0;z<NUMDATS;++z)
947     {
948     results[z].copy(dats[z].sinh());
949     if (z>=LAZY)
950     {
951     assert(results[z].isLazy());
952     }
953     }
954 gross 713 for (int i=0;i<shape[0];i++) {
955     for (int j=0;j<shape[1];j++) {
956 jfenwick 1796 tmp=sinh((double)data[getRelIndex(shape,i,j)]);
957 jfenwick 2005 for (int z=0;z<NUMDATS;++z)
958     {
959     assert(std::abs(getRef(results[z],i,j) - tmp) <= REL_TOL*std::abs(tmp));
960     }
961 gross 713 }
962     }
963 jgs 150
964     cout << "\tTest Data::cosh." << endl;
965 jfenwick 2005 for (int z=0;z<NUMDATS;++z)
966     {
967     results[z].copy(dats[z].cosh());
968     if (z>=LAZY)
969     {
970     assert(results[z].isLazy());
971     }
972     }
973 gross 713 for (int i=0;i<shape[0];i++) {
974     for (int j=0;j<shape[1];j++) {
975 jfenwick 1796 tmp=cosh((double)data[getRelIndex(shape,i,j)]);
976 jfenwick 2005 for (int z=0;z<NUMDATS;++z)
977     {
978     assert(std::abs(getRef(results[z],i,j) - tmp) <= REL_TOL*std::abs(tmp));
979     }
980 gross 713 }
981     }
982 jgs 150
983     cout << "\tTest Data::tanh." << endl;
984 jfenwick 2005 for (int z=0;z<NUMDATS;++z)
985     {
986     results[z].copy(dats[z].tanh());
987     if (z>=LAZY)
988     {
989     assert(results[z].isLazy());
990     }
991     }
992 gross 713 for (int i=0;i<shape[0];i++) {
993     for (int j=0;j<shape[1];j++) {
994 jfenwick 1796 tmp=tanh((double)data[getRelIndex(shape,i,j)]);
995 jfenwick 2005 for (int z=0;z<NUMDATS;++z)
996     {
997     assert(std::abs(getRef(results[z],i,j) - tmp) <= REL_TOL*std::abs(tmp));
998     }
999 gross 713 }
1000     }
1001 jgs 150
1002 jfenwick 2005 // rather than accomodate the different windows operations directly I'll just use inverse functions
1003 jgs 150 cout << "\tTest Data::asinh." << endl;
1004 jfenwick 2005 for (int z=0;z<NUMDATS;++z)
1005     {
1006     results[z].copy(dats[z].asinh().sinh());
1007     if (z>=LAZY)
1008     {
1009     assert(results[z].isLazy());
1010     }
1011     }
1012     for (int i=0;i<shape[0];i++) {
1013     for (int j=0;j<shape[1];j++) {
1014     tmp=data[getRelIndex(shape,i,j)];
1015     for (int z=0;z<NUMDATS;++z)
1016     {
1017     assert(std::abs(getRef(results[z],i,j) - tmp) <= REL_TOL*std::abs(tmp));
1018     }
1019     }
1020     }
1021 jgs 150
1022     cout << "\tTest Data::acosh." << endl;
1023 jfenwick 2005 for (int z=0;z<NUMDATS;++z)
1024     {
1025     results[z].copy(dats[z].acosh().cosh());
1026     if (z>=LAZY)
1027     {
1028     assert(results[z].isLazy());
1029     }
1030     }
1031     for (int i=0;i<shape[0];i++) {
1032     for (int j=0;j<shape[1];j++) {
1033     if (i==0 && j==0) break;
1034     tmp=data[getRelIndex(shape,i,j)];
1035     for (int z=0;z<NUMDATS;++z)
1036     {
1037     assert(std::abs(getRef(results[z],i,j) - tmp) <= REL_TOL*std::abs(tmp));
1038     }
1039     }
1040     }
1041 jgs 150
1042     cout << "\tTest Data::atanh." << endl;
1043 jfenwick 2005 for (int z=0;z<NUMDATS;++z)
1044     {
1045     results[z].copy(dats[z].tanh().atanh()); // if these are the other way around the results are
1046     if (z>=LAZY) // undefined
1047     {
1048     assert(results[z].isLazy());
1049     }
1050     }
1051     for (int i=0;i<shape[0];i++) {
1052     for (int j=0;j<shape[1];j++) {
1053     tmp=data[getRelIndex(shape,i,j)];
1054     for (int z=0;z<NUMDATS;++z)
1055     {
1056     assert(std::abs(getRef(results[z],i,j) - tmp) <= REL_TOL*std::abs(tmp));
1057     }
1058     }
1059     }
1060 jgs 150
1061 jgs 113 cout << "\tTest Data::log." << endl;
1062 jfenwick 2005 for (int z=0;z<NUMDATS;++z)
1063     {
1064     results[z].copy(dats[z].log());
1065     if (z>=LAZY)
1066     {
1067     assert(results[z].isLazy());
1068     }
1069     }
1070     for (int i=0;i<shape[0];i++) {
1071     for (int j=0;j<shape[1];j++) {
1072     if (i==0 && j==0) break;
1073     tmp=log((double)data[getRelIndex(shape,i,j)]);
1074     for (int z=0;z<NUMDATS;++z)
1075     {
1076     assert(std::abs(getRef(results[z],i,j) - tmp) <= REL_TOL*std::abs(tmp));
1077     }
1078     }
1079     }
1080 jgs 102
1081 jfenwick 2005 cout << "\tTest Data::log10." << endl;
1082     for (int z=0;z<NUMDATS;++z)
1083     {
1084     results[z].copy(dats[z].log10());
1085     if (z>=LAZY)
1086     {
1087     assert(results[z].isLazy());
1088     }
1089     }
1090     for (int i=0;i<shape[0];i++) {
1091     for (int j=0;j<shape[1];j++) {
1092     if (i==0 && j==0) break;
1093     tmp=log10((double)data[getRelIndex(shape,i,j)]);
1094     for (int z=0;z<NUMDATS;++z)
1095     {
1096     assert(std::abs(getRef(results[z],i,j) - tmp) <= REL_TOL*std::abs(tmp));
1097     }
1098     }
1099     }
1100 phornby 2051 #if defined (_WIN32) && !defined (__INTEL_COMPILER)
1101 phornby 2053 cout << "\tSkip test Data::erf on windows with MSVC compiler." << endl;
1102     #else
1103 jfenwick 2005 cout << "\tTest Data::erf." << endl;
1104     for (int z=0;z<NUMDATS;++z)
1105     {
1106     results[z].copy(dats[z].erf());
1107     if (z>=LAZY)
1108     {
1109     assert(results[z].isLazy());
1110     }
1111     }
1112     for (int i=0;i<shape[0];i++) {
1113     for (int j=0;j<shape[1];j++) {
1114     if (i==0 && j==0) break;
1115     tmp=erf((double)data[getRelIndex(shape,i,j)]);
1116     for (int z=0;z<NUMDATS;++z)
1117     {
1118     assert(std::abs(getRef(results[z],i,j) - tmp) <= REL_TOL*std::abs(tmp));
1119     }
1120     }
1121     }
1122     #endif
1123    
1124    
1125 jgs 113 cout << "\tTest Data::abs." << endl;
1126 jfenwick 2005 for (int z=0;z<NUMDATS;++z)
1127     {
1128     results[z].copy(dats[z].abs());
1129     if (z>=LAZY)
1130     {
1131     assert(results[z].isLazy());
1132     }
1133     }
1134 gross 713 for (int i=0;i<shape[0];i++) {
1135     for (int j=0;j<shape[1];j++) {
1136 jfenwick 1796 tmp=abs((double)data[getRelIndex(shape,i,j)]);
1137 jfenwick 2005 for (int z=0;z<NUMDATS;++z)
1138     {
1139     assert(std::abs(getRef(results[z],i,j) - tmp) <= REL_TOL*std::abs(tmp));
1140     }
1141 gross 713 }
1142     }
1143 jgs 102
1144 jfenwick 2005 cout << "\tTest Data::sign (positive)." << endl;
1145     for (int z=0;z<NUMDATS;++z)
1146     {
1147     results[z].copy(dats[z].sign());
1148     if (z>=LAZY)
1149     {
1150     assert(results[z].isLazy());
1151     }
1152     }
1153     for (int i=0;i<shape[0];i++) {
1154     for (int j=0;j<shape[1];j++) {
1155     tmp=(i==0 && j==0)?0:1;
1156     for (int z=0;z<NUMDATS;++z)
1157     {
1158     assert(std::abs(getRef(results[z],i,j) - tmp) <= REL_TOL*std::abs(tmp));
1159     }
1160     }
1161     }
1162 jgs 102
1163 jfenwick 2005 cout << "\tTest Data::sign (negative)." << endl;
1164     for (int z=0;z<NUMDATS;++z)
1165     {
1166     results[z].copy(dats[z].neg().sign());
1167     if (z>=LAZY)
1168     {
1169     assert(results[z].isLazy());
1170     }
1171     }
1172     for (int i=0;i<shape[0];i++) {
1173     for (int j=0;j<shape[1];j++) {
1174     tmp=(i==0 && j==0)?0:-1;
1175     for (int z=0;z<NUMDATS;++z)
1176     {
1177     assert(std::abs(getRef(results[z],i,j) - tmp) <= REL_TOL*std::abs(tmp));
1178     }
1179     }
1180     }
1181    
1182    
1183 jgs 113 cout << "\tTest Data::exp." << endl;
1184 jfenwick 2005 for (int z=0;z<NUMDATS;++z)
1185     {
1186     results[z].copy(dats[z].exp());
1187     if (z>=LAZY)
1188     {
1189     assert(results[z].isLazy());
1190     }
1191     }
1192 gross 713 for (int i=0;i<shape[0];i++) {
1193     for (int j=0;j<shape[1];j++) {
1194 jfenwick 1796 tmp=exp((double)data[getRelIndex(shape,i,j)]);
1195 jfenwick 2005 for (int z=0;z<NUMDATS;++z)
1196     {
1197     assert(std::abs(getRef(results[z],i,j) - tmp) <= REL_TOL*std::abs(tmp));
1198     }
1199 gross 713 }
1200     }
1201 jgs 102
1202 jgs 113 cout << "\tTest Data::sqrt." << endl;
1203 jfenwick 2005 for (int z=0;z<NUMDATS;++z)
1204     {
1205     results[z].copy(dats[z].sqrt());
1206     if (z>=LAZY)
1207     {
1208     assert(results[z].isLazy());
1209     }
1210     }
1211 gross 713 for (int i=0;i<shape[0];i++) {
1212     for (int j=0;j<shape[1];j++) {
1213 jfenwick 1796 tmp=sqrt((double)data[getRelIndex(shape,i,j)]);
1214 jfenwick 2005 for (int z=0;z<NUMDATS;++z)
1215     {
1216     assert(std::abs(getRef(results[z],i,j) - tmp) <= REL_TOL*std::abs(tmp));
1217     }
1218 gross 713 }
1219     }
1220 jgs 102
1221 jgs 113 cout << "\tTest Data::neg." << endl;
1222 jfenwick 2005 for (int z=0;z<NUMDATS;++z)
1223     {
1224     results[z].copy(dats[z].neg());
1225     if (z>=LAZY)
1226     {
1227     assert(results[z].isLazy());
1228     }
1229     }
1230     for (int i=0;i<shape[0];i++) {
1231     for (int j=0;j<shape[1];j++) {
1232     tmp=-data[getRelIndex(shape,i,j)];
1233     for (int z=0;z<NUMDATS;++z)
1234     {
1235     assert(std::abs(getRef(results[z],i,j) - tmp) <= REL_TOL*std::abs(tmp));
1236     }
1237     }
1238     }
1239 jgs 102
1240 jgs 113 cout << "\tTest Data::pos." << endl;
1241 jfenwick 2005 for (int z=0;z<NUMDATS;++z)
1242     {
1243     results[z].copy(dats[z].pos());
1244     if (z>=LAZY)
1245     {
1246     assert(results[z].isLazy());
1247     }
1248     }
1249 jgs 113 for (int i=0;i<shape[0];i++) {
1250     for (int j=0;j<shape[1];j++) {
1251 jfenwick 2005 for (int z=0;z<NUMDATS;++z)
1252     {
1253     assert(std::abs(getRef(results[z],i,j) - getRelIndex(shape,i,j)) <= REL_TOL*std::abs(data[getRelIndex(shape,i,j)]));
1254     }
1255 jgs 113 }
1256     }
1257 jgs 102
1258 jgs 113 // test reduction operations
1259    
1260     cout << "\tTest Data::Lsup." << endl;
1261 jfenwick 2005 for (int z=0;z<NUMDATS;++z)
1262     {
1263     assert(std::abs(dats[z].Lsup() - 5) <= REL_TOL*5);
1264     }
1265 jgs 113
1266     cout << "\tTest Data::sup." << endl;
1267 jfenwick 2005 for (int z=0;z<NUMDATS;++z)
1268     {
1269     assert(std::abs(dats[z].sup() - 5) <= REL_TOL*5);
1270     }
1271 jgs 113
1272     cout << "\tTest Data::inf." << endl;
1273 jfenwick 2005 for (int z=0;z<NUMDATS;++z)
1274     {
1275     assert(std::abs(dats[z].inf() - 0) <= REL_TOL*0);
1276     }
1277 jgs 113
1278     // test data-point reduction operations
1279    
1280     cout << "\tTest Data::minval." << endl;
1281 jfenwick 2005 for (int z=0;z<NUMDATS;++z)
1282     {
1283     results[z].copy(dats[z].minval());
1284     }
1285     for (int z=0;z<NUMDATS;++z)
1286     {
1287     assert(std::abs(results[z].getDataAtOffset(0) - 0) <= REL_TOL*0);
1288     }
1289    
1290 jgs 102
1291 jgs 113 cout << "\tTest Data::maxval." << endl;
1292 jfenwick 2005 for (int z=0;z<NUMDATS;++z)
1293     {
1294     results[z].copy(dats[z].maxval());
1295     }
1296     for (int z=0;z<NUMDATS;++z)
1297     {
1298     assert(std::abs(results[z].getDataAtOffset(0) - 5) <= REL_TOL*5);
1299     }
1300 jgs 102
1301 jgs 82 }
1302    
1303 jgs 110
1304 jfenwick 2005 // Here we test the binary operators in complex expressions
1305     void DataTestCase::testBinary()
1306     {
1307    
1308     cout << endl;
1309    
1310     // define the shape for the test data
1311     DataTypes::ShapeType shape;
1312     shape.push_back(2);
1313     shape.push_back(3);
1314    
1315     // allocate the data
1316     DataTypes::ValueType data(DataTypes::noValues(shape),0);
1317    
1318     // assign values to the data
1319     for (int i=0;i<shape[0];i++) {
1320     for (int j=0;j<shape[1];j++) {
1321     data[getRelIndex(shape,i,j)]=getRelIndex(shape,i,j)+2; // so we get no zeros
1322     }
1323     }
1324    
1325    
1326     Data one(1.0,DataTypes::scalarShape,FunctionSpace());
1327     Data two(2.0,DataTypes::scalarShape,FunctionSpace());
1328     Data dats[]={Data(data,shape,FunctionSpace(),false),
1329     Data(data,shape,FunctionSpace(),false),
1330     Data(data,shape,FunctionSpace(),true),
1331     Data(data,shape,FunctionSpace(),false),
1332     Data(data,shape,FunctionSpace(),false),
1333     Data(data,shape,FunctionSpace(),true)};
1334     dats[1].tag();
1335     dats[4].tag();
1336     const int NUMDATS=6;
1337     const int LAZY=3;
1338     dats[3].delaySelf();
1339     dats[4].delaySelf();
1340     dats[5].delaySelf();
1341     for (int z=0;z<NUMDATS;++z)
1342     {
1343     Data& a=dats[z];
1344     Data r1=(((a+a)/two)+a-a)*one; // scalar/*, matrix+-
1345     Data r2=(((a*a)/a+one)-one); // scalar+-, matrix*/
1346     Data r3=(a.powD(two)/a.powD(one)); // scalar power
1347     Data r4=a.powD(a); // matrix power
1348     if (z>LAZY)
1349     {
1350     assert(r1.isLazy() && r2.isLazy() && r3.isLazy() && r4.isLazy());
1351     }
1352     for (int i=0;i<DataTypes::noValues(shape);++i)
1353     {
1354     assert(std::abs(r1.getDataAtOffset(i)-data[i]) <= REL_TOL*data[i]);
1355     assert(std::abs(r2.getDataAtOffset(i)-data[i]) <= REL_TOL*data[i]);
1356     assert(std::abs(r3.getDataAtOffset(i)-data[i]) <= REL_TOL*data[i]);
1357     assert(std::abs(r4.getDataAtOffset(i)-pow(data[i],i)) <=REL_TOL*pow(data[i],i));
1358     }
1359     }
1360     }
1361    
1362    
1363 jgs 151 void DataTestCase::testMemAlloc() {
1364    
1365     //
1366     // Simple little sanity check for the memory allocator
1367    
1368     cout << endl;
1369    
1370     Data *testData;
1371     for (int i=0; i<1000; i++) {
1372 jfenwick 1796 testData = new Data(0.0, DataTypes::ShapeType(), FunctionSpace(), true);
1373 jgs 151 delete testData;
1374     }
1375    
1376 jfenwick 1796 DataTypes::ShapeType viewShape;
1377 jgs 151 viewShape.push_back(10);
1378     viewShape.push_back(10);
1379     viewShape.push_back(10);
1380    
1381     Data *testData2;
1382     Data *testData3 = new Data(0.0, viewShape, FunctionSpace(), true);
1383     for (int i=0; i<1000; i++) {
1384     testData2 = new Data(0.0, viewShape, FunctionSpace(), true);
1385     delete testData2;
1386     }
1387     delete testData3;
1388    
1389     }
1390    
1391 jgs 82 TestSuite* DataTestCase::suite ()
1392     {
1393     //
1394     // create the suite of tests to perform.
1395     TestSuite *testSuite = new TestSuite ("DataTestCase");
1396 jfenwick 1799 testSuite->addTest (new TestCaller< DataTestCase>("testCopying",&DataTestCase::testCopying));
1397 jfenwick 2005 testSuite->addTest (new TestCaller< DataTestCase>("testSome",&DataTestCase::testSome));
1398 jgs 82 testSuite->addTest (new TestCaller< DataTestCase>("testDataConstant",&DataTestCase::testDataConstant));
1399     testSuite->addTest (new TestCaller< DataTestCase>("testDataTagged",&DataTestCase::testDataTagged));
1400     testSuite->addTest (new TestCaller< DataTestCase>("testDataTaggedExceptions",&DataTestCase::testDataTaggedExceptions));
1401     testSuite->addTest (new TestCaller< DataTestCase>("testConstructors",&DataTestCase::testConstructors));
1402     testSuite->addTest (new TestCaller< DataTestCase>("testSlicing",&DataTestCase::testSlicing));
1403     testSuite->addTest (new TestCaller< DataTestCase>("testOperations",&DataTestCase::testOperations));
1404 jgs 110 //testSuite->addTest (new TestCaller< DataTestCase>("testRefValue",&DataTestCase::testRefValue));
1405 jgs 151 testSuite->addTest (new TestCaller< DataTestCase>("testMemAlloc",&DataTestCase::testMemAlloc));
1406 jfenwick 2005 testSuite->addTest (new TestCaller< DataTestCase>("Resolving",&DataTestCase::testResolveType));
1407 jgs 82
1408     return testSuite;
1409     }

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.26