/[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 496 by jgs, Tue Feb 7 01:27:14 2006 UTC revision 519 by jgs, Tue Feb 14 05:30:50 2006 UTC
# Line 26  namespace escript { Line 26  namespace escript {
26  DataTagged::DataTagged()  DataTagged::DataTagged()
27    : DataAbstract(FunctionSpace())    : DataAbstract(FunctionSpace())
28  {  {
29      // default constructor
30    
31    // create a scalar default value    // create a scalar default value
32    m_data.resize(1,0.,1);    m_data.resize(1,0.,1);
33    DataArrayView temp(m_data,DataArrayView::ShapeType());    DataArrayView temp(m_data,DataArrayView::ShapeType());
# Line 38  DataTagged::DataTagged(const TagListType Line 40  DataTagged::DataTagged(const TagListType
40                 const FunctionSpace& what)                 const FunctionSpace& what)
41    : DataAbstract(what)    : DataAbstract(what)
42  {  {
43      // constructor
44    
45    // initialise the array of data values    // initialise the array of data values
46    // the default value is always the first item in the values list    // the default value is always the first item in the values list
47    int len = defaultValue.noValues();    int len = defaultValue.noValues();
# Line 57  DataTagged::DataTagged(const TagListType Line 61  DataTagged::DataTagged(const TagListType
61  DataTagged::DataTagged(const FunctionSpace& what,  DataTagged::DataTagged(const FunctionSpace& what,
62                         const DataArrayView::ShapeType &shape,                         const DataArrayView::ShapeType &shape,
63                         const int tags[],                         const int tags[],
64                         const ValueType &data)                         const ValueType& data)
65    : DataAbstract(what)    : DataAbstract(what)
66  {  {
67      // alternative constructor
68      // not unit_tested tested yet
69    
70    // copy the data    // copy the data
71    m_data=data;    m_data=data;
72    
# Line 78  DataTagged::DataTagged(const DataTagged& Line 85  DataTagged::DataTagged(const DataTagged&
85    m_data(other.m_data),    m_data(other.m_data),
86    m_offsetLookup(other.m_offsetLookup)    m_offsetLookup(other.m_offsetLookup)
87  {  {
88      // copy constructor
89    
90    // create the data view    // create the data view
91    DataArrayView temp(m_data,other.getPointDataView().getShape());    DataArrayView temp(m_data,other.getPointDataView().getShape());
92    setPointDataView(temp);    setPointDataView(temp);
# Line 86  DataTagged::DataTagged(const DataTagged& Line 95  DataTagged::DataTagged(const DataTagged&
95  DataTagged::DataTagged(const DataConstant& other)  DataTagged::DataTagged(const DataConstant& other)
96    : DataAbstract(other.getFunctionSpace())    : DataAbstract(other.getFunctionSpace())
97  {  {
98      // copy constructor
99    
100    // fill the default value with the constant value item from "other"    // fill the default value with the constant value item from "other"
101    const DataArrayView& value=other.getPointDataView();    const DataArrayView& value=other.getPointDataView();
102    int len = value.noValues();    int len = value.noValues();
# Line 99  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())  
 {  
   // 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 161  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 and !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
# Line 223  DataTagged::getTagNumber(int dpno) Line 247  DataTagged::getTagNumber(int dpno)
247  }  }
248    
249  void  void
250    DataTagged::setTaggedValues(const TagListType& tagKeys,
251                                const ValueListType& values)
252    {
253      addTaggedValues(tagKeys,values);
254    }
255    
256    void
257  DataTagged::setTaggedValue(int tagKey,  DataTagged::setTaggedValue(int tagKey,
258                             const DataArrayView& value)                             const DataArrayView& value)
259  {  {
# Line 244  DataTagged::setTaggedValue(int tagKey, Line 275  DataTagged::setTaggedValue(int tagKey,
275  }  }
276    
277  void  void
278    DataTagged::addTaggedValues(const TagListType& tagKeys,
279                                const ValueListType& values)
280    {
281      if (values.size()==0) {
282        // copy the current default value for each of the tags
283        TagListType::const_iterator iT;
284        for (iT=tagKeys.begin();iT!=tagKeys.end();iT++) {
285          // the point data view for DataTagged points at the default value
286          addTaggedValue(*iT,getPointDataView());
287        }
288      } else if (values.size()==1 && tagKeys.size()>1) {
289        // assume the one given value will be used for all tag values
290        TagListType::const_iterator iT;
291        for (iT=tagKeys.begin();iT!=tagKeys.end();iT++) {
292          addTaggedValue(*iT,values[0]);
293        }
294      } else {
295        if (tagKeys.size()!=values.size()) {
296          stringstream temp;
297          temp << "Error - (addTaggedValue) Number of tags: " << tagKeys.size()
298           << " doesn't match number of values: " << values.size();
299          throw DataException(temp.str());
300        } else {
301          for (int i=0;i<tagKeys.size();i++) {
302            addTaggedValue(tagKeys[i],values[i]);
303          }
304        }
305      }
306    }
307    
308    void
309  DataTagged::addTaggedValue(int tagKey,  DataTagged::addTaggedValue(int tagKey,
310                             const DataArrayView& value)                             const DataArrayView& value)
311  {  {
# Line 273  DataTagged::addTaggedValue(int tagKey, Line 335  DataTagged::addTaggedValue(int tagKey,
335      }      }
336    }    }
337  }  }
   
 void  
 DataTagged::setTaggedValues(const TagListType& tagKeys,  
                             const ValueListType& values)  
 {  
   addTaggedValues(tagKeys,values);  
 }  
   
 void  
 DataTagged::addTaggedValues(const TagListType& tagKeys,  
                             const ValueListType& values)  
 {  
   if (values.size()==0) {  
     // copy the default value for each of the tags  
     TagListType::const_iterator iT;  
     for (iT=tagKeys.begin();iT!=tagKeys.end();iT++) {  
       // the point data view for DataTagged points at the default value  
       addTaggedValue(*iT,getPointDataView());  
     }  
   } else if (values.size()==1 && tagKeys.size()>1) {  
     // assume the one value will be used for all tag values  
     TagListType::const_iterator iT;  
     for (iT=tagKeys.begin();iT!=tagKeys.end();iT++) {  
       addTaggedValue(*iT,values[0]);  
     }  
   } else {  
     if (tagKeys.size()!=values.size()) {  
       stringstream temp;  
       temp << "Error - (addTaggedValue) Number of tags: " << tagKeys.size()  
        << " doesn't match the number of values: " << values.size();  
       throw DataException(temp.str());  
     } else {  
       for (int i=0;i<tagKeys.size();i++) {  
         addTaggedValue(tagKeys[i],values[i]);  
       }  
     }  
   }  
 }  
338    
339  double*  double*
340  DataTagged::getSampleDataByTag(int tag)  DataTagged::getSampleDataByTag(int tag)

Legend:
Removed from v.496  
changed lines
  Added in v.519

  ViewVC Help
Powered by ViewVC 1.1.26