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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

trunk/escript/test/Data/DataTestCase.cpp revision 311 by jgs, Mon Dec 5 02:59:54 2005 UTC trunk/escript/test/DataTestCase.cpp revision 1799 by jfenwick, Wed Sep 17 06:33:18 2008 UTC
# Line 1  Line 1 
 // $Id$  
 /*  
  *****************************************************************************  
  *                                                                           *  
  *       COPYRIGHT  ACcESS  -  All Rights Reserved                           *  
  *                                                                           *  
  * This software is the property of ACcESS. No part of this code             *  
  * may be copied in any form or by any means without the expressed written   *  
  * consent of ACcESS.  Copying, use or modification of this software         *  
  * by any unauthorised person is illegal unless that person has a software   *  
  * license agreement with ACcESS.                                            *  
  *                                                                           *  
  *****************************************************************************  
 */  
 #include "esysUtils/EsysException.h"  
 #include "escript/Data/Data.h"  
 #include "escript/Data/FunctionSpace.h"  
1    
2  #include "DataTestCase.h"  /* $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>  #include <iostream>
17    #if (defined _WIN32) && (defined __INTEL_COMPILER)
18    #include <mathimf.h>
19    #else
20  #include <math.h>  #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;  using namespace std;
32  using namespace CppUnitTest;  using namespace CppUnitTest;
33  using namespace escript;  using namespace escript;
34  using namespace esysUtils;  using namespace esysUtils;
35    using namespace escript::DataTypes;
36    
37  void DataTestCase::setUp() {  void DataTestCase::setUp() {
38    //    //
# Line 36  void DataTestCase::tearDown() { Line 44  void DataTestCase::tearDown() {
44    // This is called after each test has been run    // This is called after each test has been run
45  }  }
46    
47    
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    // This is to test new copy routines, existing tests should remain where they are
69    void DataTestCase::testCopying()
70    {
71      using namespace escript::DataTypes;
72      cout << endl;
73      {
74        // first we test the deep copy
75        cout << "\tTest deep copy DataConstant" << endl;
76        DataTypes::ShapeType shape;
77        shape.push_back(2);
78        shape.push_back(3);
79        DataTypes::ValueType data(DataTypes::noValues(shape),1);
80        DataConstant* dc=new DataConstant(FunctionSpace(),shape,data);
81        Data d(dc);
82        
83        Data* deep=d.copySelf();    // test self copy
84        for (int i=0;i<DataTypes::noValues(shape);++i)
85        {
86           if (d.getDataAtOffset(i)!=deep->getDataAtOffset(i))
87            assert(false);
88        }
89        d.setToZero();
90        for (int i=0;i<DataTypes::noValues(shape);++i)
91        {
92           if (d.getDataAtOffset(i)==deep->getDataAtOffset(i))
93            assert(false);
94        }
95        d.copy(*deep);          // test copy from object
96        for (int i=0;i<DataTypes::noValues(shape);++i)
97        {
98           if (d.getDataAtOffset(i)!=deep->getDataAtOffset(i))
99            assert(false);
100        }
101        d.setToZero();
102        for (int i=0;i<DataTypes::noValues(shape);++i)
103        {
104           if (d.getDataAtOffset(i)==deep->getDataAtOffset(i))
105            assert(false);
106        }
107        delete deep;
108      }
109    
110      {
111        // first we test the deep copy
112        cout << "\tTest deep copy DataExpanded" << endl;
113        DataTypes::ShapeType shape;
114        shape.push_back(2);
115        shape.push_back(3);
116        DataTypes::ValueType data(DataTypes::noValues(shape),1);
117        DataExpanded* dc=new DataExpanded(FunctionSpace(),shape,data);
118        Data d(dc);
119        
120        Data* deep=d.copySelf();    // test self copy
121        for (int i=0;i<DataTypes::noValues(shape);++i)
122        {
123           if (d.getDataAtOffset(i)!=deep->getDataAtOffset(i))
124            assert(false);
125        }
126        d.setToZero();
127        for (int i=0;i<DataTypes::noValues(shape);++i)
128        {
129           if (d.getDataAtOffset(i)==deep->getDataAtOffset(i))
130            assert(false);
131        }
132        d.copy(*deep);          // test copy from object
133        for (int i=0;i<DataTypes::noValues(shape);++i)
134        {
135           if (d.getDataAtOffset(i)!=deep->getDataAtOffset(i))
136            assert(false);
137        }
138        d.setToZero();
139        for (int i=0;i<DataTypes::noValues(shape);++i)
140        {
141           if (d.getDataAtOffset(i)==deep->getDataAtOffset(i))
142            assert(false);
143        }
144        delete deep;
145      }
146      {
147        // first we test the deep copy
148        cout << "\tTest deep copy DataTagged" << endl;
149        DataTypes::ShapeType shape;
150        shape.push_back(2);
151        shape.push_back(3);
152        DataTypes::ValueType data(DataTypes::noValues(shape),1);
153        DataTagged* dc=new DataTagged(FunctionSpace(),shape,data);
154        Data d(dc);
155        
156        Data* deep=d.copySelf();    // test self copy
157        for (int i=0;i<DataTypes::noValues(shape);++i)
158        {
159           if (d.getDataAtOffset(i)!=deep->getDataAtOffset(i))
160            assert(false);
161        }
162        d.setToZero();
163        for (int i=0;i<DataTypes::noValues(shape);++i)
164        {
165           if (d.getDataAtOffset(i)==deep->getDataAtOffset(i))
166            assert(false);
167        }
168        d.copy(*deep);          // test copy from object
169        for (int i=0;i<DataTypes::noValues(shape);++i)
170        {
171           if (d.getDataAtOffset(i)!=deep->getDataAtOffset(i))
172            assert(false);
173        }
174        d.setToZero();
175        for (int i=0;i<DataTypes::noValues(shape);++i)
176        {
177           if (d.getDataAtOffset(i)==deep->getDataAtOffset(i))
178            assert(false);
179        }
180        delete deep;
181      }
182    
183    }
184    
185  void DataTestCase::testSlicing() {  void DataTestCase::testSlicing() {
186    
187      using namespace escript::DataTypes;
188    cout << endl;    cout << endl;
189    
190    {    {
191      DataArrayView::ShapeType viewShape;  
192      //      cout << "\tTest get-slicing DataConstant" << endl;
193      // weak tests for slicing DataConstant  
194      cout << "\tTest slicing DataConstant" << endl;      DataTypes::ShapeType viewShape;
195      viewShape.push_back(2);      viewShape.push_back(2);
196      viewShape.push_back(3);      viewShape.push_back(3);
197      Data temp(1.3,viewShape,FunctionSpace(),false);      Data data(1.3,viewShape,FunctionSpace(),false);
198      DataArrayView::RegionType region;  
199      region.push_back(DataArrayView::RegionType::value_type(0,0));      //cout << data.toString() << endl;
200      region.push_back(DataArrayView::RegionType::value_type(0,0));  
201      Data slice(temp.getSlice(region));      DataTypes::RegionType region;
202      assert(slice.getDataPointRank()==0);      region.push_back(DataTypes::RegionType::value_type(0,0));
203      assert(slice.getDataPoint(0,0)()==1.3);      region.push_back(DataTypes::RegionType::value_type(0,0));
204      //  
205      // try the same but this time to produce a matrix containing one value      Data slice1(data.getSlice(region));
206    
207        //cout << slice1.toString() << endl;
208    
209        assert(slice1.getDataPointRank()==0);
210        assert(slice1.getDataPoint(0,0)==1.3);
211    
212      region.clear();      region.clear();
213      region.push_back(DataArrayView::RegionType::value_type(0,1));      region.push_back(DataTypes::RegionType::value_type(0,1));
214      region.push_back(DataArrayView::RegionType::value_type(0,1));      region.push_back(DataTypes::RegionType::value_type(0,1));
215      slice=temp.getSlice(region);  
216      assert(slice.getDataPointRank()==2);      Data slice2(data.getSlice(region));
217      assert(slice.getDataPoint(0,0)(0,0)==1.3);  
218        //cout << slice2.toString() << endl;
219    
220        assert(slice2.getDataPointRank()==2);
221        int off1=slice2.getDataOffset(0,0);
222    //     assert(slice2.getDataPoint(0,0)(0,0)==1.3);
223        assert(slice2.getDataAtOffset(off1+getRelIndex(slice2.getDataPointShape(),0,0))==1.3);
224    
225        region.clear();
226        region.push_back(DataTypes::RegionType::value_type(0,1));
227        region.push_back(DataTypes::RegionType::value_type(0,2));
228    
229        Data slice3(data.getSlice(region));
230    
231        //cout << slice3.toString() << endl;
232    
233        assert(slice3.getDataPointRank()==2);
234        off1=slice3.getDataOffset(0,0);
235    //     assert(slice3.getDataPoint(0,0)(0,0)==1.3);
236    //     assert(slice3.getDataPoint(0,0)(0,1)==1.3);
237        assert(slice3.getDataAtOffset(off1+getRelIndex(slice3.getDataPointShape(),0,0))==1.3);
238        assert(slice3.getDataAtOffset(off1+getRelIndex(slice3.getDataPointShape(),0,1))==1.3);
239    
240    }    }
241    
242    {    {
243      DataArrayView::ShapeType viewShape;  
244      //      cout << "\tTest set-slicing DataConstant" << endl;
245      // weak tests for slicing DataExpanded  
246      cout << "\tTest slicing DataExpanded" << endl;      DataTypes::ShapeType viewShape;
247        Data source(10.0,viewShape,FunctionSpace(),false);
248    
249        //cout << source.toString() << endl;
250    
251      viewShape.push_back(2);      viewShape.push_back(2);
252      viewShape.push_back(3);      viewShape.push_back(3);
253      Data temp(1.3,viewShape,FunctionSpace(),true);      Data target(1.3,viewShape,FunctionSpace(),false);
254      temp.getDataPoint(0,0)(0,0)=0.0;  
255      temp.getDataPoint(0,0)(1,1)=1.0;      //cout << target.toString() << endl;
256      DataArrayView::RegionType region;  
257      region.push_back(DataArrayView::RegionType::value_type(0,0));      DataTypes::RegionType region;
258      region.push_back(DataArrayView::RegionType::value_type(0,0));      region.push_back(DataTypes::RegionType::value_type(0,0));
259      Data slice(temp.getSlice(region));      region.push_back(DataTypes::RegionType::value_type(0,0));
260      assert(slice.getDataPointRank()==0);  
261      assert(slice.getDataPoint(0,0)()==0.0);      target.setSlice(source,region);
262      //  
263      // try the same but this time to produce a matrix containing one value      //cout << target.toString() << endl;
264      region.clear();  
265      region.push_back(DataArrayView::RegionType::value_type(0,1));      int off1=target.getDataOffset(0,0);
266      region.push_back(DataArrayView::RegionType::value_type(0,1));      assert(target.getDataAtOffset(off1+getRelIndex(target.getDataPointShape(),0,0)==source.getDataPoint(0,0)));
267      slice=temp.getSlice(region);  
     assert(slice.getDataPointRank()==2);  
     assert(slice.getDataPoint(0,0)(0,0)==0.0);  
     region.clear();  
     region.push_back(DataArrayView::RegionType::value_type(0,2));  
     region.push_back(DataArrayView::RegionType::value_type(0,2));  
     slice=temp.getSlice(region);  
     assert(slice.getDataPoint(0,0)(0,0)==0.0);  
     assert(slice.getDataPoint(0,0)(1,1)==1.0);  
268    }    }
269    
270    {    {
271      DataArrayView::ShapeType viewShape;  
272        cout << "\tTest get-slicing DataTagged" << endl;
273      //      //
274      // weak tests for slicing DataTagged      // create a DataTagged with a default value only
275      cout << "\tTest slicing DataTagged" << endl;  
276        DataTypes::ShapeType viewShape;
277      viewShape.push_back(2);      viewShape.push_back(2);
278      viewShape.push_back(3);      viewShape.push_back(3);
279      Data temp(1.3,viewShape,FunctionSpace(),false);      Data data(1.3,viewShape,FunctionSpace(),false);
280        data.tag();
281        data.getDataAtOffset(data.getDataOffset(0,0)+getRelIndex(viewShape,0,0))=1.0;
282        data.getDataAtOffset(data.getDataOffset(0,0)+getRelIndex(viewShape,1,1))=2.0;  
283    //     data.getDataPoint(0,0)(0,0)=1.0;
284    //     data.getDataPoint(0,0)(1,1)=2.0;
285    
286        //cout << data.toString() << endl;
287      //      //
288      // convert the data to tagged      // create a scalar slice
289      temp.tag();  
290      temp.getDataPoint(0,0)(0,0)=0.0;      DataTypes::RegionType region;
291      temp.getDataPoint(0,0)(1,1)=1.0;      region.push_back(DataTypes::RegionType::value_type(0,0));
292      DataArrayView::RegionType region;      region.push_back(DataTypes::RegionType::value_type(0,0));
293      region.push_back(DataArrayView::RegionType::value_type(0,0));  
294      region.push_back(DataArrayView::RegionType::value_type(0,0));      Data slice1(data.getSlice(region));
295      Data slice(temp.getSlice(region));      //cout << slice1.toString() << endl;
296      assert(slice.getDataPointRank()==0);  
297      assert(slice.getDataPoint(0,0)()==0.0);      assert(slice1.isTagged());
298        assert(slice1.getDataPointRank()==0);
299        assert(slice1.getDataPoint(0,0)==1.0);
300      //      //
301      // try the same but this time to produce a matrix containing one value      // create a rank 2 slice with one value
302    
303      region.clear();      region.clear();
304      region.push_back(DataArrayView::RegionType::value_type(0,1));      region.push_back(DataTypes::RegionType::value_type(0,1));
305      region.push_back(DataArrayView::RegionType::value_type(0,1));      region.push_back(DataTypes::RegionType::value_type(0,1));
306      slice=temp.getSlice(region);  
307      assert(slice.getDataPointRank()==2);      Data slice2(data.getSlice(region));
308      assert(slice.getDataPoint(0,0)(0,0)==0.0);  
309        //cout << slice2.toString() << endl;
310    
311        assert(slice2.isTagged());
312        assert(slice2.getDataPointRank()==2);
313    
314        assert(slice2.getDataAtOffset(slice2.getDataOffset(0,0)+getRelIndex(slice2.getDataPointShape(),0,0))==1.0);
315    
316        //
317        // create a rank 2 slice with four values
318    
319      region.clear();      region.clear();
320      region.push_back(DataArrayView::RegionType::value_type(0,2));      region.push_back(DataTypes::RegionType::value_type(0,2));
321      region.push_back(DataArrayView::RegionType::value_type(0,2));      region.push_back(DataTypes::RegionType::value_type(0,2));
322      slice=temp.getSlice(region);  
323      assert(slice.getDataPoint(0,0)(0,0)==0.0);      Data slice3(data.getSlice(region));
324      assert(slice.getDataPoint(0,0)(1,1)==1.0);  
325        //cout << slice3.toString() << endl;
326    
327        assert(slice3.isTagged());
328        assert(slice3.getDataPointRank()==2);
329        assert(getRef(slice3,0,0,0,0)==1.0);
330        assert(getRef(slice3,0,0,0,1)==1.3);
331        assert(getRef(slice3,0,0,1,0)==1.3);
332        assert(getRef(slice3,0,0,1,1)==2.0);
333    
334        //
335        // add a value for tag "1"
336    
337        DataTypes::ValueType viewData(6);
338        for (int i=0;i<viewData.size();i++) {
339          viewData[i]=i;
340        }
341    //    DataArrayView dataView(viewData,viewShape);
342    
343    //     data.setTaggedValueFromCPP(1, dataView);
344        data.setTaggedValueFromCPP(1, viewShape, viewData);
345    
346    
347        //
348        // create a full slice
349    
350        region.clear();
351        region.push_back(DataTypes::RegionType::value_type(0,2));
352        region.push_back(DataTypes::RegionType::value_type(0,3));
353    
354        Data slice4(data.getSlice(region));
355    
356        //cout << slice4.toString() << endl;
357    
358        assert(slice4.isTagged());
359        assert(slice4.getDataPointRank()==2);
360        assert(getRef(slice4,0,0,0,0)==0);
361        assert(getRef(slice4,0,0,0,1)==2);
362        assert(getRef(slice4,0,0,0,2)==4);
363        assert(getRef(slice4,0,0,1,0)==1);
364        assert(getRef(slice4,0,0,1,1)==3);
365        assert(getRef(slice4,0,0,1,2)==5);
366    
367    }    }
368    
369    {    {
370      DataArrayView::ShapeType viewShape;  
371        cout << "\tTest set-slicing DataTagged" << endl;
372    
373        //
374        // create a source DataTagged with a scalar default value only
375    
376        DataTypes::ShapeType viewShape;
377      Data source(10.0,viewShape,FunctionSpace(),false);      Data source(10.0,viewShape,FunctionSpace(),false);
378        source.tag();
379    
380        //cout << "source:\n" << source.toString() << endl;
381    
382      //      //
383      // weak tests for setting a slice of DataConstant      // create a target DataTagged with a rank 2 default value only
384      cout << "\tTest slicing DataConstant" << endl;  
385      viewShape.push_back(2);      viewShape.push_back(2);
386      viewShape.push_back(3);      viewShape.push_back(3);
387      Data target(1.3,viewShape,FunctionSpace(),false);      Data target(1.3,viewShape,FunctionSpace(),false);
388      DataArrayView::RegionType region;      target.tag();
389      region.push_back(DataArrayView::RegionType::value_type(0,0));  
390      region.push_back(DataArrayView::RegionType::value_type(0,0));      //cout << "target:\n" << target.toString() << endl;
391    
392        //
393        // set a slice in target from source
394    
395        DataTypes::RegionType region;
396        region.push_back(DataTypes::RegionType::value_type(1,1));
397        region.push_back(DataTypes::RegionType::value_type(1,1));
398    
399        target.setSlice(source,region);
400    
401        //cout << "target:\n" << target.toString() << endl;
402    
403        assert(target.isTagged());
404        assert(target.getDataPointRank()==2);
405        assert(getRef(target,0,0,0,0)==1.3);
406        assert(getRef(target,0,0,0,1)==1.3);
407        assert(getRef(target,0,0,0,2)==1.3);
408        assert(getRef(target,0,0,1,0)==1.3);
409        assert(getRef(target,0,0,1,1)==source.getDataPoint(0,0));
410        assert(getRef(target,0,0,1,2)==1.3);
411    
412        //
413        // add a value for tag "1" to target
414    
415        DataTypes::ValueType viewData(6);
416        for (int i=0;i<viewData.size();i++) {
417          viewData[i]=i;
418        }
419    //     DataArrayView dataView(viewData,viewShape);
420    //
421    //     target.setTaggedValueFromCPP(1, dataView);
422        target.setTaggedValueFromCPP(1, viewShape, viewData);
423    
424        //cout << "target:\n" << target.toString() << endl;
425    
426        //
427        // set a slice in target from source
428    
429        region.clear();
430        region.push_back(DataTypes::RegionType::value_type(0,0));
431        region.push_back(DataTypes::RegionType::value_type(1,1));
432    
433        target.setSlice(source,region);
434    
435        //cout << "target:\n" << target.toString() << endl;
436    
437        assert(target.isTagged());
438        assert(target.getDataPointRank()==2);
439        assert(getRef(target,0,0,0,0)==0);
440        assert(getRef(target,0,0,0,1)==source.getDataPoint(0,0));
441        assert(getRef(target,0,0,0,2)==4);
442        assert(getRef(target,0,0,1,0)==1);
443        assert(getRef(target,0,0,1,1)==3);
444        assert(getRef(target,0,0,1,2)==5);
445    
446        //
447        // add a value for tag "2" to source
448    
449        DataTypes::ShapeType viewShape2;
450        DataTypes::ValueType viewData2(1);
451        viewData2[0]=6;
452    //     DataArrayView dataView2(viewData2,viewShape2);
453    //
454    //     source.setTaggedValueFromCPP(2, dataView2);
455        source.setTaggedValueFromCPP(2, viewShape2, viewData2);
456    
457        //cout << "source:\n" << source.toString() << endl;
458    
459        //
460        // set a slice in target from source
461    
462        region.clear();
463        region.push_back(DataTypes::RegionType::value_type(0,0));
464        region.push_back(DataTypes::RegionType::value_type(1,1));
465    
466      target.setSlice(source,region);      target.setSlice(source,region);
467      assert(target.getDataPoint(0,0)(0,0)==source.getDataPoint(0,0)());  
468        //cout << "target:\n" << target.toString() << endl;
469    
470        assert(target.isTagged());
471        assert(target.getDataPointRank()==2);
472    
473        // use a non-existant tag so we get a pointer to the default value
474        // ie: the first element in the data array
475        DataAbstract::ValueType::value_type* targetData=target.getSampleDataByTag(9);
476        for (int i=0; i<target.getLength(); i++) {
477          assert(targetData[i]>=0);
478        }
479        assert(targetData[0]==1.3);
480        assert(targetData[1]==1.3);
481        assert(targetData[2]==10);
482        assert(targetData[3]==10);
483        assert(targetData[4]==1.3);
484        assert(targetData[5]==1.3);
485        assert(targetData[6]==0);
486        assert(targetData[7]==1);
487        assert(targetData[8]==10);
488        assert(targetData[9]==3);
489        assert(targetData[10]==4);
490        assert(targetData[11]==5);
491        assert(targetData[12]==1.3);
492        assert(targetData[13]==1.3);
493        assert(targetData[14]==6);
494        assert(targetData[15]==10);
495        assert(targetData[16]==1.3);
496        assert(targetData[17]==1.3);
497    
498    }    }
499    
500    {    {
501      DataArrayView::ShapeType viewShape;  
502      Data source(10.0,viewShape,FunctionSpace(),true);      cout << "\tTest get-slicing DataExpanded" << endl;
503      //  
504      // weak tests for setting a slice of DataExpanded      DataTypes::ShapeType viewShape;
505      viewShape.push_back(2);      viewShape.push_back(2);
506      viewShape.push_back(3);      viewShape.push_back(3);
507      Data target(1.3,viewShape,FunctionSpace(),true);      Data temp(1.3,viewShape,FunctionSpace(),true);
508      DataArrayView::RegionType region;  
509      region.push_back(DataArrayView::RegionType::value_type(0,0));      getRef(temp,0,0,0,0)=0.0;
510      region.push_back(DataArrayView::RegionType::value_type(0,0));      getRef(temp,0,0,1,1)=1.0;
511      target.setSlice(source,region);  
512      assert(target.getDataPoint(0,0)(0,0)==source.getDataPoint(0,0)());      DataTypes::RegionType region;
513        region.push_back(DataTypes::RegionType::value_type(0,0));
514        region.push_back(DataTypes::RegionType::value_type(0,0));
515    
516        Data slice(temp.getSlice(region));
517    
518        assert(slice.getDataPointRank()==0);
519        assert(slice.getDataPoint(0,0)==0.0);
520    
521        region.clear();
522        region.push_back(DataTypes::RegionType::value_type(0,1));
523        region.push_back(DataTypes::RegionType::value_type(0,1));
524    
525        slice=temp.getSlice(region);
526    
527        assert(slice.getDataPointRank()==2);
528        assert(getRef(slice,0,0,0,0)==0.0);
529    
530        region.clear();
531        region.push_back(DataTypes::RegionType::value_type(0,2));
532        region.push_back(DataTypes::RegionType::value_type(0,2));
533    
534        slice=temp.getSlice(region);
535    
536        assert(getRef(slice,0,0,0,0)==0.0);
537        assert(getRef(slice,0,0,1,1)==1.0);
538    
539    }    }
540    
541    {    {
542      DataArrayView::ShapeType viewShape;  
543      Data source(10.0,viewShape,FunctionSpace(),false);      cout << "\tTest set-slicing DataExpanded" << endl;
544      source.tag();  
545      //      DataTypes::ShapeType viewShape;
546      // weak tests for slicing DataTagged      Data source(10.0,viewShape,FunctionSpace(),true);
547      cout << "\tTest slicing DataTagged" << endl;  
548      viewShape.push_back(2);      viewShape.push_back(2);
549      viewShape.push_back(3);      viewShape.push_back(3);
550      Data target(1.3,viewShape,FunctionSpace(),false);      Data target(1.3,viewShape,FunctionSpace(),true);
551      //  
552      // convert the data to tagged      DataTypes::RegionType region;
553      target.tag();      region.push_back(DataTypes::RegionType::value_type(0,0));
554      DataArrayView::RegionType region;      region.push_back(DataTypes::RegionType::value_type(0,0));
555      region.push_back(DataArrayView::RegionType::value_type(0,0));  
     region.push_back(DataArrayView::RegionType::value_type(0,0));  
556      target.setSlice(source,region);      target.setSlice(source,region);
557      assert(target.getDataPoint(0,0)(0,0)==source.getDataPoint(0,0)());  
558        assert(getRef(target,0,0,0,0)==source.getDataPoint(0,0));
559    
560    }    }
561    
562  }  }
563    
564  void DataTestCase::testMore() {  void DataTestCase::testAll() {
565    
566    cout << endl;    cout << endl;
567    
568    cout << "\tCreate a Data object from a DataArrayView" << endl;    cout << "\tCreate a Data object from a DataArrayView" << endl;
569    
570    DataArrayView::ShapeType viewShape;    DataTypes::ShapeType viewShape;
571    viewShape.push_back(3);    viewShape.push_back(3);
572    DataArrayView::ValueType viewData(3);    DataTypes::ValueType viewData(3);
573    for (int i=0;i<viewShape[0];++i) {    for (int i=0;i<viewShape[0];++i) {
574      viewData[i]=i;      viewData[i]=i;
575    }    }
576    DataArrayView myView(viewData,viewShape);  //   DataArrayView myView(viewData,viewShape);
577    
578    bool expanded=true;    bool expanded=true;
579    Data exData(myView,FunctionSpace(),expanded);    Data exData(viewData,viewShape,FunctionSpace(),expanded);
580    Data cData(myView);  //   Data cData(myView);
581      Data cData(viewData,viewShape,FunctionSpace());
582    Data result;    Data result;
583    
584    assert(exData.isExpanded());    assert(exData.isExpanded());
# Line 211  void DataTestCase::testMore() { Line 589  void DataTestCase::testMore() {
589    result=exData*cData;    result=exData*cData;
590    assert(result.isExpanded());    assert(result.isExpanded());
591    
   assert(result.Lsup()==4);  
   assert(result.sup()==4);  
   assert(result.inf()==0);  
   
   result=exData+cData;  
   result=exData-cData;  
   result=exData/cData;  
   
   cout << "\tExercise wherePositive method" << endl;  
   assert(!exData.wherePositive().isEmpty());  
   
   cout << "\tExercise copyWithMask method" << endl;  
   exData.copyWithMask(result, exData.wherePositive());  
   assert(!exData.wherePositive().isEmpty());  
   
592  }  }
593    
594  void DataTestCase::testAll() {  void DataTestCase::testMore() {
595    
596    cout << endl;    cout << endl;
597    
598    cout << "\tCreate a Data object from a DataArrayView" << endl;    cout << "\tCreate a Data object from a DataArrayView" << endl;
599    
600    DataArrayView::ShapeType viewShape;    DataTypes::ShapeType viewShape;
601    viewShape.push_back(3);    viewShape.push_back(3);
602    DataArrayView::ValueType viewData(3);    DataTypes::ValueType viewData(3);
603    for (int i=0;i<viewShape[0];++i) {    for (int i=0;i<viewShape[0];++i) {
604      viewData[i]=i;      viewData[i]=i;
605    }    }
606    DataArrayView myView(viewData,viewShape);  //   DataArrayView myView(viewData,viewShape);
607    
608    bool expanded=true;    bool expanded=true;
609      Data exData(viewData,viewShape,FunctionSpace(),expanded);
610    Data exData(myView,FunctionSpace(),expanded);    Data cData(viewData,viewShape);
   Data cData(myView);  
611    Data result;    Data result;
612    
613    assert(exData.isExpanded());    assert(exData.isExpanded());
# Line 256  void DataTestCase::testAll() { Line 618  void DataTestCase::testAll() {
618    result=exData*cData;    result=exData*cData;
619    assert(result.isExpanded());    assert(result.isExpanded());
620    
621      assert(result.Lsup()==4);
622      assert(result.sup()==4);
623      assert(result.inf()==0);
624    
625      result=exData+cData;
626      result=exData-cData;
627      result=exData/cData;
628    
629      cout << "\tExercise wherePositive method" << endl;
630      assert(!exData.wherePositive().isEmpty());
631    
632      cout << "\tExercise copyWithMask method" << endl;
633      exData.copyWithMask(result, exData.wherePositive());
634      assert(!exData.wherePositive().isEmpty());
635    
636  }  }
637    
638  void DataTestCase::testDataConstant() {  void DataTestCase::testDataConstant() {
# Line 264  void DataTestCase::testDataConstant() { Line 641  void DataTestCase::testDataConstant() {
641    
642    cout << "\tCreate a DataConstant object from a DataArrayView" << endl;    cout << "\tCreate a DataConstant object from a DataArrayView" << endl;
643    
644    DataArrayView::ShapeType viewShape;    DataTypes::ShapeType viewShape;
645    viewShape.push_back(2);    viewShape.push_back(2);
646    viewShape.push_back(3);    viewShape.push_back(3);
647    viewShape.push_back(4);    viewShape.push_back(4);
648    DataArrayView::ValueType viewData(2*3*4);    DataTypes::ValueType viewData(2*3*4);
649    for (int i=0;i<DataArrayView::noValues(viewShape);++i) {    for (int i=0;i<DataTypes::noValues(viewShape);++i) {
650      viewData[i]=i;      viewData[i]=i;
651    }    }
652    DataArrayView myView(viewData,viewShape);  //   DataArrayView myView(viewData,viewShape);
653    
654    Data left(myView);    Data left(viewData,viewShape);
655    Data right(myView);    Data right(viewData,viewShape);
656    Data result;    Data result;
657    
658    cout << "\tTest some basic operations" << endl;    cout << "\tTest some basic operations" << endl;
# Line 297  void DataTestCase::testDataConstant() { Line 674  void DataTestCase::testDataConstant() {
674    
675  }  }
676    
677    void DataTestCase::testDataTagged() {
678    
679      cout << endl;
680    
681      {
682    
683        cout << "\tCreate a DataTagged object with a default value only." << endl;
684    
685    //    DataTagged::TagListType keys;
686    
687    //    DataTagged::ValueListType values;
688    
689        DataTypes::ShapeType viewShape;
690        viewShape.push_back(3);
691    
692        DataTypes::ValueType viewData(3);
693        for (int i=0;i<viewShape[0];i++) {
694          viewData[i]=i;
695        }
696    /*    DataArrayView defaultValue(viewData,viewShape);
697    
698        bool expanded=false;
699    
700        Data myData(keys,values,defaultValue,FunctionSpace(),expanded);*/
701        int arr[1]={1};     // iso c++ does not like empty arrays
702        DataTagged* dt=new DataTagged(FunctionSpace(),viewShape,arr,viewData);
703        Data myData(dt);
704    
705        // cout << myData.toString() << endl;
706    
707        assert(!myData.isEmpty());
708        assert(myData.isTagged());
709        assert(myData.getTagNumber(0)==1);
710        assert(myData.getDataPointRank()==1);
711        assert(myData.getLength()==3);
712        
713        assert(myData.getNoValues()==3);
714        assert(myData.getDataAtOffset(0)==0.0);
715        assert(myData.getDataAtOffset(1)==1.0);
716        assert(myData.getDataAtOffset(2)==2.0);
717    
718    //     DataArrayView myDataView = myData.getPointDataView();
719    //     assert(!myDataView.isEmpty());
720    //     assert(myDataView.getOffset()==0);
721    //     assert(myDataView.getRank()==1);
722    //     assert(myDataView.noValues()==3);
723    //     assert(myDataView.getShape().size()==1);
724    //     assert(myDataView(0)==0.0);
725    //     assert(myDataView(1)==1.0);
726    //     assert(myDataView(2)==2.0);
727    
728    //     myDataView = myData.getDataPoint(0,0);
729    //     assert(!myDataView.isEmpty());
730    //     assert(myDataView.getOffset()==0);
731    //     assert(myDataView.getRank()==1);
732    //     assert(myDataView.noValues()==3);
733    //     assert(myDataView.getShape().size()==1);
734    //     assert(myDataView(0)==0.0);
735    //     assert(myDataView(1)==1.0);
736    //     assert(myDataView(2)==2.0);
737    
738        double* sampleData=myData.getSampleData(0);
739        for (int i=0; i<myData.getNoValues(); i++) {
740          assert(sampleData[i]==i);
741        }
742        // use a non-existent tag so we get a pointer to
743        // the first element of the data array
744        sampleData=myData.getSampleDataByTag(9);
745        for (int i=0; i<myData.getLength(); i++) {
746          assert(sampleData[i]==i);
747        }
748    
749        cout << "\tTest setting of a tag and associated value." << endl;
750    
751        // value for tag "1"
752        DataTypes::ValueType eTwoData(viewData);
753     //   DataArrayView eTwoView(eTwoData, viewShape);
754        for (int i=0;i<viewShape[0];i++) {
755          eTwoData[i]=i+2.0;
756        }
757    
758        myData.setTaggedValueFromCPP(1,viewShape, eTwoData);
759    
760        assert(myData.getLength()==6);
761    
762        int offset=myData.getDataOffset(0,0);
763    //    myDataView = myData.getDataPoint(0,0);
764    //     assert(myDataView==eTwoView);
765    //     assert(!myDataView.isEmpty());
766        assert(offset==3);
767        assert(myData.getDataPointRank()==1);
768        assert(myData.getNoValues()==3);
769    //    assert(myDataView.getShape().size()==1);
770    
771        assert(myData.getDataAtOffset(offset+0)==2);
772        assert(myData.getDataAtOffset(offset+1)==3);
773        assert(myData.getDataAtOffset(offset+2)==4);
774    
775        sampleData=myData.getSampleDataByTag(1);
776        for (int i=0; i<myData.getNoValues(); i++) {
777          assert(sampleData[i]==i+2);
778        }
779    
780      }
781    
782      {
783    
784        cout << "\tCreate a DataTagged object via tag() method." << endl;
785    
786        DataTypes::ShapeType viewShape;
787        viewShape.push_back(2);
788        viewShape.push_back(3);
789        Data myData(1.3,viewShape,FunctionSpace(),false);
790        myData.tag();
791    
792        //cout << myData.toString() << endl;
793    
794        assert(!myData.isEmpty());
795        assert(myData.isTagged());
796        assert(myData.getTagNumber(0)==1);
797        assert(myData.getDataPointRank()==2);
798        assert(myData.getLength()==6);
799    
800        // check default value
801    //     DataArrayView myDataView = myData.getPointDataView();
802        assert(!myData.isEmpty());
803    //     assert(myDataView.getOffset()==0);
804        assert(myData.getDataPointRank()==2);
805        assert(myData.getNoValues()==6);
806        assert(myData.getDataPointShape().size()==2);
807        assert(getRef(myData,0,0)==1.3);
808        assert(getRef(myData,0,1)==1.3);
809        assert(getRef(myData,0,2)==1.3);
810        assert(getRef(myData,1,0)==1.3);
811        assert(getRef(myData,1,1)==1.3);
812        assert(getRef(myData,1,2)==1.3);
813    
814        // check value for data-point (0,0).
815    //     myDataView = myData.getDataPoint(0,0);
816        assert(!myData.isEmpty());
817    //     assert(myDataView.getOffset()==0);
818        assert(myData.getDataPointRank()==2);
819        assert(myData.getNoValues()==6);
820        assert(myData.getDataPointShape().size()==2);
821        assert(getRef(myData,0,0)==1.3);
822        assert(getRef(myData,0,1)==1.3);
823        assert(getRef(myData,0,2)==1.3);
824        assert(getRef(myData,1,0)==1.3);
825        assert(getRef(myData,1,1)==1.3);
826        assert(getRef(myData,1,2)==1.3);
827    
828      }
829    
830    }
831    
832  void DataTestCase::testDataTaggedExceptions() {  void DataTestCase::testDataTaggedExceptions() {
833    
834    cout << endl;    cout << endl;
835    
836    cout << "\tTest DataTagged operations exceptions." << endl;    cout << "\tTest DataTagged exceptions." << endl;
837    
838    Data myData;    Data myData;
   DataArrayView myView;  
839    
840    try {    try {
841        myData.getSampleDataByTag(0);;        myData.getSampleDataByTag(0);;
842        assert(false);        assert(false);
843    }    }
844    catch (EsysException& e) {    catch (EsysException&) {
845        //cout << e.what() << endl;        //cout << e.what() << endl;
846        assert(true);        assert(true);
847    }    }
848    
   /*  
849    try {    try {
850        myData.setTaggedValue(0,myView);;        myData.setTaggedValueFromCPP(0,DataTypes::ShapeType(), DataTypes::ValueType());;
851        assert(false);        assert(false);
852    }    }
853    catch (EsysException& e) {    catch (EsysException&) {
854        //cout << e.what() << endl;        //cout << e.what() << endl;
855        assert(true);        assert(true);
856    }    }
   */  
   
 }  
   
 void DataTestCase::testDataTagged() {  
   
   cout << endl;  
   
   cout << "\tCreate a DataTagged object from a DataArrayView" << endl;  
   
   DataTagged::TagListType keys;  
   DataTagged::ValueListType values;  
   DataArrayView::ShapeType viewShape;  
   viewShape.push_back(3);  
   DataArrayView::ValueType viewData(3);  
   for (int i=0;i<viewShape[0];++i) {  
     viewData[i]=i;  
   }  
   DataArrayView myView(viewData,viewShape);  
   
   // create tagged data with no tag values just a default  
   bool expanded=false;  
   
   Data myData(keys,values,myView,FunctionSpace(),expanded);  
   assert(myData.isTagged());  
   
   cout << "\tTest some basic operations" << endl;  
   
   Data myDataCopy(myData);  
   myDataCopy.expand();  
   assert(myDataCopy.isExpanded());  
857    
858  }  }
859    
# Line 362  void DataTestCase::testConstructors() { Line 861  void DataTestCase::testConstructors() {
861    
862    cout << endl;    cout << endl;
863    
864    DataArrayView::ShapeType viewShape;    DataTypes::ShapeType viewShape;
865    {    {
866      cout << "\tCreate an Empty Data object" << endl;      cout << "\tCreate an Empty Data object" << endl;
867      Data temp(1.3,viewShape,FunctionSpace(),false);      Data temp(1.3,viewShape,FunctionSpace(),false);
# Line 380  void DataTestCase::testOperations() { Line 879  void DataTestCase::testOperations() {
879    cout << endl;    cout << endl;
880    
881    // define the shape for the DataArrayView test data    // define the shape for the DataArrayView test data
882    DataArrayView::ShapeType shape;    DataTypes::ShapeType shape;
883    shape.push_back(2);    shape.push_back(2);
884    shape.push_back(3);    shape.push_back(3);
885    
886    // allocate the data for the DataArrayView    // allocate the data for the DataArrayView
887    DataArrayView::ValueType data(DataArrayView::noValues(shape),0);    DataTypes::ValueType data(DataTypes::noValues(shape),0);
888    
889    // construct DataArrayView    // construct DataArrayView
890    DataArrayView dataView(data,shape);  //   DataArrayView dataView(data,shape);
891    
892    // assign values to the data    // assign values to the data
893    for (int i=0;i<shape[0];i++) {    for (int i=0;i<shape[0];i++) {
894      for (int j=0;j<shape[1];j++) {      for (int j=0;j<shape[1];j++) {
895        dataView(i,j)=dataView.index(i,j);        data[getRelIndex(shape,i,j)]=getRelIndex(shape,i,j);
896      }      }
897    }    }
898    
899    Data base(dataView);    Data baseEx(data,shape,FunctionSpace(),true);
900      Data baseCon(data,shape,FunctionSpace(),false);
901      Data baseTag(data,shape,FunctionSpace(),false);
902      baseTag.tag();
903    
904      assert(baseEx.isExpanded());
905      assert(baseCon.isConstant());
906      assert(baseTag.isTagged());
907    
908      Data resultEx;
909      Data resultCon;
910      Data resultTag;
911    
912    // test unary operations    // test unary operations
913    
914      double tmp;
915    cout << "\tTest Data::pow." << endl;    cout << "\tTest Data::pow." << endl;
916    Data power(3.0,shape,FunctionSpace(),true);    Data power(3.0,shape,FunctionSpace(),true);
917    Data result(base.powD(power));    resultEx.copy(baseEx.powD(power));
918      resultCon.copy(baseCon.powD(power));
919      resultTag.copy(baseTag.powD(power));
920    for (int i=0;i<shape[0];i++) {    for (int i=0;i<shape[0];i++) {
921      for (int j=0;j<shape[1];j++) {      for (int j=0;j<shape[1];j++) {
922        assert(result.getPointDataView()(i,j) == pow(dataView.index(i,j),3.0));        tmp=pow((double)data[getRelIndex(shape,i,j)],(double)3.0);
923          assert(std::abs(getRef(resultEx,i,j) - tmp) <= REL_TOL*std::abs(tmp));
924          assert(std::abs(getRef(resultCon,i,j) - tmp) <= REL_TOL*std::abs(tmp));
925          assert(std::abs(getRef(resultTag,i,j) - tmp) <= REL_TOL*std::abs(tmp));
926      }      }
927    }    }
928    
929    cout << "\tTest Data::sin." << endl;    cout << "\tTest Data::sin." << endl;
930    result.copy(base.sin());    resultEx.copy(baseEx.sin());
931    assert(true);    resultCon.copy(baseCon.sin());
932      resultTag.copy(baseTag.sin());
933      for (int i=0;i<shape[0];i++) {
934        for (int j=0;j<shape[1];j++) {
935          tmp=sin((double)data[getRelIndex(shape,i,j)]);
936          assert(std::abs(getRef(resultEx,i,j) - tmp) <= REL_TOL*std::abs(tmp));
937          assert(std::abs(getRef(resultCon,i,j) - tmp) <= REL_TOL*std::abs(tmp));
938          assert(std::abs(getRef(resultTag,i,j) - tmp) <= REL_TOL*std::abs(tmp));
939        }
940      }
941    
942    cout << "\tTest Data::cos." << endl;    cout << "\tTest Data::cos." << endl;
943    result.copy(base.cos());    resultEx.copy(baseEx.cos());
944    assert(true);    resultCon.copy(baseCon.cos());
945      resultTag.copy(baseTag.cos());
946      for (int i=0;i<shape[0];i++) {
947        for (int j=0;j<shape[1];j++) {
948          tmp=cos((double)data[getRelIndex(shape,i,j)]);
949          assert(std::abs(getRef(resultEx,i,j) - tmp) <= REL_TOL*std::abs(tmp));
950          assert(std::abs(getRef(resultCon,i,j) - tmp) <= REL_TOL*std::abs(tmp));
951          assert(std::abs(getRef(resultTag,i,j) - tmp) <= REL_TOL*std::abs(tmp));
952        }
953      }
954    
955    cout << "\tTest Data::tan." << endl;    cout << "\tTest Data::tan." << endl;
956    result.copy(base.tan());    resultEx.copy(baseEx.tan());
957    assert(true);    resultCon.copy(baseCon.tan());
958      resultTag.copy(baseTag.tan());
959      for (int i=0;i<shape[0];i++) {
960        for (int j=0;j<shape[1];j++) {
961          tmp=tan((double)data[getRelIndex(shape,i,j)]);
962          assert(std::abs(getRef(resultEx,i,j) - tmp) <= REL_TOL*std::abs(tmp));
963          assert(std::abs(getRef(resultCon,i,j)- tmp) <= REL_TOL*std::abs(tmp));
964          assert(std::abs(getRef(resultTag,i,j)- tmp) <= REL_TOL*std::abs(tmp));
965        }
966      }
967    
968    cout << "\tTest Data::asin." << endl;    cout << "\tTest Data::asin." << endl;
969    result.copy(base.asin());    resultEx.copy(baseEx.asin());
970      resultCon.copy(baseCon.asin());
971      resultTag.copy(baseTag.asin());
972    assert(true);    assert(true);
973    
974    cout << "\tTest Data::acos." << endl;    cout << "\tTest Data::acos." << endl;
975    result.copy(base.acos());    resultEx.copy(baseEx.acos());
976      resultCon.copy(baseCon.acos());
977      resultTag.copy(baseTag.acos());
978    assert(true);    assert(true);
979    
980    cout << "\tTest Data::atan." << endl;    cout << "\tTest Data::atan." << endl;
981    result.copy(base.atan());    resultEx.copy(baseEx.atan());
982    assert(true);    resultCon.copy(baseCon.atan());
983      resultTag.copy(baseTag.atan());
984      for (int i=0;i<shape[0];i++) {
985        for (int j=0;j<shape[1];j++) {
986          tmp=atan((double)data[getRelIndex(shape,i,j)]);
987          assert(std::abs(getRef(resultEx,i,j) - tmp) <= REL_TOL*std::abs(tmp));
988          assert(std::abs(getRef(resultCon,i,j)- tmp) <= REL_TOL*std::abs(tmp));
989          assert(std::abs(getRef(resultTag,i,j)- tmp) <= REL_TOL*std::abs(tmp));
990        }
991      }
992    
993    cout << "\tTest Data::sinh." << endl;    cout << "\tTest Data::sinh." << endl;
994    result.copy(base.sinh());    resultEx.copy(baseEx.sinh());
995    assert(true);    resultCon.copy(baseCon.sinh());
996      resultTag.copy(baseTag.sinh());
997      for (int i=0;i<shape[0];i++) {
998        for (int j=0;j<shape[1];j++) {
999          tmp=sinh((double)data[getRelIndex(shape,i,j)]);
1000          assert(std::abs(getRef(resultEx,i,j) - tmp) <= REL_TOL*std::abs(tmp));
1001          assert(std::abs(getRef(resultCon,i,j)- tmp) <= REL_TOL*std::abs(tmp));
1002          assert(std::abs(getRef(resultTag,i,j)- tmp) <= REL_TOL*std::abs(tmp));
1003        }
1004      }
1005    
1006    cout << "\tTest Data::cosh." << endl;    cout << "\tTest Data::cosh." << endl;
1007    result.copy(base.cosh());    resultEx.copy(baseEx.cosh());
1008    assert(true);    resultCon.copy(baseCon.cosh());
1009      resultTag.copy(baseTag.cosh());
1010      for (int i=0;i<shape[0];i++) {
1011        for (int j=0;j<shape[1];j++) {
1012          tmp=cosh((double)data[getRelIndex(shape,i,j)]);
1013          assert(std::abs(getRef(resultEx,i,j) - tmp) <= REL_TOL*std::abs(tmp));
1014          assert(std::abs(getRef(resultCon,i,j)- tmp) <= REL_TOL*std::abs(tmp));
1015          assert(std::abs(getRef(resultTag,i,j)- tmp) <= REL_TOL*std::abs(tmp));
1016        }
1017      }
1018    
1019    cout << "\tTest Data::tanh." << endl;    cout << "\tTest Data::tanh." << endl;
1020    result.copy(base.tanh());    resultEx.copy(baseEx.tanh());
1021    assert(true);    resultCon.copy(baseCon.tanh());
1022      resultTag.copy(baseTag.tanh());
1023      for (int i=0;i<shape[0];i++) {
1024        for (int j=0;j<shape[1];j++) {
1025          tmp=tanh((double)data[getRelIndex(shape,i,j)]);
1026          assert(std::abs(getRef(resultEx,i,j) - tmp) <= REL_TOL*std::abs(tmp));
1027          assert(std::abs(getRef(resultCon,i,j)- tmp) <= REL_TOL*std::abs(tmp));
1028          assert(std::abs(getRef(resultTag,i,j)- tmp) <= REL_TOL*std::abs(tmp));
1029        }
1030      }
1031    
1032    cout << "\tTest Data::asinh." << endl;    cout << "\tTest Data::asinh." << endl;
1033    result.copy(base.asinh());    resultEx.copy(baseEx.asinh());
1034      resultCon.copy(baseCon.asinh());
1035      resultTag.copy(baseTag.asinh());
1036    assert(true);    assert(true);
1037    
1038    cout << "\tTest Data::acosh." << endl;    cout << "\tTest Data::acosh." << endl;
1039    result.copy(base.acosh());    resultEx.copy(baseEx.acosh());
1040      resultCon.copy(baseCon.acosh());
1041      resultTag.copy(baseTag.acosh());
1042    assert(true);    assert(true);
1043    
1044    cout << "\tTest Data::atanh." << endl;    cout << "\tTest Data::atanh." << endl;
1045    result.copy(base.atanh());    resultEx.copy(baseEx.atanh());
1046      resultCon.copy(baseCon.atanh());
1047      resultTag.copy(baseTag.atanh());
1048    assert(true);    assert(true);
1049    
1050    cout << "\tTest Data::log." << endl;    cout << "\tTest Data::log." << endl;
1051    result.copy(base.log());    resultEx.copy(baseEx.log());
1052      resultCon.copy(baseCon.log());
1053      resultTag.copy(baseTag.log());
1054    assert(true);    assert(true);
1055    
   //cout << "\tTest Data::ln." << endl;  
   //result.copy(base.ln());  
   //assert(true);  
   
1056    cout << "\tTest Data::abs." << endl;    cout << "\tTest Data::abs." << endl;
1057    result.copy(base.abs());    resultEx.copy(baseEx.abs());
1058    assert(true);    resultCon.copy(baseCon.abs());
1059      resultTag.copy(baseTag.abs());
1060      for (int i=0;i<shape[0];i++) {
1061        for (int j=0;j<shape[1];j++) {
1062          tmp=abs((double)data[getRelIndex(shape,i,j)]);
1063          assert(std::abs(getRef(resultEx,i,j) - tmp) <= REL_TOL*std::abs(tmp));
1064          assert(std::abs(getRef(resultCon,i,j)- tmp) <= REL_TOL*std::abs(tmp));
1065          assert(std::abs(getRef(resultTag,i,j)- tmp) <= REL_TOL*std::abs(tmp));
1066        }
1067      }
1068    
1069    cout << "\tTest Data::sign." << endl;    cout << "\tTest Data::sign." << endl;
1070    result.copy(base.sign());    resultEx.copy(baseEx.sign());
1071      resultCon.copy(baseCon.sign());
1072      resultTag.copy(baseTag.sign());
1073    assert(true);    assert(true);
1074    
1075    cout << "\tTest Data::exp." << endl;    cout << "\tTest Data::exp." << endl;
1076    result.copy(base.exp());    resultEx.copy(baseEx.exp());
1077    assert(true);    resultCon.copy(baseCon.exp());
1078      resultTag.copy(baseTag.exp());
1079      for (int i=0;i<shape[0];i++) {
1080        for (int j=0;j<shape[1];j++) {
1081          tmp=exp((double)data[getRelIndex(shape,i,j)]);
1082          assert(std::abs(getRef(resultEx,i,j) - tmp) <= REL_TOL*std::abs(tmp));
1083          assert(std::abs(getRef(resultCon,i,j)- tmp) <= REL_TOL*std::abs(tmp));
1084          assert(std::abs(getRef(resultTag,i,j)- tmp) <= REL_TOL*std::abs(tmp));
1085        }
1086      }
1087    
1088    cout << "\tTest Data::sqrt." << endl;    cout << "\tTest Data::sqrt." << endl;
1089    result.copy(base.sqrt());    resultEx.copy(baseEx.sqrt());
1090    assert(true);    resultCon.copy(baseCon.sqrt());
1091      resultTag.copy(baseTag.sqrt());
1092      for (int i=0;i<shape[0];i++) {
1093        for (int j=0;j<shape[1];j++) {
1094          tmp=sqrt((double)data[getRelIndex(shape,i,j)]);
1095          assert(std::abs(getRef(resultEx,i,j) - tmp) <= REL_TOL*std::abs(tmp));
1096          assert(std::abs(getRef(resultCon,i,j)- tmp) <= REL_TOL*std::abs(tmp));
1097          assert(std::abs(getRef(resultTag,i,j)- tmp) <= REL_TOL*std::abs(tmp));
1098        }
1099      }
1100    
1101    cout << "\tTest Data::neg." << endl;    cout << "\tTest Data::neg." << endl;
1102    result.copy(base.neg());    resultEx.copy(baseEx.neg());
1103      resultCon.copy(baseCon.neg());
1104      resultTag.copy(baseTag.neg());
1105    assert(true);    assert(true);
1106    
1107    cout << "\tTest Data::pos." << endl;    cout << "\tTest Data::pos." << endl;
1108    result.copy(base.pos());    resultEx.copy(baseEx.pos());
1109      resultCon.copy(baseCon.pos());
1110      resultTag.copy(baseTag.pos());
1111    for (int i=0;i<shape[0];i++) {    for (int i=0;i<shape[0];i++) {
1112      for (int j=0;j<shape[1];j++) {      for (int j=0;j<shape[1];j++) {
1113        assert(result.getPointDataView()(i,j) == dataView.index(i,j));        assert(std::abs(getRef(resultEx,i,j) - getRelIndex(shape,i,j)) <= REL_TOL*std::abs(data[getRelIndex(shape,i,j)]));
1114          assert(std::abs(getRef(resultCon,i,j) - getRelIndex(shape,i,j)) <= REL_TOL*std::abs(data[getRelIndex(shape,i,j)]));
1115          assert(std::abs(getRef(resultTag,i,j) - getRelIndex(shape,i,j)) <= REL_TOL*std::abs(data[getRelIndex(shape,i,j)]));
1116      }      }
1117    }    }
1118    
1119    // test reduction operations    // test reduction operations
1120    
1121    cout << "\tTest Data::Lsup." << endl;    cout << "\tTest Data::Lsup." << endl;
1122    assert(base.Lsup() == 5);    assert(std::abs(baseEx.Lsup() - 5) <= REL_TOL*5);
1123      assert(std::abs(baseCon.Lsup() - 5) <= REL_TOL*5);
1124      assert(std::abs(baseTag.Lsup() - 5) <= REL_TOL*5);
1125    
1126    cout << "\tTest Data::sup." << endl;    cout << "\tTest Data::sup." << endl;
1127    assert(base.sup() == 5);    assert(std::abs(baseEx.sup() - 5) <= REL_TOL*5);
1128      assert(std::abs(baseCon.sup() - 5) <= REL_TOL*5);
1129      assert(std::abs(baseTag.sup() - 5) <= REL_TOL*5);
1130    
1131    cout << "\tTest Data::inf." << endl;    cout << "\tTest Data::inf." << endl;
1132    assert(base.inf() == 0);    assert(std::abs(baseEx.inf() - 0) <= REL_TOL*0);
1133      assert(std::abs(baseCon.inf() - 0) <= REL_TOL*0);
1134      assert(std::abs(baseTag.inf() - 0) <= REL_TOL*0);
1135    
1136    // test data-point reduction operations    // test data-point reduction operations
1137    
1138    cout << "\tTest Data::minval." << endl;    cout << "\tTest Data::minval." << endl;
1139    result.copy(base.minval());    resultEx.copy(baseEx.minval());
1140    assert(result.getPointDataView()() == 0);    resultCon.copy(baseCon.minval());
1141      resultTag.copy(baseTag.minval());
1142    //   assert(std::abs(resultEx.getPointDataView()() - 0) <= REL_TOL*0);
1143    //   assert(std::abs(resultCon.getPointDataView()() - 0) <= REL_TOL*0);
1144    //   assert(std::abs(resultTag.getPointDataView()() - 0) <= REL_TOL*0);
1145      assert(std::abs(resultEx.getDataAtOffset(0) - 0) <= REL_TOL*0);
1146      assert(std::abs(resultCon.getDataAtOffset(0) - 0) <= REL_TOL*0);
1147      assert(std::abs(resultTag.getDataAtOffset(0) - 0) <= REL_TOL*0);
1148    
1149    cout << "\tTest Data::maxval." << endl;    cout << "\tTest Data::maxval." << endl;
1150    result.copy(base.maxval());    resultEx.copy(baseEx.maxval());
1151    assert(result.getPointDataView()() == 5);    resultCon.copy(baseCon.maxval());
1152      resultTag.copy(baseTag.maxval());
1153    //cout << "\tTest Data::length." << endl;    assert(std::abs(resultEx.getDataAtOffset(0) - 5) <= REL_TOL*5);
1154    //result.copy(base.length());    assert(std::abs(resultCon.getDataAtOffset(0) - 5) <= REL_TOL*5);
1155    //assert(pow(result.getPointDataView()(),2.0) == 55);    assert(std::abs(resultTag.getDataAtOffset(0) - 5) <= REL_TOL*5);
   
   cout << "\tTest Data::trace." << endl;  
   result.copy(base.trace());  
   assert(result.getPointDataView()() == 15);  
   
   //result.copy(base.transpose(0));  
   //assert(true);  
1156    
1157  }  }
1158    
 void DataTestCase::testRefValue() {  
   
   //  
   // Note - this test can't be run as boost::python::numeric::array  
   // objects can only be created and used from within a python thread!  
   //  
   
   cout << endl;  
   
   cout << "\tTest Data object RefValue methods." << endl;  
   
   // Create three Data object - DataExpanded, DataConstant and DataEmpty  
   DataArrayView::ShapeType viewShape;  
   viewShape.push_back(3);  
   DataArrayView::ValueType viewData(3);  
   for (int i=0;i<viewShape[0];++i) {  
     viewData[i]=i;  
   }  
   DataArrayView myView(viewData,viewShape);  
   
   bool expanded=true;  
   
   Data expandedData(myView,FunctionSpace(),expanded);  
   Data constantData(myView);  
   Data emptyData;  
   
   assert(expandedData.isExpanded());  
   assert(constantData.isConstant());  
   assert(emptyData.isEmpty());  
   
   // Check assertions are thrown for RefValue methods on DataEmpty  
   
   int ref = 0;  
   boost::python::numeric::array num_array(1.0);  
   
   try {  
       emptyData.getRefValue(ref,num_array);  
       assert(false);  
   }  
   catch (EsysException& e) {  
       assert(true);  
   }  
   try {  
       emptyData.setRefValue(ref,num_array);  
       assert(false);  
   }  
   catch (EsysException& e) {  
       assert(true);  
   }  
   
   // Check assertions are thrown for RefValue methods on DataConstant  
   try {  
       constantData.getRefValue(ref,num_array);  
       assert(false);  
   }  
   catch (EsysException& e) {  
       assert(true);  
   }  
   try {  
       constantData.setRefValue(ref,num_array);  
       assert(false);  
   }  
   catch (EsysException& e) {  
       assert(true);  
   }  
   
   // Check calls to RefValue methods on DataExpanded  
   expandedData.getRefValue(ref,num_array);  
   expandedData.setRefValue(ref,num_array);  
   
 }  
