/[escript]/trunk/escript/src/DataTagged.cpp
ViewVC logotype

Diff of /trunk/escript/src/DataTagged.cpp

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

revision 82 by jgs, Tue Oct 26 06:53:54 2004 UTC revision 108 by jgs, Thu Jan 27 06:21:59 2005 UTC
# Line 15  Line 15 
15    
16  #include "escript/Data/DataTagged.h"  #include "escript/Data/DataTagged.h"
17  #include "escript/Data/DataConstant.h"  #include "escript/Data/DataConstant.h"
18    #include "escript/Data/DataExpanded.h"
19    #include "escript/Data/DataException.h"
20    
21  #include <sstream>  #include <sstream>
22    
# Line 35  DataTagged::DataTagged(): Line 37  DataTagged::DataTagged():
37  DataTagged::DataTagged(const TagListType& tagKeys,  DataTagged::DataTagged(const TagListType& tagKeys,
38                 const ValueListType& values,                 const ValueListType& values,
39                 const DataArrayView& defaultValue,                 const DataArrayView& defaultValue,
40                 const FunctionSpace& what):                 const FunctionSpace& what)
41    DataAbstract(what)    : DataAbstract(what)
42  {  {
43    //    //
44    // The default value is always the first item in the values list    // The default value is always the first item in the values list
# Line 47  DataTagged::DataTagged(const TagListType Line 49  DataTagged::DataTagged(const TagListType
49    addTaggedValues(tagKeys,values);    addTaggedValues(tagKeys,values);
50  }  }
51    
52  DataTagged::DataTagged(const DataTagged& other):  DataTagged::DataTagged(const DataTagged& other)
53    DataAbstract(other.getFunctionSpace()),    : DataAbstract(other.getFunctionSpace()),
54    m_data(other.m_data),    m_data(other.m_data),
55    m_offsetLookup(other.m_offsetLookup)    m_offsetLookup(other.m_offsetLookup)
56  {  {
# Line 56  DataTagged::DataTagged(const DataTagged& Line 58  DataTagged::DataTagged(const DataTagged&
58    setPointDataView(temp);    setPointDataView(temp);
59  }  }
60    
61  DataTagged::DataTagged(const DataConstant& other):  DataTagged::DataTagged(const DataConstant& other)
62    DataAbstract(other.getFunctionSpace())    : DataAbstract(other.getFunctionSpace())
63  {  {
64    //    //
65    // Fill the default value with the constant value item from other    // Fill the default value with the constant value item from other
# Line 68  DataTagged::DataTagged(const DataConstan Line 70  DataTagged::DataTagged(const DataConstan
70  }  }
71    
72  DataTagged::DataTagged(const DataTagged& other,  DataTagged::DataTagged(const DataTagged& other,
73                 const DataArrayView::RegionType& region):                 const DataArrayView::RegionType& region)
74    DataAbstract(other.getFunctionSpace())    : DataAbstract(other.getFunctionSpace())
75  {  {
76    //    //
77    // get the shape of the slice to copy from other    // get the shape of the slice to copy from other
78    DataArrayView::ShapeType shape(DataArrayView::getResultSliceShape(region));    DataArrayView::ShapeType shape(DataArrayView::getResultSliceShape(region));
79    //    DataArrayView::RegionLoopRangeType region_loop_range=getSliceRegionLoopRange(region);
80    // allocate enough space for all values    // allocate enough space for all values
81    m_data.resize(DataArrayView::noValues(shape)*(other.m_offsetLookup.size()+1));    m_data.resize(DataArrayView::noValues(shape)*(other.m_offsetLookup.size()+1));
82    DataArrayView temp(m_data,shape);    DataArrayView temp(m_data,shape);
83    setPointDataView(temp);    setPointDataView(temp);
84    getDefaultValue().copySlice(other.getDefaultValue(),region);    getDefaultValue().copySlice(other.getDefaultValue(),region_loop_range);
85    //    //
86    // Loop through the tag values    // Loop through the tag values
87    DataMapType::const_iterator pos;    DataMapType::const_iterator pos;
88    DataArrayView::ValueType::size_type tagOffset=getPointDataView().noValues();    DataArrayView::ValueType::size_type tagOffset=getPointDataView().noValues();
89    for (pos=other.m_offsetLookup.begin();pos!=other.m_offsetLookup.end();++pos){    for (pos=other.m_offsetLookup.begin();pos!=other.m_offsetLookup.end();++pos){
90      getPointDataView().copySlice(tagOffset,other.getPointDataView(), pos->second,region);      getPointDataView().copySlice(tagOffset,other.getPointDataView(), pos->second,region_loop_range);
91      m_offsetLookup.insert(DataMapType::value_type(pos->first,tagOffset));      m_offsetLookup.insert(DataMapType::value_type(pos->first,tagOffset));
92      tagOffset+=getPointDataView().noValues();      tagOffset+=getPointDataView().noValues();
93    }    }
# Line 136  DataTagged::setSlice(const DataAbstract* Line 138  DataTagged::setSlice(const DataAbstract*
138    if (tempDataTag==0) {    if (tempDataTag==0) {
139      throw DataException("Programming error - casting to DataTagged.");      throw DataException("Programming error - casting to DataTagged.");
140    }    }
141      //
142      DataArrayView::ShapeType shape(DataArrayView::getResultSliceShape(region));
143      DataArrayView::RegionLoopRangeType region_loop_range=getSliceRegionLoopRange(region);
144      //
145    if (getPointDataView().getRank()!=region.size()) {    if (getPointDataView().getRank()!=region.size()) {
146      throw DataException("Error - Invalid slice region.");      throw DataException("Error - Invalid slice region.");
147    }    }
148    //    if (tempDataTag->getPointDataView().getRank()>0 && !value->getPointDataView().checkShape(shape)) {
   // get the shape of the slice  
   DataArrayView::ShapeType shape(DataArrayView::getResultSliceShape(region));  
   if (!value->getPointDataView().checkShape(shape)) {  
149      throw DataException (value->getPointDataView().createShapeErrorMessage(      throw DataException (value->getPointDataView().createShapeErrorMessage(
150                  "Error - Couldn't copy slice due to shape mismatch.",shape));                  "Error - Couldn't copy slice due to shape mismatch.",shape));
151    }    }
152    getDefaultValue().copySliceFrom(tempDataTag->getDefaultValue(),region);    //
153      getDefaultValue().copySliceFrom(tempDataTag->getDefaultValue(),region_loop_range);
154    //    //
155    // Loop through the tag values    // Loop through the tag values
156    DataMapType::const_iterator pos;    DataMapType::const_iterator pos;
157    for (pos=m_offsetLookup.begin();pos!=m_offsetLookup.end();++pos){    for (pos=m_offsetLookup.begin();pos!=m_offsetLookup.end();++pos){
158      getDataPointByTag(pos->first).copySliceFrom(tempDataTag->getDataPointByTag(pos->first),region);      getDataPointByTag(pos->first).copySliceFrom(tempDataTag->getDataPointByTag(pos->first),region_loop_range);
159    }    }
160  }  }
161    

Legend:
Removed from v.82  
changed lines
  Added in v.108

  ViewVC Help
Powered by ViewVC 1.1.26