Loading...
Searching...
No Matches
XDMFFile.h
// Copyright (C) 2012-2020 Chris N. Richardson, Garth N. Wells and Michal Habera
//
// This file is part of DOLFINx (https://www.fenicsproject.org)
//
// SPDX-License-Identifier: LGPL-3.0-or-later
#pragma once
#include "HDF5Interface.h"
#include <concepts>
#include <dolfinx/common/MPI.h>
#include <dolfinx/mesh/cell_types.h>
#include <filesystem>
#include <memory>
#include <optional>
#include <string>
#include <utility>
#include <variant>
namespace pugi
{
class xml_node;
class xml_document;
} // namespace pugi
namespace dolfinx::fem
{
template <std::floating_point T>
class CoordinateElement;
template <dolfinx::scalar T, std::floating_point U>
class Function;
} // namespace dolfinx::fem
namespace dolfinx::mesh
{
template <std::floating_point T>
class Geometry;
enum class GhostMode : std::uint8_t;
template <std::floating_point T>
class Mesh;
template <typename T>
class MeshTags;
} // namespace dolfinx::mesh
namespace dolfinx::io
{
class XDMFFile
{
public:
enum class Encoding : std::int8_t
{
HDF5,
ASCII
};
XDMFFile(MPI_Comm comm, const std::filesystem::path& filename,
const std::string& file_mode, Encoding encoding = Encoding::HDF5);
XDMFFile(XDMFFile&&) = default;
~XDMFFile();
void close();
template <std::floating_point U>
void write_mesh(const mesh::Mesh<U>& mesh,
const std::string& xpath = "/Xdmf/Domain");
void write_geometry(const mesh::Geometry<double>& geometry,
const std::string& name,
const std::string& xpath = "/Xdmf/Domain");
mesh::Mesh<double>
read_mesh(const fem::CoordinateElement<double>& element, mesh::GhostMode mode,
const std::string& name, const std::string& xpath = "/Xdmf/Domain",
std::optional<std::int32_t> max_facet_to_cell_links = 2) const;
std::pair<std::vector<std::int64_t>, std::array<std::size_t, 2>>
read_topology_data(const std::string& name,
const std::string& xpath = "/Xdmf/Domain") const;
std::pair<std::variant<std::vector<float>, std::vector<double>>,
std::array<std::size_t, 2>>
read_geometry_data(const std::string& name,
const std::string& xpath = "/Xdmf/Domain") const;
std::pair<mesh::CellType, int> read_cell_type(const std::string& grid_name,
const std::string& xpath
= "/Xdmf/Domain");
template <dolfinx::scalar T, std::floating_point U = scalar_value_t<T>>
void write_function(const fem::Function<T, U>& u, double t,
std::string mesh_xpath
= "/Xdmf/Domain/Grid[@GridType='Uniform'][1]");
template <std::floating_point T>
void write_meshtags(const mesh::MeshTags<std::int32_t>& meshtags,
const mesh::Geometry<T>& x,
const std::string& geometry_xpath,
const std::string& xpath = "/Xdmf/Domain");
mesh::MeshTags<std::int32_t>
read_meshtags(const mesh::Mesh<double>& mesh, const std::string& name,
std::optional<std::string> attribute_name,
const std::string& xpath = "/Xdmf/Domain");
void write_information(const std::string& name, const std::string& value,
const std::string& xpath = "/Xdmf/Domain/");
std::string read_information(const std::string& name,
const std::string& xpath = "/Xdmf/Domain/");
void flush();
MPI_Comm comm() const;
private:
// MPI communicator
dolfinx::MPI::Comm _comm;
// Filename
std::filesystem::path _filename;
// File mode
std::string _file_mode;
// HDF5 file handle
hid_t _h5_id;
// The XML document currently representing the XDMF which needs to be
// kept open for time series etc.
std::unique_ptr<pugi::xml_document> _xml_doc;
Encoding _encoding;
};
} // namespace dolfinx::io
dolfinx::MPI::Comm
A duplicate MPI communicator and manage lifetime of the communicator.
Definition MPI.h:42
dolfinx::fem::CoordinateElement
Definition CoordinateElement.h:38
dolfinx::fem::Function
Definition Function.h:47
dolfinx::io::XDMFFile::read_mesh
mesh::Mesh< double > read_mesh(const fem::CoordinateElement< double > &element, mesh::GhostMode mode, const std::string &name, const std::string &xpath="/Xdmf/Domain", std::optional< std::int32_t > max_facet_to_cell_links=2) const
Definition XDMFFile.cpp:187
dolfinx::io::XDMFFile::XDMFFile
XDMFFile(MPI_Comm comm, const std::filesystem::path &filename, const std::string &file_mode, Encoding encoding=Encoding::HDF5)
Constructor.
Definition XDMFFile.cpp:29
dolfinx::io::XDMFFile::~XDMFFile
~XDMFFile()
Destructor.
Definition XDMFFile.cpp:134
dolfinx::io::XDMFFile::write_function
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:240
dolfinx::io::XDMFFile::close
void close()
Definition XDMFFile.cpp:136
dolfinx::io::XDMFFile::read_information
std::string read_information(const std::string &name, const std::string &xpath="/Xdmf/Domain/")
Definition XDMFFile.cpp:455
dolfinx::io::XDMFFile::read_geometry_data
std::pair< std::variant< std::vector< float >, std::vector< double > >, std::array< std::size_t, 2 > > read_geometry_data(const std::string &name, const std::string &xpath="/Xdmf/Domain") const
Definition XDMFFile.cpp:223
dolfinx::io::XDMFFile::read_topology_data
std::pair< std::vector< std::int64_t >, std::array< std::size_t, 2 > > read_topology_data(const std::string &name, const std::string &xpath="/Xdmf/Domain") const
Definition XDMFFile.cpp:205
dolfinx::io::XDMFFile::XDMFFile
XDMFFile(XDMFFile &&)=default
Move constructor.
dolfinx::io::XDMFFile::write_information
void write_information(const std::string &name, const std::string &value, const std::string &xpath="/Xdmf/Domain/")
Definition XDMFFile.cpp:437
dolfinx::io::XDMFFile::Encoding
Encoding
File encoding type.
Definition XDMFFile.h:63
dolfinx::io::XDMFFile::read_cell_type
std::pair< mesh::CellType, int > read_cell_type(const std::string &grid_name, const std::string &xpath="/Xdmf/Domain")
Definition XDMFFile.cpp:413
dolfinx::io::XDMFFile::comm
MPI_Comm comm() const
Definition XDMFFile.cpp:478
dolfinx::io::XDMFFile::write_meshtags
void write_meshtags(const mesh::MeshTags< std::int32_t > &meshtags, const mesh::Geometry< T > &x, const std::string &geometry_xpath, const std::string &xpath="/Xdmf/Domain")
Definition XDMFFile.cpp:308
dolfinx::io::XDMFFile::flush
void flush()
Definition XDMFFile.cpp:472
dolfinx::io::XDMFFile::read_meshtags
mesh::MeshTags< std::int32_t > read_meshtags(const mesh::Mesh< double > &mesh, const std::string &name, std::optional< std::string > attribute_name, const std::string &xpath="/Xdmf/Domain")
Definition XDMFFile.cpp:345
dolfinx::io::XDMFFile::write_mesh
void write_mesh(const mesh::Mesh< U > &mesh, const std::string &xpath="/Xdmf/Domain")
Definition XDMFFile.cpp:144
dolfinx::io::XDMFFile::write_geometry
void write_geometry(const mesh::Geometry< double > &geometry, const std::string &name, const std::string &xpath="/Xdmf/Domain")
Definition XDMFFile.cpp:164
dolfinx::mesh::Geometry
Geometry stores the geometry imposed on a mesh.
Definition Geometry.h:34
dolfinx::mesh::MeshTags
MeshTags associate values with mesh topology entities.
Definition MeshTags.h:33
dolfinx::mesh::Mesh
A Mesh consists of a set of connected and numbered mesh topological entities, and geometry data.
Definition Mesh.h:23
dolfinx::fem
Finite element method functionality.
Definition assemble_expression_impl.h:23
dolfinx::geometry
Geometry data structures and algorithms.
Definition BoundingBoxTree.h:22
dolfinx::io
Support for file IO.
Definition cells.h:119
dolfinx::mesh
Mesh data structures and algorithms on meshes.
Definition DofMap.h:32
dolfinx::mesh::GhostMode
GhostMode
Enum for different partitioning ghost modes.
Definition utils.h:41