DataVar.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 __WEIPA_DATAVAR_H__
#define __WEIPA_DATAVAR_H__
#include <weipa/DomainChunk.h>
#include <ostream>
class DBfile;
//class NcFile;
namespace escript {
class Data;
}
namespace weipa {
class DataVar
{
public:
DataVar(const std::string& name);
DataVar(const DataVar& d);
~DataVar();
bool initFromEscript(escript::Data& escriptData, const_DomainChunk_ptr dom);
bool initFromMeshData(const_DomainChunk_ptr dom, const IntVec& data,
int fsCode, Centering c, NodeData_ptr nodes, const IntVec& id);
bool initFromFile(const std::string& filename, const_DomainChunk_ptr dom);
bool writeToSilo(DBfile* dbfile, const std::string& siloPath,
const std::string& units);
void writeToVTK(std::ostream& os, int ownIndex);
int getRank() const { return rank; }
bool isNodeCentered() const;
std::string getMeshName() const { return meshName; }
const IntVec& getShape() const { return shape; }
std::string getName() const { return varName; }
std::string getTensorDef() const;
int getNumberOfSamples() const { return numSamples; }
const CoordArray& getData() const { return dataArray; }
float* getDataFlat() const;
int getNumberOfComponents() const;
private:
void cleanup();
float* averageData(const float* src, size_t stride);
IndexMap buildIndexMap();
bool reorderSamples();
void sampleToStream(std::ostream& os, int index);
bool initialized;
const_DomainChunk_ptr domain;
std::string varName;
int numSamples, rank, ptsPerSample, funcSpace;
Centering centering;
IntVec shape;
IntVec sampleID;
CoordArray dataArray;
std::string meshName, siloMeshName;
};
inline IndexMap DataVar::buildIndexMap()
{
IndexMap sampleID2idx;
int idx = sampleID.size()-1;
// see this thread for why this is done the way it's done:
// http://www.tech-archive.net/Archive/VC/microsoft.public.vc.stl/2005-01/0075.html
IntVec::const_reverse_iterator idIt = sampleID.rbegin();
IntVec::const_reverse_iterator endIt = sampleID.rend();
for (; idIt != endIt; idIt++, idx--)
sampleID2idx[*idIt] = idx;
return sampleID2idx;
}
} // namespace weipa
#endif // __WEIPA_DATAVAR_H__
escript::Data::getNumDataPointsPerSample
int getNumDataPointsPerSample() const
Return the number of data points per sample.
Definition: Data.h:544
escript::DataTypes::real_t
double real_t
type of all real-valued scalars in escript
Definition: DataTypes.h:79
weipa::DataVar::sampleID
IntVec sampleID
Definition: DataVar.h:150
weipa::DataVar::getMeshName
std::string getMeshName() const
Returns the name of the associated mesh.
Definition: DataVar.h:87
weipa::DataVar::varName
std::string varName
Definition: DataVar.h:146
weipa::DataVar::buildIndexMap
IndexMap buildIndexMap()
Prepares a sample ID -> index mapping which is used to reorder data.
Definition: DataVar.h:155
weipa::DataVar::cleanup
void cleanup()
Definition: DataVar.cpp:92
weipa::DataVar::siloMeshName
std::string siloMeshName
Definition: DataVar.h:152
weipa::DataVar::domain
const_DomainChunk_ptr domain
Definition: DataVar.h:145
escript::Data::getSampleDataRO
const DataTypes::real_t * getSampleDataRO(DataTypes::RealVectorType::size_type sampleNo, DataTypes::real_t dummy=0) const
Return the sample data for the given sample no. Please do not use this unless you NEED to access samp...
Definition: Data.h:1989
weipa::QuadMaskInfo::mask
std::vector< IntVec > mask
Definition: ElementData.h:55
weipa::VisItControl::initialized
bool initialized
Definition: VisItControl.cpp:66
escript::Data::getDataPointShape
const DataTypes::ShapeType & getDataPointShape() const
Return a reference to the data point shape.
Definition: Data.h:705
weipa::DataVar::centering
Centering centering
Definition: DataVar.h:148
weipa::DataVar::DataVar
DataVar(const std::string &name)
Constructor with variable name.
Definition: DataVar.cpp:56
weipa::QuadMaskInfo
This struct holds a mask (0's and 1's) that indicates which quad nodes contribute to a sub-element wh...
Definition: ElementData.h:54
escript::Data::isConstant
bool isConstant() const
Return true if this Data is constant.
Definition: Data.cpp:1139
weipa::DataVar::reorderSamples
bool reorderSamples()
Reorders the samples according to the corresponding node or element IDs.
Definition: DataVar.cpp:504
weipa::DataVar::getDataFlat
float * getDataFlat() const
Returns a flattened array of data values, i.e. the ordering is s0c0 s0c1 s0c2 s1c0 s1c1 s1c2 s2c0 ....
Definition: DataVar.cpp:578
weipa::DataVar::getRank
int getRank() const
Returns the rank of the data.
Definition: DataVar.h:76
escript::Data::getFunctionSpace
const FunctionSpace & getFunctionSpace() const
Return the function space.
Definition: Data.h:463
weipa
Definition: DataVar.cpp:51
weipa::QuadMaskInfo::factor
IntVec factor
Definition: ElementData.h:56
weipa::DataVar::initFromFile
bool initFromFile(const std::string &filename, const_DomainChunk_ptr dom)
Reads values and IDs for this variable from an escript dump file.
Definition: DataVar.cpp:336
escript::Data::getNumSamples
int getNumSamples() const
Return the number of samples.
Definition: Data.h:533
paso::util::copy
void copy(dim_t N, double *out, const double *in)
out = in
Definition: PasoUtil.h:116
weipa::DataVar::averageData
float * averageData(const float *src, size_t stride)
Averages and filters data.
Definition: DataVar.cpp:455
escript::Data
Data represents a collection of datapoints.
Definition: Data.h:64
weipa::DataVar::sampleToStream
void sampleToStream(std::ostream &os, int index)
Outputs sample at index to output stream in VTK XML format.
Definition: DataVar.cpp:608
escript::DataTypes::dim_t
index_t dim_t
Definition: DataTypes.h:93
weipa::DataVar::initFromEscript
bool initFromEscript(escript::Data &escriptData, const_DomainChunk_ptr dom)
Initialises values and IDs from an escript::Data instance.
Definition: DataVar.cpp:107
weipa::DataVar::getName
std::string getName() const
Returns the variable name.
Definition: DataVar.h:95
weipa::IndexMap
std::map< int, size_t > IndexMap
Definition: weipa.h:63
weipa::CoordArray
std::vector< float * > CoordArray
Definition: weipa.h:62
weipa::DataVar::shape
IntVec shape
Definition: DataVar.h:149
weipa::ElementData_ptr
boost::shared_ptr< ElementData > ElementData_ptr
Definition: weipa.h:67
weipa::NODE_CENTERED
@ NODE_CENTERED
Definition: DomainChunk.h:32
weipa::DataVar::writeToVTK
void writeToVTK(std::ostream &os, int ownIndex)
Writes the data values to ostream in VTK text format.
Definition: DataVar.cpp:654
escript::Data::getDataRO
const DataTypes::real_t * getDataRO(DataTypes::real_t dummy=0) const
Return a pointer to the beginning of the underlying data.
Definition: Data.h:2016
weipa::DataVar::isNodeCentered
bool isNodeCentered() const
Returns true if the variable data is node centered, false if zone centered.
Definition: DataVar.cpp:444
weipa::DataVar::writeToSilo
bool writeToSilo(DBfile *dbfile, const std::string &siloPath, const std::string &units)
Writes the data into given directory within a Silo file.
Definition: DataVar.cpp:739
weipa::DataVar::dataArray
CoordArray dataArray
Definition: DataVar.h:151
weipa::DataVar::getData
const CoordArray & getData() const
Returns the array of data values where array[i] is the i-th component of the data.
Definition: DataVar.h:110
weipa::DataVar::~DataVar
~DataVar()
Destructor.
Definition: DataVar.cpp:84
weipa::DataVar::getNumberOfSamples
int getNumberOfSamples() const
Returns the number of data values.
Definition: DataVar.h:106
weipa::DataVar::ptsPerSample
int ptsPerSample
Definition: DataVar.h:147
weipa::DataVar::funcSpace
int funcSpace
Definition: DataVar.h:147
escript
Definition: AbstractContinuousDomain.cpp:23
weipa::DataVar::meshName
std::string meshName
Definition: DataVar.h:152
weipa::DataVar::initFromMeshData
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.
Definition: DataVar.cpp:203
weipa::DataVar::initialized
bool initialized
Definition: DataVar.h:144
weipa::DataVar::getTensorDef
std::string getTensorDef() const
Returns the Silo tensor definition for this tensor.
Definition: DataVar.cpp:697
weipa::NodeData_ptr
boost::shared_ptr< NodeData > NodeData_ptr
Definition: weipa.h:69
weipa::DataVar::getNumberOfComponents
int getNumberOfComponents() const
Returns the total number of components (sum of shape elements).
Definition: DataVar.cpp:570
escript::FunctionSpace::getTypeCode
int getTypeCode() const
Returns the function space type code.
Definition: FunctionSpace.cpp:95
escript::FunctionSpace::borrowSampleReferenceIDs
const DataTypes::dim_t * borrowSampleReferenceIDs() const
Returns a borrowed reference to the list of sample reference IDs.
Definition: FunctionSpace.cpp:199
escript::Data::actsExpanded
bool actsExpanded() const
Return true if this Data is expanded or resolves to expanded. That is, if it has a separate value for...
Definition: Data.cpp:1118
weipa::DataVar::getShape
const IntVec & getShape() const
Returns the shape vector of the data.
Definition: DataVar.h:92
weipa::Centering
Centering
Definition: DomainChunk.h:31
weipa::IntVec
std::vector< int > IntVec
Definition: weipa.h:60
weipa::DataVar
A class that provides functionality to read an escript data object from a dump file or an escript::Da...
Definition: DataVar.h:36
weipa::DataVar::rank
int rank
Definition: DataVar.h:147
weipa::DataVar::numSamples
int numSamples
Definition: DataVar.h:147
weipa::const_DomainChunk_ptr
boost::shared_ptr< const DomainChunk > const_DomainChunk_ptr
Definition: weipa.h:71
escript::Data::getDataPointRank
unsigned int getDataPointRank() const
Return the rank of the point data.
Definition: Data.h:512