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

Legend:
Removed from v.468  
changed lines
  Added in v.1811

  ViewVC Help
Powered by ViewVC 1.1.26