Niederer benchmark#
In this example we will use the same setup as in the Niederer benchmark [LGA+15]. It is a standard convergence/cross-code benchmark for monodomain solvers: a small cuboid slab of tissue with a detailed ionic current model (the ten Tusscher–Panfilov 2006 epicardial model), a conductivity tensor \(M\) built from the “Niederer” literature conductivity values, and a stimulus \(I_{stim}\) applied in one corner. The quantity of interest is the local activation time — the first time \(v\) crosses \(0\) mV — at nine fixed points in the slab, for a range of spatial and temporal resolutions \(dx\), \(dt\). See the mathematical background page for the underlying monodomain model and notation used below.
from pathlib import Path
import json
import time
import logging
import os
import dolfinx
import scifem
import numpy as np
import numpy.typing as npt
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
if os.environ.get("NO_PYVISTA", "0") == "1":
pyvista = None
logger.warning("Turn off pyvista")
else:
try:
import pyvista # type: ignore[no-redef, assignment]
except ImportError:
pyvista = None # type: ignore[no-redef]
logger.warning("pyvista not installed, skipping visualization")
import gotranx
import matplotlib.pyplot as plt
import beat
def setup_initial_conditions() -> npt.NDArray:
ic = {
"V": -85.23, # mV
"Xr1": 0.00621,
"Xr2": 0.4712,
"Xs": 0.0095,
"m": 0.00172,
"h": 0.7444,
"j": 0.7045,
"d": 3.373e-05,
"f": 0.7888,
"f2": 0.9755,
"fCass": 0.9953,
"s": 0.999998,
"r": 2.42e-08,
"Ca_i": 0.000126, # millimolar
"R_prime": 0.9073,
"Ca_SR": 3.64, # millimolar
"Ca_ss": 0.00036, # millimolar
"Na_i": 8.604, # millimolar
"K_i": 136.89, # millimolar
}
values = model.init_state_values(**ic)
return values
dx = 0.5
dt = 0.05
# Increase T to 100 to reproduce Niederer benchmark
T = 20.0
here = Path.cwd()
model_path = Path("tentusscher_panfilov_2006_epi_cell.py")
if not model_path.is_file() or "def rush_larsen_2" not in model_path.read_text():
here = Path.cwd()
cell_ode = gotranx.load_ode(
here
/ ".."
/ "odes"
/ "tentusscher_panfilov_2006"
/ "tentusscher_panfilov_2006_epi_cell.ode",
)
code = gotranx.cli.gotran2py.get_code(
cell_ode,
scheme=[gotranx.schemes.Scheme.rush_larsen_2],
)
model_path.write_text(code)
import tentusscher_panfilov_2006_epi_cell as model
fun = model.rush_larsen_2
init_states = setup_initial_conditions()
parameters = model.init_parameter_values(stim_amplitude=0.0)
mesh_unit = "mm"
Lx = 20.0 * beat.units.ureg("mm").to(mesh_unit).magnitude
Ly = 7 * beat.units.ureg("mm").to(mesh_unit).magnitude
Lz = 3 * beat.units.ureg("mm").to(mesh_unit).magnitude
dx_mm = dx * beat.units.ureg("mm").to(mesh_unit).magnitude
geo = beat.geometry.get_3D_slab_geometry(
comm=comm,
Lx=Lx,
Ly=Ly,
Lz=Lz,
dx=dx_mm,
)
ode_space = dolfinx.fem.functionspace(geo.mesh, ("Lagrange", 1))
if pyvista is not None:
plotter = pyvista.Plotter()
grid = pyvista.UnstructuredGrid(*dolfinx.plot.vtk_mesh(geo.mesh))
plotter.add_mesh(grid, show_edges=True)
plotter.show_grid()
plotter.add_axes(line_width=5)
plotter.show_axes()
plotter.view_xy()
if not pyvista.OFF_SCREEN:
plotter.show()
else:
figure = plotter.screenshot("niederer_mesh.png")
INFO:trame_server.utils.namespace:Translator(prefix=None)
INFO:wslink.backends.aiohttp:awaiting runner setup
INFO:wslink.backends.aiohttp:awaiting site startup
INFO:wslink.backends.aiohttp:Print WSLINK_READY_MSG
INFO:wslink.backends.aiohttp:Schedule auto shutdown with timeout 0
INFO:wslink.backends.aiohttp:awaiting running future
# Literature values for the intracellular/extracellular conductivities and the surface to volume
# ratio $\chi$, used below to build the conductivity tensor $M$.
conductivities = beat.conductivities.default_conductivities("Niederer")
# Membrane capacitance $C_m$
C_m = beat.units.ureg.Quantity(1.0, "uF/cm**2")
time_constant = dolfinx.fem.Constant(geo.mesh, 0.0)
L = 1.5 * beat.units.ureg("mm").to(mesh_unit).magnitude
S1_marker = 1
L = 1.5
tol = 1.0e-10
def S1_subdomain(x):
return np.logical_and(
np.logical_and(x[0] <= L + tol, x[1] <= L + tol),
x[2] <= L + tol,
)
cells = dolfinx.mesh.locate_entities(geo.mesh, geo.mesh.topology.dim, S1_subdomain)
S1_markers = dolfinx.mesh.meshtags(
geo.mesh,
geo.mesh.topology.dim,
cells,
np.full(len(cells), S1_marker, dtype=np.int32),
)
# The stimulus current $I_{stim}$, applied to the S1 corner subdomain defined above.
I_s = beat.stimulation.define_stimulus(
mesh=geo.mesh,
chi=conductivities["chi"],
time=time_constant,
subdomain_data=S1_markers,
marker=S1_marker,
mesh_unit=mesh_unit,
amplitude=50_000.0,
)
# The conductivity tensor $M$, built from the fibre direction `geo.f0` and the conductivities above.
assert geo.f0 is not None
M = beat.conductivities.define_conductivity_tensor(
f0=geo.f0,
**conductivities,
)
# The PDE uses the consistent mass matrix, beat's default. openCARP and CARPentry lump the mass
# matrix by default (openCARP's `mass_lumping = 1`); add `"lump_mass": True` to `params` below to
# do the same and compare like for like. Lumping delays activation on coarse meshes {cite}`niederer2011verification` (Section 6): with openCARP 19 on
# this slab at $dx = 0.5$ mm, $dt = 0.05$ ms, P8 activates at 67 ms with lumping and 38 ms without.
# See the [mathematical background](../docs/math_background.md) page.
params = {
"petsc_options": {
"ksp_type": "cg",
"pc_type": "hypre",
"pc_hypre_type": "boomeramg",
},
}
save_freq = int(1.0 / dt)
# Create a monitor to log the solver time and performance metrics every `save_freq` time steps
monitor = beat.PerformanceMonitor(log_frequency=save_freq)
pde = beat.MonodomainModel(
time=time_constant,
mesh=geo.mesh,
M=M,
I_s=I_s,
params=params,
C_m=C_m.to(f"uF/{mesh_unit}**2").magnitude,
dx=I_s.dZ,
monitor=monitor,
)
ode = beat.odesolver.DolfinODESolver(
v_ode=dolfinx.fem.Function(ode_space),
v_pde=pde.state,
fun=fun,
init_states=init_states,
parameters=parameters,
num_states=len(init_states),
v_index=model.state_index("V"),
monitor=monitor,
)
# Combine the PDE and ODE solver. We use Strang splitting (the default) without merged half-steps: we read `v` after every step
# (activation times), which merged half-steps would delay by up to half a time step.
INFO:beat.conductivities:Get harmonic mean conductivity: g_il=Quantity(0.17, "siemens / meter") g_it=Quantity(0.019, "siemens / meter") g_el=Quantity(0.62, "siemens / meter") g_et=Quantity(0.24, "siemens / meter") chi=Quantity(1400.0, "1 / centimeter")
INFO:beat.conductivities:Harmonic mean conductivities sigma_l=Quantity(0.13341772151898734, "siemens / meter") sigma_t=Quantity(0.017606177606177605, "siemens / meter")
INFO:beat.conductivities:Scaled harmonic mean conductivities s_l=0.0009529837251356239 s_t=0.00012575841147269718
INFO:beat.conductivities:Define conductivity tensor s_l=0.0009529837251356239 s_t=0.00012575841147269718 dim=3
solver = beat.SplittingSolver(pde=pde, ode=ode, monitor=monitor)
output_dir = Path("results-niederer-benchmark")
output_dir.mkdir(exist_ok=True)
filename = output_dir / f"results-{dt}-{dx}.xdmf"
filename.unlink(missing_ok=True)
filename.with_suffix(".h5").unlink(missing_ok=True)
vtx = dolfinx.io.VTXWriter(
comm,
"niederer_benchmark.bp",
[solver.v],
engine="BP4",
)
points = {
"P1": (0, 0, 0),
"P2": (0.0, Ly, 0.0),
"P3": (Lx, 0.0, 0.0),
"P4": (Lx, Ly, 0.0),
"P5": (0.0, 0.0, Lz),
"P6": (0.0, Ly, Lz),
"P7": (Lx, 0.0, Lz),
"P8": (Lx, Ly, Lz),
"P9": (Lx / 2, Ly / 2, Lz / 2),
}
activation_times = {p: -1.0 for p in points}
save_freq = int(1.0 / dt)
i = 0
if pyvista is not None:
plotter_voltage = pyvista.Plotter()
viridis = plt.get_cmap("viridis")
grid.point_data["V"] = solver.v.x.array
grid.set_active_scalars("V")
renderer = plotter_voltage.add_mesh(
grid,
show_edges=True,
lighting=False,
cmap=viridis,
clim=[-90.0, 40.0],
)
gif_file = Path("niederer_benchmark.gif")
gif_file.unlink(missing_ok=True)
plotter_voltage.open_gif(gif_file.as_posix())
T = 20
# T = 100 # Change to 100 to reproduce Niederer benchmark
t = 0.0
times: list[float] = []
while t < T + 1e-12 and any(at < 0.0 for at in activation_times.values()):
v = solver.v.x.array
if i % save_freq == 0:
logger.info(f"Solve for {t=:.2f}, {v.max() =}, {v.min() =}")
if len(times) > 0:
logger.info(f"Average solver time per time step: {np.mean(times):.5f} s")
logger.info(activation_times)
vtx.write(t)
if pyvista is not None:
grid.point_data["V"] = solver.v.x.array
plotter_voltage.write_frame()
t0 = time.perf_counter()
solver.step((t, t + dt))
times.append(time.perf_counter() - t0)
for p in points:
value = scifem.evaluate_function(solver.v, [points[p]]).squeeze()
if value > 0.0 and activation_times[p] < 0.0:
activation_times[p] = t
i += 1
t += dt
if pyvista is not None:
plotter_voltage.close()
monitor.display_summary()
monitor.save_summary(output_dir / "performance_summary.json")
INFO:__main__:Solve for t=0.00, v.max() =np.float64(-85.23), v.min() =np.float64(-85.23)
INFO:__main__:{'P1': -1.0, 'P2': -1.0, 'P3': -1.0, 'P4': -1.0, 'P5': -1.0, 'P6': -1.0, 'P7': -1.0, 'P8': -1.0, 'P9': -1.0}
INFO:beat.telemetry:PDE step timing step=20, t=(0.95000, 1.00000), ksp_iterations=5, ksp_residual_norm=6.203326e-03, ksp_converged_reason=2, ode_function_call=0.395888s, ode_state_update=0.001422s, ode_total_step=0.397895s, ode_step=0.183428s, ode_to_dolfin=0.000376s, ode_to_pde=0.000327s, pde_assign_previous_before=0.000156s, pde_set_time=0.000196s, pde_update_matrices=0.019384s, pde_update_rhs=0.004593s, pde_linear_solve=0.020082s, pde_scatter_forward=0.000075s, pde_total_step=0.044862s, pde_step=0.044959s, pde_to_ode=0.000318s, ode_from_dolfin=0.000101s, corrective_ode_step=0.214674s, corrective_ode_to_dolfin=0.000360s, corrective_ode_to_pde=0.000217s, corrective_pde_assign_previous=0.000135s, total_step=0.447136s
INFO:__main__:Solve for t=1.00, v.max() =np.float64(-8.309804486138196), v.min() =np.float64(-88.12175830205148)
INFO:__main__:Average solver time per time step: 0.02242 s
INFO:__main__:{'P1': -1.0, 'P2': -1.0, 'P3': -1.0, 'P4': -1.0, 'P5': -1.0, 'P6': -1.0, 'P7': -1.0, 'P8': -1.0, 'P9': -1.0}
INFO:beat.telemetry:PDE step timing step=40, t=(1.95000, 2.00000), ksp_iterations=5, ksp_residual_norm=6.210813e-03, ksp_converged_reason=2, ode_function_call=0.817075s, ode_state_update=0.002921s, ode_total_step=0.821281s, ode_step=0.370266s, ode_to_dolfin=0.000770s, ode_to_pde=0.000567s, pde_assign_previous_before=0.000310s, pde_set_time=0.000411s, pde_update_matrices=0.019384s, pde_update_rhs=0.009159s, pde_linear_solve=0.038843s, pde_scatter_forward=0.000154s, pde_total_step=0.069005s, pde_step=0.069170s, pde_to_ode=0.000654s, ode_from_dolfin=0.000200s, corrective_ode_step=0.451437s, corrective_ode_to_dolfin=0.000745s, corrective_ode_to_pde=0.000441s, corrective_pde_assign_previous=0.000274s, total_step=0.898963s
INFO:__main__:Solve for t=2.00, v.max() =np.float64(56.12146742498349), v.min() =np.float64(-88.84631254844517)
INFO:__main__:Average solver time per time step: 0.02254 s
INFO:__main__:{'P1': 1.2000000000000004, 'P2': -1.0, 'P3': -1.0, 'P4': -1.0, 'P5': -1.0, 'P6': -1.0, 'P7': -1.0, 'P8': -1.0, 'P9': -1.0}
INFO:beat.telemetry:PDE step timing step=60, t=(2.95000, 3.00000), ksp_iterations=5, ksp_residual_norm=6.194100e-03, ksp_converged_reason=2, ode_function_call=1.234289s, ode_state_update=0.004450s, ode_total_step=1.240676s, ode_step=0.557523s, ode_to_dolfin=0.001150s, ode_to_pde=0.000811s, pde_assign_previous_before=0.000488s, pde_set_time=0.000612s, pde_update_matrices=0.019384s, pde_update_rhs=0.013902s, pde_linear_solve=0.057239s, pde_scatter_forward=0.000226s, pde_total_step=0.092911s, pde_step=0.093146s, pde_to_ode=0.000959s, ode_from_dolfin=0.000304s, corrective_ode_step=0.683779s, corrective_ode_to_dolfin=0.001184s, corrective_ode_to_pde=0.000665s, corrective_pde_assign_previous=0.000409s, total_step=1.346635s
INFO:__main__:Solve for t=3.00, v.max() =np.float64(38.153263458416134), v.min() =np.float64(-89.74726183938343)
INFO:__main__:Average solver time per time step: 0.02251 s
INFO:__main__:{'P1': 1.2000000000000004, 'P2': -1.0, 'P3': -1.0, 'P4': -1.0, 'P5': -1.0, 'P6': -1.0, 'P7': -1.0, 'P8': -1.0, 'P9': -1.0}
INFO:beat.telemetry:PDE step timing step=80, t=(3.95000, 4.00000), ksp_iterations=5, ksp_residual_norm=6.195103e-03, ksp_converged_reason=2, ode_function_call=1.634636s, ode_state_update=0.005898s, ode_total_step=1.643225s, ode_step=0.743485s, ode_to_dolfin=0.001553s, ode_to_pde=0.001048s, pde_assign_previous_before=0.000648s, pde_set_time=0.000814s, pde_update_matrices=0.019384s, pde_update_rhs=0.018452s, pde_linear_solve=0.075401s, pde_scatter_forward=0.000293s, pde_total_step=0.116410s, pde_step=0.116713s, pde_to_ode=0.001254s, ode_from_dolfin=0.000405s, corrective_ode_step=0.900587s, corrective_ode_to_dolfin=0.001585s, corrective_ode_to_pde=0.000906s, corrective_pde_assign_previous=0.000545s, total_step=1.776956s
INFO:__main__:Solve for t=4.00, v.max() =np.float64(28.969096504059547), v.min() =np.float64(-89.33673796506199)
INFO:__main__:Average solver time per time step: 0.02228 s
INFO:__main__:{'P1': 1.2000000000000004, 'P2': -1.0, 'P3': -1.0, 'P4': -1.0, 'P5': -1.0, 'P6': -1.0, 'P7': -1.0, 'P8': -1.0, 'P9': -1.0}
INFO:beat.telemetry:PDE step timing step=100, t=(4.95000, 5.00000), ksp_iterations=5, ksp_residual_norm=6.187594e-03, ksp_converged_reason=2, ode_function_call=2.044187s, ode_state_update=0.007351s, ode_total_step=2.054899s, ode_step=0.937700s, ode_to_dolfin=0.001998s, ode_to_pde=0.001295s, pde_assign_previous_before=0.000802s, pde_set_time=0.001024s, pde_update_matrices=0.019384s, pde_update_rhs=0.022853s, pde_linear_solve=0.094006s, pde_scatter_forward=0.000367s, pde_total_step=0.140216s, pde_step=0.140588s, pde_to_ode=0.001576s, ode_from_dolfin=0.000509s, corrective_ode_step=1.118252s, corrective_ode_to_dolfin=0.002011s, corrective_ode_to_pde=0.001135s, corrective_pde_assign_previous=0.000680s, total_step=2.216858s
INFO:__main__:Solve for t=5.00, v.max() =np.float64(28.543514193063906), v.min() =np.float64(-89.18054383919183)
INFO:__main__:Average solver time per time step: 0.02223 s
INFO:__main__:{'P1': 1.2000000000000004, 'P2': -1.0, 'P3': -1.0, 'P4': -1.0, 'P5': -1.0, 'P6': -1.0, 'P7': -1.0, 'P8': -1.0, 'P9': -1.0}
INFO:beat.telemetry:PDE step timing step=120, t=(5.95000, 6.00000), ksp_iterations=5, ksp_residual_norm=6.183732e-03, ksp_converged_reason=2, ode_function_call=2.459845s, ode_state_update=0.008758s, ode_total_step=2.472589s, ode_step=1.124495s, ode_to_dolfin=0.002423s, ode_to_pde=0.001538s, pde_assign_previous_before=0.000955s, pde_set_time=0.001235s, pde_update_matrices=0.019384s, pde_update_rhs=0.027458s, pde_linear_solve=0.112729s, pde_scatter_forward=0.000461s, pde_total_step=0.164347s, pde_step=0.164793s, pde_to_ode=0.001905s, ode_from_dolfin=0.000611s, corrective_ode_step=1.349351s, corrective_ode_to_dolfin=0.002381s, corrective_ode_to_pde=0.001343s, corrective_pde_assign_previous=0.000816s, total_step=2.662965s
INFO:__main__:Solve for t=6.00, v.max() =np.float64(26.197919383370937), v.min() =np.float64(-88.43383466943689)
INFO:__main__:Average solver time per time step: 0.02226 s
INFO:__main__:{'P1': 1.2000000000000004, 'P2': -1.0, 'P3': -1.0, 'P4': -1.0, 'P5': -1.0, 'P6': -1.0, 'P7': -1.0, 'P8': -1.0, 'P9': -1.0}
INFO:beat.telemetry:PDE step timing step=140, t=(6.95000, 7.00000), ksp_iterations=5, ksp_residual_norm=6.183969e-03, ksp_converged_reason=2, ode_function_call=2.865435s, ode_state_update=0.010342s, ode_total_step=2.880541s, ode_step=1.312418s, ode_to_dolfin=0.002856s, ode_to_pde=0.001788s, pde_assign_previous_before=0.001109s, pde_set_time=0.001461s, pde_update_matrices=0.019384s, pde_update_rhs=0.032245s, pde_linear_solve=0.131472s, pde_scatter_forward=0.000543s, pde_total_step=0.188718s, pde_step=0.189241s, pde_to_ode=0.002247s, ode_from_dolfin=0.000712s, corrective_ode_step=1.569597s, corrective_ode_to_dolfin=0.002877s, corrective_ode_to_pde=0.001581s, corrective_pde_assign_previous=0.000961s, total_step=3.099843s
INFO:__main__:Solve for t=7.00, v.max() =np.float64(24.86302133907621), v.min() =np.float64(-89.02987259813695)
INFO:__main__:Average solver time per time step: 0.02221 s
INFO:__main__:{'P1': 1.2000000000000004, 'P2': -1.0, 'P3': -1.0, 'P4': -1.0, 'P5': -1.0, 'P6': -1.0, 'P7': -1.0, 'P8': -1.0, 'P9': -1.0}
INFO:beat.telemetry:PDE step timing step=160, t=(7.95000, 8.00000), ksp_iterations=5, ksp_residual_norm=6.291355e-03, ksp_converged_reason=2, ode_function_call=3.285136s, ode_state_update=0.011810s, ode_total_step=3.302368s, ode_step=1.516604s, ode_to_dolfin=0.003283s, ode_to_pde=0.002069s, pde_assign_previous_before=0.001268s, pde_set_time=0.001676s, pde_update_matrices=0.019384s, pde_update_rhs=0.036706s, pde_linear_solve=0.150263s, pde_scatter_forward=0.000622s, pde_total_step=0.212777s, pde_step=0.213370s, pde_to_ode=0.002592s, ode_from_dolfin=0.000814s, corrective_ode_step=1.787445s, corrective_ode_to_dolfin=0.003259s, corrective_ode_to_pde=0.001801s, corrective_pde_assign_previous=0.001102s, total_step=3.550177s
INFO:__main__:Solve for t=8.00, v.max() =np.float64(27.170605511317937), v.min() =np.float64(-88.81056750648716)
INFO:__main__:Average solver time per time step: 0.02225 s
INFO:__main__:{'P1': 1.2000000000000004, 'P2': -1.0, 'P3': -1.0, 'P4': -1.0, 'P5': -1.0, 'P6': -1.0, 'P7': -1.0, 'P8': -1.0, 'P9': -1.0}
INFO:beat.telemetry:PDE step timing step=180, t=(8.95000, 9.00000), ksp_iterations=5, ksp_residual_norm=6.376192e-03, ksp_converged_reason=2, ode_function_call=3.715582s, ode_state_update=0.013318s, ode_total_step=3.735004s, ode_step=1.714955s, ode_to_dolfin=0.003679s, ode_to_pde=0.002318s, pde_assign_previous_before=0.001422s, pde_set_time=0.001898s, pde_update_matrices=0.019384s, pde_update_rhs=0.041261s, pde_linear_solve=0.168973s, pde_scatter_forward=0.000707s, pde_total_step=0.236868s, pde_step=0.237537s, pde_to_ode=0.002925s, ode_from_dolfin=0.000915s, corrective_ode_step=2.021945s, corrective_ode_to_dolfin=0.003662s, corrective_ode_to_pde=0.002064s, corrective_pde_assign_previous=0.001249s, total_step=4.011337s
INFO:__main__:Solve for t=9.00, v.max() =np.float64(25.608423418759855), v.min() =np.float64(-89.34773612641564)
INFO:__main__:Average solver time per time step: 0.02235 s
INFO:__main__:{'P1': 1.2000000000000004, 'P2': -1.0, 'P3': -1.0, 'P4': -1.0, 'P5': -1.0, 'P6': -1.0, 'P7': -1.0, 'P8': -1.0, 'P9': -1.0}
INFO:beat.telemetry:PDE step timing step=200, t=(9.95000, 10.00000), ksp_iterations=5, ksp_residual_norm=6.429417e-03, ksp_converged_reason=2, ode_function_call=4.143633s, ode_state_update=0.014689s, ode_total_step=4.165094s, ode_step=1.915495s, ode_to_dolfin=0.004086s, ode_to_pde=0.002562s, pde_assign_previous_before=0.001610s, pde_set_time=0.002111s, pde_update_matrices=0.019384s, pde_update_rhs=0.045813s, pde_linear_solve=0.187418s, pde_scatter_forward=0.000777s, pde_total_step=0.260667s, pde_step=0.261407s, pde_to_ode=0.003235s, ode_from_dolfin=0.001011s, corrective_ode_step=2.251697s, corrective_ode_to_dolfin=0.004087s, corrective_ode_to_pde=0.002297s, corrective_pde_assign_previous=0.001394s, total_step=4.469616s
INFO:__main__:Solve for t=10.00, v.max() =np.float64(26.945692006261122), v.min() =np.float64(-89.48087822676452)
INFO:__main__:Average solver time per time step: 0.02241 s
INFO:__main__:{'P1': 1.2000000000000004, 'P2': -1.0, 'P3': -1.0, 'P4': -1.0, 'P5': -1.0, 'P6': -1.0, 'P7': -1.0, 'P8': -1.0, 'P9': -1.0}
INFO:beat.telemetry:PDE step timing step=220, t=(10.95000, 11.00000), ksp_iterations=5, ksp_residual_norm=6.441560e-03, ksp_converged_reason=2, ode_function_call=4.561232s, ode_state_update=0.016146s, ode_total_step=4.584815s, ode_step=2.099806s, ode_to_dolfin=0.004492s, ode_to_pde=0.002804s, pde_assign_previous_before=0.001766s, pde_set_time=0.002322s, pde_update_matrices=0.019384s, pde_update_rhs=0.050580s, pde_linear_solve=0.205822s, pde_scatter_forward=0.000847s, pde_total_step=0.284650s, pde_step=0.285457s, pde_to_ode=0.003555s, ode_from_dolfin=0.001109s, corrective_ode_step=2.487304s, corrective_ode_to_dolfin=0.004499s, corrective_ode_to_pde=0.002517s, corrective_pde_assign_previous=0.001534s, total_step=4.917590s
INFO:__main__:Solve for t=11.00, v.max() =np.float64(25.77961909630307), v.min() =np.float64(-89.34573319189356)
INFO:__main__:Average solver time per time step: 0.02242 s
INFO:__main__:{'P1': 1.2000000000000004, 'P2': -1.0, 'P3': -1.0, 'P4': -1.0, 'P5': -1.0, 'P6': -1.0, 'P7': -1.0, 'P8': -1.0, 'P9': -1.0}
INFO:beat.telemetry:PDE step timing step=240, t=(11.95000, 12.00000), ksp_iterations=5, ksp_residual_norm=6.425920e-03, ksp_converged_reason=2, ode_function_call=4.972168s, ode_state_update=0.017530s, ode_total_step=4.997749s, ode_step=2.296347s, ode_to_dolfin=0.004867s, ode_to_pde=0.003058s, pde_assign_previous_before=0.001924s, pde_set_time=0.002527s, pde_update_matrices=0.019384s, pde_update_rhs=0.055146s, pde_linear_solve=0.224403s, pde_scatter_forward=0.000918s, pde_total_step=0.308571s, pde_step=0.309448s, pde_to_ode=0.003875s, ode_from_dolfin=0.001207s, corrective_ode_step=2.703893s, corrective_ode_to_dolfin=0.004812s, corrective_ode_to_pde=0.002715s, corrective_pde_assign_previous=0.001660s, total_step=5.358545s
INFO:__main__:Solve for t=12.00, v.max() =np.float64(24.976281501934604), v.min() =np.float64(-89.57995599834642)
INFO:__main__:Average solver time per time step: 0.02239 s
INFO:__main__:{'P1': 1.2000000000000004, 'P2': -1.0, 'P3': -1.0, 'P4': -1.0, 'P5': -1.0, 'P6': -1.0, 'P7': -1.0, 'P8': -1.0, 'P9': -1.0}
INFO:beat.telemetry:PDE step timing step=260, t=(12.95000, 13.00000), ksp_iterations=5, ksp_residual_norm=6.417321e-03, ksp_converged_reason=2, ode_function_call=5.388312s, ode_state_update=0.018905s, ode_total_step=5.415945s, ode_step=2.482246s, ode_to_dolfin=0.005241s, ode_to_pde=0.003303s, pde_assign_previous_before=0.002078s, pde_set_time=0.002731s, pde_update_matrices=0.019384s, pde_update_rhs=0.059615s, pde_linear_solve=0.242985s, pde_scatter_forward=0.000987s, pde_total_step=0.332387s, pde_step=0.333333s, pde_to_ode=0.004188s, ode_from_dolfin=0.001313s, corrective_ode_step=2.936416s, corrective_ode_to_dolfin=0.005191s, corrective_ode_to_pde=0.002939s, corrective_pde_assign_previous=0.001830s, total_step=5.804805s
INFO:__main__:Solve for t=13.00, v.max() =np.float64(29.844408448305273), v.min() =np.float64(-89.94377509386747)
INFO:__main__:Average solver time per time step: 0.02239 s
INFO:__main__:{'P1': 1.2000000000000004, 'P2': -1.0, 'P3': -1.0, 'P4': -1.0, 'P5': -1.0, 'P6': -1.0, 'P7': -1.0, 'P8': -1.0, 'P9': -1.0}
INFO:beat.telemetry:PDE step timing step=280, t=(13.95000, 14.00000), ksp_iterations=5, ksp_residual_norm=6.399162e-03, ksp_converged_reason=2, ode_function_call=5.789464s, ode_state_update=0.020355s, ode_total_step=5.819212s, ode_step=2.667839s, ode_to_dolfin=0.005696s, ode_to_pde=0.003543s, pde_assign_previous_before=0.002230s, pde_set_time=0.002946s, pde_update_matrices=0.019384s, pde_update_rhs=0.064048s, pde_linear_solve=0.262114s, pde_scatter_forward=0.001058s, pde_total_step=0.356747s, pde_step=0.357760s, pde_to_ode=0.004489s, ode_from_dolfin=0.001412s, corrective_ode_step=3.154300s, corrective_ode_to_dolfin=0.005581s, corrective_ode_to_pde=0.003159s, corrective_pde_assign_previous=0.001968s, total_step=6.236765s
INFO:__main__:Solve for t=14.00, v.max() =np.float64(32.193795740671426), v.min() =np.float64(-90.92037859975402)
INFO:__main__:Average solver time per time step: 0.02234 s
INFO:__main__:{'P1': 1.2000000000000004, 'P2': -1.0, 'P3': -1.0, 'P4': -1.0, 'P5': 13.950000000000063, 'P6': -1.0, 'P7': -1.0, 'P8': -1.0, 'P9': -1.0}
INFO:beat.telemetry:PDE step timing step=300, t=(14.95000, 15.00000), ksp_iterations=5, ksp_residual_norm=6.323618e-03, ksp_converged_reason=2, ode_function_call=6.208083s, ode_state_update=0.021836s, ode_total_step=6.240048s, ode_step=2.855529s, ode_to_dolfin=0.006123s, ode_to_pde=0.003796s, pde_assign_previous_before=0.002386s, pde_set_time=0.003160s, pde_update_matrices=0.019384s, pde_update_rhs=0.068826s, pde_linear_solve=0.280768s, pde_scatter_forward=0.001138s, pde_total_step=0.380990s, pde_step=0.382078s, pde_to_ode=0.004824s, ode_from_dolfin=0.001515s, corrective_ode_step=3.387668s, corrective_ode_to_dolfin=0.006023s, corrective_ode_to_pde=0.003405s, corrective_pde_assign_previous=0.002131s, total_step=6.686407s
INFO:__main__:Solve for t=15.00, v.max() =np.float64(30.77132377328577), v.min() =np.float64(-90.83784712025061)
INFO:__main__:Average solver time per time step: 0.02235 s
INFO:__main__:{'P1': 1.2000000000000004, 'P2': -1.0, 'P3': -1.0, 'P4': -1.0, 'P5': 13.950000000000063, 'P6': -1.0, 'P7': -1.0, 'P8': -1.0, 'P9': -1.0}
INFO:beat.telemetry:PDE step timing step=320, t=(15.95000, 16.00000), ksp_iterations=5, ksp_residual_norm=6.254713e-03, ksp_converged_reason=2, ode_function_call=6.625301s, ode_state_update=0.023180s, ode_total_step=6.659214s, ode_step=3.041782s, ode_to_dolfin=0.006532s, ode_to_pde=0.004034s, pde_assign_previous_before=0.002535s, pde_set_time=0.003358s, pde_update_matrices=0.019384s, pde_update_rhs=0.073427s, pde_linear_solve=0.299083s, pde_scatter_forward=0.001227s, pde_total_step=0.404687s, pde_step=0.405840s, pde_to_ode=0.005168s, ode_from_dolfin=0.001619s, corrective_ode_step=3.620774s, corrective_ode_to_dolfin=0.006373s, corrective_ode_to_pde=0.003613s, corrective_pde_assign_previous=0.002264s, total_step=7.133399s
INFO:__main__:Solve for t=16.00, v.max() =np.float64(32.71358424809098), v.min() =np.float64(-91.21420917904523)
INFO:__main__:Average solver time per time step: 0.02236 s
INFO:__main__:{'P1': 1.2000000000000004, 'P2': -1.0, 'P3': -1.0, 'P4': -1.0, 'P5': 13.950000000000063, 'P6': -1.0, 'P7': -1.0, 'P8': -1.0, 'P9': -1.0}
INFO:beat.telemetry:PDE step timing step=340, t=(16.95000, 17.00000), ksp_iterations=5, ksp_residual_norm=6.199157e-03, ksp_converged_reason=2, ode_function_call=7.028516s, ode_state_update=0.024435s, ode_total_step=7.064177s, ode_step=3.234752s, ode_to_dolfin=0.006838s, ode_to_pde=0.004258s, pde_assign_previous_before=0.002683s, pde_set_time=0.003533s, pde_update_matrices=0.019384s, pde_update_rhs=0.077732s, pde_linear_solve=0.317314s, pde_scatter_forward=0.001287s, pde_total_step=0.427942s, pde_step=0.429158s, pde_to_ode=0.005477s, ode_from_dolfin=0.001721s, corrective_ode_step=3.832946s, corrective_ode_to_dolfin=0.006633s, corrective_ode_to_pde=0.003799s, corrective_pde_assign_previous=0.002412s, total_step=7.565370s
INFO:__main__:Solve for t=17.00, v.max() =np.float64(28.23484286782743), v.min() =np.float64(-91.9000287117351)
INFO:__main__:Average solver time per time step: 0.02232 s
INFO:__main__:{'P1': 1.2000000000000004, 'P2': -1.0, 'P3': -1.0, 'P4': -1.0, 'P5': 13.950000000000063, 'P6': -1.0, 'P7': -1.0, 'P8': -1.0, 'P9': -1.0}
INFO:beat.telemetry:PDE step timing step=360, t=(17.95000, 18.00000), ksp_iterations=5, ksp_residual_norm=6.202618e-03, ksp_converged_reason=2, ode_function_call=7.428839s, ode_state_update=0.025827s, ode_total_step=7.466528s, ode_step=3.420309s, ode_to_dolfin=0.007238s, ode_to_pde=0.004525s, pde_assign_previous_before=0.002845s, pde_set_time=0.003736s, pde_update_matrices=0.019384s, pde_update_rhs=0.082102s, pde_linear_solve=0.335750s, pde_scatter_forward=0.001357s, pde_total_step=0.451508s, pde_step=0.452791s, pde_to_ode=0.005790s, ode_from_dolfin=0.001819s, corrective_ode_step=4.049931s, corrective_ode_to_dolfin=0.007007s, corrective_ode_to_pde=0.004017s, corrective_pde_assign_previous=0.002549s, total_step=7.995485s
INFO:__main__:Solve for t=18.00, v.max() =np.float64(28.399731930570578), v.min() =np.float64(-91.7604120420496)
INFO:__main__:Average solver time per time step: 0.02227 s
INFO:__main__:{'P1': 1.2000000000000004, 'P2': -1.0, 'P3': -1.0, 'P4': -1.0, 'P5': 13.950000000000063, 'P6': -1.0, 'P7': -1.0, 'P8': -1.0, 'P9': -1.0}
INFO:beat.telemetry:PDE step timing step=380, t=(18.95000, 19.00000), ksp_iterations=5, ksp_residual_norm=6.121732e-03, ksp_converged_reason=2, ode_function_call=7.837717s, ode_state_update=0.027108s, ode_total_step=7.877235s, ode_step=3.603228s, ode_to_dolfin=0.007573s, ode_to_pde=0.004759s, pde_assign_previous_before=0.002998s, pde_set_time=0.003952s, pde_update_matrices=0.019384s, pde_update_rhs=0.086411s, pde_linear_solve=0.354258s, pde_scatter_forward=0.001419s, pde_total_step=0.475081s, pde_step=0.476429s, pde_to_ode=0.006107s, ode_from_dolfin=0.001921s, corrective_ode_step=4.277900s, corrective_ode_to_dolfin=0.007299s, corrective_ode_to_pde=0.004215s, corrective_pde_assign_previous=0.002670s, total_step=8.433670s
INFO:__main__:Solve for t=19.00, v.max() =np.float64(28.20425286106496), v.min() =np.float64(-92.23968057022388)
INFO:__main__:Average solver time per time step: 0.02226 s
INFO:__main__:{'P1': 1.2000000000000004, 'P2': -1.0, 'P3': -1.0, 'P4': -1.0, 'P5': 13.950000000000063, 'P6': -1.0, 'P7': -1.0, 'P8': -1.0, 'P9': -1.0}
INFO:beat.telemetry:PDE step timing step=400, t=(19.95000, 20.00000), ksp_iterations=5, ksp_residual_norm=6.054626e-03, ksp_converged_reason=2, ode_function_call=8.233675s, ode_state_update=0.028390s, ode_total_step=8.274975s, ode_step=3.786399s, ode_to_dolfin=0.007888s, ode_to_pde=0.005007s, pde_assign_previous_before=0.003149s, pde_set_time=0.004128s, pde_update_matrices=0.019384s, pde_update_rhs=0.090693s, pde_linear_solve=0.372810s, pde_scatter_forward=0.001479s, pde_total_step=0.498647s, pde_step=0.500062s, pde_to_ode=0.006439s, ode_from_dolfin=0.002019s, corrective_ode_step=4.492653s, corrective_ode_to_dolfin=0.007567s, corrective_ode_to_pde=0.004408s, corrective_pde_assign_previous=0.002823s, total_step=8.858831s
INFO:__main__:Solve for t=20.00, v.max() =np.float64(27.22452398551434), v.min() =np.float64(-92.13131686395846)
INFO:__main__:Average solver time per time step: 0.02221 s
INFO:__main__:{'P1': 1.2000000000000004, 'P2': -1.0, 'P3': -1.0, 'P4': -1.0, 'P5': 13.950000000000063, 'P6': -1.0, 'P7': -1.0, 'P8': -1.0, 'P9': -1.0}
INFO:beat.telemetry:
==================================================
PERFORMANCE SUMMARY
==================================================
Total Steps: 401
KSP Total Iterations: 2005
KSP Max Iterations: 5
--------------------------------------------------
Metric | Time (s)
--------------------------------------------------
total_step | 8.8802
ode_total_step | 8.2950
ode_function_call | 8.2536
corrective_ode_step | 4.5035
ode_step | 3.7956
pde_step | 0.5012
pde_total_step | 0.4998
pde_linear_solve | 0.3737
pde_update_rhs | 0.0909
ode_state_update | 0.0285
pde_update_matrices | 0.0194
ode_to_dolfin | 0.0079
corrective_ode_to_dolfin | 0.0076
pde_to_ode | 0.0065
ode_to_pde | 0.0050
corrective_ode_to_pde | 0.0044
pde_set_time | 0.0041
pde_assign_previous_before | 0.0032
corrective_pde_assign_previous | 0.0028
ode_from_dolfin | 0.0020
pde_scatter_forward | 0.0015
==================================================
INFO:beat.telemetry:Performance summary saved to results-niederer-benchmark/performance_summary.json

