escript  Revision_
Public Member Functions | Private Member Functions | Private Attributes | List of all members
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 IntVecgetShape () 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 CoordArraygetData () 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 ( )
inlineprivate

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

Referenced by reorderSamples(), and writeToVTK().

◆ cleanup()

void weipa::DataVar::cleanup ( )
private

◆ 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.

◆ 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.

◆ getName()

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

Returns the variable name.

◆ 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.

◆ getRank()

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

Returns the rank of the data.

◆ 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.

◆ 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 
)

◆ 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

◆ dataArray

CoordArray weipa::DataVar::dataArray
private

◆ domain

const_DomainChunk_ptr weipa::DataVar::domain
private

◆ funcSpace

int weipa::DataVar::funcSpace
private

◆ initialized

bool weipa::DataVar::initialized
private

◆ meshName

std::string weipa::DataVar::meshName
private

◆ numSamples

int weipa::DataVar::numSamples
private

◆ ptsPerSample

int weipa::DataVar::ptsPerSample
private

◆ rank

int weipa::DataVar::rank
private

◆ sampleID

IntVec weipa::DataVar::sampleID
private

◆ shape

IntVec weipa::DataVar::shape
private

◆ siloMeshName

std::string weipa::DataVar::siloMeshName
private

◆ varName

std::string weipa::DataVar::varName
private

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