Note: this is documentation for an old release. View the latest documentation at docs.fenicsproject.org/dolfinx/v0.9.0/cpp/doxygen/d9/d9e/classdolfinx_1_1io_1_1XDMFFile.html
DOLFINx  0.5.1
DOLFINx C++ interface
Public Types | Public Member Functions | Static Public Attributes | List of all members
XDMFFile Class Reference

Read and write mesh::Mesh, fem::Function and other objects in XDMF. More...

#include <XDMFFile.h>

Public Types

enum class  Encoding { HDF5 , ASCII }
 File encoding type.
 

Public Member Functions

 XDMFFile (MPI_Comm comm, const std::filesystem::path &filename, const std::string file_mode, const Encoding encoding=default_encoding)
 Constructor.
 
 ~XDMFFile ()
 Destructor.
 
void close ()
 Close the file. More...
 
void write_mesh (const mesh::Mesh &mesh, const std::string xpath="/Xdmf/Domain")
 Save Mesh. More...
 
void write_geometry (const mesh::Geometry &geometry, const std::string name, const std::string xpath="/Xdmf/Domain")
 Save Geometry. More...
 
mesh::Mesh read_mesh (const fem::CoordinateElement &element, const mesh::GhostMode &mode, const std::string name, const std::string xpath="/Xdmf/Domain") const
 Read in Mesh. More...
 
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
 Read Topology data for Mesh. More...
 
std::pair< std::vector< double >, std::array< std::size_t, 2 > > read_geometry_data (const std::string name, const std::string xpath="/Xdmf/Domain") const
 Read Geometry data for Mesh. More...
 
std::pair< mesh::CellType, int > read_cell_type (const std::string grid_name, const std::string xpath="/Xdmf/Domain")
 Read information about cell type. More...
 
void write_function (const fem::Function< double > &u, double t, const std::string &mesh_xpath="/Xdmf/Domain/Grid[@GridType='Uniform'][1]")
 Write Function. More...
 
void write_function (const fem::Function< std::complex< double >> &u, double t, const std::string &mesh_xpath="/Xdmf/Domain/Grid[@GridType='Uniform'][1]")
 Write Function. More...
 
void write_meshtags (const mesh::MeshTags< std::int32_t > &meshtags, const std::string &geometry_xpath, const std::string &xpath="/Xdmf/Domain")
 Write MeshTags. More...
 
mesh::MeshTags< std::int32_t > read_meshtags (const std::shared_ptr< const mesh::Mesh > &mesh, const std::string name, const std::string xpath="/Xdmf/Domain")
 Read MeshTags. More...
 
void write_information (const std::string name, const std::string value, const std::string xpath="/Xdmf/Domain/")
 Write Information. More...
 
std::string read_information (const std::string name, const std::string xpath="/Xdmf/Domain/")
 Read Information. More...
 
MPI_Comm comm () const
 Get the MPI communicator. More...
 

Static Public Attributes

static const Encoding default_encoding = Encoding::HDF5
 Default encoding type.
 

Detailed Description

Read and write mesh::Mesh, fem::Function and other objects in XDMF.

