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

revision 117 by jgs, Fri Apr 1 05:48:57 2005 UTC revision 126 by jgs, Fri Jul 22 03:53:08 2005 UTC
# 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      // copy the data in the correct format
152      m_data.getData()=data;
153      //
154      // create the view of the data
155      DataArrayView tempView(m_data.getData(),shape);
156      setPointDataView(tempView);
157    }
158    
159  DataExpanded::~DataExpanded()  DataExpanded::~DataExpanded()
160  {  {
161  }  }
# Line 160  DataExpanded::reshapeDataPoint(const Dat Line 179  DataExpanded::reshapeDataPoint(const Dat
179    int i,j;    int i,j;
180    int nRows=m_data.getNumRows();    int nRows=m_data.getNumRows();
181    int nCols=m_data.getNumCols();    int nCols=m_data.getNumCols();
182  #pragma omp parallel for private(i,j) schedule(static)    #pragma omp parallel for private(i,j) schedule(static)
183    for (i=0;i<nRows;i++) {    for (i=0;i<nRows;i++) {
184      for (j=0;j<nCols;j++) {      for (j=0;j<nCols;j++) {
185        // 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 228  DataExpanded::setSlice(const DataAbstrac
228    DataArrayView::ValueType::size_type numRows=m_data.getNumRows();    DataArrayView::ValueType::size_type numRows=m_data.getNumRows();
229    DataArrayView::ValueType::size_type numCols=m_data.getNumCols();    DataArrayView::ValueType::size_type numCols=m_data.getNumCols();
230    int i, j;    int i, j;
231  #pragma omp parallel for private(i,j) schedule(static)    #pragma omp parallel for private(i,j) schedule(static)
232    for (i=0;i<numRows;i++) {    for (i=0;i<numRows;i++) {
233      for (j=0;j<numCols;j++) {      for (j=0;j<numCols;j++) {
234        getPointDataView().copySliceFrom(getPointOffset(i,j),tempDataExp->getPointDataView(),tempDataExp->getPointOffset(i,j),region_loop_range);        getPointDataView().copySliceFrom(getPointOffset(i,j),
235                                           tempDataExp->getPointDataView(),
236                                           tempDataExp->getPointOffset(i,j),
237                                           region_loop_range);
238      }      }
239    }    }
240  }  }
# Line 225  DataExpanded::copy(const DataArrayView& Line 247  DataExpanded::copy(const DataArrayView&
247    int nRows=m_data.getNumRows();    int nRows=m_data.getNumRows();
248    int nCols=m_data.getNumCols();    int nCols=m_data.getNumCols();
249    int i,j;    int i,j;
250  #pragma omp parallel for private(i,j) schedule(static)    #pragma omp parallel for private(i,j) schedule(static)
251    for (i=0;i<nRows;i++) {    for (i=0;i<nRows;i++) {
252      for (j=0;j<nCols;j++) {      for (j=0;j<nCols;j++) {
253        // 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 359  DataExpanded::setRefValue(int ref,
359    
360    for (int n=0; n<numDPPSample; n++) {    for (int n=0; n<numDPPSample; n++) {
361      //      //
362      // Get each data-point in the sample in turn.      // Get *each* data-point in the sample in turn.
363      DataArrayView pointView = getDataPoint(sampleNo, n);      DataArrayView pointView = getDataPoint(sampleNo, n);
364      //      //
365      // 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 392  DataExpanded::getRefValue(int ref,
392    }    }
393    
394    //    //
395    // Get the first data-point associated with this sample number.    // Get the *first* data-point associated with this sample number.
396    DataArrayView pointView = getDataPoint(sampleNo, 0);    DataArrayView pointView = getDataPoint(sampleNo, 0);
397    
398    //    //
# Line 378  DataExpanded::getRefValue(int ref, Line 400  DataExpanded::getRefValue(int ref,
400    value.getView().copy(pointView);    value.getView().copy(pointView);
401  }  }
402    
403    int
404    DataExpanded::archiveData(ofstream& archiveFile,
405                              const DataArrayView::ValueType::size_type noValues) const
406    {
407      return(m_data.archiveData(archiveFile, noValues));
408    }
409    
410    int
411    DataExpanded::extractData(ifstream& archiveFile,
412                              const DataArrayView::ValueType::size_type noValues)
413    {
414      return(m_data.extractData(archiveFile, noValues));
415    }
416    
417    void
418    DataExpanded::copyAll(const boost::python::numeric::array& value) {
419      //
420      // Get the number of samples and data-points per sample.
421      int numSamples = getNumSamples();
422      int numDataPointsPerSample = getNumDPPSample();
423      int dataPointRank = getPointDataView().getRank();
424      ShapeType dataPointShape = getPointDataView().getShape();
425      //
426      // check rank:
427      if (value.getrank()!=dataPointRank+1)
428           throw DataException("Rank of numarray does not match Data object rank");
429      if (value.getshape()[0]!=numSamples*numDataPointsPerSample)
430           throw DataException("leading dimension of numarray is too small");
431      //
432      int dataPoint = 0;
433      for (int sampleNo = 0; sampleNo < numSamples; sampleNo++) {
434        for (int dataPointNo = 0; dataPointNo < numDataPointsPerSample; dataPointNo++) {
435          DataArrayView dataPointView = getDataPoint(sampleNo, dataPointNo);
436          if (dataPointRank==0) {
437             dataPointView()=extract<double>(value[dataPoint]);
438          } else if (dataPointRank==1) {
439             for (int i=0; i<dataPointShape[0]; i++) {
440                dataPointView(i)=extract<double>(value[dataPoint][i]);
441             }
442          } else if (dataPointRank==2) {
443             for (int i=0; i<dataPointShape[0]; i++) {
444               for (int j=0; j<dataPointShape[1]; j++) {
445                 dataPointView(i,j)=extract<double>(value[dataPoint][i][j]);
446               }
447             }
448           } else if (dataPointRank==3) {
449             for (int i=0; i<dataPointShape[0]; i++) {
450               for (int j=0; j<dataPointShape[1]; j++) {
451                 for (int k=0; k<dataPointShape[2]; k++) {
452                     dataPointView(i,j,k)=extract<double>(value[dataPoint][i][j][k]);
453                 }
454               }
455             }
456           } else if (dataPointRank==4) {
457             for (int i=0; i<dataPointShape[0]; i++) {
458               for (int j=0; j<dataPointShape[1]; j++) {
459                 for (int k=0; k<dataPointShape[2]; k++) {
460                   for (int l=0; l<dataPointShape[3]; l++) {
461                     dataPointView(i,j,k,l)=extract<double>(value[dataPoint][i][j][k][l]);
462                   }
463                 }
464               }
465             }
466          }
467          dataPoint++;
468        }
469      }
470    }
471  }  // end of namespace  }  // end of namespace

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

  ViewVC Help
Powered by ViewVC 1.1.26