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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2847 - (show annotations)
Fri Jan 15 03:35:05 2010 UTC (9 years, 6 months ago) by caltinay
File MIME type: text/plain
File size: 5176 byte(s)
Improved error handling when using MPI and fixed Silo output when not all
ranks contribute to a data variable.

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 varName;
37 DataBlocks dataBlocks;
38 IntVec sampleDistribution;
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 loadVarFromNetCDF(const std::string& fileName,
136 const std::string& varName);
137 void convertMeshVariables();
138 void updateSampleDistribution(VarInfo& vi);
139 void putSiloMultiMesh(DBfile* dbfile, const std::string& meshName);
140 void putSiloMultiTensor(DBfile* dbfile, const VarInfo& vi);
141 void putSiloMultiVar(DBfile* dbfile, const VarInfo& vi,
142 bool useMeshFile = false);
143
144 int numParts;
145 int cycle;
146 double time;
147 bool keepMesh, externalMesh;
148 std::string meshFmt;
149 MeshBlocks meshBlocks;
150 VarVector variables, meshVariables;
151 int mpiRank, mpiSize;
152 #if HAVE_MPI
153 MPI_Comm mpiComm;
154 #else
155 void* mpiComm;
156 #endif
157 };
158
159 } // namespace escriptexport
160
161 #endif // __ESCRIPTDATASET_H__
162

  ViewVC Help
Powered by ViewVC 1.1.26