/[escript]/branches/escript3047_with_pastix2995/escript/test/DataAlgorithmAdapterTestCase.cpp
ViewVC logotype

Diff of /branches/escript3047_with_pastix2995/escript/test/DataAlgorithmAdapterTestCase.cpp

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

revision 1388 by trankine, Fri Jan 11 07:45:58 2008 UTC revision 2005 by jfenwick, Mon Nov 10 01:21:39 2008 UTC
# Line 1  Line 1 
1    
 /* $Id$ */  
   
2  /*******************************************************  /*******************************************************
3   *  *
4   *           Copyright 2003-2007 by ACceSS MNRF  * Copyright (c) 2003-2008 by University of Queensland
5   *       Copyright 2007 by University of Queensland  * Earth Systems Science Computational Center (ESSCC)
6   *  * http://www.uq.edu.au/esscc
7   *                http://esscc.uq.edu.au  *
8   *        Primary Business: Queensland, Australia  * Primary Business: Queensland, Australia
9   *  Licensed under the Open Software License version 3.0  * Licensed under the Open Software License version 3.0
10   *     http://www.opensource.org/licenses/osl-3.0.php  * http://www.opensource.org/licenses/osl-3.0.php
11   *  *
12   *******************************************************/  *******************************************************/
13    
14    
15  #if (defined _WIN32) && (defined __INTEL_COMPILER)  #if (defined _WIN32) && (defined __INTEL_COMPILER)
16  #include <mathimf.h>  #include <mathimf.h>
# Line 20  Line 19 
19  #endif  #endif
20    
21  #include "escript/DataExpanded.h"  #include "escript/DataExpanded.h"
22  #include "escript/DataArrayView.h"  // #include "escript/DataArrayView.h"
23  #include "escript/DataAlgorithm.h"  #include "escript/DataAlgorithm.h"
24  #include "DataAlgorithmAdapterTestCase.h"  #include "DataAlgorithmAdapterTestCase.h"
25    #include "escript/DataTypes.h"
26    
27  #include <iostream>  #include <iostream>
28  #include <algorithm>  #include <algorithm>
# Line 31  Line 31 
31  using namespace CppUnitTest;  using namespace CppUnitTest;
32  using namespace std;  using namespace std;
33  using namespace escript;  using namespace escript;
34    using namespace escript::DataTypes;
35    
36  void DataAlgorithmAdapterTestCase::setUp() {  void DataAlgorithmAdapterTestCase::setUp() {
37    //    //
# Line 44  void DataAlgorithmAdapterTestCase::tearD Line 45  void DataAlgorithmAdapterTestCase::tearD
45    
46  }  }
47    
48    
49    namespace
50    {
51    
52    ValueType::reference
53    getSRef(DataReady& data,int sample, int point)
54    {
55       return data.getVector()[data.getPointOffset(sample,point)];
56    }
57    
58    
59    }
60    
61  void DataAlgorithmAdapterTestCase::testAll() {  void DataAlgorithmAdapterTestCase::testAll() {
62    
63    cout << endl;    cout << endl;
# Line 153  void DataAlgorithmAdapterTestCase::testA Line 167  void DataAlgorithmAdapterTestCase::testA
167      cout << "\tTest algorithm on Data objects with a single rank 2 data-point." << endl;      cout << "\tTest algorithm on Data objects with a single rank 2 data-point." << endl;
168    
169      // define the shape for the DataArrayView      // define the shape for the DataArrayView
170      DataArrayView::ShapeType shape;      DataTypes::ShapeType shape;
171      shape.push_back(2);      shape.push_back(2);
172      shape.push_back(3);      shape.push_back(3);
173    
174      // allocate the data for the DataArrayView      // allocate the data for the DataArrayView
175      DataArrayView::ValueType dataArray(DataArrayView::noValues(shape),0);      DataTypes::ValueType dataArray(DataTypes::noValues(shape),0);
176    
177      // construct DataArrayView      // construct DataArrayView
178      DataArrayView dataView(dataArray,shape);  //     DataArrayView dataView(dataArray,shape);
179    
180      // assign values to the data point      // assign values to the data point
181      for (int i=0;i<shape[0];i++) {      for (int i=0;i<shape[0];i++) {
182        for (int j=0;j<shape[1];j++) {        for (int j=0;j<shape[1];j++) {
183          dataView(i,j)=dataView.index(i,j);          dataArray[getRelIndex(shape,i,j)]=getRelIndex(shape,i,j);
184        }        }
185      }      }
186    
187      // create a few Data objects from the created DataArrayView      // create a few Data objects from the created DataArrayView
188      DataExpanded dataExp(dataView,FunctionSpace());      DataExpanded dataExp(FunctionSpace(),shape,dataArray);
189      DataConstant dataCon(dataView,FunctionSpace());      DataConstant dataCon(FunctionSpace(),shape,dataArray);
190      DataTagged   dataTag(dataCon);      DataTagged   dataTag(dataCon);
191    
192      // test algorithm on DataExpanded      // test algorithm on DataExpanded
# Line 202  void DataAlgorithmAdapterTestCase::testD Line 216  void DataAlgorithmAdapterTestCase::testD
216      cout << "\tTest dp_algorithm on Data objects with a single rank 2 data-point." << endl;      cout << "\tTest dp_algorithm on Data objects with a single rank 2 data-point." << endl;
217    
218      // define the shapes for the DataArrayViews      // define the shapes for the DataArrayViews
219      DataArrayView::ShapeType shape;      DataTypes::ShapeType shape;
220      shape.push_back(2);      shape.push_back(2);
221      shape.push_back(3);      shape.push_back(3);
222      DataArrayView::ShapeType shape2;      DataTypes::ShapeType shape2;
223    
224      // allocate the data for the DataArrayViews      // allocate the data for the DataArrayViews
225      DataArrayView::ValueType dataArray(DataArrayView::noValues(shape),0);      DataTypes::ValueType dataArray(DataTypes::noValues(shape),0);
226      DataArrayView::ValueType dataArray2(DataArrayView::noValues(shape2),0);      DataTypes::ValueType dataArray2(DataTypes::noValues(shape2),0);
227    
228      // construct DataArrayViews      // construct DataArrayViews
229      DataArrayView dataView(dataArray,shape);  //     DataArrayView dataView(dataArray,shape);
230      DataArrayView dataView2(dataArray2,shape2);  //     DataArrayView dataView2(dataArray2,shape2);
231    
232      // assign values to the data point      // assign values to the data point
233      for (int i=0;i<shape[0];i++) {      for (int i=0;i<shape[0];i++) {
234        for (int j=0;j<shape[1];j++) {        for (int j=0;j<shape[1];j++) {
235          dataView(i,j)=dataView.index(i,j);          dataArray[getRelIndex(shape,i,j)]=getRelIndex(shape,i,j);
236        }        }
237      }      }
238    
239      // create a few Data objects from the created DataArrayViews      // create a few Data objects from the created DataArrayViews
240      DataExpanded dataExp(dataView,FunctionSpace());      DataExpanded dataExp(FunctionSpace(),shape,dataArray);
241      DataConstant dataCon(dataView,FunctionSpace());      DataConstant dataCon(FunctionSpace(),shape,dataArray);
242      DataTagged   dataTag(dataCon);      DataTagged   dataTag(dataCon);
243    
244      // and create Data objects to receive the results of the dp_algorithm calls      // and create Data objects to receive the results of the dp_algorithm calls
245      DataExpanded dataExp2(dataView2,FunctionSpace());      DataExpanded dataExp2(FunctionSpace(),shape2,dataArray2);
246      DataConstant dataCon2(dataView2,FunctionSpace());      DataConstant dataCon2(FunctionSpace(),shape2,dataArray2);
247      DataTagged   dataTag2(dataCon2);      DataTagged   dataTag2(dataCon2);
248    
249      // test dp_algorithm on DataExpanded      // test dp_algorithm on DataExpanded
250      FMin fmin_func;      FMin fmin_func;
251      escript::dp_algorithm(dataExp,dataExp2,fmin_func,numeric_limits<double>::max());      escript::dp_algorithm(dataExp,dataExp2,fmin_func,numeric_limits<double>::max());
252      assert(std::abs(dataExp2.getDataPoint(0,0)()-0)<=REL_TOL*0);      assert(std::abs(getSRef(dataExp2,0,0)-0)<=REL_TOL*0);
253      FMax fmax_func;      FMax fmax_func;
254      escript::dp_algorithm(dataExp,dataExp2,fmax_func,numeric_limits<double>::max()*-1);      escript::dp_algorithm(dataExp,dataExp2,fmax_func,numeric_limits<double>::max()*-1);
255      assert(std::abs(dataExp2.getDataPoint(0,0)()-5)<=REL_TOL*5);      assert(std::abs(getSRef(dataExp2,0,0)-5)<=REL_TOL*5);
256    
257      // test dp_algorithm on DataTagged      // test dp_algorithm on DataTagged
258      escript::dp_algorithm(dataTag,dataTag2,fmin_func,numeric_limits<double>::max());      escript::dp_algorithm(dataTag,dataTag2,fmin_func,numeric_limits<double>::max());
259      assert(std::abs(dataTag2.getDataPoint(0,0)()-0)<=REL_TOL*0);      assert(std::abs(getSRef(dataTag2,0,0)-0)<=REL_TOL*0);
260      escript::dp_algorithm(dataTag,dataTag2,fmax_func,numeric_limits<double>::max()*-1);      escript::dp_algorithm(dataTag,dataTag2,fmax_func,numeric_limits<double>::max()*-1);
261      assert(std::abs(dataTag2.getDataPoint(0,0)()-5)<=REL_TOL*5);      assert(std::abs(getSRef(dataTag2,0,0)-5)<=REL_TOL*5);
262    
263      // test dp_algorithm on DataConstant      // test dp_algorithm on DataConstant
264      escript::dp_algorithm(dataCon,dataCon2,fmin_func,numeric_limits<double>::max());      escript::dp_algorithm(dataCon,dataCon2,fmin_func,numeric_limits<double>::max());
265      assert(std::abs(dataCon2.getDataPoint(0,0)()-0)<=REL_TOL*0);      assert(std::abs(getSRef(dataCon2,0,0)-0)<=REL_TOL*0);
266      escript::dp_algorithm(dataCon,dataCon2,fmax_func,numeric_limits<double>::max()*-1);      escript::dp_algorithm(dataCon,dataCon2,fmax_func,numeric_limits<double>::max()*-1);
267      assert(std::abs(dataCon2.getDataPoint(0,0)()-5)<=REL_TOL*5);      assert(std::abs(getSRef(dataCon2,0,0)-5)<=REL_TOL*5);
268    
269    }    }
270    

Legend:
Removed from v.1388  
changed lines
  Added in v.2005

  ViewVC Help
Powered by ViewVC 1.1.26