escript  Revision_
Public Types | Public Member Functions | Private Types | Private Attributes | Static Private Attributes
escript::DataTagged Class Reference

Simulates a full dataset accessible via sampleNo and dataPointNo. More...

#include <DataTagged.h>

Inheritance diagram for escript::DataTagged:
escript::DataReady escript::DataAbstract

List of all members.

Public Types

typedef std::vector< int > TagListType
typedef DataTypes::ValueType ValueType
typedef std::vector
< ValueType::ElementType
ValueBatchType
typedef std::map< int, int > DataMapType

Public Member Functions

 DataTagged ()
 Default constructor for DataTagged.
 DataTagged (const FunctionSpace &what, const DataTypes::ShapeType &shape, const int tags[], const ValueType &data)
 Alternative Constructor for DataTagged.
 DataTagged (const FunctionSpace &what, const DataTypes::ShapeType &shape, const TagListType &tags, const ValueType &data)
 Alternative Constructor for DataTagged.
 DataTagged (const DataTagged &other)
 Copy Constructor for DataTagged. Performs a deep copy from the given DataTagged object. T.
 DataTagged (const DataConstant &other)
 Copy Constructor for DataTagged. Construct a DataTagged object from a DataConstant object. The default value will be the value of the DataConstant object. T.
 DataTagged (const FunctionSpace &what, const DataTypes::ShapeType &shape, const DataTypes::ValueType &defaultvalue, const DataTagged *tagsource=0)
 Copies the tags from a DataTagged into a new Data Tagged and assigns them the default value. ** Not unit tested **.
virtual ~DataTagged ()
 Destructor.
bool isTagged () const
bool hasNaN () const
 Return true if any one of the datapoints contains a NaN.
virtual DataAbstractdeepCopy ()
 Return a deep copy of the current object.
virtual double * getSampleDataByTag (int tag)
 getSampleDataByTag
virtual std::string toString () const
 Write the data as a string. Writes out each tag, including the default, and the data-point which is associated with each tag. T.
virtual void dump (const std::string fileName) const
 dumps the object into a netCDF file
virtual int matrixInverse (DataAbstract *out) const
 invert square matricies
virtual void setToZero ()
 sets all values to zero
virtual int getTagNumber (int dpno)
 Return the tag number associated with the given data-point number according to the associated function space. T.
virtual ValueType::size_type getPointOffset (int sampleNo, int dataPointNo) const
 getPointOffset
virtual ValueType::size_type getPointOffset (int sampleNo, int dataPointNo)
void addTaggedValues (const TagListType &tagKeys, const ValueBatchType &values, const ShapeType &vShape)
 addTaggedValues
void addTaggedValues (const TagListType &tagKeys, const ValueType &values, const ShapeType &vShape)
void addTaggedValue (int tagKey, const DataTypes::ShapeType &pointshape, const ValueType &value, int dataOffset=0)
 addTaggedValue
void addTag (int tagKey)
 addTag - does not modify the default value for this object. ** Not unit tested **
void setTaggedValue (int tagKey, const DataTypes::ShapeType &pointshape, const ValueType &value, int dataOffset=0)
 setTaggedValue
DataTypes::ValueType::reference getDataByTagRW (int tag, DataTypes::ValueType::size_type i)
 getDataByTag
DataTypes::ValueType::const_reference getDataByTagRO (int tag, DataTypes::ValueType::size_type i) const
DataTypes::ValueType::size_type getOffsetForTag (int tag) const
 getOffsetForTag
DataTypes::ValueTypegetVectorRW ()
 Return a reference to the underlying DataVector.
const DataTypes::ValueTypegetVectorRO () const
const DataMapTypegetTagLookup () const
 getTagLookup
bool isCurrentTag (int tag) const
 isCurrentTag
DataTypes::ValueType::reference getDefaultValueRW (DataTypes::ValueType::size_type i)
 getDefaultValue
DataTypes::ValueType::const_reference getDefaultValueRO (DataTypes::ValueType::size_type i) const
virtual ValueType::size_type getLength () const
 getLength
virtual DataAbstractgetSlice (const DataTypes::RegionType &region) const
 getSlice
 DataTagged (const DataTagged &other, const DataTypes::RegionType &region)
 Slice Constructor for DataTagged.
virtual void setSlice (const DataAbstract *other, const DataTypes::RegionType &region)
 setSlice
virtual void symmetric (DataAbstract *ev)
 Computes a symmetric matrix (A + AT) / 2.
virtual void nonsymmetric (DataAbstract *ev)
 Computes a nonsymmetric matrix (A - AT) / 2.
