forked from sandialabs/omega_h
-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathOmega_h_file.hpp
More file actions
272 lines (238 loc) · 10.1 KB
/
Copy pathOmega_h_file.hpp
File metadata and controls
272 lines (238 loc) · 10.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
#ifndef OMEGA_H_FILE_HPP
#define OMEGA_H_FILE_HPP
#include <iosfwd>
#include <vector>
#include <Omega_h_config.h>
#include <Omega_h_array.hpp>
#include <Omega_h_comm.hpp>
#include <Omega_h_defines.hpp>
#include <Omega_h_mesh.hpp>
#include <Omega_h_mixedMesh.hpp>
#include <Omega_h_tag.hpp>
#include <filesystem>
#ifdef OMEGA_H_USE_SIMMODSUITE
#include "MeshSim.h"
#endif
namespace Omega_h {
OMEGA_H_DLL Mesh read_mesh_file(std::filesystem::path const& path, CommPtr comm);
bool is_little_endian_cpu();
#ifdef OMEGA_H_USE_LIBMESHB
namespace meshb {
void read(Mesh* mesh, std::string const& filepath);
void write(Mesh* mesh, std::string const& filepath, int version = 2);
void read_sol(
Mesh* mesh, std::string const& filepath, std::string const& sol_name);
void write_sol(Mesh* mesh, std::string const& filepath,
std::string const& sol_name, int version = 2);
} // namespace meshb
#endif
#ifdef OMEGA_H_USE_SIMMODSUITE
namespace meshsim {
/**
* Return if the mesh is mixed or mono topology
* @param[in] mesh path to Simmetrix .sms mesh file
* @param[in] model path to Simmetrix GeomSim .smd model file
*/
bool isMixed(filesystem::path const& mesh, filesystem::path const& model);
/**
* Convert a serial Simmetrix sms mesh classified on the specified model to an
* Omega_h mesh instance.
* @param[in] pointer to Simmetrix mesh instance (pMesh)
* @param[in] numbering path to Simmetrix MeshNex .nex numbering file
* @param[in] comm path to Omega_h communicator instance
* @param[in][optional] a pointer to pMeshDataId for coordinate transformation
* data attached to mesh vertices.
*/
Mesh read(pMesh* m, filesystem::path const& numbering_fname, CommPtr comm, pMeshDataId* transformedCoordId = NULL);
/**
* Convert a serial Simmetrix sms mesh classified on the specified model to an
* Omega_h mesh instance.
* @param[in] mesh path to Simmetrix .sms mesh file
* @param[in] model path to Simmetrix GeomSim .smd model file
* @param[in] comm path to Omega_h communicator instance
*/
Mesh read(filesystem::path const& mesh, filesystem::path const& model,
CommPtr comm);
/**
* Convert a mono topology (i.e., all tets, all triangles, all hex, etc.)
* serial Simmetrix sms mesh classified on the specified model to an
* Omega_h mesh instance and attach a Simmetrix MeshNex vertex numbering.
* @param[in] mesh path to Simmetrix .sms mesh file
* @param[in] model path to Simmetrix GeomSim .smd model file
* @param[in] numbering path to Simmetrix MeshNex .nex numbering file
* @param[in] comm path to Omega_h communicator instance
*/
Mesh read(filesystem::path const& mesh, filesystem::path const& model,
filesystem::path const& numbering, CommPtr comm);
/**
* Convert a mixed topology (i.e., tet + wedge) serial Simmetrix sms mesh
* classified on the specified model to an Omega_h mesh instance.
* @param[in] mesh path to Simmetrix .sms mesh file
* @param[in] model path to Simmetrix GeomSim .smd model file
* @param[in] comm path to Omega_h communicator instance
*/
MixedMesh readMixed(filesystem::path const& mesh, filesystem::path const& model,
CommPtr comm);
void matchRead(filesystem::path const& mesh_fname, filesystem::path const& model,
CommPtr comm, Mesh *mesh, I8 is_in);
} // namespace meshsim
#endif
#ifdef OMEGA_H_USE_SEACASEXODUS
namespace exodus {
enum ClassifyWith {
NODE_SETS = 0x1,
SIDE_SETS = 0x2,
};
int open(filesystem::path const& path, bool verbose = false);
void close(int exodus_file);
int get_num_time_steps(int exodus_file);
void read_mesh(int exodus_file, Mesh* mesh, bool verbose = false,
int classify_with = NODE_SETS | SIDE_SETS);
void read_nodal_fields(int exodus_file, Mesh* mesh, int time_step,
std::string const& prefix = "", std::string const& postfix = "",
bool verbose = false);
void read_element_fields(int exodus_file, Mesh* mesh, int time_step,
std::string const& prefix = "", std::string const& postfix = "",
bool verbose = false);
typedef std::vector<std::string> FieldNames;
void write(filesystem::path const& path, Mesh* mesh, bool verbose = false,
int classify_with = NODE_SETS | SIDE_SETS,
FieldNames excludedNodalFields = FieldNames());
Mesh read_sliced(filesystem::path const& path, CommPtr comm,
bool verbose = false, int classify_with = NODE_SETS | SIDE_SETS,
int time_step = -1);
} // namespace exodus
#endif
namespace gmsh {
Mesh read(std::istream& stream, CommPtr comm);
Mesh read(std::filesystem::path const& filename, CommPtr comm);
void write(std::ostream& stream, Mesh* mesh);
void write(std::filesystem::path const& filepath, Mesh* mesh);
#ifdef OMEGA_H_USE_GMSH
/**
* Load a parallel MSH file specified in format version 4.1 or higher.
*
* \param filename path to mesh prefix. If "/path/to/square" is passed,
* then the loader looks for parts "/path/to/square_$((RANK+1)).msh"
* \note The caller has the responsibility to initialize Gmsh library
* before calling this function with \c ::gmsh::initialize
*/
Mesh read_parallel(filesystem::path filename, CommPtr comm);
/**
* Write the specified mesh in MSH format version 4.1
*
* \note The caller has the responsibility to initialize Gmsh library
* before calling this function with \c ::gmsh::initialize
*/
void write_parallel(filesystem::path const& filename, Mesh& mesh);
#endif // OMEGA_H_USE_GMSH
} // namespace gmsh
namespace vtk {
static constexpr bool do_compress = true;
static constexpr bool dont_compress = false;
#ifdef OMEGA_H_USE_ZLIB
#define OMEGA_H_DEFAULT_COMPRESS true
#else
#define OMEGA_H_DEFAULT_COMPRESS false
#endif
TagSet get_all_vtk_tags(Mesh* mesh, Int cell_dim);
TagSet get_all_vtk_tags_mix(Mesh* mesh, Int cell_dim);
void write_vtu(std::ostream& stream, Mesh* mesh, Int cell_dim,
TagSet const& tags, bool compress = OMEGA_H_DEFAULT_COMPRESS);
void write_vtu(std::filesystem::path const& filename, Mesh* mesh, Int cell_dim,
TagSet const& tags, bool compress = OMEGA_H_DEFAULT_COMPRESS);
void write_vtu(std::string const& filename, Mesh* mesh, Int cell_dim,
bool compress = OMEGA_H_DEFAULT_COMPRESS);
void write_vtu(std::string const& filename, Mesh* mesh,
bool compress = OMEGA_H_DEFAULT_COMPRESS);
void write_vtu(std::filesystem::path const& filename, MixedMesh* mesh, Topo_type max_type,
bool compress = OMEGA_H_DEFAULT_COMPRESS);
void write_parallel(std::filesystem::path const& path, Mesh* mesh, Int cell_dim,
TagSet const& tags, bool compress = OMEGA_H_DEFAULT_COMPRESS);
void write_parallel(std::string const& path, Mesh* mesh, Int cell_dim,
bool compress = OMEGA_H_DEFAULT_COMPRESS);
void write_parallel(std::string const& path, Mesh* mesh,
bool compress = OMEGA_H_DEFAULT_COMPRESS);
void read_parallel(std::filesystem::path const& pvtupath, CommPtr comm, Mesh* mesh);
void read_vtu(std::istream& stream, CommPtr comm, Mesh* mesh);
class Writer {
Mesh* mesh_;
std::filesystem::path root_path_;
Int cell_dim_;
bool compress_;
I64 step_;
std::streampos pvd_pos_;
public:
Writer();
Writer(Writer const&) = default;
Writer& operator=(Writer const&) = default;
~Writer() = default;
Writer(std::filesystem::path const& root_path, Mesh* mesh, Int cell_dim = -1,
Real restart_time = 0.0, bool compress = OMEGA_H_DEFAULT_COMPRESS);
void write();
void write(Real time);
void write(Real time, TagSet const& tags);
void write(I64 step, Real time, TagSet const& tags);
};
class FullWriter {
std::vector<Writer> writers_;
public:
FullWriter() = default;
FullWriter(std::filesystem::path const& root_path, Mesh* mesh,
Real restart_time = 0.0, bool compress = OMEGA_H_DEFAULT_COMPRESS);
void write(Real time);
void write();
};
} // end namespace vtk
namespace binary {
void write(std::filesystem::path const& path, Mesh* mesh);
Mesh read(std::filesystem::path const& path, Library* lib, bool strict = false);
Mesh read(std::filesystem::path const& path, CommPtr comm, bool strict = false);
I32 read(std::filesystem::path const& path, CommPtr comm, Mesh* mesh,
bool strict = false);
I32 read_nparts(std::filesystem::path const& path, CommPtr comm);
I32 read_version(std::filesystem::path const& path, CommPtr comm);
void read_in_comm(
std::filesystem::path const& path, CommPtr comm, Mesh* mesh, I32 version);
constexpr I32 latest_version = 10;
template <typename T>
void swap_bytes(T&);
template <typename T>
Read<T> swap_bytes(Read<T> array, bool needs_swapping);
template <typename T>
void write_value(std::ostream& stream, T val, bool needs_swapping);
template <typename T>
void read_value(std::istream& stream, T& val, bool needs_swapping);
template <typename T>
void write_array(std::ostream& stream, Read<T> array, bool is_compressed,
bool needs_swapping);
template <typename T>
void read_array(std::istream& stream, Read<T>& array, bool is_compressed,
bool needs_swapping);
void write(std::ostream& stream, std::string const& val, bool needs_swapping);
void read(std::istream& stream, std::string& val, bool needs_swapping);
void write(std::ostream& stream, Mesh* mesh);
void read(std::istream& stream, Mesh* mesh, I32 version);
#define INST_DECL(T) \
extern template void swap_bytes(T&); \
extern template Read<T> swap_bytes(Read<T> array, bool needs_swapping); \
extern template void write_value(std::ostream& stream, T val, bool); \
extern template void read_value(std::istream& stream, T& val, bool); \
extern template void write_array( \
std::ostream& stream, Read<T> array, bool, bool); \
extern template void read_array( \
std::istream& stream, Read<T>& array, bool, bool);
INST_DECL(I8)
INST_DECL(I32)
INST_DECL(I64)
INST_DECL(Real)
#undef INST_DECL
// for VTK compression headers
extern template void swap_bytes(std::uint64_t&);
} // namespace binary
void write_reals_txt(std::filesystem::path const& filename, Reals a, Int ncomps);
void write_reals_txt(std::ostream& stream, Reals a, Int ncomps);
Reals read_reals_txt(std::filesystem::path const& filename, LO n, Int ncomps);
Reals read_reals_txt(std::istream& stream, LO n, Int ncomps);
} // namespace Omega_h
#endif