DataVar.h
Go to the documentation of this file.
/*****************************************************************************
*
* Copyright (c) 2003-2017 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 by Centre for Geoscience Computing (GeoComp)
*
*****************************************************************************/
#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__
weipa::DataVar::getName
std::string getName() const
Returns the variable name.
Definition: DataVar.h:94
weipa::CoordArray
std::vector< float * > CoordArray
Definition: weipa.h:61
weipa::DataVar::getShape
const IntVec & getShape() const
Returns the shape vector of the data.
Definition: DataVar.h:91
escript
Definition: AbstractContinuousDomain.cpp:22
weipa::DataVar::initialized
bool initialized
Definition: DataVar.h:143
weipa::DataVar::sampleID
IntVec sampleID
Definition: DataVar.h:149
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:109
weipa
Definition: DataVar.cpp:50
weipa::IntVec
std::vector< int > IntVec
Definition: weipa.h:59
weipa::DataVar::getNumberOfSamples
int getNumberOfSamples() const
Returns the number of data values.
Definition: DataVar.h:105
weipa::IndexMap
std::map< int, size_t > IndexMap
Definition: weipa.h:62
escript::Data
Data represents a collection of datapoints.
Definition: Data.h:63
weipa::DataVar::domain
const_DomainChunk_ptr domain
Definition: DataVar.h:144
weipa::DataVar::siloMeshName
std::string siloMeshName
Definition: DataVar.h:151
weipa::DataVar::shape
IntVec shape
Definition: DataVar.h:148
weipa::Centering
Centering
Definition: DomainChunk.h:30
weipa::DataVar::rank
int rank
Definition: DataVar.h:146
weipa::DataVar
A class that provides functionality to read an escript data object from a dump file or an escript::Da...
Definition: DataVar.h:35
weipa::DataVar::dataArray
CoordArray dataArray
Definition: DataVar.h:150
weipa::DataVar::getRank
int getRank() const
Returns the rank of the data.
Definition: DataVar.h:75
weipa::const_DomainChunk_ptr
boost::shared_ptr< const DomainChunk > const_DomainChunk_ptr
Definition: weipa.h:70
weipa::NodeData_ptr
boost::shared_ptr< NodeData > NodeData_ptr
Definition: weipa.h:68
weipa::DataVar::getMeshName
std::string getMeshName() const
Returns the name of the associated mesh.
Definition: DataVar.h:86
weipa::DataVar::varName
std::string varName
Definition: DataVar.h:145
weipa::DataVar::centering
Centering centering
Definition: DataVar.h:147