BiV Ellipsoid

BiV Ellipsoid#

In this example we will simulate an idealized bi-ventricular geometry. For this we will use cardiac-geometries to generate an idealized LV ellipsoid.

First lets do some imports

from pathlib import Path
from mpi4py import MPI
import dolfinx
from dolfinx import log
import ldrb
import cardiac_geometries
import cardiac_geometries.geometry
import pulse

and lets turn on logging so that we can see more info from dolfinx

log.set_log_level(log.LogLevel.INFO)

Now we create the geometry using cardiac-geometries and save it to a folder called biv_ellipsoid. We will also create fiber orientations using the Laplace-Dirichlet Rule based (LDRB) algorithm, using the library fenicsx-ldrb package

outdir = Path("biv_ellipsoid")
outdir.mkdir(parents=True, exist_ok=True)
geodir = outdir / "geometry"
if not geodir.exists():
    geo = cardiac_geometries.mesh.biv_ellipsoid(outdir=geodir)
    system = ldrb.dolfinx_ldrb(mesh=geo.mesh, ffun=geo.ffun, markers=geo.markers, alpha_endo_lv=60, alpha_epi_lv=-60, beta_endo_lv=0, beta_epi_lv=0, fiber_space="P_2")
    cardiac_geometries.fibers.utils.save_microstructure(mesh=geo.mesh, functions=[system.f0, system.s0, system.n0], outdir=geodir)
