API Reference

Contents

API Reference#

class cardiac_geometries.Geometry(mesh: dolfinx.mesh.Mesh, markers: dict[str, tuple[int, int]] = <factory>, cfun: dolfinx.mesh.MeshTags | None = None, ffun: dolfinx.mesh.MeshTags | None = None, efun: dolfinx.mesh.MeshTags | None = None, vfun: dolfinx.mesh.MeshTags | None = None, f0: dolfinx.fem.function.Function | None = None, s0: dolfinx.fem.function.Function | None = None, n0: dolfinx.fem.function.Function | None = None, info: dict[str, typing.Any] = <factory>, additional_data: dict[str, dolfinx.mesh.MeshTags | dolfinx.fem.function.Function] = <factory>, quadrature_degree: int = 4, unit: str | None = None, additional_data_info: dict[str, dict[str, typing.Any]] = <factory>, file_format: int | None = None)[source]#
additional_data_info: dict[str, dict[str, Any]]#

Per entry of additional_data, its unit, values, description and recipe.

property ds#

Surface measure for the mesh using the facet function ffun if it exists as subdomain data.

property dx#

Volume measure for the mesh using the cell function cfun if it exists as subdomain data.

property facet_normal: FacetNormal#

Facet normal vector for the mesh.

file_format: int | None = None#

The format of the file the geometry was read from, 0 or 1; None in memory.

classmethod from_file(comm: Comm, path: str | Path, ghost_mode: GhostMode = GhostMode.none, backend: str | None = None) → Geometry[source]#

Read geometry from a file using io4dolfinx.

A file of format 1 holds its metadata. A file without it is of format 0, written before format 1, whose metadata is read from the JSON files beside it (markers_<stem>.json, info_<stem>.json, microstructure_<stem>.json and additional_data_<stem>.json), those that exist.

Parameters:
  • comm (MPI.Comm) – The MPI communicator to use for reading the mesh.

  • path (str | Path) – The path to the file containing the geometry data.

  • ghost_mode (dolfinx.mesh.GhostMode, optional) – The ghost mode to use when reading the mesh, by default dolfinx.mesh.GhostMode.none. Note that if you need to refine the mesh later, you should use dolfinx.mesh.GhostMode.none.

  • backend (str | None, optional) – The io4dolfinx backend, “adios2” or “h5py”. By default it is inferred from the suffix of path (infer_io_backend()).

Returns:

An instance of the Geometry class containing the mesh, markers, and functions.

Return type:

Geometry

Raises:
  • ValueError – If path does not exist.

  • FormatError – If the file is of a higher format than this version of cardiac-geometriesx reads.

classmethod from_folder(comm: Comm, folder: str | Path, ghost_mode: GhostMode = GhostMode.none) → Geometry[source]#

Read geometry from a folder containing mesh and markers files.

Deprecated since version Use: Geometry.from_file(), which reads one self-describing file.

Parameters:
  • comm (MPI.Comm) – The MPI communicator to use for reading the mesh and markers.

  • folder (str | Path) – The path to the folder containing the geometry data.

  • ghost_mode (dolfinx.mesh.GhostMode, optional) – The ghost mode to use when reading the mesh, by default dolfinx.mesh.GhostMode.none. Note that if you need to refine the mesh later, you should use dolfinx.mesh.GhostMode.none.

Returns:

An instance of the Geometry class containing the mesh, markers, and functions.

Return type:

Geometry

Raises:

ValueError – If the required mesh file is not found in the specified folder.

refine(n=1, outdir: Path | None = None) → Geometry[source]#

Refine the mesh and transfer the meshtags to new geometry. Also regenerate fibers if self.info is found. If self.info is not found, it currently raises a NotImplementedError, however fiber could be interpolated from the old mesh to the new mesh but this will result in a loss of information about the fiber orientation.

Parameters:
  • n (int, optional) – Number of times to refine the mesh, by default 1

  • outdir (Path | None, optional) – Output directory to save the refined mesh and meshtags, by default None in which case the mesh is not saved.

Returns:

A new Geometry object with the refined mesh and updated meshtags.

Return type:

Geometry

Raises:

NotImplementedError – If self.info is not found, indicating that fiber interpolation after refinement is not implemented yet.

rotate(target_normal, base_marker)[source]#

Rotate the geometry so that the base normal aligns with the target normal.

Parameters:
  • target_normal (np.ndarray) – The target normal vector to align the base normal with.

  • base_marker (str) – The marker for the base of the geometry.

Returns:

The rotated Geometry object. Only returned if inplace is False.

Return type:

Geometry

save(path: str | Path, backend: str | None = None) → None[source]#

Save the geometry to one file using io4dolfinx (save_geometry()).

The file is of format 1: its metadata is inside it, and nothing is written beside it.

Parameters:
  • path (str | Path) – The path to the file where the geometry will be saved. The file will be created if it does not exist, or overwritten if it does.

  • backend (str | None, optional) – The io4dolfinx backend, “adios2” or “h5py”. By default it is inferred from the suffix of path (infer_io_backend()).

save_folder(folder: str | Path, backend: str = 'h5py') → None[source]#

Save the geometry to a folder containing mesh and markers files.

Deprecated since version Use: Geometry.save(), which writes one self-describing file.

Parameters:
  • folder (str | Path) – The path to the folder where the geometry will be saved. The folder will be created if it does not exist.

  • backend (str, optional) – The io4dolfinx backend used for the geometry file, “adios2” (written to geometry.bp) or “h5py” (written to geometry.h5), by default “h5py”.

save_replacing(path: str | Path) → None[source]#

Save the geometry over the existing file path (save()), so that a failure leaves the original file.

The geometry is saved beside path under a hidden name, and rank 0 then swaps it in. path may be a directory (adios2’s .bp), which os.replace() cannot put over a non-empty one, so the original is first moved aside, and removed once the new file is in place. Every rank raises RuntimeError if the swap fails, so that no rank is left waiting at a collective call.

unit: str | None = None#

The unit of the coordinates, one of UNITS.

cardiac_geometries.cli.export_option(command)[source]#

Add --export/--no-export to a generator command, and after it ran, export the geometry it wrote into OUTDIR/viz/ (a warning instead, and still exit code 0, without pyvista or on more than one rank).

cardiac_geometries.cli.unit_option(default: str | None = None, required: bool = False)[source]#

The --unit option: the unit of the geometry’s coordinates.

cardiac_geometries.geometry.DEFAULT_IO_BACKEND = 'h5py'#

io4dolfinx 2.0’s default, and what pulse, beat and simcardemsx write.

cardiac_geometries.geometry.FIND_ORDER: tuple[str, ...] = ('h5py', 'adios2')#

The order in which find_geometry_file() looks for a folder’s geometry file.

class cardiac_geometries.geometry.Geometry(mesh: dolfinx.mesh.Mesh, markers: dict[str, tuple[int, int]] = <factory>, cfun: dolfinx.mesh.MeshTags | None = None, ffun: dolfinx.mesh.MeshTags | None = None, efun: dolfinx.mesh.MeshTags | None = None, vfun: dolfinx.mesh.MeshTags | None = None, f0: dolfinx.fem.function.Function | None = None, s0: dolfinx.fem.function.Function | None = None, n0: dolfinx.fem.function.Function | None = None, info: dict[str, typing.Any] = <factory>, additional_data: dict[str, dolfinx.mesh.MeshTags | dolfinx.fem.function.Function] = <factory>, quadrature_degree: int = 4, unit: str | None = None, additional_data_info: dict[str, dict[str, typing.Any]] = <factory>, file_format: int | None = None)[source]#
additional_data_info: dict[str, dict[str, Any]]#

Per entry of additional_data, its unit, values, description and recipe.

property ds#

Surface measure for the mesh using the facet function ffun if it exists as subdomain data.

property dx#

Volume measure for the mesh using the cell function cfun if it exists as subdomain data.

property facet_normal: FacetNormal#

Facet normal vector for the mesh.

file_format: int | None = None#

The format of the file the geometry was read from, 0 or 1; None in memory.

classmethod from_file(comm: Comm, path: str | Path, ghost_mode: GhostMode = GhostMode.none, backend: str | None = None) → Geometry[source]#

Read geometry from a file using io4dolfinx.

A file of format 1 holds its metadata. A file without it is of format 0, written before format 1, whose metadata is read from the JSON files beside it (markers_<stem>.json, info_<stem>.json, microstructure_<stem>.json and additional_data_<stem>.json), those that exist.

Parameters:
  • comm (MPI.Comm) – The MPI communicator to use for reading the mesh.

  • path (str | Path) – The path to the file containing the geometry data.

  • ghost_mode (dolfinx.mesh.GhostMode, optional) – The ghost mode to use when reading the mesh, by default dolfinx.mesh.GhostMode.none. Note that if you need to refine the mesh later, you should use dolfinx.mesh.GhostMode.none.

  • backend (str | None, optional) – The io4dolfinx backend, “adios2” or “h5py”. By default it is inferred from the suffix of path (infer_io_backend()).

Returns:

An instance of the Geometry class containing the mesh, markers, and functions.

Return type:

Geometry

