/[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 2211 by jfenwick, Fri Jan 9 01:28:32 2009 UTC revision 2212 by jfenwick, Wed Jan 14 00:15:00 2009 UTC
# Line 26  Line 26 
26  #endif  #endif
27  #include "DataMaths.h"  #include "DataMaths.h"
28    
29    
30    #define CHECK_FOR_EX_WRITE if (!checkNoSharing()) {throw DataException("Attempt to modify shared object");}
31    
32    // #define CHECK_FOR_EX_WRITE if (!checkNoSharing()) {std::ostringstream ss; ss << " Attempt to modify shared object. line " << __LINE__ << " of " << __FILE__; throw DataException(ss.str());}
33    
34  using namespace std;  using namespace std;
35    
36  namespace escript {  namespace escript {
# Line 279  DataTagged::setSlice(const DataAbstract* Line 284  DataTagged::setSlice(const DataAbstract*
284      throw DataException("Programming error - casting to DataTagged.");      throw DataException("Programming error - casting to DataTagged.");
285    }    }
286    
287      CHECK_FOR_EX_WRITE
288    
289    // determine shape of the specified region    // determine shape of the specified region
290    DataTypes::ShapeType regionShape(DataTypes::getResultSliceShape(region));    DataTypes::ShapeType regionShape(DataTypes::getResultSliceShape(region));
291    
# Line 347  DataTagged::getTagNumber(int dpno) Line 354  DataTagged::getTagNumber(int dpno)
354    return(tagNo);    return(tagNo);
355  }  }
356    
 // void  
 // DataTagged::setTaggedValues(const TagListType& tagKeys,  
 //                             const ValueListType& values)  
 // {  
 //   addTaggedValues(tagKeys,values);  
 // }  
   
357  void  void
358  DataTagged::setTaggedValue(int tagKey,  DataTagged::setTaggedValue(int tagKey,
359                 const DataTypes::ShapeType& pointshape,                 const DataTypes::ShapeType& pointshape,
# Line 364  DataTagged::setTaggedValue(int tagKey, Line 364  DataTagged::setTaggedValue(int tagKey,
364        throw DataException(DataTypes::createShapeErrorMessage(        throw DataException(DataTypes::createShapeErrorMessage(
365                            "Error - Cannot setTaggedValue due to shape mismatch.", pointshape,getShape()));                            "Error - Cannot setTaggedValue due to shape mismatch.", pointshape,getShape()));
366    }    }
367      CHECK_FOR_EX_WRITE
368    DataMapType::iterator pos(m_offsetLookup.find(tagKey));    DataMapType::iterator pos(m_offsetLookup.find(tagKey));
369    if (pos==m_offsetLookup.end()) {    if (pos==m_offsetLookup.end()) {
370      // tag couldn't be found so use addTaggedValue      // tag couldn't be found so use addTaggedValue
# Line 378  DataTagged::setTaggedValue(int tagKey, Line 379  DataTagged::setTaggedValue(int tagKey,
379  }  }
380    
381    
 /*  
 void  
 DataTagged::setTaggedValue(int tagKey,  
                            const DataArrayView& value)  
 {  
   if (!getPointDataView().checkShape(value.getShape())) {  
       throw DataException(DataTypes::createShapeErrorMessage(  
                           "Error - Cannot setTaggedValue due to shape mismatch.", value.getShape(),getShape()));  
   }  
   DataMapType::iterator pos(m_offsetLookup.find(tagKey));  
   if (pos==m_offsetLookup.end()) {  
     // tag couldn't be found so use addTaggedValue  
     addTaggedValue(tagKey,value);  
   } else {  
     // copy the values into the data array at the offset determined by m_offsetLookup  
     int offset=pos->second;  
     for (int i=0; i<getPointDataView().noValues(); i++) {  
       m_data[offset+i]=value.getData(i);  
     }  
   }  
 }*/  
   
 // void  
 // DataTagged::addTaggedValues(const TagListType& tagKeys,  
 //                             const ValueListType& values)  
 // {  
 //   if (values.size()==0) {  
 //     // copy the current 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 given 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 number of values: " << values.size();  
 //       throw DataException(temp.str());  
 //     } else {  
 //       unsigned int i;  
 //       for (i=0;i<tagKeys.size();i++) {  
 //         addTaggedValue(tagKeys[i],values[i]);  
 //       }  
 //     }  
 //   }  
 // }  
   
   
