weipa::DataVar Class Reference

A class that provides functionality to read an escript data object from a dump file or an escript::Data instance and write that data in Silo or VTK XML formats. More...

`#include <DataVar.h>`

## Public Member Functions

| DataVar (const std::string &name)
| Constructor with variable name. More...
| DataVar (const DataVar &d)
| Copy constructor. Performs a deep copy of the data values. More...
| ~DataVar ()
| Destructor. More...
bool | initFromEscript (escript::Data &escriptData, const_DomainChunk_ptr dom)
| Initialises values and IDs from an escript::Data instance. More...
bool | initFromMeshData (const_DomainChunk_ptr dom, const IntVec &data, int fsCode, Centering c, NodeData_ptr nodes, const IntVec &id)
| Initialises with integral mesh data like IDs or tags. More...
bool | initFromFile (const std::string &filename, const_DomainChunk_ptr dom)
| Reads values and IDs for this variable from an escript dump file. More...
bool | writeToSilo (DBfile *dbfile, const std::string &siloPath, const std::string &units)
| Writes the data into given directory within a Silo file. More...
void | writeToVTK (std::ostream &os, int ownIndex)
| Writes the data values to ostream in VTK text format. More...
int | getRank () const
| Returns the rank of the data. More...
bool | isNodeCentered () const
| Returns true if the variable data is node centered, false if zone centered. More...
std::string | getMeshName () const
| Returns the name of the associated mesh. More...
const IntVec & | getShape () const
| Returns the shape vector of the data. More...
std::string | getName () const
| Returns the variable name. More...
std::string | getTensorDef () const
| Returns the Silo tensor definition for this tensor. More...
int | getNumberOfSamples () const
| Returns the number of data values. More...
const CoordArray & | getData () const
| Returns the array of data values where array[i] is the i-th component of the data. More...
float * | getDataFlat () const
| Returns a flattened array of data values, i.e. the ordering is s0c0 s0c1 s0c2 s1c0 s1c1 s1c2 s2c0 ... where s denotes the sample number and c the component. More...
int | getNumberOfComponents () const
| Returns the total number of components (sum of shape elements). More...

## Private Member Functions

void | cleanup ()
float * | averageData (const float *src, size_t stride)
| Averages and filters data. More...
IndexMap | buildIndexMap ()
| Prepares a sample ID -> index mapping which is used to reorder data. More...
bool | reorderSamples ()
| Reorders the samples according to the corresponding node or element IDs. More...
void | sampleToStream (std::ostream &os, int index)
| Outputs sample at index to output stream in VTK XML format. More...

## Private Attributes

bool | initialized
const_DomainChunk_ptr | domain
std::string | varName
int | numSamples
int | rank
int | ptsPerSample
int | funcSpace
Centering | centering
IntVec | shape
IntVec | sampleID
CoordArray | dataArray
std::string | meshName
std::string | siloMeshName

## Detailed Description

A class that provides functionality to read an escript data object from a dump file or an escript::Data instance and write that data in Silo or VTK XML formats.

## Constructor & Destructor Documentation

## DataVar() [1/2]

weipa::DataVar::DataVar | ( | const std::string & | name | ) |

Constructor with variable name.

## DataVar() [2/2]

weipa::DataVar::DataVar | ( | const DataVar & | d | ) |

Copy constructor. Performs a deep copy of the data values.

References paso::util::copy(), dataArray, and numSamples.

## ~DataVar()

weipa::DataVar::~DataVar | ( |  | ) |

Destructor.

References cleanup().

## Member Function Documentation

## averageData()

float * weipa::DataVar::averageData | ( | const float * | src,
|  | size_t | stride
| ) |  |

private

Averages and filters data.

If a sample consists of more than one data point then this method averages over the data points and returns the resulting array. In any case, the data is filtered according to the stride value.

References domain, weipa::QuadMaskInfo::factor, funcSpace, weipa::QuadMaskInfo::mask, numSamples, and ptsPerSample.

Referenced by initFromEscript(), and initFromFile().

## buildIndexMap()

IndexMap weipa::DataVar::buildIndexMap | ( |  | ) |

inline private

Prepares a sample ID -> index mapping which is used to reorder data.

References sampleID.

Referenced by reorderSamples(), and writeToVTK().

## cleanup()

void weipa::DataVar::cleanup | ( |  | ) |

