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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2548 - (hide annotations)
Mon Jul 20 06:20:06 2009 UTC (11 years, 4 months ago) by jfenwick
Original Path: trunk/tools/libescriptreader/src/escriptreader/DataVar.h
File MIME type: text/plain
File size: 5499 byte(s)
Updating copyright notices
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     //
15     // DataVar.h
16     //
17     #ifndef __DATAVAR_H__
18     #define __DATAVAR_H__
19    
20     #include <escriptreader/common.h>
21    
22     class DBfile;
23     class NcFile;
24 caltinay 2187
25     namespace EscriptReader {
26    
27 caltinay 2183 class MeshWithElements;
28    
29 caltinay 2206 /// \brief A class that provides functionality to read an escript data object in
30     /// the native NetCDF format and to write that data in Silo format (if available).
31 caltinay 2183 class DataVar
32     {
33     public:
34 caltinay 2206 /// \brief Constructor with variable name
35 caltinay 2183 DataVar(const std::string& name);
36    
37 caltinay 2206 /// \brief Copy constructor. Performs a deep copy of the data values.
38 caltinay 2183 DataVar(const DataVar& d);
39    
40 caltinay 2206 /// \brief Special constructor for integral mesh variables like node IDs
41 caltinay 2183 DataVar(const std::string& name, const IntVec& data,
42     MeshWithElements* mesh);
43    
44 caltinay 2206 /// \brief Destructor
45 caltinay 2183 ~DataVar();
46    
47 caltinay 2206 /// \brief Appends raw data and IDs from rhs.
48     ///
49     /// Reordered data becomes invalid, i.e. you have to call setMesh() again
50     /// before getData().
51     /// \return true if rhs is compatible and appending succeeded, false
52 caltinay 2196 /// otherwise.
53 caltinay 2183 bool append(const DataVar& rhs);
54    
55 caltinay 2206 /// \brief Reads values and IDs for this variable from escript NetCDF file.
56     ///
57     /// \return true if the file was found and contains valid escript data with
58     /// at least one sample, false otherwise.
59     /// \note Only expanded data of up to rank 2 is supported at the
60 caltinay 2196 /// moment.
61     bool readFromNc(const std::string& filename);
62 caltinay 2183
63 caltinay 2206 /// \brief Associates the data with the given mesh and reorders the samples
64 caltinay 2183 /// according to the corresponding node IDs.
65 caltinay 2206 ///
66     /// \return true if the function space is supported and the number of
67 caltinay 2196 /// elements or nodes corresponds to the number of data samples.
68 caltinay 2206 /// \note This method must be called before writeToSilo() or getData().
69 caltinay 2183 bool setMesh(MeshWithElements* mesh);
70    
71 caltinay 2206 /// \brief Writes the data into given directory in given Silo file.
72     ///
73 caltinay 2196 /// If Silo was not available at compile time or the mesh was not set
74     /// beforehand using setMesh() or if a Silo function fails this method
75     /// returns false.
76 caltinay 2183 bool writeToSilo(DBfile* dbfile, const std::string& siloPath);
77    
78 caltinay 2206 /// \brief Returns the rank of the data.
79 caltinay 2183 int getRank() const { return rank; }
80    
81 caltinay 2206 /// \brief Returns true if the variable is node centered, false if zone
82     /// centered.
83 caltinay 2183 bool isNodeCentered() const;
84    
85 caltinay 2206 /// \brief Returns the name of the associated mesh.
86     ///
87     /// The returned name is one of the meshes in mainMesh depending on function
88     /// space type and whether reduced elements are used or not.
89 caltinay 2183 std::string getMeshName(MeshWithElements* mainMesh) const;
90    
91 caltinay 2206 /// \brief Returns the shape vector of the data.
92     ///
93     /// The shape vector has as many elements as the rank of this variable.
94 caltinay 2183 const IntVec& getShape() const { return shape; }
95    
96 caltinay 2206 /// \brief Returns the variable name.
97 caltinay 2183 const std::string& getName() const { return varName; }
98 caltinay 2196
99 caltinay 2206 /// \brief Returns the Silo tensor definition for this tensor.
100     ///
101 caltinay 2196 /// If the data is tensor data then the components of the tensor are stored
102     /// separately in the Silo file. This method then returns a string that
103     /// contains the proper Silo expression to put the tensor together again.
104     /// For non-tensor data this method returns an empty string.
105 caltinay 2183 std::string getTensorDef() const;
106    
107 caltinay 2206 /// \brief Returns the number of data values.
108 caltinay 2183 int getNumberOfSamples() const { return reorderedNumSamples; }
109    
110 caltinay 2206 /// \brief Returns the reordered (not raw!) data values.
111 caltinay 2183 const CoordArray& getData() const { return reorderedData; }
112    
113     private:
114 caltinay 2206 /// \brief Averages and filters data.
115     ///
116 caltinay 2183 /// If a sample consists of more than one data point then this method
117     /// averages over the data points and returns the resulting array.
118     /// In any case, the data is filtered according to the stride value.
119     float* averageData(const float* src, size_t stride);
120    
121 caltinay 2206 /// \brief Prepares a sample ID -> index mapping which is used to reorder
122     /// data.
123 caltinay 2183 void buildIndexMap();
124    
125     void reorderSamples(const IndexMap& id2idxMap, const IntVec& requiredIDs);
126 caltinay 2196
127 caltinay 2183 void handleGhostZones(const IntVec& reorderArray);
128    
129 caltinay 2206 /// \brief Reads scalar data from NetCDF file.
130 caltinay 2183 void readRank0Data(NcFile* ncfile);
131    
132 caltinay 2206 /// \brief Reads vector data from NetCDF file.
133 caltinay 2183 void readRank1Data(NcFile* ncfile);
134    
135 caltinay 2206 /// \brief Reads tensor data from NetCDF file.
136 caltinay 2183 void readRank2Data(NcFile* ncfile);
137    
138     std::string varName;
139     int numSamples, rank, ptsPerSample, centering, funcSpace;
140     IntVec shape;
141     IntVec sampleID;
142     IndexMap sampleID2idx;
143 caltinay 2206 CoordArray rawData; /// data as read from NetCDF file
144     CoordArray reorderedData; /// reordered and filtered data
145 caltinay 2183 int reorderedNumSamples;
146     std::string siloMeshName;
147     MeshWithElements* fullMesh;
148     };
149    
150     inline void DataVar::buildIndexMap()
151     {
152     sampleID2idx.clear();
153     int idx = 0;
154     IntVec::const_iterator idIt;
155     for (idIt = sampleID.begin(); idIt != sampleID.end(); idIt++, idx++)
156     sampleID2idx[*idIt] = idx;
157     }
158    
159 caltinay 2187 } // namespace EscriptReader
160    
161 caltinay 2183 #endif // __DATAVAR_H__
162    

  ViewVC Help
Powered by ViewVC 1.1.26