1159    
1160  void DataTestCase::testMemAlloc() {  void DataTestCase::testMemAlloc() {
1161    
# Line 609  void DataTestCase::testMemAlloc() { Line 1166  void DataTestCase::testMemAlloc() {
1166    
1167    Data *testData;    Data *testData;
1168    for (int i=0; i<1000; i++) {    for (int i=0; i<1000; i++) {
1169      testData = new Data(0.0, DataArrayView::ShapeType(), FunctionSpace(), true);      testData = new Data(0.0, DataTypes::ShapeType(), FunctionSpace(), true);
1170      delete testData;      delete testData;
1171    }    }
1172    
1173    DataArrayView::ShapeType viewShape;    DataTypes::ShapeType viewShape;
1174    viewShape.push_back(10);    viewShape.push_back(10);
1175    viewShape.push_back(10);    viewShape.push_back(10);
1176    viewShape.push_back(10);    viewShape.push_back(10);
# Line 633  TestSuite* DataTestCase::suite () Line 1190  TestSuite* DataTestCase::suite ()
1190    //    //
1191    // create the suite of tests to perform.    // create the suite of tests to perform.
1192    TestSuite *testSuite = new TestSuite ("DataTestCase");    TestSuite *testSuite = new TestSuite ("DataTestCase");
1193      testSuite->addTest (new TestCaller< DataTestCase>("testCopying",&DataTestCase::testCopying));
1194    testSuite->addTest (new TestCaller< DataTestCase>("testAll",&DataTestCase::testAll));    testSuite->addTest (new TestCaller< DataTestCase>("testAll",&DataTestCase::testAll));
1195    testSuite->addTest (new TestCaller< DataTestCase>("testMore",&DataTestCase::testMore));    testSuite->addTest (new TestCaller< DataTestCase>("testMore",&DataTestCase::testMore));
1196    testSuite->addTest (new TestCaller< DataTestCase>("testDataConstant",&DataTestCase::testDataConstant));    testSuite->addTest (new TestCaller< DataTestCase>("testDataConstant",&DataTestCase::testDataConstant));

Legend:
Removed from v.311  
changed lines
  Added in v.1799

  ViewVC Help
Powered by ViewVC 1.1.26