/[escript]/trunk/tools/libescriptreader/src/escriptreader/DataVar.h
ViewVC logotype

Contents of /trunk/tools/libescriptreader/src/escriptreader/DataVar.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2183 - (show annotations)
Fri Dec 19 03:52:50 2008 UTC (11 years, 11 months ago) by caltinay
File MIME type: text/plain
File size: 3584 byte(s)
Added escriptreader library with tools. For more information refer to README
file or wait for user documentation.

1
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 class MeshWithElements;
25
26 //
27 //
28 //
29 class DataVar
30 {
31 public:
32 /// Constructor with variable name
33 DataVar(const std::string& name);
34
35 /// Copy constructor
36 DataVar(const DataVar& d);
37
38 /// Special constructor for integral mesh variables
39 DataVar(const std::string& name, const IntVec& data,
40 MeshWithElements* mesh);
41
42 /// Destructor
43 ~DataVar();
44
45 /// Appends data from rhs
46 bool append(const DataVar& rhs);
47
48 /// Reads values and IDs for this variable from NetCDF file
49 bool readFromNc(const std::string& ncFile);
50
51 /// Associates the data with the given mesh and reorders the samples
52 /// according to the corresponding node IDs.
53 /// This method must be called before writeToSilo() or getData()
54 bool setMesh(MeshWithElements* mesh);
55
56 /// Writes the data into given directory in given Silo file using
57 /// provided underlying mesh
58 bool writeToSilo(DBfile* dbfile, const std::string& siloPath);
59
60 /// Returns the rank of the data
61 int getRank() const { return rank; }
62
63 /// Returns true if the variable is node centered, false if zone centered
64 bool isNodeCentered() const;
65
66 /// Returns the name of the associated mesh which is one of the meshes
67 /// in mainMesh
68 std::string getMeshName(MeshWithElements* mainMesh) const;
69
70 /// Returns the shape vector of the data
71 const IntVec& getShape() const { return shape; }
72
73 /// Returns the variable name
74 const std::string& getName() const { return varName; }
75 std::string getTensorDef() const;
76
77 /// Returns the number of data values
78 int getNumberOfSamples() const { return reorderedNumSamples; }
79
80 const CoordArray& getData() const { return reorderedData; }
81
82 private:
83 /// If a sample consists of more than one data point then this method
84 /// averages over the data points and returns the resulting array.
85 /// In any case, the data is filtered according to the stride value.
86 float* averageData(const float* src, size_t stride);
87
88 void buildIndexMap();
89
90 void reorderSamples(const IndexMap& id2idxMap, const IntVec& requiredIDs);
91 void handleGhostZones(const IntVec& reorderArray);
92
93 /// Reads scalar data from NetCDF file
94 void readRank0Data(NcFile* ncfile);
95
96 /// Reads vector data from NetCDF file
97 void readRank1Data(NcFile* ncfile);
98
99 /// Reads tensor data from NetCDF file
100 void readRank2Data(NcFile* ncfile);
101
102 std::string varName;
103 int numSamples, rank, ptsPerSample, centering, funcSpace;
104 IntVec shape;
105 IntVec sampleID;
106 IndexMap sampleID2idx;
107 CoordArray rawData; // data as read from NetCDF file
108 CoordArray reorderedData; // reordered and filtered data
109 int reorderedNumSamples;
110 std::string siloMeshName;
111 MeshWithElements* fullMesh;
112 };
113
114 //
115 //
116 //
117 inline void DataVar::buildIndexMap()
118 {
119 sampleID2idx.clear();
120 int idx = 0;
121 IntVec::const_iterator idIt;
122 for (idIt = sampleID.begin(); idIt != sampleID.end(); idIt++, idx++)
123 sampleID2idx[*idIt] = idx;
124 }
125
126 #endif // __DATAVAR_H__
127

  ViewVC Help
Powered by ViewVC 1.1.26