Raises:
  • ValueError – If path does not exist.

  • FormatError – If the file is of a higher format than this version of cardiac-geometriesx reads.

classmethod from_folder(comm: Comm, folder: str | Path, ghost_mode: GhostMode = GhostMode.none) → Geometry[source]#

Read geometry from a folder containing mesh and markers files.

Deprecated since version Use: Geometry.from_file(), which reads one self-describing file.

Parameters:
  • comm (MPI.Comm) – The MPI communicator to use for reading the mesh and markers.

  • folder (str | Path) – The path to the folder containing the geometry data.

  • ghost_mode (dolfinx.mesh.GhostMode, optional) – The ghost mode to use when reading the mesh, by default dolfinx.mesh.GhostMode.none. Note that if you need to refine the mesh later, you should use dolfinx.mesh.GhostMode.none.

Returns:

An instance of the Geometry class containing the mesh, markers, and functions.

Return type:

Geometry

Raises:

ValueError – If the required mesh file is not found in the specified folder.

refine(n=1, outdir: Path | None = None) → Geometry[source]#

Refine the mesh and transfer the meshtags to new geometry. Also regenerate fibers if self.info is found. If self.info is not found, it currently raises a NotImplementedError, however fiber could be interpolated from the old mesh to the new mesh but this will result in a loss of information about the fiber orientation.

Parameters:
  • n (int, optional) – Number of times to refine the mesh, by default 1

  • outdir (Path | None, optional) – Output directory to save the refined mesh and meshtags, by default None in which case the mesh is not saved.

Returns:

A new Geometry object with the refined mesh and updated meshtags.

Return type:

Geometry

Raises:

NotImplementedError – If self.info is not found, indicating that fiber interpolation after refinement is not implemented yet.

rotate(target_normal, base_marker)[source]#

Rotate the geometry so that the base normal aligns with the target normal.

Parameters:
  • target_normal (np.ndarray) – The target normal vector to align the base normal with.

  • base_marker (str) – The marker for the base of the geometry.

Returns:

The rotated Geometry object. Only returned if inplace is False.

Return type:

Geometry

save(path: str | Path, backend: str | None = None) → None[source]#

Save the geometry to one file using io4dolfinx (save_geometry()).

The file is of format 1: its metadata is inside it, and nothing is written beside it.

Parameters:
  • path (str | Path) – The path to the file where the geometry will be saved. The file will be created if it does not exist, or overwritten if it does.

  • backend (str | None, optional) – The io4dolfinx backend, “adios2” or “h5py”. By default it is inferred from the suffix of path (infer_io_backend()).

save_folder(folder: str | Path, backend: str = 'h5py') → None[source]#

Save the geometry to a folder containing mesh and markers files.

Deprecated since version Use: Geometry.save(), which writes one self-describing file.

Parameters:
  • folder (str | Path) – The path to the folder where the geometry will be saved. The folder will be created if it does not exist.

  • backend (str, optional) – The io4dolfinx backend used for the geometry file, “adios2” (written to geometry.bp) or “h5py” (written to geometry.h5), by default “h5py”.

save_replacing(path: str | Path) → None[source]#

Save the geometry over the existing file path (save()), so that a failure leaves the original file.

The geometry is saved beside path under a hidden name, and rank 0 then swaps it in. path may be a directory (adios2’s .bp), which os.replace() cannot put over a non-empty one, so the original is first moved aside, and removed once the new file is in place. Every rank raises RuntimeError if the swap fails, so that no rank is left waiting at a collective call.

unit: str | None = None#

The unit of the coordinates, one of UNITS.

cardiac_geometries.geometry.IO_BACKEND_SUFFIXES: dict[str, str] = {'adios2': '.bp', 'h5py': '.h5'}#

io4dolfinx backends that support checkpointing (mesh, meshtags and functions), mapped to the file suffix used for the geometry file.

cardiac_geometries.geometry.find_geometry_file(folder: str | Path) → Path | None[source]#

The geometry file in folder: geometry.h5, else geometry.bp, else None.

cardiac_geometries.geometry.geometry_path(folder: str | Path, backend: str = 'h5py') → Path[source]#

Path of the geometry file in folder written with backend, i.e. geometry.bp for adios2 and geometry.h5 for h5py.

cardiac_geometries.geometry.infer_io_backend(path: str | Path) → str[source]#

Infer the io4dolfinx backend from the suffix of path: adios2 for .bp, h5py for .h5/.hdf5, and DEFAULT_IO_BACKEND for any other suffix.

cardiac_geometries.geometry.load_additional_data(path: Path, mesh: Mesh, backend: str | None = None) → dict[str, MeshTags | Function][source]#

Read the additional_data of the file path, which its metadata describes (format 1) or additional_data_<stem>.json beside it (format 0).

cardiac_geometries.geometry.save_geometry(path: Path, mesh: Mesh, markers: dict[str, tuple[int, int]] | None = None, info: dict[str, Any] | None = None, cfun: MeshTags | None = None, ffun: MeshTags | None = None, efun: MeshTags | None = None, vfun: MeshTags | None = None, f0: Function | None = None, s0: Function | None = None, n0: Function | None = None, additional_data: dict[str, MeshTags | Function] | None = None, backend: str | None = None, unit: str | None = None, additional_data_info: dict[str, dict[str, Any]] | None = None) → None[source]#

Save a geometry to path as one io4dolfinx file of format 1.

The file holds the mesh, the tags, the fibres, additional_data and, written last, the metadata (cardiac_geometries.metadata): markers, the fibres’ elements, the type and element of each entry of additional_data with its additional_data_info, info, unit and the format. Nothing is written beside the file. The metadata’s copy of info records the version of cardiac-geometriesx that wrote the file as cardiac_geometry_version, replacing any earlier value; info itself is not changed.

Deleted first, on rank 0: any file at path, and the JSON files that a format-0 file of the same stem kept beside it (markers_<stem>.json, info_<stem>.json, microstructure_<stem>.json and additional_data_<stem>.json), which would describe another file. A file of the same stem written with the other backend is kept, with a warning, and so are the JSON files, which may be that file’s: a folder that holds both is read through find_geometry_file(), which picks geometry.h5, and the format-1 file ignores them.

backend is the io4dolfinx backend (“adios2” or “h5py”). If None it is inferred from the suffix of path (infer_io_backend()).

cardiac_geometries.mesh.biv_ellipsoid(outdir: str | ~pathlib.Path, char_length: float = 0.5, base_cut_z: float = 1.0, box_size: float = 20.0, rv_wall_thickness: float = 0.4, lv_wall_thickness: float = 0.5, rv_offset_x: float = 1.0, lv_radius_x: float = 2.2, lv_radius_y: float = 2.2, lv_radius_z: float = 4.5, rv_radius_x: float = 3.2, rv_radius_y: float = 2.3, rv_radius_z: float = 4.3, create_fibers: bool = False, fiber_angle_endo: float = 60, fiber_angle_epi: float = -60, fiber_space: str = 'P_1', verbose: bool = False, order: int = 1, comm: ~mpi4py.MPI.Comm = <mpi4py.MPI.Intracomm object>, ghost_mode: ~dolfinx.cpp.mesh.GhostMode = GhostMode.none, unit: str = 'cm', io_backend: str = 'h5py') → Geometry[source]#

Create BiV ellipsoidal geometry

Parameters:
  • outdir (str | Path) – Directory where to save the results.

  • char_length (float, optional) – Characteristic length of mesh, by default 0.5

  • box_size (float, optional) – Size of the cutting box, by default 20.0

  • lv_radius_x (float, optional) – Radius of the left ventricle in the x-direction, by default 2.2

  • lv_radius_y (float, optional) – Radius of the left ventricle in the y-direction, by default 2.2

  • lv_radius_z (float, optional) – Radius of the left ventricle in the z-direction, by default 4.5

  • rv_radius_x (float, optional) – Radius of the right ventricle in the x-direction, by default 3.2

  • rv_radius_y (float, optional) – Radius of the right ventricle in the y-direction, by default 2.3

  • rv_radius_z (float, optional) – Radius of the right ventricle in the z-direction, by default 4.3

  • create_fibers (bool, optional) – If True create rule-based fibers with fenicsx-ldrb (the method of Bayer et al. 2012), by default False

  • fiber_angle_endo (float, optional) – Angle for the endocardium, by default 60

  • fiber_angle_epi (float, optional) – Angle for the epicardium, by default -60

  • fiber_space (str, optional) – Function space for fibers of the form family_degree, by default “P_1”

  • verbose (bool, optional) – If True print information from gmsh, by default False

  • order (int, optional) – Order of the mesh elements. With order higher than one the elements are curved to follow the boundaries, by default 1

  • comm (MPI.Comm, optional) – MPI communicator, by default MPI.COMM_WORLD

  • ghost_mode (dolfinx.mesh.GhostMode, optional) – Ghost mode for the dolfinx mesh, by default dolfinx.mesh.GhostMode.none

  • io_backend (str, optional) – io4dolfinx backend used to write the geometry, “h5py” (geometry.h5) or “adios2” (geometry.bp), by default “h5py”

  • unit (str, optional) – Unit of the coordinates, one of “m”, “cm” or “mm”, which the geometry file records, by default “cm”

