DOLFINx 0.10.0.0
DOLFINx C++ interface
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 <utility>
18#include <variant>
19
20namespace pugi
21{
22class xml_node;
23class xml_document;
24} // namespace pugi
25
26namespace dolfinx::fem
27{
28template <std::floating_point T>
30template <dolfinx::scalar T, std::floating_point U>
31class Function;
32} // namespace dolfinx::fem
33
34namespace dolfinx::mesh
35{
36template <std::floating_point T>
37class Geometry;
38enum class GhostMode : std::uint8_t;
39template <std::floating_point T>
40class Mesh;
41template <typename T>
42class MeshTags;
43} // namespace dolfinx::mesh
44
45namespace dolfinx::io
46{
47
59{
60public:
62 enum class Encoding : std::int8_t
63 {
64 HDF5,
65 ASCII
66 };
67
69 XDMFFile(MPI_Comm comm, const std::filesystem::path& filename,
70 const std::string& file_mode, Encoding encoding = Encoding::HDF5);
71
73 XDMFFile(XDMFFile&&) = default;
74
76 ~XDMFFile();
77
83 void close();
84
88 template <std::floating_point U>
89 void write_mesh(const mesh::Mesh<U>& mesh,
90 const std::string& xpath = "/Xdmf/Domain");
91
97 const std::string& name,
98 const std::string& xpath = "/Xdmf/Domain");
99
109 mesh::GhostMode mode, const std::string& name,
110 const std::string& xpath = "/Xdmf/Domain") const;
111
116 std::pair<std::vector<std::int64_t>, std::array<std::size_t, 2>>
117 read_topology_data(const std::string& name,
118 const std::string& xpath = "/Xdmf/Domain") const;
119
124 std::pair<std::variant<std::vector<float>, std::vector<double>>,
125 std::array<std::size_t, 2>>
126 read_geometry_data(const std::string& name,
127 const std::string& xpath = "/Xdmf/Domain") const;
128
132 std::pair<mesh::CellType, int> read_cell_type(const std::string& grid_name,
133 const std::string& xpath
134 = "/Xdmf/Domain");
135
152 template <dolfinx::scalar T, std::floating_point U = scalar_value_t<T>>
153 void write_function(const fem::Function<T, U>& u, double t,
154 std::string mesh_xpath
155 = "/Xdmf/Domain/Grid[@GridType='Uniform'][1]");
156
163 template <std::floating_point T>
164 void write_meshtags(const mesh::MeshTags<std::int32_t>& meshtags,
165 const mesh::Geometry<T>& x,
166 const std::string& geometry_xpath,
167 const std::string& xpath = "/Xdmf/Domain");
168
177 read_meshtags(const mesh::Mesh<double>& mesh, const std::string& name,
178 std::optional<std::string> attribute_name,
179 const std::string& xpath = "/Xdmf/Domain");
180
185 void write_information(const std::string& name, const std::string& value,
186 const std::string& xpath = "/Xdmf/Domain/");
187
191 std::string read_information(const std::string& name,
192 const std::string& xpath = "/Xdmf/Domain/");
193
196 MPI_Comm comm() const;
197
198private:
199 // MPI communicator
200 dolfinx::MPI::Comm _comm;
201
202 // Filename
203 std::filesystem::path _filename;
204
205 // File mode
206 std::string _file_mode;
207
208 // HDF5 file handle
209 hid_t _h5_id;
210
211 // The XML document currently representing the XDMF which needs to be
212 // kept open for time series etc.
213 std::unique_ptr<pugi::xml_document> _xml_doc;
214
215 Encoding _encoding;
216};
217
218} // namespace dolfinx::io
A duplicate MPI communicator and manage lifetime of the communicator.
Definition MPI.h:42
Definition CoordinateElement.h:38
Definition Function.h:47
XDMFFile(MPI_Comm comm, const std::filesystem::path &filename, const std::string &file_mode, Encoding encoding=Encoding::HDF5)
Constructor.
Definition XDMFFile.cpp:28
~XDMFFile()
Destructor.
Definition XDMFFile.cpp:133
void write_function(const fem::Function< T, U > &u, double t, std::string mesh_xpath="/Xdmf/Domain/Grid[@GridType='Uniform'][1]")
Write a fem::Function to file.
Definition XDMFFile.cpp:238
mesh::Mesh< double > read_mesh(const fem::CoordinateElement< double > &element, mesh::GhostMode mode, const std::string &name, const std::string &xpath="/Xdmf/Domain") const
Definition XDMFFile.cpp:186
void close()
Definition XDMFFile.cpp:135
std::string read_information(const std::string &name, const std::string &xpath="/Xdmf/Domain/")
Definition XDMFFile.cpp:453
std::pair< std::variant< std::vector< float >, std::vector< double > >, std::array< std::size_t, 2 > > read_geometry_data(const std::string &name, const std::string &xpath="/Xdmf/Domain") const
Definition XDMFFile.cpp:221
std::pair< std::vector< std::int64_t >, std::array< std::size_t, 2 > > read_topology_data(const std::string &name, const std::string &xpath="/Xdmf/Domain") const
Definition XDMFFile.cpp:203
XDMFFile(XDMFFile &&)=default
Move constructor.
void write_information(const std::string &name, const std::string &value, const std::string &xpath="/Xdmf/Domain/")
Definition XDMFFile.cpp:435
Encoding
File encoding type.
Definition XDMFFile.h:63
std::pair< mesh::CellType, int > read_cell_type(const std::string &grid_name, const std::string &xpath="/Xdmf/Domain")
Definition XDMFFile.cpp:411
MPI_Comm comm() const
Definition XDMFFile.cpp:470
void write_meshtags(const mesh::MeshTags< std::int32_t > &meshtags, const mesh::Geometry< T > &x, const std::string &geometry_xpath, const std::string &xpath="/Xdmf/Domain")
Definition XDMFFile.cpp:306
mesh::MeshTags< std::int32_t > read_meshtags(const mesh::Mesh< double > &mesh, const std::string &name, std::optional< std::string > attribute_name, const std::string &xpath="/Xdmf/Domain")
Definition XDMFFile.cpp:343
void write_mesh(const mesh::Mesh< U > &mesh, const std::string &xpath="/Xdmf/Domain")
Definition XDMFFile.cpp:143
void write_geometry(const mesh::Geometry< double > &geometry, const std::string &name, const std::string &xpath="/Xdmf/Domain")
Definition XDMFFile.cpp:163
Geometry stores the geometry imposed on a mesh.
Definition Geometry.h:34
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:22
Support for file IO.
Definition cells.h:119
Mesh data structures and algorithms on meshes.
Definition DofMap.h:32
GhostMode
Enum for different partitioning ghost modes.
Definition utils.h:40