2025-06-16 08:21:51 [debug    ] Convert file biv_ellipsoid/geometry/biv_ellipsoid.msh to dolfin
Info    : Reading 'biv_ellipsoid/geometry/biv_ellipsoid.msh'...
Info    : 43 entities
Info    : 664 nodes
Info    : 3293 elements
Info    : Done reading 'biv_ellipsoid/geometry/biv_ellipsoid.msh'
[2025-06-16 08:21:51.113] [info] Extract basic topology: 8668->8668
[2025-06-16 08:21:51.113] [info] Build local dual graph
[2025-06-16 08:21:51.113] [info] Build local part of mesh dual graph (mixed)
[2025-06-16 08:21:51.115] [info] GPS pseudo-diameter:(46) 1652-1941
[2025-06-16 08:21:51.115] [info] Create topology (single cell type)
[2025-06-16 08:21:51.115] [info] Create topology (generalised)
[2025-06-16 08:21:51.115] [info] Computing communication graph edges (using NBX algorithm). Number of input edges: 1
[2025-06-16 08:21:51.115] [info] Finished graph edge discovery using NBX algorithm. Number of discovered edges 1
[2025-06-16 08:21:51.115] [info] Compute ghost indices
[2025-06-16 08:21:51.115] [info] Computing communication graph edges (using PCX algorithm). Number of input edges: 0
[2025-06-16 08:21:51.115] [info] Finished graph edge discovery using PCX algorithm. Number of discovered edges 0
[2025-06-16 08:21:51.116] [info] Computing communication graph edges (using NBX algorithm). Number of input edges: 0
[2025-06-16 08:21:51.116] [info] Finished graph edge discovery using NBX algorithm. Number of discovered edges 0
[2025-06-16 08:21:51.116] [info] Computing communication graph edges (using NBX algorithm). Number of input edges: 0
[2025-06-16 08:21:51.116] [info] Finished graph edge discovery using NBX algorithm. Number of discovered edges 0
[2025-06-16 08:21:51.116] [info] Number of neighbourhood source ranks in distribute_to_postoffice: 0
[2025-06-16 08:21:51.116] [info] Computing communication graph edges (using NBX algorithm). Number of input edges: 0
[2025-06-16 08:21:51.116] [info] Finished graph edge discovery using NBX algorithm. Number of discovered edges 0
[2025-06-16 08:21:51.116] [info] Neighbourhood destination ranks from post office in distribute_data (rank, num dests, num dests/mpi_size): 0, 0, 0
[2025-06-16 08:21:51.116] [info] Checking required entities per dimension
[2025-06-16 08:21:51.116] [info] Cell type: 0 dofmap: 2167x4
[2025-06-16 08:21:51.116] [info] Global index computation
[2025-06-16 08:21:51.116] [info] Got 1 index_maps
[2025-06-16 08:21:51.116] [info] Get global indices
[2025-06-16 08:21:51.116] [info] XDMF distribute entity data
[2025-06-16 08:21:51.117] [info] Computing communication graph edges (using NBX algorithm). Number of input edges: 1
[2025-06-16 08:21:51.117] [info] Finished graph edge discovery using NBX algorithm. Number of discovered edges 1
[2025-06-16 08:21:51.117] [info] Computing communication graph edges (using NBX algorithm). Number of input edges: 1
[2025-06-16 08:21:51.117] [info] Finished graph edge discovery using NBX algorithm. Number of discovered edges 1
[2025-06-16 08:21:51.117] [info] XDMF build map
[2025-06-16 08:21:51.118] [info] Requesting connectivity (3, 0) - (0, 0)
[2025-06-16 08:21:51.118] [info] Building MeshTags object from tagged entities (defined by vertices).
[2025-06-16 08:21:51.118] [info] Build list of mesh entity indices from the entity vertices.
[2025-06-16 08:21:51.119] [info] XDMF distribute entity data
[2025-06-16 08:21:51.119] [info] Computing communication graph edges (using NBX algorithm). Number of input edges: 1
[2025-06-16 08:21:51.119] [info] Finished graph edge discovery using NBX algorithm. Number of discovered edges 1
[2025-06-16 08:21:51.119] [info] Computing communication graph edges (using NBX algorithm). Number of input edges: 1
[2025-06-16 08:21:51.119] [info] Finished graph edge discovery using NBX algorithm. Number of discovered edges 1
[2025-06-16 08:21:51.119] [info] XDMF build map
[2025-06-16 08:21:51.120] [info] Computing mesh entities of dimension 2
[2025-06-16 08:21:51.121] [info] Computing communication graph edges (using NBX algorithm). Number of input edges: 0
[2025-06-16 08:21:51.121] [info] Finished graph edge discovery using NBX algorithm. Number of discovered edges 0
[2025-06-16 08:21:51.121] [info] Requesting connectivity (2, 0) - (3, 0)
[2025-06-16 08:21:51.121] [info] Computing mesh connectivity 2-3 from transpose.
[2025-06-16 08:21:51.121] [info] Building MeshTags object from tagged entities (defined by vertices).
[2025-06-16 08:21:51.121] [info] Build list of mesh entity indices from the entity vertices.
[2025-06-16 08:21:51.124] [info] Opened HDF5 file with id "72057594037927936"
[2025-06-16 08:21:51.124] [info] Adding mesh to node "/Xdmf/Domain"
[2025-06-16 08:21:51.124] [info] Adding topology data to node /Xdmf/Domain/Grid
[2025-06-16 08:21:51.124] [info] Adding geometry data to node "/Xdmf/Domain/Grid"
[2025-06-16 08:21:51.124] [info] XDMF: add meshtags (Cell tags)
[2025-06-16 08:21:51.124] [info] Adding topology data to node /Xdmf/Domain/Grid
[2025-06-16 08:21:51.124] [info] Requesting connectivity (2, 0) - (3, 0)
[2025-06-16 08:21:51.124] [info] XDMF: add meshtags (Facet tags)
[2025-06-16 08:21:51.124] [info] Adding topology data to node /Xdmf/Domain/Grid
[2025-06-16 08:21:51.125] [info] Computing mesh entities of dimension 1
[2025-06-16 08:21:51.126] [info] Computing communication graph edges (using NBX algorithm). Number of input edges: 0
[2025-06-16 08:21:51.126] [info] Finished graph edge discovery using NBX algorithm. Number of discovered edges 0
[2025-06-16 08:21:51.126] [info] Requesting connectivity (1, 0) - (3, 0)
[2025-06-16 08:21:51.126] [info] Computing mesh connectivity 1-3 from transpose.
[2025-06-16 08:21:51.126] [info] XDMF: add meshtags (Edge tags)
[2025-06-16 08:21:51.126] [info] Adding topology data to node /Xdmf/Domain/Grid
[2025-06-16 08:21:51.127] [info] Requesting connectivity (0, 0) - (3, 0)
[2025-06-16 08:21:51.127] [info] Computing mesh connectivity 0-3 from transpose.
[2025-06-16 08:21:51.127] [info] XDMF: add meshtags (Vertex tags)
[2025-06-16 08:21:51.127] [info] Adding topology data to node /Xdmf/Domain/Grid
[2025-06-16 08:21:51.127] [info] Opened HDF5 file with id "72057594037927937"
[2025-06-16 08:21:51.127] [info] Read topology data "Mesh" at /Xdmf/Domain
[2025-06-16 08:21:51.128] [info] HDF5 Read data rate: 3759.5012198427758 MB/s
[2025-06-16 08:21:51.128] [info] IO permuting cells
[2025-06-16 08:21:51.128] [info] Read geometry data "Mesh" at /Xdmf/Domain
[2025-06-16 08:21:51.128] [info] HDF5 Read data rate: 1003.5896467031928 MB/s
[2025-06-16 08:21:51.130] [info] Using partitioner with 8668 cell data
[2025-06-16 08:21:51.130] [info] Compute partition of cells across ranks
[2025-06-16 08:21:51.130] [info] Building mesh dual graph
[2025-06-16 08:21:51.130] [info] Build local part of mesh dual graph (mixed)
[2025-06-16 08:21:51.131] [info] Build nonlocal part of mesh dual graph
[2025-06-16 08:21:51.131] [info] Graph edges (local: 7542, non-local: 0)
[2025-06-16 08:21:51.131] [info] Compute graph partition using PT-SCOTCH
[2025-06-16 08:21:51.131] [info] Computing communication graph edges (using NBX algorithm). Number of input edges: 1
[2025-06-16 08:21:51.131] [info] Finished graph edge discovery using NBX algorithm. Number of discovered edges 1
[2025-06-16 08:21:51.131] [info] Extract basic topology: 8668->8668
[2025-06-16 08:21:51.131] [info] Build local dual graph
[2025-06-16 08:21:51.131] [info] Build local part of mesh dual graph (mixed)
[2025-06-16 08:21:51.133] [info] GPS pseudo-diameter:(46) 2166-0
[2025-06-16 08:21:51.133] [info] Create topology (single cell type)
[2025-06-16 08:21:51.133] [info] Create topology (generalised)
[2025-06-16 08:21:51.133] [info] Computing communication graph edges (using NBX algorithm). Number of input edges: 1
[2025-06-16 08:21:51.133] [info] Finished graph edge discovery using NBX algorithm. Number of discovered edges 1
[2025-06-16 08:21:51.133] [info] Compute ghost indices
[2025-06-16 08:21:51.133] [info] Computing communication graph edges (using PCX algorithm). Number of input edges: 0
[2025-06-16 08:21:51.133] [info] Finished graph edge discovery using PCX algorithm. Number of discovered edges 0
[2025-06-16 08:21:51.134] [info] Computing communication graph edges (using NBX algorithm). Number of input edges: 0
[2025-06-16 08:21:51.134] [info] Finished graph edge discovery using NBX algorithm. Number of discovered edges 0
[2025-06-16 08:21:51.134] [info] Computing communication graph edges (using NBX algorithm). Number of input edges: 0
[2025-06-16 08:21:51.134] [info] Finished graph edge discovery using NBX algorithm. Number of discovered edges 0
[2025-06-16 08:21:51.134] [info] Number of neighbourhood source ranks in distribute_to_postoffice: 0
[2025-06-16 08:21:51.134] [info] Computing communication graph edges (using NBX algorithm). Number of input edges: 0
[2025-06-16 08:21:51.134] [info] Finished graph edge discovery using NBX algorithm. Number of discovered edges 0
[2025-06-16 08:21:51.134] [info] Neighbourhood destination ranks from post office in distribute_data (rank, num dests, num dests/mpi_size): 0, 0, 0
[2025-06-16 08:21:51.134] [info] Checking required entities per dimension
[2025-06-16 08:21:51.134] [info] Cell type: 0 dofmap: 2167x4
[2025-06-16 08:21:51.134] [info] Global index computation
[2025-06-16 08:21:51.134] [info] Got 1 index_maps
[2025-06-16 08:21:51.134] [info] Get global indices
[2025-06-16 08:21:51.134] [info] Requesting connectivity (3, 0) - (3, 0)
[2025-06-16 08:21:51.134] [info] XDMF read meshtags (Cell tags)
[2025-06-16 08:21:51.134] [info] Read topology data "Cell tags" at /Xdmf/Domain
[2025-06-16 08:21:51.134] [info] HDF5 Read data rate: 4520.764065454071 MB/s
[2025-06-16 08:21:51.134] [info] IO permuting cells
[2025-06-16 08:21:51.135] [info] HDF5 Read data rate: 1235.9903037216598 MB/s
[2025-06-16 08:21:51.135] [info] IO permuting cells
[2025-06-16 08:21:51.135] [info] XDMF distribute entity data
[2025-06-16 08:21:51.135] [info] Computing communication graph edges (using NBX algorithm). Number of input edges: 1
[2025-06-16 08:21:51.135] [info] Finished graph edge discovery using NBX algorithm. Number of discovered edges 1
[2025-06-16 08:21:51.135] [info] Computing communication graph edges (using NBX algorithm). Number of input edges: 1
[2025-06-16 08:21:51.135] [info] Finished graph edge discovery using NBX algorithm. Number of discovered edges 1
[2025-06-16 08:21:51.135] [info] XDMF build map
[2025-06-16 08:21:51.136] [info] XDMF create meshtags
[2025-06-16 08:21:51.136] [info] Building MeshTags object from tagged entities (defined by vertices).
[2025-06-16 08:21:51.136] [info] Build list of mesh entity indices from the entity vertices.
[2025-06-16 08:21:51.136] [info] Computing mesh entities of dimension 2
[2025-06-16 08:21:51.138] [info] Computing communication graph edges (using NBX algorithm). Number of input edges: 0
[2025-06-16 08:21:51.138] [info] Finished graph edge discovery using NBX algorithm. Number of discovered edges 0
[2025-06-16 08:21:51.138] [info] Requesting connectivity (2, 0) - (3, 0)
[2025-06-16 08:21:51.138] [info] Computing mesh connectivity 2-3 from transpose.
[2025-06-16 08:21:51.138] [info] XDMF read meshtags (Facet tags)
[2025-06-16 08:21:51.138] [info] Read topology data "Facet tags" at /Xdmf/Domain
[2025-06-16 08:21:51.138] [info] HDF5 Read data rate: 2219.995071058901 MB/s
[2025-06-16 08:21:51.138] [info] IO permuting cells
[2025-06-16 08:21:51.138] [info] HDF5 Read data rate: 722.8374257743541 MB/s
[2025-06-16 08:21:51.138] [info] IO permuting cells
[2025-06-16 08:21:51.138] [info] XDMF distribute entity data
[2025-06-16 08:21:51.138] [info] Computing communication graph edges (using NBX algorithm). Number of input edges: 1
[2025-06-16 08:21:51.138] [info] Finished graph edge discovery using NBX algorithm. Number of discovered edges 1
[2025-06-16 08:21:51.138] [info] Computing communication graph edges (using NBX algorithm). Number of input edges: 1
[2025-06-16 08:21:51.138] [info] Finished graph edge discovery using NBX algorithm. Number of discovered edges 1
[2025-06-16 08:21:51.138] [info] XDMF build map
[2025-06-16 08:21:51.139] [info] XDMF create meshtags
[2025-06-16 08:21:51.139] [info] Building MeshTags object from tagged entities (defined by vertices).
[2025-06-16 08:21:51.139] [info] Build list of mesh entity indices from the entity vertices.
[2025-06-16 08:21:51.140] [info] Computing mesh entities of dimension 1
[2025-06-16 08:21:51.141] [info] Computing communication graph edges (using NBX algorithm). Number of input edges: 0
[2025-06-16 08:21:51.141] [info] Finished graph edge discovery using NBX algorithm. Number of discovered edges 0
[2025-06-16 08:21:51.141] [info] Requesting connectivity (1, 0) - (3, 0)
[2025-06-16 08:21:51.141] [info] Computing mesh connectivity 1-3 from transpose.
[2025-06-16 08:21:51.141] [info] XDMF read meshtags (Edge tags)
[2025-06-16 08:21:51.141] [info] Read topology data "Edge tags" at /Xdmf/Domain
[2025-06-16 08:21:51.141] [info] HDF5 Read data rate: 0 MB/s
[2025-06-16 08:21:51.141] [info] IO permuting cells
[2025-06-16 08:21:51.141] [info] HDF5 Read data rate: 0 MB/s
[2025-06-16 08:21:51.141] [info] IO permuting cells
[2025-06-16 08:21:51.141] [info] XDMF distribute entity data
[2025-06-16 08:21:51.141] [info] Computing communication graph edges (using NBX algorithm). Number of input edges: 0
[2025-06-16 08:21:51.141] [info] Finished graph edge discovery using NBX algorithm. Number of discovered edges 0
[2025-06-16 08:21:51.141] [info] Computing communication graph edges (using NBX algorithm). Number of input edges: 1
[2025-06-16 08:21:51.141] [info] Finished graph edge discovery using NBX algorithm. Number of discovered edges 1
[2025-06-16 08:21:51.141] [info] XDMF build map
[2025-06-16 08:21:51.142] [info] XDMF create meshtags
[2025-06-16 08:21:51.142] [info] Building MeshTags object from tagged entities (defined by vertices).
[2025-06-16 08:21:51.142] [info] Build list of mesh entity indices from the entity vertices.
[2025-06-16 08:21:51.142] [info] Requesting connectivity (0, 0) - (3, 0)
[2025-06-16 08:21:51.142] [info] Computing mesh connectivity 0-3 from transpose.
[2025-06-16 08:21:51.142] [info] XDMF read meshtags (Vertex tags)
[2025-06-16 08:21:51.142] [info] Read topology data "Vertex tags" at /Xdmf/Domain
[2025-06-16 08:21:51.142] [info] HDF5 Read data rate: 0 MB/s
[2025-06-16 08:21:51.142] [info] IO permuting cells
[2025-06-16 08:21:51.142] [info] HDF5 Read data rate: 0 MB/s
[2025-06-16 08:21:51.142] [info] IO permuting cells
[2025-06-16 08:21:51.142] [info] XDMF distribute entity data
[2025-06-16 08:21:51.142] [info] Computing communication graph edges (using NBX algorithm). Number of input edges: 0
[2025-06-16 08:21:51.142] [info] Finished graph edge discovery using NBX algorithm. Number of discovered edges 0
[2025-06-16 08:21:51.142] [info] Computing communication graph edges (using NBX algorithm). Number of input edges: 1
[2025-06-16 08:21:51.142] [info] Finished graph edge discovery using NBX algorithm. Number of discovered edges 1
[2025-06-16 08:21:51.142] [info] XDMF build map
[2025-06-16 08:21:51.143] [info] XDMF create meshtags
[2025-06-16 08:21:51.143] [info] Building MeshTags object from tagged entities (defined by vertices).
[2025-06-16 08:21:51.143] [info] Build list of mesh entity indices from the entity vertices.
[2025-06-16 08:21:51.145] [info] Checking required entities per dimension
[2025-06-16 08:21:51.145] [info] Cell type: 0 dofmap: 2167x4
[2025-06-16 08:21:51.145] [info] Global index computation
[2025-06-16 08:21:51.145] [info] Got 1 index_maps
[2025-06-16 08:21:51.145] [info] Get global indices
[2025-06-16 08:21:51.146] [info] Requesting connectivity (2, 0) - (3, 0)
[2025-06-16 08:21:51.149] [info] Column ghost size increased from 0 to 0
[2025-06-16 08:21:51.154] [info] Requesting connectivity (2, 0) - (3, 0)
[2025-06-16 08:21:51.154] [info] Requesting connectivity (2, 0) - (0, 0)
[2025-06-16 08:21:51.154] [info] Requesting connectivity (2, 0) - (0, 0)
[2025-06-16 08:21:51.154] [info] Requesting connectivity (0, 0) - (3, 0)
[2025-06-16 08:21:51.154] [info] Requesting connectivity (3, 0) - (0, 0)
[2025-06-16 08:21:51.157] [info] Column ghost size increased from 0 to 0
[2025-06-16 08:21:51.164] [info] Column ghost size increased from 0 to 0
[2025-06-16 08:21:51.170] [info] Column ghost size increased from 0 to 0
[2025-06-16 08:21:51.175] [info] Column ghost size increased from 0 to 0
[2025-06-16 08:21:51.180] [info] Column ghost size increased from 0 to 0
[2025-06-16 08:21:51.186] [info] Checking required entities per dimension
[2025-06-16 08:21:51.186] [info] Cell type: 0 dofmap: 2167x10
[2025-06-16 08:21:51.186] [info] Global index computation
[2025-06-16 08:21:51.186] [info] Got 2 index_maps
[2025-06-16 08:21:51.186] [info] Get global indices
[2025-06-16 08:21:51.187] [info] Checking required entities per dimension
[2025-06-16 08:21:51.187] [info] Cell type: 0 dofmap: 2167x10
[2025-06-16 08:21:51.188] [info] Global index computation
[2025-06-16 08:21:51.188] [info] Got 2 index_maps
[2025-06-16 08:21:51.188] [info] Get global indices
[2025-06-16 08:21:51.941] [info] Checking required entities per dimension
[2025-06-16 08:21:51.941] [info] Cell type: 0 dofmap: 2167x10
[2025-06-16 08:21:51.941] [info] Global index computation
[2025-06-16 08:21:51.941] [info] Got 2 index_maps
[2025-06-16 08:21:51.942] [info] Get global indices
[2025-06-16 08:21:51.943] [info] Checking required entities per dimension
[2025-06-16 08:21:51.943] [info] Cell type: 0 dofmap: 2167x10
[2025-06-16 08:21:51.943] [info] Global index computation
[2025-06-16 08:21:51.943] [info] Got 2 index_maps
[2025-06-16 08:21:51.943] [info] Get global indices
[2025-06-16 08:21:53.042] [info] Checking required entities per dimension
[2025-06-16 08:21:53.042] [info] Cell type: 0 dofmap: 2167x10
[2025-06-16 08:21:53.043] [info] Global index computation
[2025-06-16 08:21:53.043] [info] Got 2 index_maps
[2025-06-16 08:21:53.043] [info] Get global indices
[2025-06-16 08:21:53.045] [info] Checking required entities per dimension
[2025-06-16 08:21:53.045] [info] Cell type: 0 dofmap: 2167x10
[2025-06-16 08:21:53.045] [info] Global index computation
[2025-06-16 08:21:53.045] [info] Got 2 index_maps
[2025-06-16 08:21:53.045] [info] Get global indices
[2025-06-16 08:21:53.048] [info] Compute face permutations
[2025-06-16 08:21:53.048] [info] Computing permutations for face type 0
[2025-06-16 08:21:53.049] [info] Compute edge permutations