382  void  void
383  DataTagged::addTaggedValues(const TagListType& tagKeys,  DataTagged::addTaggedValues(const TagListType& tagKeys,
384                              const ValueBatchType& values,                              const ValueBatchType& values,
# Line 497  DataTagged::addTaggedValue(int tagKey, Line 443  DataTagged::addTaggedValue(int tagKey,
443      throw DataException(DataTypes::createShapeErrorMessage(      throw DataException(DataTypes::createShapeErrorMessage(
444                          "Error - Cannot addTaggedValue due to shape mismatch.", pointshape,getShape()));                          "Error - Cannot addTaggedValue due to shape mismatch.", pointshape,getShape()));
445    }    }
446      CHECK_FOR_EX_WRITE
447    DataMapType::iterator pos(m_offsetLookup.find(tagKey));    DataMapType::iterator pos(m_offsetLookup.find(tagKey));
448    if (pos!=m_offsetLookup.end()) {    if (pos!=m_offsetLookup.end()) {
449      // tag already exists so use setTaggedValue      // tag already exists so use setTaggedValue
# Line 520  DataTagged::addTaggedValue(int tagKey, Line 467  DataTagged::addTaggedValue(int tagKey,
467    }    }
468  }  }
469    
   
   
   
 // void  
 // DataTagged::addTaggedValue(int tagKey,  
 //                            const DataArrayView& value)  
 // {  
 //   if (!getPointDataView().checkShape(value.getShape())) {  
 //     throw DataException(DataTypes::createShapeErrorMessage(  
 //                         "Error - Cannot addTaggedValue due to shape mismatch.", value.getShape(),getShape()));  
 //   }  
 //   DataMapType::iterator pos(m_offsetLookup.find(tagKey));  
 //   if (pos!=m_offsetLookup.end()) {  
 //     // tag already exists so use setTaggedValue  
 //     setTaggedValue(tagKey,value);  
 //   } else {  
 //     // save the key and the location of its data in the lookup tab  
 //     m_offsetLookup.insert(DataMapType::value_type(tagKey,m_data.size()));  
 //     // add the data given in "value" at the end of m_data  
 //     // need to make a temp copy of m_data, resize m_data, then copy  
 //     // all the old values plus the value to be added back into m_data  
 //     ValueType m_data_temp(m_data);  
 //     int oldSize=m_data.size();  
 //     int newSize=m_data.size()+value.noValues();  
 //     m_data.resize(newSize,0.,newSize);  
 //     for (int i=0;i<oldSize;i++) {  
 //       m_data[i]=m_data_temp[i];  
 //     }  
 //     for (int i=0;i<value.noValues();i++) {  
 //       m_data[oldSize+i]=value.getData(i);  
 //     }  
 //   }  
 // }  
   
   
