escript  Revision_
Public Member Functions | Private Member Functions | Private Attributes
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>

List of all members.

Public Member Functions

 DataVar (const std::string &name)
 Constructor with variable name.
 DataVar (const DataVar &d)
 Copy constructor. Performs a deep copy of the data values.
 ~DataVar ()
 Destructor.
bool initFromEscript (escript::Data &escriptData, const_DomainChunk_ptr dom)
 Initialises values and IDs from an escript::Data instance.
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.
bool initFromFile (const std::string &filename, const_DomainChunk_ptr dom)
 Reads values and IDs for this variable from an escript dump file.
bool writeToSilo (DBfile *dbfile, const std::string &siloPath, const std::string &units)
 Writes the data into given directory within a Silo file.
void writeToVTK (std::ostream &os, int ownIndex)
 Writes the data values to ostream in VTK text format.
int getRank () const
 Returns the rank of the data.
bool isNodeCentered () const
 Returns true if the variable data is node centered, false if zone centered.
std::string getMeshName () const
 Returns the name of the associated mesh.
const IntVecgetShape () const
 Returns the shape vector of the data.
std::string getName () const
 Returns the variable name.
std::string getTensorDef () const
 Returns the Silo tensor definition for this tensor.
int getNumberOfSamples () const
 Returns the number of data values.
const CoordArraygetData () const
 Returns the array of data values where array[i] is the i-th component of the data.
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.
int getNumberOfComponents () const
 Returns the total number of components (sum of shape elements).

Private Member Functions

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

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

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

Constructor with variable name.

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

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

Destructor.

References cleanup().


Member Function Documentation

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().

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().

void weipa::DataVar::cleanup ( ) [private]
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.

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.

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.

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

Returns the variable name.

References varName.

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

References rank, and shape.

Referenced by getDataFlat().

int weipa::DataVar::getNumberOfSamples ( ) const [inline]

Returns the number of data values.

References numSamples.

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

Returns the rank of the data.

References rank.

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.

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.

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.

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.

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

References centering, and weipa::NODE_CENTERED.

Referenced by writeToVTK().

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().

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().

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.

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

std::string weipa::DataVar::meshName [private]
int weipa::DataVar::rank [private]
std::string weipa::DataVar::siloMeshName [private]
std::string weipa::DataVar::varName [private]

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