escript  Revision_
DataAbstract.h
Go to the documentation of this file.
00001 
00002 /*****************************************************************************
00003 *
00004 * Copyright (c) 2003-2014 by University of Queensland
00005 * http://www.uq.edu.au
00006 *
00007 * Primary Business: Queensland, Australia
00008 * Licensed under the Open Software License version 3.0
00009 * http://www.opensource.org/licenses/osl-3.0.php
00010 *
00011 * Development until 2012 by Earth Systems Science Computational Center (ESSCC)
00012 * Development 2012-2013 by School of Earth Sciences
00013 * Development from 2014 by Centre for Geoscience Computing (GeoComp)
00014 *
00015 *****************************************************************************/
00016 
00017 
00018 #if !defined escript_DataAbstract_20040315_H
00019 #define escript_DataAbstract_20040315_H
00020 #include "system_dep.h"
00021 
00022 #include "DataTypes.h"
00023 #include "FunctionSpace.h"
00024 
00025 #include <boost/scoped_ptr.hpp>
00026 
00027 #include "DataException.h"
00028 
00029 #include <string>
00030 #include <fstream>
00031 #include <vector>
00032 
00033 #include "Pointers.h"
00034 
00035 namespace escript {
00036 
00051 class DataAbstract;
00052 
00053 typedef POINTER_WRAPPER_CLASS(DataAbstract) DataAbstract_ptr;
00054 typedef POINTER_WRAPPER_CLASS(const DataAbstract) const_DataAbstract_ptr;
00055 
00056 class DataReady;
00057 
00058 typedef POINTER_WRAPPER_CLASS(DataReady) DataReady_ptr;
00059 typedef POINTER_WRAPPER_CLASS(const DataReady) const_DataReady_ptr;
00060 
00061 class DataAbstract : public REFCOUNT_BASE_CLASS(DataAbstract)
00062 {
00063 
00064  public:
00065 
00066   typedef DataTypes::ValueType ValueType;
00067   typedef DataTypes::ShapeType ShapeType;
00068 
00083    ESCRIPT_DLL_API
00084    DataAbstract_ptr getPtr();
00085    ESCRIPT_DLL_API
00086    const_DataAbstract_ptr getPtr() const; 
00087 
00088 
00089 
00098   ESCRIPT_DLL_API
00099   DataAbstract(const FunctionSpace& what, const ShapeType& shape, bool isDataEmpty=false);
00100 
00105   ESCRIPT_DLL_API
00106   virtual
00107   ~DataAbstract();
00108 
00113   ESCRIPT_DLL_API
00114   virtual
00115   std::string
00116   toString() const = 0;
00117 
00121   ESCRIPT_DLL_API
00122   virtual
00123   DataAbstract*
00124   deepCopy()=0;
00125 
00129   ESCRIPT_DLL_API
00130   virtual
00131   DataReady_ptr
00132   resolve()=0;
00133 
00138   ESCRIPT_DLL_API
00139   virtual
00140   void
00141   dump(const std::string fileName) const;
00142 
00147   ESCRIPT_DLL_API
00148   int
00149   getNumDPPSample() const;
00150 
00155   ESCRIPT_DLL_API
00156   int
00157   getNumSamples() const;
00158 
00165   ESCRIPT_DLL_API
00166   const DataTypes::ShapeType& 
00167   getShape() const;
00168 
00173   ESCRIPT_DLL_API
00174   unsigned int 
00175   getRank() const;
00176 
00177 
00178 
00187   ESCRIPT_DLL_API
00188   virtual
00189   ValueType::size_type
00190   getPointOffset(int sampleNo,
00191                  int dataPointNo) const = 0;
00192 
00193   ESCRIPT_DLL_API
00194   virtual
00195   ValueType::size_type
00196   getPointOffset(int sampleNo,
00197                  int dataPointNo) = 0;
00198 
00199 
00204   ESCRIPT_DLL_API
00205   virtual
00206   ValueType::size_type
00207   getLength() const = 0;
00208 
00214   ESCRIPT_DLL_API
00215   virtual
00216   double*
00217   getSampleDataByTag(int tag);
00218 
00226   ESCRIPT_DLL_API
00227   void
00228   operandCheck(const DataAbstract& right) const;
00229 
00234   ESCRIPT_DLL_API
00235   bool
00236   validSamplePointNo(int samplePointNo) const;
00237 
00242   ESCRIPT_DLL_API
00243   bool
00244   validSampleNo(int sampleNo) const;
00245 
00246 
00251   ESCRIPT_DLL_API
00252   const
00253   FunctionSpace&
00254   getFunctionSpace() const;
00255 
00262   ESCRIPT_DLL_API
00263   virtual
00264   DataAbstract*
00265   getSlice(const DataTypes::RegionType& region) const = 0;
00266 
00267 
00268 
00286   ESCRIPT_DLL_API
00287   virtual
00288   void
00289   setTaggedValue(int tagKey,
00290          const DataTypes::ShapeType& pointshape,
00291                  const DataTypes::ValueType& value,
00292          int dataOffset=0);
00293 
00294 
00306   ESCRIPT_DLL_API
00307   virtual void
00308   copyToDataPoint(const int sampleNo, const int dataPointNo, const double value);
00309 
00318   ESCRIPT_DLL_API
00319   virtual void
00320   copyToDataPoint(const int sampleNo, const int dataPointNo, const WrappedArray& value);
00321 
00322 
00330   ESCRIPT_DLL_API
00331   virtual
00332   int
00333   getTagNumber(int dpno);
00334 
00342   ESCRIPT_DLL_API
00343   virtual void
00344   symmetric(DataAbstract* ev);
00345 
00353   ESCRIPT_DLL_API
00354   virtual void
00355   nonsymmetric(DataAbstract* ev);
00356 
00364   ESCRIPT_DLL_API
00365   virtual void
00366   trace(DataAbstract* ev, int axis_offset);
00367 
00375   ESCRIPT_DLL_API
00376   virtual void
00377   transpose(DataAbstract* ev, int axis_offset);
00378 
00387   ESCRIPT_DLL_API
00388   virtual void
00389   swapaxes(DataAbstract* ev, int axis0, int axis1);
00397   ESCRIPT_DLL_API
00398   virtual void
00399   eigenvalues(DataAbstract* ev);
00400 
00406   ESCRIPT_DLL_API
00407   virtual int
00408   matrixInverse(DataAbstract* out) const;
00409 
00415   ESCRIPT_DLL_API
00416   virtual void
00417   setToZero();
00418 
00430   ESCRIPT_DLL_API
00431   virtual void
00432   eigenvalues_and_eigenvectors(DataAbstract* ev,DataAbstract* V,const double tol=1.e-13);
00433 
00440   ESCRIPT_DLL_API
00441   virtual void
00442   reorderByReferenceIDs(int *reference_ids);
00443 
00444 
00445 
00450   ESCRIPT_DLL_API
00451   unsigned int
00452   getNoValues() const;
00453 
00454 
00455   ESCRIPT_DLL_API
00456   bool isLazy() const;  // a test to determine if this object is an instance of DataLazy
00457 
00458   ESCRIPT_DLL_API
00459   virtual
00460   bool
00461   isConstant() const {return false;}
00462 
00463   ESCRIPT_DLL_API
00464   virtual
00465   bool
00466   isExpanded() const {return false;}
00467 
00468 
00474   ESCRIPT_DLL_API
00475   virtual
00476   bool
00477   actsExpanded() const {return false;}
00478 
00479   ESCRIPT_DLL_API
00480   virtual
00481   bool
00482   isTagged() const {return false;}
00483 
00484   ESCRIPT_DLL_API
00485   bool isEmpty() const; // a fast test to determine if this object is an instance of DataEmpty
00486 
00487 
00491   void
00492   addOwner(Data*);
00493 
00497   void
00498   removeOwner(Data*);
00499 
00503   ESCRIPT_DLL_API
00504   bool
00505   isShared() const
00506   {
00507     return m_lazyshared || (m_owners.size()>1);
00508   }
00509 
00510  protected:
00511 
00516    ESCRIPT_DLL_API
00517    bool checkNoSharing() const;
00518 
00523    void
00524    makeLazyShared();    
00525 
00526    friend class DataLazy;
00527 
00528  private:
00529 
00530   //
00531   // The number of samples in this Data object.
00532   // This is derived directly from the FunctionSpace.
00533   int m_noSamples;
00534 
00535   //
00536   // The number of data points per sample in this Data object.
00537   // This is derived directly from the FunctionSpace.
00538   int m_noDataPointsPerSample;
00539 
00540   //
00541   // A FunctionSpace which provides a description of the data associated
00542   // with this Data object.
00543   FunctionSpace m_functionSpace;
00544 
00545   //
00546   // The shape of the points stored in this view
00547   DataTypes::ShapeType m_shape;
00548 
00549   //
00550   // The number of values in each point
00551   unsigned int m_novalues;
00552 
00553   //
00554   // The rank of the points stored in this view
00555   unsigned int m_rank;
00556 
00557   // 
00558   // Is this an instance of DataEmpty?
00559   bool m_isempty;
00560 
00561 public:         // these should be private once I have finished debugging
00562   std::vector<Data*> m_owners;
00563   bool m_lazyshared;
00564 };
00565 
00566 inline
00567 bool
00568 DataAbstract::isEmpty() const
00569 {
00570     return m_isempty;
00571 }
00572 
00573 inline
00574 bool
00575 DataAbstract::validSamplePointNo(int samplePointNo) const
00576 {
00577   return ((0 <= samplePointNo) && (samplePointNo < m_noDataPointsPerSample));
00578 }
00579 
00580 inline
00581 bool
00582 DataAbstract::validSampleNo(int sampleNo) const
00583 {
00584   return ((0 <= sampleNo) && (sampleNo < m_noSamples));
00585 }
00586 
00587 inline
00588 int
00589 DataAbstract::getNumDPPSample() const
00590 {
00591   if (isEmpty())
00592   {
00593         throw DataException("Error - Operations not permitted on instances of DataEmpty.");
00594   }
00595   return m_noDataPointsPerSample;
00596 }
00597 
00598 inline
00599 int
00600 DataAbstract::getNumSamples() const
00601 {
00602   if (isEmpty())
00603   {
00604         throw DataException("Error - Operations not permitted on instances of DataEmpty.");
00605   }
00606   return m_noSamples;
00607 }
00608 
00609 inline
00610 const
00611 FunctionSpace&
00612 DataAbstract::getFunctionSpace() const
00613 {
00614   return m_functionSpace;
00615 }
00616 
00617 inline
00618 const DataTypes::ShapeType& 
00619 DataAbstract::getShape() const
00620 {
00621     if (isEmpty())
00622     {
00623         throw DataException("Error - Operations not permitted on instances of DataEmpty.");
00624     }
00625     return m_shape;
00626 }
00627 
00628 inline 
00629 unsigned int
00630 DataAbstract::getRank() const
00631 {
00632     if (isEmpty())
00633     {
00634         throw DataException("Error - Operations not permitted on instances of DataEmpty.");
00635     }
00636     return m_rank;
00637 }
00638 
00639 inline
00640 unsigned int
00641 DataAbstract::getNoValues() const
00642 {   
00643     if (isEmpty())
00644     {
00645         throw DataException("Error - Operations not permitted on instances of DataEmpty.");
00646     }
00647     return m_novalues;
00648 }
00649 
00650 
00651 } // end of namespace
00652 
00653 #endif