/[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 519 by jgs, Tue Feb 14 05:30:50 2006 UTC revision 854 by gross, Thu Sep 21 05:29:42 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 "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 208  DataTagged::setSlice(const DataAbstract* Line 199  DataTagged::setSlice(const DataAbstract*
199    // copy slice from other default value to this default value    // copy slice from other default value to this default value
200    getDefaultValue().copySliceFrom(otherTemp->getDefaultValue(), regionLoopRange);    getDefaultValue().copySliceFrom(otherTemp->getDefaultValue(), regionLoopRange);
201    
202    // loop through the tag values copying slices from other to this    // loop through tag values in other, adding any which aren't in this, using default value
203    DataMapType::const_iterator pos;    DataMapType::const_iterator pos;
204      for (pos=otherTemp->m_offsetLookup.begin();pos!=otherTemp->m_offsetLookup.end();pos++) {
205        if (!isCurrentTag(pos->first)) {
206          addTaggedValue(pos->first,getDefaultValue());
207        }
208      }
209    
210      // loop through the tag values copying slices from other to this
211    for (pos=m_offsetLookup.begin();pos!=m_offsetLookup.end();pos++) {    for (pos=m_offsetLookup.begin();pos!=m_offsetLookup.end();pos++) {
212      getDataPointByTag(pos->first).copySliceFrom(otherTemp->getDataPointByTag(pos->first), regionLoopRange);      getDataPointByTag(pos->first).copySliceFrom(otherTemp->getDataPointByTag(pos->first), regionLoopRange);
213    }    }
# Line 414  DataTagged::extractData(ifstream& archiv Line 412  DataTagged::extractData(ifstream& archiv
412  {  {
413    return(m_data.extractData(archiveFile, noValues));    return(m_data.extractData(archiveFile, noValues));
414  }  }
415    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)
510    {
511      DataTagged* temp_ev=dynamic_cast<DataTagged*>(ev);
512      if (temp_ev==0) {
513        throw DataException("Error - DataTagged::eigenvalues casting to DataTagged failed (propably a programming error).");
514      }
515      const DataTagged::DataMapType& thisLookup=getTagLookup();
516      DataTagged::DataMapType::const_iterator i;
517      DataTagged::DataMapType::const_iterator thisLookupEnd=thisLookup.end();
518      for (i=thisLookup.begin();i!=thisLookupEnd;i++) {
519          temp_ev->addTaggedValue(i->first,temp_ev->getDefaultValue());
520          DataArrayView thisView=getDataPointByTag(i->first);
521          DataArrayView evView=temp_ev->getDataPointByTag(i->first);
522          DataArrayView::eigenvalues(thisView,0,evView,0);
523      }
524      DataArrayView::eigenvalues(getDefaultValue(),0,temp_ev->getDefaultValue(),0);
525    }
526    void
527    DataTagged::eigenvalues_and_eigenvectors(DataAbstract* ev,DataAbstract* V,const double tol)
528    {
529      DataTagged* temp_ev=dynamic_cast<DataTagged*>(ev);
530      if (temp_ev==0) {
531        throw DataException("Error - DataTagged::eigenvalues_and_eigenvectors casting to DataTagged failed (propably a programming error).");
532      }
533      DataTagged* temp_V=dynamic_cast<DataTagged*>(V);
534      if (temp_V==0) {
535        throw DataException("Error - DataTagged::eigenvalues_and_eigenvectors casting to DataTagged failed (propably a programming error).");
536      }
537      const DataTagged::DataMapType& thisLookup=getTagLookup();
538      DataTagged::DataMapType::const_iterator i;
539      DataTagged::DataMapType::const_iterator thisLookupEnd=thisLookup.end();
540      for (i=thisLookup.begin();i!=thisLookupEnd;i++) {
541          temp_ev->addTaggedValue(i->first,temp_ev->getDefaultValue());
542          temp_V->addTaggedValue(i->first,temp_V->getDefaultValue());
543          DataArrayView thisView=getDataPointByTag(i->first);
544          DataArrayView evView=temp_ev->getDataPointByTag(i->first);
545          DataArrayView VView=temp_V->getDataPointByTag(i->first);
546          DataArrayView::eigenvalues_and_eigenvectors(thisView,0,evView,0,VView,0,tol);
547      }
548      DataArrayView::eigenvalues_and_eigenvectors(getDefaultValue(),0,
549                                                  temp_ev->getDefaultValue(),0,
550                                                  temp_V->getDefaultValue(),0,
551                                                  tol);
552    
553    
554    }
555    
556    
557  }  // end of namespace  }  // end of namespace

Legend:
Removed from v.519  
changed lines
  Added in v.854

  ViewVC Help
Powered by ViewVC 1.1.26