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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2886 - (show annotations)
Thu Jan 28 05:39:23 2010 UTC (9 years, 6 months ago) by caltinay
File MIME type: text/plain
File size: 5788 byte(s)
New version of saveVTK within dataexporter. Not pythonised yet since it needs
more testing and release 3.1 will not ship dataexporter.

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 <escriptexport/escriptexport.h>
18 #include <ostream>
19
20 class DBfile;
21 class NcFile;
22
23 namespace escript {
24 class Data;
25 }
26
27 namespace escriptexport {
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 ESCRIPTEXPORT_DLL_API
39 DataVar(const std::string& name);
40
41 /// \brief Copy constructor. Performs a deep copy of the data values.
42 ESCRIPTEXPORT_DLL_API
43 DataVar(const DataVar& d);
44
45 /// \brief Destructor
46 ESCRIPTEXPORT_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 ESCRIPTEXPORT_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 ESCRIPTEXPORT_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 ESCRIPTEXPORT_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 ESCRIPTEXPORT_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 ESCRIPTEXPORT_DLL_API
80 void writeToVTK(std::ostream& os, int ownIndex);
81
82 /// \brief Returns the rank of the data.
83 ESCRIPTEXPORT_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 ESCRIPTEXPORT_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 ESCRIPTEXPORT_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 ESCRIPTEXPORT_DLL_API
103 const IntVec& getShape() const { return shape; }
104
105 /// \brief Returns the variable name.
106 ESCRIPTEXPORT_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 ESCRIPTEXPORT_DLL_API
116 std::string getTensorDef() const;
117
118 /// \brief Returns the number of data values.
119 ESCRIPTEXPORT_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 ESCRIPTEXPORT_DLL_API
125 const CoordArray& getData() const { return dataArray; }
126
127 private:
128 void cleanup();
129
130 /// \brief Averages and filters data.
131 ///
132 /// If a sample consists of more than one data point then this method
133 /// averages over the data points and returns the resulting array.
134 /// In any case, the data is filtered according to the stride value.
135 float* averageData(const float* src, size_t stride);
136
137 /// \brief Prepares a sample ID -> index mapping which is used to reorder
138 /// data.
139 IndexMap buildIndexMap();
140
141 /// \brief Reorders the samples according to the corresponding node or
142 /// element IDs.
143 ///
144 /// \return true if the function space is supported and the number of
145 /// elements or nodes matches the number of data samples.
146 bool reorderSamples();
147
148 /// \brief Outputs sample at index to output stream in VTK XML format
149 void sampleToStream(std::ostream& os, int index);
150
151 bool initialized;
152 FinleyMesh_ptr finleyMesh;
153 std::string varName;
154 int numSamples, rank, ptsPerSample, centering, funcSpace;
155 IntVec shape;
156 IntVec sampleID;
157 CoordArray dataArray;
158 std::string meshName, siloMeshName;
159 };
160
161 inline IndexMap DataVar::buildIndexMap()
162 {
163 IndexMap sampleID2idx;
164 int idx = sampleID.size()-1;
165 IntVec::const_reverse_iterator idIt;
166 for (idIt = sampleID.rbegin(); idIt != sampleID.rend(); idIt++, idx--)
167 sampleID2idx[*idIt] = idx;
168
169 return sampleID2idx;
170 }
171
172 } // namespace escriptexport
173
174 #endif // __DATAVAR_H__
175

  ViewVC Help
Powered by ViewVC 1.1.26