/[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 102 by jgs, Wed Dec 15 07:08:39 2004 UTC trunk/escript/src/DataTagged.cpp revision 1141 by gross, Tue May 15 04:24:51 2007 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"  
16    
17  #include <sstream>  #include "DataConstant.h"
18    #include "DataException.h"
19    #ifdef USE_NETCDF
20    #include "netcdfcpp.h"
21    #endif
22    
23  using namespace std;  using namespace std;
24    
25  namespace escript {  namespace escript {
26    
27  DataTagged::DataTagged():  DataTagged::DataTagged()
28    DataAbstract(FunctionSpace())    : DataAbstract(FunctionSpace())
29  {  {
30    //    // default constructor
31    
32    // create a scalar default value    // create a scalar default value
33    m_data.push_back(0.0);    m_data.resize(1,0.,1);
34    DataArrayView temp(m_data,DataArrayView::ShapeType());    DataArrayView temp(m_data,DataArrayView::ShapeType());
35    setPointDataView(temp);    setPointDataView(temp);
36  }  }
# Line 38  DataTagged::DataTagged(const TagListType Line 41  DataTagged::DataTagged(const TagListType
41                 const FunctionSpace& what)                 const FunctionSpace& what)
42    : DataAbstract(what)    : DataAbstract(what)
43  {  {
44    //    // constructor
45    // 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()) );    // initialise the array of data values
47      // the default value is always the first item in the values list
48      int len = defaultValue.noValues();
49      m_data.resize(len,0.,len);
50      for (int i=0; i<defaultValue.noValues(); i++) {
51        m_data[i]=defaultValue.getData(i);
52      }
53    
54      // create the data view
55    DataArrayView temp(m_data,defaultValue.getShape());    DataArrayView temp(m_data,defaultValue.getShape());
56    setPointDataView(temp);    setPointDataView(temp);
57    
58    // add remaining tags and values    // add remaining tags and values
59    addTaggedValues(tagKeys,values);    addTaggedValues(tagKeys,values);
60  }  }
61    
62    DataTagged::DataTagged(const FunctionSpace& what,
63                           const DataArrayView::ShapeType &shape,
64                           const int tags[],
65                           const ValueType& data)
66      : DataAbstract(what)
67    {
68      // alternative constructor
69      // not unit_tested tested yet
70    
71      // copy the data
72      m_data=data;
73    
74      // create the view of the data
75      DataArrayView tempView(m_data,shape);
76      setPointDataView(tempView);
77    
78      // create the tag lookup map
79      for (int sampleNo=0; sampleNo<getNumSamples(); sampleNo++) {
80        m_offsetLookup.insert(DataMapType::value_type(sampleNo,tags[sampleNo]));
81      }
82    }
83    
84    DataTagged::DataTagged(const FunctionSpace& what,
85                           const DataArrayView::ShapeType &shape,
86                           const TagListType& tags,
87                           const ValueType& data)
88      : DataAbstract(what)
89    {
90      // alternative constructor
91      // not unit_tested tested yet
92    
93      // copy the data
94      m_data=data;
95    
96      // create the view of the data
97      DataArrayView tempView(m_data,shape);
98      setPointDataView(tempView);
99    
100      // create the tag lookup map
101      for (int sampleNo=0; sampleNo<getNumSamples(); sampleNo++) {
102        m_offsetLookup.insert(DataMapType::value_type(sampleNo,tags[sampleNo]));
103      }
104    }
105    
106    
107  DataTagged::DataTagged(const DataTagged& other)  DataTagged::DataTagged(const DataTagged& other)
108    : DataAbstract(other.getFunctionSpace()),    : DataAbstract(other.getFunctionSpace()),
109    m_data(other.m_data),    m_data(other.m_data),
110    m_offsetLookup(other.m_offsetLookup)    m_offsetLookup(other.m_offsetLookup)
111  {  {
112      // copy constructor
113    
114      // create the data view
115    DataArrayView temp(m_data,other.getPointDataView().getShape());    DataArrayView temp(m_data,other.getPointDataView().getShape());
116    setPointDataView(temp);    setPointDataView(temp);
117  }  }
# Line 59  DataTagged::DataTagged(const DataTagged& Line 119  DataTagged::DataTagged(const DataTagged&
119  DataTagged::DataTagged(const DataConstant& other)  DataTagged::DataTagged(const DataConstant& other)
120    : DataAbstract(other.getFunctionSpace())    : DataAbstract(other.getFunctionSpace())
121  {  {
122    //    // copy constructor
123    // Fill the default value with the constant value item from other  
124      // fill the default value with the constant value item from "other"
125    const DataArrayView& value=other.getPointDataView();    const DataArrayView& value=other.getPointDataView();
126    m_data.insert(m_data.end(), &value.getData(0), &value.getData(value.noValues()) );    int len = value.noValues();
127      m_data.resize(len,0.,len);
128      for (int i=0; i<value.noValues(); i++) {
129        m_data[i]=value.getData(i);
130      }
131    
132      // create the data view
133    DataArrayView temp(m_data,value.getShape());    DataArrayView temp(m_data,value.getShape());
134    setPointDataView(temp);    setPointDataView(temp);
135  }  }
136    
137    DataAbstract*
138    DataTagged::getSlice(const DataArrayView::RegionType& region) const
139    {
140      return new DataTagged(*this, region);
141    }
142    
143  DataTagged::DataTagged(const DataTagged& other,  DataTagged::DataTagged(const DataTagged& other,
144                 const DataArrayView::RegionType& region)                 const DataArrayView::RegionType& region)
145    : DataAbstract(other.getFunctionSpace())    : DataAbstract(other.getFunctionSpace())
146  {  {
147    //    // slice constructor
148    
149    // get the shape of the slice to copy from other    // get the shape of the slice to copy from other
150    DataArrayView::ShapeType shape(DataArrayView::getResultSliceShape(region));    DataArrayView::ShapeType regionShape(DataArrayView::getResultSliceShape(region));
151    //    DataArrayView::RegionLoopRangeType regionLoopRange=getSliceRegionLoopRange(region);
152    // allocate enough space for all values  
153    m_data.resize(DataArrayView::noValues(shape)*(other.m_offsetLookup.size()+1));    // allocate enough space in this for all values
154    DataArrayView temp(m_data,shape);    // (need to add one to allow for the default value)
155      int len = DataArrayView::noValues(regionShape)*(other.m_offsetLookup.size()+1);
156      m_data.resize(len,0.0,len);
157    
158      // create the data view
159      DataArrayView temp(m_data,regionShape);
160    setPointDataView(temp);    setPointDataView(temp);
161    getDefaultValue().copySlice(other.getDefaultValue(),region);  
162    //    // copy the default value from other to this
163    // Loop through the tag values    getDefaultValue().copySlice(other.getDefaultValue(), regionLoopRange);
164    
165      // loop through the tag values copying these
166    DataMapType::const_iterator pos;    DataMapType::const_iterator pos;
167    DataArrayView::ValueType::size_type tagOffset=getPointDataView().noValues();    DataArrayView::ValueType::size_type tagOffset=getPointDataView().noValues();
168    for (pos=other.m_offsetLookup.begin();pos!=other.m_offsetLookup.end();++pos){    for (pos=other.m_offsetLookup.begin();pos!=other.m_offsetLookup.end();pos++){
169      getPointDataView().copySlice(tagOffset,other.getPointDataView(), pos->second,region);      getPointDataView().copySlice(tagOffset,other.getPointDataView(),pos->second,regionLoopRange);
170      m_offsetLookup.insert(DataMapType::value_type(pos->first,tagOffset));      m_offsetLookup.insert(DataMapType::value_type(pos->first,tagOffset));
171      tagOffset+=getPointDataView().noValues();      tagOffset+=getPointDataView().noValues();
   }  
 }  
   
 void  
 DataTagged::reshapeDataPoint(const DataArrayView::ShapeType& shape)  
 {  
   //  
   // can only reshape a rank zero data point  
   if (getPointDataView().getRank()!=0) {  
     stringstream temp;  
     temp << "Error - Can only reshape Data with data points of rank 0. "  
      << "This Data has data points with rank: "  
      << getPointDataView().getRank();  
     throw DataException(temp.str());  
   }  
   //  
   // allocate enough space for all values  
   DataArrayView::ValueType newData(DataArrayView::noValues(shape)*(m_offsetLookup.size()+1));  
   DataArrayView newView(newData,shape);  
   newView.copy(0,getDefaultValue()());  
   //  
   // Loop through the tag values  
   DataMapType::iterator pos;  
   DataArrayView::ValueType::size_type tagOffset=DataArrayView::noValues(shape);  
   for (pos=m_offsetLookup.begin();pos!=m_offsetLookup.end();++pos){  
     newView.copy(tagOffset,m_data[pos->second]);  
     pos->second=tagOffset;  
     tagOffset+=DataArrayView::noValues(shape);  
172    }    }
   m_data=newData;  
   DataArrayView temp(m_data,shape);  
   setPointDataView(temp);  
 }  
   
 DataAbstract*  
 DataTagged::getSlice(const DataArrayView::RegionType& region) const  
 {  
   return new DataTagged(*this,region);  
173  }  }
174    
175  void  void
176  DataTagged::setSlice(const DataAbstract* value,  DataTagged::setSlice(const DataAbstract* other,
177                       const DataArrayView::RegionType& region)                       const DataArrayView::RegionType& region)
178  {  {
179    const DataTagged* tempDataTag=dynamic_cast<const DataTagged*>(value);  
180    if (tempDataTag==0) {    // other must be another DataTagged object
181      // Data:setSlice implementation should ensure this
182      const DataTagged* otherTemp=dynamic_cast<const DataTagged*>(other);
183      if (otherTemp==0) {
184      throw DataException("Programming error - casting to DataTagged.");      throw DataException("Programming error - casting to DataTagged.");
185    }    }
186    
187      // determine shape of the specified region
188      DataArrayView::ShapeType regionShape(DataArrayView::getResultSliceShape(region));
189    
190      // modify region specification as needed to match rank of this object
191      DataArrayView::RegionLoopRangeType regionLoopRange=getSliceRegionLoopRange(region);
192    
193      // ensure rank/shape of this object is compatible with specified region
194    if (getPointDataView().getRank()!=region.size()) {    if (getPointDataView().getRank()!=region.size()) {
195      throw DataException("Error - Invalid slice region.");      throw DataException("Error - Invalid slice region.");
196    }    }
197    //    if (otherTemp->getPointDataView().getRank()>0 && !other->getPointDataView().checkShape(regionShape)) {
198    // get the shape of the slice      throw DataException (other->getPointDataView().createShapeErrorMessage(
199    DataArrayView::ShapeType shape(DataArrayView::getResultSliceShape(region));                           "Error - Couldn't copy slice due to shape mismatch.",regionShape));
   if (!value->getPointDataView().checkShape(shape)) {  
     throw DataException (value->getPointDataView().createShapeErrorMessage(  
                 "Error - Couldn't copy slice due to shape mismatch.",shape));  
200    }    }
201    //  
202    getDefaultValue().copySliceFrom(tempDataTag->getDefaultValue(),region);    // copy slice from other default value to this default value
203    //    getDefaultValue().copySliceFrom(otherTemp->getDefaultValue(), regionLoopRange);
204    // Loop through the tag values  
205      // loop through tag values in other, adding any which aren't in this, using default value
206    DataMapType::const_iterator pos;    DataMapType::const_iterator pos;
207    for (pos=m_offsetLookup.begin();pos!=m_offsetLookup.end();++pos){    for (pos=otherTemp->m_offsetLookup.begin();pos!=otherTemp->m_offsetLookup.end();pos++) {
208      getDataPointByTag(pos->first).copySliceFrom(tempDataTag->getDataPointByTag(pos->first),region);      if (!isCurrentTag(pos->first)) {
209    }        addTaggedValue(pos->first,getDefaultValue());
210        }
211      }
212    
213      // loop through the tag values copying slices from other to this
214      for (pos=m_offsetLookup.begin();pos!=m_offsetLookup.end();pos++) {
215        getDataPointByTag(pos->first).copySliceFrom(otherTemp->getDataPointByTag(pos->first), regionLoopRange);
216      }
217    
218  }  }
219    
220  void  int
221  DataTagged::setTaggedValue(int tagKey,  DataTagged::getTagNumber(int dpno)
                            const DataArrayView& value)  