Returns:

A Geometry with the mesh, markers, markers functions and fibers.

Return type:

cardiac_geometries.geometry.Geometry

cardiac_geometries.mesh.cylinder(outdir: ~pathlib.Path | str, r_inner: float = 10.0, r_outer: float = 15.0, height: float = 40.0, floor_thickness: float = 0.0, roof_thickness: float = 0.0, char_length: float = 5.0, create_fibers: bool = False, fiber_angle_endo: float = 60, fiber_angle_epi: float = -60, fiber_space: str = 'P_1', aha: bool = False, verbose: bool = False, order: int = 1, comm: ~mpi4py.MPI.Comm = <mpi4py.MPI.Intracomm object>, ghost_mode: ~dolfinx.cpp.mesh.GhostMode = GhostMode.none, unit: str = 'mm', io_backend: str = 'h5py') → Geometry[source]#

Create a cylindrical geometry

Parameters:
  • outdir (Optional[Path], optional) – Directory where to save the results.

  • r_inner (float, optional) – Radius on the endocardium layer, by default 10.0

  • r_outer (float, optional) – Radius on the epicardium layer, by default 15.0

  • height (float, optional) – Longest radius on the endocardium layer, by default 40.0

  • floor_thickness (float, optional) – Thickness of the floor, by default 0.0

  • roof_thickness (float, optional) – Thickness of the roof, by default 0.0

  • char_length (float, optional) – Characteristic length of mesh, by default 5.0

  • create_fibers (bool, optional) – If True create analytic fibers, by default False

  • fiber_angle_endo (float, optional) – Angle for the endocardium, by default 60

  • fiber_angle_epi (float, optional) – Angle for the epicardium, by default -60

  • fiber_space (str, optional) – Function space for fibers of the form family_degree, by default “P_1”

  • aha (bool, optional) – If True create 17-segment AHA regions

  • verbose (bool, optional) – If True print information from gmsh, by default False

  • order (int, optional) – Order of the mesh elements. With order higher than one the elements are curved to follow the boundaries, by default 1

  • comm (MPI.Comm, optional) – MPI communicator, by default MPI.COMM_WORLD

  • ghost_mode (dolfinx.mesh.GhostMode, optional) – Ghost mode for the dolfinx mesh, by default dolfinx.mesh.GhostMode.none

  • io_backend (str, optional) – io4dolfinx backend used to write the geometry, “h5py” (geometry.h5) or “adios2” (geometry.bp), by default “h5py”

  • unit (str, optional) – Unit of the coordinates, one of “m”, “cm” or “mm”, which the geometry file records, by default “mm”

Returns:

A Geometry with the mesh, markers, markers functions and fibers.

Return type:

cardiac_geometries.geometry.Geometry

cardiac_geometries.mesh.cylinder_D_shaped(outdir: ~pathlib.Path | str, r_inner: float = 13.0, r_outer: float = 20.0, height: float = 40.0, inner_flat_face_distance: float = 10.0, outer_flat_face_distance: float = 17.0, floor_thickness: float = 0.0, roof_thickness: float = 0.0, char_length: float = 10.0, create_fibers: bool = False, fiber_angle_endo: float = 60, fiber_angle_epi: float = -60, fiber_space: str = 'P_1', aha: bool = False, fillet_radius: float | None = None, verbose: bool = False, order: int = 1, comm: ~mpi4py.MPI.Comm = <mpi4py.MPI.Intracomm object>, ghost_mode: ~dolfinx.cpp.mesh.GhostMode = GhostMode.none, unit: str = 'mm', io_backend: str = 'h5py') → Geometry[source]#

Create a D-shaped thick cylindrical shell mesh using GMSH.

Both the inner and outer surfaces have two flat faces on opposite sides.

Parameters:
  • outdir (Optional[Path], optional) – Directory where to save the results.

  • r_inner (float, optional) – Radius on the endocardium layer, by default 13.0

  • r_outer (float, optional) – Radius on the epicardium layer, by default 20.0

  • height (float, optional) – Longest radius on the endocardium layer, by default 10.0

  • inner_flat_face_distance (float) – The distance of the inner flat face from the center (along the x-axis). This value must be less than inner_radius. Default is 10.0.

  • outer_flat_face_distance (float) – The distance of the outer flat face from the center (along the x-axis). This value must be less than outer_radius. Default is 17.0.

  • floor_thickness (float, optional) – Thickness of the floor, by default 0.0

  • roof_thickness (float, optional) – Thickness of the roof, by default 0.0

  • char_length (float, optional) – Characteristic length of mesh, by default 10.0

  • create_fibers (bool, optional) – If True create analytic fibers, by default False

  • fiber_angle_endo (float, optional) – Angle for the endocardium, by default 60

  • fiber_angle_epi (float, optional) – Angle for the epicardium, by default -60

  • fiber_space (str, optional) – Function space for fibers of the form family_degree, by default “P_1”

  • aha (bool, optional) – If True create 17-segment AHA regions

  • fillet_radius (float | None, optional) – Radius for the fillet on the flat faces. If None no fillet is created. By default None.

  • verbose (bool, optional) – If True print information from gmsh, by default False

  • order (int, optional) – Order of the mesh elements. With order higher than one the elements are curved to follow the boundaries, by default 1

  • comm (MPI.Comm, optional) – MPI communicator, by default MPI.COMM_WORLD

  • ghost_mode (dolfinx.mesh.GhostMode, optional) – Ghost mode for the dolfinx mesh, by default dolfinx.mesh.GhostMode.none

  • io_backend (str, optional) – io4dolfinx backend used to write the geometry, “h5py” (geometry.h5) or “adios2” (geometry.bp), by default “h5py”

  • unit (str, optional) – Unit of the coordinates, one of “m”, “cm” or “mm”, which the geometry file records, by default “mm”

Returns:

A Geometry with the mesh, markers, markers functions and fibers.

Return type:

cardiac_geometries.geometry.Geometry

cardiac_geometries.mesh.cylinder_elliptical(outdir: ~pathlib.Path | str, r_inner_x: float = 10.0, r_inner_y: float = 10.0, r_outer_x: float = 20.0, r_outer_y: float = 20.0, height: float = 40.0, char_length: float = 10.0, create_fibers: bool = False, fiber_angle_endo: float = 60, fiber_angle_epi: float = -60, fiber_space: str = 'P_1', aha: bool = False, verbose: bool = False, order: int = 1, comm: ~mpi4py.MPI.Comm = <mpi4py.MPI.Intracomm object>, unit: str = 'mm', io_backend: str = 'h5py') → Geometry[source]#

Create a cylindrical geometry

Parameters:
  • outdir (Optional[Path], optional) – Directory where to save the results.

  • r_inner_x (float, optional) – Radius on the endocardium layer along the x-axis, by default 10.0

  • r_inner_y (float, optional) – Radius on the endocardium layer along the y-axis, by default 10.0

  • r_outer_x (float, optional) – Radius on the epicardium layer along the x-axis, by default 20.0

  • r_outer_y (float, optional) – Radius on the epicardium layer along the y-axis, by default 20.0

  • height (float, optional) – Longest radius on the endocardium layer, by default 10.0

  • char_length (float, optional) – Characteristic length of mesh, by default 10.0

  • create_fibers (bool, optional) – If True create analytic fibers, by default False

  • fiber_angle_endo (float, optional) – Angle for the endocardium, by default 60

  • fiber_angle_epi (float, optional) – Angle for the epicardium, by default -60

  • fiber_space (str, optional) – Function space for fibers of the form family_degree, by default “P_1”

  • aha (bool, optional) – If True create 17-segment AHA regions

  • verbose (bool, optional) – If True print information from gmsh, by default False

  • order (int, optional) – Order of the mesh elements. With order higher than one the elements are curved to follow the boundaries, by default 1

  • comm (MPI.Comm, optional) – MPI communicator, by default MPI.COMM_WORLD

  • io_backend (str, optional) – io4dolfinx backend used to write the geometry, “h5py” (geometry.h5) or “adios2” (geometry.bp), by default “h5py”

  • unit (str, optional) – Unit of the coordinates, one of “m”, “cm” or “mm”, which the geometry file records, by default “mm”

Returns:

A Geometry with the mesh, markers, markers functions and fibers.

Return type:

cardiac_geometries.geometry.Geometry

cardiac_geometries.mesh.cylinder_racetrack(outdir: ~pathlib.Path | str, r_inner: float = 13.0, r_outer: float = 20.0, height: float = 40.0, inner_flat_face_distance: float = 10.0, outer_flat_face_distance: float = 17.0, char_length: float = 10.0, create_fibers: bool = False, fiber_angle_endo: float = 60, fiber_angle_epi: float = -60, fiber_space: str = 'P_1', aha: bool = False, fillet_radius: float | None = None, verbose: bool = False, order: int = 1, comm: ~mpi4py.MPI.Comm = <mpi4py.MPI.Intracomm object>, ghost_mode: ~dolfinx.cpp.mesh.GhostMode = GhostMode.none, unit: str = 'mm', io_backend: str = 'h5py') → Geometry[source]#

Create a racetrack-shaped thick cylindrical shell mesh using GMSH.

