escript  Revision_
DataVar.h
Go to the documentation of this file.
1 
2 /*****************************************************************************
3 *
4 * Copyright (c) 2003-2016 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 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 
131  IndexMap buildIndexMap();
132 
138  bool reorderSamples();
139 
141  void sampleToStream(std::ostream& os, int index);
142 
145  std::string varName;
146  int numSamples, rank, ptsPerSample, funcSpace;
151  std::string meshName, siloMeshName;
152 };
153 
154 inline IndexMap DataVar::buildIndexMap()
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 getName() const
Returns the variable name.
Definition: DataVar.h:94
std::vector< float * > CoordArray
Definition: weipa.h:61
const IntVec & getShape() const
Returns the shape vector of the data.
Definition: DataVar.h:91
Definition: AbstractContinuousDomain.cpp:22
bool initialized
Definition: DataVar.h:143
IntVec sampleID
Definition: DataVar.h:149
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
Definition: DataVar.cpp:39
std::vector< int > IntVec
Definition: weipa.h:59
int getNumberOfSamples() const
Returns the number of data values.
Definition: DataVar.h:105
std::map< int, size_t > IndexMap
Definition: weipa.h:62
Data represents a collection of datapoints.
Definition: Data.h:63
const_DomainChunk_ptr domain
Definition: DataVar.h:144
std::string siloMeshName
Definition: DataVar.h:151
IntVec shape
Definition: DataVar.h:148
Centering
Definition: DomainChunk.h:30
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
CoordArray dataArray
Definition: DataVar.h:150
int getRank() const
Returns the rank of the data.
Definition: DataVar.h:75
boost::shared_ptr< const DomainChunk > const_DomainChunk_ptr
Definition: weipa.h:70
boost::shared_ptr< NodeData > NodeData_ptr
Definition: weipa.h:68
std::string getMeshName() const
Returns the name of the associated mesh.
Definition: DataVar.h:86
std::string varName
Definition: DataVar.h:145
Centering centering
Definition: DataVar.h:147