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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2822 - (show annotations)
Mon Dec 14 03:10:16 2009 UTC (9 years, 8 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
2 /*******************************************************
3 *
4 * Copyright (c) 2003-2009 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 #ifndef __ESCRIPTDATASET_H__
15 #define __ESCRIPTDATASET_H__
16
17 #include <escriptexport/escriptexport.h>
18 #include <escript/AbstractDomain.h>
19
20 class DBfile;
21
22 namespace escript {
23
24 class Data;
25
26 }
27
28
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 struct VarInfo {
36 std::string fileName;
37 std::string varName;
38 DataBlocks dataBlocks;
39 bool valid;
40 };
41
42 typedef std::vector<VarInfo> VarVector;
43
44
45 /// \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 {
61 public:
62 /// \brief Default constructor.
63 ESCRIPTEXPORT_DLL_API
64 EscriptDataset();
65
66 #if HAVE_MPI
67 /// \brief Constructor with communicator.
68 ESCRIPTEXPORT_DLL_API
69 EscriptDataset(MPI_Comm comm);
70 #endif
71
72 /// \brief Destructor.
73 ESCRIPTEXPORT_DLL_API
74 ~EscriptDataset();
75
76 /// \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 ///
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 ESCRIPTEXPORT_DLL_API
92 bool loadNetCDF(const std::string meshFilePattern,
93 const StringVec& varFiles, const StringVec& varNames,
94 int nBlocks);
95
96 /// \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
101 /// \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
105 /// \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 /// \brief Returns the dataset's mesh.
115 ///
116 /// \note The caller is responsible for freeing the memory of the returned
117 /// mesh.
118 ESCRIPTEXPORT_DLL_API
119 MeshBlocks extractMesh() { keepMesh = true; return meshBlocks; }
120
121 /// \brief Returns the dataset's mesh.
122 ESCRIPTEXPORT_DLL_API
123 const MeshBlocks& getMesh() const { return meshBlocks; }
124
125 /// \brief Returns a vector with the dataset's variables.
126 ESCRIPTEXPORT_DLL_API
127 const VarVector& getVariables() const { return variables; }
128
129 /// \brief Returns a vector with the mesh variables.
130 ESCRIPTEXPORT_DLL_API
131 const VarVector& getMeshVariables() const { return meshVariables; }
132
133 private:
134 bool loadMeshFromNetCDF();
135 bool loadVariablesFromNetCDF();
136 void convertMeshVariables();
137 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 bool useMeshFile = false);
141
142 int numParts;
143 int cycle;
144 double time;
145 bool keepMesh, externalMesh;
146 std::string meshFmt;
147 MeshBlocks meshBlocks;
148 VarVector variables, meshVariables;
149 int mpiRank, mpiSize;
150 #if HAVE_MPI
151 MPI_Comm mpiComm;
152 #else
153 void* mpiComm;
154 #endif
155 };
156
157 } // namespace escriptexport
158
159 #endif // __ESCRIPTDATASET_H__
160

  ViewVC Help
Powered by ViewVC 1.1.26