Both the inner and outer surfaces have two flat faces on opposite sides.

Parameters:
  • outdir (Optional[Path], optional) – Directory where to save the results.

  • r_inner (float, optional) – Radius on the endocardium layer, by default 13.0

  • r_outer (float, optional) – Radius on the epicardium layer, by default 20.0

  • height (float, optional) – Longest radius on the endocardium layer, by default 10.0

  • inner_flat_face_distance (float) – The distance of the inner flat face from the center (along the x-axis). This value must be less than inner_radius. Default is 10.0.

  • outer_flat_face_distance (float) – The distance of the outer flat face from the center (along the x-axis). This value must be less than outer_radius. Default is 17.0.

  • char_length (float, optional) – Characteristic length of mesh, by default 10.0

  • create_fibers (bool, optional) – If True create analytic fibers, by default False

  • fiber_angle_endo (float, optional) – Angle for the endocardium, by default 60

  • fiber_angle_epi (float, optional) – Angle for the epicardium, by default -60

  • fiber_space (str, optional) – Function space for fibers of the form family_degree, by default “P_1”

  • aha (bool, optional) – If True create 17-segment AHA regions

  • fillet_radius (float | None, optional) – Radius for the fillet on the flat faces. If None no fillet is created. By default None.

  • verbose (bool, optional) – If True print information from gmsh, by default False

  • order (int, optional) – Order of the mesh elements. With order higher than one the elements are curved to follow the boundaries, by default 1

  • comm (MPI.Comm, optional) – MPI communicator, by default MPI.COMM_WORLD

  • ghost_mode (dolfinx.mesh.GhostMode, optional) – Ghost mode for the dolfinx mesh, by default dolfinx.mesh.GhostMode.none

  • io_backend (str, optional) – io4dolfinx backend used to write the geometry, “h5py” (geometry.h5) or “adios2” (geometry.bp), by default “h5py”

  • unit (str, optional) – Unit of the coordinates, one of “m”, “cm” or “mm”, which the geometry file records, by default “mm”

Returns:

A Geometry with the mesh, markers, markers functions and fibers.

Return type:

cardiac_geometries.geometry.Geometry

cardiac_geometries.mesh.doste_markers(markers: dict[str, tuple[int, int]]) → dict[str, list[int]][source]#

Markers for the method of Doste et al. (ldrb.dolfinx_doste) from the markers of the UKB geometries (ukb-atlas >= 2.0), which need the valves.

cardiac_geometries.mesh.from_volume(outdir: str | ~pathlib.Path, volume, surfaces: dict | None = None, rule=None, rule_data: list[str] | None = None, scale: float = 1.0, tol: float | None = None, comm: ~mpi4py.MPI.Comm = <mpi4py.MPI.Intracomm object>, create_fibers: bool = False, fiber_method: str = 'ldrb', fiber_space: str = 'P_1', fiber_angle_endo: float = 60.0, fiber_angle_epi: float = -60.0, unit: str | None = None, io_backend: str = 'h5py', petsc_options: dict | None = None, cell_tags: str | None = None, cell_names: ~collections.abc.Mapping[int, str] | None = None, fibers: ~collections.abc.Mapping[str, str] | None = None, fields: ~collections.abc.Mapping[str, ~collections.abc.Mapping[str, ~typing.Any]] | None = None) → Geometry[source]#

A geometry from a tetrahedral volume mesh and labelled boundary surfaces, e.g. a patient mesh made with another tool.

The volume is read with io4dolfinx’s pyvista backend, already distributed, and every boundary facet gets exactly one marker, either from the surface meshes in surfaces (marker name to a file pyvista reads, e.g. PLY; a facet gets the name of the surface with a triangle on its three vertices) or from rule (see cardiac_geometries.labelled.label_facets()). Use the marker names of the UKB geometries (LV_ENDO, RV_ENDO, EPI, BASE, MV, AV, TV, PV) so the fiber methods find their boundaries: Bayer’s base is BASE plus the valves, and the method of Doste et al. needs the valves.