# Save activation times
activation_times["dx"] = dx
activation_times["dt"] = dt
at_file_name = output_dir / "activation_times.json"
if at_file_name.is_file():
all_at = json.loads(at_file_name.read_text())
else:
all_at = []
all_at.append(activation_times)
at_file_name.write_text(json.dumps(all_at, indent=2))
213
The activation times are saved in the file output-niederer-benchmark/activation_times.json.
The file contains a list of dictionaries, each dictionary contains the activation times for a specific dx and dt.
Here are the activation times for the different dx and dt:
dx |
dt |
P1 |
P2 |
P3 |
P4 |
P5 |
P6 |
P7 |
P8 |
P9 |
|
|---|---|---|---|---|---|---|---|---|---|---|---|
0 |
0.5 |
0.05 |
1.25 |
51.1 |
34.9 |
58.9 |
14.1 |
49.5 |
34 |
56.65 |
26.05 |
1 |
0.5 |
0.01 |
1.22 |
50.85 |
33.96 |
58.05 |
13.98 |
49.36 |
33.07 |
55.91 |
25.64 |
2 |
0.5 |
0.005 |
1.215 |
50.775 |
33.825 |
57.96 |
13.97 |
49.345 |
32.945 |
55.825 |
25.595 |
3 |
0.2 |
0.05 |
1.25 |
29.7 |
32.9 |
40.2 |
9.55 |
30 |
32.95 |
39.9 |
18.9 |
4 |
0.2 |
0.01 |
1.24 |
29.09 |
31.25 |
38.66 |
9.34 |
29.4 |
31.29 |
38.42 |
18.14 |
5 |
0.2 |
0.005 |
1.235 |
29.015 |
31.05 |
38.475 |
9.315 |
29.32 |
31.08 |
38.235 |
18.045 |
6 |
0.1 |
0.05 |
1.25 |
26.85 |
33.3 |
40.35 |
8.4 |
27.5 |
33.85 |
40.55 |
18.95 |
7 |
0.1 |
0.01 |
1.23 |
25.64 |
31.46 |
38.08 |
8.03 |
26.24 |
31.94 |
38.21 |
17.95 |
8 |
0.1 |
0.005 |
1.225 |
25.5 |
31.26 |
37.81 |
7.99 |
26.09 |
31.72 |
37.93 |
17.835 |
Martin J. Bishop and Gernot Plank. Representing cardiac bidomain bath-loading effects by an augmented monodomain approach: application to complex ventricular models. IEEE Transactions on Biomedical Engineering, 58(4):1066–1075, 2011. doi:10.1109/TBME.2010.2096425.
Caroline Mendonca Costa, Elena Hoetzl, Bernardo Martins Rocha, Anton J. Prassl, and Gernot Plank. Automatic parameterization strategy for cardiac electrophysiology simulations. In Computing in Cardiology, volume 40, 373–376. 2013.
Dirk Durrer, R Th van Dam, GE Freud, MJ Janse, FL Meijler, and RC Arzbaecher. Total excitation of the isolated human heart. Circulation, 41(6):899–912, 1970. doi:10.1161/01.CIR.41.6.899.
Flavio Fenton and Alain Karma. Vortex dynamics in three-dimensional continuous myocardium with fiber rotation: filament instability and fibrillation. Chaos: An Interdisciplinary Journal of Nonlinear Science, 8(1):20–47, 1998. doi:10.1063/1.166311.
Zhisong Fu, Robert M. Kirby, and Ross T. Whitaker. A fast iterative method for solving the eikonal equation on tetrahedral domains. SIAM Journal on Scientific Computing, 35(5):C473–C494, 2013. doi:10.1137/120881956.
Won-Ki Jeong and Ross T. Whitaker. A fast iterative method for eikonal equations. SIAM Journal on Scientific Computing, 30(5):2512–2534, 2008. doi:10.1137/060670298.
Sander Land, Viatcheslav Gurev, Sander Arens, Christoph M Augustin, Lukas Baron, Robert Blake, Chris Bradley, Sebastian Castro, Andrew Crozier, Marco Favino, and others. Verification of cardiac mechanics software: benchmark problems and solutions for testing active and passive material behavior. Proceedings of the Royal Society A: Mathematical, Physical and Engineering Sciences, 471(2184):20150641, 2015.
Aurel Neic, Fernando O. Campos, Anton J. Prassl, Steven A. Niederer, Martin J. Bishop, Edward J. Vigmond, and Gernot Plank. Efficient computation of electrograms and ECGs in human whole heart simulations using a reaction-eikonal model. Journal of Computational Physics, 346:191–211, 2017. doi:10.1016/j.jcp.2017.06.020.
Steven A. Niederer, Eric Kerfoot, Alan P. Benson, Miguel O. Bernabeu, Olivier Bernus, Chris Bradley, Elizabeth M. Cherry, Richard Clayton, Flavio H. Fenton, Alan Garny, Elvio Heidenreich, Sander Land, Mary Maleckar, Pras Pathmanathan, Gernot Plank, José F. Rodríguez, Ishani Roy, Frank B. Sachse, Gunnar Seemann, Ola Skavhaug, and Nic P. Smith. Verification of cardiac tissue electrophysiology simulators using an N-version benchmark. Philosophical Transactions of the Royal Society A, 369(1954):4331–4351, 2011. doi:10.1098/rsta.2011.0139.
Joakim Sundnes, Glenn Terje Lines, Xing Cai, Bjørn Frederik Nielsen, Kent-Andre Mardal, and Aslak Tveito. Computing the electrical activity in the heart. Volume 1. Springer Science & Business Media, 2007.
Kirsten H W J ten Tusscher, Denis Noble, Peter J Noble, and Alexander V Panfilov. A model for human ventricular tissue. American Journal of Physiology-Heart and Circulatory Physiology, 286(4):H1573–H1589, 2004. doi:10.1152/ajpheart.00794.2003.
Kirsten H W J ten Tusscher and Alexander V Panfilov. Alternans and spiral breakup in a human ventricular tissue model. American Journal of Physiology-Heart and Circulatory Physiology, 291(3):H1088–H1100, 2006. doi:10.1152/ajpheart.00109.2006.
Zhaoyang Zhang, Michael B Liu, Xiaodong Huang, Zhen Song, and Zhilin Qu. Mechanisms of premature ventricular complexes caused by qt prolongation. Biophysical journal, 120(2):352–369, 2021.