escript  Revision_
DataAbstract.h
Go to the documentation of this file.
1 
2 /*****************************************************************************
3 *
4 * Copyright (c) 2003-2018 by The University of Queensland
5 * http://www.uq.edu.au
6 *
7 * Primary Business: Queensland, Australia
8 * Licensed under the Apache License, version 2.0
9 * http://www.apache.org/licenses/LICENSE-2.0
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 #ifndef __ESCRIPT_DATAABSTRACT_H__
18 #define __ESCRIPT_DATAABSTRACT_H__
19 
20 #include "system_dep.h"
21 #include "DataTypes.h"
22 #include "DataVector.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 
60 
61 class ESCRIPT_DLL_API DataAbstract : public REFCOUNT_BASE_CLASS(DataAbstract)
62 {
63 
64  public:
65 
67 
82  DataAbstract_ptr getPtr();
83  const_DataAbstract_ptr getPtr() const;
84 
85 
86 
95  DataAbstract(const FunctionSpace& what, const ShapeType& shape, bool isDataEmpty=false,bool isCplx=false);
96 
101  virtual
102  ~DataAbstract();
103 
108  virtual
109  std::string
110  toString() const = 0;
111 
115  virtual
116  DataAbstract*
117  deepCopy() const =0 ;
118 
123  virtual
124  DataAbstract*
125  zeroedCopy() const =0 ;
126 
127 
128 
132  virtual
133  DataReady_ptr
134  resolve()=0;
135 
140  virtual
141  void
142  dump(const std::string fileName) const;
143 
148  int
149  getNumDPPSample() const;
150 
155  int
156  getNumSamples() const;
157 
158  bool
159  hasNoSamples() const
160  {
161  return getNumSamples()==0;
162  }
163 
170  const DataTypes::ShapeType&
171  getShape() const;
172 
177  unsigned int
178  getRank() const;
179 
180 
181 
190  virtual
192  getPointOffset(int sampleNo,
193  int dataPointNo) const = 0;
194 
195 
196 
201  virtual
203  getLength() const = 0;
204 
210  virtual
212  getSampleDataByTag(int tag, DataTypes::real_t dummy=0);
213 
219  virtual
221  getSampleDataByTag(int tag, DataTypes::cplx_t dummy);
222 
229  virtual
230  size_t
231  getTagCount() const;
232 
240  void
241  operandCheck(const DataAbstract& right) const;
242 
247  bool
248  validSamplePointNo(int samplePointNo) const;
249 
254  bool
255  validSampleNo(int sampleNo) const;
256 
257 
262  const
264  getFunctionSpace() const;
265 
272  virtual
273  DataAbstract*
274  getSlice(const DataTypes::RegionType& region) const = 0;
275 
276 
277 
295  virtual
296  void
297  setTaggedValue(int tagKey,
298  const DataTypes::ShapeType& pointshape,
299  const DataTypes::RealVectorType& value,
300  int dataOffset=0);
301 
302  virtual
303  void
304  setTaggedValue(int tagKey,
305  const DataTypes::ShapeType& pointshape,
306  const DataTypes::CplxVectorType& value,
307  int dataOffset=0);
308 
320  virtual void
321  copyToDataPoint(const int sampleNo, const int dataPointNo, const DataTypes::real_t value);
322 
323  virtual void
324  copyToDataPoint(const int sampleNo, const int dataPointNo, const DataTypes::cplx_t value);
325 
334  virtual void
335  copyToDataPoint(const int sampleNo, const int dataPointNo, const WrappedArray& value);
336 
337 
345  virtual
346  int
347  getTagNumber(int dpno);
348 
356  virtual void
357  symmetric(DataAbstract* ev);
358 
366  virtual void
368 
376  virtual void
377  hermitian(DataAbstract* ev);
378 
386  virtual void
388 
396  virtual void
397  trace(DataAbstract* ev, int axis_offset);
398 
406  virtual void
407  transpose(DataAbstract* ev, int axis_offset);
408 
417  virtual void
418  swapaxes(DataAbstract* ev, int axis0, int axis1);
426  virtual void
428 
434  virtual int
435  matrixInverse(DataAbstract* out) const;
436 
442  virtual void
443  setToZero();
444 
456  virtual void
457  eigenvalues_and_eigenvectors(DataAbstract* ev,DataAbstract* V,const double tol=1.e-13);
458 
465  virtual void
466  reorderByReferenceIDs(DataTypes::dim_t *reference_ids);
467 
468 
469 
474  unsigned int
475  getNoValues() const;
476 
477 
478  bool isLazy() const; // a test to determine if this object is an instance of DataLazy
479 
480  virtual
481  bool
482  isConstant() const {return false;}
483 
484  virtual
485  bool
486  isExpanded() const {return false;}
487 
488 
494  virtual
495  bool
496  actsExpanded() const {return false;}
497 
498  virtual
499  bool
500  isTagged() const {return false;}
501 
502  bool isEmpty() const; // a fast test to determine if this object is an instance of DataEmpty
503 
507  bool isComplex() const;
508 
509 #ifdef SLOWSHARECHECK
510 
511  // For this to be threadsafe, we need to be sure that this is the
512  // only way shared-ness is tested.
516  bool
517  isShared() const
518  {
519  bool shared=false;
520  #pragma omp critical // because two treads could try
521  { // this check at the same time
522  try // and shared_from_this increments count
523  {
524  shared=shared_from_this().use_count()>2;
525  }
526  catch (...)
527  {
528  }
529  }
530  return shared;
531  }
532 #endif
533 
534 #ifdef EXWRITECHK
535  bool exclusivewritecalled; // used to check for some potential programming faults
536  // involving shared data.
537  // This flag only asserts that exclusive write has been called
538  // on this object, it does not definitively guarantee that
539  // sharing has not occurred since that call
540  // This flag is for internal use only may be removed without warning
541 #endif
542 
543 /*
544  * Make the object complex
545 */
546  virtual void complicate();
547 
548 protected:
549  friend class DataLazy;
550 
551  //
552  // The number of samples in this Data object.
553  // This is derived directly from the FunctionSpace.
555 
556  //
557  // The number of data points per sample in this Data object.
558  // This is derived directly from the FunctionSpace.
560 
561  //
562  // is the data made of complex components
563  bool m_iscompl;
564 private:
565 
566  //
567  // A FunctionSpace which provides a description of the data associated
568  // with this Data object.
570 
571  //
572  // The shape of the points stored in this view
574 
575  //
576  // The number of values in each point
577  unsigned int m_novalues;
578 
579  //
580  // The rank of the points stored in this view
581  unsigned int m_rank;
582 
583  //
584  // Is this an instance of DataEmpty?
585  bool m_isempty;
586 };
587 
588 inline
589 bool
591 {
592  return m_isempty;
593 }
594 
595 inline
596 bool
597 DataAbstract::validSamplePointNo(int samplePointNo) const
598 {
599  return ((0 <= samplePointNo) && (samplePointNo < m_noDataPointsPerSample));
600 }
601 
602 inline
603 bool
604 DataAbstract::validSampleNo(int sampleNo) const
605 {
606  return ((0 <= sampleNo) && (sampleNo < m_noSamples));
607 }
608 
609 inline
610 int
612 {
613  if (isEmpty())
614  {
615  throw DataException("Error - Operations (getNumDPPSample) not permitted on instances of DataEmpty.");
616  }
617  return m_noDataPointsPerSample;
618 }
619 
620 inline
621 int
623 {
624  if (isEmpty())
625  {
626  throw DataException("Error - Operations (getNumSamples) not permitted on instances of DataEmpty.");
627  }
628  return m_noSamples;
629 }
630 
631 inline
632 const
635 {
636  return m_functionSpace;
637 }
638 
639 inline
642 {
643  if (isEmpty())
644  {
645  throw DataException("Error - Operations (getShape) not permitted on instances of DataEmpty.");
646  }
647  return m_shape;
648 }
649 
650 inline
651 unsigned int
653 {
654  if (isEmpty())
655  {
656  throw DataException("Error - Operations (getRank) not permitted on instances of DataEmpty.");
657  }
658  return m_rank;
659 }
660 
661 inline
662 unsigned int
664 {
665  if (isEmpty())
666  {
667  throw DataException("Error - Operations (getNoValues) not permitted on instances of DataEmpty.");
668  }
669  return m_novalues;
670 }
671 
672 } // end of namespace
673 
674 #endif // __ESCRIPT_DATAABSTRACT_H__
675 
Definition: FunctionSpace.h:34
void eigenvalues(const DataTypes::RealVectorType &in, const DataTypes::ShapeType &inShape, typename DataTypes::RealVectorType::size_type inOffset, DataTypes::RealVectorType &ev, const DataTypes::ShapeType &evShape, typename DataTypes::RealVectorType::size_type evOffset)
solves a local eigenvalue problem
Definition: DataVectorOps.h:638
#define POINTER_WRAPPER_CLASS(x)
Definition: Pointers.h:32
DataTypes::ShapeType ShapeType
Definition: DataAbstract.h:66
boost::shared_ptr< const DataAbstract > const_DataAbstract_ptr
Definition: DataAbstract.h:54
unsigned int getRank() const
Return the rank information for the point data.
Definition: DataAbstract.h:652
bool isEmpty() const
Definition: DataAbstract.h:590
Definition: DataReady.h:35
DataTypes::vec_size_type size_type
Definition: DataVectorAlt.h:49
virtual bool isExpanded() const
Definition: DataAbstract.h:486
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:496
std::vector< std::pair< int, int > > RegionType
Definition: DataTypes.h:43
Definition: AbstractContinuousDomain.cpp:22
boost::shared_ptr< const DataReady > const_DataReady_ptr
Definition: DataAbstract.h:59
int m_noDataPointsPerSample
Definition: DataAbstract.h:559
void transpose(const VEC &in, const DataTypes::ShapeType &inShape, typename VEC::size_type inOffset, VEC &ev, const DataTypes::ShapeType &evShape, typename VEC::size_type evOffset, int axis_offset)
Transpose each data point of this Data object around the given axis.
Definition: DataVectorOps.h:342
DataTypes::ShapeType m_shape
Definition: DataAbstract.h:573
#define REFCOUNT_BASE_CLASS(x)
Definition: Pointers.h:30
bool hasNoSamples() const
Definition: DataAbstract.h:159
std::vector< int > ShapeType
The shape of a single datapoint.
Definition: DataTypes.h:42
boost::shared_ptr< DataAbstract > DataAbstract_ptr
Definition: DataAbstract.h:51
bool validSampleNo(int sampleNo) const
Return true if a valid sample number.
Definition: DataAbstract.h:604
void symmetric(const VEC &in, const DataTypes::ShapeType &inShape, typename VEC::size_type inOffset, VEC &ev, const DataTypes::ShapeType &evShape, typename VEC::size_type evOffset)
computes a symmetric matrix from your square matrix A: (A + transpose(A)) / 2
Definition: DataVectorOps.h:102
Typedefs and macros for reference counted storage.
const DataTypes::ShapeType & getShape() const
Return the shape information for the point data.
Definition: DataAbstract.h:641
int getNumSamples() const
Return the number of samples.
Definition: DataAbstract.h:622
int getNumDPPSample() const
Return the number of data points per sample.
Definition: DataAbstract.h:611
bool validSamplePointNo(int samplePointNo) const
Return true if a valid sample point number.
Definition: DataAbstract.h:597
unsigned int m_novalues
Definition: DataAbstract.h:577
bool m_isempty
Definition: DataAbstract.h:585
void hermitian(const DataTypes::CplxVectorType &in, const DataTypes::ShapeType &inShape, DataTypes::CplxVectorType::size_type inOffset, DataTypes::CplxVectorType &ev, const DataTypes::ShapeType &evShape, DataTypes::CplxVectorType::size_type evOffset)
computes an hermitian matrix from your square matrix A: (A + adjoint(A)) / 2
Definition: DataVectorOps.cpp:915
bool m_iscompl
Definition: DataAbstract.h:563
void swapaxes(const VEC &in, const DataTypes::ShapeType &inShape, typename VEC::size_type inOffset, VEC &ev, const DataTypes::ShapeType &evShape, typename VEC::size_type evOffset, int axis0, int axis1)
swaps the components axis0 and axis1.
Definition: DataVectorOps.h:487
virtual bool isConstant() const
Definition: DataAbstract.h:482
#define V(_K_, _I_)
Definition: ShapeFunctions.cpp:120
Wraps an expression tree of other DataObjects. The data will be evaluated when required.
Definition: DataLazy.h:47
std::complex< real_t > cplx_t
complex data type
Definition: DataTypes.h:53
int m_noSamples
Definition: DataAbstract.h:554
Definition: DataException.h:26
#define ESCRIPT_DLL_API
Definition: escriptcore/src/system_dep.h:29
void trace(const VEC &in, const DataTypes::ShapeType &inShape, typename VEC::size_type inOffset, VEC &ev, const DataTypes::ShapeType &evShape, typename VEC::size_type evOffset, int axis_offset)
computes the trace of a matrix
Definition: DataVectorOps.h:241
unsigned int getNoValues() const
Return the number of values in the shape for this object.
Definition: DataAbstract.h:663
void antisymmetric(const VEC &in, const DataTypes::ShapeType &inShape, typename VEC::size_type inOffset, VEC &ev, const DataTypes::ShapeType &evShape, typename VEC::size_type evOffset)
computes a antisymmetric matrix from your square matrix A: (A - transpose(A)) / 2 ...
Definition: DataVectorOps.h:151
Definition: DataAbstract.h:61
const FunctionSpace & getFunctionSpace() const
Return the function space associated with this Data object.
Definition: DataAbstract.h:634
void eigenvalues_and_eigenvectors(const DataTypes::RealVectorType &in, const DataTypes::ShapeType &inShape, DataTypes::RealVectorType::size_type inOffset, DataTypes::RealVectorType &ev, const DataTypes::ShapeType &evShape, DataTypes::RealVectorType::size_type evOffset, DataTypes::RealVectorType &V, const DataTypes::ShapeType &VShape, DataTypes::RealVectorType::size_type VOffset, const double tol=1.e-13)
solves a local eigenvalue problem
Definition: DataVectorOps.h:746
unsigned int m_rank
Definition: DataAbstract.h:581
int getRank(const DataTypes::ShapeType &shape)
Return the rank (number of dimensions) of the given shape.
Definition: DataTypes.h:218
boost::shared_ptr< DataReady > DataReady_ptr
Definition: DataAbstract.h:56
Definition: WrappedArray.h:31
FunctionSpace m_functionSpace
Definition: DataAbstract.h:569
virtual bool isTagged() const
Definition: DataAbstract.h:500
void antihermitian(const DataTypes::CplxVectorType &in, const DataTypes::ShapeType &inShape, typename DataTypes::CplxVectorType::size_type inOffset, DataTypes::CplxVectorType &ev, const DataTypes::ShapeType &evShape, typename DataTypes::CplxVectorType::size_type evOffset)
computes a antihermitian matrix from your square matrix A: (A - adjoint(A)) / 2
Definition: DataVectorOps.cpp:962
double real_t
type of all real-valued scalars in escript
Definition: DataTypes.h:50
index_t dim_t
Definition: DataTypes.h:64