/[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 509 by jgs, Fri Feb 10 03:24:44 2006 UTC revision 594 by gross, Tue Mar 14 23:36:08 2006 UTC
# Line 110  DataTagged::DataTagged(const DataConstan Line 110  DataTagged::DataTagged(const DataConstan
110    setPointDataView(temp);    setPointDataView(temp);
111  }  }
112    
 DataTagged::DataTagged(const DataTagged& other,  
                const DataArrayView::RegionType& region)  
   : DataAbstract(other.getFunctionSpace())  
 {  
   // slice constructor  
   
   // 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  
   int len = DataArrayView::noValues(shape)*(other.m_offsetLookup.size()+1);  
   m_data.resize(len,0.,len);  
   
   // create the data view  
   DataArrayView temp(m_data,shape);  
   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();  
   }  
 }  
   
113  void  void
114  DataTagged::reshapeDataPoint(const DataArrayView::ShapeType& shape)  DataTagged::reshapeDataPoint(const DataArrayView::ShapeType& shape)
115  {  {
# Line 174  DataTagged::reshapeDataPoint(const DataA Line 143  DataTagged::reshapeDataPoint(const DataA
143  DataAbstract*  DataAbstract*
144  DataTagged::getSlice(const DataArrayView::RegionType& region) const  DataTagged::getSlice(const DataArrayView::RegionType& region) const
145  {  {
146    return new DataTagged(*this,region);    return new DataTagged(*this, region);
147    }
148    
149    DataTagged::DataTagged(const DataTagged& other,
150                   const DataArrayView::RegionType& region)
151      : DataAbstract(other.getFunctionSpace())
152    {
153      // slice constructor
154    
155      // get the shape of the slice to copy from other
156      DataArrayView::ShapeType regionShape(DataArrayView::getResultSliceShape(region));
157      DataArrayView::RegionLoopRangeType regionLoopRange=getSliceRegionLoopRange(region);
158    
159      // allocate enough space in this for all values
160      // (need to add one to allow for the default value)
161      int len = DataArrayView::noValues(regionShape)*(other.m_offsetLookup.size()+1);
162      m_data.resize(len,0.0,len);
163    
164      // create the data view
165      DataArrayView temp(m_data,regionShape);
166      setPointDataView(temp);
167    
168      // copy the default value from other to this
169      getDefaultValue().copySlice(other.getDefaultValue(), regionLoopRange);
170    
171      // loop through the tag values copying these
172      DataMapType::const_iterator pos;
173      DataArrayView::ValueType::size_type tagOffset=getPointDataView().noValues();
174      for (pos=other.m_offsetLookup.begin();pos!=other.m_offsetLookup.end();pos++){
175        getPointDataView().copySlice(tagOffset,other.getPointDataView(),pos->second,regionLoopRange);
176        m_offsetLookup.insert(DataMapType::value_type(pos->first,tagOffset));
177        tagOffset+=getPointDataView().noValues();
178      }
179  }  }
180    
181  void  void
182  DataTagged::setSlice(const DataAbstract* value,  DataTagged::setSlice(const DataAbstract* other,
183                       const DataArrayView::RegionType& region)                       const DataArrayView::RegionType& region)
184  {  {
185    const DataTagged* tempDataTag=dynamic_cast<const DataTagged*>(value);  
186    if (tempDataTag==0) {    // other must be another DataTagged object
187      // Data:setSlice implementation should ensure this
188      const DataTagged* otherTemp=dynamic_cast<const DataTagged*>(other);
189      if (otherTemp==0) {
190      throw DataException("Programming error - casting to DataTagged.");      throw DataException("Programming error - casting to DataTagged.");
191    }    }
192    
193    DataArrayView::ShapeType shape(DataArrayView::getResultSliceShape(region));    // determine shape of the specified region
194    DataArrayView::RegionLoopRangeType region_loop_range=getSliceRegionLoopRange(region);    DataArrayView::ShapeType regionShape(DataArrayView::getResultSliceShape(region));
195    
196      // modify region specification as needed to match rank of this object
197      DataArrayView::RegionLoopRangeType regionLoopRange=getSliceRegionLoopRange(region);
198    
199      // ensure rank/shape of this object is compatible with specified region
200    if (getPointDataView().getRank()!=region.size()) {    if (getPointDataView().getRank()!=region.size()) {
201      throw DataException("Error - Invalid slice region.");      throw DataException("Error - Invalid slice region.");
202    }    }
203    if (tempDataTag->getPointDataView().getRank()>0 && !value->getPointDataView().checkShape(shape)) {    if (otherTemp->getPointDataView().getRank()>0 and !other->getPointDataView().checkShape(regionShape)) {
204      throw DataException (value->getPointDataView().createShapeErrorMessage(      throw DataException (other->getPointDataView().createShapeErrorMessage(
205                  "Error - Couldn't copy slice due to shape mismatch.",shape));                           "Error - Couldn't copy slice due to shape mismatch.",regionShape));
206    }    }
207    
208    getDefaultValue().copySliceFrom(tempDataTag->getDefaultValue(),region_loop_range);    // copy slice from other default value to this default value
209      getDefaultValue().copySliceFrom(otherTemp->getDefaultValue(), regionLoopRange);
210    
211    // loop through the tag values    // loop through tag values in other, adding any which aren't in this, using default value
212    DataMapType::const_iterator pos;    DataMapType::const_iterator pos;
213      for (pos=otherTemp->m_offsetLookup.begin();pos!=otherTemp->m_offsetLookup.end();pos++) {
214        if (!isCurrentTag(pos->first)) {
215          addTaggedValue(pos->first,getDefaultValue());
216        }
217      }
218    
219      // loop through the tag values copying slices from other to this
220    for (pos=m_offsetLookup.begin();pos!=m_offsetLookup.end();pos++) {    for (pos=m_offsetLookup.begin();pos!=m_offsetLookup.end();pos++) {
221      getDataPointByTag(pos->first).copySliceFrom(tempDataTag->getDataPointByTag(pos->first),region_loop_range);      getDataPointByTag(pos->first).copySliceFrom(otherTemp->getDataPointByTag(pos->first), regionLoopRange);
222    }    }
223    
224  }  }
225    
226  int  int
# Line 403  DataTagged::extractData(ifstream& archiv Line 421  DataTagged::extractData(ifstream& archiv
421  {  {
422    return(m_data.extractData(archiveFile, noValues));    return(m_data.extractData(archiveFile, noValues));
423  }  }
424    void
425    DataTagged::eigenvalues(DataAbstract* ev)
426    {
427      DataTagged* temp_ev=dynamic_cast<DataTagged*>(ev);
428      if (temp_ev==0) {
429        throw DataException("Error - DataTagged::eigenvalues casting to DataTagged failed (propably a programming error).");
430      }
431      const DataTagged::DataMapType& thisLookup=getTagLookup();
432      DataTagged::DataMapType::const_iterator i;
433      DataTagged::DataMapType::const_iterator thisLookupEnd=thisLookup.end();
434      for (i=thisLookup.begin();i!=thisLookupEnd;i++) {
435          temp_ev->addTaggedValue(i->first,temp_ev->getDefaultValue());
436          DataArrayView thisView=getDataPointByTag(i->first);
437          DataArrayView evView=temp_ev->getDataPointByTag(i->first);
438          DataArrayView::eigenvalues(thisView,0,evView,0);
439      }
440      DataArrayView::eigenvalues(getDefaultValue(),0,temp_ev->getDefaultValue(),0);
441    }
442    void
443    DataTagged::eigenvalues_and_eigenvectors(DataAbstract* ev,DataAbstract* V,const double tol)
444    {
445      DataTagged* temp_ev=dynamic_cast<DataTagged*>(ev);
446      if (temp_ev==0) {
447        throw DataException("Error - DataTagged::eigenvalues_and_eigenvectors casting to DataTagged failed (propably a programming error).");
448      }
449      DataTagged* temp_V=dynamic_cast<DataTagged*>(V);
450      if (temp_V==0) {
451        throw DataException("Error - DataTagged::eigenvalues_and_eigenvectors casting to DataTagged failed (propably a programming error).");
452      }
453      const DataTagged::DataMapType& thisLookup=getTagLookup();
454      DataTagged::DataMapType::const_iterator i;
455      DataTagged::DataMapType::const_iterator thisLookupEnd=thisLookup.end();
456      for (i=thisLookup.begin();i!=thisLookupEnd;i++) {
457          temp_ev->addTaggedValue(i->first,temp_ev->getDefaultValue());
458          temp_V->addTaggedValue(i->first,temp_V->getDefaultValue());
459          DataArrayView thisView=getDataPointByTag(i->first);
460          DataArrayView evView=temp_ev->getDataPointByTag(i->first);
461          DataArrayView VView=temp_V->getDataPointByTag(i->first);
462          DataArrayView::eigenvalues_and_eigenvectors(thisView,0,evView,0,VView,0,tol);
463      }
464      DataArrayView::eigenvalues_and_eigenvectors(getDefaultValue(),0,
465                                                  temp_ev->getDefaultValue(),0,
466                                                  temp_V->getDefaultValue(),0,
467                                                  tol);
468    
469    
470    }
471    
472    
473  }  // end of namespace  }  // end of namespace

Legend:
Removed from v.509  
changed lines
  Added in v.594

  ViewVC Help
Powered by ViewVC 1.1.26