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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2187 - (hide annotations)
Tue Dec 23 04:13:15 2008 UTC (11 years, 11 months ago) by caltinay
Original Path: trunk/tools/libescriptreader/src/escriptreader/DataVar.h
File MIME type: text/plain
File size: 3642 byte(s)
Moved escriptreader related classes into own namespace.

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

  ViewVC Help
Powered by ViewVC 1.1.26