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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2880 - (hide annotations)
Thu Jan 28 01:21:30 2010 UTC (9 years, 3 months ago) by caltinay
File MIME type: text/plain
File size: 5491 byte(s)
Better resolution for Hex27 & Rec9 data in dataexporter (mantis #486).
Saved Silo data resolution is now equal to finley.SaveVTK generated data in
all cases.

1 caltinay 2183
2     /*******************************************************
3     *
4 jfenwick 2548 * Copyright (c) 2003-2009 by University of Queensland
5 caltinay 2183 * 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 caltinay 2810 #include <escriptexport/escriptexport.h>
18 caltinay 2183
19     class DBfile;
20     class NcFile;
21 caltinay 2187
22 caltinay 2810 namespace escript {
23     class Data;
24     }
25 caltinay 2187
26 caltinay 2810 namespace escriptexport {
27 caltinay 2183
28 caltinay 2810 class FinleyMesh;
29    
30     /// \brief A class that provides functionality to read an escript data object
31     /// from NetCDF file or an escript::Data instance and write that data in Silo
32     /// or VTK XML formats.
33 caltinay 2183 class DataVar
34     {
35     public:
36 caltinay 2206 /// \brief Constructor with variable name
37 caltinay 2810 ESCRIPTEXPORT_DLL_API
38 caltinay 2183 DataVar(const std::string& name);
39    
40 caltinay 2206 /// \brief Copy constructor. Performs a deep copy of the data values.
41 caltinay 2810 ESCRIPTEXPORT_DLL_API
42 caltinay 2183 DataVar(const DataVar& d);
43    
44 caltinay 2206 /// \brief Destructor
45 caltinay 2810 ESCRIPTEXPORT_DLL_API
46 caltinay 2183 ~DataVar();
47    
48 caltinay 2810 /// \brief Initialises values and IDs from an escript::Data instance.
49 caltinay 2206 ///
50 caltinay 2810 /// \return true if a valid instance of expanded data was supplied,
51     /// false if the initialisation was unsuccessful.
52     ESCRIPTEXPORT_DLL_API
53     bool initFromEscript(escript::Data& escriptData, FinleyMesh_ptr mesh);
54 caltinay 2183
55 caltinay 2810 /// \brief Initialises with integral mesh data like IDs or tags.
56 caltinay 2206 ///
57 caltinay 2810 /// The data is retrieved from the mesh using the variable name.
58     ESCRIPTEXPORT_DLL_API
59     bool initFromMesh(FinleyMesh_ptr mesh);
60 caltinay 2183
61 caltinay 2810 /// \brief Reads values and IDs for this variable from escript NetCDF file.
62 caltinay 2206 ///
63 caltinay 2810 /// \return true if the file was found and contains valid escript data
64     /// with at least one sample, false otherwise.
65     /// \note Only expanded data with rank <=2 is supported at the moment.
66     ESCRIPTEXPORT_DLL_API
67     bool initFromNetCDF(const std::string& filename, FinleyMesh_ptr mesh);
68 caltinay 2183
69 caltinay 2206 /// \brief Writes the data into given directory in given Silo file.
70     ///
71 caltinay 2196 /// If Silo was not available at compile time or the mesh was not set
72     /// beforehand using setMesh() or if a Silo function fails this method
73     /// returns false.
74 caltinay 2810 ESCRIPTEXPORT_DLL_API
75 caltinay 2183 bool writeToSilo(DBfile* dbfile, const std::string& siloPath);
76    
77 caltinay 2206 /// \brief Returns the rank of the data.
78 caltinay 2810 ESCRIPTEXPORT_DLL_API
79 caltinay 2183 int getRank() const { return rank; }
80    
81 caltinay 2810 /// \brief Returns true if the variable data is node centered, false if
82     /// zone centered.
83     ESCRIPTEXPORT_DLL_API
84 caltinay 2183 bool isNodeCentered() const;
85    
86 caltinay 2206 /// \brief Returns the name of the associated mesh.
87     ///
88 caltinay 2810 /// The returned name is one of the sub-meshes of the mesh set with
89     /// setMesh() determined on the basis of the function space type and
90     /// whether reduced elements are used or not.
91     ESCRIPTEXPORT_DLL_API
92     std::string getMeshName() const { return meshName; }
93 caltinay 2183
94 caltinay 2206 /// \brief Returns the shape vector of the data.
95     ///
96     /// The shape vector has as many elements as the rank of this variable.
97 caltinay 2810 ESCRIPTEXPORT_DLL_API
98 caltinay 2183 const IntVec& getShape() const { return shape; }
99    
100 caltinay 2206 /// \brief Returns the variable name.
101 caltinay 2810 ESCRIPTEXPORT_DLL_API
102     std::string getName() const { return varName; }
103 caltinay 2196
104 caltinay 2206 /// \brief Returns the Silo tensor definition for this tensor.
105     ///
106 caltinay 2196 /// If the data is tensor data then the components of the tensor are stored
107     /// separately in the Silo file. This method then returns a string that
108     /// contains the proper Silo expression to put the tensor together again.
109     /// For non-tensor data this method returns an empty string.
110 caltinay 2810 ESCRIPTEXPORT_DLL_API
111 caltinay 2183 std::string getTensorDef() const;
112    
113 caltinay 2206 /// \brief Returns the number of data values.
114 caltinay 2810 ESCRIPTEXPORT_DLL_API
115     int getNumberOfSamples() const { return numSamples; }
116 caltinay 2183
117 caltinay 2810 /// \brief Returns the array of data values where array[i] is the i-th
118     /// component of the data.
119     ESCRIPTEXPORT_DLL_API
120     const CoordArray& getData() const { return dataArray; }
121 caltinay 2183
122     private:
123 caltinay 2810 void cleanup();
124    
125 caltinay 2206 /// \brief Averages and filters data.
126     ///
127 caltinay 2183 /// If a sample consists of more than one data point then this method
128     /// averages over the data points and returns the resulting array.
129     /// In any case, the data is filtered according to the stride value.
130     float* averageData(const float* src, size_t stride);
131    
132 caltinay 2206 /// \brief Prepares a sample ID -> index mapping which is used to reorder
133 caltinay 2810 /// data.
134     IndexMap buildIndexMap();
135 caltinay 2183
136 caltinay 2880 /// \brief Reorders the samples according to the corresponding node or
137     /// element IDs.
138 caltinay 2810 ///
139     /// \return true if the function space is supported and the number of
140 caltinay 2880 /// elements or nodes matches the number of data samples.
141     bool reorderSamples();
142 caltinay 2196
143 caltinay 2810 bool initialized;
144 caltinay 2880 FinleyMesh_ptr finleyMesh;
145 caltinay 2183 std::string varName;
146     int numSamples, rank, ptsPerSample, centering, funcSpace;
147     IntVec shape;
148     IntVec sampleID;
149 caltinay 2810 CoordArray dataArray;
150     std::string meshName, siloMeshName;
151 caltinay 2183 };
152    
153 caltinay 2810 inline IndexMap DataVar::buildIndexMap()
154 caltinay 2183 {
155 caltinay 2810 IndexMap sampleID2idx;
156 caltinay 2880 int idx = sampleID.size()-1;
157     IntVec::const_reverse_iterator idIt;
158     for (idIt = sampleID.rbegin(); idIt != sampleID.rend(); idIt++, idx--)
159 caltinay 2183 sampleID2idx[*idIt] = idx;
160 caltinay 2810
161     return sampleID2idx;
162 caltinay 2183 }
163    
164 caltinay 2810 } // namespace escriptexport
165 caltinay 2187
166 caltinay 2183 #endif // __DATAVAR_H__
167    

  ViewVC Help
Powered by ViewVC 1.1.26