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 fileName; |
37 |
std::string varName; |
38 |
DataBlocks dataBlocks; |
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 Constructor. |
63 |
ESCRIPTEXPORT_DLL_API |
64 |
EscriptDataset(); |
65 |
|
66 |
/// \brief Destructor. |
67 |
ESCRIPTEXPORT_DLL_API |
68 |
~EscriptDataset(); |
69 |
|
70 |
/// \brief Initialises with instances of escript domain and data. |
71 |
ESCRIPTEXPORT_DLL_API |
72 |
bool initFromEscript(escript::const_Domain_ptr mesh, |
73 |
DataVec& escriptVars, const StringVec& varNames); |
74 |
|
75 |
/// \brief Loads mesh and variables from escript NetCDF files. |
76 |
ESCRIPTEXPORT_DLL_API |
77 |
bool loadNetCDF(const std::string meshFile, const StringVec& varFiles, |
78 |
const StringVec& varNames, int nBlocks); |
79 |
|
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. |
99 |
/// |
100 |
/// \note The caller is responsible for freeing the memory of the returned |
101 |
/// mesh. |
102 |
ESCRIPTEXPORT_DLL_API |
103 |
MeshBlocks extractMesh() { keepMesh = true; return meshBlocks; } |
104 |
|
105 |
/// \brief Returns the dataset's mesh. |
106 |
ESCRIPTEXPORT_DLL_API |
107 |
const MeshBlocks& getMesh() const { return meshBlocks; } |
108 |
|
109 |
/// \brief Returns a vector with the dataset's variables. |
110 |
ESCRIPTEXPORT_DLL_API |
111 |
const VarVector& getVariables() const { return variables; } |
112 |
|
113 |
/// \brief Returns a vector with the mesh variables. |
114 |
ESCRIPTEXPORT_DLL_API |
115 |
const VarVector& getMeshVariables() const { return meshVariables; } |
116 |
|
117 |
private: |
118 |
bool loadMeshFromNetCDF(); |
119 |
bool loadVariablesFromNetCDF(); |
120 |
void convertMeshVariables(); |
121 |
void putSiloMultiMesh(DBfile* dbfile, const std::string& meshName); |
122 |
void putSiloMultiTensor(DBfile* dbfile, const VarInfo& vi); |
123 |
void putSiloMultiVar(DBfile* dbfile, const VarInfo& vi, |
124 |
bool useMeshFile = false); |
125 |
|
126 |
int numParts; |
127 |
int cycle; |
128 |
double time; |
129 |
bool keepMesh, externalMesh; |
130 |
std::string meshFmt; |
131 |
MeshBlocks meshBlocks; |
132 |
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 escriptexport |
142 |
|
143 |
#endif // __ESCRIPTDATASET_H__ |
144 |
|