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

Diff of /trunk/escript/src/Data/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 113 by jgs, Mon Feb 28 07:06:33 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      // Get the number of samples and data-points per sample.
308      int numSamples = getNumSamples();
309      int numDPPSample = getNumDPPSample();
310    
311      //
312      // Determine the sample number which corresponds to this reference number.
313      int sampleNo = -1;
314      int tempRef = -1;
315      for (int n=0; n<numSamples; n++) {
316        tempRef = getFunctionSpace().getReferenceNoFromSampleNo(n);
317        if (tempRef == ref) {
318          sampleNo = n;
319          break;
320        }
321      }
322      if (sampleNo == -1) {
323        throw DataException("DataExpanded::setRefValue error: invalid ref number supplied.");
324      }
325    
326      for (int n=0; n<numDPPSample; n++) {
327        //
328        // Get each data-point in the sample in turn.
329        DataArrayView pointView = getDataPoint(sampleNo, n);
330    
331        //
332        // Assign the values in the DataArray to this data-point.
333        pointView.copy(value.getView());
334      }
335    }
336    
337    void
338    DataExpanded::getRefValue(int ref,
339                              DataArray& value)
340    {
341      //
342      // Get the number of samples and data-points per sample.
343      int numSamples = getNumSamples();
344      int numDPPSample = getNumDPPSample();
345    
346      //
347      // Determine the sample number which corresponds to this reference number
348      int sampleNo = -1;
349      int tempRef = -1;
350      for (int n=0; n<numSamples; n++) {
351        tempRef = getFunctionSpace().getReferenceNoFromSampleNo(n);
352        if (tempRef == ref) {
353          sampleNo = n;
354          break;
355        }
356      }
357      if (sampleNo == -1) {
358        throw DataException("DataExpanded::getRefValue error: invalid ref number supplied.");
359      }
360    
361      //
362      // Get the first data-point associated with this sample number.
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.113

  ViewVC Help
Powered by ViewVC 1.1.26