Parameters:
  • outdir (str | Path) – Folder for the markers and the saved geometry

  • volume (str | Path) – The volume mesh (linear tetrahedra), a file io4dolfinx’s pyvista backend reads (e.g. VTU, VTK)

  • surfaces (dict | None) – Marker name to a triangle surface file

  • rule (Callable | None) – rule(coords, data) returns the marker name of each boundary facet, from its vertex coordinates (F, 3, 3, scaled) and data: the point data named in rule_data at those vertices, each (F, 3)

  • rule_data (list[str] | None) – Names of point data in the volume file that the rule needs

  • scale (float) – Multiplies all coordinates (volume and surfaces), e.g. 1e-3 from micrometres to mm. Never guessed

  • tol (float | None) – Distance within which a surface point matches a facet vertex (after scaling); by default round-off (1e-6 of the surfaces’ size)

  • comm (MPI.Comm) – The communicator

  • create_fibers – As in ukb(): fibers by the method of Bayer et al. (“ldrb”) or Doste et al. (“doste”)

  • fiber_method – As in ukb(): fibers by the method of Bayer et al. (“ldrb”) or Doste et al. (“doste”)

  • fiber_space – As in ukb(): fibers by the method of Bayer et al. (“ldrb”) or Doste et al. (“doste”)

  • fiber_angle_endo – As in ukb(): fibers by the method of Bayer et al. (“ldrb”) or Doste et al. (“doste”)

  • fiber_angle_epi – As in ukb(): fibers by the method of Bayer et al. (“ldrb”) or Doste et al. (“doste”)

  • io_backend (str) – io4dolfinx backend for the saved geometry

  • petsc_options (dict, optional) – PETSc options for the Laplace solves of the fiber method (fenicsx-ldrb’s default if None)

  • cell_tags (str | None) – A cell-data array of integer tags. Without it every cell is Wall (1)

  • cell_names (Mapping[int, str] | None) – The name of each tag in cell_tags; every tag in the data needs one. Use the names of the cell regions of the standard (LV_WALL, MITRAL_VALVE, Bath, …)

  • fibers (Mapping[str, str] | None) – {"f0": array, "s0": array, "n0": array}, names of arrays in the volume read instead of computed (check wants f0 and s0 together). Point data stay on P1 and cell data on DG0; they are not normalised, so cardiac_geometries.check.check() reports a deviation. Excludes create_fibers

  • fields (Mapping[str, Mapping[str, Any]] | None) – {name: {"array": array, "unit": ..., "values": ..., "description": ...}}: arrays copied in as fields, at least one of unit, values and description each

  • order (The arrays of the volume are matched to the mesh by the file's own point and cell)

  • so

  • them. (scale cannot move)

  • unit (str | None, optional) – Unit of the coordinates, one of “m”, “cm” or “mm”, which the geometry file records, by default None: no unit is recorded, and geox check reports that

Returns:

  • cardiac_geometries.geometry.Geometry – The mesh, markers, facet tags and (optionally) fibers

  • The stages are timed with the dolfinx timers in FROM_VOLUME_TIMERS.

cardiac_geometries.mesh.lv_ellipsoid(outdir: ~pathlib.Path | str, r_short_endo: float = 7.0, r_short_epi: float = 10.0, r_long_endo: float = 17.0, r_long_epi: float = 20.0, psize_ref: float = 3, mu_apex_endo: float = -3.141592653589793, mu_base_endo: float = -1.2722641256100204, mu_apex_epi: float = -3.141592653589793, mu_base_epi: float = -1.318116071652818, create_fibers: bool = False, fiber_angle_endo: float = 60, fiber_angle_epi: float = -60, fiber_space: str = 'P_1', aha: bool = False, dmu_factor: float = 0.25, verbose: bool = False, order: int = 1, comm: ~mpi4py.MPI.Comm = <mpi4py.MPI.Intracomm object>, ghost_mode: ~dolfinx.cpp.mesh.GhostMode = GhostMode.none, unit: str = 'mm', io_backend: str = 'h5py') → Geometry[source]#

Create an LV ellipsoidal geometry

Parameters:
  • outdir (Optional[Path], optional) – Directory where to save the results.

  • r_short_endo (float, optional) – Shortest radius on the endocardium layer, by default 7.0

  • r_short_epi (float, optional) – Shortest radius on the epicardium layer, by default 10.0

  • r_long_endo (float, optional) – Longest radius on the endocardium layer, by default 17.0

  • r_long_epi (float, optional) – Longest radius on the epicardium layer, by default 20.0

  • psize_ref (float, optional) – The reference point size (smaller values yield as finer mesh, by default 3

  • mu_apex_endo (float, optional) – Angle for the endocardial apex, by default -math.pi

  • mu_base_endo (float, optional) – Angle for the endocardial base, by default -math.acos(5 / 17)

  • mu_apex_epi (float, optional) – Angle for the epicardial apex, by default -math.pi

  • mu_base_epi (float, optional) – Angle for the epicardial apex, by default -math.acos(5 / 20)

  • create_fibers (bool, optional) – If True create analytic fibers, by default False

  • fiber_angle_endo (float, optional) – Angle for the endocardium, by default 60

  • fiber_angle_epi (float, optional) – Angle for the epicardium, by default -60

  • fiber_space (str, optional) – Function space for fibers of the form family_degree, by default “P_1”

  • aha (bool, optional) – If True create 17-segment AHA regions

  • dmu_factor (float, optional) – Factor to determine the aha segmentation width, by default 1/4

  • verbose (bool, optional) – If True print information from gmsh, by default False

  • order (int, optional) – Order of the mesh elements. With order higher than one the elements are curved to follow the boundaries, by default 1

  • comm (MPI.Comm, optional) – MPI communicator, by default MPI.COMM_WORLD

  • ghost_mode (dolfinx.mesh.GhostMode, optional) – Ghost mode for the dolfinx mesh, by default dolfinx.mesh.GhostMode.none

  • io_backend (str, optional) – io4dolfinx backend used to write the geometry, “h5py” (geometry.h5) or “adios2” (geometry.bp), by default “h5py”

  • unit (str, optional) – Unit of the coordinates, one of “m”, “cm” or “mm”, which the geometry file records, by default “mm”

Returns:

A Geometry with the mesh, markers, markers functions and fibers.

Return type:

cardiac_geometries.geometry.Geometry

cardiac_geometries.mesh.lv_ellipsoid_2D(outdir: ~pathlib.Path | str, r_short_endo: float = 7.0, r_short_epi: float = 10.0, r_long_endo: float = 17.0, r_long_epi: float = 20.0, psize_ref: float = 3, mu_apex_endo: float = 3.141592653589793, mu_base_endo: float = 1.2722641256100204, mu_apex_epi: float = 3.141592653589793, mu_base_epi: float = 1.318116071652818, create_fibers: bool = False, fiber_angle_endo: float = 60, fiber_angle_epi: float = -60, fiber_space: str = 'P_1', verbose: bool = False, order: int = 1, comm: ~mpi4py.MPI.Comm = <mpi4py.MPI.Intracomm object>, ghost_mode: ~dolfinx.cpp.mesh.GhostMode = GhostMode.none, unit: str = 'mm', io_backend: str = 'h5py') → Geometry[source]#

Create the meridian of an LV ellipsoid, for axisymmetric problems

The mesh lies in the plane z = 0, with the long axis along x and the radial direction along y, and has geometric dimension 2. The angles mu must be in [0, pi] so that y = r_short sin(mu) >= 0: unlike lv_ellipsoid, whose default angles are negative, the defaults here give the same ellipsoid with the meridian in the upper half plane. APEX marks the segment of the axis between the two apices, where an axisymmetric problem needs its symmetry condition.

The fibers have three components: the axial, the radial and the circumferential one. The fiber angle varies linearly in the transmural coordinate of the ellipsoid itself (see cardiac_geometries.fibers.lv_ellipsoid.transmural_coordinate), as a planar Laplace problem on the meridian is not the axisymmetric one.

Parameters:
  • outdir (Optional[Path], optional) – Directory where to save the results.

  • r_short_endo (float, optional) – Shortest radius on the endocardium layer, by default 7.0

  • r_short_epi (float, optional) – Shortest radius on the epicardium layer, by default 10.0

  • r_long_endo (float, optional) – Longest radius on the endocardium layer, by default 17.0

  • r_long_epi (float, optional) – Longest radius on the epicardium layer, by default 20.0

  • psize_ref (float, optional) – The reference point size (smaller values yield as finer mesh, by default 3

  • mu_apex_endo (float, optional) – Angle for the endocardial apex, by default math.pi

  • mu_base_endo (float, optional) – Angle for the endocardial base, by default math.acos(5 / 17)

  • mu_apex_epi (float, optional) – Angle for the epicardial apex, by default math.pi

  • mu_base_epi (float, optional) – Angle for the epicardial base, by default math.acos(5 / 20)

  • create_fibers (bool, optional) – If True create analytic fibers, by default False

  • fiber_angle_endo (float, optional) – Angle for the endocardium, by default 60

  • fiber_angle_epi (float, optional) – Angle for the epicardium, by default -60

  • fiber_space (str, optional) – Function space for fibers of the form family_degree, by default “P_1”

  • verbose (bool, optional) – If True print information from gmsh, by default False

  • order (int, optional) – Order of the mesh elements. With order higher than one the elements are curved to follow the boundaries, by default 1

  • comm (MPI.Comm, optional) – MPI communicator, by default MPI.COMM_WORLD

  • ghost_mode (dolfinx.mesh.GhostMode, optional) – Ghost mode for the dolfinx mesh, by default dolfinx.mesh.GhostMode.none

  • io_backend (str, optional) – io4dolfinx backend used to write the geometry, “h5py” (geometry.h5) or “adios2” (geometry.bp), by default “h5py”

  • unit (str, optional) – Unit of the coordinates, one of “m”, “cm” or “mm”, which the geometry file records, by default “mm”

Returns:

A Geometry with the mesh, markers, markers functions and fibers.

Return type:

cardiac_geometries.geometry.Geometry

cardiac_geometries.mesh.slab(outdir: ~pathlib.Path | str, lx: float = 20.0, ly: float = 7.0, lz: float = 3.0, dx: float = 1.0, create_fibers: bool = True, fiber_angle_endo: float = 60, fiber_angle_epi: float = -60, fiber_space: str = 'P_1', verbose: bool = False, use_dolfinx: bool = False, order: int = 1, comm: ~mpi4py.MPI.Comm = <mpi4py.MPI.Intracomm object>, ghost_mode: ~dolfinx.cpp.mesh.GhostMode = GhostMode.none, unit: str = 'mm', io_backend: str = 'h5py') → Geometry[source]#

Create slab geometry

Parameters:
  • outdir (Optional[Path], optional) – Directory where to save the results.

  • lx (float, optional) – Length of slab the x-direction, by default 20.0

  • ly (float, optional) – Length of slab the x-direction, by default 7.0

  • lz (float, optional) – Length of slab the z-direction, by default 3.0

  • dx (float, optional) – Element size, by default 1.0

  • create_fibers (bool, optional) – If True create analytic fibers, by default True

  • fiber_angle_endo (float, optional) – Angle for the endocardium, by default 60

  • fiber_angle_epi (float, optional) – Angle for the epicardium, by default -60

  • fiber_space (str, optional) – Function space for fibers of the form family_degree, by default “P_1”

  • verbose (bool, optional) – If True print information from gmsh, by default False

  • use_dolfinx (bool, optional) – If True use dolfinx to create the mesh, by default False (gmsh)

  • order (int, optional) – Order of the mesh elements. With order higher than one the elements are curved to follow the boundaries, by default 1

  • comm (MPI.Comm, optional) – MPI communicator, by default MPI.COMM_WORLD

  • ghost_mode (dolfinx.mesh.GhostMode, optional) – Ghost mode for the dolfinx mesh, by default dolfinx.mesh.GhostMode.none

  • io_backend (str, optional) – io4dolfinx backend used to write the geometry, “h5py” (geometry.h5) or “adios2” (geometry.bp), by default “h5py”

  • unit (str, optional) – Unit of the coordinates, one of “m”, “cm” or “mm”, which the geometry file records, by default “mm”

Returns:

A Geometry with the mesh, markers, markers functions and fibers.

Return type:

cardiac_geometries.geometry.Geometry

cardiac_geometries.mesh.slab_in_bath(outdir: ~pathlib.Path | str, lx: float = 1.0, ly: float = 0.01, lz: float = 0.5, bx: float = 0.0, by: float = 0.0, bz: float = 0.1, dx: float = 0.001, verbose: bool = False, order: int = 1, comm: ~mpi4py.MPI.Comm = <mpi4py.MPI.Intracomm object>, ghost_mode: ~dolfinx.cpp.mesh.GhostMode = GhostMode.none, unit: str | None = None, io_backend: str = 'h5py') → Geometry[source]#

Create slab geometry

Parameters:
  • outdir (Path) – Directory where to save the results.

  • lx (float, optional) – Length of slab the x-direction, by default 1.0

  • ly (float, optional) – Length of slab the x-direction, by default 0.5

  • lz (float, optional) – Length of slab the z-direction, by default 0.01

  • bx (float, optional) – Thickness of bath the x-direction, by default 0.0

  • by (float, optional) – Thickness of bath the x-direction, by default 0.0

  • bz (float, optional) – Thickness of bath the z-direction, by default 0.1

  • dx (float, optional) – Element size, by default 0.001

  • verbose (bool, optional) – If True print information from gmsh, by default False

  • order (int, optional) – Order of the mesh elements. With order higher than one the elements are curved to follow the boundaries, by default 1

  • comm (MPI.Comm, optional) – MPI communicator, by default MPI.COMM_WORLD

  • ghost_mode (dolfinx.mesh.GhostMode, optional) – Ghost mode for the dolfinx mesh, by default dolfinx.mesh.GhostMode.none

  • io_backend (str, optional) – io4dolfinx backend used to write the geometry, “h5py” (geometry.h5) or “adios2” (geometry.bp), by default “h5py”

  • unit (str | None, optional) – Unit of the coordinates, one of “m”, “cm” or “mm”, which the geometry file records, by default None: no unit is recorded, and geox check reports that

Returns:

A Geometry with the mesh, markers, markers functions and fibers.

Return type:

cardiac_geometries.geometry.Geometry

cardiac_geometries.mesh.ukb(outdir: str | ~pathlib.Path, mode: int = -1, std: float = 1.5, case: str = 'ED', char_length_max: float = 5.0, char_length_min: float = 5.0, fiber_angle_endo: float = 60, fiber_angle_epi: float = -60, create_fibers: bool = True, fiber_space: str = 'P_1', clipped: bool = False, use_burns: bool = False, burns_path: ~pathlib.Path | None = None, refine: int = 0, order: int = 1, comm: ~mpi4py.MPI.Comm = <mpi4py.MPI.Intracomm object>, ghost_mode: ~dolfinx.cpp.mesh.GhostMode = GhostMode.none, geometry: str = 'biv', fiber_method: str | None = None, io_backend: str = 'h5py', aha: bool = False, rv_regions: bool = False, rv_septum_fraction: float | None = None, reuse_mesh: bool = False, score: ~typing.Sequence[float] | None = None) → Geometry[source]#

Create a mesh from the UK-Biobank atlas using the ukb-atlas package.

Parameters:
  • outdir (str | Path) – Directory where to save the results.

  • mode (int, optional) – Mode for the UKB mesh, by default -1

  • std (float, optional) – Standard deviation for the UKB mesh, by default 1.5

  • case (str, optional) – Case for the UKB mesh (either “ED” or “ES”), by default “ED”

  • char_length_max (float, optional) – Maximum characteristic length of the mesh, by default 2.0

  • char_length_min (float, optional) – Minimum characteristic length of the mesh, by default 2.0

  • fiber_angle_endo (float, optional) – Fiber angle for the endocardium, by default 60

  • fiber_angle_epi (float, optional) – Fiber angle for the epicardium, by default -60

  • create_fibers (bool, optional) – If True create rule-based fibers, by default True

  • fiber_space (str, optional) – Function space for fibers of the form family_degree, by default “P_1”

  • clipped (bool, optional) – If True create a clipped mesh, by default False

  • use_burns (bool) – If true, use the atlas from Richard Burns to generate the surfaces. This will override the all parameter and use the burns atlas instead.

  • burns_path (Path | None) – Path to the burns atlas file. This will be a .mat file which will be loaded using scipy.io.loadmat. This needs to be specified if use_burns.

  • refine (int, optional) – Number of times to refine the surfaces of the atlas before meshing, placing the new nodes on smooth surfaces through the nodes of the atlas. This makes meshes of higher order more accurate, by default 0

  • order (int, optional) – Order of the mesh elements. With order higher than one the elements are curved to follow the boundaries, by default 1

  • comm (MPI.Comm, optional) – MPI communicator, by default MPI.COMM_WORLD

  • ghost_mode (dolfinx.mesh.GhostMode, optional) – Ghost mode for the dolfinx mesh, by default dolfinx.mesh.GhostMode.none

  • geometry (str, optional) – Which geometry to create: biventricular (“biv”) or LV only (“lv”), with open valves, or with the valves closed by caps (“biv-closed”, “lv-closed”). The closed geometries also mesh the cavities, which are marked as “LV_CAVITY” and “RV_CAVITY” in the cell tags, while the myocardium is marked as “Wall”. Fibers are only created in the wall. By default “biv”.

  • fiber_method (str | None, optional) – Rule-based method for the fibers: “doste” for the method of Doste et al. (2019), which handles the outflow tracts, or “ldrb” for the method of Bayer et al. (2012). With “doste”, fiber_angle_endo and fiber_angle_epi are the angles in the LV, while the RV and outflow tracts get the angles from the paper. By default “doste”, or “ldrb” for clipped meshes, which have no outflow tracts.

  • io_backend (str, optional) – io4dolfinx backend used to write the geometry, “h5py” (geometry.h5) or “adios2” (geometry.bp), by default “h5py”

  • aha (bool, optional) – If True, the cell tags are the 17 AHA segments of the LV, the RV free wall (“RV”) and the LV above the mitral plane (“LVOT”), see cardiac_geometries.aha.biv_aha(). Only for the “biv” geometry (not clipped), and it needs ukb-atlas >= 2.2 for the landmarks. By default False

  • rv_regions (bool, optional) – If True (with aha), the RV is divided into the 15 regions of Zhong et al. (2012) (tags 18-32) and the septum is split between the LV and the RV by a transventricular Laplace solution; the LV above the mitral plane is 33. See cardiac_geometries.aha.biv_regions(). By default False

  • rv_septum_fraction (float | None, optional) – With rv_regions, the share of the septum, in the transventricular coordinate from the RV side, that belongs to the RV, in [0, 1]: 0 gives the whole septum to the LV, 1 to the RV, 0.5 splits it at the middle (Cobiveco) and 1/3 approximates Doste et al. (2019). Only allowed with rv_regions. By default None, meaning 0.5

  • reuse_mesh (bool, optional) – If True, do not run ukb-atlas but read the mesh (and the landmarks) that an earlier call wrote to outdir. The earlier call’s info.json must have the same mode, std, case, clipped, char_length_max, char_length_min, refine, order, geometry, use_burns and score, otherwise a ValueError is raised; a missing file raises a FileNotFoundError. The fiber and region arguments may differ. By default False (always make a new mesh)

  • score (Sequence[float] | None, optional) – PCA scores of the shape, in standard deviations, one per mode from mode 0 (passed to ukb-atlas as --score). When given they replace mode and std, so shapes that combine several modes can be made. By default None

Returns:

A Geometry with the mesh, markers, markers functions and fibers.

Return type:

cardiac_geometries.geometry.Geometry

Notes

The stages are timed with the dolfinx timers in UKB_TIMERS: meshing with ukb-atlas, reading the mesh, the regions (only with aha), the fibers (which contain fenicsx-ldrb’s own timers) and saving every file written after the fibers.

class cardiac_geometries.utils.BaseData(centroid, vector, normal)[source]#
centroid: ndarray[tuple[Any, ...], dtype[float64]]#

Alias for field number 0

count(value, /)#

Return number of occurrences of value.

index(value, start=0, stop=9223372036854775807, /)#

Return first index of value.

Raises ValueError if the value is not present.

normal: ndarray[tuple[Any, ...], dtype[float64]]#

Alias for field number 2

vector: ndarray[tuple[Any, ...], dtype[float64]]#

Alias for field number 1

class cardiac_geometries.utils.GMshGeometry(mesh, cfun, ffun, efun, vfun, markers)[source]#
cfun: MeshTags | None#

Alias for field number 1

count(value, /)#

Return number of occurrences of value.

efun: MeshTags | None#

Alias for field number 3

ffun: MeshTags | None#

Alias for field number 2

index(value, start=0, stop=9223372036854775807, /)#

Return first index of value.

Raises ValueError if the value is not present.

markers: dict[str, tuple[int, int]]#

Alias for field number 5

mesh: Mesh#

Alias for field number 0

vfun: MeshTags | None#

Alias for field number 4

cardiac_geometries.utils.array2element(arr: ndarray) → _ElementBase[source]#

The element that element2array() wrote as arr. An array of four entries, written before the value shape was recorded, is a 3-vector.

cardiac_geometries.utils.compute_base_data(mesh: Mesh, facet_tags: MeshTags, marker) → BaseData[source]#

Compute the centroid, vector and normal of the base

Parameters:
Returns:

NamedTuple containing the centroid, vector and normal of the base

Return type:

BaseData

cardiac_geometries.utils.element2array(el: _ElementBase) → ndarray[source]#

The element el as an array: its family, cell type, degree and whether it is discontinuous, then the rank of its value shape and the shape’s extents (0 for a scalar, 1, 3 for a 3-vector). array2element() reads it back.

cardiac_geometries.utils.extract_submesh(mesh: Mesh, cfun: MeshTags, ffun: MeshTags, cell_markers: Iterable[int]) → tuple[Mesh, MeshTags, ndarray[tuple[Any, ...], dtype[int32]]][source]#

Create a submesh of the cells tagged with any of cell_markers.

Returns the submesh, the facet tags of ffun on the submesh, and the parent cell of each (owned and ghost) cell of the submesh.

cardiac_geometries.utils.json_serial(obj)[source]#

default= of json.dump: numpy integers, floats and bools stay numbers, arrays become lists, and anything else is written as its string.

cardiac_geometries.utils.parse_element(space_string: str, mesh: Mesh, dim: int, discontinuous: bool = False) → _ElementBase[source]#

Parse a string representation of a basix element family

cardiac_geometries.utils.rotate_geometry_and_fields(mesh: Mesh, ffun: MeshTags, base_marker: int, target_normal: Sequence[float] = (1.0, 0.0, 0.0), fields: Sequence[Function] | None = None) → tuple[Mesh, ndarray, list[Function]][source]#

Rotates the mesh and vector fields so that the base normal points in the +x direction.

cardiac_geometries.utils.save_mesh_to_xdmf(comm: Comm, fname: Path, mesh: Mesh, ct: MeshTags | None, ft: MeshTags | None, et: MeshTags | None, vt: MeshTags | None)[source]#

Write mesh and its tags to the XDMF file fname, as read_mesh() reads them.

The mesh is written as Mesh and the tags as Cell tags, Facet tags, Edge tags and Vertex tags, whatever their own names, which are kept: tags made with dolfinx’s default name all share it, and would overwrite each other’s data in the file.

cardiac_geometries.utils.space_from_string(space_string: str, mesh: Mesh, dim: int, discontinuous: bool = False) → FunctionSpace[source]#

Constructed a finite elements space from a string representation of the space

Parameters:
  • space_string (str) – A string on the form {family}_{degree} which determines the space. Example ‘Lagrange_1’.

  • mesh (df.Mesh) – The mesh

  • dim (int) – 1 for scalar space, 3 for vector space.

  • discontinuous (bool) – If true force element to be discontinuous, by default False

cardiac_geometries.utils.tag_dimensions(tdim: int) → list[tuple[str, str, int]][source]#

The tags of a mesh of topological dimension tdim and the dimension of their entities. A mesh of dimension 2 has no edge tags: its edges are its facets.

cardiac_geometries.utils.transfer_to_parent(u_sub: Function, V: FunctionSpace, parent_cells: ndarray[tuple[Any, ...], dtype[int32]]) → Function[source]#

Copy a function on a submesh into V on the parent mesh, cell by cell.

V must use the same element as the space of u_sub, and parent_cells is the parent cell of each cell of the submesh (see extract_submesh). The degrees of freedom of the parent outside the submesh are zero. The local dofs are copied as is, which is exact for elements whose dofs do not need permuting between the meshes, such as Lagrange of degree at most 2 and quadrature elements.

class cardiac_geometries.fibers.Microstructure(f0, s0, n0)[source]#
count(value, /)#

Return number of occurrences of value.

f0: Function#

Alias for field number 0

index(value, start=0, stop=9223372036854775807, /)#

Return first index of value.

Raises ValueError if the value is not present.

n0: Function#

Alias for field number 2

s0: Function#

Alias for field number 1

cardiac_geometries.fibers.lv_ellipsoid.compute_system(t_func: Function, r_short_endo=0.025, r_short_epi=0.035, r_long_endo=0.09, r_long_epi=0.097, alpha_endo: float = -60, alpha_epi: float = 60, long_axis: int = 0, **kwargs) → Microstructure[source]#

Compute the microstructure for the given time function.

Parameters:
  • t_func (dolfinx.fem.Function) – Solution of the Laplace equation

  • r_short_endo (float, optional) – Short radius at the endocardium, by default 0.025

  • r_short_epi (float, optional) – Short radius at the epicardium, by default 0.035

  • r_long_endo (float, optional) – Long radius at the endocardium, by default 0.09

  • r_long_epi (float, optional) – Long radius at the epicardium, by default 0.097

  • alpha_endo (float, optional) – Angle at the endocardium, by default -60

  • alpha_epi (float, optional) – Angle at the epicardium, by default 60

  • long_axis (int, optional) – Long axis, by default 0 (x-axis)

Returns:

The microstructure

Return type:

utils.Microstructure

cardiac_geometries.fibers.lv_ellipsoid.create_microstructure(mesh, ffun, markers, function_space='P_1', r_short_endo=0.025, r_short_epi=0.035, r_long_endo=0.09, r_long_epi=0.097, alpha_endo: float = -60, alpha_epi: float = 60, long_axis: int = 0, outdir: str | Path | None = None, transmural: str = 'laplace', **kwargs)[source]#

Create the microstructure of an LV ellipsoid.

transmural selects the transmural coordinate the fiber angle varies linearly in: "laplace", the solution of a Laplace problem between ENDO and EPI, or "analytic", the coordinate of the ellipsoid itself (see transmural_coordinate), which is the one of the benchmark of Land et al. (2015). Use "analytic" on the meridian of an axisymmetric geometry, where a planar Laplace problem is not the axisymmetric one.

cardiac_geometries.fibers.lv_ellipsoid.mu_theta(x: ndarray, y: ndarray, z: ndarray, rs: ndarray, rl: ndarray, long_axis: int = 0) → tuple[ndarray, ndarray, list[int]][source]#

Get the angles mu and theta from the coordinates x, y, z given the long axis.

Parameters:
  • x (np.ndarray) – The x-coordinates

  • y (np.ndarray) – The y-coordinates

  • z (np.ndarray) – The z-coordinates

  • rs (np.ndarray) – The short radius

  • rl (np.ndarray) – The long radius

  • long_axis (int, optional) – The long axis, by default 0 (x-axis)

Returns:

The angles mu and theta and the permutation of the axes

Return type:

tuple[np.ndarray, np.ndarray, list[int]]

Raises:

ValueError – If the long axis is not 0, 1 or 2

cardiac_geometries.fibers.lv_ellipsoid.transmural_coordinate(V: FunctionSpace, r_short_endo=0.025, r_short_epi=0.035, r_long_endo=0.09, r_long_epi=0.097, long_axis: int = 0, num_iterations: int = 60) → Function[source]#

The transmural coordinate t in [0, 1] of the ellipsoid, as defined in the benchmark of Land et al. (2015): the point lies on the ellipsoid with radii r_short(t) and r_long(t), interpolated linearly between the endocardium (t = 0) and the epicardium (t = 1).

The root is found by bisection, as (r^2 - x_long^2) / r_short(t)^2 + x_long^2 / r_long(t)^2 - 1 decreases with t. Points just outside the wall get t = 0 or t = 1.

Parameters:
  • V (dolfinx.fem.FunctionSpace) – Scalar function space of the transmural coordinate

  • r_short_endo (float, optional) – Short radius at the endocardium, by default 0.025

  • r_short_epi (float, optional) – Short radius at the epicardium, by default 0.035

  • r_long_endo (float, optional) – Long radius at the endocardium, by default 0.09

  • r_long_epi (float, optional) – Long radius at the epicardium, by default 0.097

  • long_axis (int, optional) – Long axis, by default 0 (x-axis)

  • num_iterations (int, optional) – Number of bisection steps, by default 60

Returns:

The transmural coordinate

Return type:

dolfinx.fem.Function

cardiac_geometries.fibers.slab.compute_system(t_func: Function, alpha_endo: float = -60, alpha_epi: float = 60, endo_epi_axis='y') → Microstructure[source]#

Compute ldrb system for slab, assuming linear angle between endo and epi

Parameters:
  • t_func (dolfin.Function) – Solution to laplace equation with 0 on endo and 1 on epi

  • alpha_endo (float, optional) – Angle on endocardium, by default -60

  • alpha_epi (float, optional) – Angle on epicardium, by default 60

Returns:

Tuple with fiber, sheet and sheet normal

Return type:

Microstructure

cardiac_geometries.fibers.slab.create_microstructure(mesh: Mesh, ffun: MeshTags, markers: dict[str, tuple[int, int]], alpha_endo: float, alpha_epi: float, function_space: str = 'P_1', outdir: str | Path | None = None, **kwargs: dict) → Microstructure[source]#

Generate microstructure for slab using LDRB algorithm

Parameters:
  • mesh (dolfinx.mesh.Mesh) – A slab mesh

  • ffun (dolfinx.mesh.MeshTags) – Facet function defining the boundaries

  • markers (Dict[str, Tuple[int, int]]) – Markers with keys Y0 and Y1 representing the endo and epi planes respectively. The values should be a tuple whose first value is the value of the marker (corresponding to ffun) and the second value is the dimension

  • alpha_endo (float) – Angle on the endocardium

  • alpha_epi (float) – Angle on the epicardium

  • function_space (str) – Function space to interpolate the fibers, by default P_1

  • outdir (Optional[Union[str, Path]], optional) – Output directory to store the results, by default None. If no output directory is specified the results will not be stored, but only returned.

Returns:

Tuple with fiber, sheet and sheet normal

Return type:

Microstructure

The metadata of a geometry file, stored inside the file (format 1).

A geometry file is an io4dolfinx file holding the mesh, its tags, the fibres and the fields. Since format 1 it also holds one attribute group, GROUP, with one attribute, KEY: a JSON document whose top-level keys are format, unit, markers, microstructure, additional_data and info. The document is stored as its UTF-8 bytes in a uint8 array, since that is the form both the h5py and the adios2 backends store (adios2 refuses a string attribute).

A file without the group is format 0: its metadata, if any, sits in JSON files beside it.

cardiac_geometries.metadata.FORMAT: int = 1#

The version of the file standard that this version of cardiac-geometriesx writes, and the highest it reads.

exception cardiac_geometries.metadata.FormatError[source]#

A geometry file of a format that this version of cardiac-geometriesx cannot read.

add_note()#

Exception.add_note(note) – add a note to the exception

with_traceback()#

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

cardiac_geometries.metadata.GROUP = 'cardiac_geometries'#

The attribute group holding the metadata.

cardiac_geometries.metadata.KEY = 'metadata'#

The attribute holding the metadata in GROUP.

cardiac_geometries.metadata.UNITS = ('m', 'cm', 'mm')#

The units a geometry’s coordinates may be in.

cardiac_geometries.metadata.decode(array: ndarray) → dict[str, Any][source]#

The JSON document stored by encode() in array.

cardiac_geometries.metadata.encode(metadata: dict[str, Any]) → ndarray[source]#

The JSON document metadata as a uint8 array of its UTF-8 bytes.

cardiac_geometries.metadata.read_metadata(path: Path, comm: Comm, backend: str) → dict[str, Any] | None[source]#

The metadata of the geometry file path, or None if it has none (format 0).

Every rank must call it.

cardiac_geometries.metadata.write_metadata(path: Path, comm: Comm, metadata: dict[str, Any], backend: str) → None[source]#

Write metadata into the geometry file path, replacing any metadata it holds.

Every rank must call it. Rank 0’s document is written, so that every rank writes the same bytes.

The names that the geometry standard reserves, and what they mean.

cardiac_geometries.standard.CELLTYPE_SPACES: dict[str, tuple[str, int]] = {'DG_0': ('DG', 0), 'P_1': ('P', 1)}#

each is one of the elements of celltype in RESERVED_FIELDS.

Type:

The spaces geox celltype computes the field celltype in, by their CLI name

cardiac_geometries.standard.CELLTYPE_VALUES: dict[str, int] = {'endo': 0, 'epi': 1, 'mid': 2}#

The legend of the field celltype.

cardiac_geometries.standard.ELEMENTS_KEY = 'elements'#

The key of RESERVED_FIELDS that is about the field’s element, not its info. Each element is (family, degree, discontinuous) of a scalar field; ("P", 0, True) is DG0.

cardiac_geometries.standard.FACET_NAMES: tuple[str, ...] = ('LV_ENDO', 'RV_ENDO', 'EPI', 'BASE', 'MV', 'AV', 'TV', 'PV')#

The facet names of the standard.

cardiac_geometries.standard.FIBER_NAMES: tuple[str, ...] = ('f0', 's0', 'n0')#

fibre, sheet and sheet-normal directions.

Type:

The names of the fibre fields

cardiac_geometries.standard.FIELD_INFO_KEYS: tuple[str, ...] = ('unit', 'values', 'description')#

What a field says about itself; a field needs at least one of them (rule C8).

cardiac_geometries.standard.NON_MYOCARDIUM: tuple[str, ...] = ('MITRAL_VALVE', 'AORTIC_VALVE', 'TRICUSPID_VALVE', 'PULMONARY_VALVE', 'Bath')#

The cell names of what is not myocardium.

cardiac_geometries.standard.OLD_FACET_NAMES: dict[str, str] = {'ENDO': 'LV_ENDO', 'ENDO_LV': 'LV_ENDO', 'ENDO_RV': 'RV_ENDO', 'LV': 'LV_ENDO', 'RV': 'RV_ENDO'}#

Old facet names and the standard name each stands for. They apply to facet markers only, since the AHA RV is a cell marker.

cardiac_geometries.standard.RESERVED_FIELDS: dict[str, dict] = {'activation_time': {'elements': {('P', 1, False)}, 'unit': 'ms'}, 'celltype': {'elements': {('P', 0, True), ('P', 1, False)}, 'values': {'endo': 0, 'epi': 1, 'mid': 2}}}#

What a reserved field must declare in its info.

cardiac_geometries.standard.VALVE_PLANES: tuple[str, ...] = ('MV', 'AV', 'TV', 'PV')#

The facet names of the valve planes.

cardiac_geometries.standard.VALVE_REGIONS: tuple[str, ...] = ('MITRAL_VALVE', 'AORTIC_VALVE', 'TRICUSPID_VALVE', 'PULMONARY_VALVE')#

The cell names of the valve regions.

Check a geometry against the standard: the rules C1 to C10 of geox check.

class cardiac_geometries.check.Problem(code: str, severity: Literal['error', 'warning'], message: str)[source]#

A way in which a geometry departs from the standard.

code is the rule it breaks, "C1" to "C10" (see the geometry-file docs), and an "error" makes geox check exit with 1, a "warning" does not.

cardiac_geometries.check.check(geometry: Geometry) → list[Problem][source]#

The problems of geometry: the errors first, then the warnings, each in code order.

Every count is global and every set of tags is the union over the ranks, so every rank returns the same list. Every rank must call it.

cardiac_geometries.check.describe_data(data: object) → str[source]#

The element of a Function as DG0 or P1, whatever its value shape, and mesh tags for a MeshTags.

cardiac_geometries.check.has_errors(problems: list[Problem]) → bool[source]#

Whether any of problems is an error, which makes geox check fail.

cardiac_geometries.check.max_dot(comm: Comm, a1: ndarray, a2: ndarray) → float[source]#

The global largest |a1 . a2| over the rows.

cardiac_geometries.check.max_norm_error(comm: Comm, a: ndarray) → float[source]#

The global largest | |a| - 1 | over the rows of a.

What a geometry file holds: summarize() measures it, format_summary() prints it.

cardiac_geometries.summary.format_summary(summary: dict[str, Any]) → str[source]#

The text of summary, in the layout of the spec.

cardiac_geometries.summary.summarize(geometry: Geometry, path: Path | None = None) → dict[str, Any][source]#

Measure geometry. Every count is global; every rank must call it.

Convert an existing geometry into one file of format 1, through a mapping (geox convert).

cardiac_geometries.convert.convert(source: ~pathlib.Path, out: ~pathlib.Path, mapping: ~pathlib.Path | ~collections.abc.Mapping[str, ~typing.Any], comm: ~mpi4py.MPI.Comm = <mpi4py.MPI.Intracomm object>) → Geometry[source]#

Convert the geometry source, a file of any format or an old folder, into the file out of format 1, through mapping (a TOML file or the dict it reads as).

The result is checked before anything is written; any error raises ValueError.

cardiac_geometries.convert.function_names(path: Path, backend: str) → list[str][source]#

The names of the functions the io4dolfinx file path holds. io4dolfinx’s adios2 backend cannot list them, so there they are the names that have both <name>_values and <name>_XDofmap variables.

cardiac_geometries.convert.load_mapping(path: Path) → dict[str, Any][source]#

Read a mapping from the TOML file path. The tags of [cells] become integers.

cardiac_geometries.convert.load_volume_data(path: Path) → dict[str, Any][source]#

Read the TOML file of geox from-volume --data as the keyword arguments of cardiac_geometries.mesh.from_volume(): cell_tags, cell_names (the tags of [cells] as integers, as in a mapping of convert()), fibers and fields.

cardiac_geometries.convert.read_field(path: Path, mesh: Mesh, name: str, source_name: str, element: str) → Function[source]#

Read the field source_name of the io4dolfinx file path as name on element.

Raises ValueError, naming name, if the file or the field is missing, or the field is of another size than the mesh and the element: the number of values and of cells are compared before anything is read.

cardiac_geometries.convert.recorded_sizes(path: Path, name: str, backend: str, field: str = '') → tuple[int, int][source]#

The number of values and of cells that the io4dolfinx file path records for the function name.

adios2 records the global shapes of the variables <name>_values and <name>_XDofmap (the cells plus one), h5py the datasets mesh/functions/<name>/<time>/array and dofmap_offsets (again the cells plus one). field is the name in the mapping, for messages.

Raises ValueError if the function is not in the file, or if the file’s layout is not the one this version reads, so the size cannot be verified.

Transmural cell types by Laplace solves: endo 0, epi 1, mid 2 (geox celltype).

The algorithm is that of beat’s expand_layer_biv: a Laplace solution that is 0 on the endocardium and 1 on the epicardium, thresholded; in a BiV the smaller of the solutions from the LV and from the RV endocardium. The result is stored as the reserved field celltype.

cardiac_geometries.celltype.add_celltype(geometry: Geometry, endo: float = 0.3, epi: float = 0.3, space: str = 'P_1') → None[source]#

Compute the cell type (compute_celltype()) and store it as celltype, replacing, with a warning, one that is there.

cardiac_geometries.celltype.compute_celltype(geometry: Geometry, endo: float = 0.3, epi: float = 0.3, space: str = 'P_1') → Function[source]#

The cell type of every node ("P_1") or cell ("DG_0") of geometry.

A value t of the Laplace solution (0 on the endocardium, 1 on the epicardium; the smaller of the LV’s and the RV’s in a BiV) is endo (0) up to endo, epi (1) from 1 - epi and mid (2) between. Collective: every rank must call it.

Raises:

ValueError – If space is not "P_1" or "DG_0", or the geometry has no lv and epi markers (transform_markers()).

Export a geometry as VTU files, which ParaView reads without extra readers.

cardiac_geometries.export.export(geometry: Geometry, outdir: Path) → list[Path][source]#

Write geometry into outdir as VTU files for ParaView, and return the files written.

  • volume.vtu: the mesh on its geometry’s scalar Lagrange space. Its point data is every function on exactly that space, and its cell data the Cell tags (0 where untagged) and every DG0 function.

  • facets.vtu: the tagged facets, with Facet tags as cell data (only with facet tags).

  • <name>.vtu: each other Lagrange or DG function, on the grid of its own space.

  • <name>_points.vtu: each quadrature function, a point cloud at the quadrature points.

  • markers.json: the legend of the tags.

MeshTags in additional_data are not exported, only Functions.

Raises:
  • ImportError – Without pyvista.

  • RuntimeError – On more than one rank.