If the folder exist we just load it

geo = cardiac_geometries.geometry.Geometry.from_folder(
    comm=MPI.COMM_WORLD,
    folder=geodir,
)
[2025-06-16 08:21:53.060] [info] Opened HDF5 file with id "72057594037927938"
[2025-06-16 08:21:53.060] [info] Read topology data "Mesh" at /Xdmf/Domain
[2025-06-16 08:21:53.060] [info] HDF5 Read data rate: 2770.7675710232947 MB/s
[2025-06-16 08:21:53.060] [info] IO permuting cells
[2025-06-16 08:21:53.060] [info] Read geometry data "Mesh" at /Xdmf/Domain
[2025-06-16 08:21:53.060] [info] HDF5 Read data rate: 1265.3644592663175 MB/s
[2025-06-16 08:21:53.062] [info] Using partitioner with 8668 cell data
[2025-06-16 08:21:53.062] [info] Compute partition of cells across ranks
[2025-06-16 08:21:53.062] [info] Building mesh dual graph
[2025-06-16 08:21:53.062] [info] Build local part of mesh dual graph (mixed)
[2025-06-16 08:21:53.063] [info] Build nonlocal part of mesh dual graph
[2025-06-16 08:21:53.063] [info] Graph edges (local: 7542, non-local: 0)
[2025-06-16 08:21:53.063] [info] Compute graph partition using PT-SCOTCH
[2025-06-16 08:21:53.063] [info] Computing communication graph edges (using NBX algorithm). Number of input edges: 1
[2025-06-16 08:21:53.063] [info] Finished graph edge discovery using NBX algorithm. Number of discovered edges 1
[2025-06-16 08:21:53.063] [info] Extract basic topology: 8668->8668
[2025-06-16 08:21:53.063] [info] Build local dual graph
[2025-06-16 08:21:53.063] [info] Build local part of mesh dual graph (mixed)
[2025-06-16 08:21:53.064] [info] GPS pseudo-diameter:(46) 2166-0
[2025-06-16 08:21:53.065] [info] Create topology (single cell type)
[2025-06-16 08:21:53.065] [info] Create topology (generalised)
[2025-06-16 08:21:53.065] [info] Computing communication graph edges (using NBX algorithm). Number of input edges: 1
[2025-06-16 08:21:53.065] [info] Finished graph edge discovery using NBX algorithm. Number of discovered edges 1
[2025-06-16 08:21:53.065] [info] Compute ghost indices
[2025-06-16 08:21:53.065] [info] Computing communication graph edges (using PCX algorithm). Number of input edges: 0
[2025-06-16 08:21:53.065] [info] Finished graph edge discovery using PCX algorithm. Number of discovered edges 0
[2025-06-16 08:21:53.065] [info] Computing communication graph edges (using NBX algorithm). Number of input edges: 0
[2025-06-16 08:21:53.065] [info] Finished graph edge discovery using NBX algorithm. Number of discovered edges 0
[2025-06-16 08:21:53.066] [info] Computing communication graph edges (using NBX algorithm). Number of input edges: 0
[2025-06-16 08:21:53.066] [info] Finished graph edge discovery using NBX algorithm. Number of discovered edges 0
[2025-06-16 08:21:53.066] [info] Number of neighbourhood source ranks in distribute_to_postoffice: 0
[2025-06-16 08:21:53.066] [info] Computing communication graph edges (using NBX algorithm). Number of input edges: 0
[2025-06-16 08:21:53.066] [info] Finished graph edge discovery using NBX algorithm. Number of discovered edges 0
[2025-06-16 08:21:53.066] [info] Neighbourhood destination ranks from post office in distribute_data (rank, num dests, num dests/mpi_size): 0, 0, 0
[2025-06-16 08:21:53.066] [info] Checking required entities per dimension
[2025-06-16 08:21:53.066] [info] Cell type: 0 dofmap: 2167x4
[2025-06-16 08:21:53.066] [info] Global index computation
[2025-06-16 08:21:53.066] [info] Got 1 index_maps
[2025-06-16 08:21:53.066] [info] Get global indices
[2025-06-16 08:21:53.066] [info] Requesting connectivity (3, 0) - (3, 0)
[2025-06-16 08:21:53.066] [info] XDMF read meshtags (Cell tags)
[2025-06-16 08:21:53.066] [info] Read topology data "Cell tags" at /Xdmf/Domain
[2025-06-16 08:21:53.067] [info] HDF5 Read data rate: 1860.5849208478667 MB/s
[2025-06-16 08:21:53.067] [info] IO permuting cells
[2025-06-16 08:21:53.067] [info] HDF5 Read data rate: 688.8111888111888 MB/s
[2025-06-16 08:21:53.067] [info] IO permuting cells
[2025-06-16 08:21:53.067] [info] XDMF distribute entity data
[2025-06-16 08:21:53.067] [info] Computing communication graph edges (using NBX algorithm). Number of input edges: 1
[2025-06-16 08:21:53.067] [info] Finished graph edge discovery using NBX algorithm. Number of discovered edges 1
[2025-06-16 08:21:53.067] [info] Computing communication graph edges (using NBX algorithm). Number of input edges: 1
[2025-06-16 08:21:53.067] [info] Finished graph edge discovery using NBX algorithm. Number of discovered edges 1
[2025-06-16 08:21:53.067] [info] XDMF build map
[2025-06-16 08:21:53.068] [info] XDMF create meshtags
[2025-06-16 08:21:53.068] [info] Building MeshTags object from tagged entities (defined by vertices).
[2025-06-16 08:21:53.068] [info] Build list of mesh entity indices from the entity vertices.
[2025-06-16 08:21:53.069] [info] Computing mesh entities of dimension 2
[2025-06-16 08:21:53.070] [info] Computing communication graph edges (using NBX algorithm). Number of input edges: 0
[2025-06-16 08:21:53.070] [info] Finished graph edge discovery using NBX algorithm. Number of discovered edges 0
[2025-06-16 08:21:53.070] [info] Requesting connectivity (2, 0) - (3, 0)
[2025-06-16 08:21:53.070] [info] Computing mesh connectivity 2-3 from transpose.
[2025-06-16 08:21:53.070] [info] XDMF read meshtags (Facet tags)
[2025-06-16 08:21:53.070] [info] Read topology data "Facet tags" at /Xdmf/Domain
[2025-06-16 08:21:53.070] [info] HDF5 Read data rate: 2035.859575109236 MB/s
[2025-06-16 08:21:53.070] [info] IO permuting cells
[2025-06-16 08:21:53.070] [info] HDF5 Read data rate: 675.9717844814647 MB/s
[2025-06-16 08:21:53.070] [info] IO permuting cells
[2025-06-16 08:21:53.070] [info] XDMF distribute entity data
[2025-06-16 08:21:53.070] [info] Computing communication graph edges (using NBX algorithm). Number of input edges: 1
[2025-06-16 08:21:53.070] [info] Finished graph edge discovery using NBX algorithm. Number of discovered edges 1
[2025-06-16 08:21:53.070] [info] Computing communication graph edges (using NBX algorithm). Number of input edges: 1
[2025-06-16 08:21:53.070] [info] Finished graph edge discovery using NBX algorithm. Number of discovered edges 1
[2025-06-16 08:21:53.070] [info] XDMF build map
[2025-06-16 08:21:53.071] [info] XDMF create meshtags
[2025-06-16 08:21:53.071] [info] Building MeshTags object from tagged entities (defined by vertices).
[2025-06-16 08:21:53.071] [info] Build list of mesh entity indices from the entity vertices.
[2025-06-16 08:21:53.072] [info] Computing mesh entities of dimension 1
[2025-06-16 08:21:53.074] [info] Computing communication graph edges (using NBX algorithm). Number of input edges: 0
[2025-06-16 08:21:53.074] [info] Finished graph edge discovery using NBX algorithm. Number of discovered edges 0
[2025-06-16 08:21:53.074] [info] Requesting connectivity (1, 0) - (3, 0)
[2025-06-16 08:21:53.074] [info] Computing mesh connectivity 1-3 from transpose.
[2025-06-16 08:21:53.074] [info] XDMF read meshtags (Edge tags)
[2025-06-16 08:21:53.074] [info] Read topology data "Edge tags" at /Xdmf/Domain
[2025-06-16 08:21:53.074] [info] HDF5 Read data rate: 0 MB/s
[2025-06-16 08:21:53.074] [info] IO permuting cells
[2025-06-16 08:21:53.074] [info] HDF5 Read data rate: 0 MB/s
[2025-06-16 08:21:53.074] [info] IO permuting cells
[2025-06-16 08:21:53.074] [info] XDMF distribute entity data
[2025-06-16 08:21:53.074] [info] Computing communication graph edges (using NBX algorithm). Number of input edges: 0
[2025-06-16 08:21:53.074] [info] Finished graph edge discovery using NBX algorithm. Number of discovered edges 0
[2025-06-16 08:21:53.074] [info] Computing communication graph edges (using NBX algorithm). Number of input edges: 1
[2025-06-16 08:21:53.074] [info] Finished graph edge discovery using NBX algorithm. Number of discovered edges 1
[2025-06-16 08:21:53.074] [info] XDMF build map
[2025-06-16 08:21:53.074] [info] XDMF create meshtags
[2025-06-16 08:21:53.074] [info] Building MeshTags object from tagged entities (defined by vertices).
[2025-06-16 08:21:53.074] [info] Build list of mesh entity indices from the entity vertices.
[2025-06-16 08:21:53.075] [info] Requesting connectivity (0, 0) - (3, 0)
[2025-06-16 08:21:53.075] [info] Computing mesh connectivity 0-3 from transpose.
[2025-06-16 08:21:53.075] [info] XDMF read meshtags (Vertex tags)
[2025-06-16 08:21:53.075] [info] Read topology data "Vertex tags" at /Xdmf/Domain
[2025-06-16 08:21:53.075] [info] HDF5 Read data rate: 0 MB/s
[2025-06-16 08:21:53.075] [info] IO permuting cells
[2025-06-16 08:21:53.075] [info] HDF5 Read data rate: 0 MB/s
[2025-06-16 08:21:53.075] [info] IO permuting cells
[2025-06-16 08:21:53.075] [info] XDMF distribute entity data
[2025-06-16 08:21:53.075] [info] Computing communication graph edges (using NBX algorithm). Number of input edges: 0
[2025-06-16 08:21:53.075] [info] Finished graph edge discovery using NBX algorithm. Number of discovered edges 0
[2025-06-16 08:21:53.075] [info] Computing communication graph edges (using NBX algorithm). Number of input edges: 1
[2025-06-16 08:21:53.075] [info] Finished graph edge discovery using NBX algorithm. Number of discovered edges 1
[2025-06-16 08:21:53.075] [info] XDMF build map
[2025-06-16 08:21:53.076] [info] XDMF create meshtags
[2025-06-16 08:21:53.076] [info] Building MeshTags object from tagged entities (defined by vertices).
[2025-06-16 08:21:53.076] [info] Build list of mesh entity indices from the entity vertices.
[2025-06-16 08:21:53.078] [info] Checking required entities per dimension
[2025-06-16 08:21:53.078] [info] Cell type: 0 dofmap: 2167x10
[2025-06-16 08:21:53.078] [info] Global index computation
[2025-06-16 08:21:53.078] [info] Got 2 index_maps
[2025-06-16 08:21:53.078] [info] Get global indices
[2025-06-16 08:21:53.079] [info] Compute face permutations
[2025-06-16 08:21:53.079] [info] Computing permutations for face type 0
[2025-06-16 08:21:53.080] [info] Compute edge permutations
[2025-06-16 08:21:53.086] [info] Checking required entities per dimension
[2025-06-16 08:21:53.086] [info] Cell type: 0 dofmap: 2167x10
[2025-06-16 08:21:53.087] [info] Global index computation
[2025-06-16 08:21:53.087] [info] Got 2 index_maps
[2025-06-16 08:21:53.087] [info] Get global indices
[2025-06-16 08:21:53.094] [info] Checking required entities per dimension
[2025-06-16 08:21:53.094] [info] Cell type: 0 dofmap: 2167x10
[2025-06-16 08:21:53.094] [info] Global index computation
[2025-06-16 08:21:53.094] [info] Got 2 index_maps
[2025-06-16 08:21:53.094] [info] Get global indices