private

References dataArray, initialized, numSamples, sampleID, and shape.

Referenced by initFromEscript(), initFromFile(), initFromMeshData(), and ~DataVar().

## getData()

const CoordArray& weipa::DataVar::getData | ( |  | ) | const

inline

Returns the array of data values where array[i] is the i-th component of the data.

References dataArray.

## getDataFlat()

float * weipa::DataVar::getDataFlat | ( |  | ) | const

Returns a flattened array of data values, i.e. the ordering is s0c0 s0c1 s0c2 s1c0 s1c1 s1c2 s2c0 ... where s denotes the sample number and c the component.

References paso::util::copy(), dataArray, getNumberOfComponents(), numSamples, rank, and shape.

## getMeshName()

std::string weipa::DataVar::getMeshName | ( |  | ) | const

inline

Returns the name of the associated mesh.

The returned name is one of the sub-meshes of the mesh set with setMesh() determined on the basis of the function space type and whether reduced elements are used or not.

References meshName.

## getName()

std::string weipa::DataVar::getName | ( |  | ) | const

inline

Returns the variable name.

References varName.

## getNumberOfComponents()

int weipa::DataVar::getNumberOfComponents | ( |  | ) | const

Returns the total number of components (sum of shape elements).

References rank, and shape.

Referenced by getDataFlat().

## getNumberOfSamples()

int weipa::DataVar::getNumberOfSamples | ( |  | ) | const

inline

Returns the number of data values.

References numSamples.

## getRank()

int weipa::DataVar::getRank | ( |  | ) | const

inline

Returns the rank of the data.

References rank.

## getShape()

const IntVec& weipa::DataVar::getShape | ( |  | ) | const

inline

Returns the shape vector of the data.

The shape vector has as many elements as the rank of this variable.

References shape.

## getTensorDef()

string weipa::DataVar::getTensorDef | ( |  | ) | const

Returns the Silo tensor definition for this tensor.

If the data is tensor data then the components of the tensor are stored separately in the Silo file. This method then returns a string that contains the proper Silo expression to put the tensor together again. For non-tensor data this method returns an empty string.

Format string for Silo 2x2 tensor

Format string for Silo 3x3 tensor

References initialized, rank, shape, and varName.

## initFromEscript()

bool weipa::DataVar::initFromEscript | ( | escript::Data & | escriptData,
|  | const_DomainChunk_ptr | dom
| ) |  |

Initialises values and IDs from an escript::Data instance.

Returns
  true if a valid instance of expanded data was supplied, false if the initialisation was unsuccessful.

References escript::Data::actsExpanded(), averageData(), escript::FunctionSpace::borrowSampleReferenceIDs(), centering, cleanup(), paso::util::copy(), dataArray, domain, funcSpace, escript::Data::getDataPointRank(), escript::Data::getDataPointShape(), escript::Data::getDataRO(), escript::Data::getFunctionSpace(), escript::Data::getNumDataPointsPerSample(), escript::Data::getNumSamples(), escript::Data::getSampleDataRO(), escript::FunctionSpace::getTypeCode(), initialized, escript::Data::isConstant(), meshName, numSamples, ptsPerSample, rank, reorderSamples(), sampleID, shape, siloMeshName, and varName.

## initFromFile()

bool weipa::DataVar::initFromFile | ( | const std::string & | filename,
|  | const_DomainChunk_ptr | dom
| ) |  |

Reads values and IDs for this variable from an escript dump file.

Returns
  true if the file was found and contains valid escript data with at least one sample, false otherwise.

Note
  Only expanded data with rank <=2 is supported at the moment.

References averageData(), centering, cleanup(), dataArray, domain, funcSpace, initialized, meshName, numSamples, ptsPerSample, rank, reorderSamples(), sampleID, shape, siloMeshName, and varName.

## initFromMeshData()

bool weipa::DataVar::initFromMeshData | ( | const_DomainChunk_ptr | dom,
|  | const IntVec & | data,
|  | int | fsCode,
|  | Centering | c,
|  | NodeData_ptr | nodes,
|  | const IntVec & | id
| ) |  |

Initialises with integral mesh data like IDs or tags.

References centering, cleanup(), dataArray, domain, initialized, meshName, numSamples, ptsPerSample, rank, sampleID, and siloMeshName.

## isNodeCentered()

