Note: this is documentation for an old release. View the latest documentation at docs.fenicsproject.org/v0.1.0/v0.9.0/cpp
DOLFINx  0.1.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
22 {
23 namespace fem
24 {
25 class CoordinateElement;
26 }
27 
28 namespace fem
29 {
30 template <typename T>
31 class Function;
32 } // namespace fem
33 
34 namespace mesh
35 {
36 class Geometry;
37 enum class GhostMode : int;
38 class Mesh;
39 template <typename T>
40 class MeshTags;
41 } // namespace mesh
42 
43 namespace io
44 {
45 
48 
56 
57 class XDMFFile
58 {
59 public:
61  enum class Encoding
62  {
63  HDF5,
64  ASCII
65  };
66 
68  static const Encoding default_encoding = Encoding::HDF5;
69 
71  XDMFFile(MPI_Comm comm, const std::string filename,
72  const std::string file_mode,
73  const Encoding encoding = default_encoding);
74 
76  ~XDMFFile();
77 
83  void close();
84 
88  void write_mesh(const mesh::Mesh& mesh,
89  const std::string xpath = "/Xdmf/Domain");
90 
95  void write_geometry(const mesh::Geometry& geometry, const std::string name,
96  const std::string xpath = "/Xdmf/Domain");
97 
106  mesh::Mesh read_mesh(const fem::CoordinateElement& element,
107  const mesh::GhostMode& mode, const std::string name,
108  const std::string xpath = "/Xdmf/Domain") const;
109 
114  xt::xtensor<std::int64_t, 2> read_topology_data(const std::string name,
115  const std::string xpath
116  = "/Xdmf/Domain") const;
117 
122  xt::xtensor<double, 2> read_geometry_data(const std::string name,
123  const std::string xpath
124  = "/Xdmf/Domain") const;
125 
129  std::pair<mesh::CellType, int> read_cell_type(const std::string grid_name,
130  const std::string xpath
131  = "/Xdmf/Domain");
132 
138  void write_function(const fem::Function<double>& u, double t,
139  const std::string& mesh_xpath
140  = "/Xdmf/Domain/Grid[@GridType='Uniform'][1]");
141 
147  void write_function(const fem::Function<std::complex<double>>& u, double t,
148  const std::string& mesh_xpath
149  = "/Xdmf/Domain/Grid[@GridType='Uniform'][1]");
150 
156  void write_meshtags(const mesh::MeshTags<std::int32_t>& meshtags,
157  const std::string& geometry_xpath,
158  const std::string& xpath = "/Xdmf/Domain");
159 
165  read_meshtags(const std::shared_ptr<const mesh::Mesh>& mesh,
166  const std::string name,
167  const std::string xpath = "/Xdmf/Domain");
168 
173  void write_information(const std::string name, const std::string value,
174  const std::string xpath = "/Xdmf/Domain/");
175 
179  std::string read_information(const std::string name,
180  const std::string xpath = "/Xdmf/Domain/");
181 
184  MPI_Comm comm() const;
185 
186 private:
187  // MPI communicator
188  dolfinx::MPI::Comm _mpi_comm;
189 
190  // Cached filename
191  std::string _filename;
192 
193  // File mode
194  std::string _file_mode;
195 
196  // HDF5 file handle
197  hid_t _h5_id;
198 
199  // The XML document currently representing the XDMF which needs to be
200  // kept open for time series etc.
201  std::unique_ptr<pugi::xml_document> _xml_doc;
202 
203  Encoding _encoding;
204 };
205 
206 } // namespace io
207 } // namespace dolfinx
dolfinx::fem::Function
This class represents a function in a finite element function space , given by.
Definition: Form.h:23
dolfinx::io::XDMFFile::Encoding
Encoding
File encoding type.
Definition: XDMFFile.h:61
dolfinx::mesh::GhostMode
GhostMode
Enum for different partitioning ghost modes.
Definition: Mesh.h:46
dolfinx::mesh::MeshTags
A MeshTags are used to associate mesh entities with values. The entity index (local to process) ident...
Definition: XDMFFile.h:40
dolfinx::mesh::Mesh
A Mesh consists of a set of connected and numbered mesh topological entities, and geometry data.
Definition: Mesh.h:55
dolfinx::MPI::Comm
A duplicate MPI communicator and manage lifetime of the communicator.
Definition: MPI.h:35
dolfinx::mesh::Geometry
Geometry stores the geometry imposed on a mesh.
Definition: Geometry.h:36
dolfinx::io::XDMFFile
Read and write mesh::Mesh, fem::Function and other objects in XDMF.
Definition: XDMFFile.h:57
dolfinx::fem::CoordinateElement
This class manages coordinate mappings for isoparametric cells.
Definition: CoordinateElement.h:30