escript  Revision_Unversioneddirectory
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 
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 
83  DataAbstract_ptr getPtr();
84  const_DataAbstract_ptr getPtr() const;
85 
86 
87 
96  DataAbstract(const FunctionSpace& what, const ShapeType& shape, bool isDataEmpty=false);
97 
102  virtual
103  ~DataAbstract();
104 
109  virtual
110  std::string
111  toString() const = 0;
112 
116  virtual
117  DataAbstract*
118  deepCopy()=0;
119 
123  virtual
124  DataReady_ptr
125  resolve()=0;
126 
131  virtual
132  void
133  dump(const std::string fileName) const;
134 
139  int
140  getNumDPPSample() const;
141 
146  int
147  getNumSamples() const;
148 
155  const DataTypes::ShapeType&
156  getShape() const;
157 
162  unsigned int
163  getRank() const;
164 
165 
166 
175  virtual
177  getPointOffset(int sampleNo,
178  int dataPointNo) const = 0;
179 
180  virtual
182  getPointOffset(int sampleNo,
183  int dataPointNo) = 0;
184 
185 
190  virtual
192  getLength() const = 0;
193 
199  virtual
200  double*
201  getSampleDataByTag(int tag);
202 
203 
210  virtual
211  size_t
212  getTagCount() const;
213 
221  void
222  operandCheck(const DataAbstract& right) const;
223 
228  bool
229  validSamplePointNo(int samplePointNo) const;
230 
235  bool
236  validSampleNo(int sampleNo) const;
237 
238 
243  const
245  getFunctionSpace() const;
246 
253  virtual
254  DataAbstract*
255  getSlice(const DataTypes::RegionType& region) const = 0;
256 
257 
258 
276  virtual
277  void
278  setTaggedValue(int tagKey,
279  const DataTypes::ShapeType& pointshape,
280  const DataTypes::ValueType& value,
281  int dataOffset=0);
282 
283 
295  virtual void
296  copyToDataPoint(const int sampleNo, const int dataPointNo, const double value);
297 
306  virtual void
307  copyToDataPoint(const int sampleNo, const int dataPointNo, const WrappedArray& value);
308 
309 
317  virtual
318  int
319  getTagNumber(int dpno);
320 
328  virtual void
329  symmetric(DataAbstract* ev);
330 
338  virtual void
339  nonsymmetric(DataAbstract* ev);
340 
348  virtual void
349  trace(DataAbstract* ev, int axis_offset);
350 
358  virtual void
359  transpose(DataAbstract* ev, int axis_offset);
360 
369  virtual void
370  swapaxes(DataAbstract* ev, int axis0, int axis1);
378  virtual void
379  eigenvalues(DataAbstract* ev);
380 
386  virtual int
387  matrixInverse(DataAbstract* out) const;
388 
394  virtual void
395  setToZero();
396 
408  virtual void
409  eigenvalues_and_eigenvectors(DataAbstract* ev,DataAbstract* V,const double tol=1.e-13);
410 
417  virtual void
418  reorderByReferenceIDs(dim_t *reference_ids);
419 
420 
421 
426  unsigned int
427  getNoValues() const;
428 
429 
430  bool isLazy() const; // a test to determine if this object is an instance of DataLazy
431 
432  virtual
433  bool
434  isConstant() const {return false;}
435 
436  virtual
437  bool
438  isExpanded() const {return false;}
439 
440 
446  virtual
447  bool
448  actsExpanded() const {return false;}
449 
450  virtual
451  bool
452  isTagged() const {return false;}
453 
454  bool isEmpty() const; // a fast test to determine if this object is an instance of DataEmpty
455 
456 
460  void
461  addOwner(Data*);
462 
466  void
467  removeOwner(Data*);
468 
472  bool
473  isShared() const
474  {
475  return m_lazyshared || (m_owners.size()>1);
476  }
477 
478 #ifdef EXWRITECHK
479  bool exclusivewritecalled; // used to check for some potential programming faults
480  // involving shared data.
481  // This flag only asserts that exclusive write has been called
482  // on this object, it does not definitively guarantee that
483  // sharing has not occurred since that call
484  // This flag is for internal use only may be removed without warning
485 #endif
486 
487 protected:
492  bool checkNoSharing() const;
493 
498  void
499  makeLazyShared();
500 
501  friend class DataLazy;
502 
503  std::vector<Data*> m_owners;
505 
506 private:
507  //
508  // The number of samples in this Data object.
509  // This is derived directly from the FunctionSpace.
511 
512  //
513  // The number of data points per sample in this Data object.
514  // This is derived directly from the FunctionSpace.
516 
517  //
518  // A FunctionSpace which provides a description of the data associated
519  // with this Data object.
521 
522  //
523  // The shape of the points stored in this view
525 
526  //
527  // The number of values in each point
528  unsigned int m_novalues;
529 
530  //
531  // The rank of the points stored in this view
532  unsigned int m_rank;
533 
534  //
535  // Is this an instance of DataEmpty?
536  bool m_isempty;
537 };
538 
539 inline
540 bool
542 {
543  return m_isempty;
544 }
545 
546 inline
547 bool
548 DataAbstract::validSamplePointNo(int samplePointNo) const
549 {
550  return ((0 <= samplePointNo) && (samplePointNo < m_noDataPointsPerSample));
551 }
552 
553 inline
554 bool
555 DataAbstract::validSampleNo(int sampleNo) const
556 {
557  return ((0 <= sampleNo) && (sampleNo < m_noSamples));
558 }
559 
560 inline
561 int
563 {
564  if (isEmpty())
565  {
566  throw DataException("Error - Operations (getNumDPPSample) not permitted on instances of DataEmpty.");
567  }
569 }
570 
571 inline
572 int
574 {
575  if (isEmpty())
576  {
577  throw DataException("Error - Operations (getNumSamples) not permitted on instances of DataEmpty.");
578  }
579  return m_noSamples;
580 }
581 
582 inline
583 const
586 {
587  return m_functionSpace;
588 }
589 
590 inline
593 {
594  if (isEmpty())
595  {
596  throw DataException("Error - Operations (getShape) not permitted on instances of DataEmpty.");
597  }
598  return m_shape;
599 }
600 
601 inline
602 unsigned int
604 {
605  if (isEmpty())
606  {
607  throw DataException("Error - Operations (getRank) not permitted on instances of DataEmpty.");
608  }
609  return m_rank;
610 }
611 
612 inline
613 unsigned int
615 {
616  if (isEmpty())
617  {
618  throw DataException("Error - Operations (getNoValues) not permitted on instances of DataEmpty.");
619  }
620  return m_novalues;
621 }
622 
623 
624 } // end of namespace
625 
626 #endif
Definition: FunctionSpace.h:34
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:473
std::vector< std::pair< int, int > > RegionType
Definition: DataTypes.h:39
Definition: AbstractContinuousDomain.cpp:24
int getLength(const escript::Data *data)
Definition: DataC.cpp:92
boost::shared_ptr< const DataReady > const_DataReady_ptr
Definition: DataAbstract.h:59
int m_noDataPointsPerSample
Definition: DataAbstract.h:515
bool validSampleNo(int sampleNo) const
Return true if a valid sample number.
Definition: DataAbstract.h:555
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:452
bool m_lazyshared
Definition: DataAbstract.h:504
DataTypes::ShapeType m_shape
Definition: DataAbstract.h:524
#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:448
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
int isEmpty(const escript::Data *data)
Returns the true if the data are empty or data is NULL.
Definition: DataC.cpp:110
unsigned int getNoValues() const
Return the number of values in the shape for this object.
Definition: DataAbstract.h:614
bool validSamplePointNo(int samplePointNo) const
Return true if a valid sample point number.
Definition: DataAbstract.h:548
virtual bool isExpanded() const
Definition: DataAbstract.h:438
Typedefs and macros for reference counted storage.
unsigned int m_novalues
Definition: DataAbstract.h:528
int getNumDPPSample() const
Return the number of data points per sample.
Definition: DataAbstract.h:562
bool m_isempty
Definition: DataAbstract.h:536
Data represents a collection of datapoints.
Definition: Data.h:68
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:573
const DataTypes::ShapeType & getShape() const
Return the shape information for the point data.
Definition: DataAbstract.h:592
Wraps an expression tree of other DataObjects. The data will be evaluated when required.
Definition: DataLazy.h:102
int m_noSamples
Definition: DataAbstract.h:510
DataException exception class.
Definition: DataException.h:35
#define ESCRIPT_DLL_API
Definition: escriptcore/src/system_dep.h:54
bool isEmpty() const
Definition: DataAbstract.h:541
index_t dim_t
Definition: types.h:27
Definition: DataAbstract.h:61
const FunctionSpace & getFunctionSpace() const
Return the function space associated with this Data object.
Definition: DataAbstract.h:585
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:532
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:603
FunctionSpace m_functionSpace
Definition: DataAbstract.h:520
virtual bool isConstant() const
Definition: DataAbstract.h:434
DataTypes::ValueType ValueType
Definition: DataAbstract.h:66
std::vector< Data * > m_owners
Definition: DataAbstract.h:503
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