common.io

Classes

IsDataclass

Dataclass protocol. See https://stackoverflow.com/a/55240861

Functions

load_options(→ dict[str, Any])

Load options dictionary from YAML file.

dump_options(→ None)

Dump options dictionary from YAML file.

read_mesh(→ tuple[dolfinx.mesh.Mesh, ...)

Read mesh from dolfinx XDMF or Gmsh MSH file.

_read_mesh_gmsh(→ tuple[dolfinx.mesh.Mesh, ...)

Read dolfinx mesh, subdomain and boundary identifiers from GMSH file.

_read_mesh_xdmf(→ tuple[dolfinx.mesh.Mesh, ...)

Read dolfinx mesh, subdomain and boundary identifiers from XDMF file.

convert_msh_to_xdmf(→ None)

Read Gmsh mesh (MSH format) and write to disk in DOLFINX XDMF format.

copy_inputfile(→ None)

Copy input file to results directory.

write_version_githash(→ None)

Write version and git hash to results directory.

write_sysinfo(→ None)

Write host info and dolfinx, PETSc versions to file.

enum_asdict_factory(→ Any)

Factory to convert dataclasses to dict, to allow serializing Enums for yaml.dump().

Module Contents

class common.io.IsDataclass[source]

Bases: Protocol

Dataclass protocol. See https://stackoverflow.com/a/55240861

__dataclass_fields__: ClassVar[dict[str, Any]][source]
common.io.load_options(input_file: os.PathLike[str] | str) → dict[str, Any][source]

Load options dictionary from YAML file.

Parameters:

input_file – path to options input file

Returns:

options dictionary

common.io.dump_options(options: IsDataclass, file: os.PathLike[str] | str) → None[source]

Dump options dictionary from YAML file.

Parameters:
  • options – options dataclass to be written to file

  • file – output file

common.io.read_mesh(mesh_file: os.PathLike[str] | str) → tuple[dolfinx.mesh.Mesh, dolfinx.mesh.MeshTags | None, dolfinx.mesh.MeshTags | None][source]

Read mesh from dolfinx XDMF or Gmsh MSH file.

Both formats are supported in parallel.

Parameters:

mesh_file – path to mesh file

Returns:

  • mesh

  • boundary identifiers or None

common.io._read_mesh_gmsh(mesh_file: os.PathLike[str] | str) → tuple[dolfinx.mesh.Mesh, dolfinx.mesh.MeshTags | None, dolfinx.mesh.MeshTags | None][source]

Read dolfinx mesh, subdomain and boundary identifiers from GMSH file.

Parameters:

mesh_file – input Gmsh mesh file

Returns:

  • mesh

  • boundary identifiers or None

  • subdomain identifiers

common.io._read_mesh_xdmf(mesh_file: os.PathLike[str] | str) → tuple[dolfinx.mesh.Mesh, dolfinx.mesh.MeshTags | None, dolfinx.mesh.MeshTags | None][source]

Read dolfinx mesh, subdomain and boundary identifiers from XDMF file.

The boundary identifiers – ‘facet tags’ – have to be labeled “Facet tags” (dolfinx default) or “mesh_tags”. The subdomain identifiers must be labeled “Cell tags”.

Parameters:

path – input XDMF mesh file

Returns:

  • mesh

  • subdomain identifiers

  • boundary identifiers or None

common.io.convert_msh_to_xdmf(msh_file: os.PathLike[str] | str) → None[source]

Read Gmsh mesh (MSH format) and write to disk in DOLFINX XDMF format.

Parameters:

path – input Gmsh mesh file

common.io.copy_inputfile(inputfile: os.PathLike[str] | str, write_path: os.PathLike[str] | str) → None[source]

Copy input file to results directory.

Parameters:
  • inputfile – options YAML input file

  • write_path – path where simulation output files are stored

common.io.write_version_githash(repo_file: os.PathLike[str] | str, version: str, write_path: os.PathLike[str] | str) → None[source]

Write version and git hash to results directory.

Deprecated since version 0.4.0: replaced by common.utils.capture_environment()

Parameters:
  • repo_file – path to file within git repository (__file__ of calling class)

  • version – package version to write

  • write_path – path where simulation output files are stored

common.io.write_sysinfo(write_path: os.PathLike[str] | str) → None[source]

Write host info and dolfinx, PETSc versions to file.

Deprecated since version 0.4.0: replaced by common.utils.capture_environment()

Parameters:

write_path – path where simulation output files are stored

common.io.enum_asdict_factory(data: Any) → Any[source]

Factory to convert dataclasses to dict, to allow serializing Enums for yaml.dump().