/[escript]/branches/arrexp_2137_win/escript/src/DataTagged.cpp
ViewVC logotype

Diff of /branches/arrexp_2137_win/escript/src/DataTagged.cpp

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

revision 512 by jgs, Fri Feb 10 03:24:44 2006 UTC revision 513 by jgs, Mon Feb 13 04:46:51 2006 UTC
# Line 110  DataTagged::DataTagged(const DataConstan Line 110  DataTagged::DataTagged(const DataConstan
110    setPointDataView(temp);    setPointDataView(temp);
111  }  }
112    
 DataTagged::DataTagged(const DataTagged& other,  
                const DataArrayView::RegionType& region)  
   : DataAbstract(other.getFunctionSpace())  
 {  
   // slice constructor  
   
   // get the shape of the slice to copy from other  
   DataArrayView::ShapeType shape(DataArrayView::getResultSliceShape(region));  
   DataArrayView::RegionLoopRangeType region_loop_range=getSliceRegionLoopRange(region);  
   
   // allocate enough space for all values  
   int len = DataArrayView::noValues(shape)*(other.m_offsetLookup.size()+1);  
   m_data.resize(len,0.,len);  
   
   // create the data view  
   DataArrayView temp(m_data,shape);  
   setPointDataView(temp);  
   
   // copy the default value  
   getDefaultValue().copySlice(other.getDefaultValue(),region_loop_range);  
   
   // loop through the tag values copying these  
   DataMapType::const_iterator pos;  
   DataArrayView::ValueType::size_type tagOffset=getPointDataView().noValues();  
   for (pos=other.m_offsetLookup.begin();pos!=other.m_offsetLookup.end();pos++){  
     getPointDataView().copySlice(tagOffset,other.getPointDataView(),pos->second,region_loop_range);  
     m_offsetLookup.insert(DataMapType::value_type(pos->first,tagOffset));  
     tagOffset+=getPointDataView().noValues();  
   }  
 }  
   
113  void  void
114  DataTagged::reshapeDataPoint(const DataArrayView::ShapeType& shape)  DataTagged::reshapeDataPoint(const DataArrayView::ShapeType& shape)
115  {  {
# Line 174  DataTagged::reshapeDataPoint(const DataA Line 143  DataTagged::reshapeDataPoint(const DataA
143  DataAbstract*  DataAbstract*
144  DataTagged::getSlice(const DataArrayView::RegionType& region) const  DataTagged::getSlice(const DataArrayView::RegionType& region) const
145  {  {
146    return new DataTagged(*this,region);    return new DataTagged(*this, region);
147    }
148    
149    DataTagged::DataTagged(const DataTagged& other,
150                   const DataArrayView::RegionType& region)
151      : DataAbstract(other.getFunctionSpace())
152    {
153      // slice constructor
154    
155      // get the shape of the slice to copy from other
156      DataArrayView::ShapeType regionShape(DataArrayView::getResultSliceShape(region));
157      DataArrayView::RegionLoopRangeType regionLoopRange=getSliceRegionLoopRange(region);
158    
159      // allocate enough space in this for all values
160      // (need to add one to allow for the default value)
161      int len = DataArrayView::noValues(regionShape)*(other.m_offsetLookup.size()+1);
162      m_data.resize(len,0.0,len);
163    
164      // create the data view
165      DataArrayView temp(m_data,regionShape);
166      setPointDataView(temp);
167    
168      // copy the default value from other to this
169      getDefaultValue().copySlice(other.getDefaultValue(), regionLoopRange);
170    
171      // loop through the tag values copying these
172      DataMapType::const_iterator pos;
173      DataArrayView::ValueType::size_type tagOffset=getPointDataView().noValues();
174      for (pos=other.m_offsetLookup.begin();pos!=other.m_offsetLookup.end();pos++){
175        getPointDataView().copySlice(tagOffset,other.getPointDataView(),pos->second,regionLoopRange);
176        m_offsetLookup.insert(DataMapType::value_type(pos->first,tagOffset));
177        tagOffset+=getPointDataView().noValues();
178      }
179  }  }
180    
181  void  void
182  DataTagged::setSlice(const DataAbstract* value,  DataTagged::setSlice(const DataAbstract* other,
183                       const DataArrayView::RegionType& region)                       const DataArrayView::RegionType& region)
184  {  {
185    const DataTagged* tempDataTag=dynamic_cast<const DataTagged*>(value);  
186    if (tempDataTag==0) {    // other must be another DataTagged object
187      // Data:setSlice implementation should ensure this
188      const DataTagged* otherTemp=dynamic_cast<const DataTagged*>(other);
189      if (otherTemp==0) {
190      throw DataException("Programming error - casting to DataTagged.");      throw DataException("Programming error - casting to DataTagged.");
191    }    }
192    
193    DataArrayView::ShapeType shape(DataArrayView::getResultSliceShape(region));    // determine shape of the specified region
194    DataArrayView::RegionLoopRangeType region_loop_range=getSliceRegionLoopRange(region);    DataArrayView::ShapeType regionShape(DataArrayView::getResultSliceShape(region));
195    
196      // modify region specification as needed to match rank of this object
197      DataArrayView::RegionLoopRangeType regionLoopRange=getSliceRegionLoopRange(region);
198    
199      // ensure rank/shape of this object is compatible with specified region
200    if (getPointDataView().getRank()!=region.size()) {    if (getPointDataView().getRank()!=region.size()) {
201      throw DataException("Error - Invalid slice region.");      throw DataException("Error - Invalid slice region.");
202    }    }
203    if (tempDataTag->getPointDataView().getRank()>0 && !value->getPointDataView().checkShape(shape)) {    if (otherTemp->getPointDataView().getRank()>0 && !other->getPointDataView().checkShape(regionShape)) {
204      throw DataException (value->getPointDataView().createShapeErrorMessage(      throw DataException (other->getPointDataView().createShapeErrorMessage(
205                  "Error - Couldn't copy slice due to shape mismatch.",shape));                           "Error - Couldn't copy slice due to shape mismatch.",regionShape));
206    }    }
207    
208    getDefaultValue().copySliceFrom(tempDataTag->getDefaultValue(),region_loop_range);    // copy slice from other default value to this default value
209      getDefaultValue().copySliceFrom(otherTemp->getDefaultValue(), regionLoopRange);
210    
211    // loop through the tag values    // loop through the tag values copying slices from other to this
212    DataMapType::const_iterator pos;    DataMapType::const_iterator pos;
213    for (pos=m_offsetLookup.begin();pos!=m_offsetLookup.end();pos++) {    for (pos=m_offsetLookup.begin();pos!=m_offsetLookup.end();pos++) {
214      getDataPointByTag(pos->first).copySliceFrom(tempDataTag->getDataPointByTag(pos->first),region_loop_range);      getDataPointByTag(pos->first).copySliceFrom(otherTemp->getDataPointByTag(pos->first), regionLoopRange);
215    }    }
216    
217  }  }
218    
219  int  int

Legend:
Removed from v.512  
changed lines
  Added in v.513

  ViewVC Help
Powered by ViewVC 1.1.26