In order to use the geometry with pulse we need to convert it to a pulse.Geometry object. We can do this by using the from_cardiac_geometries method. We also specify that we want to use a quadrature degree of 4

geometry = pulse.Geometry.from_cardiac_geometries(geo, metadata={"quadrature_degree": 4})

Next we create the material object, and we will use the transversely isotropic version of the Neo Hookean model

material = pulse.NeoHookean(mu=dolfinx.fem.Constant(geometry.mesh, dolfinx.default_scalar_type(15.0)))
# and use an active stress approach
Setting mu to c_6 kPa
Ta = dolfinx.fem.Constant(geometry.mesh, dolfinx.default_scalar_type(0.0))
active_model = pulse.ActiveStress(geo.f0, activation=Ta)
Activation is not a Variable, defaulting to kPa

Now we will also implement two different versions, one where we use a compressible model and one where we use an incompressible model. To do this we will introduce a flag

incompressible = False

And in both cases we will use different compressible models, mechanics problems and different ways to get the displacement.

if incompressible:
    comp_model: pulse.Compressibility = pulse.Incompressible()
else:
    comp_model = pulse.Compressible()

Now we can assemble the CardiacModel

model = pulse.CardiacModel(
    material=material,
    active=active_model,
    compressibility=comp_model,
)