222  {  {
223    DataMapType::iterator pos(m_offsetLookup.find(tagKey));    //
224    if (pos==m_offsetLookup.end()) {    // Get the number of samples and data-points per sample
225      //    int numSamples = getNumSamples();
226      // tag couldn't be found so add as a new tag    int numDataPointsPerSample = getNumDPPSample();
227      addTaggedValue(tagKey,value);    int numDataPoints = numSamples * numDataPointsPerSample;
228    } else {  
229      if (!getPointDataView().checkShape(value.getShape())) {    if (numDataPointsPerSample==0) {
230        throw DataException(getPointDataView().createShapeErrorMessage(      throw DataException("DataTagged::getTagNumber error: no data-points associated with this object.");
231           "Error - Cannot setTaggedValue due to shape mismatch.", value.getShape()));    }
232      }  
233      //    if (dpno<0 || dpno>numDataPoints-1) {
234      // copy the values into tagged data storage      throw DataException("DataTagged::getTagNumber error: invalid data-point number supplied.");
     copy(&value.getData(0), &value.getData(getPointDataView().noValues()), &m_data[pos->second]);  
235    }    }
236    
237      //
238      // Determine the sample number which corresponds to this data-point number
239      int sampleNo = dpno / numDataPointsPerSample;
240    
241      //
242      // Determine the tag number which corresponds to this sample number
243      int tagNo = getFunctionSpace().getTagFromSampleNo(sampleNo);
244    
245      //
246      // return the tag number
247      return(tagNo);
248  }  }
249    
250  void  void
251  DataTagged::setTaggedValues(const TagListType& tagKeys,  DataTagged::setTaggedValues(const TagListType& tagKeys,
252                              const ValueListType& values)                              const ValueListType& values)
253  {  {
254    for (int i=0;i<tagKeys.size();++i) {    addTaggedValues(tagKeys,values);
     setTaggedValue(tagKeys[i],values[i]);  
   }  
255  }  }
256    
257  void  void
258  DataTagged::addTaggedValue(int tagKey,  DataTagged::setTaggedValue(int tagKey,
259                             const DataArrayView& value)                             const DataArrayView& value)
260  {  {
261    if (!getPointDataView().checkShape(value.getShape())) {    if (!getPointDataView().checkShape(value.getShape())) {
262      throw DataException(getPointDataView().createShapeErrorMessage(        throw DataException(getPointDataView().createShapeErrorMessage(
263           "Error - Cannot addTaggedValue due to shape mismatch.", value.getShape()));                            "Error - Cannot setTaggedValue due to shape mismatch.", value.getShape()));
264      }
265      DataMapType::iterator pos(m_offsetLookup.find(tagKey));
266      if (pos==m_offsetLookup.end()) {
267        // tag couldn't be found so use addTaggedValue
268        addTaggedValue(tagKey,value);
269      } else {
270        // copy the values into the data array at the offset determined by m_offsetLookup
271        int offset=pos->second;
272        for (int i=0; i<getPointDataView().noValues(); i++) {
273          m_data[offset+i]=value.getData(i);
274        }
275    }    }
   //  
   // 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())) );  
276  }  }
277    
278  void  void
# Line 206  DataTagged::addTaggedValues(const TagLis Line 280  DataTagged::addTaggedValues(const TagLis
280                              const ValueListType& values)                              const ValueListType& values)
281  {  {
282    if (values.size()==0) {    if (values.size()==0) {
283      //      // copy the current default value for each of the tags
     // Copy the default value for each of the tags  
284      TagListType::const_iterator iT;      TagListType::const_iterator iT;
285      for (iT=tagKeys.begin();iT!=tagKeys.end();++iT) {      for (iT=tagKeys.begin();iT!=tagKeys.end();iT++) {
       //  
286        // the point data view for DataTagged points at the default value        // the point data view for DataTagged points at the default value
287        addTaggedValue(*iT,getPointDataView());        addTaggedValue(*iT,getPointDataView());
288      }      }
289    } else if (values.size()==1 && tagKeys.size()>1) {    } else if (values.size()==1 && tagKeys.size()>1) {
290      //      // 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  
291      TagListType::const_iterator iT;      TagListType::const_iterator iT;
292      for (iT=tagKeys.begin();iT!=tagKeys.end();++iT) {      for (iT=tagKeys.begin();iT!=tagKeys.end();iT++) {
293        addTaggedValue(*iT,values[0]);        addTaggedValue(*iT,values[0]);
294      }      }
295    } else {    } else {
296      if (tagKeys.size()!=values.size()) {      if (tagKeys.size()!=values.size()) {
297        stringstream temp;        stringstream temp;
298        temp << "Error - (addTaggedValue) Number of tags: " << tagKeys.size()        temp << "Error - (addTaggedValue) Number of tags: " << tagKeys.size()
299         << " doesn't match the number of values: " << values.size();         << " doesn't match number of values: " << values.size();
300        throw DataException(temp.str());        throw DataException(temp.str());
301      } else {      } else {
302        for (int i=0;i<tagKeys.size();++i) {        for (int i=0;i<tagKeys.size();i++) {
303          addTaggedValue(tagKeys[i],values[i]);          addTaggedValue(tagKeys[i],values[i]);
304        }        }
305      }      }
306    }    }
307  }  }
308    
309    void
310    DataTagged::addTaggedValue(int tagKey,
311                               const DataArrayView& value)
312    {
313      if (!getPointDataView().checkShape(value.getShape())) {
314        throw DataException(getPointDataView().createShapeErrorMessage(
315                            "Error - Cannot addTaggedValue due to shape mismatch.", value.getShape()));
316      }
317      DataMapType::iterator pos(m_offsetLookup.find(tagKey));
318      if (pos!=m_offsetLookup.end()) {
319        // tag already exists so use setTaggedValue
320        setTaggedValue(tagKey,value);
321      } else {
322        // save the key and the location of its data in the lookup tab
323        m_offsetLookup.insert(DataMapType::value_type(tagKey,m_data.size()));
324        // add the data given in "value" at the end of m_data
325        // need to make a temp copy of m_data, resize m_data, then copy
326        // all the old values plus the value to be added back into m_data
327        ValueType m_data_temp(m_data);
328        int oldSize=m_data.size();
329        int newSize=m_data.size()+value.noValues();
330        m_data.resize(newSize,0.,newSize);
331        for (int i=0;i<oldSize;i++) {
332          m_data[i]=m_data_temp[i];
333        }
334        for (int i=0;i<value.noValues();i++) {
335          m_data[oldSize+i]=value.getData(i);
336        }
337      }
338    }
339    
340  double*  double*
341  DataTagged::getSampleDataByTag(int tag)  DataTagged::getSampleDataByTag(int tag)
342  {  {
343    DataMapType::iterator pos(m_offsetLookup.find(tag));    DataMapType::iterator pos(m_offsetLookup.find(tag));
344    if (pos==m_offsetLookup.end()) {    if (pos==m_offsetLookup.end()) {
     //  
345      // tag couldn't be found so return the default value      // tag couldn't be found so return the default value
346      return &(m_data[0]);      return &(m_data[0]);
347    } else {    } else {
     //  
348      // return the data-point corresponding to the given tag      // return the data-point corresponding to the given tag
349      return &(m_data[pos->second]);      return &(m_data[pos->second]);
350    }    }
# Line 258  DataTagged::toString() const Line 357  DataTagged::toString() const
357    DataMapType::const_iterator i;    DataMapType::const_iterator i;
358    temp << "Tag(Default)" << endl;    temp << "Tag(Default)" << endl;
359    temp << getDefaultValue().toString() << endl;    temp << getDefaultValue().toString() << endl;
   //  
360    // create a temporary view as the offset will be changed    // create a temporary view as the offset will be changed
361    DataArrayView tempView(getPointDataView().getData(), getPointDataView().getShape());    DataArrayView tempView(getPointDataView().getData(), getPointDataView().getShape());
362    for (i=m_offsetLookup.begin();i!=m_offsetLookup.end();++i) {    for (i=m_offsetLookup.begin();i!=m_offsetLookup.end();++i) {
# Line 266  DataTagged::toString() const Line 364  DataTagged::toString() const
364      tempView.setOffset(i->second);      tempView.setOffset(i->second);
365      temp << tempView.toString() << endl;      temp << tempView.toString() << endl;
366    }    }
367    return temp.str();    return string(temp.str());
368  }  }
369    
370  DataArrayView  DataArrayView::ValueType::size_type
371  DataTagged::getDataPointByTag(int tag) const  DataTagged::getPointOffset(int sampleNo,
372                               int dataPointNo) const
373  {  {
374    DataMapType::const_iterator pos(m_offsetLookup.find(tag));    int tagKey=getFunctionSpace().getTagFromSampleNo(sampleNo);
375      DataMapType::const_iterator pos(m_offsetLookup.find(tagKey));
376    DataArrayView::ValueType::size_type offset=m_defaultValueOffset;    DataArrayView::ValueType::size_type offset=m_defaultValueOffset;
377    if (pos!=m_offsetLookup.end()) {    if (pos!=m_offsetLookup.end()) {
378      offset=pos->second;      offset=pos->second;
379    }    }
380    DataArrayView temp(getPointDataView());    return offset;
   temp.setOffset(offset);  
   return temp;  
381  }  }
382    
383  DataArrayView::ValueType::size_type  DataArrayView
384  DataTagged::getPointOffset(int sampleNo,  DataTagged::getDataPointByTag(int tag) const
                            int dataPointNo) const  