This class supports the output of meshes and functions in XDMF (http://www.xdmf.org) format. It creates an XML file that describes the data and points to a HDF5 file that stores the actual problem data. Output of data in parallel is supported.

XDMF is not suitable for higher order geometries, as their currently only supports 1st and 2nd order geometries.

Member Function Documentation

◆ close()

void close ( )

Close the file.

This closes open underlying HDF5 file. In ASCII mode the XML file is closed each time it is written to or read from, so close() has no effect.

◆ comm()

MPI_Comm comm ( ) const

Get the MPI communicator.

Returns
The MPI communicator for the file object

◆ read_cell_type()

std::pair< mesh::CellType, int > read_cell_type ( const std::string  grid_name,
const std::string  xpath = "/Xdmf/Domain" 
)

Read information about cell type.

Parameters
[in]grid_nameName of Grid for which cell type is needed
[in]xpathXPath where Grid is stored

◆ read_geometry_data()

std::pair< std::vector< double >, std::array< std::size_t, 2 > > read_geometry_data ( const std::string  name,
const std::string  xpath = "/Xdmf/Domain" 
) const

Read Geometry data for Mesh.

Parameters
[in]nameName of the mesh (Grid)
[in]xpathXPath where Mesh Grid data is located
Returns
points on each process

◆ read_information()

std::string read_information ( const std::string  name,
const std::string  xpath = "/Xdmf/Domain/" 
)

Read Information.

Parameters
[in]name
[in]xpathXPath where Information is stored in file

◆ read_mesh()

mesh::Mesh read_mesh ( const fem::CoordinateElement element,
const mesh::GhostMode mode,
const std::string  name,
const std::string  xpath = "/Xdmf/Domain" 
) const

Read in Mesh.

Parameters
[in]elementElement that describes the geometry of a cell
[in]modeThe type of ghosting/halo to use for the mesh when distributed in parallel
[in]name
[in]xpathXPath where Mesh Grid is located
Returns
A Mesh distributed on the same communicator as the XDMFFile

◆ read_meshtags()

mesh::MeshTags< std::int32_t > read_meshtags ( const std::shared_ptr< const mesh::Mesh > &  mesh,
const std::string  name,
const std::string  xpath = "/Xdmf/Domain" 
)

Read MeshTags.

Parameters
[in]meshThe Mesh that the data is defined on
[in]name
[in]xpathXPath where MeshTags Grid is stored in file

◆ 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

Read Topology data for Mesh.

Parameters
[in]nameName of the mesh (Grid)
[in]xpathXPath where Mesh Grid data is located
Returns
(Cell type, degree), and cells topology (global node indexing)

◆ write_function() [1/2]

void write_function ( const fem::Function< double > &  u,
double  t,
const std::string &  mesh_xpath = "/Xdmf/Domain/Grid[@GridType='Uniform'][1]" 
)

Write Function.

Parameters
[in]uThe Function to write to file
[in]tThe time stamp to associate with the Function
[in]mesh_xpathXPath for a Grid under which Function will be inserted

◆ write_function() [2/2]

void write_function ( const fem::Function< std::complex< double >> &  u,
double  t,
const std::string &  mesh_xpath = "/Xdmf/Domain/Grid[@GridType='Uniform'][1]" 
)

Write Function.

Parameters
[in]uThe Function to write to file
[in]tThe time stamp to associate with the Function
[in]mesh_xpathXPath for a Grid under which Function will be inserted

◆ write_geometry()

void write_geometry ( const mesh::Geometry geometry,
const std::string  name,
const std::string  xpath = "/Xdmf/Domain" 
)

Save Geometry.

Parameters
[in]geometry
[in]name
[in]xpathXPath of a node where Geometry will be inserted

◆ write_information()

void write_information ( const std::string  name,
const std::string  value,
const std::string  xpath = "/Xdmf/Domain/" 
)

Write Information.

Parameters
[in]name
[in]valueString to store into Information tag
[in]xpathXPath where Information will be inserted

◆ write_mesh()

void write_mesh ( const mesh::Mesh mesh,
const std::string  xpath = "/Xdmf/Domain" 
)

Save Mesh.

Parameters
[in]mesh
[in]xpathXPath where Mesh Grid will be written

◆ write_meshtags()

void write_meshtags ( const mesh::MeshTags< std::int32_t > &  meshtags,
const std::string &  geometry_xpath,
const std::string &  xpath = "/Xdmf/Domain" 
)

Write MeshTags.

Parameters
[in]meshtags
[in]geometry_xpathXPath where Geometry is already stored in file
[in]xpathXPath where MeshTags Grid will be inserted

The documentation for this class was generated from the following files: