11 |
* |
* |
12 |
*******************************************************/ |
*******************************************************/ |
13 |
|
|
14 |
// |
#ifndef __ESCRIPTDATASET_H__ |
15 |
// MPDataSet.h |
#define __ESCRIPTDATASET_H__ |
|
// |
|
|
#ifndef __MPDATASET_H__ |
|
|
#define __MPDATASET_H__ |
|
16 |
|
|
17 |
#include <escriptreader/common.h> |
#include <escriptexport/escriptexport.h> |
18 |
|
#include <escript/AbstractDomain.h> |
19 |
|
|
20 |
class DBfile; |
class DBfile; |
21 |
|
|
22 |
namespace EscriptReader { |
namespace escript { |
23 |
|
|
24 |
|
class Data; |
25 |
|
|
26 |
|
} |
27 |
|
|
28 |
|
|
29 |
class DataVar; |
namespace escriptexport { |
|
class MeshWithElements; |
|
30 |
|
|
31 |
typedef std::vector<MeshWithElements*> MeshBlocks; |
typedef std::vector<escript::Data> DataVec; |
32 |
|
typedef std::vector<DataVar_ptr> DataBlocks; |
33 |
|
typedef std::vector<FinleyMesh_ptr> MeshBlocks; |
34 |
|
|
35 |
struct VarInfo { |
struct VarInfo { |
36 |
std::string fileName; |
std::string fileName; |
37 |
std::string varName; |
std::string varName; |
38 |
DataVar* dataVar; |
DataBlocks dataBlocks; |
39 |
bool valid; |
bool valid; |
40 |
}; |
}; |
41 |
|
|
42 |
typedef std::vector<VarInfo> VarVector; |
typedef std::vector<VarInfo> VarVector; |
43 |
|
|
44 |
|
|
45 |
/// \brief Represents an escript/finley dataset including mesh and variables for |
/// \brief Represents an escript dataset including domain and variables for |
46 |
/// one timestep. The domain may consist of multiple blocks. |
/// one timestep. |
47 |
class MPDataSet |
// |
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: |
public: |
62 |
/// \brief Constructor. |
/// \brief Constructor. |
63 |
MPDataSet(); |
ESCRIPTEXPORT_DLL_API |
64 |
|
EscriptDataset(); |
65 |
|
|
66 |
/// \brief Destructor. |
/// \brief Destructor. |
67 |
~MPDataSet(); |
ESCRIPTEXPORT_DLL_API |
68 |
|
~EscriptDataset(); |
69 |
|
|
70 |
/// \brief Loads mesh and variables. |
/// \brief Initialises with instances of escript domain and data. |
71 |
bool load(const std::string meshFile, const StringVec& varFiles, |
ESCRIPTEXPORT_DLL_API |
72 |
const StringVec& varNames, int nBlocks); |
bool initFromEscript(escript::const_Domain_ptr mesh, |
73 |
|
DataVec& escriptVars, const StringVec& varNames); |
74 |
/// \brief Loads only variables using given external mesh. |
|
75 |
bool load(const MeshBlocks& m, const std::string siloFile, |
/// \brief Loads mesh and variables from escript NetCDF files. |
76 |
const StringVec& varFiles, const StringVec& varNames); |
ESCRIPTEXPORT_DLL_API |
77 |
|
bool loadNetCDF(const std::string meshFile, const StringVec& varFiles, |
78 |
/// \brief Saves the dataset to a Silo file. |
const StringVec& varNames, int nBlocks); |
79 |
bool saveAsSilo(const std::string siloFile, bool useMultiMesh=true); |
|
80 |
|
/// \brief Loads only variables from escript NetCDF files using given mesh. |
81 |
|
ESCRIPTEXPORT_DLL_API |
82 |
|
bool loadNetCDF(const MeshBlocks& mesh, const StringVec& varFiles, |
83 |
|
const StringVec& varNames); |
84 |
|
|
85 |
|
/// \brief Sets the cycle number and time value for this dataset. |
86 |
|
ESCRIPTEXPORT_DLL_API |
87 |
|
void setCycleAndTime(int c, double t) { cycle=c; time=t; } |
88 |
|
|
89 |
|
/// \brief Saves the dataset in the Silo file format. |
90 |
|
ESCRIPTEXPORT_DLL_API |
91 |
|
bool saveSilo(const std::string fileName, bool useMultiMesh=true); |
92 |
|
|
93 |
|
/// \brief Saves the dataset in the VTK XML file format. |
94 |
|
/// \note NOT IMPLEMENTED. |
95 |
|
ESCRIPTEXPORT_DLL_API |
96 |
|
bool saveVTK(const std::string fileName); |
97 |
|
|
98 |
/// \brief Returns the dataset's mesh. |
/// \brief Returns the dataset's mesh. |
99 |
/// |
/// |
100 |
/// \note The caller is responsible for freeing the memory of the returned |
/// \note The caller is responsible for freeing the memory of the returned |
101 |
/// mesh. |
/// mesh. |
102 |
|
ESCRIPTEXPORT_DLL_API |
103 |
MeshBlocks extractMesh() { keepMesh = true; return meshBlocks; } |
MeshBlocks extractMesh() { keepMesh = true; return meshBlocks; } |
104 |
|
|
105 |
/// \brief Returns the dataset's mesh. |
/// \brief Returns the dataset's mesh. |
106 |
|
ESCRIPTEXPORT_DLL_API |
107 |
const MeshBlocks& getMesh() const { return meshBlocks; } |
const MeshBlocks& getMesh() const { return meshBlocks; } |
108 |
|
|
109 |
/// \brief Returns a vector with the dataset's variables. |
/// \brief Returns a vector with the dataset's variables. |
110 |
|
ESCRIPTEXPORT_DLL_API |
111 |
const VarVector& getVariables() const { return variables; } |
const VarVector& getVariables() const { return variables; } |
112 |
|
|
113 |
/// \brief Returns a vector with the mesh variables. |
/// \brief Returns a vector with the mesh variables. |
114 |
|
ESCRIPTEXPORT_DLL_API |
115 |
const VarVector& getMeshVariables() const { return meshVariables; } |
const VarVector& getMeshVariables() const { return meshVariables; } |
116 |
|
|
117 |
private: |
private: |
118 |
typedef std::vector<DataVar*> DataParts; |
bool loadMeshFromNetCDF(); |
119 |
|
bool loadVariablesFromNetCDF(); |
|
bool readMeshes(); |
|
|
bool readVariables(); |
|
120 |
void convertMeshVariables(); |
void convertMeshVariables(); |
121 |
void assembleVariable(VarInfo& vi, const DataParts& parts); |
void putSiloMultiMesh(DBfile* dbfile, const std::string& meshName); |
122 |
void putSiloMultiMesh(DBfile* dbfile, std::string meshName); |
void putSiloMultiTensor(DBfile* dbfile, const VarInfo& vi); |
123 |
void putSiloMultiTensor(DBfile* dbfile, const DataVar* var); |
void putSiloMultiVar(DBfile* dbfile, const VarInfo& vi, |
|
void putSiloMultiVar(DBfile* dbfile, std::string varName, |
|
124 |
bool useMeshFile = false); |
bool useMeshFile = false); |
125 |
|
|
126 |
int numParts; |
int numParts; |
127 |
bool keepMesh; |
int cycle; |
128 |
|
double time; |
129 |
|
bool keepMesh, externalMesh; |
130 |
std::string meshFmt; |
std::string meshFmt; |
|
std::string siloMeshFile; |
|
131 |
MeshBlocks meshBlocks; |
MeshBlocks meshBlocks; |
132 |
VarVector variables, meshVariables; |
VarVector variables, meshVariables; |
133 |
|
int mpiRank, mpiSize; |
134 |
|
#if HAVE_MPI |
135 |
|
MPI_Comm mpiComm; |
136 |
|
#else |
137 |
|
void* mpiComm; |
138 |
|
#endif |
139 |
}; |
}; |
140 |
|
|
141 |
} // namespace EscriptReader |
} // namespace escriptexport |
142 |
|
|
143 |
#endif // __MPDATASET_H__ |
#endif // __ESCRIPTDATASET_H__ |
144 |
|
|