385  {  {
386    int tagKey=getFunctionSpace().getTagFromSampleNo(sampleNo);    DataMapType::const_iterator pos(m_offsetLookup.find(tag));
   DataMapType::const_iterator pos(m_offsetLookup.find(tagKey));  
387    DataArrayView::ValueType::size_type offset=m_defaultValueOffset;    DataArrayView::ValueType::size_type offset=m_defaultValueOffset;
388    if (pos!=m_offsetLookup.end()) {    if (pos!=m_offsetLookup.end()) {
389      offset=pos->second;      offset=pos->second;
390    }    }
391    return offset;    DataArrayView temp(getPointDataView());
392      temp.setOffset(offset);
393      return temp;
394  }  }
395    
396  DataArrayView  DataArrayView
# Line 304  DataTagged::getDataPoint(int sampleNo, Line 402  DataTagged::getDataPoint(int sampleNo,
402    return getDataPointByTag(tagKey);    return getDataPointByTag(tagKey);
403  }  }
404    
405  const DataTagged::DataMapType&  int
406  DataTagged::getTagLookup() const  DataTagged::archiveData(ofstream& archiveFile,
407                            const DataArrayView::ValueType::size_type noValues) const
408  {  {
409    return m_offsetLookup;    return(m_data.archiveData(archiveFile, noValues));
410  }  }
411    
412  DataArrayView::ValueType::size_type  int
413  DataTagged::getLength() const  DataTagged::extractData(ifstream& archiveFile,
414                            const DataArrayView::ValueType::size_type noValues)
415    {
416      return(m_data.extractData(archiveFile, noValues));
417    }
418    void
419    DataTagged::symmetric(DataAbstract* ev)
420  {  {
421    return m_data.size();    DataTagged* temp_ev=dynamic_cast<DataTagged*>(ev);
422      if (temp_ev==0) {
423        throw DataException("Error - DataTagged::symmetric casting to DataTagged failed (probably a programming error).");
424      }
425      const DataTagged::DataMapType& thisLookup=getTagLookup();
426      DataTagged::DataMapType::const_iterator i;
427      DataTagged::DataMapType::const_iterator thisLookupEnd=thisLookup.end();
428      for (i=thisLookup.begin();i!=thisLookupEnd;i++) {
429          temp_ev->addTaggedValue(i->first,temp_ev->getDefaultValue());
430          DataArrayView thisView=getDataPointByTag(i->first);
431          DataArrayView evView=temp_ev->getDataPointByTag(i->first);
432          DataArrayView::symmetric(thisView,0,evView,0);
433      }
434      DataArrayView::symmetric(getDefaultValue(),0,temp_ev->getDefaultValue(),0);
435    }
436    void
437    DataTagged::nonsymmetric(DataAbstract* ev)
438    {
439      DataTagged* temp_ev=dynamic_cast<DataTagged*>(ev);
440      if (temp_ev==0) {
441        throw DataException("Error - DataTagged::nonsymmetric casting to DataTagged failed (probably a programming error).");
442      }
443      const DataTagged::DataMapType& thisLookup=getTagLookup();
444      DataTagged::DataMapType::const_iterator i;
445      DataTagged::DataMapType::const_iterator thisLookupEnd=thisLookup.end();
446      for (i=thisLookup.begin();i!=thisLookupEnd;i++) {
447          temp_ev->addTaggedValue(i->first,temp_ev->getDefaultValue());
448          DataArrayView thisView=getDataPointByTag(i->first);
449          DataArrayView evView=temp_ev->getDataPointByTag(i->first);
450          DataArrayView::nonsymmetric(thisView,0,evView,0);
451      }
452      DataArrayView::nonsymmetric(getDefaultValue(),0,temp_ev->getDefaultValue(),0);
453    }
454    void
455    DataTagged::trace(DataAbstract* ev, int axis_offset)
456    {
457      DataTagged* temp_ev=dynamic_cast<DataTagged*>(ev);
458      if (temp_ev==0) {
459        throw DataException("Error - DataTagged::trace casting to DataTagged failed (probably a programming error).");
460      }
461      const DataTagged::DataMapType& thisLookup=getTagLookup();
462      DataTagged::DataMapType::const_iterator i;
463      DataTagged::DataMapType::const_iterator thisLookupEnd=thisLookup.end();
464      for (i=thisLookup.begin();i!=thisLookupEnd;i++) {
465          temp_ev->addTaggedValue(i->first,temp_ev->getDefaultValue());
466          DataArrayView thisView=getDataPointByTag(i->first);
467          DataArrayView evView=temp_ev->getDataPointByTag(i->first);
468          DataArrayView::trace(thisView,0,evView,0, axis_offset);
469      }
470      DataArrayView::trace(getDefaultValue(),0,temp_ev->getDefaultValue(),0,axis_offset);
471  }  }
472    
473    void
474    DataTagged::transpose(DataAbstract* ev, int axis_offset)
475    {
476      DataTagged* temp_ev=dynamic_cast<DataTagged*>(ev);
477      if (temp_ev==0) {
478        throw DataException("Error - DataTagged::transpose casting to DataTagged failed (probably a programming error).");
479      }
480      const DataTagged::DataMapType& thisLookup=getTagLookup();
481      DataTagged::DataMapType::const_iterator i;
482      DataTagged::DataMapType::const_iterator thisLookupEnd=thisLookup.end();
483      for (i=thisLookup.begin();i!=thisLookupEnd;i++) {
484          temp_ev->addTaggedValue(i->first,temp_ev->getDefaultValue());
485          DataArrayView thisView=getDataPointByTag(i->first);
486          DataArrayView evView=temp_ev->getDataPointByTag(i->first);
487          DataArrayView::transpose(thisView,0,evView,0, axis_offset);
488      }
489      DataArrayView::transpose(getDefaultValue(),0,temp_ev->getDefaultValue(),0,axis_offset);
490    }
491    
492    void
493    DataTagged::swapaxes(DataAbstract* ev, int axis0, int axis1)
494    {
495      DataTagged* temp_ev=dynamic_cast<DataTagged*>(ev);
496      if (temp_ev==0) {
497        throw DataException("Error - DataTagged::swapaxes casting to DataTagged failed (probably a programming error).");
498      }
499      const DataTagged::DataMapType& thisLookup=getTagLookup();
500      DataTagged::DataMapType::const_iterator i;
501      DataTagged::DataMapType::const_iterator thisLookupEnd=thisLookup.end();
502      for (i=thisLookup.begin();i!=thisLookupEnd;i++) {
503          temp_ev->addTaggedValue(i->first,temp_ev->getDefaultValue());
504          DataArrayView thisView=getDataPointByTag(i->first);
505          DataArrayView evView=temp_ev->getDataPointByTag(i->first);
506          DataArrayView::swapaxes(thisView,0,evView,0,axis0,axis1);
507      }
508      DataArrayView::swapaxes(getDefaultValue(),0,temp_ev->getDefaultValue(),0,axis0,axis1);
509    }
510    
511    void
512    DataTagged::eigenvalues(DataAbstract* ev)
513    {
514      DataTagged* temp_ev=dynamic_cast<DataTagged*>(ev);
515      if (temp_ev==0) {
516        throw DataException("Error - DataTagged::eigenvalues casting to DataTagged failed (propably a programming error).");
517      }
518      const DataTagged::DataMapType& thisLookup=getTagLookup();
519      DataTagged::DataMapType::const_iterator i;
520      DataTagged::DataMapType::const_iterator thisLookupEnd=thisLookup.end();
521      for (i=thisLookup.begin();i!=thisLookupEnd;i++) {
522          temp_ev->addTaggedValue(i->first,temp_ev->getDefaultValue());
523          DataArrayView thisView=getDataPointByTag(i->first);
524          DataArrayView evView=temp_ev->getDataPointByTag(i->first);
525          DataArrayView::eigenvalues(thisView,0,evView,0);
526      }
527      DataArrayView::eigenvalues(getDefaultValue(),0,temp_ev->getDefaultValue(),0);
528    }
529    void
530    DataTagged::eigenvalues_and_eigenvectors(DataAbstract* ev,DataAbstract* V,const double tol)
531    {
532      DataTagged* temp_ev=dynamic_cast<DataTagged*>(ev);
533      if (temp_ev==0) {
534        throw DataException("Error - DataTagged::eigenvalues_and_eigenvectors casting to DataTagged failed (propably a programming error).");
535      }
536      DataTagged* temp_V=dynamic_cast<DataTagged*>(V);
537      if (temp_V==0) {
538        throw DataException("Error - DataTagged::eigenvalues_and_eigenvectors casting to DataTagged failed (propably a programming error).");
539      }
540      const DataTagged::DataMapType& thisLookup=getTagLookup();
541      DataTagged::DataMapType::const_iterator i;
542      DataTagged::DataMapType::const_iterator thisLookupEnd=thisLookup.end();
543      for (i=thisLookup.begin();i!=thisLookupEnd;i++) {
544          temp_ev->addTaggedValue(i->first,temp_ev->getDefaultValue());
545          temp_V->addTaggedValue(i->first,temp_V->getDefaultValue());
546          DataArrayView thisView=getDataPointByTag(i->first);
547          DataArrayView evView=temp_ev->getDataPointByTag(i->first);
548          DataArrayView VView=temp_V->getDataPointByTag(i->first);
549          DataArrayView::eigenvalues_and_eigenvectors(thisView,0,evView,0,VView,0,tol);
550      }
551      DataArrayView::eigenvalues_and_eigenvectors(getDefaultValue(),0,
552                                                  temp_ev->getDefaultValue(),0,
553                                                  temp_V->getDefaultValue(),0,
554                                                  tol);
555    
556    
557    }
558    
559    void
560    DataTagged::setToZero(){
561        DataArrayView::ValueType::size_type n=m_data.size();
562        for (int i=0; i<n ;++i) m_data[i]=0.;
563    }
564    
565    void
566    DataTagged::dump(const std::string fileName) const
567    {
568       #ifdef PASO_MPI
569       throw DataException("Error - DataTagged:: dump is not implemented for MPI yet.")
570       #endif
571       #ifdef USE_NETCDF
572       const int ldims=DataArrayView::maxRank+1;
573       const NcDim* ncdims[ldims];
574       NcVar *var, *tags_var;
575       int rank = getPointDataView().getRank();
576       int type=  getFunctionSpace().getTypeCode();
577       int ndims =0;
578       long dims[ldims];
579       const double* d_ptr=&(m_data[0]);
580       DataArrayView::ShapeType shape = getPointDataView().getShape();
581    
582       // netCDF error handler
583       NcError err(NcError::verbose_nonfatal);
584       // Create the file.
585       NcFile dataFile(fileName.c_str(), NcFile::Replace);
586       // check if writing was successful
587       if (!dataFile.is_valid())
588            throw DataException("Error - DataTagged:: opening of netCDF file for output failed.");
589       if (!dataFile.add_att("type_id",1) )
590            throw DataException("Error - DataTagged:: appending data type to netCDF file failed.");
591       if (!dataFile.add_att("rank",rank) )
592            throw DataException("Error - DataTagged:: appending rank attribute to netCDF file failed.");
593       if (!dataFile.add_att("function_space_type",type))
594            throw DataException("Error - DataTagged:: appending function space attribute to netCDF file failed.");
595       ndims=rank+1;
596       if ( rank >0 ) {
597           dims[0]=shape[0];
598           if (! (ncdims[0] = dataFile.add_dim("d0",shape[0])) )
599                throw DataException("Error - DataTagged:: appending ncdimsion 0 to netCDF file failed.");
600       }
601       if ( rank >1 ) {
602           dims[1]=shape[1];
603           if (! (ncdims[1] = dataFile.add_dim("d1",shape[1])) )
604                throw DataException("Error - DataTagged:: appending ncdimsion 1 to netCDF file failed.");
605       }
606       if ( rank >2 ) {
607           dims[2]=shape[2];
608           if (! (ncdims[2] = dataFile.add_dim("d2", shape[2])) )
609                throw DataException("Error - DataTagged:: appending ncdimsion 2 to netCDF file failed.");
610       }
611       if ( rank >3 ) {
612           dims[3]=shape[3];
613           if (! (ncdims[3] = dataFile.add_dim("d3", shape[3])) )
614                throw DataException("Error - DataTagged:: appending ncdimsion 3 to netCDF file failed.");
615       }
616       const DataTagged::DataMapType& thisLookup=getTagLookup();
617       DataTagged::DataMapType::const_iterator i;
618       DataTagged::DataMapType::const_iterator thisLookupEnd=thisLookup.end();
619       int ntags=1;
620       for (i=thisLookup.begin();i!=thisLookupEnd;i++) ntags++;
621       int* tags =(int*) malloc(ntags*sizeof(int));
622       int c=1;
623       tags[0]=-1;
624       for (i=thisLookup.begin();i!=thisLookupEnd;i++) tags[c++]=i->first;
625       dims[rank]=ntags;
626       if (! (ncdims[rank] = dataFile.add_dim("num_tags", dims[rank])) )
627       {
628           free(tags);
629               throw DataException("Error - DataTagged:: appending num_tags to netCDF file failed.");
630       }
631       if (! ( tags_var = dataFile.add_var("tags", ncInt, ncdims[rank])) )
632       {
633        free(tags);
634            throw DataException("Error - DataTagged:: appending tags to netCDF file failed.");
635       }
636       if (! (tags_var->put(tags,dims[rank])) )
637       {
638        free(tags);
639            throw DataException("Error - DataTagged:: copy tags to netCDF buffer failed.");
640       }
641       if (! ( var = dataFile.add_var("data", ncDouble, ndims, ncdims)) )
642       {
643        free(tags);
644            throw DataException("Error - DataTagged:: appending variable to netCDF file failed.");
645       }
646       if (! (var->put(d_ptr,dims)) )
647       {
648        free(tags);
649            throw DataException("Error - DataTagged:: copy data to netCDF buffer failed.");
650       }
651       #else
652       throw DataException("Error - DataTagged:: dump is not configured with netCDF. Please contact your installation manager.");
653       #endif
654    }
655  }  // end of namespace  }  // end of namespace

Legend:
Removed from v.102  
changed lines
  Added in v.1141

  ViewVC Help
Powered by ViewVC 1.1.26