Escript  Revision_4320
EscriptDataset.h
Go to the documentation of this file.
1 
2 /*****************************************************************************
3 *
4 * Copyright (c) 2003-2013 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 since 2012 by School of Earth Sciences
13 *
14 *****************************************************************************/
15 
16 #ifndef __WEIPA_ESCRIPTDATASET_H__
17 #define __WEIPA_ESCRIPTDATASET_H__
18 
19 #include <weipa/weipa.h>
20 
21 #include <ostream>
22 
23 class DBfile;
24 
25 namespace escript {
26  class AbstractDomain;
27  class Data;
28 }
29 
30 
31 namespace weipa {
32 
33 typedef std::vector<DataVar_ptr> DataChunks;
34 typedef std::vector<DomainChunk_ptr> DomainChunks;
35 
36 struct VarInfo {
37  std::string varName;
38  std::string units;
41  bool valid;
42 };
43 
44 typedef std::vector<VarInfo> VarVector;
45 
46 
49 //
62 {
63 public:
66 
67 #if HAVE_MPI
68 
70 #endif
71 
73  ~EscriptDataset();
74 
81  bool setDomain(const escript::AbstractDomain* domain);
82 
85  // setDomain(), otherwise you will get undefined behaviour later!
86  bool addData(escript::Data& data, const std::string name,
87  const std::string units = "");
88 
99  bool loadNetCDF(const std::string domainFilePattern,
100  const StringVec& varFiles, const StringVec& varNames,
101  int nChunks);
102 
105  bool loadNetCDF(const DomainChunks& domain, const StringVec& varFiles,
106  const StringVec& varNames);
107 
109  void setCycleAndTime(int c, double t) { cycle=c; time=t; }
110 
112  int getCycle() const { return cycle; }
113 
115  double getTime() const { return time; }
116 
119  void setMeshLabels(const std::string x, const std::string y, const std::string z="");
120 
123  void setMeshUnits(const std::string x, const std::string y, const std::string z="");
124 
127  void setMetadataSchemaString(const std::string schema,
128  const std::string metadata)
129  { mdSchema=schema; mdString=metadata; }
130 
132  void setSaveMeshData(bool flag) { wantsMeshVars=flag; }
133 
135  bool saveSilo(const std::string fileName, bool useMultiMesh=true);
136 
138  bool saveVTK(const std::string fileName);
139 
141  DomainChunks getConvertedDomain() { return domainChunks; }
142 
144  const VarVector& getVariables() const { return variables; }
145 
147  const VarVector& getMeshVariables() const { return meshVariables; }
148 
149 #if HAVE_MPI
150  MPI_Comm
151 #else
152  void*
153 #endif
154  getMPIComm() { return mpiComm; }
155 
156 private:
157  bool loadDomain(const std::string filePattern, int nChunks);
158  bool setExternalDomain(const DomainChunks& domain);
159  bool loadData(const std::string filePattern, const std::string name,
160  const std::string units);
161 
162  void convertMeshVariables();
163  void updateSampleDistribution(VarInfo& vi);
164  void putSiloMultiMesh(DBfile* dbfile, const std::string& meshName);
165  void putSiloMultiTensor(DBfile* dbfile, const VarInfo& vi);
166  void putSiloMultiVar(DBfile* dbfile, const VarInfo& vi,
167  bool useMeshFile = false);
168  bool saveVTKsingle(const std::string& fileName,
169  const std::string& meshName, const VarVector& vars);
170  void writeVarToVTK(const VarInfo& varInfo, std::ostream& os);
171 
172  int cycle;
173  double time;
174  std::string mdSchema, mdString;
175  StringVec meshLabels, meshUnits;
176  bool externalDomain, wantsMeshVars;
178  VarVector variables, meshVariables;
179  int mpiRank, mpiSize;
180 #if HAVE_MPI
181  MPI_Comm mpiComm;
182 #else
183  void* mpiComm;
184 #endif
185 };
186 
187 } // namespace weipa
188 
189 #endif // __WEIPA_ESCRIPTDATASET_H__
190