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
74 XDMFFile(XDMFFile&&) = default;
75
77 ~XDMFFile();
78
84 void close();
85
89 template <std::floating_point U>
90 void write_mesh(const mesh::Mesh<U>& mesh,
91 std::string_view xpath = "/Xdmf/Domain");
92
98 std::string_view name,
99 std::string_view xpath = "/Xdmf/Domain");
100
113 std::string_view name, std::string_view xpath = "/Xdmf/Domain",
114 std::optional<std::int32_t> max_facet_to_cell_links = 2) const;
115
120 std::pair<std::vector<std::int64_t>, std::array<std::size_t, 2>>
121 read_topology_data(std::string_view name,
122 std::string_view xpath = "/Xdmf/Domain") const;
123
128 std::pair<std::variant<std::vector<float>, std::vector<double>>,
129 std::array<std::size_t, 2>>
130 read_geometry_data(std::string_view name,
131 std::string_view xpath = "/Xdmf/Domain") const;
132
136 std::pair<mesh::CellType, int> read_cell_type(std::string_view grid_name,
137 std::string_view xpath
138 = "/Xdmf/Domain") const;
139
156 template <dolfinx::scalar T, std::floating_point U = scalar_value_t<T>>
157 void write_function(const fem::Function<T, U>& u, double t,
158 std::string_view mesh_xpath
159 = "/Xdmf/Domain/Grid[@GridType='Uniform'][1]");
160
167 template <std::floating_point T>
168 void write_meshtags(const mesh::MeshTags<std::int32_t>& meshtags,
169 const mesh::Geometry<T>& x,
170 std::string_view geometry_xpath,
171 std::string_view xpath = "/Xdmf/Domain");
172
181 read_meshtags(const mesh::Mesh<double>& mesh, std::string_view name,
182 std::optional<std::string_view> attribute_name,
183 std::string_view xpath = "/Xdmf/Domain") const;
184
189 void write_information(std::string_view name, std::string_view value,
190 std::string_view xpath = "/Xdmf/Domain/");
191
195 std::string read_information(std::string_view name,
196 std::string_view xpath = "/Xdmf/Domain/") const;
197
200 void flush();
201
204 MPI_Comm comm() const;
205
206private:
207 // MPI communicator
208 dolfinx::MPI::Comm _comm;
209
210 // Filename
211 std::filesystem::path _filename;
212
213 // File mode
214 std::string _file_mode;
215
216 // HDF5 file handle
217 hid_t _h5_id;
218
219 // The XML document currently representing the XDMF which needs to be
220 // kept open for time series etc.
221 std::unique_ptr<pugi::xml_document> _xml_doc;
222
223 Encoding _encoding;
224};
225
226} // namespace dolfinx::io
A duplicate MPI communicator and manage lifetime of the communicator.
Definition MPI.h:43
Definition CoordinateElement.h:38
Definition Function.h:47
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:245
XDMFFile(MPI_Comm comm, const std::filesystem::path &filename, std::string_view file_mode, Encoding encoding=Encoding::HDF5)
Constructor.
Definition XDMFFile.cpp:30
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:226
~XDMFFile()
Destructor.
Definition XDMFFile.cpp:135
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:206
std::pair< mesh::CellType, int > read_cell_type(std::string_view grid_name, std::string_view xpath="/Xdmf/Domain") const
Definition XDMFFile.cpp:423
void close()
Definition XDMFFile.cpp:137
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) const
Definition XDMFFile.cpp:188
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:314
XDMFFile(XDMFFile &&)=default
Move constructor.
void write_information(std::string_view name, std::string_view value, std::string_view xpath="/Xdmf/Domain/")
Definition XDMFFile.cpp:451
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:164
std::string read_information(std::string_view name, std::string_view xpath="/Xdmf/Domain/") const
Definition XDMFFile.cpp:469
void write_mesh(const mesh::Mesh< U > &mesh, std::string_view xpath="/Xdmf/Domain")
Definition XDMFFile.cpp:145
MPI_Comm comm() const
Definition XDMFFile.cpp:494
void flush()
Definition XDMFFile.cpp:488
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:352
Geometry stores the geometry imposed on a mesh.
Definition Geometry.h:37
MeshTags associate values with mesh topology entities.
Definition MeshTags.h:33
A Mesh consists of a set of connected and numbered mesh topological entities, and geometry data.
Definition Mesh.h:23
Finite element method functionality.
Definition assemble_expression_impl.h:23
Geometry data structures and algorithms.
Definition BoundingBoxTree.h:24
Support for file IO.
Definition ADIOS2Writers.h:43
Mesh data structures and algorithms on meshes.
Definition DofMap.h:32
GhostMode
Enum for different partitioning ghost modes.
Definition utils.h:44