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

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

  ViewVC Help
Powered by ViewVC 1.1.26