/[escript]/branches/split/weipa/src/EscriptDataset.h
ViewVC logotype

Contents of /branches/split/weipa/src/EscriptDataset.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4724 - (show annotations)
Thu Mar 6 05:22:12 2014 UTC (5 years, 1 month ago) by jfenwick
File MIME type: text/plain
File size: 6703 byte(s)
Work towards parallel domains

1
2 /*****************************************************************************
3 *
4 * Copyright (c) 2003-2014 by University of Queensland
5 * http://www.uq.edu.au
6 *
7 * Primary Business: Queensland, Australia
8 * Licensed under the Open Software License version 3.0
9 * http://www.opensource.org/licenses/osl-3.0.php
10 *
11 * Development until 2012 by Earth Systems Science Computational Center (ESSCC)
12 * Development 2012-2013 by School of Earth Sciences
13 * Development from 2014 by Centre for Geoscience Computing (GeoComp)
14 *
15 *****************************************************************************/
16
17 #ifndef __WEIPA_ESCRIPTDATASET_H__
18 #define __WEIPA_ESCRIPTDATASET_H__
19
20 #include <weipa/weipa.h>
21
22 #include <ostream>
23
24 class DBfile;
25
26 namespace escript {
27 class AbstractDomain;
28 class Data;
29 }
30
31
32 namespace weipa {
33
34 typedef std::vector<DataVar_ptr> DataChunks;
35 typedef std::vector<DomainChunk_ptr> DomainChunks;
36
37 struct VarInfo {
38 std::string varName;
39 std::string units;
40 DataChunks dataChunks;
41 IntVec sampleDistribution;
42 bool valid;
43 };
44
45 typedef std::vector<VarInfo> VarVector;
46
47
48 /// \brief Represents an escript dataset including a domain and data variables
49 /// for one timestep.
50 //
51 /// This class represents an escript dataset complete with domain and
52 /// variable data. It can read the dataset from files generated by the
53 /// dump() methods within escript or through an escript domain instance plus
54 /// a number of escript::Data instances. Subsequently, the dataset can be
55 /// saved in the Silo or VTK file format or accessed through a number of
56 /// accessor methods.
57 ///
58 /// If the data is distributed via MPI then all ranks should create an instance
59 /// of this class and call the respective methods. Dump files that stem from
60 /// a parallel run can be read on one processor or on the same number of MPI
61 /// processes as they were created with.
62 class WEIPA_DLL_API EscriptDataset
63 {
64 public:
65 /// \brief Default constructor.
66 EscriptDataset();
67
68 #if HAVE_MPI
69 /// \brief Constructor with communicator.
70 EscriptDataset(MPI_Comm comm);
71 #endif
72
73 /// \brief Destructor.
74 ~EscriptDataset();
75
76 /// \brief Sets the escript domain for this dataset. This method can only
77 /// be called once and should be the first call unless loading from
78 /// dump files.
79 ///
80 /// \note If MPI is enabled this method also initialises the communicator
81 /// that will be used subsequently.
82 bool setDomain(const escript::AbstractDomain* domain);
83
84 /// \brief Adds an escript data instance to this dataset. You must ensure
85 /// that the data is defined on the domain that was used in
86 // setDomain(), otherwise you will get undefined behaviour later!
87 bool addData(escript::Data& data, const std::string name,
88 const std::string units = "");
89
90 /// \brief Loads domain and variables from escript NetCDF files.
91 ///
92 /// \param domainFilePattern a printf-style pattern for the domain file
93 /// names (e.g. "dom.%02d.nc")
94 /// \param varFiles a vector of file name patterns for variables
95 /// \param varNames a vector of variable names
96 /// \param nChunks number of chunks to load
97 ///
98 /// \note If MPI is enabled nChunks must be equal to the size of the
99 /// communicator or this method fails.
100 bool loadNetCDF(const std::string domainFilePattern,
101 const StringVec& varFiles, const StringVec& varNames,
102 int nChunks);
103
104 /// \brief Loads only variables from escript NetCDF files using the domain
105 /// provided.
106 bool loadNetCDF(const DomainChunks& domain, const StringVec& varFiles,
107 const StringVec& varNames);
108
109 /// \brief Sets the cycle number and time value for this dataset.
110 void setCycleAndTime(int c, double t) { cycle=c; time=t; }
111
112 /// \brief Returns the cycle number.
113 int getCycle() const { return cycle; }
114
115 /// \brief Returns the time value.
116 double getTime() const { return time; }
117
118 /// \brief Sets labels for the mesh axes.
119 /// \note This information is only used by the Silo writer.
120 void setMeshLabels(const std::string x, const std::string y, const std::string z="");
121
122 /// \brief Sets units for the mesh axes.
123 /// \note This information is only used by the Silo writer.
124 void setMeshUnits(const std::string x, const std::string y, const std::string z="");
125
126 /// \brief Sets a metadata schema and content
127 /// \note Only used by the VTK writer.
128 void setMetadataSchemaString(const std::string schema,
129 const std::string metadata)
130 { mdSchema=schema; mdString=metadata; }
131
132 /// \brief Enables/Disables saving of mesh-related data
133 void setSaveMeshData(bool flag) { wantsMeshVars=flag; }
134
135 /// \brief Saves the dataset in the Silo file format.
136 bool saveSilo(const std::string fileName, bool useMultiMesh=true);
137
138 /// \brief Saves the dataset in the VTK XML file format.
139 bool saveVTK(const std::string fileName);
140
141 /// \brief Returns the dataset's converted domain so it can be reused.
142 DomainChunks getConvertedDomain() { return domainChunks; }
143
144 /// \brief Returns a vector with the dataset's variables.
145 const VarVector& getVariables() const { return variables; }
146
147 /// \brief Returns a vector with the mesh variables.
148 const VarVector& getMeshVariables() const { return meshVariables; }
149
150 #if HAVE_MPI
151 MPI_Comm
152 #else
153 void*
154 #endif
155 getMPIComm() { return mpiComm; }
156
157 private:
158 bool loadDomain(const std::string filePattern, int nChunks);
159 bool setExternalDomain(const DomainChunks& domain);
160 bool loadData(const std::string filePattern, const std::string name,
161 const std::string units);
162
163 void convertMeshVariables();
164 void updateSampleDistribution(VarInfo& vi);
165 void putSiloMultiMesh(DBfile* dbfile, const std::string& meshName);
166 void putSiloMultiTensor(DBfile* dbfile, const VarInfo& vi);
167 void putSiloMultiVar(DBfile* dbfile, const VarInfo& vi,
168 bool useMeshFile = false);
169 bool saveVTKsingle(const std::string& fileName,
170 const std::string& meshName, const VarVector& vars);
171 void writeVarToVTK(const VarInfo& varInfo, std::ostream& os);
172
173 int cycle;
174 double time;
175 std::string mdSchema, mdString;
176 StringVec meshLabels, meshUnits;
177 bool externalDomain, wantsMeshVars;
178 DomainChunks domainChunks;
179 VarVector variables, meshVariables;
180 int mpiRank, mpiSize;
181 #if HAVE_MPI
182 MPI_Comm mpiComm;
183 #else
184 void* mpiComm;
185 #endif
186 };
187
188 } // namespace weipa
189
190 #endif // __WEIPA_ESCRIPTDATASET_H__
191

  ViewVC Help
Powered by ViewVC 1.1.26