escript  Revision_
DataAbstract.h
Go to the documentation of this file.
1 
2 /*****************************************************************************
3 *
4 * Copyright (c) 2003-2016 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 
122  virtual
123  DataReady_ptr
124  resolve()=0;
125 
130  virtual
131  void
132  dump(const std::string fileName) const;
133 
138  int
139  getNumDPPSample() const;
140 
145  int
146  getNumSamples() const;
147 
148  bool
149  hasNoSamples() const
150  {
151  return getNumSamples()==0;
152  }
153 
160  const DataTypes::ShapeType&
161  getShape() const;
162 
167  unsigned int
168  getRank() const;
169 
170 
171 
180  virtual
182  getPointOffset(int sampleNo,
183  int dataPointNo) const = 0;
184 
185 
186 
191  virtual
193  getLength() const = 0;
194 
200  virtual
202  getSampleDataByTag(int tag, DataTypes::real_t dummy=0);
203 
209  virtual
211  getSampleDataByTag(int tag, DataTypes::cplx_t dummy);
212 
219  virtual
220  size_t
221  getTagCount() const;
222 
230  void
231  operandCheck(const DataAbstract& right) const;
232 
237  bool
238  validSamplePointNo(int samplePointNo) const;
239 
244  bool
245  validSampleNo(int sampleNo) const;
246 
247 
252  const
254  getFunctionSpace() const;
255 
262  virtual
263  DataAbstract*
264  getSlice(const DataTypes::RegionType& region) const = 0;
265 
266 
267 
285  virtual
286  void
287  setTaggedValue(int tagKey,
288  const DataTypes::ShapeType& pointshape,
289  const DataTypes::RealVectorType& value,
290  int dataOffset=0);
291 
292  virtual
293  void
294  setTaggedValue(int tagKey,
295  const DataTypes::ShapeType& pointshape,
296  const DataTypes::CplxVectorType& value,
297  int dataOffset=0);
298 
310  virtual void
311  copyToDataPoint(const int sampleNo, const int dataPointNo, const DataTypes::real_t value);
312 
313  virtual void
314  copyToDataPoint(const int sampleNo, const int dataPointNo, const DataTypes::cplx_t value);
315 
324  virtual void
325  copyToDataPoint(const int sampleNo, const int dataPointNo, const WrappedArray& value);
326 
327 
335  virtual
336  int
337  getTagNumber(int dpno);
338 
346  virtual void
347  symmetric(DataAbstract* ev);
348 
356  virtual void
358 
366  virtual void
367  hermitian(DataAbstract* ev);
368 
376  virtual void
378 
386  virtual void
387  trace(DataAbstract* ev, int axis_offset);
388 
396  virtual void
397  transpose(DataAbstract* ev, int axis_offset);
398 
407  virtual void
408  swapaxes(DataAbstract* ev, int axis0, int axis1);
416  virtual void
418 
424  virtual int
425  matrixInverse(DataAbstract* out) const;
426 
432  virtual void
433  setToZero();
434 
446  virtual void
447  eigenvalues_and_eigenvectors(DataAbstract* ev,DataAbstract* V,const double tol=1.e-13);
448 
455  virtual void
456  reorderByReferenceIDs(DataTypes::dim_t *reference_ids);
457 
458 
459 
464  unsigned int
465  getNoValues() const;
466 
467 
468  bool isLazy() const; // a test to determine if this object is an instance of DataLazy
469 
470  virtual
471  bool
472  isConstant() const {return false;}
473 
474  virtual
475  bool
476  isExpanded() const {return false;}
477 
478 
484  virtual
485  bool
486  actsExpanded() const {return false;}
487 
488  virtual
489  bool
490  isTagged() const {return false;}
491 
492  bool isEmpty() const; // a fast test to determine if this object is an instance of DataEmpty
493 
497  bool isComplex() const;
498 
499 #ifdef SLOWSHARECHECK
500 
501  // For this to be threadsafe, we need to be sure that this is the
502  // only way shared-ness is tested.
506  bool
507  isShared() const
508  {
509  bool shared=false;
510  #pragma omp critical // because two treads could try
511  { // this check at the same time
512  try // and shared_from_this increments count
513  {
514  shared=shared_from_this().use_count()>2;
515  }
516  catch (...)
517  {
518  }
519  }
520  return shared;
521  }
522 #endif
523 
524 #ifdef EXWRITECHK
525  bool exclusivewritecalled; // used to check for some potential programming faults
526  // involving shared data.
527  // This flag only asserts that exclusive write has been called
528  // on this object, it does not definitively guarantee that
529  // sharing has not occurred since that call
530  // This flag is for internal use only may be removed without warning
531 #endif
532 
533 /*
534  * Make the object complex
535 */
536  virtual void complicate();
537 
538 protected:
539  friend class DataLazy;
540 
541  //
542  // The number of samples in this Data object.
543  // This is derived directly from the FunctionSpace.
545 
546  //
547  // The number of data points per sample in this Data object.
548  // This is derived directly from the FunctionSpace.
550 
551  //
552  // is the data made of complex components
553  bool m_iscompl;
554 private:
555 
556  //
557  // A FunctionSpace which provides a description of the data associated
558  // with this Data object.
560 
561  //
562  // The shape of the points stored in this view
564 
565  //
566  // The number of values in each point
567  unsigned int m_novalues;
568 
569  //
570  // The rank of the points stored in this view
571  unsigned int m_rank;
572 
573  //
574  // Is this an instance of DataEmpty?
575  bool m_isempty;
576 };
577 
578 inline
579 bool
581 {
582  return m_isempty;
583 }
584 
585 inline
586 bool
587 DataAbstract::validSamplePointNo(int samplePointNo) const
588 {
589  return ((0 <= samplePointNo) && (samplePointNo < m_noDataPointsPerSample));
590 }
591 
592 inline
593 bool
594 DataAbstract::validSampleNo(int sampleNo) const
595 {
596  return ((0 <= sampleNo) && (sampleNo < m_noSamples));
597 }
598 
599 inline
600 int
602 {
603  if (isEmpty())
604  {
605  throw DataException("Error - Operations (getNumDPPSample) not permitted on instances of DataEmpty.");
606  }
607  return m_noDataPointsPerSample;
608 }
609 
610 inline
611 int
613 {
614  if (isEmpty())
615  {
616  throw DataException("Error - Operations (getNumSamples) not permitted on instances of DataEmpty.");
617  }
618  return m_noSamples;
619 }
620 
621 inline
622 const
625 {
626  return m_functionSpace;
627 }
628 
629 inline
632 {
633  if (isEmpty())
634  {
635  throw DataException("Error - Operations (getShape) not permitted on instances of DataEmpty.");
636  }
637  return m_shape;
638 }
639 
640 inline
641 unsigned int
643 {
644  if (isEmpty())
645  {
646  throw DataException("Error - Operations (getRank) not permitted on instances of DataEmpty.");
647  }
648  return m_rank;
649 }
650 
651 inline
652 unsigned int
654 {
655  if (isEmpty())
656  {
657  throw DataException("Error - Operations (getNoValues) not permitted on instances of DataEmpty.");
658  }
659  return m_novalues;
660 }
661 
662 } // end of namespace
663 
664 #endif // __ESCRIPT_DATAABSTRACT_H__
665 
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:642
bool isEmpty() const
Definition: DataAbstract.h:580
Definition: DataReady.h:35
DataTypes::vec_size_type size_type
Definition: DataVectorAlt.h:49
virtual bool isExpanded() const
Definition: DataAbstract.h:476
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:486
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:549
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:563
#define REFCOUNT_BASE_CLASS(x)
Definition: Pointers.h:30
bool hasNoSamples() const
Definition: DataAbstract.h:149
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:594
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:631
int getNumSamples() const
Return the number of samples.
Definition: DataAbstract.h:612
int getNumDPPSample() const
Return the number of data points per sample.
Definition: DataAbstract.h:601
bool validSamplePointNo(int samplePointNo) const
Return true if a valid sample point number.
Definition: DataAbstract.h:587
unsigned int m_novalues
Definition: DataAbstract.h:567
bool m_isempty
Definition: DataAbstract.h:575
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:553
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:472
#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:544
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:653
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:624
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:571
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:559
virtual bool isTagged() const
Definition: DataAbstract.h:490
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