omega_h
Reliable mesh adaptation
Omega_h_file.hpp
Go to the documentation of this file.
1 #ifndef OMEGA_H_FILE_HPP
2 #define OMEGA_H_FILE_HPP
3 
4 #include <iosfwd>
5 #include <vector>
6 #include <fstream>
7 
8 #include <Omega_h_config.h>
9 #include <Omega_h_array.hpp>
10 #include <Omega_h_comm.hpp>
11 #include <Omega_h_defines.hpp>
12 #include <Omega_h_filesystem.hpp>
13 #include <Omega_h_mesh.hpp>
14 #include <Omega_h_mixedMesh.hpp>
15 #include <Omega_h_tag.hpp>
16 
17 #ifdef OMEGA_H_USE_SIMMODSUITE
18 #include "MeshSim.h"
19 #endif
20 
26 namespace Omega_h {
27 
28 OMEGA_H_DLL Mesh read_mesh_file(filesystem::path const& path, CommPtr comm);
29 
30 bool is_little_endian_cpu();
31 
32 #ifdef OMEGA_H_USE_LIBMESHB
33 namespace meshb {
34 void read(Mesh* mesh, std::string const& filepath);
35 void write(Mesh* mesh, std::string const& filepath, int version = 2);
36 void read_sol(
37  Mesh* mesh, std::string const& filepath, std::string const& sol_name);
38 void write_sol(Mesh* mesh, std::string const& filepath,
39  std::string const& sol_name, int version = 2);
40 } // namespace meshb
41 #endif
42 
43 #ifdef OMEGA_H_USE_SIMMODSUITE
45 namespace meshsim {
51 bool isMixed(filesystem::path const& mesh, filesystem::path const& model);
61 Mesh read(pMesh* m, filesystem::path const& numbering_fname, CommPtr comm, pMeshDataId* transformedCoordId = NULL);
69 Mesh read(filesystem::path const& mesh, filesystem::path const& model,
70  CommPtr comm);
80 Mesh read(filesystem::path const& mesh, filesystem::path const& model,
81  filesystem::path const& numbering, CommPtr comm);
89 MixedMesh readMixed(filesystem::path const& mesh, filesystem::path const& model,
90  CommPtr comm);
91 void matchRead(filesystem::path const& mesh_fname, filesystem::path const& model,
92  CommPtr comm, Mesh *mesh, I8 is_in);
93 } // namespace meshsim
94 #endif
95 
96 #ifdef OMEGA_H_USE_SEACASEXODUS
98 namespace exodus {
99 enum ClassifyWith {
100  NODE_SETS = 0x1,
101  SIDE_SETS = 0x2,
102 };
103 int open(filesystem::path const& path, bool verbose = false);
104 void close(int exodus_file);
105 int get_num_time_steps(int exodus_file);
106 
146 void read_mesh(int exodus_file, Mesh* mesh, bool verbose = false,
147  int classify_with = NODE_SETS | SIDE_SETS);
167 void read_nodal_fields(int exodus_file, Mesh* mesh, int time_step,
168  std::string const& prefix = "", std::string const& postfix = "",
169  bool verbose = false, bool merge_components = false);
176 void read_element_fields(int exodus_file, Mesh* mesh, int time_step,
177  std::string const& prefix = "", std::string const& postfix = "",
178  bool verbose = false, bool merge_components = false);
179 typedef std::vector<std::string> FieldNames;
197 void write(filesystem::path const& path, Mesh* mesh, bool verbose = false,
198  int classify_with = NODE_SETS | SIDE_SETS,
199  FieldNames excludedNodalFields = FieldNames());
225 Mesh read_sliced(filesystem::path const& path, CommPtr comm,
226  bool verbose = false, int classify_with = NODE_SETS | SIDE_SETS,
227  int time_step = -1, bool merge_components = false);
228 } // namespace exodus
229 #endif
230 
231 namespace gmsh {
232 Mesh read(std::istream& stream, CommPtr comm);
233 Mesh read(filesystem::path const& filename, CommPtr comm);
234 void write(std::ostream& stream, Mesh* mesh);
235 void write(filesystem::path const& filepath, Mesh* mesh);
236 
237 #ifdef OMEGA_H_USE_GMSH
238 
247 Mesh read_parallel(filesystem::path filename, CommPtr comm);
248 
255 void write_parallel(filesystem::path const& filename, Mesh& mesh);
256 #endif // OMEGA_H_USE_GMSH
257 
258 } // namespace gmsh
259 
260 namespace vtk {
261 static constexpr bool do_compress = true;
262 static constexpr bool dont_compress = false;
263 #ifdef OMEGA_H_USE_ZLIB
264 #define OMEGA_H_DEFAULT_COMPRESS true
265 #else
266 #define OMEGA_H_DEFAULT_COMPRESS false
267 #endif
268 TagSet get_all_vtk_tags(Mesh* mesh, Int cell_dim);
269 TagSet get_all_vtk_tags_mix(Mesh* mesh, Int cell_dim);
270 void write_vtu(std::ostream& stream, Mesh* mesh, Int cell_dim,
271  TagSet const& tags, bool compress = OMEGA_H_DEFAULT_COMPRESS);
272 void write_vtu(filesystem::path const& filename, Mesh* mesh, Int cell_dim,
273  TagSet const& tags, bool compress = OMEGA_H_DEFAULT_COMPRESS);
274 void write_vtu(std::string const& filename, Mesh* mesh, Int cell_dim,
275  bool compress = OMEGA_H_DEFAULT_COMPRESS);
276 void write_vtu(std::string const& filename, Mesh* mesh,
277  bool compress = OMEGA_H_DEFAULT_COMPRESS);
278 
279 void write_vtu(filesystem::path const& filename, MixedMesh* mesh, Topo_type max_type,
280  bool compress = OMEGA_H_DEFAULT_COMPRESS);
281 
282 void write_parallel(filesystem::path const& path, Mesh* mesh, Int cell_dim,
283  TagSet const& tags, bool compress = OMEGA_H_DEFAULT_COMPRESS);
284 void write_parallel(std::string const& path, Mesh* mesh, Int cell_dim,
285  bool compress = OMEGA_H_DEFAULT_COMPRESS);
286 void write_parallel(std::string const& path, Mesh* mesh,
287  bool compress = OMEGA_H_DEFAULT_COMPRESS);
288 
289 void read_parallel(filesystem::path const& pvtupath, CommPtr comm, Mesh* mesh);
290 void read_vtu(std::istream& stream, CommPtr comm, Mesh* mesh);
291 
292 class Writer {
293  Mesh* mesh_;
294  filesystem::path root_path_;
295  Int cell_dim_;
296  bool compress_;
297  I64 step_;
298  std::streampos pvd_pos_;
299 
300  public:
301  Writer();
302  Writer(Writer const&) = default;
303  Writer& operator=(Writer const&) = default;
304  ~Writer() = default;
305  Writer(filesystem::path const& root_path, Mesh* mesh, Int cell_dim = -1,
306  Real restart_time = 0.0, bool compress = OMEGA_H_DEFAULT_COMPRESS);
307  void write();
308  void write(Real time);
309  void write(Real time, TagSet const& tags);
310  void write(I64 step, Real time, TagSet const& tags);
311 };
312 class FullWriter {
313  std::vector<Writer> writers_;
314 
315  public:
316  FullWriter() = default;
317  FullWriter(filesystem::path const& root_path, Mesh* mesh,
318  Real restart_time = 0.0, bool compress = OMEGA_H_DEFAULT_COMPRESS);
319  void write(Real time);
320  void write();
321 };
322 } // end namespace vtk
323 
324 namespace binary {
325 
326 void write(filesystem::path const& path, Mesh* mesh);
327 Mesh read(filesystem::path const& path, Library* lib, bool strict = false);
328 Mesh read(filesystem::path const& path, CommPtr comm, bool strict = false);
329 I32 read(filesystem::path const& path, CommPtr comm, Mesh* mesh,
330  bool strict = false);
331 I32 read_nparts(filesystem::path const& path, CommPtr comm);
332 I32 read_version(filesystem::path const& path, CommPtr comm);
333 void read_in_comm(
334  filesystem::path const& path, CommPtr comm, Mesh* mesh, I32 version);
335 
336 constexpr I32 latest_version = 11;
337 
338 template <typename T>
339 void swap_bytes(T&);
340 
341 template <typename T>
342 Read<T> swap_bytes(Read<T> array, bool needs_swapping);
343 
344 template <typename T>
345 void write_value(std::ostream& stream, T val, bool needs_swapping);
346 template <typename T>
347 void read_value(std::istream& stream, T& val, bool needs_swapping);
348 template <typename T>
349 void write_array(std::ostream& stream, Read<T> array, bool is_compressed,
350  bool needs_swapping);
351 template <typename T>
352 void read_array(std::istream& stream, Read<T>& array, bool is_compressed,
353  bool needs_swapping);
354 
355 void write(std::ostream& stream, std::string const& val, bool needs_swapping);
356 void read(std::istream& stream, std::string& val, bool needs_swapping);
357 
358 void write(std::ostream& stream, Mesh* mesh);
359 void read(std::istream& stream, Mesh* mesh, I32 version);
360 
361 #define INST_DECL(T) \
362  extern template void swap_bytes(T&); \
363  extern template Read<T> swap_bytes(Read<T> array, bool needs_swapping); \
364  extern template void write_value(std::ostream& stream, T val, bool); \
365  extern template void read_value(std::istream& stream, T& val, bool); \
366  extern template void write_array( \
367  std::ostream& stream, Read<T> array, bool, bool); \
368  extern template void read_array( \
369  std::istream& stream, Read<T>& array, bool, bool);
370 INST_DECL(I8)
371 INST_DECL(I32)
372 INST_DECL(I64)
373 INST_DECL(Real)
374 #undef INST_DECL
375 
376 // for VTK compression headers
377 extern template void swap_bytes(std::uint64_t&);
378 
379 } // namespace binary
380 
381 void write_reals_txt(filesystem::path const& filename, Reals a, Int ncomps);
382 void write_reals_txt(std::ostream& stream, Reals a, Int ncomps);
383 Reals read_reals_txt(filesystem::path const& filename, LO n, Int ncomps);
384 Reals read_reals_txt(std::istream& stream, LO n, Int ncomps);
385 
386 } // namespace Omega_h
387 
388 #endif
void write_parallel(filesystem::path const &filename, Mesh &mesh)
Definition: Omega_h_gmsh.cpp:812
Mesh read_parallel(filesystem::path filename, CommPtr comm)
Definition: Omega_h_gmsh.cpp:572
Definition: Omega_h_library.hpp:10
Definition: Omega_h_mesh.hpp:35
Definition: Omega_h_array.hpp:89
Definition: Omega_h_filesystem.hpp:22
Definition: Omega_h_file.hpp:312
Definition: Omega_h_file.hpp:292
void read_nodal_fields(int exodus_file, Mesh *mesh, int time_step, std::string const &prefix, std::string const &postfix, bool verbose, bool merge_components)
Read nodal (vertex) fields from an open Exodus file into a mesh.
Definition: Omega_h_exodus.cpp:369
void read_element_fields(int exodus_file, Mesh *mesh, int time_step, std::string const &prefix, std::string const &postfix, bool verbose, bool merge_components)
Read element fields from an open Exodus file into a mesh.
Definition: Omega_h_exodus.cpp:376
void read_mesh(int file, Mesh *mesh, bool verbose, int classify_with)
Read an Exodus II file into an Omega_h::Mesh and assign geometric classification.
Definition: Omega_h_exodus.cpp:383
Mesh read_sliced(filesystem::path const &, CommPtr, bool, int, int, bool)
Collectively read an Exodus II file into a distributed Omega_h::Mesh.
Definition: Omega_h_exodus.cpp:727
void write(filesystem::path const &path, Mesh *mesh, bool verbose, int classify_with, FieldNames excludedNodalFields)
Write an Omega_h::Mesh to an Exodus II file.
Definition: Omega_h_exodus.cpp:783
Mesh read(pMesh *m, filesystem::path const &numbering_fname, CommPtr comm, pMeshDataId *transformedCoordId=NULL)
Definition: Omega_h_meshsim.cpp:727
bool isMixed(filesystem::path const &mesh, filesystem::path const &model)
Definition: Omega_h_meshsim.cpp:751
MixedMesh readMixed(filesystem::path const &mesh, filesystem::path const &model, CommPtr comm)
Definition: Omega_h_meshsim.cpp:773
Definition: amr_mpi_test.cpp:6