/[escript]/trunk/weipa/src/DataVar.h
ViewVC logotype

Contents of /trunk/weipa/src/DataVar.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3092 - (show annotations)
Fri Aug 13 07:55:03 2010 UTC (9 years ago) by caltinay
File MIME type: text/plain
File size: 6215 byte(s)
Added getDataFlat() which will be used by the VisIt simulation interface

1
2 /*******************************************************
3 *
4 * Copyright (c) 2003-2010 by University of Queensland
5 * Earth Systems Science Computational Center (ESSCC)
6 * http://www.uq.edu.au/esscc
7 *
8 * Primary Business: Queensland, Australia
9 * Licensed under the Open Software License version 3.0
10 * http://www.opensource.org/licenses/osl-3.0.php
11 *
12 *******************************************************/
13
14 #ifndef __DATAVAR_H__
15 #define __DATAVAR_H__
16
17 #include <weipa/weipa.h>
18 #include <ostream>
19
20 class DBfile;
21 class NcFile;
22
23 namespace escript {
24 class Data;
25 }
26
27 namespace weipa {
28
29 class FinleyMesh;
30
31 /// \brief A class that provides functionality to read an escript data object
32 /// from NetCDF file or an escript::Data instance and write that data in Silo
33 /// or VTK XML formats.
34 class DataVar
35 {
36 public:
37 /// \brief Constructor with variable name
38 WEIPA_DLL_API
39 DataVar(const std::string& name);
40
41 /// \brief Copy constructor. Performs a deep copy of the data values.
42 WEIPA_DLL_API
43 DataVar(const DataVar& d);
44
45 /// \brief Destructor
46 WEIPA_DLL_API
47 ~DataVar();
48
49 /// \brief Initialises values and IDs from an escript::Data instance.
50 ///
51 /// \return true if a valid instance of expanded data was supplied,
52 /// false if the initialisation was unsuccessful.
53 WEIPA_DLL_API
54 bool initFromEscript(escript::Data& escriptData, FinleyMesh_ptr mesh);
55
56 /// \brief Initialises with integral mesh data like IDs or tags.
57 ///
58 /// The data is retrieved from the mesh using the variable name.
59 WEIPA_DLL_API
60 bool initFromMesh(FinleyMesh_ptr mesh);
61
62 /// \brief Reads values and IDs for this variable from escript NetCDF file.
63 ///
64 /// \return true if the file was found and contains valid escript data
65 /// with at least one sample, false otherwise.
66 /// \note Only expanded data with rank <=2 is supported at the moment.
67 WEIPA_DLL_API
68 bool initFromNetCDF(const std::string& filename, FinleyMesh_ptr mesh);
69
70 /// \brief Writes the data into given directory in given Silo file.
71 ///
72 /// If Silo was not available at compile time or the mesh was not set
73 /// beforehand using setMesh() or if a Silo function fails this method
74 /// returns false.
75 WEIPA_DLL_API
76 bool writeToSilo(DBfile* dbfile, const std::string& siloPath);
77
78 /// \brief Writes the data values to ostream in VTK text format.
79 WEIPA_DLL_API
80 void writeToVTK(std::ostream& os, int ownIndex);
81
82 /// \brief Returns the rank of the data.
83 WEIPA_DLL_API
84 int getRank() const { return rank; }
85
86 /// \brief Returns true if the variable data is node centered, false if
87 /// zone centered.
88 WEIPA_DLL_API
89 bool isNodeCentered() const;
90
91 /// \brief Returns the name of the associated mesh.
92 ///
93 /// The returned name is one of the sub-meshes of the mesh set with
94 /// setMesh() determined on the basis of the function space type and
95 /// whether reduced elements are used or not.
96 WEIPA_DLL_API
97 std::string getMeshName() const { return meshName; }
98
99 /// \brief Returns the shape vector of the data.
100 ///
101 /// The shape vector has as many elements as the rank of this variable.
102 WEIPA_DLL_API
103 const IntVec& getShape() const { return shape; }
104
105 /// \brief Returns the variable name.
106 WEIPA_DLL_API
107 std::string getName() const { return varName; }
108
109 /// \brief Returns the Silo tensor definition for this tensor.
110 ///
111 /// If the data is tensor data then the components of the tensor are stored
112 /// separately in the Silo file. This method then returns a string that
113 /// contains the proper Silo expression to put the tensor together again.
114 /// For non-tensor data this method returns an empty string.
115 WEIPA_DLL_API
116 std::string getTensorDef() const;
117
118 /// \brief Returns the number of data values.
119 WEIPA_DLL_API
120 int getNumberOfSamples() const { return numSamples; }
121
122 /// \brief Returns the array of data values where array[i] is the i-th
123 /// component of the data.
124 WEIPA_DLL_API
125 const CoordArray& getData() const { return dataArray; }
126
127 /// \brief Returns a flattened array of data values, i.e. the ordering is
128 /// s0c0 s0c1 s0c2 s1c0 s1c1 s1c2 s2c0 ...
129 /// where s denotes the sample number and c the component.
130 WEIPA_DLL_API
131 float* getDataFlat() const;
132
133 /// \brief Returns the total number of components (sum of shape elements).
134 WEIPA_DLL_API
135 int getNumberOfComponents() const;
136
137 private:
138 void cleanup();
139
140 /// \brief Averages and filters data.
141 ///
142 /// If a sample consists of more than one data point then this method
143 /// averages over the data points and returns the resulting array.
144 /// In any case, the data is filtered according to the stride value.
145 float* averageData(const float* src, size_t stride);
146
147 /// \brief Prepares a sample ID -> index mapping which is used to reorder
148 /// data.
149 IndexMap buildIndexMap();
150
151 /// \brief Reorders the samples according to the corresponding node or
152 /// element IDs.
153 ///
154 /// \return true if the function space is supported and the number of
155 /// elements or nodes matches the number of data samples.
156 bool reorderSamples();
157
158 /// \brief Outputs sample at index to output stream in VTK XML format
159 void sampleToStream(std::ostream& os, int index);
160
161 bool initialized;
162 FinleyMesh_ptr finleyMesh;
163 std::string varName;
164 int numSamples, rank, ptsPerSample, centering, funcSpace;
165 IntVec shape;
166 IntVec sampleID;
167 CoordArray dataArray;
168 std::string meshName, siloMeshName;
169 };
170
171 inline IndexMap DataVar::buildIndexMap()
172 {
173 IndexMap sampleID2idx;
174 int idx = sampleID.size()-1;
175 // see this thread for why this is done the way it's done:
176 // http://www.tech-archive.net/Archive/VC/microsoft.public.vc.stl/2005-01/0075.html
177 IntVec::const_reverse_iterator idIt = sampleID.rbegin();
178 IntVec::const_reverse_iterator endIt = sampleID.rend();
179 for (; idIt != endIt; idIt++, idx--)
180 sampleID2idx[*idIt] = idx;
181
182 return sampleID2idx;
183 }
184
185 } // namespace weipa
186
187 #endif // __DATAVAR_H__
188

  ViewVC Help
Powered by ViewVC 1.1.26