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

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

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

revision 1795 by trankine, Fri Jan 11 07:45:58 2008 UTC revision 1796 by jfenwick, Wed Sep 17 01:45:46 2008 UTC
# Line 24  using namespace CppUnitTest; Line 24  using namespace CppUnitTest;
24  using namespace escript;  using namespace escript;
25  using namespace std;  using namespace std;
26  using namespace esysUtils;  using namespace esysUtils;
27    using namespace escript::DataTypes;
28    
29  void DataExpandedTestCase::setUp() {  void DataExpandedTestCase::setUp() {
30    //    //
# Line 37  void DataExpandedTestCase::tearDown() { Line 38  void DataExpandedTestCase::tearDown() {
38    
39  }  }
40    
41    namespace
42    {
43    
44    ValueType::reference
45    getRef(DataAbstract& data,int i, int j)
46    {
47       return data.getVector()[getRelIndex(data.getShape(),i,j)];
48    }
49    
50    ValueType::reference
51    getRef(DataAbstract& data,int i, int j,int k)
52    {
53       return data.getVector()[getRelIndex(data.getShape(),i,j,k)];
54    }
55    
56    ValueType::reference
57    getDRef(ValueType& data,const ShapeType& shape,int i, int j)
58    {
59       return data[getRelIndex(shape,i,j)];
60    }
61    
62    ValueType::reference
63    getDRef(ValueType& data,const ShapeType& shape,int i, int j, int k)
64    {
65       return data[getRelIndex(shape,i,j,k)];
66    }
67    
68    }
69    
70    
71  void DataExpandedTestCase::testAll() {  void DataExpandedTestCase::testAll() {
72    
73    cout << endl;    cout << endl;
74    
75    //    //
76    // Create a rank 1 pointData    // Create a rank 1 pointData
77    DataArrayView::ShapeType shape;    DataTypes::ShapeType shape;
78    shape.push_back(3);    shape.push_back(3);
79    DataArrayView::ValueType data(DataArrayView::noValues(shape),0);    DataTypes::ValueType data(DataTypes::noValues(shape),0);
80    DataArrayView pointData(data,shape);  //  DataArrayView pointData(data,shape);
81    
82    //    //
83    // Assign an arbitrary value    // Assign an arbitrary value
84    pointData(0)=0.0;    data[0]=0.0;
85    pointData(1)=1.0;    data[1]=1.0;
86    pointData(2)=2.0;    data[2]=2.0;
87    
88    //    //
89    // Test constructor    // Test constructor
90    cout << "\tTest DataExpanded constructor." << endl;    cout << "\tTest DataExpanded constructor." << endl;
91    DataExpanded testData(pointData,FunctionSpace());    DataExpanded testData(FunctionSpace(), shape, data);
92    
93    cout << "\tTest getLength." << endl;  //   cout << "\tTest getLength." << endl;
94    assert(testData.getLength()==pointData.noValues());  //   assert(testData.getLength()==pointData.getNoValues());
95    
96    cout << "\tTest getPointDataView." << endl;    cout << "\tTest getDataAtOffset." << endl;
97    for (int i=0;i<testData.getPointDataView().getShape()[0];i++) {    for (int i=0;i<testData.getShape()[0];i++) {
98        assert(testData.getPointDataView()(i)==pointData(i));        assert(testData.getDataAtOffset(i)==data[i]);
99    }    }
100    
101    cout << "\tVerify data point attributes." << endl;    cout << "\tVerify data point attributes." << endl;
102    DataArrayView dataView=testData.getPointDataView();  //  DataArrayView dataView=testData.getPointDataView();
103    assert(dataView.getRank()==shape.size());    assert(testData.getRank()==shape.size());
104    assert(dataView.noValues()==shape[0]*1);    assert(testData.getNoValues()==shape[0]*1);
105    assert(dataView.getShape()[0]==shape[0]);    assert(testData.getShape()[0]==shape[0]);
106    assert(testData.getNumDPPSample()==1);    assert(testData.getNumDPPSample()==1);
107    assert(testData.getNumSamples()==1);    assert(testData.getNumSamples()==1);
108    assert(testData.validSamplePointNo(testData.getNumDPPSample()-1));    assert(testData.validSamplePointNo(testData.getNumDPPSample()-1));
# Line 86  void DataExpandedTestCase::testAll() { Line 117  void DataExpandedTestCase::testAll() {
117    FunctionSpace tmp_fns;    FunctionSpace tmp_fns;
118    DataExpanded testData1(tmp_fns,shape,data);    DataExpanded testData1(tmp_fns,shape,data);
119    
120    cout << "\tTest getLength." << endl;  //   cout << "\tTest getLength." << endl;
121    assert(testData1.getLength()==pointData.noValues());  //   assert(testData1.getLength()==pointData.noValues());
122    
123    cout << "\tTest getPointDataView." << endl;  //   cout << "\tTest getPointDataView." << endl;
124    for (int i=0;i<testData1.getPointDataView().getShape()[0];i++) {  //   for (int i=0;i<testData1.getPointDataView().getShape()[0];i++) {
125        assert(testData1.getPointDataView()(i)==pointData(i));  //       assert(testData1.getPointDataView()(i)==pointData(i));
126    }  //   }
127    
128    cout << "\tVerify data point attributes." << endl;    cout << "\tVerify data point attributes." << endl;
129    dataView=testData1.getPointDataView();  //  dataView=testData1.getPointDataView();
130    assert(dataView.getRank()==shape.size());    assert(testData1.getRank()==shape.size());
131    assert(dataView.noValues()==shape[0]*1);    assert(testData1.getNoValues()==shape[0]*1);
132    assert(dataView.getShape()[0]==shape[0]);    assert(testData1.getShape()[0]==shape[0]);
133    assert(testData.getNumDPPSample()==1);    assert(testData1.getNumDPPSample()==1);
134    assert(testData.getNumSamples()==1);    assert(testData1.getNumSamples()==1);
135    assert(testData.validSamplePointNo(testData.getNumDPPSample()-1));    assert(testData1.validSamplePointNo(testData1.getNumDPPSample()-1));
136    assert(testData.validSampleNo(testData.getNumSamples()-1));    assert(testData1.validSampleNo(testData1.getNumSamples()-1));
137    
138    //    //
139    // Test copy constructor    // Test copy constructor
# Line 110  void DataExpandedTestCase::testAll() { Line 141  void DataExpandedTestCase::testAll() {
141    DataExpanded testData2(testData);    DataExpanded testData2(testData);
142    
143    cout << "\tTest getLength." << endl;    cout << "\tTest getLength." << endl;
144    assert(testData2.getLength()==pointData.noValues());    assert(testData2.getLength()==data.size());
145    
146    cout << "\tTest getPointDataView." << endl;    cout << "\tTest getPointDataView." << endl;
147    for (int i=0;i<testData2.getPointDataView().getShape()[0];i++) {    for (int i=0;i<testData2.getShape()[0];i++) {
148      assert(testData2.getPointDataView()(i)==pointData(i));      assert(testData2.getDataAtOffset(i)==data[i]);
149    }    }
150    
151    cout << "\tVerify data point attributes." << endl;    cout << "\tVerify data point attributes." << endl;
152    dataView=testData2.getPointDataView();  //   dataView=testData2.getPointDataView();
153    assert(dataView.getRank()==shape.size());    assert(testData2.getRank()==shape.size());
154    assert(dataView.noValues()==shape[0]*1);    assert(testData2.getNoValues()==shape[0]*1);
155    assert(dataView.getShape()[0]==shape[0]);    assert(testData2.getShape()[0]==shape[0]);
156    assert(testData2.getNumDPPSample()==1);    assert(testData2.getNumDPPSample()==1);
157    assert(testData2.getNumSamples()==1);    assert(testData2.getNumSamples()==1);
158    assert(testData2.validSamplePointNo(testData2.getNumDPPSample()-1));    assert(testData2.validSamplePointNo(testData2.getNumDPPSample()-1));
# Line 136  void DataExpandedTestCase::testSlicing() Line 167  void DataExpandedTestCase::testSlicing()
167    
168    //    //
169    // Create a rank 1 pointData    // Create a rank 1 pointData
170    DataArrayView::ShapeType shape;    DataTypes::ShapeType shape;
171    shape.push_back(3);    shape.push_back(3);
172    DataArrayView::ValueType data(DataArrayView::noValues(shape),0);    DataTypes::ValueType data(DataTypes::noValues(shape),0);
173    DataArrayView pointData(data,shape);  //   DataArrayView pointData(data,shape);
174    
175    //    //
176    // Assign an arbitrary value    // Assign an arbitrary value
177    pointData(0)=0.0;    data[0]=0.0;
178    pointData(1)=1.0;    data[1]=1.0;
179    pointData(2)=2.0;    data[2]=2.0;
180    
181    //    //
182    // Create object to test    // Create object to test
183    cout << "\tCreate rank 1 DataExpanded object." << endl;    cout << "\tCreate rank 1 DataExpanded object." << endl;
184    DataExpanded testData(pointData,FunctionSpace());    DataExpanded testData(FunctionSpace(),shape,data);
185    
186    cout << "\tTest slicing (whole object)." << endl;    cout << "\tTest slicing (whole object)." << endl;
187    DataArrayView::RegionType region;    DataTypes::RegionType region;
188    region.push_back(DataArrayView::RegionType::value_type(0,shape[0]));    region.push_back(DataTypes::RegionType::value_type(0,shape[0]));
189    
190    DataAbstract* testData2=testData.getSlice(region);    DataAbstract* testData2=testData.getSlice(region);
191    
192    //    //
193    // Verify data values    // Verify data values
194    cout << "\tVerify data point values." << endl;    cout << "\tVerify data point values." << endl;
195    for (int i=0;i<testData2->getPointDataView().getShape()[0];i++) {    for (int i=0;i<testData2->getShape()[0];i++) {
196      assert(testData2->getPointDataView()(i)==pointData(region[0].first+i));      assert(testData2->getDataAtOffset(i)==data[region[0].first+i]);
197    }    }
198    
199    cout << "\tVerify data point attributes." << endl;  //   cout << "\tVerify data point attributes." << endl;
200    DataArrayView dataView=testData2->getPointDataView();  //   DataArrayView dataView=testData2->getPointDataView();
201    assert(dataView.getRank()==shape.size());  //   assert(data.getRank()==shape.size());
202    assert(dataView.noValues()==shape[0]*1);  //   assert(data.getNoValues()==shape[0]*1);
203    assert(dataView.getShape()[0]==shape[0]);  //   assert(data.getShape()[0]==shape[0]);
204    
205    delete testData2;    delete testData2;
206  }  }
# Line 180  void DataExpandedTestCase::testSlicing2( Line 211  void DataExpandedTestCase::testSlicing2(
211    
212    //    //
213    // Create a rank 2 pointData    // Create a rank 2 pointData
214    DataArrayView::ShapeType shape;    DataTypes::ShapeType shape;
215    shape.push_back(3);    shape.push_back(3);
216    shape.push_back(3);    shape.push_back(3);
217    DataArrayView::ValueType data(DataArrayView::noValues(shape),0);    DataTypes::ValueType data(DataTypes::noValues(shape),0);
218    DataArrayView pointData(data,shape);  //  DataArrayView pointData(data,shape);
219    
220    //    //
221    // Assign an arbitrary value    // Assign an arbitrary value
222    pointData(0,0)=0.0;    getDRef(data,shape,0,0)=0.0;
223    pointData(1,0)=1.0;    getDRef(data,shape,1,0)=1.0;
224    pointData(2,0)=2.0;    getDRef(data,shape,2,0)=2.0;
225    pointData(0,1)=3.0;    getDRef(data,shape,0,1)=3.0;
226    pointData(1,1)=4.0;    getDRef(data,shape,1,1)=4.0;
227    pointData(2,1)=5.0;    getDRef(data,shape,2,1)=5.0;
228    pointData(0,2)=6.0;    getDRef(data,shape,0,2)=6.0;
229    pointData(1,2)=7.0;    getDRef(data,shape,1,2)=7.0;
230    pointData(2,2)=8.0;    getDRef(data,shape,2,2)=8.0;
231    
232    //    //
233    // Create object to test    // Create object to test
234    cout << "\tCreate rank 2 DataExpanded object." << endl;    cout << "\tCreate rank 2 DataExpanded object." << endl;
235    DataExpanded testData(pointData,FunctionSpace());    DataExpanded testData(FunctionSpace(),shape,data);
236    
237    cout << "\tTest slicing (part object)." << endl;    cout << "\tTest slicing (part object)." << endl;
238    DataArrayView::RegionType region;    DataTypes::RegionType region;
239    region.push_back(DataArrayView::RegionType::value_type(0,2));    region.push_back(DataTypes::RegionType::value_type(0,2));
240    region.push_back(DataArrayView::RegionType::value_type(0,2));    region.push_back(DataTypes::RegionType::value_type(0,2));
241    DataAbstract* testData2=testData.getSlice(region);    DataAbstract* testData2=testData.getSlice(region);
242    
243    //    //
244    // Verify data values    // Verify data values
245    cout << "\tVerify data point values." << endl;    cout << "\tVerify data point values." << endl;
246    for (int j=0;j<testData2->getPointDataView().getShape()[1];j++) {    for (int j=0;j<testData2->getShape()[1];j++) {
247      for (int i=0;i<testData2->getPointDataView().getShape()[0];i++) {      for (int i=0;i<testData2->getShape()[0];i++) {
248        assert(testData2->getPointDataView()(i,j)==pointData(region[0].first+i,region[1].first+j));        assert(getRef(*testData2,i,j)==data[getRelIndex(shape,region[0].first+i,region[1].first+j)]);
249      }      }
250    }    }
251    
252    cout << "\tVerify data point attributes." << endl;    cout << "\tVerify data point attributes." << endl;
253    DataArrayView dataView=testData2->getPointDataView();  //   DataArrayView dataView=testData2->getPointDataView();
254    assert(dataView.getRank()==region.size());    assert(testData2->getRank()==region.size());
255    assert(dataView.noValues()==(region[0].second-region[0].first)*(region[1].second-region[1].first));    assert(testData2->getNoValues()==(region[0].second-region[0].first)*(region[1].second-region[1].first));
256    assert(dataView.getShape()[0]==(region[0].second-region[0].first));    assert(testData2->getShape()[0]==(region[0].second-region[0].first));
257    assert(dataView.getShape()[1]==(region[1].second-region[1].first));    assert(testData2->getShape()[1]==(region[1].second-region[1].first));
258    
259    cout << "\tTest slicing (part object)." << endl;    cout << "\tTest slicing (part object)." << endl;
260    DataArrayView::RegionType region2;    DataTypes::RegionType region2;
261    region2.push_back(DataArrayView::RegionType::value_type(1,3));    region2.push_back(DataTypes::RegionType::value_type(1,3));
262    region2.push_back(DataArrayView::RegionType::value_type(1,3));    region2.push_back(DataTypes::RegionType::value_type(1,3));
263    DataAbstract* testData3=testData.getSlice(region2);    DataAbstract* testData3=testData.getSlice(region2);
264    
265    //    //
266    // Verify data values    // Verify data values
267    cout << "\tVerify data point values." << endl;    cout << "\tVerify data point values." << endl;
268    for (int j=0;j<testData3->getPointDataView().getShape()[1];j++) {    for (int j=0;j<testData3->getShape()[1];j++) {
269      for (int i=0;i<testData3->getPointDataView().getShape()[0];i++) {      for (int i=0;i<testData3->getShape()[0];i++) {
270        assert(testData3->getPointDataView()(i,j)==pointData(region2[0].first+i,region2[1].first+j));        assert(getRef(*testData3,i,j)==getDRef(data,shape,region2[0].first+i,region2[1].first+j));
271      }      }
272    }    }
273    
274    cout << "\tVerify data point attributes." << endl;    cout << "\tVerify data point attributes." << endl;
275    dataView=testData3->getPointDataView();  //   dataView=testData3->getPointDataView();
276    assert(dataView.getRank()==region2.size());    assert(testData3->getRank()==region2.size());
277    assert(dataView.noValues()==(region2[0].second-region2[0].first)*(region2[1].second-region2[1].first));    assert(testData3->getNoValues()==(region2[0].second-region2[0].first)*(region2[1].second-region2[1].first));
278    assert(dataView.getShape()[0]==(region2[0].second-region2[0].first));    assert(testData3->getShape()[0]==(region2[0].second-region2[0].first));
279    assert(dataView.getShape()[1]==(region2[1].second-region2[1].first));    assert(testData3->getShape()[1]==(region2[1].second-region2[1].first));
280    
281    delete testData2;    delete testData2;
282    delete testData3;    delete testData3;
# Line 258  void DataExpandedTestCase::testSlicing3( Line 289  void DataExpandedTestCase::testSlicing3(
289    
290    //    //
291    // Create a rank 3 pointData    // Create a rank 3 pointData
292    DataArrayView::ShapeType shape;    DataTypes::ShapeType shape;
293    shape.push_back(3);    shape.push_back(3);
294    shape.push_back(3);    shape.push_back(3);
295    shape.push_back(3);    shape.push_back(3);
296    DataArrayView::ValueType data(DataArrayView::noValues(shape),0);    DataTypes::ValueType data(DataTypes::noValues(shape),0);
297    DataArrayView pointData(data,shape);  //   DataArrayView pointData(data,shape);
298    
299    //    //
300    // Assign an arbitrary value    // Assign an arbitrary value
301    pointData(0,0,0)=0.0;    getDRef(data,shape,0,0,0)=0.0;
302    pointData(1,0,0)=1.0;    getDRef(data,shape,1,0,0)=1.0;
303    pointData(2,0,0)=2.0;    getDRef(data,shape,2,0,0)=2.0;
304    pointData(0,1,0)=3.0;    getDRef(data,shape,0,1,0)=3.0;
305    pointData(1,1,0)=4.0;    getDRef(data,shape,1,1,0)=4.0;
306    pointData(2,1,0)=5.0;    getDRef(data,shape,2,1,0)=5.0;
307    pointData(0,2,0)=6.0;    getDRef(data,shape,0,2,0)=6.0;
308    pointData(1,2,0)=7.0;    getDRef(data,shape,1,2,0)=7.0;
309    pointData(2,2,0)=8.0;    getDRef(data,shape,2,2,0)=8.0;
310    
311    pointData(0,0,1)=9.0;    getDRef(data,shape,0,0,1)=9.0;
312    pointData(1,0,1)=10.0;    getDRef(data,shape,1,0,1)=10.0;
313    pointData(2,0,1)=11.0;    getDRef(data,shape,2,0,1)=11.0;
314    pointData(0,1,1)=12.0;    getDRef(data,shape,0,1,1)=12.0;
315    pointData(1,1,1)=13.0;    getDRef(data,shape,1,1,1)=13.0;
316    pointData(2,1,1)=14.0;    getDRef(data,shape,2,1,1)=14.0;
317    pointData(0,2,1)=15.0;    getDRef(data,shape,0,2,1)=15.0;
318    pointData(1,2,1)=16.0;    getDRef(data,shape,1,2,1)=16.0;
319    pointData(2,2,1)=17.0;    getDRef(data,shape,2,2,1)=17.0;
320    
321    pointData(0,0,2)=18.0;    getDRef(data,shape,0,0,2)=18.0;
322    pointData(1,0,2)=19.0;    getDRef(data,shape,1,0,2)=19.0;
323    pointData(2,0,2)=20.0;    getDRef(data,shape,2,0,2)=20.0;
324    pointData(0,1,2)=21.0;    getDRef(data,shape,0,1,2)=21.0;
325    pointData(1,1,2)=22.0;    getDRef(data,shape,1,1,2)=22.0;
326    pointData(2,1,2)=23.0;    getDRef(data,shape,2,1,2)=23.0;
327    pointData(0,2,2)=24.0;    getDRef(data,shape,0,2,2)=24.0;
328    pointData(1,2,2)=25.0;    getDRef(data,shape,1,2,2)=25.0;
329    pointData(2,2,2)=26.0;    getDRef(data,shape,2,2,2)=26.0;
330    
331    //    //
332    // Create object to test    // Create object to test
333    cout << "\tCreate rank 3 DataExpanded object." << endl;    cout << "\tCreate rank 3 DataExpanded object." << endl;
334    DataExpanded testData(pointData,FunctionSpace());    DataExpanded testData(FunctionSpace(),shape,data);
335    
336    cout << "\tTest slicing (part object)." << endl;    cout << "\tTest slicing (part object)." << endl;
337    DataArrayView::RegionType region;    DataTypes::RegionType region;
338    region.push_back(DataArrayView::RegionType::value_type(0,2));    region.push_back(DataTypes::RegionType::value_type(0,2));
339    region.push_back(DataArrayView::RegionType::value_type(0,2));    region.push_back(DataTypes::RegionType::value_type(0,2));
340    region.push_back(DataArrayView::RegionType::value_type(0,2));    region.push_back(DataTypes::RegionType::value_type(0,2));
341    DataAbstract* testData2=testData.getSlice(region);    DataAbstract* testData2=testData.getSlice(region);
342    
343    //    //
344    // Verify data values    // Verify data values
345    cout << "\tVerify data point values." << endl;    cout << "\tVerify data point values." << endl;
346    for (int k=0;k<testData2->getPointDataView().getShape()[2];k++) {    for (int k=0;k<testData2->getShape()[2];k++) {
347      for (int j=0;j<testData2->getPointDataView().getShape()[1];j++) {      for (int j=0;j<testData2->getShape()[1];j++) {
348        for (int i=0;i<testData2->getPointDataView().getShape()[0];i++) {        for (int i=0;i<testData2->getShape()[0];i++) {
349          assert(testData2->getPointDataView()(i,j,k)==pointData(region[0].first+i,          assert(getRef(*testData2,i,j,k)==getDRef(data,shape,region[0].first+i,
350                                                                 region[1].first+j,                                                                 region[1].first+j,
351                                                                 region[2].first+k));                                                                 region[2].first+k));
352        }        }
# Line 323  void DataExpandedTestCase::testSlicing3( Line 354  void DataExpandedTestCase::testSlicing3(
354    }    }
355    
356    cout << "\tVerify data point attributes." << endl;    cout << "\tVerify data point attributes." << endl;
357    DataArrayView dataView=testData2->getPointDataView();  //   DataArrayView dataView=testData2->getPointDataView();
358    assert(dataView.getRank()==region.size());    assert(testData2->getRank()==region.size());
359    assert(dataView.noValues()==(region[0].second-region[0].first)    assert(testData2->getNoValues()==(region[0].second-region[0].first)
360                                 *(region[1].second-region[1].first)                                 *(region[1].second-region[1].first)
361                                 *(region[2].second-region[2].first));                                 *(region[2].second-region[2].first));
362    assert(dataView.getShape()[0]==(region[0].second-region[0].first));    assert(testData2->getShape()[0]==(region[0].second-region[0].first));
363    assert(dataView.getShape()[1]==(region[1].second-region[1].first));    assert(testData2->getShape()[1]==(region[1].second-region[1].first));
364    assert(dataView.getShape()[2]==(region[2].second-region[2].first));    assert(testData2->getShape()[2]==(region[2].second-region[2].first));
365    
366    cout << "\tTest slicing (part object)." << endl;    cout << "\tTest slicing (part object)." << endl;
367    DataArrayView::RegionType region2;    DataTypes::RegionType region2;
368    region2.push_back(DataArrayView::RegionType::value_type(1,3));    region2.push_back(DataTypes::RegionType::value_type(1,3));
369    region2.push_back(DataArrayView::RegionType::value_type(1,3));    region2.push_back(DataTypes::RegionType::value_type(1,3));
370    region2.push_back(DataArrayView::RegionType::value_type(1,3));    region2.push_back(DataTypes::RegionType::value_type(1,3));
371    DataAbstract* testData3=testData.getSlice(region2);    DataAbstract* testData3=testData.getSlice(region2);
372    
373    //    //
374    // Verify data values    // Verify data values
375    cout << "\tVerify data point values." << endl;    cout << "\tVerify data point values." << endl;
376    for (int k=0;k<testData3->getPointDataView().getShape()[2];k++) {    for (int k=0;k<testData3->getShape()[2];k++) {
377      for (int j=0;j<testData3->getPointDataView().getShape()[1];j++) {      for (int j=0;j<testData3->getShape()[1];j++) {
378        for (int i=0;i<testData3->getPointDataView().getShape()[0];i++) {        for (int i=0;i<testData3->getShape()[0];i++) {
379          assert(testData3->getPointDataView()(i,j,k)==pointData(region2[0].first+i,          assert(getRef(*testData3,i,j,k)==getDRef(data,shape,region2[0].first+i,
380                                                                 region2[1].first+j,                                                                 region2[1].first+j,
381                                                                 region2[2].first+k));                                                                 region2[2].first+k));
382        }        }
# Line 353  void DataExpandedTestCase::testSlicing3( Line 384  void DataExpandedTestCase::testSlicing3(
384    }    }
385    
386    cout << "\tVerify data point attributes." << endl;    cout << "\tVerify data point attributes." << endl;
387    dataView=testData2->getPointDataView();  //   dataView=testData2->getPointDataView();
388    assert(dataView.getRank()==region.size());    assert(testData2->getRank()==region.size());
389    assert(dataView.noValues()==(region[0].second-region[0].first)    assert(testData2->getNoValues()==(region[0].second-region[0].first)
390                                 *(region[1].second-region[1].first)                                 *(region[1].second-region[1].first)
391                                 *(region[2].second-region[2].first));                                 *(region[2].second-region[2].first));
392    assert(dataView.getShape()[0]==(region[0].second-region[0].first));    assert(testData2->getShape()[0]==(region[0].second-region[0].first));
393    assert(dataView.getShape()[1]==(region[1].second-region[1].first));    assert(testData2->getShape()[1]==(region[1].second-region[1].first));
394    assert(dataView.getShape()[2]==(region[2].second-region[2].first));    assert(testData2->getShape()[2]==(region[2].second-region[2].first));
395    
396    delete testData2;    delete testData2;
397    delete testData3;    delete testData3;
# Line 374  void DataExpandedTestCase::testSliceSett Line 405  void DataExpandedTestCase::testSliceSett
405    
406    //    //
407    // Create a rank 2 pointData    // Create a rank 2 pointData
408    DataArrayView::ShapeType shape;    DataTypes::ShapeType shape;
409    shape.push_back(2);    shape.push_back(2);
410    shape.push_back(2);    shape.push_back(2);
411    DataArrayView::ValueType data(DataArrayView::noValues(shape),0);    DataTypes::ValueType data(DataTypes::noValues(shape),0);
412    DataArrayView pointData(data,shape);  //   DataArrayView pointData(data,shape);
413    
414    //    //
415    // Assign an arbitrary value    // Assign an arbitrary value
416    pointData(0,0)=0.0;    data[getRelIndex(shape,0,0)]=0.0;
417    pointData(0,1)=1.0;    data[getRelIndex(shape,0,1)]=1.0;
418    pointData(1,0)=2.0;    data[getRelIndex(shape,1,0)]=2.0;
419    pointData(1,1)=3.0;    data[getRelIndex(shape,1,1)]=3.0;
420    
421    //    //
422    // Create object to test    // Create object to test
423    cout << "\tCreate rank 2 DataExpanded object." << endl;    cout << "\tCreate rank 2 DataExpanded object." << endl;
424    DataExpanded testData(pointData,FunctionSpace());    DataExpanded testData(FunctionSpace(),shape,data);
425    
426    //    //
427    // Create another rank 2 pointData    // Create another rank 2 pointData
428    DataArrayView::ShapeType shape2;    DataTypes::ShapeType shape2;
429    shape2.push_back(3);    shape2.push_back(3);
430    shape2.push_back(3);    shape2.push_back(3);
431    DataArrayView::ValueType data2(DataArrayView::noValues(shape2),0);    DataTypes::ValueType data2(DataTypes::noValues(shape2),0);
432    DataArrayView pointData2(data2,shape2);  //   DataArrayView pointData2(data2,shape2);
433    
434    //    //
435    // Assign an arbitrary value    // Assign an arbitrary value
436    pointData2(0,0)=0.1;    data2[getRelIndex(shape2,0,0)]=0.1;
437    pointData2(0,1)=1.1;    data2[getRelIndex(shape2,0,1)]=1.1;
438    pointData2(0,2)=2.1;    data2[getRelIndex(shape2,0,2)]=2.1;
439    pointData2(1,0)=3.1;    data2[getRelIndex(shape2,1,0)]=3.1;
440    pointData2(1,1)=4.1;    data2[getRelIndex(shape2,1,1)]=4.1;
441    pointData2(1,2)=5.1;    data2[getRelIndex(shape2,1,2)]=5.1;
442    pointData2(2,0)=6.1;    data2[getRelIndex(shape2,2,0)]=6.1;
443    pointData2(2,1)=7.1;    data2[getRelIndex(shape2,2,1)]=7.1;
444    pointData2(2,2)=8.1;    data2[getRelIndex(shape2,2,2)]=8.1;
445    
446    //    //
447    // Create object to test    // Create object to test
448    cout << "\tCreate second rank 2 DataExpanded object." << endl;    cout << "\tCreate second rank 2 DataExpanded object." << endl;
449    DataExpanded testData2(pointData2,FunctionSpace());    DataExpanded testData2(FunctionSpace(),shape2,data2);
450    
451    cout << "\tTest slice setting (1)." << endl;    cout << "\tTest slice setting (1)." << endl;
452    
453    DataArrayView::RegionType region;    DataTypes::RegionType region;
454    region.push_back(DataArrayView::RegionType::value_type(0,2));    region.push_back(DataTypes::RegionType::value_type(0,2));
455    region.push_back(DataArrayView::RegionType::value_type(0,2));    region.push_back(DataTypes::RegionType::value_type(0,2));
456    
457    DataArrayView::RegionType region2;    DataTypes::RegionType region2;
458    region2.push_back(DataArrayView::RegionType::value_type(1,3));    region2.push_back(DataTypes::RegionType::value_type(1,3));
459    region2.push_back(DataArrayView::RegionType::value_type(1,3));    region2.push_back(DataTypes::RegionType::value_type(1,3));
460    
461    DataAbstract* testData3=testData.getSlice(region);    DataAbstract* testData3=testData.getSlice(region);
462    
463    testData2.setSlice(testData3,region2);    testData2.setSlice(testData3,region2);
   
464    //    //
465    // Verify data values    // Verify data values
466    cout << "\tVerify data point values." << endl;    cout << "\tVerify data point values." << endl;
467    for (int j=region2[1].first;j<region2[1].second;j++) {    for (int j=region2[1].first;j<region2[1].second;j++) {
468      for (int i=region2[0].first;i<region2[0].second;i++) {      for (int i=region2[0].first;i<region2[0].second;i++) {
469        assert(testData2.getPointDataView()(i,j)==pointData(i-(region[0].second-1),j-(region[1].second-1)));        assert(getRef(testData2,i,j)==data[getRelIndex(shape,i-(region[0].second-1),j-(region[1].second-1))]);
470      }      }
471     }     }
472    
# Line 450  void DataExpandedTestCase::testSliceSett Line 480  void DataExpandedTestCase::testSliceSett
480    
481    //    //
482    // Create a rank 0 pointData    // Create a rank 0 pointData
483    DataArrayView::ShapeType shape;    DataTypes::ShapeType shape;
484    DataArrayView::ValueType data(DataArrayView::noValues(shape),0);    DataTypes::ValueType data(DataTypes::noValues(shape),0);
485    DataArrayView pointData(data,shape);  //   DataArrayView pointData(data,shape);
486    
487    //    //
488    // Assign an arbitrary value    // Assign an arbitrary value
489    pointData()=0.0;    data[0]=0.0;
490    
491    //    //
492    // Create object to test    // Create object to test
493    cout << "\tCreate rank 0 DataExpanded object." << endl;    cout << "\tCreate rank 0 DataExpanded object." << endl;
494    DataExpanded testData(pointData,FunctionSpace());    DataExpanded testData(FunctionSpace(),shape,data);
495    
496    //    //
497    // Create a rank 2 pointData    // Create a rank 2 pointData
498    DataArrayView::ShapeType shape2;    DataTypes::ShapeType shape2;
499    shape2.push_back(3);    shape2.push_back(3);
500    shape2.push_back(3);    shape2.push_back(3);
501    DataArrayView::ValueType data2(DataArrayView::noValues(shape2),0);    DataTypes::ValueType data2(DataTypes::noValues(shape2),0);
502    DataArrayView pointData2(data2,shape2);  //   DataArrayView pointData2(data2,shape2);
503    
504    //    //
505    // Assign an arbitrary value    // Assign an arbitrary value
506    pointData2(0,0)=0.1;    data2[getRelIndex(shape2,0,0)]=0.1;
507    pointData2(0,1)=1.1;    data2[getRelIndex(shape2,0,1)]=1.1;
508    pointData2(0,2)=2.1;    data2[getRelIndex(shape2,0,2)]=2.1;
509    pointData2(1,0)=3.1;    data2[getRelIndex(shape2,1,0)]=3.1;
510    pointData2(1,1)=4.1;    data2[getRelIndex(shape2,1,1)]=4.1;
511    pointData2(1,2)=5.1;    data2[getRelIndex(shape2,1,2)]=5.1;
512    pointData2(2,0)=6.1;    data2[getRelIndex(shape2,2,0)]=6.1;
513    pointData2(2,1)=7.1;    data2[getRelIndex(shape2,2,1)]=7.1;
514    pointData2(2,2)=8.1;    data2[getRelIndex(shape2,2,2)]=8.1;
515    
516    //    //
517    // Create object to test    // Create object to test
518    cout << "\tCreate rank 2 DataExpanded object." << endl;    cout << "\tCreate rank 2 DataExpanded object." << endl;
519    DataExpanded testData2(pointData2,FunctionSpace());    DataExpanded testData2(FunctionSpace(),shape2, data2);
520    
521    cout << "\tTest slice setting (1)." << endl;    cout << "\tTest slice setting (1)." << endl;
522    
523    DataArrayView::RegionType region;    DataTypes::RegionType region;
524    
525    DataArrayView::RegionType region2;    DataTypes::RegionType region2;
526    region2.push_back(DataArrayView::RegionType::value_type(1,1));    region2.push_back(DataTypes::RegionType::value_type(1,1));
527    region2.push_back(DataArrayView::RegionType::value_type(1,1));    region2.push_back(DataTypes::RegionType::value_type(1,1));
528    
529    DataAbstract* testData3=testData.getSlice(region);    DataAbstract* testData3=testData.getSlice(region);
530    
# Line 505  void DataExpandedTestCase::testSliceSett Line 535  void DataExpandedTestCase::testSliceSett
535    cout << "\tVerify data point values." << endl;    cout << "\tVerify data point values." << endl;
536    for (int j=region2[1].first;j<region2[1].second;j++) {    for (int j=region2[1].first;j<region2[1].second;j++) {
537      for (int i=region2[0].first;i<region2[0].second;i++) {      for (int i=region2[0].first;i<region2[0].second;i++) {
538        assert(testData2.getPointDataView()(i,j)==pointData());        assert(getRef(testData2,i,j)==data[0]);
539      }      }
540     }     }
541    
# Line 514  void DataExpandedTestCase::testSliceSett Line 544  void DataExpandedTestCase::testSliceSett
544  }  }
545    
546    
547    
548    
549    
550  TestSuite* DataExpandedTestCase::suite ()  TestSuite* DataExpandedTestCase::suite ()
551  {  {
552    //    //

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

  ViewVC Help
Powered by ViewVC 1.1.26