escript  Revision_
EscriptDataset.h
Go to the documentation of this file.
00001 
00002 /*****************************************************************************
00003 *
00004 * Copyright (c) 2003-2014 by University of Queensland
00005 * http://www.uq.edu.au
00006 *
00007 * Primary Business: Queensland, Australia
00008 * Licensed under the Open Software License version 3.0
00009 * http://www.opensource.org/licenses/osl-3.0.php
00010 *
00011 * Development until 2012 by Earth Systems Science Computational Center (ESSCC)
00012 * Development 2012-2013 by School of Earth Sciences
00013 * Development from 2014 by Centre for Geoscience Computing (GeoComp)
00014 *
00015 *****************************************************************************/
00016 
00017 #ifndef __WEIPA_ESCRIPTDATASET_H__
00018 #define __WEIPA_ESCRIPTDATASET_H__
00019 
00020 #include <weipa/weipa.h>
00021 
00022 #include <ostream>
00023 
00024 class DBfile;
00025 
00026 namespace escript {
00027     class AbstractDomain;
00028     class Data;
00029 }
00030 
00031 
00032 namespace weipa {
00033 
00034 typedef std::vector<DataVar_ptr>     DataChunks;
00035 typedef std::vector<DomainChunk_ptr> DomainChunks;
00036 
00037 struct VarInfo {
00038     std::string varName;
00039     std::string units;
00040     DataChunks dataChunks;
00041     IntVec sampleDistribution;
00042     bool valid;
00043 };
00044 
00045 typedef std::vector<VarInfo> VarVector;
00046 
00047 
00050 //
00062 class WEIPA_DLL_API EscriptDataset
00063 {
00064 public:
00066     EscriptDataset();
00067 
00068 #if HAVE_MPI
00069 
00070     EscriptDataset(MPI_Comm comm);
00071 #endif
00072 
00074     ~EscriptDataset();
00075 
00082     bool setDomain(const escript::AbstractDomain* domain);
00083 
00086     //         setDomain(), otherwise you will get undefined behaviour later!
00087     bool addData(escript::Data& data, const std::string name,
00088                  const std::string units = "");
00089 
00100     bool loadNetCDF(const std::string domainFilePattern,
00101                     const StringVec& varFiles, const StringVec& varNames,
00102                     int nChunks);
00103 
00106     bool loadNetCDF(const DomainChunks& domain, const StringVec& varFiles,
00107                     const StringVec& varNames);
00108 
00110     void setCycleAndTime(int c, double t) { cycle=c; time=t; }
00111 
00113     int getCycle() const { return cycle; }
00114 
00116     double getTime() const { return time; }
00117 
00120     void setMeshLabels(const std::string x, const std::string y, const std::string z="");
00121 
00124     void setMeshUnits(const std::string x, const std::string y, const std::string z="");
00125 
00128     void setMetadataSchemaString(const std::string schema,
00129                                  const std::string metadata)
00130         { mdSchema=schema; mdString=metadata; }
00131 
00133     void setSaveMeshData(bool flag) { wantsMeshVars=flag; }
00134 
00136     bool saveSilo(const std::string fileName, bool useMultiMesh=true);
00137 
00139     bool saveVTK(const std::string fileName);
00140 
00142     DomainChunks getConvertedDomain() { return domainChunks; }
00143 
00145     const VarVector& getVariables() const { return variables; }
00146 
00148     const VarVector& getMeshVariables() const { return meshVariables; }
00149 
00150 #if HAVE_MPI
00151     MPI_Comm
00152 #else
00153     void*
00154 #endif
00155         getMPIComm() { return mpiComm; }
00156 
00157 private:
00158     bool loadDomain(const std::string filePattern, int nChunks);
00159     bool setExternalDomain(const DomainChunks& domain);
00160     bool loadData(const std::string filePattern, const std::string name,
00161                   const std::string units);
00162 
00163     void convertMeshVariables();
00164     void updateSampleDistribution(VarInfo& vi);
00165     void putSiloMultiMesh(DBfile* dbfile, const std::string& meshName);
00166     void putSiloMultiTensor(DBfile* dbfile, const VarInfo& vi);
00167     void putSiloMultiVar(DBfile* dbfile, const VarInfo& vi,
00168                          bool useMeshFile = false);
00169     bool saveVTKsingle(const std::string& fileName,
00170                        const std::string& meshName, const VarVector& vars);
00171     void writeVarToVTK(const VarInfo& varInfo, std::ostream& os);
00172 
00173     int cycle;
00174     double time;
00175     std::string mdSchema, mdString;
00176     StringVec meshLabels, meshUnits;
00177     bool externalDomain, wantsMeshVars;
00178     DomainChunks domainChunks;
00179     VarVector variables, meshVariables;
00180     int mpiRank, mpiSize;
00181 #if HAVE_MPI
00182     MPI_Comm mpiComm;
00183 #else
00184     void* mpiComm;
00185 #endif
00186 };
00187 
00188 } // namespace weipa
00189 
00190 #endif // __WEIPA_ESCRIPTDATASET_H__
00191