We will add a pressure on the LV endocarium

lvp = dolfinx.fem.Constant(geometry.mesh, dolfinx.default_scalar_type(0.0))
neumann_lv = pulse.NeumannBC(traction=lvp, marker=geometry.markers["ENDO_LV"][0])
Traction is not a Variable, defaulting to kPa

and on the RV endocardium

rvp = dolfinx.fem.Constant(geometry.mesh, dolfinx.default_scalar_type(0.0))
neumann_rv = pulse.NeumannBC(traction=lvp, marker=geometry.markers["ENDO_RV"][0])
Traction is not a Variable, defaulting to kPa

We will also add a Robin type spring on the epicardial surface to mimic the pericardium.

pericardium = dolfinx.fem.Constant(geometry.mesh, dolfinx.default_scalar_type(1.0))
robin_per = pulse.RobinBC(value=pericardium, marker=geometry.markers["EPI"][0])
Value is not a Variable, defaulting to Pa / m

We collect all the boundary conditions

bcs = pulse.BoundaryConditions(neumann=(neumann_lv, neumann_rv), robin=(robin_per,))

create the problem

problem = pulse.StaticProblem(model=model, geometry=geometry, bcs=bcs, parameters={"base_bc": pulse.BaseBC.fixed})
[2025-06-16 08:21:53.147] [info] Checking required entities per dimension
[2025-06-16 08:21:53.147] [info] Cell type: 0 dofmap: 2167x10
[2025-06-16 08:21:53.147] [info] Global index computation
[2025-06-16 08:21:53.147] [info] Got 2 index_maps
[2025-06-16 08:21:53.147] [info] Get global indices
[2025-06-16 08:21:53.841] [info] Requesting connectivity (2, 0) - (3, 0)
[2025-06-16 08:21:53.841] [info] Requesting connectivity (3, 0) - (2, 0)
[2025-06-16 08:21:53.841] [info] Requesting connectivity (2, 0) - (3, 0)
[2025-06-16 08:21:53.841] [info] Requesting connectivity (3, 0) - (2, 0)
[2025-06-16 08:21:55.786] [info] Requesting connectivity (2, 0) - (3, 0)
[2025-06-16 08:21:55.786] [info] Requesting connectivity (3, 0) - (2, 0)
[2025-06-16 08:21:55.786] [info] Requesting connectivity (2, 0) - (3, 0)
[2025-06-16 08:21:55.786] [info] Requesting connectivity (3, 0) - (2, 0)
[2025-06-16 08:21:55.786] [info] Requesting connectivity (2, 0) - (3, 0)
[2025-06-16 08:21:55.849] [info] Column ghost size increased from 0 to 0

