escript Revision_
DataAbstract.h
Go to the documentation of this file.
1
2/*****************************************************************************
3*
4* Copyright (c) 2003-2020 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-2017 by Centre for Geoscience Computing (GeoComp)
14* Development from 2019 by School of Earth and Environmental Sciences
15**
16*****************************************************************************/
17
18#ifndef __ESCRIPT_DATAABSTRACT_H__
19#define __ESCRIPT_DATAABSTRACT_H__
20
21#include "system_dep.h"
22#include "DataTypes.h"
23#include "DataVector.h"
24#include "FunctionSpace.h"
25
26#include <boost/scoped_ptr.hpp>
27
28#include "DataException.h"
29
30#include <string>
31#include <fstream>
32#include <vector>
33
34#include "Pointers.h"
35
36namespace escript {
37
52class DataAbstract;
53
56
57class DataReady;
58
61
63{
64
65 public:
66
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,bool isCplx=false);
97
102 virtual
104
109 virtual
110 std::string
111 toString() const = 0;
112
116 virtual
118 deepCopy() const =0 ;
119
124 virtual
126 zeroedCopy() const =0 ;
127
128
129
133 virtual
136
141 virtual
142 void
143 dump(const std::string fileName) const;
144
149 int
150 getNumDPPSample() const;
151
156 int
157 getNumSamples() const;
158
159 bool
161 {
162 return getNumSamples()==0;
163 }
164
172 getShape() const;
173
178 unsigned int
179 getRank() const;
180
181
182
191 virtual
193 getPointOffset(int sampleNo,
194 int dataPointNo) const = 0;
195
196
197
202 virtual
204 getLength() const = 0;
205
211 virtual
213 getSampleDataByTag(int tag, DataTypes::real_t dummy=0);
214
220 virtual
222 getSampleDataByTag(int tag, DataTypes::cplx_t dummy);
223
230 virtual
231 size_t
232 getTagCount() const;
233
241 void
242 operandCheck(const DataAbstract& right) const;
243
248 bool
249 validSamplePointNo(int samplePointNo) const;
250
255 bool
256 validSampleNo(int sampleNo) const;
257
258
263 const
265 getFunctionSpace() const;
266
273 virtual
275 getSlice(const DataTypes::RegionType& region) const = 0;
276
277
278
296 virtual
297 void
298 setTaggedValue(int tagKey,
299 const DataTypes::ShapeType& pointshape,
300 const DataTypes::RealVectorType& value,
301 int dataOffset=0);
302
303 virtual
304 void
305 setTaggedValue(int tagKey,
306 const DataTypes::ShapeType& pointshape,
307 const DataTypes::CplxVectorType& value,
308 int dataOffset=0);
309
321 virtual void
322 copyToDataPoint(const int sampleNo, const int dataPointNo, const DataTypes::real_t value);
323
324 virtual void
325 copyToDataPoint(const int sampleNo, const int dataPointNo, const DataTypes::cplx_t value);
326
335 virtual void
336 copyToDataPoint(const int sampleNo, const int dataPointNo, const WrappedArray& value);
337
338
346 virtual
347 int
348 getTagNumber(int dpno);
349
357 virtual void
359
367 virtual void
369
377 virtual void
379
387 virtual void
389
397 virtual void
398 trace(DataAbstract* ev, int axis_offset);
399
407 virtual void
408 transpose(DataAbstract* ev, int axis_offset);
409
418 virtual void
419 swapaxes(DataAbstract* ev, int axis0, int axis1);
427 virtual void
429
435 virtual int
436 matrixInverse(DataAbstract* out) const;
437
443 virtual void
444 setToZero();
445
457 virtual void
458 eigenvalues_and_eigenvectors(DataAbstract* ev,DataAbstract* V,const double tol=1.e-13);
459
466 virtual void
467 reorderByReferenceIDs(DataTypes::dim_t *reference_ids);
468
469
470
475 unsigned int
476 getNoValues() const;
477
478
479 bool isLazy() const; // a test to determine if this object is an instance of DataLazy
480
481 virtual
482 bool
483 isConstant() const {return false;}
484
485 virtual
486 bool
487 isExpanded() const {return false;}
488
489
495 virtual
496 bool
497 actsExpanded() const {return false;}
498
499 virtual
500 bool
501 isTagged() const {return false;}
502
503 bool isEmpty() const; // a fast test to determine if this object is an instance of DataEmpty
504
508 bool isComplex() const;
509
510#ifdef SLOWSHARECHECK
511
512 // For this to be threadsafe, we need to be sure that this is the
513 // only way shared-ness is tested.
517 bool
518 isShared() const
519 {
520 bool shared=false;
521 #pragma omp critical // because two treads could try
522 { // this check at the same time
523 try // and shared_from_this increments count
524 {
525 shared=shared_from_this().use_count()>2;
526 }
527 catch (...)
528 {
529 }
530 }
531 return shared;
532 }
533#endif
534
535#ifdef EXWRITECHK
536 bool exclusivewritecalled; // used to check for some potential programming faults
537 // involving shared data.
538 // This flag only asserts that exclusive write has been called
539 // on this object, it does not definitively guarantee that
540 // sharing has not occurred since that call
541 // This flag is for internal use only may be removed without warning
542#endif
543
544/*
545 * Make the object complex
546*/
547 virtual void complicate();
548
549protected:
550 friend class DataLazy;
551
552 //
553 // The number of samples in this Data object.
554 // This is derived directly from the FunctionSpace.
556
557 //
558 // The number of data points per sample in this Data object.
559 // This is derived directly from the FunctionSpace.
561
562 //
563 // is the data made of complex components
565private:
566
567 //
568 // A FunctionSpace which provides a description of the data associated
569 // with this Data object.
571
572 //
573 // The shape of the points stored in this view
575
576 //
577 // The number of values in each point
578 unsigned int m_novalues;
579
580 //
581 // The rank of the points stored in this view
582 unsigned int m_rank;
583
584 //
585 // Is this an instance of DataEmpty?
587};
588
589inline
590bool
592{
593 return m_isempty;
594}
595
596inline
597bool
598DataAbstract::validSamplePointNo(int samplePointNo) const
599{
600 return ((0 <= samplePointNo) && (samplePointNo < m_noDataPointsPerSample));
601}
602
603inline
604bool
606{
607 return ((0 <= sampleNo) && (sampleNo < m_noSamples));
608}
609
610inline
611int
613{
614 if (isEmpty())
615 {
616 throw DataException("Error - Operations (getNumDPPSample) not permitted on instances of DataEmpty.");
617 }
619}
620
621inline
622int
624{
625 if (isEmpty())
626 {
627 throw DataException("Error - Operations (getNumSamples) not permitted on instances of DataEmpty.");
628 }
629 return m_noSamples;
630}
631
632inline
633const
639
640inline
643{
644 if (isEmpty())
645 {
646 throw DataException("Error - Operations (getShape) not permitted on instances of DataEmpty.");
647 }
648 return m_shape;
649}
650
651inline
652unsigned int
654{
655 if (isEmpty())
656 {
657 throw DataException("Error - Operations (getRank) not permitted on instances of DataEmpty.");
658 }
659 return m_rank;
660}
661
662inline
663unsigned int
665{
666 if (isEmpty())
667 {
668 throw DataException("Error - Operations (getNoValues) not permitted on instances of DataEmpty.");
669 }
670 return m_novalues;
671}
672
673} // end of namespace
674
675#endif // __ESCRIPT_DATAABSTRACT_H__
676
Typedefs and macros for reference counted storage.
#define POINTER_WRAPPER_CLASS(x)
Definition Pointers.h:33
#define REFCOUNT_BASE_CLASS(x)
Definition Pointers.h:31
#define V(_K_, _I_)
Definition ShapeFunctions.cpp:121
Definition DataAbstract.h:63
bool isEmpty() const
Definition DataAbstract.h:591
int getNumDPPSample() const
Return the number of data points per sample.
Definition DataAbstract.h:612
unsigned int getNoValues() const
Return the number of values in the shape for this object.
Definition DataAbstract.h:664
const DataTypes::ShapeType & getShape() const
Return the shape information for the point data.
Definition DataAbstract.h:642
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:497
int m_noSamples
Definition DataAbstract.h:555
virtual bool isConstant() const
Definition DataAbstract.h:483
virtual DataTypes::RealVectorType::size_type getPointOffset(int sampleNo, int dataPointNo) const =0
Return the offset for the given sample. This returns the offset for the given point into the containe...
bool hasNoSamples() const
Definition DataAbstract.h:160
FunctionSpace m_functionSpace
Definition DataAbstract.h:570
bool m_iscompl
Definition DataAbstract.h:564
int getNumSamples() const
Return the number of samples.
Definition DataAbstract.h:623
virtual DataAbstract * deepCopy() const =0
Return a deep copy of the current object.
virtual DataReady_ptr resolve()=0
Return a data object with all points resolved.
bool m_isempty
Definition DataAbstract.h:586
unsigned int getRank() const
Return the rank information for the point data.
Definition DataAbstract.h:653
DataTypes::ShapeType ShapeType
Definition DataAbstract.h:67
bool validSamplePointNo(int samplePointNo) const
Return true if a valid sample point number.
Definition DataAbstract.h:598
virtual DataAbstract * getSlice(const DataTypes::RegionType &region) const =0
Return the given slice from this object.
const FunctionSpace & getFunctionSpace() const
Return the function space associated with this Data object.
Definition DataAbstract.h:635
unsigned int m_rank
Definition DataAbstract.h:582
virtual DataAbstract * zeroedCopy() const =0
Return an object with the same type, domain (and tags if appropriate) as this, but all values are zer...
virtual std::string toString() const =0
Write the data as a string.
virtual bool isTagged() const
Definition DataAbstract.h:501
virtual DataTypes::RealVectorType::size_type getLength() const =0
Return the number of doubles stored for this Data object.
unsigned int m_novalues
Definition DataAbstract.h:578
DataTypes::ShapeType m_shape
Definition DataAbstract.h:574
int m_noDataPointsPerSample
Definition DataAbstract.h:560
bool validSampleNo(int sampleNo) const
Return true if a valid sample number.
Definition DataAbstract.h:605
virtual bool isExpanded() const
Definition DataAbstract.h:487
Definition DataException.h:28
Wraps an expression tree of other DataObjects. The data will be evaluated when required.
Definition DataLazy.h:49
Definition DataReady.h:37
DataTypes::vec_size_type size_type
Definition DataVectorAlt.h:50
Definition FunctionSpace.h:36
Definition WrappedArray.h:33
#define ESCRIPT_DLL_API
Definition escriptcore/src/system_dep.h:30
std::complex< real_t > cplx_t
complex data type
Definition DataTypes.h:55
std::vector< std::pair< int, int > > RegionType
Definition DataTypes.h:45
double real_t
type of all real-valued scalars in escript
Definition DataTypes.h:52
std::vector< int > ShapeType
The shape of a single datapoint.
Definition DataTypes.h:44
index_t dim_t
Definition DataTypes.h:66
Definition AbstractContinuousDomain.cpp:23
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:750
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:639
boost::shared_ptr< const DataReady > const_DataReady_ptr
Definition DataAbstract.h:60
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:103
boost::shared_ptr< DataAbstract > DataAbstract_ptr
Definition DataAbstract.h:54
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:488
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:343
boost::shared_ptr< const DataAbstract > const_DataAbstract_ptr
Definition DataAbstract.h:55
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:152
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:963
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:242
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:916
boost::shared_ptr< DataReady > DataReady_ptr
Definition DataAbstract.h:59