DOLFINx 0.9.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 <string>
16#include <variant>
17
18namespace pugi
19{
20class xml_node;
21class xml_document;
22} // namespace pugi
23
24namespace dolfinx::fem
25{
26template <std::floating_point T>
28template <dolfinx::scalar T, std::floating_point U>
30} // namespace dolfinx::fem
31
32namespace dolfinx::mesh
33{
34template <std::floating_point T>
35class Geometry;
36enum class GhostMode : int;
37template <std::floating_point T>
38class Mesh;
39template <typename T>
40class MeshTags;
41} // namespace dolfinx::mesh
42
43namespace dolfinx::io
44{
45
57{
58public:
60 enum class Encoding
61 {
62 HDF5,
63 ASCII
64 };
65
67 static const Encoding default_encoding = Encoding::HDF5;
68
70 XDMFFile(MPI_Comm comm, const std::filesystem::path& filename,
71 std::string file_mode, Encoding encoding = default_encoding);
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 xpath = "/Xdmf/Domain");
92
97 void write_geometry(const mesh::Geometry<double>& geometry, std::string name,
98 std::string xpath = "/Xdmf/Domain");
99
109 mesh::GhostMode mode, std::string name,
110 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(std::string name,
118 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(std::string name,
127 std::string xpath = "/Xdmf/Domain") const;
128
132 std::pair<mesh::CellType, int>
133 read_cell_type(std::string grid_name, std::string xpath = "/Xdmf/Domain");
134
151 template <dolfinx::scalar T, std::floating_point U = scalar_value_type_t<T>>
152 void write_function(const fem::Function<T, U>& u, double t,
153 std::string mesh_xpath
154 = "/Xdmf/Domain/Grid[@GridType='Uniform'][1]");
155
162 template <std::floating_point T>
163 void write_meshtags(const mesh::MeshTags<std::int32_t>& meshtags,
164 const mesh::Geometry<T>& x, std::string geometry_xpath,
165 std::string xpath = "/Xdmf/Domain");
166
172 read_meshtags(const mesh::Mesh<double>& mesh, std::string name,
173 std::string xpath = "/Xdmf/Domain");
174
179 void write_information(std::string name, std::string value,
180 std::string xpath = "/Xdmf/Domain/");
181
185 std::string read_information(std::string name,
186 std::string xpath = "/Xdmf/Domain/");
187
190 MPI_Comm comm() const;
191
192private:
193 // MPI communicator
194 dolfinx::MPI::Comm _comm;
195
196 // Filename
197 std::filesystem::path _filename;
198
199 // File mode
200 std::string _file_mode;
201
202 // HDF5 file handle
203 hid_t _h5_id;
204
205 // The XML document currently representing the XDMF which needs to be
206 // kept open for time series etc.
207 std::unique_ptr<pugi::xml_document> _xml_doc;
208
209 Encoding _encoding;
210};
211
212} // namespace dolfinx::io
A duplicate MPI communicator and manage lifetime of the communicator.
Definition MPI.h:43
Definition XDMFFile.h:27
Definition XDMFFile.h:29
Definition XDMFFile.h:57
XDMFFile(MPI_Comm comm, const std::filesystem::path &filename, std::string file_mode, Encoding encoding=default_encoding)
Constructor.
Definition XDMFFile.cpp:27
mesh::Mesh< double > read_mesh(const fem::CoordinateElement< double > &element, mesh::GhostMode mode, std::string name, std::string xpath="/Xdmf/Domain") const
Definition XDMFFile.cpp:183
void write_meshtags(const mesh::MeshTags< std::int32_t > &meshtags, const mesh::Geometry< T > &x, std::string geometry_xpath, std::string xpath="/Xdmf/Domain")
Definition XDMFFile.cpp:301
void write_information(std::string name, std::string value, std::string xpath="/Xdmf/Domain/")
Definition XDMFFile.cpp:416
~XDMFFile()
Destructor.
Definition XDMFFile.cpp:132
static const Encoding default_encoding
Default encoding type.
Definition XDMFFile.h:67
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:233
void close()
Definition XDMFFile.cpp:134
mesh::MeshTags< std::int32_t > read_meshtags(const mesh::Mesh< double > &mesh, std::string name, std::string xpath="/Xdmf/Domain")
Definition XDMFFile.cpp:337
XDMFFile(XDMFFile &&)=default
Move constructor.
std::pair< std::vector< std::int64_t >, std::array< std::size_t, 2 > > read_topology_data(std::string name, std::string xpath="/Xdmf/Domain") const
Definition XDMFFile.cpp:200
std::pair< mesh::CellType, int > read_cell_type(std::string grid_name, std::string xpath="/Xdmf/Domain")
Definition XDMFFile.cpp:391
std::pair< std::variant< std::vector< float >, std::vector< double > >, std::array< std::size_t, 2 > > read_geometry_data(std::string name, std::string xpath="/Xdmf/Domain") const
Definition XDMFFile.cpp:217
void write_geometry(const mesh::Geometry< double > &geometry, std::string name, std::string xpath="/Xdmf/Domain")
Definition XDMFFile.cpp:160
std::string read_information(std::string name, std::string xpath="/Xdmf/Domain/")
Definition XDMFFile.cpp:433
MPI_Comm comm() const
Definition XDMFFile.cpp:449
Encoding
File encoding type.
Definition XDMFFile.h:61
void write_mesh(const mesh::Mesh< U > &mesh, std::string xpath="/Xdmf/Domain")
Definition XDMFFile.cpp:142
Geometry stores the geometry imposed on a mesh.
Definition Geometry.h:34
MeshTags associate values with mesh topology entities.
Definition utils.h:26
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_matrix_impl.h:26
Support for file IO.
Definition ADIOS2Writers.h:42
Mesh data structures and algorithms on meshes.
Definition DofMap.h:32
GhostMode
Enum for different partitioning ghost modes.
Definition utils.h:36