DOLFINx 0.12.0.0
DOLFINx C++
Loading...
Searching...
No Matches
XDMFFile.h
1// Copyright (C) 2012-2020 Chris N. Richardson, Garth N. Wells and Michal Habera
2//
3// This file is part of DOLFINx (https://www.fenicsproject.org)
4//
5// SPDX-License-Identifier: LGPL-3.0-or-later
6
7#pragma once
8
9#include "HDF5Interface.h"
10#include <concepts>
11#include <dolfinx/common/MPI.h>
12#include <dolfinx/mesh/cell_types.h>
13#include <filesystem>
14#include <memory>
15#include <optional>
16#include <string>
17#include <string_view>
18#include <utility>
19#include <variant>
20
21namespace pugi
22{
23class xml_node;
24class xml_document;
25} // namespace pugi
26
27namespace dolfinx::fem
28{
29template <std::floating_point T>
31template <dolfinx::scalar T, std::floating_point U>
32class Function;
33} // namespace dolfinx::fem
34
35namespace dolfinx::mesh
36{
37template <std::floating_point T>
38class Geometry;
39enum class GhostMode : std::uint8_t;
40template <std::floating_point T>
41class Mesh;
42template <typename T>
43class MeshTags;
44} // namespace dolfinx::mesh
45
46namespace dolfinx::io
47{
48
60{
61public:
63 enum class Encoding : std::int8_t
64 {
65 HDF5,
66 ASCII
67 };
68
70 XDMFFile(MPI_Comm comm, const std::filesystem::path& filename,
71 std::string_view file_mode, Encoding encoding = Encoding::HDF5);
72
73 // Copy constructor (deleted)
74 XDMFFile(const XDMFFile& file) = delete;
75
79 XDMFFile(XDMFFile&& file) noexcept;
80
88
89 // Copy assignment (deleted)
90 XDMFFile& operator=(const XDMFFile& file) = delete;
91
95 XDMFFile& operator=(XDMFFile&& file) noexcept;
96
103 void close();
104
108 template <std::floating_point U>
109 void write_mesh(const mesh::Mesh<U>& mesh,
110 std::string_view xpath = "/Xdmf/Domain");
111
117 std::string_view name,
118 std::string_view xpath = "/Xdmf/Domain");
119
133 std::string_view name, std::string_view xpath = "/Xdmf/Domain",
134 std::optional<std::int32_t> max_facet_to_cell_links = 2,
135 int num_threads = 1) const;
136
141 std::pair<std::vector<std::int64_t>, std::array<std::size_t, 2>>
142 read_topology_data(std::string_view name,
143 std::string_view xpath = "/Xdmf/Domain") const;
144
149 std::pair<std::variant<std::vector<float>, std::vector<double>>,
150 std::array<std::size_t, 2>>
151 read_geometry_data(std::string_view name,
152 std::string_view xpath = "/Xdmf/Domain") const;
153
157 std::pair<mesh::CellType, int> read_cell_type(std::string_view grid_name,
158 std::string_view xpath
159 = "/Xdmf/Domain") const;
160
177 template <dolfinx::scalar T, std::floating_point U = scalar_value_t<T>>
178 void write_function(const fem::Function<T, U>& u, double t,
179 std::string_view mesh_xpath
180 = "/Xdmf/Domain/Grid[@GridType='Uniform'][1]");
181
188 template <std::floating_point T>
189 void write_meshtags(const mesh::MeshTags<std::int32_t>& meshtags,
190 const mesh::Geometry<T>& x,
191 std::string_view geometry_xpath,
192 std::string_view xpath = "/Xdmf/Domain");
193
202 read_meshtags(const mesh::Mesh<double>& mesh, std::string_view name,
203 std::optional<std::string_view> attribute_name,
204 std::string_view xpath = "/Xdmf/Domain") const;
205
210 void write_information(std::string_view name, std::string_view value,
211 std::string_view xpath = "/Xdmf/Domain/");
212
216 std::string read_information(std::string_view name,
217 std::string_view xpath = "/Xdmf/Domain/") const;
218
221 void flush();
222
225 MPI_Comm comm() const;
226
227private:
228 // MPI communicator
229 dolfinx::MPI::Comm _comm;
230
231 // Filename
232 std::filesystem::path _filename;
233
234 // File mode
235 std::string _file_mode;
236
237 // HDF5 file handle. Owning, so that the identifier is released if the
238 // constructor throws after opening the file, and on destruction.
239 hdf5::Handle _h5_id{H5I_INVALID_HID, H5Fclose};
240
241 // The XML document currently representing the XDMF which needs to be
242 // kept open for time series etc.
243 std::unique_ptr<pugi::xml_document> _xml_doc;
244
245 Encoding _encoding;
246};
247
248} // namespace dolfinx::io
A duplicate MPI communicator and manage lifetime of the communicator.
Definition MPI.h:47
Definition CoordinateElement.h:39
Definition Function.h:44
Read and write mesh::Mesh, fem::Function and other objects in XDMF.
Definition XDMFFile.h:60
void write_function(const fem::Function< T, U > &u, double t, std::string_view mesh_xpath="/Xdmf/Domain/Grid[@GridType='Uniform'][1]")
Write a fem::Function to file.
Definition XDMFFile.cpp:253
XDMFFile(MPI_Comm comm, const std::filesystem::path &filename, std::string_view file_mode, Encoding encoding=Encoding::HDF5)
Constructor.
Definition XDMFFile.cpp:31
std::pair< std::variant< std::vector< float >, std::vector< double > >, std::array< std::size_t, 2 > > read_geometry_data(std::string_view name, std::string_view xpath="/Xdmf/Domain") const
Definition XDMFFile.cpp:232
XDMFFile(XDMFFile &&file) noexcept
std::pair< std::vector< std::int64_t >, std::array< std::size_t, 2 > > read_topology_data(std::string_view name, std::string_view xpath="/Xdmf/Domain") const
Definition XDMFFile.cpp:210
std::pair< mesh::CellType, int > read_cell_type(std::string_view grid_name, std::string_view xpath="/Xdmf/Domain") const
Definition XDMFFile.cpp:432
void close()
Definition XDMFFile.cpp:138
void write_meshtags(const mesh::MeshTags< std::int32_t > &meshtags, const mesh::Geometry< T > &x, std::string_view geometry_xpath, std::string_view xpath="/Xdmf/Domain")
Definition XDMFFile.cpp:322
void write_information(std::string_view name, std::string_view value, std::string_view xpath="/Xdmf/Domain/")
Definition XDMFFile.cpp:462
XDMFFile & operator=(XDMFFile &&file) noexcept
Encoding
File encoding type.
Definition XDMFFile.h:64
void write_geometry(const mesh::Geometry< double > &geometry, std::string_view name, std::string_view xpath="/Xdmf/Domain")
Definition XDMFFile.cpp:165
std::string read_information(std::string_view name, std::string_view xpath="/Xdmf/Domain/") const
Definition XDMFFile.cpp:480
void write_mesh(const mesh::Mesh< U > &mesh, std::string_view xpath="/Xdmf/Domain")
Definition XDMFFile.cpp:146
mesh::Mesh< double > read_mesh(const fem::CoordinateElement< double > &element, mesh::GhostMode mode, std::string_view name, std::string_view xpath="/Xdmf/Domain", std::optional< std::int32_t > max_facet_to_cell_links=2, int num_threads=1) const
Definition XDMFFile.cpp:188
MPI_Comm comm() const
Definition XDMFFile.cpp:508
void flush()
Definition XDMFFile.cpp:501
mesh::MeshTags< std::int32_t > read_meshtags(const mesh::Mesh< double > &mesh, std::string_view name, std::optional< std::string_view > attribute_name, std::string_view xpath="/Xdmf/Domain") const
Definition XDMFFile.cpp:360
Scope guard for an HDF5 identifier.
Definition HDF5Interface.h:39
Geometry stores the geometry imposed on a mesh.
Definition Geometry.h:39
MeshTags associate values with mesh topology entities.
Definition MeshTags.h:37
A Mesh consists of a set of connected and numbered mesh topological entities, and geometry data.
Definition Mesh.h:25
Finite element method functionality.
Definition assemble_expression_impl.h:28
Geometry data structures and algorithms.
Definition BoundingBoxTree.h:26
Support for file IO.
Definition ADIOS2Writers.h:44
Mesh data structures and algorithms on meshes.
Definition DofMap.h:32
GhostMode
Enum for different partitioning ghost modes.
Definition types.h:19