DOLFIN-X
DOLFIN-X 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 <memory>
13 #include <petscsys.h>
14 #include <string>
15 
16 namespace pugi
17 {
18 class xml_node;
19 class xml_document;
20 } // namespace pugi
21 
22 namespace dolfinx
23 {
24 namespace fem
25 {
26 class CoordinateElement;
27 }
28 
29 namespace function
30 {
31 template <typename T>
32 class Function;
33 } // namespace function
34 
35 namespace mesh
36 {
37 class Geometry;
38 enum class GhostMode : int;
39 class Mesh;
40 template <typename T>
41 class MeshTags;
42 } // namespace mesh
43 
44 namespace io
45 {
46 
49 
57 
58 class XDMFFile
59 {
60 public:
62  enum class Encoding
63  {
64  HDF5,
65  ASCII
66  };
67 
69  static const Encoding default_encoding = Encoding::HDF5;
70 
72  XDMFFile(MPI_Comm comm, const std::string filename,
73  const std::string file_mode,
74  const Encoding encoding = default_encoding);
75 
77  ~XDMFFile();
78 
84  void close();
85 
89  void write_mesh(const mesh::Mesh& mesh,
90  const std::string xpath = "/Xdmf/Domain");
91 
96  void write_geometry(const mesh::Geometry& geometry, const std::string name,
97  const std::string xpath = "/Xdmf/Domain");
98 
107  mesh::Mesh read_mesh(const fem::CoordinateElement& element,
108  const mesh::GhostMode& mode, const std::string name,
109  const std::string xpath = "/Xdmf/Domain") const;
110 
115  Eigen::Array<std::int64_t, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor>
116  read_topology_data(const std::string name,
117  const std::string xpath = "/Xdmf/Domain") const;
118 
123  Eigen::Array<double, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor>
124  read_geometry_data(const std::string name,
125  const std::string xpath = "/Xdmf/Domain") const;
126 
130  std::pair<mesh::CellType, int> read_cell_type(const std::string grid_name,
131  const std::string xpath
132  = "/Xdmf/Domain");
133 
139  void write_function(const function::Function<PetscScalar>& function,
140  const double t,
141  const std::string mesh_xpath
142  = "/Xdmf/Domain/Grid[@GridType='Uniform'][1]");
143 
149  void write_meshtags(const mesh::MeshTags<std::int32_t>& meshtags,
150  const std::string geometry_xpath,
151  const std::string xpath = "/Xdmf/Domain");
152 
158  read_meshtags(const std::shared_ptr<const mesh::Mesh>& mesh,
159  const std::string name,
160  const std::string xpath = "/Xdmf/Domain");
161 
166  void write_information(const std::string name, const std::string value,
167  const std::string xpath = "/Xdmf/Domain/");
168 
172  std::string read_information(const std::string name,
173  const std::string xpath = "/Xdmf/Domain/");
174 
177  MPI_Comm comm() const;
178 
179 private:
180  // MPI communicator
181  dolfinx::MPI::Comm _mpi_comm;
182 
183  // Cached filename
184  std::string _filename;
185 
186  // File mode
187  std::string _file_mode;
188 
189  // HDF5 file handle
190  hid_t _h5_id;
191 
192  // The XML document currently representing the XDMF which needs to be
193  // kept open for time series etc.
194  std::unique_ptr<pugi::xml_document> _xml_doc;
195 
196  Encoding _encoding;
197 };
198 
199 } // namespace io
200 } // namespace dolfinx
A duplicate MPI communicator and manage lifetime of the communicator.
Definition: MPI.h:36
This class manages coordinate mappings for isoparametric cells.
Definition: CoordinateElement.h:24
This class represents a function in a finite element function space , given by.
Definition: Function.h:42
Read and write mesh::Mesh, function::Function and other objects in XDMF.
Definition: XDMFFile.h:59
Encoding
File encoding type.
Definition: XDMFFile.h:63
Geometry stores the geometry imposed on a mesh.
Definition: Geometry.h:39
A MeshTags are used to associate mesh entities with values. The entity index (local to process) ident...
Definition: MeshTags.h:37
A Mesh consists of a set of connected and numbered mesh topological entities, and geometry data.
Definition: Mesh.h:47
GhostMode
Enum for different partitioning ghost modes.
Definition: Mesh.h:37