escript  Revision_4925
DataAbstract.h
Go to the documentation of this file.
1 
2 /*****************************************************************************
3 *
4 * Copyright (c) 2003-2014 by University of Queensland
5 * http://www.uq.edu.au
6 *
7 * Primary Business: Queensland, Australia
8 * Licensed under the Open Software License version 3.0
9 * http://www.opensource.org/licenses/osl-3.0.php
10 *
11 * Development until 2012 by Earth Systems Science Computational Center (ESSCC)
12 * Development 2012-2013 by School of Earth Sciences
13 * Development from 2014 by Centre for Geoscience Computing (GeoComp)
14 *
15 *****************************************************************************/
16 
17 
18 #if !defined escript_DataAbstract_20040315_H
19 #define escript_DataAbstract_20040315_H
20 #include "system_dep.h"
21 
22 #include "DataTypes.h"
23 #include "FunctionSpace.h"
24 
25 #include <boost/scoped_ptr.hpp>
26 
27 #include "DataException.h"
28 
29 #include <string>
30 #include <fstream>
31 #include <vector>
32 
33 #include "Pointers.h"
34 
35 namespace escript {
36 
52 
55 
56 class DataReady;
57 
58 typedef POINTER_WRAPPER_CLASS(DataReady) DataReady_ptr;
59 typedef POINTER_WRAPPER_CLASS(const DataReady) const_DataReady_ptr;
60 
62 {
63 
64  public:
65 
68 
84  DataAbstract_ptr getPtr();
86  const_DataAbstract_ptr getPtr() const;
87 
88 
89 
99  DataAbstract(const FunctionSpace& what, const ShapeType& shape, bool isDataEmpty=false);
100 
106  virtual
107  ~DataAbstract();
108 
114  virtual
115  std::string
116  toString() const = 0;
117 
122  virtual
123  DataAbstract*
124  deepCopy()=0;
125 
130  virtual
131  DataReady_ptr
132  resolve()=0;
133 
139  virtual
140  void
141  dump(const std::string fileName) const;
142 
148  int
149  getNumDPPSample() const;
150 
156  int
157  getNumSamples() const;
158 
166  const DataTypes::ShapeType&
167  getShape() const;
168 
174  unsigned int
175  getRank() const;
176 
177 
178 
188  virtual
190  getPointOffset(int sampleNo,
191  int dataPointNo) const = 0;
192 
194  virtual
196  getPointOffset(int sampleNo,
197  int dataPointNo) = 0;
198 
199 
205  virtual
207  getLength() const = 0;
208 
215  virtual
216  double*
217  getSampleDataByTag(int tag);
218 
227  void
228  operandCheck(const DataAbstract& right) const;
229 
235  bool
236  validSamplePointNo(int samplePointNo) const;
237 
243  bool
244  validSampleNo(int sampleNo) const;
245 
246 
252  const
254  getFunctionSpace() const;
255 
263  virtual
264  DataAbstract*
265  getSlice(const DataTypes::RegionType& region) const = 0;
266 
267 
268 
287  virtual
288  void
289  setTaggedValue(int tagKey,
290  const DataTypes::ShapeType& pointshape,
291  const DataTypes::ValueType& value,
292  int dataOffset=0);
293 
294 
307  virtual void
308  copyToDataPoint(const int sampleNo, const int dataPointNo, const double value);
309 
319  virtual void
320  copyToDataPoint(const int sampleNo, const int dataPointNo, const WrappedArray& value);
321 
322 
331  virtual
332  int
333  getTagNumber(int dpno);
334 
343  virtual void
344  symmetric(DataAbstract* ev);
345 
354  virtual void
355  nonsymmetric(DataAbstract* ev);
356 
365  virtual void
366  trace(DataAbstract* ev, int axis_offset);
367 
376  virtual void
377  transpose(DataAbstract* ev, int axis_offset);
378 
388  virtual void
389  swapaxes(DataAbstract* ev, int axis0, int axis1);
398  virtual void
399  eigenvalues(DataAbstract* ev);
400 
407  virtual int
408  matrixInverse(DataAbstract* out) const;
409 
416  virtual void
417  setToZero();
418 
431  virtual void
432  eigenvalues_and_eigenvectors(DataAbstract* ev,DataAbstract* V,const double tol=1.e-13);
433 
441  virtual void
442  reorderByReferenceIDs(int *reference_ids);
443 
444 
445 
451  unsigned int
452  getNoValues() const;
453 
454 
456  bool isLazy() const; // a test to determine if this object is an instance of DataLazy
457 
459  virtual
460  bool
461  isConstant() const {return false;}
462 
464  virtual
465  bool
466  isExpanded() const {return false;}
467 
468 
475  virtual
476  bool
477  actsExpanded() const {return false;}
478 
480  virtual
481  bool
482  isTagged() const {return false;}
483 
485  bool isEmpty() const; // a fast test to determine if this object is an instance of DataEmpty
486 
487 
491  void
492  addOwner(Data*);
493 
497  void
498  removeOwner(Data*);
499 
504  bool
505  isShared() const
506  {
507  return m_lazyshared || (m_owners.size()>1);
508  }
509 
510  protected:
511 
517  bool checkNoSharing() const;
518 
523  void
524  makeLazyShared();
525 
526  friend class DataLazy;
527 
528  private:
529 
530  //
531  // The number of samples in this Data object.
532  // This is derived directly from the FunctionSpace.
534 
535  //
536  // The number of data points per sample in this Data object.
537  // This is derived directly from the FunctionSpace.
539 
540  //
541  // A FunctionSpace which provides a description of the data associated
542  // with this Data object.
544 
545  //
546  // The shape of the points stored in this view
548 
549  //
550  // The number of values in each point
551  unsigned int m_novalues;
552 
553  //
554  // The rank of the points stored in this view
555  unsigned int m_rank;
556 
557  //
558  // Is this an instance of DataEmpty?
559  bool m_isempty;
560 
561 public: // these should be private once I have finished debugging
562  std::vector<Data*> m_owners;
564 };
565 
566 inline
567 bool
569 {
570  return m_isempty;
571 }
572 
573 inline
574 bool
575 DataAbstract::validSamplePointNo(int samplePointNo) const
576 {
577  return ((0 <= samplePointNo) && (samplePointNo < m_noDataPointsPerSample));
578 }
579 
580 inline
581 bool
582 DataAbstract::validSampleNo(int sampleNo) const
583 {
584  return ((0 <= sampleNo) && (sampleNo < m_noSamples));
585 }
586 
587 inline
588 int
590 {
591  if (isEmpty())
592  {
593  throw DataException("Error - Operations not permitted on instances of DataEmpty.");
594  }
596 }
597 
598 inline
599 int
601 {
602  if (isEmpty())
603  {
604  throw DataException("Error - Operations not permitted on instances of DataEmpty.");
605  }
606  return m_noSamples;
607 }
608 
609 inline
610 const
613 {
614  return m_functionSpace;
615 }
616 
617 inline
618 const DataTypes::ShapeType&
620 {
621  if (isEmpty())
622  {
623  throw DataException("Error - Operations not permitted on instances of DataEmpty.");
624  }
625  return m_shape;
626 }
627 
628 inline
629 unsigned int
631 {
632  if (isEmpty())
633  {
634  throw DataException("Error - Operations not permitted on instances of DataEmpty.");
635  }
636  return m_rank;
637 }
638 
639 inline
640 unsigned int
642 {
643  if (isEmpty())
644  {
645  throw DataException("Error - Operations not permitted on instances of DataEmpty.");
646  }
647  return m_novalues;
648 }
649 
650 
651 } // end of namespace
652 
653 #endif
Give a short description of what FunctionSpace does.
Definition: FunctionSpace.h:46
DataVector implements an arbitrarily long vector of data values. DataVector is the underlying data co...
Definition: DataVector.h:44
#define POINTER_WRAPPER_CLASS(x)
Definition: Pointers.h:32
DataTypes::ShapeType ShapeType
Definition: DataAbstract.h:67
boost::shared_ptr< const DataAbstract > const_DataAbstract_ptr
Definition: DataAbstract.h:54
Definition: DataReady.h:35
bool isShared() const
Is this object owned by more than one Data object.
Definition: DataAbstract.h:505
std::vector< std::pair< int, int > > RegionType
Definition: DataTypes.h:39
boost::shared_ptr< const DataReady > const_DataReady_ptr
Definition: DataAbstract.h:59
int m_noDataPointsPerSample
Definition: DataAbstract.h:538
bool validSampleNo(int sampleNo) const
Return true if a valid sample number.
Definition: DataAbstract.h:582
void transpose(const DataTypes::ValueType &in, const DataTypes::ShapeType &inShape, DataTypes::ValueType::size_type inOffset, DataTypes::ValueType &ev, const DataTypes::ShapeType &evShape, DataTypes::ValueType::size_type evOffset, int axis_offset)
Transpose each data point of this Data object around the given axis.
Definition: DataMaths.h:394
virtual bool isTagged() const
Definition: DataAbstract.h:482
bool m_lazyshared
Definition: DataAbstract.h:563
DataTypes::ShapeType m_shape
Definition: DataAbstract.h:547
#define REFCOUNT_BASE_CLASS(x)
Definition: Pointers.h:29
std::vector< int > ShapeType
The shape of a single datapoint.
Definition: DataTypes.h:38
void swapaxes(const DataTypes::ValueType &in, const DataTypes::ShapeType &inShape, DataTypes::ValueType::size_type inOffset, DataTypes::ValueType &ev, const DataTypes::ShapeType &evShape, DataTypes::ValueType::size_type evOffset, int axis0, int axis1)
swaps the components axis0 and axis1.
Definition: DataMaths.h:538
boost::shared_ptr< DataAbstract > DataAbstract_ptr
Definition: DataAbstract.h:51
virtual bool actsExpanded() const
Return true if this Data is expanded or resolves to expanded. That is, if it has a separate value for...
Definition: DataAbstract.h:477
void eigenvalues(const DataTypes::ValueType &in, const DataTypes::ShapeType &inShape, DataTypes::ValueType::size_type inOffset, DataTypes::ValueType &ev, const DataTypes::ShapeType &evShape, DataTypes::ValueType::size_type evOffset)
solves a local eigenvalue problem
Definition: DataMaths.h:689
void symmetric(const DataTypes::ValueType &in, const DataTypes::ShapeType &inShape, DataTypes::ValueType::size_type inOffset, DataTypes::ValueType &ev, const DataTypes::ShapeType &evShape, DataTypes::ValueType::size_type evOffset)
computes a symmetric matrix from your square matrix A: (A + transpose(A)) / 2
Definition: DataMaths.h:197
unsigned int getNoValues() const
Return the number of values in the shape for this object.
Definition: DataAbstract.h:641
bool validSamplePointNo(int samplePointNo) const
Return true if a valid sample point number.
Definition: DataAbstract.h:575
virtual bool isExpanded() const
Definition: DataAbstract.h:466
Typedefs and macros for reference counted storage.
unsigned int m_novalues
Definition: DataAbstract.h:551
int getNumDPPSample() const
Return the number of data points per sample.
Definition: DataAbstract.h:589
int isEmpty(escriptDataC *data)
Returns the true if the data are empty or data is NULL.
Definition: DataC.cpp:117
bool m_isempty
Definition: DataAbstract.h:559
Data represents a collection of datapoints.
Definition: Data.h:71
void eigenvalues_and_eigenvectors(const DataTypes::ValueType &in, const DataTypes::ShapeType &inShape, DataTypes::ValueType::size_type inOffset, DataTypes::ValueType &ev, const DataTypes::ShapeType &evShape, DataTypes::ValueType::size_type evOffset, DataTypes::ValueType &V, const DataTypes::ShapeType &VShape, DataTypes::ValueType::size_type VOffset, const double tol=1.e-13)
solves a local eigenvalue problem
Definition: DataMaths.h:750
#define V(_K_, _I_)
Definition: ShapeFunctions.cpp:120
int getNumSamples() const
Return the number of samples.
Definition: DataAbstract.h:600
const DataTypes::ShapeType & getShape() const
Return the shape information for the point data.
Definition: DataAbstract.h:619
Wraps an expression tree of other DataObjects. The data will be evaluated when required.
Definition: DataLazy.h:102
int m_noSamples
Definition: DataAbstract.h:533
DataException exception class.
Definition: DataException.h:35
#define ESCRIPT_DLL_API
Definition: escriptcore/src/system_dep.h:64
bool isEmpty() const
Definition: DataAbstract.h:568
Definition: DataAbstract.h:61
const FunctionSpace & getFunctionSpace() const
Return the function space associated with this Data object.
Definition: DataAbstract.h:612
void nonsymmetric(const DataTypes::ValueType &in, const DataTypes::ShapeType &inShape, DataTypes::ValueType::size_type inOffset, DataTypes::ValueType &ev, const DataTypes::ShapeType &evShape, DataTypes::ValueType::size_type evOffset)
computes a nonsymmetric matrix from your square matrix A: (A - transpose(A)) / 2
Definition: DataMaths.h:246
unsigned int m_rank
Definition: DataAbstract.h:555
int getRank(const DataTypes::ShapeType &shape)
Return the rank (number of dimensions) of the given shape.
Definition: DataTypes.h:167
boost::shared_ptr< DataReady > DataReady_ptr
Definition: DataAbstract.h:56
long size_type
Definition: DataVector.h:60
Definition: WrappedArray.h:29
unsigned int getRank() const
Return the rank information for the point data.
Definition: DataAbstract.h:630
FunctionSpace m_functionSpace
Definition: DataAbstract.h:543
virtual bool isConstant() const
Definition: DataAbstract.h:461
int getLength(struct escriptDataC *data)
Definition: DataC.cpp:97
DataTypes::ValueType ValueType
Definition: DataAbstract.h:66
std::vector< Data * > m_owners
Definition: DataAbstract.h:562
void trace(const DataTypes::ValueType &in, const DataTypes::ShapeType &inShape, DataTypes::ValueType::size_type inOffset, DataTypes::ValueType &ev, const DataTypes::ShapeType &evShape, DataTypes::ValueType::size_type evOffset, int axis_offset)
computes the trace of a matrix
Definition: DataMaths.h:295