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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2051 - (hide annotations)
Mon Nov 17 09:24:02 2008 UTC (10 years, 11 months ago) by phornby
File size: 34511 byte(s)
Now add the erf() test back for windows under the intelc compiler.


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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26