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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2196 - (hide annotations)
Wed Jan 7 06:14:59 2009 UTC (11 years, 10 months ago) by caltinay
Original Path: trunk/tools/libescriptreader/src/escriptreader/DataVar.h
File MIME type: text/plain
File size: 5164 byte(s)
As harsh as it sounds: removed obsolete friendship between DataVar and Mesh.
Updated and added documentation to some more methods.

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

  ViewVC Help
Powered by ViewVC 1.1.26