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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2810 - (hide annotations)
Mon Dec 7 04:13:49 2009 UTC (11 years ago) by caltinay
File MIME type: text/plain
File size: 5439 byte(s)
Reincarnation of the escriptreader as a more flexible escriptexport library:
 - can be initialised with instances of escript::Data and Finley_Mesh
 - is now MPI aware at the EscriptDataset level including Silo writer
 - now uses boost shared pointers
The lib is currently only used by the escriptconvert tool but this is going to
change...

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 2810 /// \brief Reorders the samples according to the corresponding node IDs.
137     ///
138     /// \return true if the function space is supported and the number of
139     /// elements or nodes corresponds to the number of data samples.
140     bool filterSamples(const FinleyMesh_ptr mesh);
141 caltinay 2196
142 caltinay 2810 bool initialized;
143 caltinay 2183 std::string varName;
144     int numSamples, rank, ptsPerSample, centering, funcSpace;
145     IntVec shape;
146     IntVec sampleID;
147 caltinay 2810 CoordArray dataArray;
148     std::string meshName, siloMeshName;
149 caltinay 2183 };
150    
151 caltinay 2810 inline IndexMap DataVar::buildIndexMap()
152 caltinay 2183 {
153 caltinay 2810 IndexMap sampleID2idx;
154 caltinay 2183 int idx = 0;
155     IntVec::const_iterator idIt;
156     for (idIt = sampleID.begin(); idIt != sampleID.end(); idIt++, idx++)
157     sampleID2idx[*idIt] = idx;
158 caltinay 2810
159     return sampleID2idx;
160 caltinay 2183 }
161    
162 caltinay 2810 } // namespace escriptexport
163 caltinay 2187
164 caltinay 2183 #endif // __DATAVAR_H__
165    

  ViewVC Help
Powered by ViewVC 1.1.26