/[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 97 by jgs, Tue Dec 14 05:39:33 2004 UTC revision 119 by jgs, Tue Apr 12 04:45:05 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 39  DataTagged::DataTagged(const TagListType Line 41  DataTagged::DataTagged(const TagListType
41    : DataAbstract(what)    : DataAbstract(what)
42  {  {
43    //    //
44      // Initialise the array of data values
45    // The default value is always the first item in the values list    // The default value is always the first item in the values list
46    m_data.insert(m_data.end(), &defaultValue.getData(0), &defaultValue.getData(defaultValue.noValues()) );    m_data.insert(m_data.end(), &defaultValue.getData(0), &defaultValue.getData(defaultValue.noValues()) );
47      // create the data view
48    DataArrayView temp(m_data,defaultValue.getShape());    DataArrayView temp(m_data,defaultValue.getShape());
49    setPointDataView(temp);    setPointDataView(temp);
50    // add remaining tags and values    // add remaining tags and values
51    addTaggedValues(tagKeys,values);    addTaggedValues(tagKeys,values);
52  }  }
53    
54    DataTagged::DataTagged(const FunctionSpace& what,
55                           const DataArrayView::ShapeType &shape,
56                           const int tags[],
57                           const DataArrayView::ValueType &data)
58      : DataAbstract(what)
59    {
60      //
61      // copy the data in the correct format
62      m_data=data;
63      //
64      // create the view of the data
65      DataArrayView tempView(m_data,shape);
66      setPointDataView(tempView);
67      //
68      // create the tag lookup map
69      for (int sampleNo=0; sampleNo<getNumSamples(); sampleNo++) {
70        m_offsetLookup.insert(DataMapType::value_type(sampleNo,tags[sampleNo]));
71      }
72    }
73    
74  DataTagged::DataTagged(const DataTagged& other)  DataTagged::DataTagged(const DataTagged& other)
75    : DataAbstract(other.getFunctionSpace()),    : DataAbstract(other.getFunctionSpace()),
76    m_data(other.m_data),    m_data(other.m_data),
77    m_offsetLookup(other.m_offsetLookup)    m_offsetLookup(other.m_offsetLookup)
78  {  {
79      // create the data view
80    DataArrayView temp(m_data,other.getPointDataView().getShape());    DataArrayView temp(m_data,other.getPointDataView().getShape());
81    setPointDataView(temp);    setPointDataView(temp);
82  }  }
# Line 63  DataTagged::DataTagged(const DataConstan Line 88  DataTagged::DataTagged(const DataConstan
88    // Fill the default value with the constant value item from other    // Fill the default value with the constant value item from other
89    const DataArrayView& value=other.getPointDataView();    const DataArrayView& value=other.getPointDataView();
90    m_data.insert(m_data.end(), &value.getData(0), &value.getData(value.noValues()) );    m_data.insert(m_data.end(), &value.getData(0), &value.getData(value.noValues()) );
91      // create the data view
92    DataArrayView temp(m_data,value.getShape());    DataArrayView temp(m_data,value.getShape());
93    setPointDataView(temp);    setPointDataView(temp);
94  }  }
# Line 74  DataTagged::DataTagged(const DataTagged& Line 100  DataTagged::DataTagged(const DataTagged&
100    //    //
101    // get the shape of the slice to copy from other    // get the shape of the slice to copy from other
102    DataArrayView::ShapeType shape(DataArrayView::getResultSliceShape(region));    DataArrayView::ShapeType shape(DataArrayView::getResultSliceShape(region));
103    //    DataArrayView::RegionLoopRangeType region_loop_range=getSliceRegionLoopRange(region);
104    // allocate enough space for all values    // allocate enough space for all values
105    m_data.resize(DataArrayView::noValues(shape)*(other.m_offsetLookup.size()+1));    m_data.resize(DataArrayView::noValues(shape)*(other.m_offsetLookup.size()+1));
106      // create the data view
107    DataArrayView temp(m_data,shape);    DataArrayView temp(m_data,shape);
108    setPointDataView(temp);    setPointDataView(temp);
109    getDefaultValue().copySlice(other.getDefaultValue(),region);    // copy the default value
110      getDefaultValue().copySlice(other.getDefaultValue(),region_loop_range);
111    //    //
112    // Loop through the tag values    // Loop through the tag values copying these
113    DataMapType::const_iterator pos;    DataMapType::const_iterator pos;
114    DataArrayView::ValueType::size_type tagOffset=getPointDataView().noValues();    DataArrayView::ValueType::size_type tagOffset=getPointDataView().noValues();
115    for (pos=other.m_offsetLookup.begin();pos!=other.m_offsetLookup.end();++pos){    for (pos=other.m_offsetLookup.begin();pos!=other.m_offsetLookup.end();++pos){
116      getPointDataView().copySlice(tagOffset,other.getPointDataView(), pos->second,region);      getPointDataView().copySlice(tagOffset,other.getPointDataView(), pos->second,region_loop_range);
117      m_offsetLookup.insert(DataMapType::value_type(pos->first,tagOffset));      m_offsetLookup.insert(DataMapType::value_type(pos->first,tagOffset));
118      tagOffset+=getPointDataView().noValues();      tagOffset+=getPointDataView().noValues();
119    }    }
# Line 136  DataTagged::setSlice(const DataAbstract* Line 164  DataTagged::setSlice(const DataAbstract*
164    if (tempDataTag==0) {    if (tempDataTag==0) {
165      throw DataException("Programming error - casting to DataTagged.");      throw DataException("Programming error - casting to DataTagged.");
166    }    }
167      //
168      DataArrayView::ShapeType shape(DataArrayView::getResultSliceShape(region));
169      DataArrayView::RegionLoopRangeType region_loop_range=getSliceRegionLoopRange(region);
170      //
171    if (getPointDataView().getRank()!=region.size()) {    if (getPointDataView().getRank()!=region.size()) {
172      throw DataException("Error - Invalid slice region.");      throw DataException("Error - Invalid slice region.");
173    }    }
174    //    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)) {  
175      throw DataException (value->getPointDataView().createShapeErrorMessage(      throw DataException (value->getPointDataView().createShapeErrorMessage(
176                  "Error - Couldn't copy slice due to shape mismatch.",shape));                  "Error - Couldn't copy slice due to shape mismatch.",shape));
177    }    }
178    //    //
179    getDefaultValue().copySliceFrom(tempDataTag->getDefaultValue(),region);    getDefaultValue().copySliceFrom(tempDataTag->getDefaultValue(),region_loop_range);
180    //    //
181    // Loop through the tag values    // Loop through the tag values
182    DataMapType::const_iterator pos;    DataMapType::const_iterator pos;
183    for (pos=m_offsetLookup.begin();pos!=m_offsetLookup.end();++pos){    for (pos=m_offsetLookup.begin();pos!=m_offsetLookup.end();++pos){
184      getDataPointByTag(pos->first).copySliceFrom(tempDataTag->getDataPointByTag(pos->first),region);      getDataPointByTag(pos->first).copySliceFrom(tempDataTag->getDataPointByTag(pos->first),region_loop_range);
185    }    }
186  }  }
187    

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

  ViewVC Help
Powered by ViewVC 1.1.26