/[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

trunk/tools/libescriptreader/src/escriptreader/DataVar.h revision 2548 by jfenwick, Mon Jul 20 06:20:06 2009 UTC trunk/dataexporter/src/DataVar.h revision 2810 by caltinay, Mon Dec 7 04:13:49 2009 UTC
# Line 11  Line 11 
11  *  *
12  *******************************************************/  *******************************************************/
13    
 //  
 // DataVar.h  
 //  
14  #ifndef __DATAVAR_H__  #ifndef __DATAVAR_H__
15  #define __DATAVAR_H__  #define __DATAVAR_H__
16    
17  #include <escriptreader/common.h>  #include <escriptexport/escriptexport.h>
18    
19  class DBfile;  class DBfile;
20  class NcFile;  class NcFile;
21    
22  namespace EscriptReader {  namespace escript {
23        class Data;
24    }
25    
26    namespace escriptexport {
27    
28  class MeshWithElements;  class FinleyMesh;
29    
30  /// \brief A class that provides functionality to read an escript data object in  /// \brief A class that provides functionality to read an escript data object
31  /// the native NetCDF format and to write that data in Silo format (if available).  /// from NetCDF file or an escript::Data instance and write that data in Silo
32    /// or VTK XML formats.
33  class DataVar  class DataVar
34  {  {
35  public:  public:
36      /// \brief Constructor with variable name      /// \brief Constructor with variable name
37        ESCRIPTEXPORT_DLL_API
38      DataVar(const std::string& name);      DataVar(const std::string& name);
39    
40      /// \brief Copy constructor. Performs a deep copy of the data values.      /// \brief Copy constructor. Performs a deep copy of the data values.
41        ESCRIPTEXPORT_DLL_API
42      DataVar(const DataVar& d);      DataVar(const DataVar& d);
43    
     /// \brief Special constructor for integral mesh variables like node IDs  
     DataVar(const std::string& name, const IntVec& data,  
             MeshWithElements* mesh);  
   
44      /// \brief Destructor      /// \brief Destructor
45        ESCRIPTEXPORT_DLL_API
46      ~DataVar();      ~DataVar();
47    
48      /// \brief Appends raw data and IDs from rhs.      /// \brief Initialises values and IDs from an escript::Data instance.
49      ///      ///
50      /// Reordered data becomes invalid, i.e. you have to call setMesh() again      /// \return true if a valid instance of expanded data was supplied,
51      /// before getData().      ///         false if the initialisation was unsuccessful.
52      /// \return true if rhs is compatible and appending succeeded, false      ESCRIPTEXPORT_DLL_API
53      /// otherwise.      bool initFromEscript(escript::Data& escriptData, FinleyMesh_ptr mesh);
54      bool append(const DataVar& rhs);  
55        /// \brief Initialises with integral mesh data like IDs or tags.
56        ///
57        /// The data is retrieved from the mesh using the variable name.
58        ESCRIPTEXPORT_DLL_API
59        bool initFromMesh(FinleyMesh_ptr mesh);
60    
61      /// \brief Reads values and IDs for this variable from escript NetCDF file.      /// \brief Reads values and IDs for this variable from escript NetCDF file.
62      ///      ///
63      /// \return true if the file was found and contains valid escript data with      /// \return true if the file was found and contains valid escript data
64      /// at least one sample, false otherwise.      ///         with at least one sample, false otherwise.
65      /// \note Only expanded data of up to rank 2 is supported at the      /// \note Only expanded data with rank <=2 is supported at the moment.
66      /// moment.      ESCRIPTEXPORT_DLL_API
67      bool readFromNc(const std::string& filename);      bool initFromNetCDF(const std::string& filename, FinleyMesh_ptr mesh);
   
     /// \brief Associates the data with the given mesh and reorders the samples  
     /// according to the corresponding node IDs.  
     ///  
     /// \return true if the function space is supported and the number of  
     /// elements or nodes corresponds to the number of data samples.  
     /// \note This method must be called before writeToSilo() or getData().  
     bool setMesh(MeshWithElements* mesh);  
68    
69      /// \brief Writes the data into given directory in given Silo file.      /// \brief Writes the data into given directory in given Silo file.
70      ///      ///
71      /// 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
72      /// beforehand using setMesh() or if a Silo function fails this method      /// beforehand using setMesh() or if a Silo function fails this method
73      /// returns false.      /// returns false.
74        ESCRIPTEXPORT_DLL_API
75      bool writeToSilo(DBfile* dbfile, const std::string& siloPath);      bool writeToSilo(DBfile* dbfile, const std::string& siloPath);
76    
77      /// \brief Returns the rank of the data.      /// \brief Returns the rank of the data.
78        ESCRIPTEXPORT_DLL_API
79      int getRank() const { return rank; }      int getRank() const { return rank; }
80    
81      /// \brief Returns true if the variable is node centered, false if zone      /// \brief Returns true if the variable data is node centered, false if
82      /// centered.      ///        zone centered.
83        ESCRIPTEXPORT_DLL_API
84      bool isNodeCentered() const;      bool isNodeCentered() const;
85    
86      /// \brief Returns the name of the associated mesh.      /// \brief Returns the name of the associated mesh.
87      ///      ///
88      /// The returned name is one of the meshes in mainMesh depending on function      /// The returned name is one of the sub-meshes of the mesh set with
89      /// space type and whether reduced elements are used or not.      /// setMesh() determined on the basis of the function space type and
90      std::string getMeshName(MeshWithElements* mainMesh) const;      /// whether reduced elements are used or not.
91        ESCRIPTEXPORT_DLL_API
92        std::string getMeshName() const { return meshName; }
93    
94      /// \brief Returns the shape vector of the data.      /// \brief Returns the shape vector of the data.
95      ///      ///
96      /// The shape vector has as many elements as the rank of this variable.      /// The shape vector has as many elements as the rank of this variable.
97        ESCRIPTEXPORT_DLL_API
98      const IntVec& getShape() const { return shape; }      const IntVec& getShape() const { return shape; }
99    
100      /// \brief Returns the variable name.      /// \brief Returns the variable name.
101      const std::string& getName() const { return varName; }      ESCRIPTEXPORT_DLL_API
102        std::string getName() const { return varName; }
103    
104      /// \brief Returns the Silo tensor definition for this tensor.      /// \brief Returns the Silo tensor definition for this tensor.
105      ///      ///
# Line 102  public: Line 107  public:
107      /// separately in the Silo file. This method then returns a string that      /// separately in the Silo file. This method then returns a string that
108      /// contains the proper Silo expression to put the tensor together again.      /// contains the proper Silo expression to put the tensor together again.
109      /// For non-tensor data this method returns an empty string.      /// For non-tensor data this method returns an empty string.
110        ESCRIPTEXPORT_DLL_API
111      std::string getTensorDef() const;      std::string getTensorDef() const;
112    
113      /// \brief Returns the number of data values.      /// \brief Returns the number of data values.
114      int getNumberOfSamples() const { return reorderedNumSamples; }      ESCRIPTEXPORT_DLL_API
115        int getNumberOfSamples() const { return numSamples; }
116    
117      /// \brief Returns the reordered (not raw!) data values.      /// \brief Returns the array of data values where array[i] is the i-th
118      const CoordArray& getData() const { return reorderedData; }      ///        component of the data.
119        ESCRIPTEXPORT_DLL_API
120        const CoordArray& getData() const { return dataArray; }
121    
122  private:  private:
123        void cleanup();
124    
125      /// \brief Averages and filters data.      /// \brief Averages and filters data.
126      ///      ///
127      /// 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
# Line 119  private: Line 130  private:
130      float* averageData(const float* src, size_t stride);      float* averageData(const float* src, size_t stride);
131    
132      /// \brief Prepares a sample ID -> index mapping which is used to reorder      /// \brief Prepares a sample ID -> index mapping which is used to reorder
133      /// data.      ///        data.
134      void buildIndexMap();      IndexMap buildIndexMap();
   
     void reorderSamples(const IndexMap& id2idxMap, const IntVec& requiredIDs);  
135    
136      void handleGhostZones(const IntVec& reorderArray);      /// \brief Reorders the samples according to the corresponding node IDs.
137        ///
138      /// \brief Reads scalar data from NetCDF file.      /// \return true if the function space is supported and the number of
139      void readRank0Data(NcFile* ncfile);      ///         elements or nodes corresponds to the number of data samples.
140        bool filterSamples(const FinleyMesh_ptr mesh);
     /// \brief Reads vector data from NetCDF file.  
     void readRank1Data(NcFile* ncfile);  
   
     /// \brief Reads tensor data from NetCDF file.  
     void readRank2Data(NcFile* ncfile);  
141    
142        bool initialized;
143      std::string varName;      std::string varName;
144      int numSamples, rank, ptsPerSample, centering, funcSpace;      int numSamples, rank, ptsPerSample, centering, funcSpace;
145      IntVec shape;      IntVec shape;
146      IntVec sampleID;      IntVec sampleID;
147      IndexMap sampleID2idx;      CoordArray dataArray;
148      CoordArray rawData;       /// data as read from NetCDF file      std::string meshName, siloMeshName;
     CoordArray reorderedData; /// reordered and filtered data  
     int reorderedNumSamples;  
     std::string siloMeshName;  
     MeshWithElements* fullMesh;  
149  };  };
150    
151  inline void DataVar::buildIndexMap()  inline IndexMap DataVar::buildIndexMap()
152  {  {
153      sampleID2idx.clear();      IndexMap sampleID2idx;
154      int idx = 0;      int idx = 0;
155      IntVec::const_iterator idIt;      IntVec::const_iterator idIt;
156      for (idIt = sampleID.begin(); idIt != sampleID.end(); idIt++, idx++)      for (idIt = sampleID.begin(); idIt != sampleID.end(); idIt++, idx++)
157          sampleID2idx[*idIt] = idx;          sampleID2idx[*idIt] = idx;
158    
159        return sampleID2idx;
160  }  }
161    
162  } // namespace EscriptReader  } // namespace escriptexport
163    
164  #endif // __DATAVAR_H__  #endif // __DATAVAR_H__
165    

Legend:
Removed from v.2548  
changed lines
  Added in v.2810

  ViewVC Help
Powered by ViewVC 1.1.26