escript  Revision_
DataVar.h
Go to the documentation of this file.
1 
2 /*****************************************************************************
3 *
4 * Copyright (c) 2003-2020 by The University of Queensland
5 * http://www.uq.edu.au
6 *
7 * Primary Business: Queensland, Australia
8 * Licensed under the Apache License, version 2.0
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Development until 2012 by Earth Systems Science Computational Center (ESSCC)
12 * Development 2012-2013 by School of Earth Sciences
13 * Development from 2014-2017 by Centre for Geoscience Computing (GeoComp)
14 * Development from 2019 by School of Earth and Environmental Sciences
15 **
16 *****************************************************************************/
17 
18 #ifndef __WEIPA_DATAVAR_H__
19 #define __WEIPA_DATAVAR_H__
20 
21 #include <weipa/DomainChunk.h>
22 #include <ostream>
23 
24 class DBfile;
25 //class NcFile;
26 
27 namespace escript {
28  class Data;
29 }
30 
31 namespace weipa {
32 
36 class DataVar
37 {
38 public:
40  DataVar(const std::string& name);
41 
43  DataVar(const DataVar& d);
44 
46  ~DataVar();
47 
52  bool initFromEscript(escript::Data& escriptData, const_DomainChunk_ptr dom);
53 
55  bool initFromMeshData(const_DomainChunk_ptr dom, const IntVec& data,
56  int fsCode, Centering c, NodeData_ptr nodes, const IntVec& id);
57 
64  bool initFromFile(const std::string& filename, const_DomainChunk_ptr dom);
65 
69  bool writeToSilo(DBfile* dbfile, const std::string& siloPath,
70  const std::string& units);
71 
73  void writeToVTK(std::ostream& os, int ownIndex);
74 
76  int getRank() const { return rank; }
77 
80  bool isNodeCentered() const;
81 
87  std::string getMeshName() const { return meshName; }
88 
92  const IntVec& getShape() const { return shape; }
93 
95  std::string getName() const { return varName; }
96 
103  std::string getTensorDef() const;
104 
106  int getNumberOfSamples() const { return numSamples; }
107 
110  const CoordArray& getData() const { return dataArray; }
111 
115  float* getDataFlat() const;
116 
118  int getNumberOfComponents() const;
119 
120 private:
121  void cleanup();
122 
128  float* averageData(const float* src, size_t stride);
129 
133 
139  bool reorderSamples();
140 
142  void sampleToStream(std::ostream& os, int index);
143 
146  std::string varName;
152  std::string meshName, siloMeshName;
153 };
154 
156 {
157  IndexMap sampleID2idx;
158  int idx = sampleID.size()-1;
159  // see this thread for why this is done the way it's done:
160  // http://www.tech-archive.net/Archive/VC/microsoft.public.vc.stl/2005-01/0075.html
161  IntVec::const_reverse_iterator idIt = sampleID.rbegin();
162  IntVec::const_reverse_iterator endIt = sampleID.rend();
163  for (; idIt != endIt; idIt++, idx--)
164  sampleID2idx[*idIt] = idx;
165 
166  return sampleID2idx;
167 }
168 
169 } // namespace weipa
170 
171 #endif // __WEIPA_DATAVAR_H__
172 
Data represents a collection of datapoints.
Definition: Data.h:64
A class that provides functionality to read an escript data object from a dump file or an escript::Da...
Definition: DataVar.h:37
IntVec sampleID
Definition: DataVar.h:150
int getRank() const
Returns the rank of the data.
Definition: DataVar.h:76
const_DomainChunk_ptr domain
Definition: DataVar.h:145
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
void sampleToStream(std::ostream &os, int index)
Outputs sample at index to output stream in VTK XML format.
Definition: DataVar.cpp:608
bool isNodeCentered() const
Returns true if the variable data is node centered, false if zone centered.
Definition: DataVar.cpp:444
bool initialized
Definition: DataVar.h:144
CoordArray dataArray
Definition: DataVar.h:151
Centering centering
Definition: DataVar.h:148
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
int numSamples
Definition: DataVar.h:147
const IntVec & getShape() const
Returns the shape vector of the data.
Definition: DataVar.h:92
~DataVar()
Destructor.
Definition: DataVar.cpp:84
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
int getNumberOfComponents() const
Returns the total number of components (sum of shape elements).
Definition: DataVar.cpp:570
IndexMap buildIndexMap()
Prepares a sample ID -> index mapping which is used to reorder data.
Definition: DataVar.h:155
std::string getMeshName() const
Returns the name of the associated mesh.
Definition: DataVar.h:87
int funcSpace
Definition: DataVar.h:147
std::string getName() const
Returns the variable name.
Definition: DataVar.h:95
float * averageData(const float *src, size_t stride)
Averages and filters data.
Definition: DataVar.cpp:455
std::string meshName
Definition: DataVar.h:152
std::string siloMeshName
Definition: DataVar.h:152
int rank
Definition: DataVar.h:147
std::string getTensorDef() const
Returns the Silo tensor definition for this tensor.
Definition: DataVar.cpp:697
std::string varName
Definition: DataVar.h:146
void cleanup()
Definition: DataVar.cpp:92
int getNumberOfSamples() const
Returns the number of data values.
Definition: DataVar.h:106
IntVec shape
Definition: DataVar.h:149
int ptsPerSample
Definition: DataVar.h:147
bool initFromEscript(escript::Data &escriptData, const_DomainChunk_ptr dom)
Initialises values and IDs from an escript::Data instance.
Definition: DataVar.cpp:107
DataVar(const std::string &name)
Constructor with variable name.
Definition: DataVar.cpp:56
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
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
bool reorderSamples()
Reorders the samples according to the corresponding node or element IDs.
Definition: DataVar.cpp:504
void writeToVTK(std::ostream &os, int ownIndex)
Writes the data values to ostream in VTK text format.
Definition: DataVar.cpp:654
Definition: AbstractContinuousDomain.cpp:23
Definition: DataVar.cpp:51
Centering
Definition: DomainChunk.h:31
std::vector< int > IntVec
Definition: weipa.h:60
boost::shared_ptr< NodeData > NodeData_ptr
Definition: weipa.h:69
std::vector< float * > CoordArray
Definition: weipa.h:62
std::map< int, size_t > IndexMap
Definition: weipa.h:63
boost::shared_ptr< const DomainChunk > const_DomainChunk_ptr
Definition: weipa.h:71