/[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

trunk/esys2/escript/src/Data/DataTagged.cpp revision 119 by jgs, Tue Apr 12 04:45:05 2005 UTC trunk/escript/src/DataTagged.cpp revision 757 by woo409, Mon Jun 26 13:12:56 2006 UTC
# Line 1  Line 1 
1  // $Id$  // $Id$
2    
3  /*  /*
4   ******************************************************************************   ************************************************************
5   *                                                                            *   *          Copyright 2006 by ACcESS MNRF                   *
6   *       COPYRIGHT  ACcESS 2004 -  All Rights Reserved                        *   *                                                          *
7   *                                                                            *   *              http://www.access.edu.au                    *
8   * This software is the property of ACcESS. No part of this code              *   *       Primary Business: Queensland, Australia            *
9   * may be copied in any form or by any means without the expressed written    *   *  Licensed under the Open Software License version 3.0    *
10   * consent of ACcESS.  Copying, use or modification of this software          *   *     http://www.opensource.org/licenses/osl-3.0.php       *
11   * by any unauthorised person is illegal unless that person has a software    *   *                                                          *
12   * license agreement with ACcESS.                                             *   ************************************************************
  *                                                                            *  
  ******************************************************************************  
13  */  */
14    
15  #include "escript/Data/DataTagged.h"  #include "DataTagged.h"
 #include "escript/Data/DataConstant.h"  
 #include "escript/Data/DataExpanded.h"  
 #include "escript/Data/DataException.h"  
16    
17  #include <sstream>  #include "DataConstant.h"
18    #include "DataException.h"
19    
20  using namespace std;  using namespace std;
21    
22  namespace escript {  namespace escript {
23    
24  DataTagged::DataTagged():  DataTagged::DataTagged()
25    DataAbstract(FunctionSpace())    : DataAbstract(FunctionSpace())
26  {  {
27    //    // default constructor
28    
29    // create a scalar default value    // create a scalar default value
30    m_data.push_back(0.0);    m_data.resize(1,0.,1);
31    DataArrayView temp(m_data,DataArrayView::ShapeType());    DataArrayView temp(m_data,DataArrayView::ShapeType());
32    setPointDataView(temp);    setPointDataView(temp);
33  }  }
# Line 40  DataTagged::DataTagged(const TagListType Line 38  DataTagged::DataTagged(const TagListType
38                 const FunctionSpace& what)                 const FunctionSpace& what)
39    : DataAbstract(what)    : DataAbstract(what)
40  {  {
41    //    // constructor
42    // Initialise the array of data values  
43    // The default value is always the first item in the values list    // initialise the array of data values
44    m_data.insert(m_data.end(), &defaultValue.getData(0), &defaultValue.getData(defaultValue.noValues()) );    // the default value is always the first item in the values list
45      int len = defaultValue.noValues();
46      m_data.resize(len,0.,len);
47      for (int i=0; i<defaultValue.noValues(); i++) {
48        m_data[i]=defaultValue.getData(i);
49      }
50    
51    // create the data view    // create the data view
52    DataArrayView temp(m_data,defaultValue.getShape());    DataArrayView temp(m_data,defaultValue.getShape());
53    setPointDataView(temp);    setPointDataView(temp);
54    
55    // add remaining tags and values    // add remaining tags and values
56    addTaggedValues(tagKeys,values);    addTaggedValues(tagKeys,values);
57  }  }
# Line 54  DataTagged::DataTagged(const TagListType Line 59  DataTagged::DataTagged(const TagListType
59  DataTagged::DataTagged(const FunctionSpace& what,  DataTagged::DataTagged(const FunctionSpace& what,
60                         const DataArrayView::ShapeType &shape,                         const DataArrayView::ShapeType &shape,
61                         const int tags[],                         const int tags[],
62                         const DataArrayView::ValueType &data)                         const ValueType& data)
63    : DataAbstract(what)    : DataAbstract(what)
64  {  {
65    //    // alternative constructor
66    // copy the data in the correct format    // not unit_tested tested yet
67    
68      // copy the data
69    m_data=data;    m_data=data;
70    //  
71    // create the view of the data    // create the view of the data
72    DataArrayView tempView(m_data,shape);    DataArrayView tempView(m_data,shape);
73    setPointDataView(tempView);    setPointDataView(tempView);
74    //  
75      // create the tag lookup map
76      for (int sampleNo=0; sampleNo<getNumSamples(); sampleNo++) {
77        m_offsetLookup.insert(DataMapType::value_type(sampleNo,tags[sampleNo]));
78      }
79    }
80    
81    DataTagged::DataTagged(const FunctionSpace& what,
82                           const DataArrayView::ShapeType &shape,
83                           const TagListType& tags,
84                           const ValueType& data)
85      : DataAbstract(what)
86    {
87      // alternative constructor
88      // not unit_tested tested yet
89    
90      // copy the data
91      m_data=data;
92    
93      // create the view of the data
94      DataArrayView tempView(m_data,shape);
95      setPointDataView(tempView);
96    
97    // create the tag lookup map    // create the tag lookup map
98    for (int sampleNo=0; sampleNo<getNumSamples(); sampleNo++) {    for (int sampleNo=0; sampleNo<getNumSamples(); sampleNo++) {
99      m_offsetLookup.insert(DataMapType::value_type(sampleNo,tags[sampleNo]));      m_offsetLookup.insert(DataMapType::value_type(sampleNo,tags[sampleNo]));
100    }    }
101  }  }
102    
103    
104  DataTagged::DataTagged(const DataTagged& other)  DataTagged::DataTagged(const DataTagged& other)
105    : DataAbstract(other.getFunctionSpace()),    : DataAbstract(other.getFunctionSpace()),
106    m_data(other.m_data),    m_data(other.m_data),
107    m_offsetLookup(other.m_offsetLookup)    m_offsetLookup(other.m_offsetLookup)
108  {  {
109      // copy constructor
110    
111    // create the data view    // create the data view
112    DataArrayView temp(m_data,other.getPointDataView().getShape());    DataArrayView temp(m_data,other.getPointDataView().getShape());
113    setPointDataView(temp);    setPointDataView(temp);
# Line 84  DataTagged::DataTagged(const DataTagged& Line 116  DataTagged::DataTagged(const DataTagged&
116  DataTagged::DataTagged(const DataConstant& other)  DataTagged::DataTagged(const DataConstant& other)
117    : DataAbstract(other.getFunctionSpace())    : DataAbstract(other.getFunctionSpace())
118  {  {
119    //    // copy constructor
120    // Fill the default value with the constant value item from other  
121      // fill the default value with the constant value item from "other"
122    const DataArrayView& value=other.getPointDataView();    const DataArrayView& value=other.getPointDataView();
123    m_data.insert(m_data.end(), &value.getData(0), &value.getData(value.noValues()) );    int len = value.noValues();
124    // create the data view    m_data.resize(len,0.,len);
125    DataArrayView temp(m_data,value.getShape());    for (int i=0; i<value.noValues(); i++) {
126    setPointDataView(temp);      m_data[i]=value.getData(i);
127  }    }
128    
 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  
   m_data.resize(DataArrayView::noValues(shape)*(other.m_offsetLookup.size()+1));  
129    // create the data view    // create the data view
130    DataArrayView temp(m_data,shape);    DataArrayView temp(m_data,value.getShape());
131    setPointDataView(temp);    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();  
   }  
132  }  }
133    
134  void  void
135  DataTagged::reshapeDataPoint(const DataArrayView::ShapeType& shape)  DataTagged::reshapeDataPoint(const DataArrayView::ShapeType& shape)
136  {  {
   //  
137    // can only reshape a rank zero data point    // can only reshape a rank zero data point
138    if (getPointDataView().getRank()!=0) {    if (getPointDataView().getRank()!=0) {
139      stringstream temp;      stringstream temp;
# Line 131  DataTagged::reshapeDataPoint(const DataA Line 142  DataTagged::reshapeDataPoint(const DataA
142       << getPointDataView().getRank();       << getPointDataView().getRank();
143      throw DataException(temp.str());      throw DataException(temp.str());
144    }    }
145    //  
146    // allocate enough space for all values    // allocate enough space for all values
147    DataArrayView::ValueType newData(DataArrayView::noValues(shape)*(m_offsetLookup.size()+1));    DataArrayView::ValueType newData(DataArrayView::noValues(shape)*(m_offsetLookup.size()+1));
148    DataArrayView newView(newData,shape);    DataArrayView newView(newData,shape);
149    newView.copy(0,getDefaultValue()());    newView.copy(0,getDefaultValue()());
150    //  
151    // Loop through the tag values    // loop through the tag values
152    DataMapType::iterator pos;    DataMapType::iterator pos;
153    DataArrayView::ValueType::size_type tagOffset=DataArrayView::noValues(shape);    DataArrayView::ValueType::size_type tagOffset=DataArrayView::noValues(shape);
154    for (pos=m_offsetLookup.begin();pos!=m_offsetLookup.end();++pos){    for (pos=m_offsetLookup.begin();pos!=m_offsetLookup.end();pos++){
155      newView.copy(tagOffset,m_data[pos->second]);      newView.copy(tagOffset,m_data[pos->second]);
156      pos->second=tagOffset;      pos->second=tagOffset;
157      tagOffset+=DataArrayView::noValues(shape);      tagOffset+=DataArrayView::noValues(shape);
# Line 153  DataTagged::reshapeDataPoint(const DataA Line 164  DataTagged::reshapeDataPoint(const DataA
164  DataAbstract*  DataAbstract*
165  DataTagged::getSlice(const DataArrayView::RegionType& region) const  DataTagged::getSlice(const DataArrayView::RegionType& region) const
166  {  {
167    return new DataTagged(*this,region);    return new DataTagged(*this, region);
168    }
169    
170    DataTagged::DataTagged(const DataTagged& other,
171                   const DataArrayView::RegionType& region)
172      : DataAbstract(other.getFunctionSpace())
173    {
174      // slice constructor
175    
176      // get the shape of the slice to copy from other
177      DataArrayView::ShapeType regionShape(DataArrayView::getResultSliceShape(region));
178      DataArrayView::RegionLoopRangeType regionLoopRange=getSliceRegionLoopRange(region);
179    
180      // allocate enough space in this for all values
181      // (need to add one to allow for the default value)
182      int len = DataArrayView::noValues(regionShape)*(other.m_offsetLookup.size()+1);
183      m_data.resize(len,0.0,len);
184    
185      // create the data view
186      DataArrayView temp(m_data,regionShape);
187      setPointDataView(temp);
188    
189      // copy the default value from other to this
190      getDefaultValue().copySlice(other.getDefaultValue(), regionLoopRange);
191    
192      // loop through the tag values copying these
193      DataMapType::const_iterator pos;
194      DataArrayView::ValueType::size_type tagOffset=getPointDataView().noValues();
195      for (pos=other.m_offsetLookup.begin();pos!=other.m_offsetLookup.end();pos++){
196        getPointDataView().copySlice(tagOffset,other.getPointDataView(),pos->second,regionLoopRange);
197        m_offsetLookup.insert(DataMapType::value_type(pos->first,tagOffset));
198        tagOffset+=getPointDataView().noValues();
199      }
200  }  }
201    
202  void  void
203  DataTagged::setSlice(const DataAbstract* value,  DataTagged::setSlice(const DataAbstract* other,
204                       const DataArrayView::RegionType& region)                       const DataArrayView::RegionType& region)
205  {  {
206    const DataTagged* tempDataTag=dynamic_cast<const DataTagged*>(value);  
207    if (tempDataTag==0) {    // other must be another DataTagged object
208      // Data:setSlice implementation should ensure this
209      const DataTagged* otherTemp=dynamic_cast<const DataTagged*>(other);
210      if (otherTemp==0) {
211      throw DataException("Programming error - casting to DataTagged.");      throw DataException("Programming error - casting to DataTagged.");
212    }    }
213    //  
214    DataArrayView::ShapeType shape(DataArrayView::getResultSliceShape(region));    // determine shape of the specified region
215    DataArrayView::RegionLoopRangeType region_loop_range=getSliceRegionLoopRange(region);    DataArrayView::ShapeType regionShape(DataArrayView::getResultSliceShape(region));
216    //  
217      // modify region specification as needed to match rank of this object
218      DataArrayView::RegionLoopRangeType regionLoopRange=getSliceRegionLoopRange(region);
219    
220      // ensure rank/shape of this object is compatible with specified region
221    if (getPointDataView().getRank()!=region.size()) {    if (getPointDataView().getRank()!=region.size()) {
222      throw DataException("Error - Invalid slice region.");      throw DataException("Error - Invalid slice region.");
223    }    }
224    if (tempDataTag->getPointDataView().getRank()>0 && !value->getPointDataView().checkShape(shape)) {    if (otherTemp->getPointDataView().getRank()>0 && !other->getPointDataView().checkShape(regionShape)) {
225      throw DataException (value->getPointDataView().createShapeErrorMessage(      throw DataException (other->getPointDataView().createShapeErrorMessage(
226                  "Error - Couldn't copy slice due to shape mismatch.",shape));                           "Error - Couldn't copy slice due to shape mismatch.",regionShape));
227    }    }
228    //  
229    getDefaultValue().copySliceFrom(tempDataTag->getDefaultValue(),region_loop_range);    // copy slice from other default value to this default value
230    //    getDefaultValue().copySliceFrom(otherTemp->getDefaultValue(), regionLoopRange);
231    // Loop through the tag values  
232      // loop through tag values in other, adding any which aren't in this, using default value
233    DataMapType::const_iterator pos;    DataMapType::const_iterator pos;
234    for (pos=m_offsetLookup.begin();pos!=m_offsetLookup.end();++pos){    for (pos=otherTemp->m_offsetLookup.begin();pos!=otherTemp->m_offsetLookup.end();pos++) {
235      getDataPointByTag(pos->first).copySliceFrom(tempDataTag->getDataPointByTag(pos->first),region_loop_range);      if (!isCurrentTag(pos->first)) {
236    }        addTaggedValue(pos->first,getDefaultValue());
237        }
238      }
239    
240      // loop through the tag values copying slices from other to this
241      for (pos=m_offsetLookup.begin();pos!=m_offsetLookup.end();pos++) {
242        getDataPointByTag(pos->first).copySliceFrom(otherTemp->getDataPointByTag(pos->first), regionLoopRange);
243      }
244    
245  }  }
246    
247  void  int
248  DataTagged::setTaggedValue(int tagKey,  DataTagged::getTagNumber(int dpno)
                            const DataArrayView& value)  
249  {  {
250    DataMapType::iterator pos(m_offsetLookup.find(tagKey));    //
251    if (pos==m_offsetLookup.end()) {    // Get the number of samples and data-points per sample
252      //    int numSamples = getNumSamples();
253      // tag couldn't be found so add as a new tag    int numDataPointsPerSample = getNumDPPSample();
254      addTaggedValue(tagKey,value);    int numDataPoints = numSamples * numDataPointsPerSample;
255    } else {  
256      if (!getPointDataView().checkShape(value.getShape())) {    if (numDataPointsPerSample==0) {
257        throw DataException(getPointDataView().createShapeErrorMessage(      throw DataException("DataTagged::getTagNumber error: no data-points associated with this object.");
          "Error - Cannot setTaggedValue due to shape mismatch.", value.getShape()));  
     }  
     //  
     // copy the values into tagged data storage  
     copy(&value.getData(0), &value.getData(getPointDataView().noValues()), &m_data[pos->second]);  
258    }    }
259    
260      if (dpno<0 || dpno>numDataPoints-1) {
261        throw DataException("DataTagged::getTagNumber error: invalid data-point number supplied.");
262      }
263    
264      //
265      // Determine the sample number which corresponds to this data-point number
266      int sampleNo = dpno / numDataPointsPerSample;
267    
268      //
269      // Determine the tag number which corresponds to this sample number
270      int tagNo = getFunctionSpace().getTagFromSampleNo(sampleNo);
271    
272      //
273      // return the tag number
274      return(tagNo);
275  }  }
276    
277  void  void
278  DataTagged::setTaggedValues(const TagListType& tagKeys,  DataTagged::setTaggedValues(const TagListType& tagKeys,
279                              const ValueListType& values)                              const ValueListType& values)
280  {  {
281    for (int i=0;i<tagKeys.size();++i) {    addTaggedValues(tagKeys,values);
     setTaggedValue(tagKeys[i],values[i]);  
   }  
282  }  }
283    
284  void  void
285  DataTagged::addTaggedValue(int tagKey,  DataTagged::setTaggedValue(int tagKey,
286                             const DataArrayView& value)                             const DataArrayView& value)
287  {  {
288    if (!getPointDataView().checkShape(value.getShape())) {    if (!getPointDataView().checkShape(value.getShape())) {
289      throw DataException(getPointDataView().createShapeErrorMessage(        throw DataException(getPointDataView().createShapeErrorMessage(
290           "Error - Cannot addTaggedValue due to shape mismatch.", value.getShape()));                            "Error - Cannot setTaggedValue due to shape mismatch.", value.getShape()));
291      }
292      DataMapType::iterator pos(m_offsetLookup.find(tagKey));
293      if (pos==m_offsetLookup.end()) {
294        // tag couldn't be found so use addTaggedValue
295        addTaggedValue(tagKey,value);
296      } else {
297        // copy the values into the data array at the offset determined by m_offsetLookup
298        int offset=pos->second;
299        for (int i=0; i<getPointDataView().noValues(); i++) {
300          m_data[offset+i]=value.getData(i);
301        }
302    }    }
   //  
   // save the key and the location of its data  
   m_offsetLookup.insert( DataMapType::value_type(tagKey,m_data.size()) );  
   //  
   // insert the data given in value at the end of m_data  
   m_data.insert( m_data.end(), &(value.getData(0)), &(value.getData(value.noValues())) );  
303  }  }
304    
305  void  void
# Line 235  DataTagged::addTaggedValues(const TagLis Line 307  DataTagged::addTaggedValues(const TagLis
307                              const ValueListType& values)                              const ValueListType& values)
308  {  {
309    if (values.size()==0) {    if (values.size()==0) {
310      //      // copy the current default value for each of the tags
     // Copy the default value for each of the tags  
311      TagListType::const_iterator iT;      TagListType::const_iterator iT;
312      for (iT=tagKeys.begin();iT!=tagKeys.end();++iT) {      for (iT=tagKeys.begin();iT!=tagKeys.end();iT++) {
       //  
313        // the point data view for DataTagged points at the default value        // the point data view for DataTagged points at the default value
314        addTaggedValue(*iT,getPointDataView());        addTaggedValue(*iT,getPointDataView());
315      }      }
316    } else if (values.size()==1 && tagKeys.size()>1) {    } else if (values.size()==1 && tagKeys.size()>1) {
317      //      // assume the one given value will be used for all tag values
     // assume the one value will be used for all tag values  
     // Copy the input data  
318      TagListType::const_iterator iT;      TagListType::const_iterator iT;
319      for (iT=tagKeys.begin();iT!=tagKeys.end();++iT) {      for (iT=tagKeys.begin();iT!=tagKeys.end();iT++) {
320        addTaggedValue(*iT,values[0]);        addTaggedValue(*iT,values[0]);
321      }      }
322    } else {    } else {
323      if (tagKeys.size()!=values.size()) {      if (tagKeys.size()!=values.size()) {
324        stringstream temp;        stringstream temp;
325        temp << "Error - (addTaggedValue) Number of tags: " << tagKeys.size()        temp << "Error - (addTaggedValue) Number of tags: " << tagKeys.size()
326         << " doesn't match the number of values: " << values.size();         << " doesn't match number of values: " << values.size();
327        throw DataException(temp.str());        throw DataException(temp.str());
328      } else {      } else {
329        for (int i=0;i<tagKeys.size();++i) {        for (int i=0;i<tagKeys.size();i++) {
330          addTaggedValue(tagKeys[i],values[i]);          addTaggedValue(tagKeys[i],values[i]);
331        }        }
332      }      }
333    }    }
334  }  }
335    
336    void
337    DataTagged::addTaggedValue(int tagKey,
338                               const DataArrayView& value)
339    {
340      if (!getPointDataView().checkShape(value.getShape())) {
341        throw DataException(getPointDataView().createShapeErrorMessage(
342                            "Error - Cannot addTaggedValue due to shape mismatch.", value.getShape()));
343      }
344      DataMapType::iterator pos(m_offsetLookup.find(tagKey));
345      if (pos!=m_offsetLookup.end()) {
346        // tag already exists so use setTaggedValue
347        setTaggedValue(tagKey,value);
348      } else {
349        // save the key and the location of its data in the lookup tab
350        m_offsetLookup.insert(DataMapType::value_type(tagKey,m_data.size()));
351        // add the data given in "value" at the end of m_data
352        // need to make a temp copy of m_data, resize m_data, then copy
353        // all the old values plus the value to be added back into m_data
354        ValueType m_data_temp(m_data);
355        int oldSize=m_data.size();
356        int newSize=m_data.size()+value.noValues();
357        m_data.resize(newSize,0.,newSize);
358        for (int i=0;i<oldSize;i++) {
359          m_data[i]=m_data_temp[i];
360        }
361        for (int i=0;i<value.noValues();i++) {
362          m_data[oldSize+i]=value.getData(i);
363        }
364      }
365    }
366    
367  double*  double*
368  DataTagged::getSampleDataByTag(int tag)  DataTagged::getSampleDataByTag(int tag)
369  {  {
370    DataMapType::iterator pos(m_offsetLookup.find(tag));    DataMapType::iterator pos(m_offsetLookup.find(tag));
371    if (pos==m_offsetLookup.end()) {    if (pos==m_offsetLookup.end()) {
     //  
372      // tag couldn't be found so return the default value      // tag couldn't be found so return the default value
373      return &(m_data[0]);      return &(m_data[0]);
374    } else {    } else {
     //  
375      // return the data-point corresponding to the given tag      // return the data-point corresponding to the given tag
376      return &(m_data[pos->second]);      return &(m_data[pos->second]);
377    }    }
# Line 287  DataTagged::toString() const Line 384  DataTagged::toString() const
384    DataMapType::const_iterator i;    DataMapType::const_iterator i;
385    temp << "Tag(Default)" << endl;    temp << "Tag(Default)" << endl;
386    temp << getDefaultValue().toString() << endl;    temp << getDefaultValue().toString() << endl;
   //  
387    // create a temporary view as the offset will be changed    // create a temporary view as the offset will be changed
388    DataArrayView tempView(getPointDataView().getData(), getPointDataView().getShape());    DataArrayView tempView(getPointDataView().getData(), getPointDataView().getShape());
389    for (i=m_offsetLookup.begin();i!=m_offsetLookup.end();++i) {    for (i=m_offsetLookup.begin();i!=m_offsetLookup.end();++i) {
# Line 298  DataTagged::toString() const Line 394  DataTagged::toString() const
394    return temp.str();    return temp.str();
395  }  }
396    
397  DataArrayView  DataArrayView::ValueType::size_type
398  DataTagged::getDataPointByTag(int tag) const  DataTagged::getPointOffset(int sampleNo,
399                               int dataPointNo) const
400  {  {
401    DataMapType::const_iterator pos(m_offsetLookup.find(tag));    int tagKey=getFunctionSpace().getTagFromSampleNo(sampleNo);
402      DataMapType::const_iterator pos(m_offsetLookup.find(tagKey));
403    DataArrayView::ValueType::size_type offset=m_defaultValueOffset;    DataArrayView::ValueType::size_type offset=m_defaultValueOffset;
404    if (pos!=m_offsetLookup.end()) {    if (pos!=m_offsetLookup.end()) {
405      offset=pos->second;      offset=pos->second;
406    }    }
407    DataArrayView temp(getPointDataView());    return offset;
   temp.setOffset(offset);  
   return temp;  
408  }  }
409    
410  DataArrayView::ValueType::size_type  DataArrayView
411  DataTagged::getPointOffset(int sampleNo,  DataTagged::getDataPointByTag(int tag) const
                            int dataPointNo) const  
412  {  {
413    int tagKey=getFunctionSpace().getTagFromSampleNo(sampleNo);    DataMapType::const_iterator pos(m_offsetLookup.find(tag));
   DataMapType::const_iterator pos(m_offsetLookup.find(tagKey));  
414    DataArrayView::ValueType::size_type offset=m_defaultValueOffset;    DataArrayView::ValueType::size_type offset=m_defaultValueOffset;
415    if (pos!=m_offsetLookup.end()) {    if (pos!=m_offsetLookup.end()) {
416      offset=pos->second;      offset=pos->second;
417    }    }
418    return offset;    DataArrayView temp(getPointDataView());
419      temp.setOffset(offset);
420      return temp;
421  }  }
422    
423  DataArrayView  DataArrayView
# Line 333  DataTagged::getDataPoint(int sampleNo, Line 429  DataTagged::getDataPoint(int sampleNo,
429    return getDataPointByTag(tagKey);    return getDataPointByTag(tagKey);
430  }  }
431    
432  const DataTagged::DataMapType&  int
433  DataTagged::getTagLookup() const  DataTagged::archiveData(ofstream& archiveFile,
434                            const DataArrayView::ValueType::size_type noValues) const
435  {  {
436    return m_offsetLookup;    return(m_data.archiveData(archiveFile, noValues));
437  }  }
438    
439  DataArrayView::ValueType::size_type  int
440  DataTagged::getLength() const  DataTagged::extractData(ifstream& archiveFile,
441                            const DataArrayView::ValueType::size_type noValues)
442    {
443      return(m_data.extractData(archiveFile, noValues));
444    }
445    void
446    DataTagged::eigenvalues(DataAbstract* ev)
447  {  {
448    return m_data.size();    DataTagged* temp_ev=dynamic_cast<DataTagged*>(ev);
449      if (temp_ev==0) {
450        throw DataException("Error - DataTagged::eigenvalues casting to DataTagged failed (propably a programming error).");
451      }
452      const DataTagged::DataMapType& thisLookup=getTagLookup();
453      DataTagged::DataMapType::const_iterator i;
454      DataTagged::DataMapType::const_iterator thisLookupEnd=thisLookup.end();
455      for (i=thisLookup.begin();i!=thisLookupEnd;i++) {
456          temp_ev->addTaggedValue(i->first,temp_ev->getDefaultValue());
457          DataArrayView thisView=getDataPointByTag(i->first);
458          DataArrayView evView=temp_ev->getDataPointByTag(i->first);
459          DataArrayView::eigenvalues(thisView,0,evView,0);
460      }
461      DataArrayView::eigenvalues(getDefaultValue(),0,temp_ev->getDefaultValue(),0);
462  }  }
463    void
464    DataTagged::eigenvalues_and_eigenvectors(DataAbstract* ev,DataAbstract* V,const double tol)
465    {
466      DataTagged* temp_ev=dynamic_cast<DataTagged*>(ev);
467      if (temp_ev==0) {
468        throw DataException("Error - DataTagged::eigenvalues_and_eigenvectors casting to DataTagged failed (propably a programming error).");
469      }
470      DataTagged* temp_V=dynamic_cast<DataTagged*>(V);
471      if (temp_V==0) {
472        throw DataException("Error - DataTagged::eigenvalues_and_eigenvectors casting to DataTagged failed (propably a programming error).");
473      }
474      const DataTagged::DataMapType& thisLookup=getTagLookup();
475      DataTagged::DataMapType::const_iterator i;
476      DataTagged::DataMapType::const_iterator thisLookupEnd=thisLookup.end();
477      for (i=thisLookup.begin();i!=thisLookupEnd;i++) {
478          temp_ev->addTaggedValue(i->first,temp_ev->getDefaultValue());
479          temp_V->addTaggedValue(i->first,temp_V->getDefaultValue());
480          DataArrayView thisView=getDataPointByTag(i->first);
481          DataArrayView evView=temp_ev->getDataPointByTag(i->first);
482          DataArrayView VView=temp_V->getDataPointByTag(i->first);
483          DataArrayView::eigenvalues_and_eigenvectors(thisView,0,evView,0,VView,0,tol);
484      }
485      DataArrayView::eigenvalues_and_eigenvectors(getDefaultValue(),0,
486                                                  temp_ev->getDefaultValue(),0,
487                                                  temp_V->getDefaultValue(),0,
488                                                  tol);
489    
490    
491    }
492    
493    
494  }  // end of namespace  }  // end of namespace

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

  ViewVC Help
Powered by ViewVC 1.1.26