bool weipa::DataVar::isNodeCentered | ( |  | ) | const

Returns true if the variable data is node centered, false if zone centered.

References centering, and weipa::NODE_CENTERED.

Referenced by writeToVTK().

## reorderSamples()

bool weipa::DataVar::reorderSamples | ( |  | ) |

private

Reorders the samples according to the corresponding node or element IDs.

Returns
  true if the function space is supported and the number of elements or nodes matches the number of data samples.

References buildIndexMap(), centering, paso::util::copy(), dataArray, domain, funcSpace, weipa::NODE_CENTERED, numSamples, sampleID, and varName.

Referenced by initFromEscript(), and initFromFile().

## sampleToStream()

void weipa::DataVar::sampleToStream | ( | std::ostream & | os,
|  | int | index
| ) |  |

private

Outputs sample at index to output stream in VTK XML format.

References dataArray, rank, and shape.

Referenced by writeToVTK().

## writeToSilo()

bool weipa::DataVar::writeToSilo | ( | DBfile * | dbfile,
|  | const std::string & | siloPath,
|  | const std::string & | units
| ) |  |

Writes the data into given directory within a Silo file.

If Silo was not available at compile time this method returns false.

References centering, dataArray, initialized, weipa::NODE_CENTERED, numSamples, rank, shape, siloMeshName, and varName.

## writeToVTK()

void weipa::DataVar::writeToVTK | ( | std::ostream & | os,
|  | int | ownIndex
| ) |  |

Writes the data values to ostream in VTK text format.

References buildIndexMap(), domain, isNodeCentered(), meshName, numSamples, and sampleToStream().

## Member Data Documentation

## centering

Centering weipa::DataVar::centering

private

Referenced by initFromEscript(), initFromFile(), initFromMeshData(), isNodeCentered(), reorderSamples(), and writeToSilo().

## dataArray

CoordArray weipa::DataVar::dataArray

private

Referenced by cleanup(), DataVar(), getData(), getDataFlat(), initFromEscript(), initFromFile(), initFromMeshData(), reorderSamples(), sampleToStream(), and writeToSilo().

## domain

const_DomainChunk_ptr weipa::DataVar::domain

private

Referenced by averageData(), initFromEscript(), initFromFile(), initFromMeshData(), reorderSamples(), and writeToVTK().

## funcSpace

int weipa::DataVar::funcSpace

private

Referenced by averageData(), initFromEscript(), initFromFile(), and reorderSamples().

## initialized

bool weipa::DataVar::initialized

private

Referenced by cleanup(), getTensorDef(), initFromEscript(), initFromFile(), initFromMeshData(), and writeToSilo().

## meshName

std::string weipa::DataVar::meshName

private

Referenced by getMeshName(), initFromEscript(), initFromFile(), initFromMeshData(), and writeToVTK().

## numSamples

int weipa::DataVar::numSamples

private

Referenced by averageData(), cleanup(), DataVar(), getDataFlat(), getNumberOfSamples(), initFromEscript(), initFromFile(), initFromMeshData(), reorderSamples(), writeToSilo(), and writeToVTK().

## ptsPerSample

int weipa::DataVar::ptsPerSample

private

Referenced by averageData(), initFromEscript(), initFromFile(), and initFromMeshData().

## rank

int weipa::DataVar::rank

private

Referenced by getDataFlat(), getNumberOfComponents(), getRank(), getTensorDef(), initFromEscript(), initFromFile(), initFromMeshData(), sampleToStream(), and writeToSilo().

## sampleID

IntVec weipa::DataVar::sampleID

private

Referenced by buildIndexMap(), cleanup(), initFromEscript(), initFromFile(), initFromMeshData(), and reorderSamples().

## shape

IntVec weipa::DataVar::shape

private

Referenced by cleanup(), getDataFlat(), getNumberOfComponents(), getShape(), getTensorDef(), initFromEscript(), initFromFile(), sampleToStream(), and writeToSilo().

## siloMeshName

std::string weipa::DataVar::siloMeshName

private

Referenced by initFromEscript(), initFromFile(), initFromMeshData(), and writeToSilo().

## varName

std::string weipa::DataVar::varName

private

Referenced by getName(), getTensorDef(), initFromEscript(), initFromFile(), reorderSamples(), and writeToSilo().

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

- DataVar.h
- DataVar.cpp