/[escript]/trunk/escript/src/DataExpanded.cpp
ViewVC logotype

Diff of /trunk/escript/src/DataExpanded.cpp

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

trunk/esys2/escript/src/Data/DataExpanded.cpp revision 117 by jgs, Fri Apr 1 05:48:57 2005 UTC trunk/escript/src/DataExpanded.cpp revision 474 by jgs, Mon Jan 30 04:23:44 2006 UTC
# Line 13  Line 13 
13   ******************************************************************************   ******************************************************************************
14  */  */
15    
16  #include "escript/Data/DataException.h"  #include "DataException.h"
17  #include "escript/Data/DataExpanded.h"  #include "DataExpanded.h"
18  #include "escript/Data/DataConstant.h"  #include "DataConstant.h"
19  #include "escript/Data/DataTagged.h"  #include "DataTagged.h"
20  #include "escript/Data/DataArrayView.h"  #include "DataArrayView.h"
21    
22  #include <boost/python/extract.hpp>  #include <boost/python/extract.hpp>
23    
# Line 72  DataExpanded::DataExpanded(const DataTag Line 72  DataExpanded::DataExpanded(const DataTag
72    : DataAbstract(other.getFunctionSpace())    : DataAbstract(other.getFunctionSpace())
73  {  {
74    //    //
75    // initialise the data for this object    // initialise the data array for this object
76    initialise(other.getPointDataView().getShape(),other.getNumSamples(),other.getNumDPPSample());    initialise(other.getPointDataView().getShape(),other.getNumSamples(),other.getNumDPPSample());
77    //    //
78    // for each data point in this object, extract and copy the corresponding data    // for each data point in this object, extract and copy the corresponding data
# Line 80  DataExpanded::DataExpanded(const DataTag Line 80  DataExpanded::DataExpanded(const DataTag
80    int i,j;    int i,j;
81    DataArrayView::ValueType::size_type numRows=m_data.getNumRows();    DataArrayView::ValueType::size_type numRows=m_data.getNumRows();
82    DataArrayView::ValueType::size_type numCols=m_data.getNumCols();    DataArrayView::ValueType::size_type numCols=m_data.getNumCols();
83  #pragma omp parallel for private(i,j) schedule(static)    #pragma omp parallel for private(i,j) schedule(static)
84    for (i=0;i<numRows;i++) {    for (i=0;i<numRows;i++) {
85      for (j=0;j<numCols;j++) {      for (j=0;j<numCols;j++) {
86        try {        try {
87          getPointDataView().copy(getPointOffset(i,j),other.getPointDataView(),other.getPointOffset(i,j));          getPointDataView().copy(getPointOffset(i,j),
88                                    other.getPointDataView(),
89                                    other.getPointOffset(i,j));
90        }        }
91        catch (std::exception& e) {        catch (std::exception& e) {
92          cout << e.what() << endl;          cout << e.what() << endl;
# Line 109  DataExpanded::DataExpanded(const DataExp Line 111  DataExpanded::DataExpanded(const DataExp
111    DataArrayView::ValueType::size_type numRows=m_data.getNumRows();    DataArrayView::ValueType::size_type numRows=m_data.getNumRows();
112    DataArrayView::ValueType::size_type numCols=m_data.getNumCols();    DataArrayView::ValueType::size_type numCols=m_data.getNumCols();
113    int i,j;    int i,j;
114  #pragma omp parallel for private(i,j) schedule(static)    #pragma omp parallel for private(i,j) schedule(static)
115    for (i=0;i<numRows;i++) {    for (i=0;i<numRows;i++) {
116      for (j=0;j<numCols;j++) {      for (j=0;j<numCols;j++) {
117        try {        try {
118          getPointDataView().copySlice(getPointOffset(i,j),other.getPointDataView(),other.getPointOffset(i,j),region_loop_range);          getPointDataView().copySlice(getPointOffset(i,j),
119                                         other.getPointDataView(),
120                                         other.getPointOffset(i,j),
121                                         region_loop_range);
122        }        }
123        catch (std::exception& e) {        catch (std::exception& e) {
124          cout << e.what() << endl;          cout << e.what() << endl;
# Line 137  DataExpanded::DataExpanded(const DataArr Line 142  DataExpanded::DataExpanded(const DataArr
142    copy(value);    copy(value);
143  }  }
144    
145    DataExpanded::DataExpanded(const FunctionSpace& what,
146                               const DataArrayView::ShapeType &shape,
147                               const DataArrayView::ValueType &data)
148      : DataAbstract(what)
149    {
150      //
151      // create the view of the data
152      initialise(shape,what.getNumSamples(),what.getNumDPPSample());
153      //
154      // copy the data in the correct format
155      m_data.getData()=data;
156    }
157    
158  DataExpanded::~DataExpanded()  DataExpanded::~DataExpanded()
159  {  {
160  }  }
# Line 160  DataExpanded::reshapeDataPoint(const Dat Line 178  DataExpanded::reshapeDataPoint(const Dat
178    int i,j;    int i,j;
179    int nRows=m_data.getNumRows();    int nRows=m_data.getNumRows();
180    int nCols=m_data.getNumCols();    int nCols=m_data.getNumCols();
181  #pragma omp parallel for private(i,j) schedule(static)    #pragma omp parallel for private(i,j) schedule(static)
182    for (i=0;i<nRows;i++) {    for (i=0;i<nRows;i++) {
183      for (j=0;j<nCols;j++) {      for (j=0;j<nCols;j++) {
184        // NOTE: An exception may be thown from this call if        // NOTE: An exception may be thown from this call if
# Line 209  DataExpanded::setSlice(const DataAbstrac Line 227  DataExpanded::setSlice(const DataAbstrac
227    DataArrayView::ValueType::size_type numRows=m_data.getNumRows();    DataArrayView::ValueType::size_type numRows=m_data.getNumRows();
228    DataArrayView::ValueType::size_type numCols=m_data.getNumCols();    DataArrayView::ValueType::size_type numCols=m_data.getNumCols();
229    int i, j;    int i, j;
230  #pragma omp parallel for private(i,j) schedule(static)    #pragma omp parallel for private(i,j) schedule(static)
231    for (i=0;i<numRows;i++) {    for (i=0;i<numRows;i++) {
232      for (j=0;j<numCols;j++) {      for (j=0;j<numCols;j++) {
233        getPointDataView().copySliceFrom(getPointOffset(i,j),tempDataExp->getPointDataView(),tempDataExp->getPointOffset(i,j),region_loop_range);        getPointDataView().copySliceFrom(getPointOffset(i,j),
234                                           tempDataExp->getPointDataView(),
235                                           tempDataExp->getPointOffset(i,j),
236                                           region_loop_range);
237      }      }
238    }    }
239  }  }
# Line 225  DataExpanded::copy(const DataArrayView& Line 246  DataExpanded::copy(const DataArrayView&
246    int nRows=m_data.getNumRows();    int nRows=m_data.getNumRows();
247    int nCols=m_data.getNumCols();    int nCols=m_data.getNumCols();
248    int i,j;    int i,j;
249  #pragma omp parallel for private(i,j) schedule(static)    #pragma omp parallel for private(i,j) schedule(static)
250    for (i=0;i<nRows;i++) {    for (i=0;i<nRows;i++) {
251      for (j=0;j<nCols;j++) {      for (j=0;j<nCols;j++) {
252        // NOTE: An exception may be thown from this call if        // NOTE: An exception may be thown from this call if
# Line 337  DataExpanded::setRefValue(int ref, Line 358  DataExpanded::setRefValue(int ref,
358    
359    for (int n=0; n<numDPPSample; n++) {    for (int n=0; n<numDPPSample; n++) {
360      //      //
361      // Get each data-point in the sample in turn.      // Get *each* data-point in the sample in turn.
362      DataArrayView pointView = getDataPoint(sampleNo, n);      DataArrayView pointView = getDataPoint(sampleNo, n);
363      //      //
364      // Assign the values in the DataArray to this data-point.      // Assign the values in the DataArray to this data-point.
# Line 370  DataExpanded::getRefValue(int ref, Line 391  DataExpanded::getRefValue(int ref,
391    }    }
392    
393    //    //
394    // Get the first data-point associated with this sample number.    // Get the *first* data-point associated with this sample number.
395    DataArrayView pointView = getDataPoint(sampleNo, 0);    DataArrayView pointView = getDataPoint(sampleNo, 0);
396    
397    //    //
# Line 378  DataExpanded::getRefValue(int ref, Line 399  DataExpanded::getRefValue(int ref,
399    value.getView().copy(pointView);    value.getView().copy(pointView);
400  }  }
401    
402    int
403    DataExpanded::archiveData(ofstream& archiveFile,
404                              const DataArrayView::ValueType::size_type noValues) const
405    {
406      return(m_data.archiveData(archiveFile, noValues));
407    }
408    
409    int
410    DataExpanded::extractData(ifstream& archiveFile,
411                              const DataArrayView::ValueType::size_type noValues)
412    {
413      return(m_data.extractData(archiveFile, noValues));
414    }
415    
416    void
417    DataExpanded::copyAll(const boost::python::numeric::array& value) {
418      //
419      // Get the number of samples and data-points per sample.
420      int numSamples = getNumSamples();
421      int numDataPointsPerSample = getNumDPPSample();
422      int dataPointRank = getPointDataView().getRank();
423      ShapeType dataPointShape = getPointDataView().getShape();
424      //
425      // check rank:
426      if (value.getrank()!=dataPointRank+1)
427           throw DataException("Rank of numarray does not match Data object rank");
428      if (value.getshape()[0]!=numSamples*numDataPointsPerSample)
429           throw DataException("leading dimension of numarray is too small");
430      //
431      int dataPoint = 0;
432      for (int sampleNo = 0; sampleNo < numSamples; sampleNo++) {
433        for (int dataPointNo = 0; dataPointNo < numDataPointsPerSample; dataPointNo++) {
434          DataArrayView dataPointView = getDataPoint(sampleNo, dataPointNo);
435          if (dataPointRank==0) {
436             dataPointView()=extract<double>(value[dataPoint]);
437          } else if (dataPointRank==1) {
438             for (int i=0; i<dataPointShape[0]; i++) {
439                dataPointView(i)=extract<double>(value[dataPoint][i]);
440             }
441          } else if (dataPointRank==2) {
442             for (int i=0; i<dataPointShape[0]; i++) {
443               for (int j=0; j<dataPointShape[1]; j++) {
444                 dataPointView(i,j)=extract<double>(value[dataPoint][i][j]);
445               }
446             }
447           } else if (dataPointRank==3) {
448             for (int i=0; i<dataPointShape[0]; i++) {
449               for (int j=0; j<dataPointShape[1]; j++) {
450                 for (int k=0; k<dataPointShape[2]; k++) {
451                     dataPointView(i,j,k)=extract<double>(value[dataPoint][i][j][k]);
452                 }
453               }
454             }
455           } else if (dataPointRank==4) {
456             for (int i=0; i<dataPointShape[0]; i++) {
457               for (int j=0; j<dataPointShape[1]; j++) {
458                 for (int k=0; k<dataPointShape[2]; k++) {
459                   for (int l=0; l<dataPointShape[3]; l++) {
460                     dataPointView(i,j,k,l)=extract<double>(value[dataPoint][i][j][k][l]);
461                   }
462                 }
463               }
464             }
465          }
466          dataPoint++;
467        }
468      }
469    }
470  }  // end of namespace  }  // end of namespace

Legend:
Removed from v.117  
changed lines
  Added in v.474

  ViewVC Help
Powered by ViewVC 1.1.26