/[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 97 by jgs, Tue Dec 14 05:39:33 2004 UTC revision 110 by jgs, Mon Feb 14 04:14:42 2005 UTC
# Line 96  DataExpanded::DataExpanded(const DataExp Line 96  DataExpanded::DataExpanded(const DataExp
96    // initialise this Data object to the shape of the slice    // initialise this Data object to the shape of the slice
97    initialise(shape,other.getNumSamples(),other.getNumDPPSample());    initialise(shape,other.getNumSamples(),other.getNumDPPSample());
98    //    //
99      DataArrayView::RegionLoopRangeType region_loop_range=getSliceRegionLoopRange(region);
100      //
101    // copy the data    // copy the data
102    DataArrayView::ValueType::size_type numRows=m_data.getNumRows();    DataArrayView::ValueType::size_type numRows=m_data.getNumRows();
103    DataArrayView::ValueType::size_type numCols=m_data.getNumCols();    DataArrayView::ValueType::size_type numCols=m_data.getNumCols();
# Line 104  DataExpanded::DataExpanded(const DataExp Line 106  DataExpanded::DataExpanded(const DataExp
106    for (i=0;i<numRows;++i) {    for (i=0;i<numRows;++i) {
107      for (j=0;j<numCols;++j) {      for (j=0;j<numCols;++j) {
108        try {        try {
109          getPointDataView().copySlice(getPointOffset(i,j),other.getPointDataView(),other.getPointOffset(i,j),region);          getPointDataView().copySlice(getPointOffset(i,j),other.getPointDataView(),other.getPointOffset(i,j),region_loop_range);
110        }        }
111        catch (std::exception& e) {        catch (std::exception& e) {
112          cout << e.what() << endl;          cout << e.what() << endl;
# Line 176  DataExpanded::setSlice(const DataAbstrac Line 178  DataExpanded::setSlice(const DataAbstrac
178    if (tempDataExp==0) {    if (tempDataExp==0) {
179      throw DataException("Programming error - casting to DataExpanded.");      throw DataException("Programming error - casting to DataExpanded.");
180    }    }
181      //
182      DataArrayView::ShapeType shape(DataArrayView::getResultSliceShape(region));
183      DataArrayView::RegionLoopRangeType region_loop_range=getSliceRegionLoopRange(region);
184      //
185      // check shape:
186    if (getPointDataView().getRank()!=region.size()) {    if (getPointDataView().getRank()!=region.size()) {
187      throw DataException("Error - Invalid slice region.");      throw DataException("Error - Invalid slice region.");
188    }    }
189    if (!value->getPointDataView().checkShape(DataArrayView::getResultSliceShape(region))) {    if (tempDataExp->getPointDataView().getRank()>0 and !value->getPointDataView().checkShape(shape)) {
190      throw DataException (value->getPointDataView().createShapeErrorMessage(      throw DataException (value->getPointDataView().createShapeErrorMessage(
191          "Error - Couldn't copy slice due to shape mismatch.",DataArrayView::getResultSliceShape(region)));          "Error - Couldn't copy slice due to shape mismatch.",shape));
192    }    }
193    //    //
194    // copy the data    // copy the data
# Line 191  DataExpanded::setSlice(const DataAbstrac Line 198  DataExpanded::setSlice(const DataAbstrac
198  #pragma omp parallel for private(i,j) schedule(static)  #pragma omp parallel for private(i,j) schedule(static)
199    for (i=0;i<numRows;i++) {    for (i=0;i<numRows;i++) {
200      for (j=0;j<numCols;j++) {      for (j=0;j<numCols;j++) {
201        getPointDataView().copySliceFrom(getPointOffset(i,j),tempDataExp->getPointDataView(),tempDataExp->getPointOffset(i,j),region);        getPointDataView().copySliceFrom(getPointOffset(i,j),tempDataExp->getPointDataView(),tempDataExp->getPointOffset(i,j),region_loop_range);
202      }      }
203    }    }
204  }  }
# Line 292  DataExpanded::getLength() const Line 299  DataExpanded::getLength() const
299    return m_data.getData().size();    return m_data.getData().size();
300  }  }
301    
302    void
303    DataExpanded::setRefValue(int ref,
304                              const DataArray& value)
305    {
306      //
307      // Check number of samples and data-points per sample.
308      int numSamples = getNumSamples();
309      int numDPPSample = getNumDPPSample();
310      if (numDPPSample > 1) {
311        throw DataException("DataExpanded::setRefValue error: more than one DPPSample in this Data.");
312      }
313    
314      //
315      // Determine the data-point which corresponds to this reference number.
316      int sampleNo = -1;
317      int tempRef = -1;
318      for (int n=0; n<numSamples; n++) {
319        tempRef = getFunctionSpace().getReferenceNoFromSampleNo(n);
320        if (tempRef == ref) {
321          sampleNo = n;
322          break;
323        }
324      }
325      if (sampleNo == -1) {
326        throw DataException("DataExpanded::setRefValue error: invalid ref number supplied.");
327      }
328    
329      DataArrayView pointView = getDataPoint(sampleNo, 0);
330    
331      //
332      // Assign the values in the DataArray to this data-point.
333      pointView.copy(value.getView());
334    }
335    
336    void
337    DataExpanded::getRefValue(int ref,
338                              DataArray& value)
339    {
340      //
341      // Check number of samples and data-points per sample.
342      int numSamples = getNumSamples();
343      int numDPPSample = getNumDPPSample();
344      if (numDPPSample > 1) {
345        throw DataException("DataExpanded::getRefValue error: more than one DPPSample in this Data.");
346      }
347    
348      //
349      // Determine the data-point which corresponds to this reference number
350      int sampleNo = -1;
351      int tempRef = -1;
352      for (int n=0; n<numSamples; n++) {
353        tempRef = getFunctionSpace().getReferenceNoFromSampleNo(n);
354        if (tempRef == ref) {
355          sampleNo = n;
356          break;
357        }
358      }
359      if (sampleNo == -1) {
360        throw DataException("DataExpanded::getRefValue error: invalid ref number supplied.");
361      }
362    
363      DataArrayView pointView = getDataPoint(sampleNo, 0);
364    
365      //
366      // Load the values from this data-point into the DataArray
367      value.getView().copy(pointView);
368    }
369    
370  }  // end of namespace  }  // end of namespace

Legend:
Removed from v.97  
changed lines
  Added in v.110

  ViewVC Help
Powered by ViewVC 1.1.26