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

Legend:
Removed from v.151  
changed lines
  Added in v.1796

  ViewVC Help
Powered by ViewVC 1.1.26