escript  Revision_4925
DataVar.h
Go to the documentation of this file.
1 
2 /*****************************************************************************
3 *
4 * Copyright (c) 2003-2014 by University of Queensland
5 * http://www.uq.edu.au
6 *
7 * Primary Business: Queensland, Australia
8 * Licensed under the Open Software License version 3.0
9 * http://www.opensource.org/licenses/osl-3.0.php
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 by Centre for Geoscience Computing (GeoComp)
14 *
15 *****************************************************************************/
16 
17 #ifndef __WEIPA_DATAVAR_H__
18 #define __WEIPA_DATAVAR_H__
19 
20 #include <weipa/DomainChunk.h>
21 #include <ostream>
22 
23 class DBfile;
24 class NcFile;
25 
26 namespace escript {
27  class Data;
28 }
29 
30 namespace weipa {
31 
35 class DataVar
36 {
37 public:
39  DataVar(const std::string& name);
40 
42  DataVar(const DataVar& d);
43 
45  ~DataVar();
46 
51  bool initFromEscript(escript::Data& escriptData, const_DomainChunk_ptr dom);
52 
54  bool initFromMeshData(const_DomainChunk_ptr dom, const IntVec& data,
55  int fsCode, Centering c, NodeData_ptr nodes, const IntVec& id);
56 
63  bool initFromFile(const std::string& filename, const_DomainChunk_ptr dom);
64 
68  bool writeToSilo(DBfile* dbfile, const std::string& siloPath,
69  const std::string& units);
70 
72  void writeToVTK(std::ostream& os, int ownIndex);
73 
75  int getRank() const { return rank; }
76 
79  bool isNodeCentered() const;
80 
86  std::string getMeshName() const { return meshName; }
87 
91  const IntVec& getShape() const { return shape; }
92 
94  std::string getName() const { return varName; }
95 
102  std::string getTensorDef() const;
103 
105  int getNumberOfSamples() const { return numSamples; }
106 
109  const CoordArray& getData() const { return dataArray; }
110 
114  float* getDataFlat() const;
115 
117  int getNumberOfComponents() const;
118 
119 private:
120  void cleanup();
121 
127  float* averageData(const float* src, size_t stride);
128 
132 
138  bool reorderSamples();
139 
141  void sampleToStream(std::ostream& os, int index);
142 
145  std::string varName;
151  std::string meshName, siloMeshName;
152 };
153 
155 {
156  IndexMap sampleID2idx;
157  int idx = sampleID.size()-1;
158  // see this thread for why this is done the way it's done:
159  // http://www.tech-archive.net/Archive/VC/microsoft.public.vc.stl/2005-01/0075.html
160  IntVec::const_reverse_iterator idIt = sampleID.rbegin();
161  IntVec::const_reverse_iterator endIt = sampleID.rend();
162  for (; idIt != endIt; idIt++, idx--)
163  sampleID2idx[*idIt] = idx;
164 
165  return sampleID2idx;
166 }
167 
168 } // namespace weipa
169 
170 #endif // __WEIPA_DATAVAR_H__
171 
std::string meshName
Definition: DataVar.h:151
std::vector< float * > CoordArray
Definition: weipa.h:57
bool reorderSamples()
Reorders the samples according to the corresponding node or element IDs.
Definition: DataVar.cpp:387
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:191
bool initialized
Definition: DataVar.h:143
IntVec sampleID
Definition: DataVar.h:149
void sampleToStream(std::ostream &os, int index)
Outputs sample at index to output stream in VTK XML format.
Definition: DataVar.cpp:491
IndexMap buildIndexMap()
Prepares a sample ID -> index mapping which is used to reorder data.
Definition: DataVar.h:154
std::string getName() const
Returns the variable name.
Definition: DataVar.h:94
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:622
void writeToVTK(std::ostream &os, int ownIndex)
Writes the data values to ostream in VTK text format.
Definition: DataVar.cpp:537
std::string getMeshName() const
Returns the name of the associated mesh.
Definition: DataVar.h:86
int numSamples
Definition: DataVar.h:146
const IntVec & getShape() const
Returns the shape vector of the data.
Definition: DataVar.h:91
int ptsPerSample
Definition: DataVar.h:146
int funcSpace
Definition: DataVar.h:146
std::vector< int > IntVec
Definition: weipa.h:55
~DataVar()
Destructor.
Definition: DataVar.cpp:72
std::map< int, size_t > IndexMap
Definition: weipa.h:58
Data represents a collection of datapoints.
Definition: Data.h:71
bool initFromEscript(escript::Data &escriptData, const_DomainChunk_ptr dom)
Initialises values and IDs from an escript::Data instance.
Definition: DataVar.cpp:95
const_DomainChunk_ptr domain
Definition: DataVar.h:144
std::string siloMeshName
Definition: DataVar.h:151
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:220
IntVec shape
Definition: DataVar.h:148
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
float * averageData(const float *src, size_t stride)
Averages and filters data.
Definition: DataVar.cpp:338
int getNumberOfComponents() const
Returns the total number of components (sum of shape elements).
Definition: DataVar.cpp:453
bool isNodeCentered() const
Returns true if the variable data is node centered, false if zone centered.
Definition: DataVar.cpp:327
Centering
Definition: DomainChunk.h:30
void cleanup()
Definition: DataVar.cpp:80
int rank
Definition: DataVar.h:146
A class that provides functionality to read an escript data object from a dump file or an escript::Da...
Definition: DataVar.h:35
DataVar(const std::string &name)
Constructor with variable name.
Definition: DataVar.cpp:44
CoordArray dataArray
Definition: DataVar.h:150
int getRank() const
Returns the rank of the data.
Definition: DataVar.h:75
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:461
boost::shared_ptr< const DomainChunk > const_DomainChunk_ptr
Definition: weipa.h:66
int getNumberOfSamples() const
Returns the number of data values.
Definition: DataVar.h:105
std::string getTensorDef() const
Returns the Silo tensor definition for this tensor.
Definition: DataVar.cpp:580
boost::shared_ptr< NodeData > NodeData_ptr
Definition: weipa.h:64
std::string varName
Definition: DataVar.h:145
Centering centering
Definition: DataVar.h:147