/[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 594 by gross, Tue Mar 14 23:36:08 2006 UTC revision 950 by gross, Tue Feb 6 07:01:11 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 "DataTagged.h"  #include "DataTagged.h"
# Line 80  DataTagged::DataTagged(const FunctionSpa Line 78  DataTagged::DataTagged(const FunctionSpa
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
98      for (int sampleNo=0; sampleNo<getNumSamples(); sampleNo++) {
99        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),
# Line 110  DataTagged::DataTagged(const DataConstan Line 131  DataTagged::DataTagged(const DataConstan
131    setPointDataView(temp);    setPointDataView(temp);
132  }  }
133    
 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);  
   }  
   m_data=newData;  
   DataArrayView temp(m_data,shape);  
   setPointDataView(temp);  
 }  
   
134  DataAbstract*  DataAbstract*
135  DataTagged::getSlice(const DataArrayView::RegionType& region) const  DataTagged::getSlice(const DataArrayView::RegionType& region) const
136  {  {
# Line 200  DataTagged::setSlice(const DataAbstract* Line 191  DataTagged::setSlice(const DataAbstract*
191    if (getPointDataView().getRank()!=region.size()) {    if (getPointDataView().getRank()!=region.size()) {
192      throw DataException("Error - Invalid slice region.");      throw DataException("Error - Invalid slice region.");
193    }    }
194    if (otherTemp->getPointDataView().getRank()>0 and !other->getPointDataView().checkShape(regionShape)) {    if (otherTemp->getPointDataView().getRank()>0 && !other->getPointDataView().checkShape(regionShape)) {
195      throw DataException (other->getPointDataView().createShapeErrorMessage(      throw DataException (other->getPointDataView().createShapeErrorMessage(
196                           "Error - Couldn't copy slice due to shape mismatch.",regionShape));                           "Error - Couldn't copy slice due to shape mismatch.",regionShape));
197    }    }
# Line 422  DataTagged::extractData(ifstream& archiv Line 413  DataTagged::extractData(ifstream& archiv
413    return(m_data.extractData(archiveFile, noValues));    return(m_data.extractData(archiveFile, noValues));
414  }  }
415  void  void
416    DataTagged::symmetric(DataAbstract* ev)
417    {
418      DataTagged* temp_ev=dynamic_cast<DataTagged*>(ev);
419      if (temp_ev==0) {
420        throw DataException("Error - DataTagged::symmetric casting to DataTagged failed (probably a programming error).");
421      }
422      const DataTagged::DataMapType& thisLookup=getTagLookup();
423      DataTagged::DataMapType::const_iterator i;
424      DataTagged::DataMapType::const_iterator thisLookupEnd=thisLookup.end();
425      for (i=thisLookup.begin();i!=thisLookupEnd;i++) {
426          temp_ev->addTaggedValue(i->first,temp_ev->getDefaultValue());
427          DataArrayView thisView=getDataPointByTag(i->first);
428          DataArrayView evView=temp_ev->getDataPointByTag(i->first);
429          DataArrayView::symmetric(thisView,0,evView,0);
430      }
431      DataArrayView::symmetric(getDefaultValue(),0,temp_ev->getDefaultValue(),0);
432    }
433    void
434    DataTagged::nonsymmetric(DataAbstract* ev)
435    {
436      DataTagged* temp_ev=dynamic_cast<DataTagged*>(ev);
437      if (temp_ev==0) {
438        throw DataException("Error - DataTagged::nonsymmetric casting to DataTagged failed (probably a programming error).");
439      }
440      const DataTagged::DataMapType& thisLookup=getTagLookup();
441      DataTagged::DataMapType::const_iterator i;
442      DataTagged::DataMapType::const_iterator thisLookupEnd=thisLookup.end();
443      for (i=thisLookup.begin();i!=thisLookupEnd;i++) {
444          temp_ev->addTaggedValue(i->first,temp_ev->getDefaultValue());
445          DataArrayView thisView=getDataPointByTag(i->first);
446          DataArrayView evView=temp_ev->getDataPointByTag(i->first);
447          DataArrayView::nonsymmetric(thisView,0,evView,0);
448      }
449      DataArrayView::nonsymmetric(getDefaultValue(),0,temp_ev->getDefaultValue(),0);
450    }
451    void
452    DataTagged::trace(DataAbstract* ev, int axis_offset)
453    {
454      DataTagged* temp_ev=dynamic_cast<DataTagged*>(ev);
455      if (temp_ev==0) {
456        throw DataException("Error - DataTagged::trace casting to DataTagged failed (probably a programming error).");
457      }
458      const DataTagged::DataMapType& thisLookup=getTagLookup();
459      DataTagged::DataMapType::const_iterator i;
460      DataTagged::DataMapType::const_iterator thisLookupEnd=thisLookup.end();
461      for (i=thisLookup.begin();i!=thisLookupEnd;i++) {
462          temp_ev->addTaggedValue(i->first,temp_ev->getDefaultValue());
463          DataArrayView thisView=getDataPointByTag(i->first);
464          DataArrayView evView=temp_ev->getDataPointByTag(i->first);
465          DataArrayView::trace(thisView,0,evView,0, axis_offset);
466      }
467      DataArrayView::trace(getDefaultValue(),0,temp_ev->getDefaultValue(),0,axis_offset);
468    }
469    
470    void
471    DataTagged::transpose(DataAbstract* ev, int axis_offset)
472    {
473      DataTagged* temp_ev=dynamic_cast<DataTagged*>(ev);
474      if (temp_ev==0) {
475        throw DataException("Error - DataTagged::transpose casting to DataTagged failed (probably a programming error).");
476      }
477      const DataTagged::DataMapType& thisLookup=getTagLookup();
478      DataTagged::DataMapType::const_iterator i;
479      DataTagged::DataMapType::const_iterator thisLookupEnd=thisLookup.end();
480      for (i=thisLookup.begin();i!=thisLookupEnd;i++) {
481          temp_ev->addTaggedValue(i->first,temp_ev->getDefaultValue());
482          DataArrayView thisView=getDataPointByTag(i->first);
483          DataArrayView evView=temp_ev->getDataPointByTag(i->first);
484          DataArrayView::transpose(thisView,0,evView,0, axis_offset);
485      }
486      DataArrayView::transpose(getDefaultValue(),0,temp_ev->getDefaultValue(),0,axis_offset);
487    }
488    
489    void
490    DataTagged::swapaxes(DataAbstract* ev, int axis0, int axis1)
491    {
492      DataTagged* temp_ev=dynamic_cast<DataTagged*>(ev);
493      if (temp_ev==0) {
494        throw DataException("Error - DataTagged::swapaxes casting to DataTagged failed (probably a programming error).");
495      }
496      const DataTagged::DataMapType& thisLookup=getTagLookup();
497      DataTagged::DataMapType::const_iterator i;
498      DataTagged::DataMapType::const_iterator thisLookupEnd=thisLookup.end();
499      for (i=thisLookup.begin();i!=thisLookupEnd;i++) {
500          temp_ev->addTaggedValue(i->first,temp_ev->getDefaultValue());
501          DataArrayView thisView=getDataPointByTag(i->first);
502          DataArrayView evView=temp_ev->getDataPointByTag(i->first);
503          DataArrayView::swapaxes(thisView,0,evView,0,axis0,axis1);
504      }
505      DataArrayView::swapaxes(getDefaultValue(),0,temp_ev->getDefaultValue(),0,axis0,axis1);
506    }
507    
508    void
509  DataTagged::eigenvalues(DataAbstract* ev)  DataTagged::eigenvalues(DataAbstract* ev)
510  {  {
511    DataTagged* temp_ev=dynamic_cast<DataTagged*>(ev);    DataTagged* temp_ev=dynamic_cast<DataTagged*>(ev);
# Line 469  DataTagged::eigenvalues_and_eigenvectors Line 553  DataTagged::eigenvalues_and_eigenvectors
553    
554  }  }
555    
556    void
557    DataTagged::dump(const std::string fileName) const
558    {
559        throw DataException("Error - DataTagged:: dump: not implemented.");
560    }
561    
562    
563  }  // end of namespace  }  // end of namespace

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

  ViewVC Help
Powered by ViewVC 1.1.26