virtual void trace (DataAbstract *ev, int axis_offset)
 Computes the trace of a matrix.
virtual void swapaxes (DataAbstract *ev, int axis0, int axis1)
 swaps components axis0 and axis1
virtual void transpose (DataAbstract *ev, int axis_offset)
 Transpose each data point of this Data object around the given axis.
virtual void eigenvalues (DataAbstract *ev)
 solves the eigenvalue problem this*V=ev*V for the eigenvalues ev
virtual void eigenvalues_and_eigenvectors (DataAbstract *ev, DataAbstract *V, const double tol=1.e-13)
 solves the eigenvalue problem this*V=ev*V for the eigenvalues ev and eigenvectors V
DataTypes::ValueType::size_type getDefaultOffset () const
 Returns the offset in the structure which stores the default value.

Private Types

typedef DataReady parent

Private Attributes

DataMapType m_offsetLookup
ValueType m_data

Static Private Attributes

static const int m_defaultValueOffset = 0

Detailed Description

Simulates a full dataset accessible via sampleNo and dataPointNo.

Description: Each data-point has an associated tag number, and a given tag can represent a range of dataPointNo and sampleNo. Each tag indexes only a single data-point. Thus only a single data-point needs to be stored for a range of sampleNo and dataPointNo values.


Member Typedef Documentation

typedef std::map<int, int> escript::DataTagged::DataMapType

Reimplemented from escript::DataReady.

typedef std::vector<int> escript::DataTagged::TagListType

Reimplemented from escript::DataAbstract.


Constructor & Destructor Documentation

Default constructor for DataTagged.

Description: Default constructor for DataTagged. Creates a DataTagged object for which the default data-point is a scalar data-point with value 0.0, and no other tag values are stored. T

References m_data, and escript::DataVector::resize().

Referenced by deepCopy(), and getSlice().

escript::DataTagged::DataTagged ( const FunctionSpace what,
const DataTypes::ShapeType shape,
const int  tags[],
const ValueType data 
)

Alternative Constructor for DataTagged.

Description: Alternative Constructor for DataTagged.

Parameters:
what- Input - A description of what this data object represents.
shape- Input - The shape of each data-point.
tags- Input - An array of tags, one for each sample number (starts at tag[1]).
data- The data values for each tag. NB: no unit testing yet

References escript::FunctionSpace::canTag(), m_data, m_offsetLookup, escript::DataTypes::noValues(), and escript::DataVector::size().

escript::DataTagged::DataTagged ( const FunctionSpace what,
const DataTypes::ShapeType shape,
const TagListType tags,
const ValueType data 
)

Alternative Constructor for DataTagged.

Description: Alternative Constructor for DataTagged.

Parameters:
what- Input - A description of what this data object represents.
shape- Input - The shape of each data-point.
tags- Input - An vector of tags, one for each sample number.
data- The data values for each tag. TODO Make sure to document the relationship between tags and data, ie: data also contains the default value

References escript::FunctionSpace::canTag(), m_data, m_offsetLookup, escript::DataTypes::noValues(), and escript::DataVector::size().

Copy Constructor for DataTagged. Performs a deep copy from the given DataTagged object. T.

escript::DataTagged::DataTagged ( const FunctionSpace what,
const DataTypes::ShapeType shape,
const DataTypes::ValueType defaultvalue,
const DataTagged tagsource = 0 
)

Copies the tags from a DataTagged into a new Data Tagged and assigns them the default value. ** Not unit tested **.

This is different from a deep copy because we are not copying shape or other information, just tags.

Parameters:
what- Input - FunctionSpace for the new DataTagged
shape- Input - Shape for points in the new DataTagged
defaultvalue- Input - Default value for new DataTagged
tagsource- Input - A DataTagged object which supplies the tags.

References addTag(), escript::FunctionSpace::canTag(), getTagLookup(), m_data, escript::DataTypes::noValues(), escript::DataVector::resize(), and escript::DataVector::size().

virtual escript::DataTagged::~DataTagged ( ) [inline, virtual]

Destructor.

escript::DataTagged::DataTagged ( const DataTagged other,
const DataTypes::RegionType region 
)

Slice Constructor for DataTagged.

Description: Creates a DataTagged object which is the specified slice from the given DataTagged object.

Parameters:
other- Input - DataTagged object to slice from.
region- Input - Region to slice. T

