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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2822 - (hide annotations)
Mon Dec 14 03:10:16 2009 UTC (9 years, 9 months ago) by caltinay
File MIME type: text/plain
File size: 5047 byte(s)
dataexporter: Ensure that NetCDF files created using N ranks are only loaded
when mpi size equals N or 1.

1 caltinay 2183
2     /*******************************************************
3     *
4 jfenwick 2548 * Copyright (c) 2003-2009 by University of Queensland
5 caltinay 2183 * 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 caltinay 2810 #ifndef __ESCRIPTDATASET_H__
15     #define __ESCRIPTDATASET_H__
16 caltinay 2183
17 caltinay 2810 #include <escriptexport/escriptexport.h>
18     #include <escript/AbstractDomain.h>
19 caltinay 2183
20     class DBfile;
21    
22 caltinay 2810 namespace escript {
23 caltinay 2187
24 caltinay 2810 class Data;
25 caltinay 2187
26 caltinay 2810 }
27 caltinay 2183
28 caltinay 2810
29     namespace escriptexport {
30    
31     typedef std::vector<escript::Data> DataVec;
32     typedef std::vector<DataVar_ptr> DataBlocks;
33     typedef std::vector<FinleyMesh_ptr> MeshBlocks;
34    
35 caltinay 2183 struct VarInfo {
36     std::string fileName;
37     std::string varName;
38 caltinay 2810 DataBlocks dataBlocks;
39 caltinay 2183 bool valid;
40     };
41 caltinay 2810
42 caltinay 2183 typedef std::vector<VarInfo> VarVector;
43    
44    
45 caltinay 2810 /// \brief Represents an escript dataset including domain and variables for
46     /// one timestep.
47     //
48     /// This class represents an escript/finley dataset complete with domain and
49     /// variable data. It can read the dataset from NetCDF files generated by the
50     /// dump() methods within escript or through an escript domain instance plus
51     /// a number of escript::Data instances. Subsequently, the dataset can be
52     /// saved in the Silo file format or accessed through a number of accessor
53     /// methods.
54     ///
55     /// If the data is distributed via MPI then all ranks should create an instance
56     /// of this class and call the respective methods. NetCDF files that stem from
57     /// a parallel run can be read on one processor or on the same number of MPI
58     /// processes as they were created with.
59     class EscriptDataset
60 caltinay 2183 {
61     public:
62 caltinay 2821 /// \brief Default constructor.
63 caltinay 2810 ESCRIPTEXPORT_DLL_API
64     EscriptDataset();
65 caltinay 2183
66 caltinay 2821 #if HAVE_MPI
67     /// \brief Constructor with communicator.
68     ESCRIPTEXPORT_DLL_API
69     EscriptDataset(MPI_Comm comm);
70     #endif
71    
72 caltinay 2206 /// \brief Destructor.
73 caltinay 2810 ESCRIPTEXPORT_DLL_API
74     ~EscriptDataset();
75 caltinay 2183
76 caltinay 2810 /// \brief Initialises with instances of escript domain and data.
77     ESCRIPTEXPORT_DLL_API
78     bool initFromEscript(escript::const_Domain_ptr mesh,
79     DataVec& escriptVars, const StringVec& varNames);
80    
81     /// \brief Loads mesh and variables from escript NetCDF files.
82 caltinay 2822 ///
83     /// \param meshFilePattern a printf-style pattern for the mesh file names
84     /// (e.g. "mesh.%02d.nc")
85     /// \param varFiles a vector of file name patterns for variables
86     /// \param varNames a vector of variable names
87     /// \param nBlocks number of blocks/chunks to load
88     ///
89     /// \note If MPI is enabled nBlocks must be equal to the size of the
90     /// communicator or this method fails.
91 caltinay 2810 ESCRIPTEXPORT_DLL_API
92 caltinay 2822 bool loadNetCDF(const std::string meshFilePattern,
93     const StringVec& varFiles, const StringVec& varNames,
94     int nBlocks);
95 caltinay 2183
96 caltinay 2810 /// \brief Loads only variables from escript NetCDF files using given mesh.
97     ESCRIPTEXPORT_DLL_API
98     bool loadNetCDF(const MeshBlocks& mesh, const StringVec& varFiles,
99     const StringVec& varNames);
100 caltinay 2183
101 caltinay 2810 /// \brief Sets the cycle number and time value for this dataset.
102     ESCRIPTEXPORT_DLL_API
103     void setCycleAndTime(int c, double t) { cycle=c; time=t; }
104 caltinay 2183
105 caltinay 2810 /// \brief Saves the dataset in the Silo file format.
106     ESCRIPTEXPORT_DLL_API
107     bool saveSilo(const std::string fileName, bool useMultiMesh=true);
108    
109     /// \brief Saves the dataset in the VTK XML file format.
110     /// \note NOT IMPLEMENTED.
111     ESCRIPTEXPORT_DLL_API
112     bool saveVTK(const std::string fileName);
113    
114 caltinay 2206 /// \brief Returns the dataset's mesh.
115     ///
116     /// \note The caller is responsible for freeing the memory of the returned
117     /// mesh.
118 caltinay 2810 ESCRIPTEXPORT_DLL_API
119 caltinay 2183 MeshBlocks extractMesh() { keepMesh = true; return meshBlocks; }
120    
121 caltinay 2206 /// \brief Returns the dataset's mesh.
122 caltinay 2810 ESCRIPTEXPORT_DLL_API
123 caltinay 2183 const MeshBlocks& getMesh() const { return meshBlocks; }
124 caltinay 2206
125     /// \brief Returns a vector with the dataset's variables.
126 caltinay 2810 ESCRIPTEXPORT_DLL_API
127 caltinay 2183 const VarVector& getVariables() const { return variables; }
128 caltinay 2206
129     /// \brief Returns a vector with the mesh variables.
130 caltinay 2810 ESCRIPTEXPORT_DLL_API
131 caltinay 2183 const VarVector& getMeshVariables() const { return meshVariables; }
132    
133     private:
134 caltinay 2810 bool loadMeshFromNetCDF();
135     bool loadVariablesFromNetCDF();
136 caltinay 2183 void convertMeshVariables();
137 caltinay 2810 void putSiloMultiMesh(DBfile* dbfile, const std::string& meshName);
138     void putSiloMultiTensor(DBfile* dbfile, const VarInfo& vi);
139     void putSiloMultiVar(DBfile* dbfile, const VarInfo& vi,
140 caltinay 2183 bool useMeshFile = false);
141    
142     int numParts;
143 caltinay 2810 int cycle;
144     double time;
145     bool keepMesh, externalMesh;
146 caltinay 2183 std::string meshFmt;
147     MeshBlocks meshBlocks;
148     VarVector variables, meshVariables;
149 caltinay 2810 int mpiRank, mpiSize;
150     #if HAVE_MPI
151     MPI_Comm mpiComm;
152     #else
153     void* mpiComm;
154     #endif
155 caltinay 2183 };
156    
157 caltinay 2810 } // namespace escriptexport
158 caltinay 2187
159 caltinay 2810 #endif // __ESCRIPTDATASET_H__
160 caltinay 2183

  ViewVC Help
Powered by ViewVC 1.1.26