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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1312 - (show annotations)
Mon Sep 24 06:18:44 2007 UTC (12 years, 4 months ago) by ksteube
File size: 30318 byte(s)
The MPI branch is hereby closed. All future work should be in trunk.

Previously in revision 1295 I merged the latest changes to trunk into trunk-mpi-branch.
In this revision I copied all files from trunk-mpi-branch over the corresponding
trunk files. I did not use 'svn merge', it was a copy.

1
2 /* $Id$ */
3
4 /*******************************************************
5 *
6 * Copyright 2003-2007 by ACceSS MNRF
7 * Copyright 2007 by University of Queensland
8 *
9 * http://esscc.uq.edu.au
10 * Primary Business: Queensland, Australia
11 * Licensed under the Open Software License version 3.0
12 * http://www.opensource.org/licenses/osl-3.0.php
13 *
14 *******************************************************/
15
16 #include <iostream>
17 #if (defined _WIN32) && (defined __INTEL_COMPILER)
18 #include <mathimf.h>
19 #else
20 #include <math.h>
21 #endif
22
23 #include "DataTestCase.h"
24
25 #include "escript/FunctionSpace.h"
26 #include "esysUtils/EsysException.h"
27
28 #include "escript/Data.h"
29
30
31 using namespace std;
32 using namespace CppUnitTest;
33 using namespace escript;
34 using namespace esysUtils;
35
36 void DataTestCase::setUp() {
37 //
38 // This is called before each test is run
39 }
40
41 void DataTestCase::tearDown() {
42 //
43 // This is called after each test has been run
44 }
45
46 void DataTestCase::testSlicing() {
47
48 cout << endl;
49
50 {
51
52 cout << "\tTest get-slicing DataConstant" << endl;
53
54 DataArrayView::ShapeType viewShape;
55 viewShape.push_back(2);
56 viewShape.push_back(3);
57 Data data(1.3,viewShape,FunctionSpace(),false);
58
59 //cout << data.toString() << endl;
60
61 DataArrayView::RegionType region;
62 region.push_back(DataArrayView::RegionType::value_type(0,0));
63 region.push_back(DataArrayView::RegionType::value_type(0,0));
64
65 Data slice1(data.getSlice(region));
66
67 //cout << slice1.toString() << endl;
68
69 assert(slice1.getDataPointRank()==0);
70 assert(slice1.getDataPoint(0,0)()==1.3);
71
72 region.clear();
73 region.push_back(DataArrayView::RegionType::value_type(0,1));
74 region.push_back(DataArrayView::RegionType::value_type(0,1));
75
76 Data slice2(data.getSlice(region));
77
78 //cout << slice2.toString() << endl;
79
80 assert(slice2.getDataPointRank()==2);
81 assert(slice2.getDataPoint(0,0)(0,0)==1.3);
82
83 region.clear();
84 region.push_back(DataArrayView::RegionType::value_type(0,1));
85 region.push_back(DataArrayView::RegionType::value_type(0,2));
86
87 Data slice3(data.getSlice(region));
88
89 //cout << slice3.toString() << endl;
90
91 assert(slice3.getDataPointRank()==2);
92 assert(slice3.getDataPoint(0,0)(0,0)==1.3);
93 assert(slice3.getDataPoint(0,0)(0,1)==1.3);
94
95 }
96
97 {
98
99 cout << "\tTest set-slicing DataConstant" << endl;
100
101 DataArrayView::ShapeType viewShape;
102 Data source(10.0,viewShape,FunctionSpace(),false);
103
104 //cout << source.toString() << endl;
105
106 viewShape.push_back(2);
107 viewShape.push_back(3);
108 Data target(1.3,viewShape,FunctionSpace(),false);
109
110 //cout << target.toString() << endl;
111
112 DataArrayView::RegionType region;
113 region.push_back(DataArrayView::RegionType::value_type(0,0));
114 region.push_back(DataArrayView::RegionType::value_type(0,0));
115
116 target.setSlice(source,region);
117
118 //cout << target.toString() << endl;
119
120 assert(target.getDataPoint(0,0)(0,0)==source.getDataPoint(0,0)());
121
122 }
123
124 {
125
126 cout << "\tTest get-slicing DataTagged" << endl;
127
128 //
129 // create a DataTagged with a default value only
130
131 DataArrayView::ShapeType viewShape;
132 viewShape.push_back(2);
133 viewShape.push_back(3);
134 Data data(1.3,viewShape,FunctionSpace(),false);
135 data.tag();
136 data.getDataPoint(0,0)(0,0)=1.0;
137 data.getDataPoint(0,0)(1,1)=2.0;
138
139 //cout << data.toString() << endl;
140
141 //
142 // create a scalar slice
143
144 DataArrayView::RegionType region;
145 region.push_back(DataArrayView::RegionType::value_type(0,0));
146 region.push_back(DataArrayView::RegionType::value_type(0,0));
147
148 Data slice1(data.getSlice(region));
149
150 //cout << slice1.toString() << endl;
151
152 assert(slice1.isTagged());
153 assert(slice1.getDataPointRank()==0);
154 assert(slice1.getDataPoint(0,0)()==1.0);
155
156 //
157 // create a rank 2 slice with one value
158
159 region.clear();
160 region.push_back(DataArrayView::RegionType::value_type(0,1));
161 region.push_back(DataArrayView::RegionType::value_type(0,1));
162
163 Data slice2(data.getSlice(region));
164
165 //cout << slice2.toString() << endl;
166
167 assert(slice2.isTagged());
168 assert(slice2.getDataPointRank()==2);
169 assert(slice2.getDataPoint(0,0)(0,0)==1.0);
170
171 //
172 // create a rank 2 slice with four values
173
174 region.clear();
175 region.push_back(DataArrayView::RegionType::value_type(0,2));
176 region.push_back(DataArrayView::RegionType::value_type(0,2));
177
178 Data slice3(data.getSlice(region));
179
180 //cout << slice3.toString() << endl;
181
182 assert(slice3.isTagged());
183 assert(slice3.getDataPointRank()==2);
184 assert(slice3.getDataPoint(0,0)(0,0)==1.0);
185 assert(slice3.getDataPoint(0,0)(0,1)==1.3);
186 assert(slice3.getDataPoint(0,0)(1,0)==1.3);
187 assert(slice3.getDataPoint(0,0)(1,1)==2.0);
188
189 //
190 // add a value for tag "1"
191
192 DataArrayView::ValueType viewData(6);
193 for (int i=0;i<viewData.size();i++) {
194 viewData[i]=i;
195 }
196 DataArrayView dataView(viewData,viewShape);
197
198 data.setTaggedValueFromCPP(1, dataView);
199
200 //
201 // create a full slice
202
203 region.clear();
204 region.push_back(DataArrayView::RegionType::value_type(0,2));
205 region.push_back(DataArrayView::RegionType::value_type(0,3));
206
207 Data slice4(data.getSlice(region));
208
209 //cout << slice4.toString() << endl;
210
211 assert(slice4.isTagged());
212 assert(slice4.getDataPointRank()==2);
213 assert(slice4.getDataPoint(0,0)(0,0)==0);
214 assert(slice4.getDataPoint(0,0)(0,1)==2);
215 assert(slice4.getDataPoint(0,0)(0,2)==4);
216 assert(slice4.getDataPoint(0,0)(1,0)==1);
217 assert(slice4.getDataPoint(0,0)(1,1)==3);
218 assert(slice4.getDataPoint(0,0)(1,2)==5);
219
220 }
221
222 {
223
224 cout << "\tTest set-slicing DataTagged" << endl;
225
226 //
227 // create a source DataTagged with a scalar default value only
228
229 DataArrayView::ShapeType viewShape;
230 Data source(10.0,viewShape,FunctionSpace(),false);
231 source.tag();
232
233 //cout << "source:\n" << source.toString() << endl;
234
235 //
236 // create a target DataTagged with a rank 2 default value only
237
238 viewShape.push_back(2);
239 viewShape.push_back(3);
240 Data target(1.3,viewShape,FunctionSpace(),false);
241 target.tag();
242
243 //cout << "target:\n" << target.toString() << endl;
244
245 //
246 // set a slice in target from source
247
248 DataArrayView::RegionType region;
249 region.push_back(DataArrayView::RegionType::value_type(1,1));
250 region.push_back(DataArrayView::RegionType::value_type(1,1));
251
252 target.setSlice(source,region);
253
254 //cout << "target:\n" << target.toString() << endl;
255
256 assert(target.isTagged());
257 assert(target.getDataPointRank()==2);
258 assert(target.getDataPoint(0,0)(0,0)==1.3);
259 assert(target.getDataPoint(0,0)(0,1)==1.3);
260 assert(target.getDataPoint(0,0)(0,2)==1.3);
261 assert(target.getDataPoint(0,0)(1,0)==1.3);
262 assert(target.getDataPoint(0,0)(1,1)==source.getDataPoint(0,0)());
263 assert(target.getDataPoint(0,0)(1,2)==1.3);
264
265 //
266 // add a value for tag "1" to target
267
268 DataArrayView::ValueType viewData(6);
269 for (int i=0;i<viewData.size();i++) {
270 viewData[i]=i;
271 }
272 DataArrayView dataView(viewData,viewShape);
273
274 target.setTaggedValueFromCPP(1, dataView);
275
276 //cout << "target:\n" << target.toString() << endl;
277
278 //
279 // set a slice in target from source
280
281 region.clear();
282 region.push_back(DataArrayView::RegionType::value_type(0,0));
283 region.push_back(DataArrayView::RegionType::value_type(1,1));
284
285 target.setSlice(source,region);
286
287 //cout << "target:\n" << target.toString() << endl;
288
289 assert(target.isTagged());
290 assert(target.getDataPointRank()==2);
291 assert(target.getDataPoint(0,0)(0,0)==0);
292 assert(target.getDataPoint(0,0)(0,1)==source.getDataPoint(0,0)());
293 assert(target.getDataPoint(0,0)(0,2)==4);
294 assert(target.getDataPoint(0,0)(1,0)==1);
295 assert(target.getDataPoint(0,0)(1,1)==3);
296 assert(target.getDataPoint(0,0)(1,2)==5);
297
298 //
299 // add a value for tag "2" to source
300
301 DataArrayView::ShapeType viewShape2;
302 DataArrayView::ValueType viewData2(1);
303 viewData2[0]=6;
304 DataArrayView dataView2(viewData2,viewShape2);
305
306 source.setTaggedValueFromCPP(2, dataView2);
307
308 //cout << "source:\n" << source.toString() << endl;
309
310 //
311 // set a slice in target from source
312
313 region.clear();
314 region.push_back(DataArrayView::RegionType::value_type(0,0));
315 region.push_back(DataArrayView::RegionType::value_type(1,1));
316
317 target.setSlice(source,region);
318
319 //cout << "target:\n" << target.toString() << endl;
320
321 assert(target.isTagged());
322 assert(target.getDataPointRank()==2);
323
324 // use a non-existant tag so we get a pointer to the default value
325 // ie: the first element in the data array
326 DataAbstract::ValueType::value_type* targetData=target.getSampleDataByTag(9);
327 for (int i=0; i<target.getLength(); i++) {
328 assert(targetData[i]>=0);
329 }
330 assert(targetData[0]==1.3);
331 assert(targetData[1]==1.3);
332 assert(targetData[2]==10);
333 assert(targetData[3]==10);
334 assert(targetData[4]==1.3);
335 assert(targetData[5]==1.3);
336 assert(targetData[6]==0);
337 assert(targetData[7]==1);
338 assert(targetData[8]==10);
339 assert(targetData[9]==3);
340 assert(targetData[10]==4);
341 assert(targetData[11]==5);
342 assert(targetData[12]==1.3);
343 assert(targetData[13]==1.3);
344 assert(targetData[14]==6);
345 assert(targetData[15]==10);
346 assert(targetData[16]==1.3);
347 assert(targetData[17]==1.3);
348
349 }
350
351 {
352
353 cout << "\tTest get-slicing DataExpanded" << endl;
354
355 DataArrayView::ShapeType viewShape;
356 viewShape.push_back(2);
357 viewShape.push_back(3);
358 Data temp(1.3,viewShape,FunctionSpace(),true);
359
360 temp.getDataPoint(0,0)(0,0)=0.0;
361 temp.getDataPoint(0,0)(1,1)=1.0;
362
363 DataArrayView::RegionType region;
364 region.push_back(DataArrayView::RegionType::value_type(0,0));
365 region.push_back(DataArrayView::RegionType::value_type(0,0));
366
367 Data slice(temp.getSlice(region));
368
369 assert(slice.getDataPointRank()==0);
370 assert(slice.getDataPoint(0,0)()==0.0);
371
372 region.clear();
373 region.push_back(DataArrayView::RegionType::value_type(0,1));
374 region.push_back(DataArrayView::RegionType::value_type(0,1));
375
376 slice=temp.getSlice(region);
377
378 assert(slice.getDataPointRank()==2);
379 assert(slice.getDataPoint(0,0)(0,0)==0.0);
380
381 region.clear();
382 region.push_back(DataArrayView::RegionType::value_type(0,2));
383 region.push_back(DataArrayView::RegionType::value_type(0,2));
384
385 slice=temp.getSlice(region);
386
387 assert(slice.getDataPoint(0,0)(0,0)==0.0);
388 assert(slice.getDataPoint(0,0)(1,1)==1.0);
389
390 }
391
392 {
393
394 cout << "\tTest set-slicing DataExpanded" << endl;
395
396 DataArrayView::ShapeType viewShape;
397 Data source(10.0,viewShape,FunctionSpace(),true);
398
399 viewShape.push_back(2);
400 viewShape.push_back(3);
401 Data target(1.3,viewShape,FunctionSpace(),true);
402
403 DataArrayView::RegionType region;
404 region.push_back(DataArrayView::RegionType::value_type(0,0));
405 region.push_back(DataArrayView::RegionType::value_type(0,0));
406
407 target.setSlice(source,region);
408
409 assert(target.getDataPoint(0,0)(0,0)==source.getDataPoint(0,0)());
410
411 }
412
413 }
414
415 void DataTestCase::testAll() {
416
417 cout << endl;
418
419 cout << "\tCreate a Data object from a DataArrayView" << endl;
420
421 DataArrayView::ShapeType viewShape;
422 viewShape.push_back(3);
423 DataArrayView::ValueType viewData(3);
424 for (int i=0;i<viewShape[0];++i) {
425 viewData[i]=i;
426 }
427 DataArrayView myView(viewData,viewShape);
428
429 bool expanded=true;
430 Data exData(myView,FunctionSpace(),expanded);
431 Data cData(myView);
432 Data result;
433
434 assert(exData.isExpanded());
435 assert(cData.isConstant());
436 assert(result.isEmpty());
437
438 cout << "\tTest some basic operations" << endl;
439 result=exData*cData;
440 assert(result.isExpanded());
441
442 }
443
444 void DataTestCase::testMore() {
445
446 cout << endl;
447
448 cout << "\tCreate a Data object from a DataArrayView" << endl;
449
450 DataArrayView::ShapeType viewShape;
451 viewShape.push_back(3);
452 DataArrayView::ValueType viewData(3);
453 for (int i=0;i<viewShape[0];++i) {
454 viewData[i]=i;
455 }
456 DataArrayView myView(viewData,viewShape);
457
458 bool expanded=true;
459 Data exData(myView,FunctionSpace(),expanded);
460 Data cData(myView);
461 Data result;
462
463 assert(exData.isExpanded());
464 assert(cData.isConstant());
465 assert(result.isEmpty());
466
467 cout << "\tTest some basic operations" << endl;
468 result=exData*cData;
469 assert(result.isExpanded());
470
471 assert(result.Lsup()==4);
472 assert(result.sup()==4);
473 assert(result.inf()==0);
474
475 result=exData+cData;
476 result=exData-cData;
477 result=exData/cData;
478
479 cout << "\tExercise wherePositive method" << endl;
480 assert(!exData.wherePositive().isEmpty());
481
482 cout << "\tExercise copyWithMask method" << endl;
483 exData.copyWithMask(result, exData.wherePositive());
484 assert(!exData.wherePositive().isEmpty());
485
486 }
487
488 void DataTestCase::testDataConstant() {
489
490 cout << endl;
491
492 cout << "\tCreate a DataConstant object from a DataArrayView" << endl;
493
494 DataArrayView::ShapeType viewShape;
495 viewShape.push_back(2);
496 viewShape.push_back(3);
497 viewShape.push_back(4);
498 DataArrayView::ValueType viewData(2*3*4);
499 for (int i=0;i<DataArrayView::noValues(viewShape);++i) {
500 viewData[i]=i;
501 }
502 DataArrayView myView(viewData,viewShape);
503
504 Data left(myView);
505 Data right(myView);
506 Data result;
507
508 cout << "\tTest some basic operations" << endl;
509
510 result=left-right;
511
512 assert(left.isConstant());
513 assert(right.isConstant());
514 assert(result.isConstant());
515
516 result=left+right;
517
518 assert(left.isConstant());
519 assert(right.isConstant());
520 assert(result.isConstant());
521
522 assert(!result.isExpanded());
523 assert(!result.isTagged());
524
525 }
526
527 void DataTestCase::testDataTagged() {
528
529 cout << endl;
530
531 {
532
533 cout << "\tCreate a DataTagged object with a default value only." << endl;
534
535 DataTagged::TagListType keys;
536
537 DataTagged::ValueListType values;
538
539 DataArrayView::ShapeType viewShape;
540 viewShape.push_back(3);
541
542 DataArrayView::ValueType viewData(3);
543 for (int i=0;i<viewShape[0];i++) {
544 viewData[i]=i;
545 }
546 DataArrayView defaultValue(viewData,viewShape);
547
548 bool expanded=false;
549
550 Data myData(keys,values,defaultValue,FunctionSpace(),expanded);
551
552 // cout << myData.toString() << endl;
553
554 assert(!myData.isEmpty());
555 assert(myData.isTagged());
556 assert(myData.getTagNumber(0)==1);
557 assert(myData.getDataPointRank()==1);
558 assert(myData.getLength()==3);
559
560 DataArrayView myDataView = myData.getPointDataView();
561 assert(!myDataView.isEmpty());
562 assert(myDataView.getOffset()==0);
563 assert(myDataView.getRank()==1);
564 assert(myDataView.noValues()==3);
565 assert(myDataView.getShape().size()==1);
566 assert(myDataView(0)==0.0);
567 assert(myDataView(1)==1.0);
568 assert(myDataView(2)==2.0);
569
570 myDataView = myData.getDataPoint(0,0);
571 assert(!myDataView.isEmpty());
572 assert(myDataView.getOffset()==0);
573 assert(myDataView.getRank()==1);
574 assert(myDataView.noValues()==3);
575 assert(myDataView.getShape().size()==1);
576 assert(myDataView(0)==0.0);
577 assert(myDataView(1)==1.0);
578 assert(myDataView(2)==2.0);
579
580 double* sampleData=myData.getSampleData(0);
581 for (int i=0; i<myDataView.noValues(); i++) {
582 assert(sampleData[i]==i);
583 }
584 // use a non-existent tag so we get a pointer to
585 // the first element of the data array
586 sampleData=myData.getSampleDataByTag(9);
587 for (int i=0; i<myData.getLength(); i++) {
588 assert(sampleData[i]==i);
589 }
590
591 cout << "\tTest setting of a tag and associated value." << endl;
592
593 // value for tag "1"
594 DataArray eTwo(defaultValue);
595 for (int i=0;i<eTwo.getView().getShape()[0];i++) {
596 eTwo.getView()(i)=i+2.0;
597 }
598
599 myData.setTaggedValueFromCPP(1,eTwo.getView());
600
601 assert(myData.getLength()==6);
602
603 myDataView = myData.getDataPoint(0,0);
604 assert(myDataView==eTwo.getView());
605 assert(!myDataView.isEmpty());
606 assert(myDataView.getOffset()==3);
607 assert(myDataView.getRank()==1);
608 assert(myDataView.noValues()==3);
609 assert(myDataView.getShape().size()==1);
610 assert(myDataView(0)==2);
611 assert(myDataView(1)==3);
612 assert(myDataView(2)==4);
613
614 sampleData=myData.getSampleDataByTag(1);
615 for (int i=0; i<myDataView.noValues(); i++) {
616 assert(sampleData[i]==i+2);
617 }
618
619 }
620
621 {
622
623 cout << "\tCreate a DataTagged object via tag() method." << endl;
624
625 DataArrayView::ShapeType viewShape;
626 viewShape.push_back(2);
627 viewShape.push_back(3);
628 Data myData(1.3,viewShape,FunctionSpace(),false);
629 myData.tag();
630
631 //cout << myData.toString() << endl;
632
633 assert(!myData.isEmpty());
634 assert(myData.isTagged());
635 assert(myData.getTagNumber(0)==1);
636 assert(myData.getDataPointRank()==2);
637 assert(myData.getLength()==6);
638
639 // check default value
640 DataArrayView myDataView = myData.getPointDataView();
641 assert(!myDataView.isEmpty());
642 assert(myDataView.getOffset()==0);
643 assert(myDataView.getRank()==2);
644 assert(myDataView.noValues()==6);
645 assert(myDataView.getShape().size()==2);
646 assert(myDataView(0,0)==1.3);
647 assert(myDataView(0,1)==1.3);
648 assert(myDataView(0,2)==1.3);
649 assert(myDataView(1,0)==1.3);
650 assert(myDataView(1,1)==1.3);
651 assert(myDataView(1,2)==1.3);
652
653 // check value for data-point (0,0).
654 myDataView = myData.getDataPoint(0,0);
655 assert(!myDataView.isEmpty());
656 assert(myDataView.getOffset()==0);
657 assert(myDataView.getRank()==2);
658 assert(myDataView.noValues()==6);
659 assert(myDataView.getShape().size()==2);
660 assert(myDataView(0,0)==1.3);
661 assert(myDataView(0,1)==1.3);
662 assert(myDataView(0,2)==1.3);
663 assert(myDataView(1,0)==1.3);
664 assert(myDataView(1,1)==1.3);
665 assert(myDataView(1,2)==1.3);
666
667 }
668
669 }
670
671 void DataTestCase::testDataTaggedExceptions() {
672
673 cout << endl;
674
675 cout << "\tTest DataTagged exceptions." << endl;
676
677 Data myData;
678 DataArrayView myView;
679
680 try {
681 myData.getSampleDataByTag(0);;
682 assert(false);
683 }
684 catch (EsysException& e) {
685 //cout << e.what() << endl;
686 assert(true);
687 }
688
689 try {
690 myData.setTaggedValueFromCPP(0,myView);;
691 assert(false);
692 }
693 catch (EsysException& e) {
694 //cout << e.what() << endl;
695 assert(true);
696 }
697
698 }
699
700 void DataTestCase::testConstructors() {
701
702 cout << endl;
703
704 DataArrayView::ShapeType viewShape;
705 {
706 cout << "\tCreate an Empty Data object" << endl;
707 Data temp(1.3,viewShape,FunctionSpace(),false);
708 }
709 {
710 cout << "\tCreate a rank 2 Data object" << endl;
711 viewShape.push_back(2);
712 viewShape.push_back(3);
713 Data temp(1.3,viewShape,FunctionSpace(),false);
714 }
715 }
716
717 void DataTestCase::testOperations() {
718
719 cout << endl;
720
721 // define the shape for the DataArrayView test data
722 DataArrayView::ShapeType shape;
723 shape.push_back(2);
724 shape.push_back(3);
725
726 // allocate the data for the DataArrayView
727 DataArrayView::ValueType data(DataArrayView::noValues(shape),0);
728
729 // construct DataArrayView
730 DataArrayView dataView(data,shape);
731
732 // assign values to the data
733 for (int i=0;i<shape[0];i++) {
734 for (int j=0;j<shape[1];j++) {
735 dataView(i,j)=dataView.index(i,j);
736 }
737 }
738
739 Data baseEx(dataView,FunctionSpace(),true);
740 Data baseCon(dataView,FunctionSpace(),false);
741 Data baseTag(dataView,FunctionSpace(),false);
742 baseTag.tag();
743
744 assert(baseEx.isExpanded());
745 assert(baseCon.isConstant());
746 assert(baseTag.isTagged());
747
748 Data resultEx;
749 Data resultCon;
750 Data resultTag;
751
752 // test unary operations
753
754 double tmp;
755 cout << "\tTest Data::pow." << endl;
756 Data power(3.0,shape,FunctionSpace(),true);
757 resultEx.copy(baseEx.powD(power));
758 resultCon.copy(baseCon.powD(power));
759 resultTag.copy(baseTag.powD(power));
760 for (int i=0;i<shape[0];i++) {
761 for (int j=0;j<shape[1];j++) {
762 tmp=pow(dataView.index(i,j),3.0);
763 assert(std::abs(resultEx.getPointDataView()(i,j) - tmp) <= REL_TOL*std::abs(tmp));
764 assert(std::abs(resultCon.getPointDataView()(i,j)- tmp) <= REL_TOL*std::abs(tmp));
765 assert(std::abs(resultTag.getPointDataView()(i,j)- tmp) <= REL_TOL*std::abs(tmp));
766 }
767 }
768
769 cout << "\tTest Data::sin." << endl;
770 resultEx.copy(baseEx.sin());
771 resultCon.copy(baseCon.sin());
772 resultTag.copy(baseTag.sin());
773 for (int i=0;i<shape[0];i++) {
774 for (int j=0;j<shape[1];j++) {
775 tmp=sin((double)dataView.index(i,j));
776 assert(std::abs(resultEx.getPointDataView()(i,j) - tmp) <= REL_TOL*std::abs(tmp));
777 assert(std::abs(resultCon.getPointDataView()(i,j)- tmp) <= REL_TOL*std::abs(tmp));
778 assert(std::abs(resultTag.getPointDataView()(i,j)- tmp) <= REL_TOL*std::abs(tmp));
779 }
780 }
781
782 cout << "\tTest Data::cos." << endl;
783 resultEx.copy(baseEx.cos());
784 resultCon.copy(baseCon.cos());
785 resultTag.copy(baseTag.cos());
786 for (int i=0;i<shape[0];i++) {
787 for (int j=0;j<shape[1];j++) {
788 tmp=cos((double)dataView.index(i,j));
789 assert(std::abs(resultEx.getPointDataView()(i,j) - tmp) <= REL_TOL*std::abs(tmp));
790 assert(std::abs(resultCon.getPointDataView()(i,j)- tmp) <= REL_TOL*std::abs(tmp));
791 assert(std::abs(resultTag.getPointDataView()(i,j)- tmp) <= REL_TOL*std::abs(tmp));
792 }
793 }
794
795 cout << "\tTest Data::tan." << endl;
796 resultEx.copy(baseEx.tan());
797 resultCon.copy(baseCon.tan());
798 resultTag.copy(baseTag.tan());
799 for (int i=0;i<shape[0];i++) {
800 for (int j=0;j<shape[1];j++) {
801 tmp=tan((double)dataView.index(i,j));
802 assert(std::abs(resultEx.getPointDataView()(i,j) - tmp) <= REL_TOL*std::abs(tmp));
803 assert(std::abs(resultCon.getPointDataView()(i,j)- tmp) <= REL_TOL*std::abs(tmp));
804 assert(std::abs(resultTag.getPointDataView()(i,j)- tmp) <= REL_TOL*std::abs(tmp));
805 }
806 }
807
808 cout << "\tTest Data::asin." << endl;
809 resultEx.copy(baseEx.asin());
810 resultCon.copy(baseCon.asin());
811 resultTag.copy(baseTag.asin());
812 assert(true);
813
814 cout << "\tTest Data::acos." << endl;
815 resultEx.copy(baseEx.acos());
816 resultCon.copy(baseCon.acos());
817 resultTag.copy(baseTag.acos());
818 assert(true);
819
820 cout << "\tTest Data::atan." << endl;
821 resultEx.copy(baseEx.atan());
822 resultCon.copy(baseCon.atan());
823 resultTag.copy(baseTag.atan());
824 for (int i=0;i<shape[0];i++) {
825 for (int j=0;j<shape[1];j++) {
826 tmp=atan((double)dataView.index(i,j));
827 assert(std::abs(resultEx.getPointDataView()(i,j) - tmp) <= REL_TOL*std::abs(tmp));
828 assert(std::abs(resultCon.getPointDataView()(i,j)- tmp) <= REL_TOL*std::abs(tmp));
829 assert(std::abs(resultTag.getPointDataView()(i,j)- tmp) <= REL_TOL*std::abs(tmp));
830 }
831 }
832
833 cout << "\tTest Data::sinh." << endl;
834 resultEx.copy(baseEx.sinh());
835 resultCon.copy(baseCon.sinh());
836 resultTag.copy(baseTag.sinh());
837 for (int i=0;i<shape[0];i++) {
838 for (int j=0;j<shape[1];j++) {
839 tmp=sinh((double)dataView.index(i,j));
840 assert(std::abs(resultEx.getPointDataView()(i,j) - tmp) <= REL_TOL*std::abs(tmp));
841 assert(std::abs(resultCon.getPointDataView()(i,j)- tmp) <= REL_TOL*std::abs(tmp));
842 assert(std::abs(resultTag.getPointDataView()(i,j)- tmp) <= REL_TOL*std::abs(tmp));
843 }
844 }
845
846 cout << "\tTest Data::cosh." << endl;
847 resultEx.copy(baseEx.cosh());
848 resultCon.copy(baseCon.cosh());
849 resultTag.copy(baseTag.cosh());
850 for (int i=0;i<shape[0];i++) {
851 for (int j=0;j<shape[1];j++) {
852 tmp=cosh((double)dataView.index(i,j));
853 assert(std::abs(resultEx.getPointDataView()(i,j) - tmp) <= REL_TOL*std::abs(tmp));
854 assert(std::abs(resultCon.getPointDataView()(i,j)- tmp) <= REL_TOL*std::abs(tmp));
855 assert(std::abs(resultTag.getPointDataView()(i,j)- tmp) <= REL_TOL*std::abs(tmp));
856 }
857 }
858
859 cout << "\tTest Data::tanh." << endl;
860 resultEx.copy(baseEx.tanh());
861 resultCon.copy(baseCon.tanh());
862 resultTag.copy(baseTag.tanh());
863 for (int i=0;i<shape[0];i++) {
864 for (int j=0;j<shape[1];j++) {
865 tmp=tanh((double)dataView.index(i,j));
866 assert(std::abs(resultEx.getPointDataView()(i,j) - tmp) <= REL_TOL*std::abs(tmp));
867 assert(std::abs(resultCon.getPointDataView()(i,j)- tmp) <= REL_TOL*std::abs(tmp));
868 assert(std::abs(resultTag.getPointDataView()(i,j)- tmp) <= REL_TOL*std::abs(tmp));
869 }
870 }
871
872 cout << "\tTest Data::asinh." << endl;
873 resultEx.copy(baseEx.asinh());
874 resultCon.copy(baseCon.asinh());
875 resultTag.copy(baseTag.asinh());
876 assert(true);
877
878 cout << "\tTest Data::acosh." << endl;
879 resultEx.copy(baseEx.acosh());
880 resultCon.copy(baseCon.acosh());
881 resultTag.copy(baseTag.acosh());
882 assert(true);
883
884 cout << "\tTest Data::atanh." << endl;
885 resultEx.copy(baseEx.atanh());
886 resultCon.copy(baseCon.atanh());
887 resultTag.copy(baseTag.atanh());
888 assert(true);
889
890 cout << "\tTest Data::log." << endl;
891 resultEx.copy(baseEx.log());
892 resultCon.copy(baseCon.log());
893 resultTag.copy(baseTag.log());
894 assert(true);
895
896 cout << "\tTest Data::abs." << endl;
897 resultEx.copy(baseEx.abs());
898 resultCon.copy(baseCon.abs());
899 resultTag.copy(baseTag.abs());
900 for (int i=0;i<shape[0];i++) {
901 for (int j=0;j<shape[1];j++) {
902 tmp=abs((double)dataView.index(i,j));
903 assert(std::abs(resultEx.getPointDataView()(i,j) - tmp) <= REL_TOL*std::abs(tmp));
904 assert(std::abs(resultCon.getPointDataView()(i,j)- tmp) <= REL_TOL*std::abs(tmp));
905 assert(std::abs(resultTag.getPointDataView()(i,j)- tmp) <= REL_TOL*std::abs(tmp));
906 }
907 }
908
909 cout << "\tTest Data::sign." << endl;
910 resultEx.copy(baseEx.sign());
911 resultCon.copy(baseCon.sign());
912 resultTag.copy(baseTag.sign());
913 assert(true);
914
915 cout << "\tTest Data::exp." << endl;
916 resultEx.copy(baseEx.exp());
917 resultCon.copy(baseCon.exp());
918 resultTag.copy(baseTag.exp());
919 for (int i=0;i<shape[0];i++) {
920 for (int j=0;j<shape[1];j++) {
921 tmp=exp((double)dataView.index(i,j));
922 assert(std::abs(resultEx.getPointDataView()(i,j) - tmp) <= REL_TOL*std::abs(tmp));
923 assert(std::abs(resultCon.getPointDataView()(i,j)- tmp) <= REL_TOL*std::abs(tmp));
924 assert(std::abs(resultTag.getPointDataView()(i,j)- tmp) <= REL_TOL*std::abs(tmp));
925 }
926 }
927
928 cout << "\tTest Data::sqrt." << endl;
929 resultEx.copy(baseEx.sqrt());
930 resultCon.copy(baseCon.sqrt());
931 resultTag.copy(baseTag.sqrt());
932 for (int i=0;i<shape[0];i++) {
933 for (int j=0;j<shape[1];j++) {
934 tmp=sqrt((double)dataView.index(i,j));
935 assert(std::abs(resultEx.getPointDataView()(i,j) - tmp) <= REL_TOL*std::abs(tmp));
936 assert(std::abs(resultCon.getPointDataView()(i,j)- tmp) <= REL_TOL*std::abs(tmp));
937 assert(std::abs(resultTag.getPointDataView()(i,j)- tmp) <= REL_TOL*std::abs(tmp));
938 }
939 }
940
941 cout << "\tTest Data::neg." << endl;
942 resultEx.copy(baseEx.neg());
943 resultCon.copy(baseCon.neg());
944 resultTag.copy(baseTag.neg());
945 assert(true);
946
947 cout << "\tTest Data::pos." << endl;
948 resultEx.copy(baseEx.pos());
949 resultCon.copy(baseCon.pos());
950 resultTag.copy(baseTag.pos());
951 for (int i=0;i<shape[0];i++) {
952 for (int j=0;j<shape[1];j++) {
953 assert(std::abs(resultEx.getPointDataView()(i,j) - dataView.index(i,j)) <= REL_TOL*std::abs(dataView.index(i,j)));
954 assert(std::abs(resultCon.getPointDataView()(i,j) - dataView.index(i,j)) <= REL_TOL*std::abs(dataView.index(i,j)));
955 assert(std::abs(resultTag.getPointDataView()(i,j) - dataView.index(i,j)) <= REL_TOL*std::abs(dataView.index(i,j)));
956 }
957 }
958
959 // test reduction operations
960
961 cout << "\tTest Data::Lsup." << endl;
962 assert(std::abs(baseEx.Lsup() - 5) <= REL_TOL*5);
963 assert(std::abs(baseCon.Lsup() - 5) <= REL_TOL*5);
964 assert(std::abs(baseTag.Lsup() - 5) <= REL_TOL*5);
965
966 cout << "\tTest Data::sup." << endl;
967 assert(std::abs(baseEx.sup() - 5) <= REL_TOL*5);
968 assert(std::abs(baseCon.sup() - 5) <= REL_TOL*5);
969 assert(std::abs(baseTag.sup() - 5) <= REL_TOL*5);
970
971 cout << "\tTest Data::inf." << endl;
972 assert(std::abs(baseEx.inf() - 0) <= REL_TOL*0);
973 assert(std::abs(baseCon.inf() - 0) <= REL_TOL*0);
974 assert(std::abs(baseTag.inf() - 0) <= REL_TOL*0);
975
976 // test data-point reduction operations
977
978 cout << "\tTest Data::minval." << endl;
979 resultEx.copy(baseEx.minval());
980 resultCon.copy(baseCon.minval());
981 resultTag.copy(baseTag.minval());
982 assert(std::abs(resultEx.getPointDataView()() - 0) <= REL_TOL*0);
983 assert(std::abs(resultCon.getPointDataView()() - 0) <= REL_TOL*0);
984 assert(std::abs(resultTag.getPointDataView()() - 0) <= REL_TOL*0);
985
986 cout << "\tTest Data::maxval." << endl;
987 resultEx.copy(baseEx.maxval());
988 resultCon.copy(baseCon.maxval());
989 resultTag.copy(baseTag.maxval());
990 assert(std::abs(resultEx.getPointDataView()() - 5) <= REL_TOL*5);
991 assert(std::abs(resultCon.getPointDataView()() - 5) <= REL_TOL*5);
992 assert(std::abs(resultTag.getPointDataView()() - 5) <= REL_TOL*5);
993
994 }
995
996
997 void DataTestCase::testMemAlloc() {
998
999 //
1000 // Simple little sanity check for the memory allocator
1001
1002 cout << endl;
1003
1004 Data *testData;
1005 for (int i=0; i<1000; i++) {
1006 testData = new Data(0.0, DataArrayView::ShapeType(), FunctionSpace(), true);
1007 delete testData;
1008 }
1009
1010 DataArrayView::ShapeType viewShape;
1011 viewShape.push_back(10);
1012 viewShape.push_back(10);
1013 viewShape.push_back(10);
1014
1015 Data *testData2;
1016 Data *testData3 = new Data(0.0, viewShape, FunctionSpace(), true);
1017 for (int i=0; i<1000; i++) {
1018 testData2 = new Data(0.0, viewShape, FunctionSpace(), true);
1019 delete testData2;
1020 }
1021 delete testData3;
1022
1023 }
1024
1025 TestSuite* DataTestCase::suite ()
1026 {
1027 //
1028 // create the suite of tests to perform.
1029 TestSuite *testSuite = new TestSuite ("DataTestCase");
1030
1031 testSuite->addTest (new TestCaller< DataTestCase>("testAll",&DataTestCase::testAll));
1032 testSuite->addTest (new TestCaller< DataTestCase>("testMore",&DataTestCase::testMore));
1033 testSuite->addTest (new TestCaller< DataTestCase>("testDataConstant",&DataTestCase::testDataConstant));
1034 testSuite->addTest (new TestCaller< DataTestCase>("testDataTagged",&DataTestCase::testDataTagged));
1035 testSuite->addTest (new TestCaller< DataTestCase>("testDataTaggedExceptions",&DataTestCase::testDataTaggedExceptions));
1036 testSuite->addTest (new TestCaller< DataTestCase>("testConstructors",&DataTestCase::testConstructors));
1037 testSuite->addTest (new TestCaller< DataTestCase>("testSlicing",&DataTestCase::testSlicing));
1038 testSuite->addTest (new TestCaller< DataTestCase>("testOperations",&DataTestCase::testOperations));
1039 //testSuite->addTest (new TestCaller< DataTestCase>("testRefValue",&DataTestCase::testRefValue));
1040 testSuite->addTest (new TestCaller< DataTestCase>("testMemAlloc",&DataTestCase::testMemAlloc));
1041
1042 return testSuite;
1043 }

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26