References escript::DataTypes::copySlice(), getDefaultOffset(), escript::DataAbstract::getNoValues(), escript::DataTypes::getResultSliceShape(), escript::DataAbstract::getShape(), escript::DataTypes::getSliceRegionLoopRange(), getVectorRO(), getVectorRW(), m_data, m_offsetLookup, escript::DataTypes::noValues(), and escript::DataVector::resize().


Member Function Documentation

void escript::DataTagged::addTag ( int  tagKey)

addTag - does not modify the default value for this object. ** Not unit tested **

Description: Add a single tag. The default value for this DataTagged will be associated with the tag. If this tag already has a value associated with it, then no change will be made.

Parameters:
tagKey- Input - Integer tag. TODO: Make sure this is unit tested

References CHECK_FOR_EX_WRITE, escript::DataAbstract::getNoValues(), m_data, m_defaultValueOffset, m_offsetLookup, escript::DataVector::resize(), and escript::DataVector::size().

Referenced by addTaggedValues(), escript::binaryOp(), escript::C_GeneralTensorProduct(), escript::C_TensorBinaryOperation(), escript::C_TensorUnaryOperation(), escript::Data::copyWithMask(), DataTagged(), eigenvalues(), eigenvalues_and_eigenvectors(), matrixInverse(), nonsymmetric(), setSlice(), swapaxes(), symmetric(), trace(), and transpose().

void escript::DataTagged::addTaggedValue ( int  tagKey,
const DataTypes::ShapeType pointshape,
const ValueType value,
int  dataOffset = 0 
)

addTaggedValue

Description: Add a single tag and value to this DataTagged object. If this tag already has a value associated with it, setTaggedValue will be used to update this value.

Parameters:
tagKey- Input - Integer tag.
pointshape- Shape of the value parameter
value- Input - Single DataArrayView value to be assigned to the tag.
dataOffset- Input - Offset of the beginning of the point in the value parameter

References CHECK_FOR_EX_WRITE, escript::DataTypes::checkShape(), escript::DataTypes::createShapeErrorMessage(), escript::DataAbstract::getNoValues(), escript::DataAbstract::getShape(), m_data, m_offsetLookup, escript::DataVector::resize(), setTaggedValue(), and escript::DataVector::size().

Referenced by addTaggedValues(), escript::condEval(), and setTaggedValue().

void escript::DataTagged::addTaggedValues ( const TagListType tagKeys,
const ValueBatchType values,
const ShapeType vShape 
)

addTaggedValues

Description: Add the given tags and values to this DataTagged object.

Parameters:
tagKeys- Input - A vector of integer tags.
values- Input - A vector of doubles. If this is empty, the default value for this DataTagged will be used for all tags. If it contains one value all tag values will be assigned this value. Otherwise consecutive tags will be assigned consecutive values. If there is a mismatch between the number of keys and the number of values an exception will be generated.
vShape- shape of the datapoints in "values" T
void escript::DataTagged::addTaggedValues ( const TagListType tagKeys,
const ValueType values,
const ShapeType vShape 
)

Description: Add the given tags and values to this DataTagged object.

Parameters:
tagKeys- Input - A vector of integer tags.
values- Input - A DataVector containing the datapoints. If this is empty, the default value for this DataTagged will be used for all tags. If it contains one value all tag values will be assigned this value. Otherwise consecutive tags will be assigned consecutive values. If there is a mismatch between the number of keys and the number of values an exception will be generated.
vShape- shape of the datapoints in "values"

TODO Makesure this is properly unit tested

References addTag(), addTaggedValue(), escript::DataAbstract::getNoValues(), and escript::DataVector::size().

Return a deep copy of the current object.

Implements escript::DataAbstract.

References DataTagged().

void escript::DataTagged::dump ( const std::string  fileName) const [virtual]

solves the eigenvalue problem this*V=ev*V for the eigenvalues ev

Parameters:
ev- Output - eigenvalues in increasing order at each data point

Reimplemented from escript::DataAbstract.

References addTag(), getDefaultOffset(), getOffsetForTag(), escript::DataAbstract::getShape(), getTagLookup(), getVectorRW(), and m_data.

void escript::DataTagged::eigenvalues_and_eigenvectors ( DataAbstract ev,
DataAbstract V,
const double  tol = 1.e-13 
) [virtual]

solves the eigenvalue problem this*V=ev*V for the eigenvalues ev and eigenvectors V

Parameters:
ev- Output - eigenvalues in increasing order at each data point
V- Output - corresponding eigenvectors. They are normalized such that their length is one and the first nonzero component is positive.
tol- Input - eigenvalue with relative distance tol are treated as equal.

Reimplemented from escript::DataAbstract.

