Note: this is documentation for an old release. View the latest documentation at docs.fenicsproject.org/v0.3.0/v0.9.0/cpp
DOLFINx  0.3.0
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 <memory>
13 #include <string>
14 
15 namespace pugi
16 {
17 class xml_node;
18 class xml_document;
19 } // namespace pugi
20 
21 namespace dolfinx::fem
22 {
23 class CoordinateElement;
24 }
25 
26 namespace dolfinx::fem
27 {
28 template <typename T>
29 class Function;
30 }
31 
32 namespace dolfinx::mesh
33 {
34 class Geometry;
35 enum class GhostMode : int;
36 class Mesh;
37 template <typename T>
38 class MeshTags;
39 } // namespace dolfinx::mesh
40 
41 namespace dolfinx::io
42 {
43 
46 
54 
55 class XDMFFile
56 {
57 public:
59  enum class Encoding
60  {
61  HDF5,
62  ASCII
63  };
64 
66  static const Encoding default_encoding = Encoding::HDF5;
67 
69  XDMFFile(MPI_Comm comm, const std::string filename,
70  const std::string file_mode,
71  const Encoding encoding = default_encoding);
72 
74  ~XDMFFile();
75 
81  void close();
82 
86  void write_mesh(const mesh::Mesh& mesh,
87  const std::string xpath = "/Xdmf/Domain");
88 
93  void write_geometry(const mesh::Geometry& geometry, const std::string name,
94  const std::string xpath = "/Xdmf/Domain");
95 
104  mesh::Mesh read_mesh(const fem::CoordinateElement& element,
105  const mesh::GhostMode& mode, const std::string name,
106  const std::string xpath = "/Xdmf/Domain") const;
107 
112  xt::xtensor<std::int64_t, 2> read_topology_data(const std::string name,
113  const std::string xpath
114  = "/Xdmf/Domain") const;
115 
120  xt::xtensor<double, 2> read_geometry_data(const std::string name,
121  const std::string xpath
122  = "/Xdmf/Domain") const;
123 
127  std::pair<mesh::CellType, int> read_cell_type(const std::string grid_name,
128  const std::string xpath
129  = "/Xdmf/Domain");
130 
136  void write_function(const fem::Function<double>& u, double t,
137  const std::string& mesh_xpath
138  = "/Xdmf/Domain/Grid[@GridType='Uniform'][1]");
139 
145  void write_function(const fem::Function<std::complex<double>>& u, double t,
146  const std::string& mesh_xpath
147  = "/Xdmf/Domain/Grid[@GridType='Uniform'][1]");
148 
154  void write_meshtags(const mesh::MeshTags<std::int32_t>& meshtags,
155  const std::string& geometry_xpath,
156  const std::string& xpath = "/Xdmf/Domain");
157 
163  read_meshtags(const std::shared_ptr<const mesh::Mesh>& mesh,
164  const std::string name,
165  const std::string xpath = "/Xdmf/Domain");
166 
171  void write_information(const std::string name, const std::string value,
172  const std::string xpath = "/Xdmf/Domain/");
173 
177  std::string read_information(const std::string name,
178  const std::string xpath = "/Xdmf/Domain/");
179 
182  MPI_Comm comm() const;
183 
184 private:
185  // MPI communicator
186  dolfinx::MPI::Comm _mpi_comm;
187 
188  // Cached filename
189  std::string _filename;
190 
191  // File mode
192  std::string _file_mode;
193 
194  // HDF5 file handle
195  hid_t _h5_id;
196 
197  // The XML document currently representing the XDMF which needs to be
198  // kept open for time series etc.
199  std::unique_ptr<pugi::xml_document> _xml_doc;
200 
201  Encoding _encoding;
202 };
203 
204 } // namespace dolfinx::io
A duplicate MPI communicator and manage lifetime of the communicator.
Definition: MPI.h:32
This class manages coordinate mappings for isoparametric cells.
Definition: CoordinateElement.h:29
This class represents a function in a finite element function space , given by.
Definition: Function.h:47
Read and write mesh::Mesh, fem::Function and other objects in XDMF.
Definition: XDMFFile.h:56
Encoding
File encoding type.
Definition: XDMFFile.h:60
Geometry stores the geometry imposed on a mesh.
Definition: Geometry.h:37
A MeshTags are used to associate mesh entities with values. The entity index (local to process) ident...
Definition: MeshTags.h:36
A Mesh consists of a set of connected and numbered mesh topological entities, and geometry data.
Definition: Mesh.h:53
Finite element method functionality.
Definition: assemble_matrix_impl.h:23
Support for file IO.
Definition: cells.h:22
Mesh data structures and algorithms on meshes.
Definition: DirichletBC.h:20
GhostMode
Enum for different partitioning ghost modes.
Definition: Mesh.h:44