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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2548 - (show 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
2 /*******************************************************
3 *
4 * Copyright (c) 2003-2009 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
25 namespace EscriptReader {
26
27 class MeshWithElements;
28
29 /// \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 class DataVar
32 {
33 public:
34 /// \brief Constructor with variable name
35 DataVar(const std::string& name);
36
37 /// \brief Copy constructor. Performs a deep copy of the data values.
38 DataVar(const DataVar& d);
39
40 /// \brief Special constructor for integral mesh variables like node IDs
41 DataVar(const std::string& name, const IntVec& data,
42 MeshWithElements* mesh);
43
44 /// \brief Destructor
45 ~DataVar();
46
47 /// \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 /// otherwise.
53 bool append(const DataVar& rhs);
54
55 /// \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 /// moment.
61 bool readFromNc(const std::string& filename);
62
63 /// \brief Associates the data with the given mesh and reorders the samples
64 /// according to the corresponding node IDs.
65 ///
66 /// \return true if the function space is supported and the number of
67 /// elements or nodes corresponds to the number of data samples.
68 /// \note This method must be called before writeToSilo() or getData().
69 bool setMesh(MeshWithElements* mesh);
70
71 /// \brief Writes the data into given directory in given Silo file.
72 ///
73 /// 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 bool writeToSilo(DBfile* dbfile, const std::string& siloPath);
77
78 /// \brief Returns the rank of the data.
79 int getRank() const { return rank; }
80
81 /// \brief Returns true if the variable is node centered, false if zone
82 /// centered.
83 bool isNodeCentered() const;
84
85 /// \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 std::string getMeshName(MeshWithElements* mainMesh) const;
90
91 /// \brief Returns the shape vector of the data.
92 ///
93 /// The shape vector has as many elements as the rank of this variable.
94 const IntVec& getShape() const { return shape; }
95
96 /// \brief Returns the variable name.
97 const std::string& getName() const { return varName; }
98
99 /// \brief Returns the Silo tensor definition for this tensor.
100 ///
101 /// 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 std::string getTensorDef() const;
106
107 /// \brief Returns the number of data values.
108 int getNumberOfSamples() const { return reorderedNumSamples; }
109
110 /// \brief Returns the reordered (not raw!) data values.
111 const CoordArray& getData() const { return reorderedData; }
112
113 private:
114 /// \brief Averages and filters data.
115 ///
116 /// 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 /// \brief Prepares a sample ID -> index mapping which is used to reorder
122 /// data.
123 void buildIndexMap();
124
125 void reorderSamples(const IndexMap& id2idxMap, const IntVec& requiredIDs);
126
127 void handleGhostZones(const IntVec& reorderArray);
128
129 /// \brief Reads scalar data from NetCDF file.
130 void readRank0Data(NcFile* ncfile);
131
132 /// \brief Reads vector data from NetCDF file.
133 void readRank1Data(NcFile* ncfile);
134
135 /// \brief Reads tensor data from NetCDF file.
136 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 CoordArray rawData; /// data as read from NetCDF file
144 CoordArray reorderedData; /// reordered and filtered data
145 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 } // namespace EscriptReader
160
161 #endif // __DATAVAR_H__
162

  ViewVC Help
Powered by ViewVC 1.1.26