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);
148 void read_nodal_fields(int exodus_file, Mesh* mesh, int time_step,
149  std::string const& prefix = "", std::string const& postfix = "",
150  bool verbose = false);
151 void read_element_fields(int exodus_file, Mesh* mesh, int time_step,
152  std::string const& prefix = "", std::string const& postfix = "",
153  bool verbose = false);
154 typedef std::vector<std::string> FieldNames;
155 void write(filesystem::path const& path, Mesh* mesh, bool verbose = false,
156  int classify_with = NODE_SETS | SIDE_SETS,
157  FieldNames excludedNodalFields = FieldNames());
158 Mesh read_sliced(filesystem::path const& path, CommPtr comm,
159  bool verbose = false, int classify_with = NODE_SETS | SIDE_SETS,
160  int time_step = -1);
161 } // namespace exodus
162 #endif
163 
164 namespace gmsh {
165 Mesh read(std::istream& stream, CommPtr comm);
166 Mesh read(filesystem::path const& filename, CommPtr comm);
167 void write(std::ostream& stream, Mesh* mesh);
168 void write(filesystem::path const& filepath, Mesh* mesh);
169 
170 #ifdef OMEGA_H_USE_GMSH
171 
180 Mesh read_parallel(filesystem::path filename, CommPtr comm);
181 
188 void write_parallel(filesystem::path const& filename, Mesh& mesh);
189 #endif // OMEGA_H_USE_GMSH
190 
191 } // namespace gmsh
192 
193 namespace vtk {
194 static constexpr bool do_compress = true;
195 static constexpr bool dont_compress = false;
196 #ifdef OMEGA_H_USE_ZLIB
197 #define OMEGA_H_DEFAULT_COMPRESS true
198 #else
199 #define OMEGA_H_DEFAULT_COMPRESS false
200 #endif
201 TagSet get_all_vtk_tags(Mesh* mesh, Int cell_dim);
202 TagSet get_all_vtk_tags_mix(Mesh* mesh, Int cell_dim);
203 void write_vtu(std::ostream& stream, Mesh* mesh, Int cell_dim,
204  TagSet const& tags, bool compress = OMEGA_H_DEFAULT_COMPRESS);
205 void write_vtu(filesystem::path const& filename, Mesh* mesh, Int cell_dim,
206  TagSet const& tags, bool compress = OMEGA_H_DEFAULT_COMPRESS);
207 void write_vtu(std::string const& filename, Mesh* mesh, Int cell_dim,
208  bool compress = OMEGA_H_DEFAULT_COMPRESS);
209 void write_vtu(std::string const& filename, Mesh* mesh,
210  bool compress = OMEGA_H_DEFAULT_COMPRESS);
211 
212 void write_vtu(filesystem::path const& filename, MixedMesh* mesh, Topo_type max_type,
213  bool compress = OMEGA_H_DEFAULT_COMPRESS);
214 
215 void write_parallel(filesystem::path const& path, Mesh* mesh, Int cell_dim,
216  TagSet const& tags, bool compress = OMEGA_H_DEFAULT_COMPRESS);
217 void write_parallel(std::string const& path, Mesh* mesh, Int cell_dim,
218  bool compress = OMEGA_H_DEFAULT_COMPRESS);
219 void write_parallel(std::string const& path, Mesh* mesh,
220  bool compress = OMEGA_H_DEFAULT_COMPRESS);
221 
222 void read_parallel(filesystem::path const& pvtupath, CommPtr comm, Mesh* mesh);
223 void read_vtu(std::istream& stream, CommPtr comm, Mesh* mesh);
224 
225 class Writer {
226  Mesh* mesh_;
227  filesystem::path root_path_;
228  Int cell_dim_;
229  bool compress_;
230  I64 step_;
231  std::streampos pvd_pos_;
232 
233  public:
234  Writer();
235  Writer(Writer const&) = default;
236  Writer& operator=(Writer const&) = default;
237  ~Writer() = default;
238  Writer(filesystem::path const& root_path, Mesh* mesh, Int cell_dim = -1,
239  Real restart_time = 0.0, bool compress = OMEGA_H_DEFAULT_COMPRESS);
240  void write();
241  void write(Real time);
242  void write(Real time, TagSet const& tags);
243  void write(I64 step, Real time, TagSet const& tags);
244 };
245 class FullWriter {
246  std::vector<Writer> writers_;
247 
248  public:
249  FullWriter() = default;
250  FullWriter(filesystem::path const& root_path, Mesh* mesh,
251  Real restart_time = 0.0, bool compress = OMEGA_H_DEFAULT_COMPRESS);
252  void write(Real time);
253  void write();
254 };
255 } // end namespace vtk
256 
257 namespace binary {
258 
259 void write(filesystem::path const& path, Mesh* mesh);
260 Mesh read(filesystem::path const& path, Library* lib, bool strict = false);
261 Mesh read(filesystem::path const& path, CommPtr comm, bool strict = false);
262 I32 read(filesystem::path const& path, CommPtr comm, Mesh* mesh,
263  bool strict = false);
264 I32 read_nparts(filesystem::path const& path, CommPtr comm);
265 I32 read_version(filesystem::path const& path, CommPtr comm);
266 void read_in_comm(
267  filesystem::path const& path, CommPtr comm, Mesh* mesh, I32 version);
268 
269 constexpr I32 latest_version = 11;
270 
271 template <typename T>
272 void swap_bytes(T&);
273 
274 template <typename T>
275 Read<T> swap_bytes(Read<T> array, bool needs_swapping);
276 
277 template <typename T>
278 void write_value(std::ostream& stream, T val, bool needs_swapping);
279 template <typename T>
280 void read_value(std::istream& stream, T& val, bool needs_swapping);
281 template <typename T>
282 void write_array(std::ostream& stream, Read<T> array, bool is_compressed,
283  bool needs_swapping);
284 template <typename T>
285 void read_array(std::istream& stream, Read<T>& array, bool is_compressed,
286  bool needs_swapping);
287 
288 void write(std::ostream& stream, std::string const& val, bool needs_swapping);
289 void read(std::istream& stream, std::string& val, bool needs_swapping);
290 
291 void write(std::ostream& stream, Mesh* mesh);
292 void read(std::istream& stream, Mesh* mesh, I32 version);
293 
294 #define INST_DECL(T) \
295  extern template void swap_bytes(T&); \
296  extern template Read<T> swap_bytes(Read<T> array, bool needs_swapping); \
297  extern template void write_value(std::ostream& stream, T val, bool); \
298  extern template void read_value(std::istream& stream, T& val, bool); \
299  extern template void write_array( \
300  std::ostream& stream, Read<T> array, bool, bool); \
301  extern template void read_array( \
302  std::istream& stream, Read<T>& array, bool, bool);
303 INST_DECL(I8)
304 INST_DECL(I32)
305 INST_DECL(I64)
306 INST_DECL(Real)
307 #undef INST_DECL
308 
309 // for VTK compression headers
310 extern template void swap_bytes(std::uint64_t&);
311 
312 } // namespace binary
313 
314 void write_reals_txt(filesystem::path const& filename, Reals a, Int ncomps);
315 void write_reals_txt(std::ostream& stream, Reals a, Int ncomps);
316 Reals read_reals_txt(filesystem::path const& filename, LO n, Int ncomps);
317 Reals read_reals_txt(std::istream& stream, LO n, Int ncomps);
318 
319 } // namespace Omega_h
320 
321 #endif
void write_parallel(filesystem::path const &filename, Mesh &mesh)
Definition: Omega_h_gmsh.cpp:783
Mesh read_parallel(filesystem::path filename, CommPtr comm)
Definition: Omega_h_gmsh.cpp:543
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:245
Definition: Omega_h_file.hpp:225
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:249
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