470  void  void
471  DataTagged::addTag(int tagKey)  DataTagged::addTag(int tagKey)
472  {  {
473      CHECK_FOR_EX_WRITE
474    DataMapType::iterator pos(m_offsetLookup.find(tagKey));    DataMapType::iterator pos(m_offsetLookup.find(tagKey));
475    if (pos!=m_offsetLookup.end()) {    if (pos!=m_offsetLookup.end()) {
476      // tag already exists so use setTaggedValue      // tag already exists so use setTaggedValue
# Line 585  DataTagged::addTag(int tagKey) Line 498  DataTagged::addTag(int tagKey)
498  double*  double*
499  DataTagged::getSampleDataByTag(int tag)  DataTagged::getSampleDataByTag(int tag)
500  {  {
501      CHECK_FOR_EX_WRITE
502    DataMapType::iterator pos(m_offsetLookup.find(tag));    DataMapType::iterator pos(m_offsetLookup.find(tag));
503    if (pos==m_offsetLookup.end()) {    if (pos==m_offsetLookup.end()) {
504      // tag couldn't be found so return the default value      // tag couldn't be found so return the default value
# Line 676  DataTagged::getDataByTag(int tag, DataTy Line 590  DataTagged::getDataByTag(int tag, DataTy
590      offset=pos->second;      offset=pos->second;
591    }    }
592    return m_data[offset+i];    return m_data[offset+i];
593  /*  DataArrayView temp(getPointDataView());  }
594    temp.setOffset(offset);  
595    return temp.getData()[offset+i];*/  DataTypes::ValueType::const_reference
596    DataTagged::getDataByTagRO(int tag, DataTypes::ValueType::size_type i) const
597    {
598      DataMapType::const_iterator pos(m_offsetLookup.find(tag));
599      DataTypes::ValueType::size_type offset=m_defaultValueOffset;
600      if (pos!=m_offsetLookup.end()) {
601        offset=pos->second;
602      }
603      return m_data[offset+i];
604  }  }
605    
606    
607  DataTypes::ValueType::reference  DataTypes::ValueType::reference
608  DataTagged::getDataByTag(int tag, DataTypes::ValueType::size_type i)  DataTagged::getDataByTag(int tag, DataTypes::ValueType::size_type i)
609  {  {
610      CHECK_FOR_EX_WRITE
611    DataMapType::const_iterator pos(m_offsetLookup.find(tag));    DataMapType::const_iterator pos(m_offsetLookup.find(tag));
612    DataTypes::ValueType::size_type offset=m_defaultValueOffset;    DataTypes::ValueType::size_type offset=m_defaultValueOffset;
613    if (pos!=m_offsetLookup.end()) {    if (pos!=m_offsetLookup.end()) {
614      offset=pos->second;      offset=pos->second;
615    }    }
616    return m_data[offset+i];    return m_data[offset+i];
 /*  DataArrayView temp(getPointDataView());  
   temp.setOffset(offset);  
   return temp.getData()[offset+i];*/  
617  }  }
618    
   
   
   
   
   
 // DataArrayView  
 // DataTagged::getDataPoint(int sampleNo,  
 //                          int dataPointNo)  
 // {  
 //   EsysAssert(validSampleNo(sampleNo),"(getDataPoint) Invalid sampleNo: " << sampleNo);  
 //   int tagKey=getFunctionSpace().getTagFromSampleNo(sampleNo);  
 //   return getDataPointByTag(tagKey);  
 // }  
   
   
619  void  void
620  DataTagged::symmetric(DataAbstract* ev)  DataTagged::symmetric(DataAbstract* ev)
621  {  {
# Line 893  DataTagged::eigenvalues_and_eigenvectors Line 798  DataTagged::eigenvalues_and_eigenvectors
798    
799  void  void
800  DataTagged::setToZero(){  DataTagged::setToZero(){
801        CHECK_FOR_EX_WRITE
802      DataTypes::ValueType::size_type n=m_data.size();      DataTypes::ValueType::size_type n=m_data.size();
803      for (int i=0; i<n ;++i) m_data[i]=0.;      for (int i=0; i<n ;++i) m_data[i]=0.;
804  }  }
# Line 1002  DataTagged::dump(const std::string fileN Line 908  DataTagged::dump(const std::string fileN
908  DataTypes::ValueType&  DataTypes::ValueType&
909  DataTagged::getVector()  DataTagged::getVector()
910  {  {
911        CHECK_FOR_EX_WRITE
912      return m_data;      return m_data;
913  }  }
914    
915  const DataTypes::ValueType&  const DataTypes::ValueType&
916  DataTagged::getVector() const  DataTagged::getVector() const
917  {  {
918        // exclusive write not required for const access
919      return m_data;      return m_data;
920  }  }
921    
922    const DataTypes::ValueType&
923    DataTagged::getVectorRO() const
924    {
925        return m_data;
926    }
927    
928  }  // end of namespace  }  // end of namespace

Legend:
Removed from v.2211  
changed lines
  Added in v.2212

  ViewVC Help
Powered by ViewVC 1.1.26