and solve

problem.solve()
5

Now let us inflate the two ventricles and save the displacement

vtx = dolfinx.io.VTXWriter(geometry.mesh.comm, outdir / "biv_displacement.bp", [problem.u], engine="BP4")
vtx.write(0.0)
i = 1
for plv in [0.1]: #, 0.5, 1.0, 2.0]:
    print(f"plv: {plv}")
    lvp.value = plv
    rvp.value = plv * 0.2
    problem.solve()
    vtx.write(float(i))
    i += 1
plv: 0.1

and then apply an active tension

for ta in [0.1] : #, 1.0, 5.0, 10.0]:
    print(f"ta: {ta}")
    Ta.value = ta
    problem.solve()
    vtx.write(float(i))
    i += 1
ta: 0.1
vtx.close()
try:
    import pyvista
except ImportError:
    print("Pyvista is not installed")
else:
    pyvista.start_xvfb()
    V = dolfinx.fem.functionspace(geometry.mesh, ("Lagrange", 1, (geometry.mesh.geometry.dim,)))
    uh = dolfinx.fem.Function(V)
    uh.interpolate(problem.u)
    # Create plotter and pyvista grid
    p = pyvista.Plotter()
    topology, cell_types, geometry = dolfinx.plot.vtk_mesh(V)
    grid = pyvista.UnstructuredGrid(topology, cell_types, geometry)

    # Attach vector values to grid and warp grid by vector
    grid["u"] = uh.x.array.reshape((geometry.shape[0], 3))
    actor_0 = p.add_mesh(grid, style="wireframe", color="k")
    warped = grid.warp_by_vector("u", factor=1.5)
    actor_1 = p.add_mesh(warped, show_edges=True)
    p.show_axes()
    if not pyvista.OFF_SCREEN:
        p.show()
    else:
        figure_as_array = p.screenshot("biv_ellipsoid_pressure.png")
[2025-06-16 08:22:03.088] [info] Checking required entities per dimension
[2025-06-16 08:22:03.088] [info] Cell type: 0 dofmap: 2167x4
[2025-06-16 08:22:03.088] [info] Global index computation
[2025-06-16 08:22:03.088] [info] Got 1 index_maps
[2025-06-16 08:22:03.088] [info] Get global indices
error: XDG_RUNTIME_DIR is invalid or not set in the environment.