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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2187 by caltinay, Tue Dec 23 04:13:15 2008 UTC revision 2196 by caltinay, Wed Jan 7 06:14:59 2009 UTC
# Line 27  namespace EscriptReader { Line 27  namespace EscriptReader {
27  class MeshWithElements;  class MeshWithElements;
28    
29  //  //
30  //  // 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  //  //
33  class DataVar  class DataVar
34  {  {
# Line 35  public: Line 36  public:
36      /// Constructor with variable name      /// Constructor with variable name
37      DataVar(const std::string& name);      DataVar(const std::string& name);
38    
39      /// Copy constructor      /// Copy constructor. Performs a deep copy of the data values.
40      DataVar(const DataVar& d);      DataVar(const DataVar& d);
41    
42      /// Special constructor for integral mesh variables      /// Special constructor for integral mesh variables like node IDs
43      DataVar(const std::string& name, const IntVec& data,      DataVar(const std::string& name, const IntVec& data,
44              MeshWithElements* mesh);              MeshWithElements* mesh);
45    
46      /// Destructor      /// Destructor
47      ~DataVar();      ~DataVar();
48    
49      /// Appends data from rhs      /// 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      bool append(const DataVar& rhs);      bool append(const DataVar& rhs);
54    
55      /// Reads values and IDs for this variable from NetCDF file      /// Reads values and IDs for this variable from escript NetCDF file.
56      bool readFromNc(const std::string& ncFile);      /// 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    
62      /// Associates the data with the given mesh and reorders the samples      /// Associates the data with the given mesh and reorders the samples
63      /// according to the corresponding node IDs.      /// according to the corresponding node IDs.
64      /// This method must be called before writeToSilo() or getData()      /// 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      bool setMesh(MeshWithElements* mesh);      bool setMesh(MeshWithElements* mesh);
68    
69      /// Writes the data into given directory in given Silo file using      /// Writes the data into given directory in given Silo file.
70      /// provided underlying mesh      /// 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      bool writeToSilo(DBfile* dbfile, const std::string& siloPath);      bool writeToSilo(DBfile* dbfile, const std::string& siloPath);
74    
75      /// Returns the rank of the data      /// Returns the rank of the data.
76      int getRank() const { return rank; }      int getRank() const { return rank; }
77    
78      /// Returns true if the variable is node centered, false if zone centered      /// Returns true if the variable is node centered, false if zone centered.
79      bool isNodeCentered() const;      bool isNodeCentered() const;
80    
81      /// Returns the name of the associated mesh which is one of the meshes      /// Returns the name of the associated mesh which is one of the meshes
82      /// in mainMesh      /// in mainMesh depending on function space type and whether reduced
83        /// elements are used or not.
84      std::string getMeshName(MeshWithElements* mainMesh) const;      std::string getMeshName(MeshWithElements* mainMesh) const;
85    
86      /// Returns the shape vector of the data      /// Returns the shape vector of the data. The shape vector has as many
87        /// elements as the rank of this variable.
88      const IntVec& getShape() const { return shape; }      const IntVec& getShape() const { return shape; }
89    
90      /// Returns the variable name      /// Returns the variable name.
91      const std::string& getName() const { return varName; }      const std::string& getName() const { return varName; }
92    
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      std::string getTensorDef() const;      std::string getTensorDef() const;
98    
99      /// Returns the number of data values      /// Returns the number of data values.
100      int getNumberOfSamples() const { return reorderedNumSamples; }      int getNumberOfSamples() const { return reorderedNumSamples; }
101    
102        /// Returns the reordered (not raw!) data values.
103      const CoordArray& getData() const { return reorderedData; }      const CoordArray& getData() const { return reorderedData; }
104    
105  private:  private:
# Line 88  private: Line 108  private:
108      /// In any case, the data is filtered according to the stride value.      /// In any case, the data is filtered according to the stride value.
109      float* averageData(const float* src, size_t stride);      float* averageData(const float* src, size_t stride);
110    
111        /// Prepares a sample ID -> index mapping which is used to reorder data.
112      void buildIndexMap();      void buildIndexMap();
113    
114      void reorderSamples(const IndexMap& id2idxMap, const IntVec& requiredIDs);      void reorderSamples(const IndexMap& id2idxMap, const IntVec& requiredIDs);
115    
116      void handleGhostZones(const IntVec& reorderArray);      void handleGhostZones(const IntVec& reorderArray);
117    
118      /// Reads scalar data from NetCDF file      /// Reads scalar data from NetCDF file.
119      void readRank0Data(NcFile* ncfile);      void readRank0Data(NcFile* ncfile);
120    
121      /// Reads vector data from NetCDF file      /// Reads vector data from NetCDF file.
122      void readRank1Data(NcFile* ncfile);      void readRank1Data(NcFile* ncfile);
123    
124      /// Reads tensor data from NetCDF file      /// Reads tensor data from NetCDF file.
125      void readRank2Data(NcFile* ncfile);      void readRank2Data(NcFile* ncfile);
126    
127      std::string varName;      std::string varName;

Legend:
Removed from v.2187  
changed lines
  Added in v.2196

  ViewVC Help
Powered by ViewVC 1.1.26