DataAbstract.h
Go to the documentation of this file.
/*****************************************************************************
*
* Copyright (c) 2003-2020 by The University of Queensland
* http://www.uq.edu.au
*
* Primary Business: Queensland, Australia
* Licensed under the Apache License, version 2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Development until 2012 by Earth Systems Science Computational Center (ESSCC)
* Development 2012-2013 by School of Earth Sciences
* Development from 2014-2017 by Centre for Geoscience Computing (GeoComp)
* Development from 2019 by School of Earth and Environmental Sciences
**
*****************************************************************************/
#ifndef __ESCRIPT_DATAABSTRACT_H__
#define __ESCRIPT_DATAABSTRACT_H__
#include "system_dep.h"
#include "DataTypes.h"
#include "DataVector.h"
#include "FunctionSpace.h"
#include <boost/scoped_ptr.hpp>
#include "DataException.h"
#include <string>
#include <fstream>
#include <vector>
#include "Pointers.h"
namespace escript {
class DataAbstract;
typedef POINTER_WRAPPER_CLASS(DataAbstract) DataAbstract_ptr;
typedef POINTER_WRAPPER_CLASS(const DataAbstract) const_DataAbstract_ptr;
class DataReady;
typedef POINTER_WRAPPER_CLASS(DataReady) DataReady_ptr;
typedef POINTER_WRAPPER_CLASS(const DataReady) const_DataReady_ptr;
class ESCRIPT_DLL_API DataAbstract : public REFCOUNT_BASE_CLASS(DataAbstract)
{
public:
typedef DataTypes::ShapeType ShapeType;
DataAbstract_ptr getPtr();
const_DataAbstract_ptr getPtr() const;
DataAbstract(const FunctionSpace& what, const ShapeType& shape, bool isDataEmpty=false,bool isCplx=false);
virtual
~DataAbstract();
virtual
std::string
toString() const = 0;
virtual
DataAbstract*
deepCopy() const =0 ;
virtual
DataAbstract*
zeroedCopy() const =0 ;
virtual
DataReady_ptr
resolve()=0;
virtual
void
dump(const std::string fileName) const;
int
getNumDPPSample() const;
int
getNumSamples() const;
bool
hasNoSamples() const
{
return getNumSamples()==0;
}
const DataTypes::ShapeType&
getShape() const;
unsigned int
getRank() const;
virtual
DataTypes::RealVectorType::size_type
getPointOffset(int sampleNo,
int dataPointNo) const = 0;
virtual
DataTypes::RealVectorType::size_type
getLength() const = 0;
virtual
DataTypes::real_t*
getSampleDataByTag(int tag, DataTypes::real_t dummy=0);
virtual
DataTypes::cplx_t*
getSampleDataByTag(int tag, DataTypes::cplx_t dummy);
virtual
size_t
getTagCount() const;
void
operandCheck(const DataAbstract& right) const;
bool
validSamplePointNo(int samplePointNo) const;
bool
validSampleNo(int sampleNo) const;
const
FunctionSpace&
getFunctionSpace() const;
virtual
DataAbstract*
getSlice(const DataTypes::RegionType& region) const = 0;
virtual
void
setTaggedValue(int tagKey,
const DataTypes::ShapeType& pointshape,
const DataTypes::RealVectorType& value,
int dataOffset=0);
virtual
void
setTaggedValue(int tagKey,
const DataTypes::ShapeType& pointshape,
const DataTypes::CplxVectorType& value,
int dataOffset=0);
virtual void
copyToDataPoint(const int sampleNo, const int dataPointNo, const DataTypes::real_t value);
virtual void
copyToDataPoint(const int sampleNo, const int dataPointNo, const DataTypes::cplx_t value);
virtual void
copyToDataPoint(const int sampleNo, const int dataPointNo, const WrappedArray& value);
virtual
int
getTagNumber(int dpno);
virtual void
symmetric(DataAbstract* ev);
virtual void
antisymmetric(DataAbstract* ev);
virtual void
hermitian(DataAbstract* ev);
virtual void
antihermitian(DataAbstract* ev);
virtual void
trace(DataAbstract* ev, int axis_offset);
virtual void
transpose(DataAbstract* ev, int axis_offset);
virtual void
swapaxes(DataAbstract* ev, int axis0, int axis1);
virtual void
eigenvalues(DataAbstract* ev);
virtual int
matrixInverse(DataAbstract* out) const;
virtual void
setToZero();
virtual void
eigenvalues_and_eigenvectors(DataAbstract* ev,DataAbstract* V,const double tol=1.e-13);
virtual void
reorderByReferenceIDs(DataTypes::dim_t *reference_ids);
unsigned int
getNoValues() const;
bool isLazy() const; // a test to determine if this object is an instance of DataLazy
virtual
bool
isConstant() const {return false;}
virtual
bool
isExpanded() const {return false;}
virtual
bool
actsExpanded() const {return false;}
virtual
bool
isTagged() const {return false;}
bool isEmpty() const; // a fast test to determine if this object is an instance of DataEmpty
bool isComplex() const;
#ifdef SLOWSHARECHECK
// For this to be threadsafe, we need to be sure that this is the
// only way shared-ness is tested.
bool
isShared() const
{
bool shared=false;
#pragma omp critical // because two treads could try
{ // this check at the same time
try // and shared_from_this increments count
{
shared=shared_from_this().use_count()>2;
}
catch (...)
{
}
}
return shared;
}
#endif
#ifdef EXWRITECHK
bool exclusivewritecalled; // used to check for some potential programming faults
// involving shared data.
// This flag only asserts that exclusive write has been called
// on this object, it does not definitively guarantee that
// sharing has not occurred since that call
// This flag is for internal use only may be removed without warning
#endif
/*
* Make the object complex
*/
virtual void complicate();
protected:
friend class DataLazy;
//
// The number of samples in this Data object.
// This is derived directly from the FunctionSpace.
int m_noSamples;
//
// The number of data points per sample in this Data object.
// This is derived directly from the FunctionSpace.
int m_noDataPointsPerSample;
//
// is the data made of complex components
bool m_iscompl;
private:
//
// A FunctionSpace which provides a description of the data associated
// with this Data object.
FunctionSpace m_functionSpace;
//
// The shape of the points stored in this view
DataTypes::ShapeType m_shape;
//
// The number of values in each point
unsigned int m_novalues;
//
// The rank of the points stored in this view
unsigned int m_rank;
//
// Is this an instance of DataEmpty?
bool m_isempty;
};
inline
bool
DataAbstract::isEmpty() const
{
return m_isempty;
}
inline
bool
DataAbstract::validSamplePointNo(int samplePointNo) const
{
return ((0 <= samplePointNo) && (samplePointNo < m_noDataPointsPerSample));
}
inline
bool
DataAbstract::validSampleNo(int sampleNo) const
{
return ((0 <= sampleNo) && (sampleNo < m_noSamples));
}
inline
int
DataAbstract::getNumDPPSample() const
{
if (isEmpty())
{
throw DataException("Error - Operations (getNumDPPSample) not permitted on instances of DataEmpty.");
}
return m_noDataPointsPerSample;
}
inline
int
DataAbstract::getNumSamples() const
{
if (isEmpty())
{
throw DataException("Error - Operations (getNumSamples) not permitted on instances of DataEmpty.");
}
return m_noSamples;
}
inline
const
FunctionSpace&
DataAbstract::getFunctionSpace() const
{
return m_functionSpace;
}
inline
const DataTypes::ShapeType&
DataAbstract::getShape() const
{
if (isEmpty())
{
throw DataException("Error - Operations (getShape) not permitted on instances of DataEmpty.");
}
return m_shape;
}
inline
unsigned int
DataAbstract::getRank() const
{
if (isEmpty())
{
throw DataException("Error - Operations (getRank) not permitted on instances of DataEmpty.");
}
return m_rank;
}
inline
unsigned int
DataAbstract::getNoValues() const
{
if (isEmpty())
{
throw DataException("Error - Operations (getNoValues) not permitted on instances of DataEmpty.");
}
return m_novalues;
}
} // end of namespace
#endif // __ESCRIPT_DATAABSTRACT_H__
DataException.h
DataTypes.h
DataVector.h
FunctionSpace.h
Pointers.h
Typedefs and macros for reference counted storage.
POINTER_WRAPPER_CLASS
#define POINTER_WRAPPER_CLASS(x)
Definition: Pointers.h:33
REFCOUNT_BASE_CLASS
#define REFCOUNT_BASE_CLASS(x)
Definition: Pointers.h:31
V
#define V(_K_, _I_)
Definition: ShapeFunctions.cpp:121
escript::DataAbstract
Definition: DataAbstract.h:63
escript::DataAbstract::isEmpty
bool isEmpty() const
Definition: DataAbstract.h:591
escript::DataAbstract::deepCopy
virtual DataAbstract * deepCopy() const =0
Return a deep copy of the current object.
escript::DataAbstract::getNumDPPSample
int getNumDPPSample() const
Return the number of data points per sample.
Definition: DataAbstract.h:612
escript::DataAbstract::getNoValues
unsigned int getNoValues() const
Return the number of values in the shape for this object.
Definition: DataAbstract.h:664
escript::DataAbstract::getShape
const DataTypes::ShapeType & getShape() const
Return the shape information for the point data.
Definition: DataAbstract.h:642
escript::DataAbstract::actsExpanded
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
escript::DataAbstract::m_noSamples
int m_noSamples
Definition: DataAbstract.h:555
escript::DataAbstract::isConstant
virtual bool isConstant() const
Definition: DataAbstract.h:483
escript::DataAbstract::getPointOffset
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...
escript::DataAbstract::hasNoSamples
bool hasNoSamples() const
Definition: DataAbstract.h:160
escript::DataAbstract::m_functionSpace
FunctionSpace m_functionSpace
Definition: DataAbstract.h:570
escript::DataAbstract::m_iscompl
bool m_iscompl
Definition: DataAbstract.h:564
escript::DataAbstract::getNumSamples
int getNumSamples() const
Return the number of samples.
Definition: DataAbstract.h:623
escript::DataAbstract::resolve
virtual DataReady_ptr resolve()=0
Return a data object with all points resolved.
escript::DataAbstract::zeroedCopy
virtual DataAbstract * zeroedCopy() const =0
Return an object with the same type, domain (and tags if appropriate) as this, but all values are zer...
escript::DataAbstract::m_isempty
bool m_isempty
Definition: DataAbstract.h:586
escript::DataAbstract::getRank
unsigned int getRank() const
Return the rank information for the point data.
Definition: DataAbstract.h:653
escript::DataAbstract::ShapeType
DataTypes::ShapeType ShapeType
Definition: DataAbstract.h:67
escript::DataAbstract::validSamplePointNo
bool validSamplePointNo(int samplePointNo) const
Return true if a valid sample point number.
Definition: DataAbstract.h:598
escript::DataAbstract::getFunctionSpace
const FunctionSpace & getFunctionSpace() const
Return the function space associated with this Data object.
Definition: DataAbstract.h:635
escript::DataAbstract::m_rank
unsigned int m_rank
Definition: DataAbstract.h:582
escript::DataAbstract::toString
virtual std::string toString() const =0
Write the data as a string.
escript::DataAbstract::isTagged
virtual bool isTagged() const
Definition: DataAbstract.h:501
escript::DataAbstract::getLength
virtual DataTypes::RealVectorType::size_type getLength() const =0
Return the number of doubles stored for this Data object.
escript::DataAbstract::m_novalues
unsigned int m_novalues
Definition: DataAbstract.h:578
escript::DataAbstract::m_shape
DataTypes::ShapeType m_shape
Definition: DataAbstract.h:574
escript::DataAbstract::m_noDataPointsPerSample
int m_noDataPointsPerSample
Definition: DataAbstract.h:560
escript::DataAbstract::validSampleNo
bool validSampleNo(int sampleNo) const
Return true if a valid sample number.
Definition: DataAbstract.h:605
escript::DataAbstract::getSlice
virtual DataAbstract * getSlice(const DataTypes::RegionType &region) const =0
Return the given slice from this object.
escript::DataAbstract::isExpanded
virtual bool isExpanded() const
Definition: DataAbstract.h:487
escript::DataException
Definition: DataException.h:28
escript::DataLazy
Wraps an expression tree of other DataObjects. The data will be evaluated when required.
Definition: DataLazy.h:49
escript::DataReady
Definition: DataReady.h:37
escript::DataTypes::DataVectorAlt< real_t >
escript::DataTypes::DataVectorAlt::size_type
DataTypes::vec_size_type size_type
Definition: DataVectorAlt.h:50
escript::FunctionSpace
Definition: FunctionSpace.h:36
escript::WrappedArray
Definition: WrappedArray.h:33
ESCRIPT_DLL_API
#define ESCRIPT_DLL_API
Definition: escriptcore/src/system_dep.h:30
escript::DataTypes::cplx_t
std::complex< real_t > cplx_t
complex data type
Definition: DataTypes.h:55
escript::DataTypes::RegionType
std::vector< std::pair< int, int > > RegionType
Definition: DataTypes.h:45
escript::DataTypes::real_t
double real_t
type of all real-valued scalars in escript
Definition: DataTypes.h:52
escript::DataTypes::getRank
int getRank(const DataTypes::ShapeType &shape)
Return the rank (number of dimensions) of the given shape.
Definition: DataTypes.h:225
escript::DataTypes::ShapeType
std::vector< int > ShapeType
The shape of a single datapoint.
Definition: DataTypes.h:44
escript::DataTypes::dim_t
index_t dim_t
Definition: DataTypes.h:66
escript
Definition: AbstractContinuousDomain.cpp:23
escript::eigenvalues_and_eigenvectors
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
escript::eigenvalues
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
escript::const_DataReady_ptr
boost::shared_ptr< const DataReady > const_DataReady_ptr
Definition: DataAbstract.h:60
escript::symmetric
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
escript::DataAbstract_ptr
boost::shared_ptr< DataAbstract > DataAbstract_ptr
Definition: DataAbstract.h:52
escript::swapaxes
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
escript::transpose
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
escript::const_DataAbstract_ptr
boost::shared_ptr< const DataAbstract > const_DataAbstract_ptr
Definition: DataAbstract.h:55
escript::antisymmetric
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
escript::antihermitian
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
escript::trace
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
escript::hermitian
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
escript::DataReady_ptr
boost::shared_ptr< DataReady > DataReady_ptr
Definition: DataAbstract.h:57
system_dep.h