/[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

branches/ROBW_XPLATFORM/escript/test/Data/DataTestCase.cpp revision 622 by robwdcock, Wed Mar 22 14:00:08 2006 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.                                            *  
  *                                                                           *  
  *****************************************************************************  
 */  
1    
2  #include "DataTestCase.h"  /* $Id$ */
   
 #include "FunctionSpace.h"  
 #include "EsysException.h"  
3    
4  #include "Data.h"  /*******************************************************
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 38  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    
192      cout << "\tTest get-slicing DataConstant" << endl;      cout << "\tTest get-slicing DataConstant" << endl;
193    
194      DataArrayView::ShapeType viewShape;      DataTypes::ShapeType viewShape;
195      viewShape.push_back(2);      viewShape.push_back(2);
196      viewShape.push_back(3);      viewShape.push_back(3);
197      Data data(1.3,viewShape,FunctionSpace(),false);      Data data(1.3,viewShape,FunctionSpace(),false);
198    
199      //cout << data.toString() << endl;      //cout << data.toString() << endl;
200    
201      DataArrayView::RegionType region;      DataTypes::RegionType region;
202      region.push_back(DataArrayView::RegionType::value_type(0,0));      region.push_back(DataTypes::RegionType::value_type(0,0));
203      region.push_back(DataArrayView::RegionType::value_type(0,0));      region.push_back(DataTypes::RegionType::value_type(0,0));
204    
205      Data slice1(data.getSlice(region));      Data slice1(data.getSlice(region));
206    
207      //cout << slice1.toString() << endl;      //cout << slice1.toString() << endl;
208    
209      assert(slice1.getDataPointRank()==0);      assert(slice1.getDataPointRank()==0);
210      assert(slice1.getDataPoint(0,0)()==1.3);      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    
216      Data slice2(data.getSlice(region));      Data slice2(data.getSlice(region));
217    
218      //cout << slice2.toString() << endl;      //cout << slice2.toString() << endl;
219    
220      assert(slice2.getDataPointRank()==2);      assert(slice2.getDataPointRank()==2);
221      assert(slice2.getDataPoint(0,0)(0,0)==1.3);      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();      region.clear();
226      region.push_back(DataArrayView::RegionType::value_type(0,1));      region.push_back(DataTypes::RegionType::value_type(0,1));
227      region.push_back(DataArrayView::RegionType::value_type(0,2));      region.push_back(DataTypes::RegionType::value_type(0,2));
228    
229      Data slice3(data.getSlice(region));      Data slice3(data.getSlice(region));
230    
231      //cout << slice3.toString() << endl;      //cout << slice3.toString() << endl;
232    
233      assert(slice3.getDataPointRank()==2);      assert(slice3.getDataPointRank()==2);
234      assert(slice3.getDataPoint(0,0)(0,0)==1.3);      off1=slice3.getDataOffset(0,0);
235      assert(slice3.getDataPoint(0,0)(0,1)==1.3);  //     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    
# Line 93  void DataTestCase::testSlicing() { Line 243  void DataTestCase::testSlicing() {
243    
244      cout << "\tTest set-slicing DataConstant" << endl;      cout << "\tTest set-slicing DataConstant" << endl;
245    
246      DataArrayView::ShapeType viewShape;      DataTypes::ShapeType viewShape;
247      Data source(10.0,viewShape,FunctionSpace(),false);      Data source(10.0,viewShape,FunctionSpace(),false);
248    
249      //cout << source.toString() << endl;      //cout << source.toString() << endl;
# Line 104  void DataTestCase::testSlicing() { Line 254  void DataTestCase::testSlicing() {
254    
255      //cout << target.toString() << endl;      //cout << target.toString() << endl;
256    
257      DataArrayView::RegionType region;      DataTypes::RegionType region;
258      region.push_back(DataArrayView::RegionType::value_type(0,0));      region.push_back(DataTypes::RegionType::value_type(0,0));
259      region.push_back(DataArrayView::RegionType::value_type(0,0));      region.push_back(DataTypes::RegionType::value_type(0,0));
260    
261      target.setSlice(source,region);      target.setSlice(source,region);
262    
263      //cout << target.toString() << endl;      //cout << target.toString() << endl;
264    
265      assert(target.getDataPoint(0,0)(0,0)==source.getDataPoint(0,0)());      int off1=target.getDataOffset(0,0);
266        assert(target.getDataAtOffset(off1+getRelIndex(target.getDataPointShape(),0,0)==source.getDataPoint(0,0)));
267    
268    }    }
269    
270    {    {
271    
272      cout << "\tTest get-slicing DataTagged" << endl;      cout << "\tTest get-slicing DataTagged" << endl;
   
273      //      //
274      // create a DataTagged with a default value only      // create a DataTagged with a default value only
275    
276      DataArrayView::ShapeType viewShape;      DataTypes::ShapeType viewShape;
277      viewShape.push_back(2);      viewShape.push_back(2);
278      viewShape.push_back(3);      viewShape.push_back(3);
279      Data data(1.3,viewShape,FunctionSpace(),false);      Data data(1.3,viewShape,FunctionSpace(),false);
280      data.tag();      data.tag();
281      data.getDataPoint(0,0)(0,0)=1.0;      data.getDataAtOffset(data.getDataOffset(0,0)+getRelIndex(viewShape,0,0))=1.0;
282      data.getDataPoint(0,0)(1,1)=2.0;      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;      //cout << data.toString() << endl;
   
287      //      //
288      // create a scalar slice      // create a scalar slice
289    
290      DataArrayView::RegionType region;      DataTypes::RegionType region;
291      region.push_back(DataArrayView::RegionType::value_type(0,0));      region.push_back(DataTypes::RegionType::value_type(0,0));
292      region.push_back(DataArrayView::RegionType::value_type(0,0));      region.push_back(DataTypes::RegionType::value_type(0,0));
293    
294      Data slice1(data.getSlice(region));      Data slice1(data.getSlice(region));
   
295      //cout << slice1.toString() << endl;      //cout << slice1.toString() << endl;
296    
297      assert(slice1.isTagged());      assert(slice1.isTagged());
298      assert(slice1.getDataPointRank()==0);      assert(slice1.getDataPointRank()==0);
299      assert(slice1.getDataPoint(0,0)()==1.0);      assert(slice1.getDataPoint(0,0)==1.0);
   
300      //      //
301      // create a rank 2 slice with 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    
307      Data slice2(data.getSlice(region));      Data slice2(data.getSlice(region));
308    
# Line 161  void DataTestCase::testSlicing() { Line 310  void DataTestCase::testSlicing() {
310    
311      assert(slice2.isTagged());      assert(slice2.isTagged());
312      assert(slice2.getDataPointRank()==2);      assert(slice2.getDataPointRank()==2);
313      assert(slice2.getDataPoint(0,0)(0,0)==1.0);  
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      // 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    
323      Data slice3(data.getSlice(region));      Data slice3(data.getSlice(region));
324    
# Line 176  void DataTestCase::testSlicing() { Line 326  void DataTestCase::testSlicing() {
326    
327      assert(slice3.isTagged());      assert(slice3.isTagged());
328      assert(slice3.getDataPointRank()==2);      assert(slice3.getDataPointRank()==2);
329      assert(slice3.getDataPoint(0,0)(0,0)==1.0);      assert(getRef(slice3,0,0,0,0)==1.0);
330      assert(slice3.getDataPoint(0,0)(0,1)==1.3);      assert(getRef(slice3,0,0,0,1)==1.3);
331      assert(slice3.getDataPoint(0,0)(1,0)==1.3);      assert(getRef(slice3,0,0,1,0)==1.3);
332      assert(slice3.getDataPoint(0,0)(1,1)==2.0);      assert(getRef(slice3,0,0,1,1)==2.0);
333    
334      //      //
335      // add a value for tag "1"      // add a value for tag "1"
336    
337      DataArrayView::ValueType viewData(6);      DataTypes::ValueType viewData(6);
338      for (int i=0;i<viewData.size();i++) {      for (int i=0;i<viewData.size();i++) {
339        viewData[i]=i;        viewData[i]=i;
340      }      }
341      DataArrayView dataView(viewData,viewShape);  //    DataArrayView dataView(viewData,viewShape);
342    
343    //     data.setTaggedValueFromCPP(1, dataView);
344        data.setTaggedValueFromCPP(1, viewShape, viewData);
345    
     data.setTaggedValueFromCPP(1, dataView);  
346    
347      //      //
348      // create a full slice      // create a full slice
349    
350      region.clear();      region.clear();
351      region.push_back(DataArrayView::RegionType::value_type(0,2));      region.push_back(DataTypes::RegionType::value_type(0,2));
352      region.push_back(DataArrayView::RegionType::value_type(0,3));      region.push_back(DataTypes::RegionType::value_type(0,3));
353    
354      Data slice4(data.getSlice(region));      Data slice4(data.getSlice(region));
355    
# Line 205  void DataTestCase::testSlicing() { Line 357  void DataTestCase::testSlicing() {
357    
358      assert(slice4.isTagged());      assert(slice4.isTagged());
359      assert(slice4.getDataPointRank()==2);      assert(slice4.getDataPointRank()==2);
360      assert(slice4.getDataPoint(0,0)(0,0)==0);      assert(getRef(slice4,0,0,0,0)==0);
361      assert(slice4.getDataPoint(0,0)(0,1)==2);      assert(getRef(slice4,0,0,0,1)==2);
362      assert(slice4.getDataPoint(0,0)(0,2)==4);      assert(getRef(slice4,0,0,0,2)==4);
363      assert(slice4.getDataPoint(0,0)(1,0)==1);      assert(getRef(slice4,0,0,1,0)==1);
364      assert(slice4.getDataPoint(0,0)(1,1)==3);      assert(getRef(slice4,0,0,1,1)==3);
365      assert(slice4.getDataPoint(0,0)(1,2)==5);      assert(getRef(slice4,0,0,1,2)==5);
366    
367    }    }
368    
# Line 221  void DataTestCase::testSlicing() { Line 373  void DataTestCase::testSlicing() {
373      //      //
374      // create a source DataTagged with a scalar default value only      // create a source DataTagged with a scalar default value only
375    
376      DataArrayView::ShapeType viewShape;      DataTypes::ShapeType viewShape;
377      Data source(10.0,viewShape,FunctionSpace(),false);      Data source(10.0,viewShape,FunctionSpace(),false);
378      source.tag();      source.tag();
379    
# Line 240  void DataTestCase::testSlicing() { Line 392  void DataTestCase::testSlicing() {
392      //      //
393      // set a slice in target from source      // set a slice in target from source
394    
395      DataArrayView::RegionType region;      DataTypes::RegionType region;
396      region.push_back(DataArrayView::RegionType::value_type(1,1));      region.push_back(DataTypes::RegionType::value_type(1,1));
397      region.push_back(DataArrayView::RegionType::value_type(1,1));      region.push_back(DataTypes::RegionType::value_type(1,1));
398    
399      target.setSlice(source,region);      target.setSlice(source,region);
400    
# Line 250  void DataTestCase::testSlicing() { Line 402  void DataTestCase::testSlicing() {
402    
403      assert(target.isTagged());      assert(target.isTagged());
404      assert(target.getDataPointRank()==2);      assert(target.getDataPointRank()==2);
405      assert(target.getDataPoint(0,0)(0,0)==1.3);      assert(getRef(target,0,0,0,0)==1.3);
406      assert(target.getDataPoint(0,0)(0,1)==1.3);      assert(getRef(target,0,0,0,1)==1.3);
407      assert(target.getDataPoint(0,0)(0,2)==1.3);      assert(getRef(target,0,0,0,2)==1.3);
408      assert(target.getDataPoint(0,0)(1,0)==1.3);      assert(getRef(target,0,0,1,0)==1.3);
409      assert(target.getDataPoint(0,0)(1,1)==source.getDataPoint(0,0)());      assert(getRef(target,0,0,1,1)==source.getDataPoint(0,0));
410      assert(target.getDataPoint(0,0)(1,2)==1.3);      assert(getRef(target,0,0,1,2)==1.3);
411    
412      //      //
413      // add a value for tag "1" to target      // add a value for tag "1" to target
414    
415      DataArrayView::ValueType viewData(6);      DataTypes::ValueType viewData(6);
416      for (int i=0;i<viewData.size();i++) {      for (int i=0;i<viewData.size();i++) {
417        viewData[i]=i;        viewData[i]=i;
418      }      }
419      DataArrayView dataView(viewData,viewShape);  //     DataArrayView dataView(viewData,viewShape);
420    //
421      target.setTaggedValueFromCPP(1, dataView);  //     target.setTaggedValueFromCPP(1, dataView);
422        target.setTaggedValueFromCPP(1, viewShape, viewData);
423    
424      //cout << "target:\n" << target.toString() << endl;      //cout << "target:\n" << target.toString() << endl;
425    
# Line 274  void DataTestCase::testSlicing() { Line 427  void DataTestCase::testSlicing() {
427      // set a slice in target from source      // set a slice in target from source
428    
429      region.clear();      region.clear();
430      region.push_back(DataArrayView::RegionType::value_type(0,0));      region.push_back(DataTypes::RegionType::value_type(0,0));
431      region.push_back(DataArrayView::RegionType::value_type(1,1));      region.push_back(DataTypes::RegionType::value_type(1,1));
432    
433      target.setSlice(source,region);      target.setSlice(source,region);
434    
# Line 283  void DataTestCase::testSlicing() { Line 436  void DataTestCase::testSlicing() {
436    
437      assert(target.isTagged());      assert(target.isTagged());
438      assert(target.getDataPointRank()==2);      assert(target.getDataPointRank()==2);
439      assert(target.getDataPoint(0,0)(0,0)==0);      assert(getRef(target,0,0,0,0)==0);
440      assert(target.getDataPoint(0,0)(0,1)==source.getDataPoint(0,0)());      assert(getRef(target,0,0,0,1)==source.getDataPoint(0,0));
441      assert(target.getDataPoint(0,0)(0,2)==4);      assert(getRef(target,0,0,0,2)==4);
442      assert(target.getDataPoint(0,0)(1,0)==1);      assert(getRef(target,0,0,1,0)==1);
443      assert(target.getDataPoint(0,0)(1,1)==3);      assert(getRef(target,0,0,1,1)==3);
444      assert(target.getDataPoint(0,0)(1,2)==5);      assert(getRef(target,0,0,1,2)==5);
445    
446      //      //
447      // add a value for tag "2" to source      // add a value for tag "2" to source
448    
449      DataArrayView::ShapeType viewShape2;      DataTypes::ShapeType viewShape2;
450      DataArrayView::ValueType viewData2(1);      DataTypes::ValueType viewData2(1);
451      viewData2[0]=6;      viewData2[0]=6;
452      DataArrayView dataView2(viewData2,viewShape2);  //     DataArrayView dataView2(viewData2,viewShape2);
453    //
454      source.setTaggedValueFromCPP(2, dataView2);  //     source.setTaggedValueFromCPP(2, dataView2);
455        source.setTaggedValueFromCPP(2, viewShape2, viewData2);
456    
457      //cout << "source:\n" << source.toString() << endl;      //cout << "source:\n" << source.toString() << endl;
458    
# Line 306  void DataTestCase::testSlicing() { Line 460  void DataTestCase::testSlicing() {
460      // set a slice in target from source      // set a slice in target from source
461    
462      region.clear();      region.clear();
463      region.push_back(DataArrayView::RegionType::value_type(0,0));      region.push_back(DataTypes::RegionType::value_type(0,0));
464      region.push_back(DataArrayView::RegionType::value_type(1,1));      region.push_back(DataTypes::RegionType::value_type(1,1));
465    
466      target.setSlice(source,region);      target.setSlice(source,region);
467    
# Line 347  void DataTestCase::testSlicing() { Line 501  void DataTestCase::testSlicing() {
501    
502      cout << "\tTest get-slicing DataExpanded" << endl;      cout << "\tTest get-slicing DataExpanded" << endl;
503    
504      DataArrayView::ShapeType viewShape;      DataTypes::ShapeType viewShape;
505      viewShape.push_back(2);      viewShape.push_back(2);
506      viewShape.push_back(3);      viewShape.push_back(3);
507      Data temp(1.3,viewShape,FunctionSpace(),true);      Data temp(1.3,viewShape,FunctionSpace(),true);
508    
509      temp.getDataPoint(0,0)(0,0)=0.0;      getRef(temp,0,0,0,0)=0.0;
510      temp.getDataPoint(0,0)(1,1)=1.0;      getRef(temp,0,0,1,1)=1.0;
511    
512      DataArrayView::RegionType region;      DataTypes::RegionType region;
513      region.push_back(DataArrayView::RegionType::value_type(0,0));      region.push_back(DataTypes::RegionType::value_type(0,0));
514      region.push_back(DataArrayView::RegionType::value_type(0,0));      region.push_back(DataTypes::RegionType::value_type(0,0));
515    
516      Data slice(temp.getSlice(region));      Data slice(temp.getSlice(region));
517    
518      assert(slice.getDataPointRank()==0);      assert(slice.getDataPointRank()==0);
519      assert(slice.getDataPoint(0,0)()==0.0);      assert(slice.getDataPoint(0,0)==0.0);
520    
521      region.clear();      region.clear();
522      region.push_back(DataArrayView::RegionType::value_type(0,1));      region.push_back(DataTypes::RegionType::value_type(0,1));
523      region.push_back(DataArrayView::RegionType::value_type(0,1));      region.push_back(DataTypes::RegionType::value_type(0,1));
524    
525      slice=temp.getSlice(region);      slice=temp.getSlice(region);
526    
527      assert(slice.getDataPointRank()==2);      assert(slice.getDataPointRank()==2);
528      assert(slice.getDataPoint(0,0)(0,0)==0.0);      assert(getRef(slice,0,0,0,0)==0.0);
529    
530      region.clear();      region.clear();
531      region.push_back(DataArrayView::RegionType::value_type(0,2));      region.push_back(DataTypes::RegionType::value_type(0,2));
532      region.push_back(DataArrayView::RegionType::value_type(0,2));      region.push_back(DataTypes::RegionType::value_type(0,2));
533    
534      slice=temp.getSlice(region);      slice=temp.getSlice(region);
535    
536      assert(slice.getDataPoint(0,0)(0,0)==0.0);      assert(getRef(slice,0,0,0,0)==0.0);
537      assert(slice.getDataPoint(0,0)(1,1)==1.0);      assert(getRef(slice,0,0,1,1)==1.0);
538    
539    }    }
540    
# Line 388  void DataTestCase::testSlicing() { Line 542  void DataTestCase::testSlicing() {
542    
543      cout << "\tTest set-slicing DataExpanded" << endl;      cout << "\tTest set-slicing DataExpanded" << endl;
544    
545      DataArrayView::ShapeType viewShape;      DataTypes::ShapeType viewShape;
546      Data source(10.0,viewShape,FunctionSpace(),true);      Data source(10.0,viewShape,FunctionSpace(),true);
547    
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(),true);      Data target(1.3,viewShape,FunctionSpace(),true);
551    
552      DataArrayView::RegionType region;      DataTypes::RegionType region;
553      region.push_back(DataArrayView::RegionType::value_type(0,0));      region.push_back(DataTypes::RegionType::value_type(0,0));
554      region.push_back(DataArrayView::RegionType::value_type(0,0));      region.push_back(DataTypes::RegionType::value_type(0,0));
555    
556      target.setSlice(source,region);      target.setSlice(source,region);
557    
558      assert(target.getDataPoint(0,0)(0,0)==source.getDataPoint(0,0)());      assert(getRef(target,0,0,0,0)==source.getDataPoint(0,0));
559    
560    }    }
561    
# Line 413  void DataTestCase::testAll() { Line 567  void DataTestCase::testAll() {
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 442  void DataTestCase::testMore() { Line 597  void DataTestCase::testMore() {
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(myView,FunctionSpace(),expanded);    Data exData(viewData,viewShape,FunctionSpace(),expanded);
610    Data cData(myView);    Data cData(viewData,viewShape);
611    Data result;    Data result;
612    
613    assert(exData.isExpanded());    assert(exData.isExpanded());
# Line 486  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 527  void DataTestCase::testDataTagged() { Line 682  void DataTestCase::testDataTagged() {
682    
683      cout << "\tCreate a DataTagged object with a default value only." << endl;      cout << "\tCreate a DataTagged object with a default value only." << endl;
684    
685      DataTagged::TagListType keys;  //    DataTagged::TagListType keys;
686    
687      DataTagged::ValueListType values;  //    DataTagged::ValueListType values;
688    
689      DataArrayView::ShapeType viewShape;      DataTypes::ShapeType viewShape;
690      viewShape.push_back(3);      viewShape.push_back(3);
691    
692      DataArrayView::ValueType viewData(3);      DataTypes::ValueType viewData(3);
693      for (int i=0;i<viewShape[0];i++) {      for (int i=0;i<viewShape[0];i++) {
694        viewData[i]=i;        viewData[i]=i;
695      }      }
696      DataArrayView defaultValue(viewData,viewShape);  /*    DataArrayView defaultValue(viewData,viewShape);
697    
698      bool expanded=false;      bool expanded=false;
699      
700      Data myData(keys,values,defaultValue,FunctionSpace(),expanded);      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;      // cout << myData.toString() << endl;
706    
# Line 551  void DataTestCase::testDataTagged() { Line 709  void DataTestCase::testDataTagged() {
709      assert(myData.getTagNumber(0)==1);      assert(myData.getTagNumber(0)==1);
710      assert(myData.getDataPointRank()==1);      assert(myData.getDataPointRank()==1);
711      assert(myData.getLength()==3);      assert(myData.getLength()==3);
712        
713      DataArrayView myDataView = myData.getPointDataView();      assert(myData.getNoValues()==3);
714      assert(!myDataView.isEmpty());      assert(myData.getDataAtOffset(0)==0.0);
715      assert(myDataView.getOffset()==0);      assert(myData.getDataAtOffset(1)==1.0);
716      assert(myDataView.getRank()==1);      assert(myData.getDataAtOffset(2)==2.0);
717      assert(myDataView.noValues()==3);  
718      assert(myDataView.getShape().size()==1);  //     DataArrayView myDataView = myData.getPointDataView();
719      assert(myDataView(0)==0.0);  //     assert(!myDataView.isEmpty());
720      assert(myDataView(1)==1.0);  //     assert(myDataView.getOffset()==0);
721      assert(myDataView(2)==2.0);  //     assert(myDataView.getRank()==1);
722    //     assert(myDataView.noValues()==3);
723      myDataView = myData.getDataPoint(0,0);  //     assert(myDataView.getShape().size()==1);
724      assert(!myDataView.isEmpty());  //     assert(myDataView(0)==0.0);
725      assert(myDataView.getOffset()==0);  //     assert(myDataView(1)==1.0);
726      assert(myDataView.getRank()==1);  //     assert(myDataView(2)==2.0);
727      assert(myDataView.noValues()==3);  
728      assert(myDataView.getShape().size()==1);  //     myDataView = myData.getDataPoint(0,0);
729      assert(myDataView(0)==0.0);  //     assert(!myDataView.isEmpty());
730      assert(myDataView(1)==1.0);  //     assert(myDataView.getOffset()==0);
731      assert(myDataView(2)==2.0);  //     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);      double* sampleData=myData.getSampleData(0);
739      for (int i=0; i<myDataView.noValues(); i++) {      for (int i=0; i<myData.getNoValues(); i++) {
740        assert(sampleData[i]==i);        assert(sampleData[i]==i);
741      }      }
742      // use a non-existent tag so we get a pointer to      // use a non-existent tag so we get a pointer to
# Line 586  void DataTestCase::testDataTagged() { Line 749  void DataTestCase::testDataTagged() {
749      cout << "\tTest setting of a tag and associated value." << endl;      cout << "\tTest setting of a tag and associated value." << endl;
750    
751      // value for tag "1"      // value for tag "1"
752      DataArray eTwo(defaultValue);      DataTypes::ValueType eTwoData(viewData);
753      for (int i=0;i<eTwo.getView().getShape()[0];i++) {   //   DataArrayView eTwoView(eTwoData, viewShape);
754        eTwo.getView()(i)=i+2.0;      for (int i=0;i<viewShape[0];i++) {
755          eTwoData[i]=i+2.0;
756      }      }
757    
758      myData.setTaggedValueFromCPP(1,eTwo.getView());      myData.setTaggedValueFromCPP(1,viewShape, eTwoData);
759    
760      assert(myData.getLength()==6);      assert(myData.getLength()==6);
761    
762      myDataView = myData.getDataPoint(0,0);      int offset=myData.getDataOffset(0,0);
763      assert(myDataView==eTwo.getView());  //    myDataView = myData.getDataPoint(0,0);
764      assert(!myDataView.isEmpty());  //     assert(myDataView==eTwoView);
765      assert(myDataView.getOffset()==3);  //     assert(!myDataView.isEmpty());
766      assert(myDataView.getRank()==1);      assert(offset==3);
767      assert(myDataView.noValues()==3);      assert(myData.getDataPointRank()==1);
768      assert(myDataView.getShape().size()==1);      assert(myData.getNoValues()==3);
769      assert(myDataView(0)==2);  //    assert(myDataView.getShape().size()==1);
770      assert(myDataView(1)==3);  
771      assert(myDataView(2)==4);      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);      sampleData=myData.getSampleDataByTag(1);
776      for (int i=0; i<myDataView.noValues(); i++) {      for (int i=0; i<myData.getNoValues(); i++) {
777        assert(sampleData[i]==i+2);        assert(sampleData[i]==i+2);
778      }      }
779    
# Line 617  void DataTestCase::testDataTagged() { Line 783  void DataTestCase::testDataTagged() {
783    
784      cout << "\tCreate a DataTagged object via tag() method." << endl;      cout << "\tCreate a DataTagged object via tag() method." << endl;
785    
786      DataArrayView::ShapeType viewShape;      DataTypes::ShapeType viewShape;
787      viewShape.push_back(2);      viewShape.push_back(2);
788      viewShape.push_back(3);      viewShape.push_back(3);
789      Data myData(1.3,viewShape,FunctionSpace(),false);      Data myData(1.3,viewShape,FunctionSpace(),false);
# Line 632  void DataTestCase::testDataTagged() { Line 798  void DataTestCase::testDataTagged() {
798      assert(myData.getLength()==6);      assert(myData.getLength()==6);
799    
800      // check default value      // check default value
801      DataArrayView myDataView = myData.getPointDataView();  //     DataArrayView myDataView = myData.getPointDataView();
802      assert(!myDataView.isEmpty());      assert(!myData.isEmpty());
803      assert(myDataView.getOffset()==0);  //     assert(myDataView.getOffset()==0);
804      assert(myDataView.getRank()==2);      assert(myData.getDataPointRank()==2);
805      assert(myDataView.noValues()==6);      assert(myData.getNoValues()==6);
806      assert(myDataView.getShape().size()==2);      assert(myData.getDataPointShape().size()==2);
807      assert(myDataView(0,0)==1.3);      assert(getRef(myData,0,0)==1.3);
808      assert(myDataView(0,1)==1.3);      assert(getRef(myData,0,1)==1.3);
809      assert(myDataView(0,2)==1.3);      assert(getRef(myData,0,2)==1.3);
810      assert(myDataView(1,0)==1.3);      assert(getRef(myData,1,0)==1.3);
811      assert(myDataView(1,1)==1.3);      assert(getRef(myData,1,1)==1.3);
812      assert(myDataView(1,2)==1.3);      assert(getRef(myData,1,2)==1.3);
813    
814      // check value for data-point (0,0).      // check value for data-point (0,0).
815      myDataView = myData.getDataPoint(0,0);  //     myDataView = myData.getDataPoint(0,0);
816      assert(!myDataView.isEmpty());      assert(!myData.isEmpty());
817      assert(myDataView.getOffset()==0);  //     assert(myDataView.getOffset()==0);
818      assert(myDataView.getRank()==2);      assert(myData.getDataPointRank()==2);
819      assert(myDataView.noValues()==6);      assert(myData.getNoValues()==6);
820      assert(myDataView.getShape().size()==2);      assert(myData.getDataPointShape().size()==2);
821      assert(myDataView(0,0)==1.3);      assert(getRef(myData,0,0)==1.3);
822      assert(myDataView(0,1)==1.3);      assert(getRef(myData,0,1)==1.3);
823      assert(myDataView(0,2)==1.3);      assert(getRef(myData,0,2)==1.3);
824      assert(myDataView(1,0)==1.3);      assert(getRef(myData,1,0)==1.3);
825      assert(myDataView(1,1)==1.3);      assert(getRef(myData,1,1)==1.3);
826      assert(myDataView(1,2)==1.3);      assert(getRef(myData,1,2)==1.3);
827    
828    }    }
829    
# Line 670  void DataTestCase::testDataTaggedExcepti Line 836  void DataTestCase::testDataTaggedExcepti
836    cout << "\tTest DataTagged 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.setTaggedValueFromCPP(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    }    }
# Line 696  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 714  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 baseEx(dataView,FunctionSpace(),true);    Data baseEx(data,shape,FunctionSpace(),true);
900    Data baseCon(dataView,FunctionSpace(),false);    Data baseCon(data,shape,FunctionSpace(),false);
901    Data baseTag(dataView,FunctionSpace(),false);    Data baseTag(data,shape,FunctionSpace(),false);
902    baseTag.tag();    baseTag.tag();
903    
904    assert(baseEx.isExpanded());    assert(baseEx.isExpanded());
# Line 746  void DataTestCase::testOperations() { Line 911  void DataTestCase::testOperations() {
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    resultEx.copy(baseEx.powD(power));    resultEx.copy(baseEx.powD(power));
# Line 753  void DataTestCase::testOperations() { Line 919  void DataTestCase::testOperations() {
919    resultTag.copy(baseTag.powD(power));    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(resultEx.getPointDataView()(i,j) == pow(dataView.index(i,j),3.0));        tmp=pow((double)data[getRelIndex(shape,i,j)],(double)3.0);
923        assert(resultCon.getPointDataView()(i,j) == pow(dataView.index(i,j),3.0));        assert(std::abs(getRef(resultEx,i,j) - tmp) <= REL_TOL*std::abs(tmp));
924        assert(resultTag.getPointDataView()(i,j) == pow(dataView.index(i,j),3.0));        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    
# Line 763  void DataTestCase::testOperations() { Line 930  void DataTestCase::testOperations() {
930    resultEx.copy(baseEx.sin());    resultEx.copy(baseEx.sin());
931    resultCon.copy(baseCon.sin());    resultCon.copy(baseCon.sin());
932    resultTag.copy(baseTag.sin());    resultTag.copy(baseTag.sin());
933    assert(true);    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    resultEx.copy(baseEx.cos());    resultEx.copy(baseEx.cos());
944    resultCon.copy(baseCon.cos());    resultCon.copy(baseCon.cos());
945    resultTag.copy(baseTag.cos());    resultTag.copy(baseTag.cos());
946    assert(true);    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    resultEx.copy(baseEx.tan());    resultEx.copy(baseEx.tan());
957    resultCon.copy(baseCon.tan());    resultCon.copy(baseCon.tan());
958    resultTag.copy(baseTag.tan());    resultTag.copy(baseTag.tan());
959    assert(true);    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    resultEx.copy(baseEx.asin());    resultEx.copy(baseEx.asin());
# Line 793  void DataTestCase::testOperations() { Line 981  void DataTestCase::testOperations() {
981    resultEx.copy(baseEx.atan());    resultEx.copy(baseEx.atan());
982    resultCon.copy(baseCon.atan());    resultCon.copy(baseCon.atan());
983    resultTag.copy(baseTag.atan());    resultTag.copy(baseTag.atan());
984    assert(true);    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    resultEx.copy(baseEx.sinh());    resultEx.copy(baseEx.sinh());
995    resultCon.copy(baseCon.sinh());    resultCon.copy(baseCon.sinh());
996    resultTag.copy(baseTag.sinh());    resultTag.copy(baseTag.sinh());
997    assert(true);    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    resultEx.copy(baseEx.cosh());    resultEx.copy(baseEx.cosh());
1008    resultCon.copy(baseCon.cosh());    resultCon.copy(baseCon.cosh());
1009    resultTag.copy(baseTag.cosh());    resultTag.copy(baseTag.cosh());
1010    assert(true);    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    resultEx.copy(baseEx.tanh());    resultEx.copy(baseEx.tanh());
1021    resultCon.copy(baseCon.tanh());    resultCon.copy(baseCon.tanh());
1022    resultTag.copy(baseTag.tanh());    resultTag.copy(baseTag.tanh());
1023    assert(true);    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    resultEx.copy(baseEx.asinh());    resultEx.copy(baseEx.asinh());
# Line 841  void DataTestCase::testOperations() { Line 1057  void DataTestCase::testOperations() {
1057    resultEx.copy(baseEx.abs());    resultEx.copy(baseEx.abs());
1058    resultCon.copy(baseCon.abs());    resultCon.copy(baseCon.abs());
1059    resultTag.copy(baseTag.abs());    resultTag.copy(baseTag.abs());
1060    assert(true);    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    resultEx.copy(baseEx.sign());    resultEx.copy(baseEx.sign());
# Line 853  void DataTestCase::testOperations() { Line 1076  void DataTestCase::testOperations() {
1076    resultEx.copy(baseEx.exp());    resultEx.copy(baseEx.exp());
1077    resultCon.copy(baseCon.exp());    resultCon.copy(baseCon.exp());
1078    resultTag.copy(baseTag.exp());    resultTag.copy(baseTag.exp());
1079    assert(true);    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    resultEx.copy(baseEx.sqrt());    resultEx.copy(baseEx.sqrt());
1090    resultCon.copy(baseCon.sqrt());    resultCon.copy(baseCon.sqrt());
1091    resultTag.copy(baseTag.sqrt());    resultTag.copy(baseTag.sqrt());
1092    assert(true);    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    resultEx.copy(baseEx.neg());    resultEx.copy(baseEx.neg());
# Line 873  void DataTestCase::testOperations() { Line 1110  void DataTestCase::testOperations() {
1110    resultTag.copy(baseTag.pos());    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(resultEx.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(resultCon.getPointDataView()(i,j) == dataView.index(i,j));        assert(std::abs(getRef(resultCon,i,j) - getRelIndex(shape,i,j)) <= REL_TOL*std::abs(data[getRelIndex(shape,i,j)]));
1115        assert(resultTag.getPointDataView()(i,j) == dataView.index(i,j));        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(baseEx.Lsup() == 5);    assert(std::abs(baseEx.Lsup() - 5) <= REL_TOL*5);
1123    assert(baseCon.Lsup() == 5);    assert(std::abs(baseCon.Lsup() - 5) <= REL_TOL*5);
1124    assert(baseTag.Lsup() == 5);    assert(std::abs(baseTag.Lsup() - 5) <= REL_TOL*5);
1125    
1126    cout << "\tTest Data::sup." << endl;    cout << "\tTest Data::sup." << endl;
1127    assert(baseEx.sup() == 5);    assert(std::abs(baseEx.sup() - 5) <= REL_TOL*5);
1128    assert(baseCon.sup() == 5);    assert(std::abs(baseCon.sup() - 5) <= REL_TOL*5);
1129    assert(baseTag.sup() == 5);    assert(std::abs(baseTag.sup() - 5) <= REL_TOL*5);
1130    
1131    cout << "\tTest Data::inf." << endl;    cout << "\tTest Data::inf." << endl;
1132    assert(baseEx.inf() == 0);    assert(std::abs(baseEx.inf() - 0) <= REL_TOL*0);
1133    assert(baseCon.inf() == 0);    assert(std::abs(baseCon.inf() - 0) <= REL_TOL*0);
1134    assert(baseTag.inf() == 0);    assert(std::abs(baseTag.inf() - 0) <= REL_TOL*0);
1135    
1136    // test data-point reduction operations    // test data-point reduction operations
1137    
# Line 902  void DataTestCase::testOperations() { Line 1139  void DataTestCase::testOperations() {
1139    resultEx.copy(baseEx.minval());    resultEx.copy(baseEx.minval());
1140    resultCon.copy(baseCon.minval());    resultCon.copy(baseCon.minval());
1141    resultTag.copy(baseTag.minval());    resultTag.copy(baseTag.minval());
1142    assert(resultEx.getPointDataView()() == 0);  //   assert(std::abs(resultEx.getPointDataView()() - 0) <= REL_TOL*0);
1143    assert(resultCon.getPointDataView()() == 0);  //   assert(std::abs(resultCon.getPointDataView()() - 0) <= REL_TOL*0);
1144    assert(resultTag.getPointDataView()() == 0);  //   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    resultEx.copy(baseEx.maxval());    resultEx.copy(baseEx.maxval());
1151    resultCon.copy(baseCon.maxval());    resultCon.copy(baseCon.maxval());
1152    resultTag.copy(baseTag.maxval());    resultTag.copy(baseTag.maxval());
1153    assert(resultEx.getPointDataView()() == 5);    assert(std::abs(resultEx.getDataAtOffset(0) - 5) <= REL_TOL*5);
1154    assert(resultCon.getPointDataView()() == 5);    assert(std::abs(resultCon.getDataAtOffset(0) - 5) <= REL_TOL*5);
1155    assert(resultTag.getPointDataView()() == 5);    assert(std::abs(resultTag.getDataAtOffset(0) - 5) <= REL_TOL*5);
   
   cout << "\tTest Data::trace." << endl;  
   resultEx.copy(baseEx.trace());  
   resultCon.copy(baseCon.trace());  
   resultTag.copy(baseTag.trace());  
   assert(resultEx.getPointDataView()() == 15);  
   assert(resultCon.getPointDataView()() == 15);  
   assert(resultTag.getPointDataView()() == 15);  
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 1005  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 1029  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.622  
changed lines
  Added in v.1799

  ViewVC Help
Powered by ViewVC 1.1.26