References addTag(), getDefaultOffset(), getOffsetForTag(), escript::DataAbstract::getShape(), getTagLookup(), getVectorRW(), m_data, and V.

getDataByTag

Return a pointer to the beginning of the datapoint with the specified tag. TODO Eventually these should be inlined.

Parameters:
tag- Input - Integer key.
i- position in the underlying datastructure

References CHECK_FOR_EX_WRITE, m_data, m_defaultValueOffset, and m_offsetLookup.

Referenced by escript::C_GeneralTensorProduct(), escript::C_TensorBinaryOperation(), escript::C_TensorUnaryOperation(), and escript::dp_algorithm().

getDefaultValue

Description: Return the default value. This value is associated with any tag which is not explicitly recorded in this DataTagged object's tag map.

Parameters:
i- position in the underlying datastructure

References getVectorRW().

Referenced by escript::C_GeneralTensorProduct(), escript::C_TensorBinaryOperation(), escript::C_TensorUnaryOperation(), and escript::condEval().

getLength

Description: Return the total number of doubles stored for this DataTagged object. T

Implements escript::DataAbstract.

References m_data, and escript::DataVector::size().

getOffsetForTag

Parameters:
tag
Returns:
the offset of the beginning of the datapoint corresponding to tag.

Note: If the tag is not valid, the offset of the default value is returned instead.

References m_defaultValueOffset, and m_offsetLookup.

Referenced by escript::binaryOp(), escript::condEval(), escript::Data::copyWithMask(), escript::dp_algorithm(), eigenvalues(), eigenvalues_and_eigenvectors(), matrixInverse(), nonsymmetric(), setSlice(), swapaxes(), symmetric(), trace(), and transpose().

DataTypes::ValueType::size_type escript::DataTagged::getPointOffset ( int  sampleNo,
int  dataPointNo 
) const [virtual]

getPointOffset

Description: Return the offset to the given data-point value in the underlying data vector.

Parameters:
sampleNo- Input - sample number.
dataPointNo- Input - data-point number. T

Implements escript::DataAbstract.

References escript::DataAbstract::getFunctionSpace(), escript::FunctionSpace::getTagFromSampleNo(), m_defaultValueOffset, and m_offsetLookup.

Referenced by escript::C_GeneralTensorProduct(), escript::C_TensorBinaryOperation(), and escript::DataExpanded::DataExpanded().

DataTypes::ValueType::size_type escript::DataTagged::getPointOffset ( int  sampleNo,
int  dataPointNo 
) [virtual]
double * escript::DataTagged::getSampleDataByTag ( int  tag) [virtual]

getSampleDataByTag

Description: Return the data-point for the given tag. All of the data for the sample will be visible via the returned pointer.

This provides an interface into the data suitable for legacy C code. NB: need to do array bounds checking when accessing returned value! T

Reimplemented from escript::DataAbstract.

References CHECK_FOR_EX_WRITE, m_data, and m_offsetLookup.

DataAbstract * escript::DataTagged::getSlice ( const DataTypes::RegionType region) const [virtual]

getSlice

Description: Factory method that returns a newly created DataTagged object generated by taking the specified slice from this DataTagged object. The caller is reponsible for managing the returned object. T

Implements escript::DataAbstract.

References DataTagged().

int escript::DataTagged::getTagNumber ( int  dpno) [virtual]

Return the tag number associated with the given data-point number according to the associated function space. T.

Reimplemented from escript::DataAbstract.

References escript::DataAbstract::getFunctionSpace(), escript::DataAbstract::getNumDPPSample(), escript::DataAbstract::getNumSamples(), and escript::FunctionSpace::getTagFromSampleNo().

bool escript::DataTagged::hasNaN ( ) const [virtual]

Return true if any one of the datapoints contains a NaN.

Implements escript::DataReady.

References m_data, escript::nancheck(), and escript::DataVector::size().

bool escript::DataTagged::isCurrentTag ( int  tag) const [inline]

isCurrentTag

Description: Return true if the given tag exists within the DataTagged tag map.

NB: The DataTagged tag map does not necessarily coincide with the tag keys in the associated function space. T

References m_offsetLookup.

Referenced by escript::binaryOp(), and setSlice().

bool escript::DataTagged::isTagged ( ) const [inline, virtual]

Reimplemented from escript::DataAbstract.

int escript::DataTagged::matrixInverse ( DataAbstract out) const [virtual]

invert square matricies

Parameters:
out- Where to store the results
Returns:
errorcode (0 indicates success)

Reimplemented from escript::DataAbstract.

