Note: this is documentation for an old release. View the latest documentation at docs.fenicsproject.org/dolfinx/v0.9.0/cpp/doxygen/d5/d2a/XDMFFile_8h_source.html
DOLFINx  0.5.1
DOLFINx C++ interface
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 <dolfinx/common/MPI.h>
11 #include <dolfinx/mesh/cell_types.h>
12 #include <filesystem>
13 #include <memory>
14 #include <string>
15 
16 namespace pugi
17 {
18 class xml_node;
19 class xml_document;
20 } // namespace pugi
21 
22 namespace dolfinx::fem
23 {
24 class CoordinateElement;
25 }
26 
27 namespace dolfinx::fem
28 {
29 template <typename T>
30 class Function;
31 }
32 
33 namespace dolfinx::mesh
34 {
35 class Geometry;
36 enum class GhostMode : int;
37 class Mesh;
38 template <typename T>
39 class MeshTags;
40 } // namespace dolfinx::mesh
41 
42 namespace dolfinx::io
43 {
44 
47 
55 
56 class XDMFFile
57 {
58 public:
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  const std::string file_mode,
72  const Encoding encoding = default_encoding);
73 
75  ~XDMFFile();
76 
82  void close();
83 
87  void write_mesh(const mesh::Mesh& mesh,
88  const std::string xpath = "/Xdmf/Domain");
89 
94  void write_geometry(const mesh::Geometry& geometry, const std::string name,
95  const std::string xpath = "/Xdmf/Domain");
96 
105  mesh::Mesh read_mesh(const fem::CoordinateElement& element,
106  const mesh::GhostMode& mode, const std::string name,
107  const std::string xpath = "/Xdmf/Domain") const;
108 
113  std::pair<std::vector<std::int64_t>, std::array<std::size_t, 2>>
114  read_topology_data(const std::string name,
115  const std::string xpath = "/Xdmf/Domain") const;
116 
121  std::pair<std::vector<double>, std::array<std::size_t, 2>>
122  read_geometry_data(const std::string name,
123  const std::string xpath = "/Xdmf/Domain") const;
124 
128  std::pair<mesh::CellType, int> read_cell_type(const std::string grid_name,
129  const std::string xpath
130  = "/Xdmf/Domain");
131 
137  void write_function(const fem::Function<double>& u, double t,
138  const std::string& mesh_xpath
139  = "/Xdmf/Domain/Grid[@GridType='Uniform'][1]");
140 
146  void write_function(const fem::Function<std::complex<double>>& u, double t,
147  const std::string& mesh_xpath
148  = "/Xdmf/Domain/Grid[@GridType='Uniform'][1]");
149 
155  void write_meshtags(const mesh::MeshTags<std::int32_t>& meshtags,
156  const std::string& geometry_xpath,
157  const std::string& xpath = "/Xdmf/Domain");
158 
164  read_meshtags(const std::shared_ptr<const mesh::Mesh>& mesh,
165  const std::string name,
166  const std::string xpath = "/Xdmf/Domain");
167 
172  void write_information(const std::string name, const std::string value,
173  const std::string xpath = "/Xdmf/Domain/");
174 
178  std::string read_information(const std::string name,
179  const std::string xpath = "/Xdmf/Domain/");
180 
183  MPI_Comm comm() const;
184 
185 private:
186  // MPI communicator
187  dolfinx::MPI::Comm _comm;
188 
189  // Filename
190  std::filesystem::path _filename;
191 
192  // File mode
193  std::string _file_mode;
194 
195  // HDF5 file handle
196  hid_t _h5_id;
197 
198  // The XML document currently representing the XDMF which needs to be
199  // kept open for time series etc.
200  std::unique_ptr<pugi::xml_document> _xml_doc;
201 
202  Encoding _encoding;
203 };
204 
205 } // namespace dolfinx::io
A duplicate MPI communicator and manage lifetime of the communicator.
Definition: MPI.h:41
A CoordinateElement manages coordinate mappings for isoparametric cells.
Definition: CoordinateElement.h:32
This class represents a function in a finite element function space , given by.
Definition: Function.h:45
Read and write mesh::Mesh, fem::Function and other objects in XDMF.
Definition: XDMFFile.h:57
Encoding
File encoding type.
Definition: XDMFFile.h:61
Geometry stores the geometry imposed on a mesh.
Definition: Geometry.h:28
MeshTags associate values with mesh entities.
Definition: MeshTags.h:36
A Mesh consists of a set of connected and numbered mesh topological entities, and geometry data.
Definition: Mesh.h:33
Finite element method functionality.
Definition: assemble_matrix_impl.h:25
Support for file IO.
Definition: ADIOS2Writers.h:39
Mesh data structures and algorithms on meshes.
Definition: DofMap.h:30
GhostMode
Enum for different partitioning ghost modes.
Definition: utils.h:29