References addTag(), getDefaultOffset(), getOffsetForTag(), escript::DataAbstract::getRank(), escript::DataAbstract::getShape(), getTagLookup(), getVectorRW(), m_data, and escript::DataMaths::matrix_inverse().

Computes a nonsymmetric matrix (A - AT) / 2.

Parameters:
ev- Output - nonsymmetric matrix

Reimplemented from escript::DataAbstract.

References addTag(), getDefaultOffset(), getOffsetForTag(), escript::DataAbstract::getShape(), getTagLookup(), getVectorRW(), and m_data.

void escript::DataTagged::setSlice ( const DataAbstract other,
const DataTypes::RegionType region 
) [virtual]

setSlice

Description: Copy the given Data object into the specified region in this object.

Parameters:
other- Input - Data object to copy from.
region- Input - Region to copy into (NB: must have same shape as other!). T

Implements escript::DataReady.

References addTag(), CHECK_FOR_EX_WRITE, escript::DataTypes::checkShape(), escript::DataTypes::copySliceFrom(), escript::DataTypes::createShapeErrorMessage(), getDefaultOffset(), getOffsetForTag(), escript::DataAbstract::getRank(), escript::DataTypes::getResultSliceShape(), escript::DataAbstract::getShape(), escript::DataTypes::getSliceRegionLoopRange(), getVectorRO(), isCurrentTag(), m_data, and m_offsetLookup.

void escript::DataTagged::setTaggedValue ( int  tagKey,
const DataTypes::ShapeType pointshape,
const ValueType value,
int  dataOffset = 0 
) [virtual]

setTaggedValue

Description: Assign the given value to the given tag.

Parameters:
tagKey- Input - Integer tag.
pointshape- the shape of the value parameter
value- Input - Vector storing the datapoint to be assigned to the tag.
dataOffset- beginning of the datapoint within "value". T

Reimplemented from escript::DataAbstract.

References addTaggedValue(), CHECK_FOR_EX_WRITE, escript::DataTypes::checkShape(), escript::DataTypes::createShapeErrorMessage(), escript::DataAbstract::getNoValues(), escript::DataAbstract::getShape(), m_data, and m_offsetLookup.

Referenced by addTaggedValue().

void escript::DataTagged::setToZero ( ) [virtual]

sets all values to zero

Reimplemented from escript::DataAbstract.

References CHECK_FOR_EX_WRITE, m_data, and escript::DataVector::size().

void escript::DataTagged::swapaxes ( DataAbstract ev,
int  axis0,
int  axis1 
) [virtual]

swaps components axis0 and axis1

Parameters:
ev- Output - swapped components
axis0
axis1

Reimplemented from escript::DataAbstract.

References addTag(), getDefaultOffset(), getOffsetForTag(), escript::DataAbstract::getShape(), getTagLookup(), getVectorRW(), and m_data.

void escript::DataTagged::symmetric ( DataAbstract ev) [virtual]

Computes a symmetric matrix (A + AT) / 2.

Parameters:
ev- Output - symmetric matrix

Reimplemented from escript::DataAbstract.

References addTag(), getDefaultOffset(), getOffsetForTag(), escript::DataAbstract::getShape(), getTagLookup(), getVectorRW(), and m_data.

string escript::DataTagged::toString ( ) const [virtual]

Write the data as a string. Writes out each tag, including the default, and the data-point which is associated with each tag. T.

Implements escript::DataAbstract.

References getDefaultOffset(), escript::DataAbstract::getShape(), m_data, m_offsetLookup, and escript::DataTypes::pointToString().

void escript::DataTagged::trace ( DataAbstract ev,
int  axis_offset 
) [virtual]

Computes the trace of a matrix.

Parameters:
ev- Output - the trace of a matrix
axis_offset

Reimplemented from escript::DataAbstract.

References addTag(), getDefaultOffset(), getOffsetForTag(), escript::DataAbstract::getShape(), getTagLookup(), getVectorRW(), and m_data.

void escript::DataTagged::transpose ( DataAbstract ev,
int  axis_offset 
) [virtual]

Transpose each data point of this Data object around the given axis.

Parameters:
ev- Output - the transpose of a matrix
axis_offset

Reimplemented from escript::DataAbstract.

References addTag(), getDefaultOffset(), getOffsetForTag(), escript::DataAbstract::getShape(), getTagLookup(), getVectorRW(), and m_data.


Member Data Documentation

const int escript::DataTagged::m_defaultValueOffset = 0 [static, private]

The documentation for this class was generated from the following files: