simcardemsx 0.2.0__tar.gz → 0.4.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {simcardemsx-0.2.0/src/simcardemsx.egg-info → simcardemsx-0.4.0}/PKG-INFO +81 -22
- simcardemsx-0.4.0/README.md +198 -0
- {simcardemsx-0.2.0 → simcardemsx-0.4.0}/pyproject.toml +47 -7
- {simcardemsx-0.2.0 → simcardemsx-0.4.0}/src/simcardemsx/checkpoint.py +1 -1
- {simcardemsx-0.2.0 → simcardemsx-0.4.0}/src/simcardemsx/controller.py +24 -7
- simcardemsx-0.4.0/src/simcardemsx/ode_model.py +263 -0
- {simcardemsx-0.2.0 → simcardemsx-0.4.0}/src/simcardemsx/zero_d.py +8 -0
- {simcardemsx-0.2.0 → simcardemsx-0.4.0/src/simcardemsx.egg-info}/PKG-INFO +81 -22
- {simcardemsx-0.2.0 → simcardemsx-0.4.0}/src/simcardemsx.egg-info/SOURCES.txt +6 -0
- {simcardemsx-0.2.0 → simcardemsx-0.4.0}/src/simcardemsx.egg-info/requires.txt +13 -4
- simcardemsx-0.4.0/tests/test_biv_case.py +73 -0
- simcardemsx-0.4.0/tests/test_biv_cells.py +221 -0
- simcardemsx-0.4.0/tests/test_biv_ep_mesh.py +304 -0
- simcardemsx-0.4.0/tests/test_biv_example.py +1375 -0
- {simcardemsx-0.2.0 → simcardemsx-0.4.0}/tests/test_checkpoint.py +27 -4
- simcardemsx-0.4.0/tests/test_compiled_ep.py +232 -0
- simcardemsx-0.4.0/tests/test_composed.py +161 -0
- {simcardemsx-0.2.0 → simcardemsx-0.4.0}/tests/test_coupled_system.py +29 -0
- {simcardemsx-0.2.0 → simcardemsx-0.4.0}/tests/test_crossbridge_coupling.py +10 -8
- simcardemsx-0.4.0/tests/test_demo_io.py +417 -0
- {simcardemsx-0.2.0 → simcardemsx-0.4.0}/tests/test_isolated_ep.py +3 -3
- {simcardemsx-0.2.0 → simcardemsx-0.4.0}/tests/test_ode_model.py +23 -2
- simcardemsx-0.4.0/tests/test_reaction_eikonal.py +129 -0
- {simcardemsx-0.2.0 → simcardemsx-0.4.0}/tests/test_rodero_case.py +72 -14
- simcardemsx-0.4.0/tests/test_rodero_example.py +932 -0
- {simcardemsx-0.2.0 → simcardemsx-0.4.0}/tests/test_rollback.py +43 -2
- {simcardemsx-0.2.0 → simcardemsx-0.4.0}/tests/test_scheme_report.py +64 -0
- {simcardemsx-0.2.0 → simcardemsx-0.4.0}/tests/test_slab_example.py +380 -11
- {simcardemsx-0.2.0 → simcardemsx-0.4.0}/tests/test_transfer_plan.py +2 -1
- {simcardemsx-0.2.0 → simcardemsx-0.4.0}/tests/test_zero_d_coupling.py +24 -0
- {simcardemsx-0.2.0 → simcardemsx-0.4.0}/tests/test_zero_mech_reference.py +12 -5
- simcardemsx-0.2.0/README.md +0 -148
- simcardemsx-0.2.0/src/simcardemsx/ode_model.py +0 -137
- simcardemsx-0.2.0/tests/test_biv_example.py +0 -187
- simcardemsx-0.2.0/tests/test_demo_io.py +0 -171
- simcardemsx-0.2.0/tests/test_rodero_example.py +0 -419
- {simcardemsx-0.2.0 → simcardemsx-0.4.0}/LICENSE +0 -0
- {simcardemsx-0.2.0 → simcardemsx-0.4.0}/setup.cfg +0 -0
- {simcardemsx-0.2.0 → simcardemsx-0.4.0}/src/simcardemsx/__init__.py +0 -0
- {simcardemsx-0.2.0 → simcardemsx-0.4.0}/src/simcardemsx/averaging.py +0 -0
- {simcardemsx-0.2.0 → simcardemsx-0.4.0}/src/simcardemsx/backends/__init__.py +0 -0
- {simcardemsx-0.2.0 → simcardemsx-0.4.0}/src/simcardemsx/backends/base.py +0 -0
- {simcardemsx-0.2.0 → simcardemsx-0.4.0}/src/simcardemsx/backends/generated.py +0 -0
- {simcardemsx-0.2.0 → simcardemsx-0.4.0}/src/simcardemsx/backends/segregated.py +0 -0
- {simcardemsx-0.2.0 → simcardemsx-0.4.0}/src/simcardemsx/backends/zeta_split.py +0 -0
- {simcardemsx-0.2.0 → simcardemsx-0.4.0}/src/simcardemsx/config.py +0 -0
- {simcardemsx-0.2.0 → simcardemsx-0.4.0}/src/simcardemsx/datacollector.py +0 -0
- {simcardemsx-0.2.0 → simcardemsx-0.4.0}/src/simcardemsx/interpolation.py +0 -0
- {simcardemsx-0.2.0 → simcardemsx-0.4.0}/src/simcardemsx/mechanics.py +0 -0
- {simcardemsx-0.2.0 → simcardemsx-0.4.0}/src/simcardemsx/provenance.py +0 -0
- {simcardemsx-0.2.0 → simcardemsx-0.4.0}/src/simcardemsx/py.typed +0 -0
- {simcardemsx-0.2.0 → simcardemsx-0.4.0}/src/simcardemsx/results.py +0 -0
- {simcardemsx-0.2.0 → simcardemsx-0.4.0}/src/simcardemsx/transfer_plan.py +0 -0
- {simcardemsx-0.2.0 → simcardemsx-0.4.0}/src/simcardemsx/units.py +0 -0
- {simcardemsx-0.2.0 → simcardemsx-0.4.0}/src/simcardemsx/utils.py +0 -0
- {simcardemsx-0.2.0 → simcardemsx-0.4.0}/src/simcardemsx.egg-info/dependency_links.txt +0 -0
- {simcardemsx-0.2.0 → simcardemsx-0.4.0}/src/simcardemsx.egg-info/top_level.txt +0 -0
- {simcardemsx-0.2.0 → simcardemsx-0.4.0}/tests/test_averaging.py +0 -0
- {simcardemsx-0.2.0 → simcardemsx-0.4.0}/tests/test_backends.py +0 -0
- {simcardemsx-0.2.0 → simcardemsx-0.4.0}/tests/test_checkpoint_backends.py +0 -0
- {simcardemsx-0.2.0 → simcardemsx-0.4.0}/tests/test_checkpoint_circulation.py +0 -0
- {simcardemsx-0.2.0 → simcardemsx-0.4.0}/tests/test_circulation.py +0 -0
- {simcardemsx-0.2.0 → simcardemsx-0.4.0}/tests/test_coupled_backend.py +0 -0
- {simcardemsx-0.2.0 → simcardemsx-0.4.0}/tests/test_cycle_coupling.py +0 -0
- {simcardemsx-0.2.0 → simcardemsx-0.4.0}/tests/test_datacollector.py +0 -0
- {simcardemsx-0.2.0 → simcardemsx-0.4.0}/tests/test_dynamic_coupling.py +0 -0
- {simcardemsx-0.2.0 → simcardemsx-0.4.0}/tests/test_generated_activation.py +0 -0
- {simcardemsx-0.2.0 → simcardemsx-0.4.0}/tests/test_interpolation.py +0 -0
- {simcardemsx-0.2.0 → simcardemsx-0.4.0}/tests/test_isolated_mechanics.py +0 -0
- {simcardemsx-0.2.0 → simcardemsx-0.4.0}/tests/test_mechanics_drivers.py +0 -0
- {simcardemsx-0.2.0 → simcardemsx-0.4.0}/tests/test_monolithic_coupling.py +0 -0
- {simcardemsx-0.2.0 → simcardemsx-0.4.0}/tests/test_provenance.py +0 -0
- {simcardemsx-0.2.0 → simcardemsx-0.4.0}/tests/test_results.py +0 -0
- {simcardemsx-0.2.0 → simcardemsx-0.4.0}/tests/test_round_trip.py +0 -0
- {simcardemsx-0.2.0 → simcardemsx-0.4.0}/tests/test_scheme_comparison.py +0 -0
- {simcardemsx-0.2.0 → simcardemsx-0.4.0}/tests/test_segregated_backend.py +0 -0
- {simcardemsx-0.2.0 → simcardemsx-0.4.0}/tests/test_stability.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: simcardemsx
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.4.0
|
|
4
4
|
Summary: Next generation cardiac electro-mechanics solver based on FEniCSx
|
|
5
5
|
Author-email: Henrik Finsberg <henriknf@simula.no>
|
|
6
6
|
License-Expression: MIT
|
|
@@ -17,12 +17,12 @@ Requires-Python: >=3.12.0
|
|
|
17
17
|
Description-Content-Type: text/markdown
|
|
18
18
|
License-File: LICENSE
|
|
19
19
|
Requires-Dist: fenics-dolfinx
|
|
20
|
-
Requires-Dist: fenicsx-pulse>=0.
|
|
21
|
-
Requires-Dist: fenicsx-beat>=0.
|
|
20
|
+
Requires-Dist: fenicsx-pulse>=0.13.1
|
|
21
|
+
Requires-Dist: fenicsx-beat>=0.16.0
|
|
22
22
|
Requires-Dist: crossbridge>=0.3.4
|
|
23
23
|
Requires-Dist: io4dolfinx[h5py]
|
|
24
24
|
Requires-Dist: scipy
|
|
25
|
-
Requires-Dist: gotranx>=2.
|
|
25
|
+
Requires-Dist: gotranx>=2.11.0
|
|
26
26
|
Requires-Dist: toml
|
|
27
27
|
Requires-Dist: pydantic
|
|
28
28
|
Requires-Dist: pydantic_pint
|
|
@@ -32,6 +32,7 @@ Requires-Dist: pytest-cov; extra == "test"
|
|
|
32
32
|
Requires-Dist: cardiac-geometriesx; extra == "test"
|
|
33
33
|
Requires-Dist: circulation>=0.4.0; extra == "test"
|
|
34
34
|
Requires-Dist: zero-mech>=0.3.0; extra == "test"
|
|
35
|
+
Requires-Dist: odezoo; extra == "test"
|
|
35
36
|
Provides-Extra: dev
|
|
36
37
|
Requires-Dist: pdbpp; extra == "dev"
|
|
37
38
|
Requires-Dist: ipython; extra == "dev"
|
|
@@ -45,7 +46,10 @@ Requires-Dist: cardiac-geometriesx; extra == "demo"
|
|
|
45
46
|
Requires-Dist: fenicsx-ldrb; extra == "demo"
|
|
46
47
|
Requires-Dist: ukb-atlas; extra == "demo"
|
|
47
48
|
Requires-Dist: circulation>=0.4.0; extra == "demo"
|
|
48
|
-
Requires-Dist: gotranx; extra == "demo"
|
|
49
|
+
Requires-Dist: gotranx>=2.11.0; extra == "demo"
|
|
50
|
+
Requires-Dist: odezoo; extra == "demo"
|
|
51
|
+
Requires-Dist: pyvista; extra == "demo"
|
|
52
|
+
Requires-Dist: imageio; extra == "demo"
|
|
49
53
|
Requires-Dist: io4dolfinx[h5py]; extra == "demo"
|
|
50
54
|
Provides-Extra: docs
|
|
51
55
|
Requires-Dist: mystmd; extra == "docs"
|
|
@@ -54,6 +58,11 @@ Requires-Dist: ipykernel; extra == "docs"
|
|
|
54
58
|
Requires-Dist: jupyter-server; extra == "docs"
|
|
55
59
|
Requires-Dist: griffe>=2; extra == "docs"
|
|
56
60
|
Requires-Dist: zero-mech>=0.3.0; extra == "docs"
|
|
61
|
+
Requires-Dist: odezoo; extra == "docs"
|
|
62
|
+
Requires-Dist: gotranx>=2.11.0; extra == "docs"
|
|
63
|
+
Requires-Dist: pyvista; extra == "docs"
|
|
64
|
+
Requires-Dist: imageio; extra == "docs"
|
|
65
|
+
Requires-Dist: trame-vtk>=2.11.15; extra == "docs"
|
|
57
66
|
Requires-Dist: simcardemsx[demo]; extra == "docs"
|
|
58
67
|
Provides-Extra: benchmark
|
|
59
68
|
Requires-Dist: pytest-codspeed; extra == "benchmark"
|
|
@@ -69,12 +78,18 @@ Dynamic: license-file
|
|
|
69
78
|
|
|
70
79
|
Cardiac electro-mechanics in [FEniCSx](https://fenicsproject.org).
|
|
71
80
|
|
|
81
|
+
[](https://computationalphysiology.github.io/simcardemsx/circulation-biv/)
|
|
82
|
+
|
|
83
|
+
*One beat of a biventricular heart in a closed-loop circulation, cut along its long axis:
|
|
84
|
+
the membrane potential on a fine EP mesh (left) and the displacement on the mechanics mesh
|
|
85
|
+
(right). From the [BiV application](https://computationalphysiology.github.io/simcardemsx/circulation-biv/).*
|
|
86
|
+
|
|
72
87
|
simcardemsx couples a model of cardiac electrophysiology (EP) to a model of tissue
|
|
73
88
|
mechanics, with the contraction of each cell in between. It does not solve either
|
|
74
89
|
physics itself. It connects two solvers that do:
|
|
75
90
|
|
|
76
91
|
- [fenicsx-beat](https://github.com/finsberg/fenicsx-beat) for EP (the monodomain
|
|
77
|
-
model);
|
|
92
|
+
model, or reaction-eikonal EP);
|
|
78
93
|
- [fenicsx-pulse](https://github.com/finsberg/fenicsx-pulse) for the mechanics, from a
|
|
79
94
|
single element to a beating heart in a circulation model.
|
|
80
95
|
|
|
@@ -90,19 +105,60 @@ coupled with the stabilized scheme of the same paper instead.
|
|
|
90
105
|
|
|
91
106
|
📖 **Documentation**: <https://computationalphysiology.github.io/simcardemsx>
|
|
92
107
|
|
|
108
|
+
## How it fits together
|
|
109
|
+
|
|
110
|
+
```mermaid
|
|
111
|
+
flowchart LR
|
|
112
|
+
zoo["published models<br/>(odezoo) + glue"] -.->|"gotranx compose"| ode
|
|
113
|
+
ode[".ode cell model<br/>EP + contraction"] -->|"split, generate"| ep["EP half<br/>NumPy or C"]
|
|
114
|
+
ode -->|"split, generate"| ufl["contraction half<br/>UFL"]
|
|
115
|
+
ep --> beat["beat: EP<br/>monodomain or reaction-eikonal<br/>on the EP mesh"]
|
|
116
|
+
ufl --> backend["activation backend"]
|
|
117
|
+
xb["crossbridge<br/>NumPy models"] --> backend
|
|
118
|
+
beat <-->|"calcium, crossbridges, … ⇄ stretch, …"| backend
|
|
119
|
+
backend --> pulse["pulse: mechanics<br/>static or dynamic<br/>on the mechanics mesh"]
|
|
120
|
+
pulse <--> circ["0D circulation<br/>or cardiac cycle"]
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
A `SimulationController` takes the time steps: EP steps up to the next mechanics step,
|
|
124
|
+
what crosses is moved between the two meshes, and the mechanics is solved with the
|
|
125
|
+
contraction model inside its Newton iteration. The
|
|
126
|
+
[user guide](https://computationalphysiology.github.io/simcardemsx/overview/) explains each piece.
|
|
127
|
+
|
|
93
128
|
## Features
|
|
94
129
|
|
|
95
|
-
- One `.ode` file for the whole cell,
|
|
96
|
-
|
|
97
|
-
configured by hand.
|
|
98
|
-
- Separate meshes and time steps for EP and mechanics
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
130
|
+
- One `.ode` file for the whole cell, written by hand or composed from published models
|
|
131
|
+
with gotranx, and split anywhere between EP and contraction. Which variables cross
|
|
132
|
+
between the two sides is read off the generated code, not configured by hand.
|
|
133
|
+
- Separate meshes and time steps for EP and mechanics, such as a fine EP mesh nested in a
|
|
134
|
+
coarse mechanics mesh.
|
|
135
|
+
- EP from beat: the monodomain model or reaction-eikonal EP, activated by a stimulus, an
|
|
136
|
+
eikonal solve or Durrer's endocardial sequence, with the cell model stepped in NumPy or
|
|
137
|
+
in compiled C.
|
|
138
|
+
- Three coupling schemes: monolithic (the default), stabilized segregated, and the naive
|
|
139
|
+
segregated scheme for comparison. The contraction model is the `.ode` file's own, or
|
|
140
|
+
one of crossbridge's.
|
|
141
|
+
- Static and dynamic mechanics, prestressing to the unloaded state, closed-loop
|
|
142
|
+
circulation (Regazzoni's 0D circuit) and open-loop cardiac cycles, through pulse.
|
|
103
143
|
- Rollback of a failed time step, and checkpoints that a run continues from in a new
|
|
104
144
|
process (bit for bit under pulse's default direct solver).
|
|
105
145
|
|
|
146
|
+
## Gallery
|
|
147
|
+
|
|
148
|
+
Each image links to the page of the application that made it.
|
|
149
|
+
|
|
150
|
+
| | |
|
|
151
|
+
| --- | --- |
|
|
152
|
+
| [](https://computationalphysiology.github.io/simcardemsx/slab/) | [](https://computationalphysiology.github.io/simcardemsx/rodero/) |
|
|
153
|
+
| **[Slab](https://computationalphysiology.github.io/simcardemsx/slab/)**: ToR-ORd + Land composed from published models and split three ways, coloured by the active tension. | **[Rodero BiV](https://computationalphysiology.github.io/simcardemsx/rodero/)**: a heart from a virtual cohort through the five phases of the cardiac cycle, with reaction-eikonal activation. |
|
|
154
|
+
|
|
155
|
+
[](https://computationalphysiology.github.io/simcardemsx/scheme-comparison/)
|
|
156
|
+
|
|
157
|
+
**[Coupling schemes](https://computationalphysiology.github.io/simcardemsx/scheme-comparison/)**: on one soft element, the error of each
|
|
158
|
+
scheme against a monolithic reference as the time step shrinks. The naive segregated scheme
|
|
159
|
+
(open squares) fails at every time step, while the stabilized one converges at first
|
|
160
|
+
order.
|
|
161
|
+
|
|
106
162
|
## Installation
|
|
107
163
|
|
|
108
164
|
simcardemsx needs [DOLFINx](https://github.com/FEniCS/dolfinx), which is not
|
|
@@ -160,7 +216,7 @@ from simcardemsx.controller import SimulationController
|
|
|
160
216
|
|
|
161
217
|
controller = SimulationController(
|
|
162
218
|
mechanics=problem, # a pulse.StaticProblem or DynamicProblem using `model`
|
|
163
|
-
ep_solver=ep_solver, # a beat.
|
|
219
|
+
ep_solver=ep_solver, # a beat.SplittingSolver
|
|
164
220
|
backend=backend,
|
|
165
221
|
ode_modules=modules,
|
|
166
222
|
dt_mech=1.0, # ms
|
|
@@ -170,18 +226,19 @@ while controller.t < 200.0:
|
|
|
170
226
|
controller.step()
|
|
171
227
|
```
|
|
172
228
|
|
|
173
|
-
The [tutorials](https://github.
|
|
229
|
+
The [tutorials](https://computationalphysiology.github.io/simcardemsx/cell-model/) build this up step by step, from one cell to a
|
|
174
230
|
coupled slab.
|
|
175
231
|
|
|
176
232
|
## Examples
|
|
177
233
|
|
|
178
|
-
[`examples/`](https://github.com/ComputationalPhysiology/simcardemsx/tree/main/examples) holds
|
|
179
|
-
applications:
|
|
234
|
+
[`examples/`](https://github.com/ComputationalPhysiology/simcardemsx/tree/main/examples) holds eight short tutorials, executed when the
|
|
235
|
+
documentation is built, and four larger applications:
|
|
180
236
|
|
|
181
|
-
- an electro-mechanical slab, for any split, scheme or contraction model;
|
|
182
|
-
- a biventricular heart
|
|
183
|
-
|
|
184
|
-
- a convergence study of the coupling schemes.
|
|
237
|
+
- [an electro-mechanical slab](https://computationalphysiology.github.io/simcardemsx/slab/), for any split, scheme or contraction model;
|
|
238
|
+
- [a biventricular heart from the Rodero cohort](https://computationalphysiology.github.io/simcardemsx/rodero/), driven through the
|
|
239
|
+
cardiac cycle;
|
|
240
|
+
- [a convergence study of the coupling schemes](https://computationalphysiology.github.io/simcardemsx/scheme-comparison/);
|
|
241
|
+
- [a biventricular heart beating in a closed-loop circulation](https://computationalphysiology.github.io/simcardemsx/circulation-biv/).
|
|
185
242
|
|
|
186
243
|
## Development
|
|
187
244
|
|
|
@@ -194,6 +251,8 @@ pre-commit run --all # ruff, mypy, cspell, …
|
|
|
194
251
|
|
|
195
252
|
The documentation is built with [MyST](https://mystmd.org). See
|
|
196
253
|
[`docs/README.md`](https://github.com/ComputationalPhysiology/simcardemsx/blob/main/docs/README.md).
|
|
254
|
+
[`CONTRIBUTING.md`](https://github.com/ComputationalPhysiology/simcardemsx/blob/main/CONTRIBUTING.md)
|
|
255
|
+
describes the development environment and how to open a pull request.
|
|
197
256
|
|
|
198
257
|
## References
|
|
199
258
|
|
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
# simcardemsx
|
|
2
|
+
|
|
3
|
+
Cardiac electro-mechanics in [FEniCSx](https://fenicsproject.org).
|
|
4
|
+
|
|
5
|
+
[](https://computationalphysiology.github.io/simcardemsx/circulation-biv/)
|
|
6
|
+
|
|
7
|
+
*One beat of a biventricular heart in a closed-loop circulation, cut along its long axis:
|
|
8
|
+
the membrane potential on a fine EP mesh (left) and the displacement on the mechanics mesh
|
|
9
|
+
(right). From the [BiV application](https://computationalphysiology.github.io/simcardemsx/circulation-biv/).*
|
|
10
|
+
|
|
11
|
+
simcardemsx couples a model of cardiac electrophysiology (EP) to a model of tissue
|
|
12
|
+
mechanics, with the contraction of each cell in between. It does not solve either
|
|
13
|
+
physics itself. It connects two solvers that do:
|
|
14
|
+
|
|
15
|
+
- [fenicsx-beat](https://github.com/finsberg/fenicsx-beat) for EP (the monodomain
|
|
16
|
+
model, or reaction-eikonal EP);
|
|
17
|
+
- [fenicsx-pulse](https://github.com/finsberg/fenicsx-pulse) for the mechanics, from a
|
|
18
|
+
single element to a beating heart in a circulation model.
|
|
19
|
+
|
|
20
|
+
The cell model, EP and contraction alike, is a single
|
|
21
|
+
[gotranx](https://github.com/finsberg/gotranx) `.ode` file. simcardemsx splits it in two
|
|
22
|
+
and generates code for each half. The EP half is NumPy code for beat. The contraction
|
|
23
|
+
half is UFL, which the mechanics solver can differentiate through, so the contraction
|
|
24
|
+
model can be stepped *inside* the mechanics Newton iteration. That removes the
|
|
25
|
+
instability the usual staggered coupling suffers from when the tissue is soft
|
|
26
|
+
(Regazzoni & Quarteroni, 2021). Models that cannot be written in UFL, such as the NumPy
|
|
27
|
+
models of [crossbridge](https://github.com/ComputationalPhysiology/crossbridge), are
|
|
28
|
+
coupled with the stabilized scheme of the same paper instead.
|
|
29
|
+
|
|
30
|
+
📖 **Documentation**: <https://computationalphysiology.github.io/simcardemsx>
|
|
31
|
+
|
|
32
|
+
## How it fits together
|
|
33
|
+
|
|
34
|
+
```mermaid
|
|
35
|
+
flowchart LR
|
|
36
|
+
zoo["published models<br/>(odezoo) + glue"] -.->|"gotranx compose"| ode
|
|
37
|
+
ode[".ode cell model<br/>EP + contraction"] -->|"split, generate"| ep["EP half<br/>NumPy or C"]
|
|
38
|
+
ode -->|"split, generate"| ufl["contraction half<br/>UFL"]
|
|
39
|
+
ep --> beat["beat: EP<br/>monodomain or reaction-eikonal<br/>on the EP mesh"]
|
|
40
|
+
ufl --> backend["activation backend"]
|
|
41
|
+
xb["crossbridge<br/>NumPy models"] --> backend
|
|
42
|
+
beat <-->|"calcium, crossbridges, … ⇄ stretch, …"| backend
|
|
43
|
+
backend --> pulse["pulse: mechanics<br/>static or dynamic<br/>on the mechanics mesh"]
|
|
44
|
+
pulse <--> circ["0D circulation<br/>or cardiac cycle"]
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
A `SimulationController` takes the time steps: EP steps up to the next mechanics step,
|
|
48
|
+
what crosses is moved between the two meshes, and the mechanics is solved with the
|
|
49
|
+
contraction model inside its Newton iteration. The
|
|
50
|
+
[user guide](https://computationalphysiology.github.io/simcardemsx/overview/) explains each piece.
|
|
51
|
+
|
|
52
|
+
## Features
|
|
53
|
+
|
|
54
|
+
- One `.ode` file for the whole cell, written by hand or composed from published models
|
|
55
|
+
with gotranx, and split anywhere between EP and contraction. Which variables cross
|
|
56
|
+
between the two sides is read off the generated code, not configured by hand.
|
|
57
|
+
- Separate meshes and time steps for EP and mechanics, such as a fine EP mesh nested in a
|
|
58
|
+
coarse mechanics mesh.
|
|
59
|
+
- EP from beat: the monodomain model or reaction-eikonal EP, activated by a stimulus, an
|
|
60
|
+
eikonal solve or Durrer's endocardial sequence, with the cell model stepped in NumPy or
|
|
61
|
+
in compiled C.
|
|
62
|
+
- Three coupling schemes: monolithic (the default), stabilized segregated, and the naive
|
|
63
|
+
segregated scheme for comparison. The contraction model is the `.ode` file's own, or
|
|
64
|
+
one of crossbridge's.
|
|
65
|
+
- Static and dynamic mechanics, prestressing to the unloaded state, closed-loop
|
|
66
|
+
circulation (Regazzoni's 0D circuit) and open-loop cardiac cycles, through pulse.
|
|
67
|
+
- Rollback of a failed time step, and checkpoints that a run continues from in a new
|
|
68
|
+
process (bit for bit under pulse's default direct solver).
|
|
69
|
+
|
|
70
|
+
## Gallery
|
|
71
|
+
|
|
72
|
+
Each image links to the page of the application that made it.
|
|
73
|
+
|
|
74
|
+
| | |
|
|
75
|
+
| --- | --- |
|
|
76
|
+
| [](https://computationalphysiology.github.io/simcardemsx/slab/) | [](https://computationalphysiology.github.io/simcardemsx/rodero/) |
|
|
77
|
+
| **[Slab](https://computationalphysiology.github.io/simcardemsx/slab/)**: ToR-ORd + Land composed from published models and split three ways, coloured by the active tension. | **[Rodero BiV](https://computationalphysiology.github.io/simcardemsx/rodero/)**: a heart from a virtual cohort through the five phases of the cardiac cycle, with reaction-eikonal activation. |
|
|
78
|
+
|
|
79
|
+
[](https://computationalphysiology.github.io/simcardemsx/scheme-comparison/)
|
|
80
|
+
|
|
81
|
+
**[Coupling schemes](https://computationalphysiology.github.io/simcardemsx/scheme-comparison/)**: on one soft element, the error of each
|
|
82
|
+
scheme against a monolithic reference as the time step shrinks. The naive segregated scheme
|
|
83
|
+
(open squares) fails at every time step, while the stabilized one converges at first
|
|
84
|
+
order.
|
|
85
|
+
|
|
86
|
+
## Installation
|
|
87
|
+
|
|
88
|
+
simcardemsx needs [DOLFINx](https://github.com/FEniCS/dolfinx), which is not
|
|
89
|
+
installable from PyPI on its own. The simplest way to get it is the DOLFINx container:
|
|
90
|
+
|
|
91
|
+
```bash
|
|
92
|
+
docker run -ti -v $(pwd):/home/shared -w /home/shared ghcr.io/fenics/dolfinx/dolfinx:stable
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
Inside it, install simcardemsx with pip:
|
|
96
|
+
|
|
97
|
+
```bash
|
|
98
|
+
python3 -m pip install simcardemsx
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
or from source, with the dependencies of the examples:
|
|
102
|
+
|
|
103
|
+
```bash
|
|
104
|
+
git clone https://github.com/ComputationalPhysiology/simcardemsx.git
|
|
105
|
+
cd simcardemsx
|
|
106
|
+
python3 -m pip install -e ".[demo]"
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
The extras are `demo` (the examples), `test`, `docs` and `dev`.
|
|
110
|
+
|
|
111
|
+
## A first look
|
|
112
|
+
|
|
113
|
+
Generate the two halves of a cell model and see what crosses between them:
|
|
114
|
+
|
|
115
|
+
```python
|
|
116
|
+
from pathlib import Path
|
|
117
|
+
|
|
118
|
+
from simcardemsx.ode_model import load_ode_modules
|
|
119
|
+
|
|
120
|
+
odefile = Path("examples/odefiles/ToRORd_dynCl_endo_zetasplit.ode")
|
|
121
|
+
modules = load_ode_modules(odefile, Path("generated_odes"))
|
|
122
|
+
|
|
123
|
+
print(modules.mechanics.missing) # what contraction needs from EP: {'XS': 0, 'XW': 1}
|
|
124
|
+
print(modules.ep.missing) # what EP needs back: {'Zetas': 0, 'Zetaw': 1}
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
The contraction half becomes the active stress of a pulse model:
|
|
128
|
+
|
|
129
|
+
```python
|
|
130
|
+
from simcardemsx.backends import GeneratedActivation
|
|
131
|
+
|
|
132
|
+
backend = GeneratedActivation(modules.mechanics, mesh, f0, quadrature_degree=4)
|
|
133
|
+
model = pulse.CardiacModel(material=material, active=backend, compressibility=compressibility)
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
and `SimulationController` steps EP and mechanics together:
|
|
137
|
+
|
|
138
|
+
```python
|
|
139
|
+
from simcardemsx.controller import SimulationController
|
|
140
|
+
|
|
141
|
+
controller = SimulationController(
|
|
142
|
+
mechanics=problem, # a pulse.StaticProblem or DynamicProblem using `model`
|
|
143
|
+
ep_solver=ep_solver, # a beat.SplittingSolver
|
|
144
|
+
backend=backend,
|
|
145
|
+
ode_modules=modules,
|
|
146
|
+
dt_mech=1.0, # ms
|
|
147
|
+
dt_ep=0.05, # ms
|
|
148
|
+
)
|
|
149
|
+
while controller.t < 200.0:
|
|
150
|
+
controller.step()
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
The [tutorials](https://computationalphysiology.github.io/simcardemsx/cell-model/) build this up step by step, from one cell to a
|
|
154
|
+
coupled slab.
|
|
155
|
+
|
|
156
|
+
## Examples
|
|
157
|
+
|
|
158
|
+
[`examples/`](https://github.com/ComputationalPhysiology/simcardemsx/tree/main/examples) holds eight short tutorials, executed when the
|
|
159
|
+
documentation is built, and four larger applications:
|
|
160
|
+
|
|
161
|
+
- [an electro-mechanical slab](https://computationalphysiology.github.io/simcardemsx/slab/), for any split, scheme or contraction model;
|
|
162
|
+
- [a biventricular heart from the Rodero cohort](https://computationalphysiology.github.io/simcardemsx/rodero/), driven through the
|
|
163
|
+
cardiac cycle;
|
|
164
|
+
- [a convergence study of the coupling schemes](https://computationalphysiology.github.io/simcardemsx/scheme-comparison/);
|
|
165
|
+
- [a biventricular heart beating in a closed-loop circulation](https://computationalphysiology.github.io/simcardemsx/circulation-biv/).
|
|
166
|
+
|
|
167
|
+
## Development
|
|
168
|
+
|
|
169
|
+
```bash
|
|
170
|
+
python3 -m pip install -e ".[dev,test]"
|
|
171
|
+
python3 -m pytest # the test suite
|
|
172
|
+
python3 -m pytest -m "not slow" # the fast part of it
|
|
173
|
+
pre-commit run --all # ruff, mypy, cspell, …
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
The documentation is built with [MyST](https://mystmd.org). See
|
|
177
|
+
[`docs/README.md`](https://github.com/ComputationalPhysiology/simcardemsx/blob/main/docs/README.md).
|
|
178
|
+
[`CONTRIBUTING.md`](https://github.com/ComputationalPhysiology/simcardemsx/blob/main/CONTRIBUTING.md)
|
|
179
|
+
describes the development environment and how to open a pull request.
|
|
180
|
+
|
|
181
|
+
## References
|
|
182
|
+
|
|
183
|
+
- F. Regazzoni and A. Quarteroni. An oscillation-free fully staggered algorithm for
|
|
184
|
+
velocity-dependent active models of cardiac mechanics. *Computer Methods in Applied
|
|
185
|
+
Mechanics and Engineering* 373, 113506 (2021).
|
|
186
|
+
- J. Tomek et al. Development, calibration, and validation of a novel human ventricular
|
|
187
|
+
myocyte model in health, disease, and drug block. *eLife* 8, e48890 (2019).
|
|
188
|
+
- S. Land et al. A model of cardiac contraction based on novel measurements of tension
|
|
189
|
+
development in human cardiomyocytes. *Journal of Molecular and Cellular Cardiology*
|
|
190
|
+
106, 68–83 (2017).
|
|
191
|
+
|
|
192
|
+
## Authors
|
|
193
|
+
|
|
194
|
+
Henrik Finsberg (<henriknf@simula.no>)
|
|
195
|
+
|
|
196
|
+
## License
|
|
197
|
+
|
|
198
|
+
MIT. See [LICENSE](https://github.com/ComputationalPhysiology/simcardemsx/blob/main/LICENSE).
|
|
@@ -9,7 +9,7 @@ requires = [
|
|
|
9
9
|
|
|
10
10
|
[project]
|
|
11
11
|
name = "simcardemsx"
|
|
12
|
-
version = "0.
|
|
12
|
+
version = "0.4.0"
|
|
13
13
|
description = "Next generation cardiac electro-mechanics solver based on FEniCSx"
|
|
14
14
|
authors = [{name = "Henrik Finsberg", email = "henriknf@simula.no"}]
|
|
15
15
|
license = "MIT"
|
|
@@ -29,8 +29,18 @@ dependencies = [
|
|
|
29
29
|
# simcardemsx.checkpoint calls (restart_functions/restart_metadata, and pulse's
|
|
30
30
|
# CycleController.state_dict); SimulationController.step() snapshots through it.
|
|
31
31
|
# beat 0.9.0 replaced beat.ecg.Leads12 with twelve_lead(), which rodero_05's post.py uses.
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
# pulse 0.12.0 closes an open cavity with a flat lid, so its volume does not depend on
|
|
33
|
+
# the origin, and 0.13.1's PrestressProblem pulls back the fibres it is given: the BiV's
|
|
34
|
+
# operating point needs both (circulation_biv.main.UNLOADING).
|
|
35
|
+
"fenicsx-pulse>=0.13.1",
|
|
36
|
+
# 0.11.0 is the first release with beat.reaction_eikonal.
|
|
37
|
+
# 0.13.0 adds FootCurrentODESolver(period=...), which the BiV and rodero_05 R-E options use.
|
|
38
|
+
# 0.14.0 makes Strang splitting the default; simcardemsx passes splitting="strang" explicitly.
|
|
39
|
+
# 0.15.0 adds Source(t0=<P1 Function>) and EndocardialActivation.volume_activation_times,
|
|
40
|
+
# which rodero_05's Durrer activation uses.
|
|
41
|
+
# 0.16.0 is the first release whose C backend compiles a split model's missing variables,
|
|
42
|
+
# which compile_ep_scheme uses.
|
|
43
|
+
"fenicsx-beat>=0.16.0",
|
|
34
44
|
# crossbridge backs the Ca_i-split activation backend and is imported at
|
|
35
45
|
# package import time via simcardemsx.backends. 0.3.3 is the first release whose
|
|
36
46
|
# RDQ20MF can take a step longer than its 25 us RU step (gate X2), and 0.3.4 the
|
|
@@ -43,8 +53,9 @@ dependencies = [
|
|
|
43
53
|
"scipy",
|
|
44
54
|
# gotranx 2.2.0 orders the generated states independently of PYTHONHASHSEED, and its
|
|
45
55
|
# GRL step linearizes every state, also through intermediates (1.8 advanced v, cai
|
|
46
|
-
# and the concentrations by forward Euler).
|
|
47
|
-
|
|
56
|
+
# and the concentrations by forward Euler). 2.10.0 is the first release with
|
|
57
|
+
# rush_larsen_2, 2.11.0 the first with compose.
|
|
58
|
+
"gotranx>=2.11.0",
|
|
48
59
|
"toml",
|
|
49
60
|
"pydantic",
|
|
50
61
|
"pydantic_pint",
|
|
@@ -67,6 +78,8 @@ test = [
|
|
|
67
78
|
# StretchActiveStress and Holzapfel-Ogden's b = 0 limit (pulse's transversely
|
|
68
79
|
# isotropic parameters)
|
|
69
80
|
"zero-mech>=0.3.0",
|
|
81
|
+
# The composed ToR-ORd + Land of examples/odefiles/composed.py
|
|
82
|
+
"odezoo",
|
|
70
83
|
]
|
|
71
84
|
dev = [
|
|
72
85
|
"pdbpp",
|
|
@@ -84,7 +97,10 @@ demo = [
|
|
|
84
97
|
"fenicsx-ldrb",
|
|
85
98
|
"ukb-atlas",
|
|
86
99
|
"circulation>=0.4.0",
|
|
87
|
-
"gotranx",
|
|
100
|
+
"gotranx>=2.11.0",
|
|
101
|
+
"odezoo",
|
|
102
|
+
"pyvista",
|
|
103
|
+
"imageio",
|
|
88
104
|
"io4dolfinx[h5py]",
|
|
89
105
|
]
|
|
90
106
|
docs = [
|
|
@@ -98,6 +114,18 @@ docs = [
|
|
|
98
114
|
"griffe>=2",
|
|
99
115
|
# Tutorial 5's independent 0D reference
|
|
100
116
|
"zero-mech>=0.3.0",
|
|
117
|
+
# Tutorials 7 and 8 fetch their cell models
|
|
118
|
+
"odezoo",
|
|
119
|
+
# The first release with gotranx.compose, which tutorials 7 and 8 compose their models with
|
|
120
|
+
"gotranx>=2.11.0",
|
|
121
|
+
# Tutorials 7 and 8 render with pyvista, off screen: imageio writes the animations, and
|
|
122
|
+
# trame-vtk turns a scene into the standalone vtk.js page each interactive view embeds.
|
|
123
|
+
# Not through pyvista's export_html, which since pyvista 0.49 needs trame-pyvista, and
|
|
124
|
+
# that pins every trame package. trame-vtk 2.11.15 is the first that serializes VTK 9.7's
|
|
125
|
+
# scenes (trame-pyvista refuses an older one with VTK 9.7).
|
|
126
|
+
"pyvista",
|
|
127
|
+
"imageio",
|
|
128
|
+
"trame-vtk>=2.11.15",
|
|
101
129
|
"simcardemsx[demo]",
|
|
102
130
|
]
|
|
103
131
|
benchmark = [
|
|
@@ -137,6 +165,12 @@ testpaths = [
|
|
|
137
165
|
]
|
|
138
166
|
markers = ["slow: takes more than a few seconds"]
|
|
139
167
|
|
|
168
|
+
[tool.coverage.run]
|
|
169
|
+
# Before Python 3.14 coverage defaults to the C tracer (sys.settrace), which slows every Python
|
|
170
|
+
# call in the process: CI's stable job (3.12) ran 7x longer than nightly (3.14). sys.monitoring
|
|
171
|
+
# works from 3.12 while branch coverage is off.
|
|
172
|
+
core = "sysmon"
|
|
173
|
+
|
|
140
174
|
|
|
141
175
|
[[tool.mypy.overrides]]
|
|
142
176
|
# scipy ships no types of its own. scipy-stubs would supply them, but it installs optype, and
|
|
@@ -156,6 +190,12 @@ ignore_missing_imports = true
|
|
|
156
190
|
module = ["sympy", "sympy.*", "zero_mech", "zero_mech.*"]
|
|
157
191
|
ignore_missing_imports = true
|
|
158
192
|
|
|
193
|
+
[[tool.mypy.overrides]]
|
|
194
|
+
# trame-vtk (the scene serializer of tutorials 7 and 8's interactive views) ships no py.typed
|
|
195
|
+
# marker.
|
|
196
|
+
module = ["trame_vtk", "trame_vtk.*"]
|
|
197
|
+
ignore_missing_imports = true
|
|
198
|
+
|
|
159
199
|
|
|
160
200
|
[tool.ruff]
|
|
161
201
|
# Exclude a variety of commonly ignored directories.
|
|
@@ -239,7 +279,7 @@ tag = true
|
|
|
239
279
|
sign_tags = false
|
|
240
280
|
tag_name = "v{new_version}"
|
|
241
281
|
tag_message = "Bump version: {current_version} → {new_version}"
|
|
242
|
-
current_version = "0.
|
|
282
|
+
current_version = "0.4.0"
|
|
243
283
|
|
|
244
284
|
|
|
245
285
|
[[tool.bumpversion.files]]
|
|
@@ -21,6 +21,7 @@ from typing import TYPE_CHECKING, Any, Callable, cast
|
|
|
21
21
|
|
|
22
22
|
import beat
|
|
23
23
|
import pulse
|
|
24
|
+
from beat.reaction_eikonal import FootCurrentODESolver
|
|
24
25
|
|
|
25
26
|
from .checkpoint import (
|
|
26
27
|
Checkpointable,
|
|
@@ -47,6 +48,25 @@ logger = logging.getLogger(__name__)
|
|
|
47
48
|
_DT_RTOL = 1e-9
|
|
48
49
|
|
|
49
50
|
|
|
51
|
+
def dolfin_ode_solver(ep_solver: Any) -> beat.odesolver.DolfinODESolver:
|
|
52
|
+
"""The one-model ODE solver inside ``ep_solver.ode``.
|
|
53
|
+
|
|
54
|
+
Returns ``ep_solver.ode``, or the solver it wraps when that is a
|
|
55
|
+
:class:`beat.reaction_eikonal.FootCurrentODESolver` (reaction-eikonal EP).
|
|
56
|
+
The transfer plan writes into the ``missing_variables``/``parameters`` arrays of
|
|
57
|
+
beat's :class:`~beat.odesolver.DolfinODESolver`, which no other solver has.
|
|
58
|
+
"""
|
|
59
|
+
ode = ep_solver.ode
|
|
60
|
+
if isinstance(ode, FootCurrentODESolver):
|
|
61
|
+
ode = ode.ode
|
|
62
|
+
if not isinstance(ode, beat.odesolver.DolfinODESolver):
|
|
63
|
+
raise TypeError(
|
|
64
|
+
"ep_solver.ode must be a beat.odesolver.DolfinODESolver "
|
|
65
|
+
f"(optionally inside a FootCurrentODESolver), got {type(ode).__name__}",
|
|
66
|
+
)
|
|
67
|
+
return ode
|
|
68
|
+
|
|
69
|
+
|
|
50
70
|
class SimulationController:
|
|
51
71
|
"""Advance EP and mechanics together, one mechanics time step at a time.
|
|
52
72
|
|
|
@@ -92,7 +112,8 @@ class SimulationController:
|
|
|
92
112
|
``parameters["dt"]`` does not equal ``dt_mech``, or if the backend stores its
|
|
93
113
|
states on a quadrature space whose degree differs from the mechanics form's.
|
|
94
114
|
TypeError
|
|
95
|
-
If ``ep_solver.ode`` is
|
|
115
|
+
If ``ep_solver.ode`` is neither a :class:`beat.odesolver.DolfinODESolver` nor a
|
|
116
|
+
:class:`beat.reaction_eikonal.FootCurrentODESolver` around one.
|
|
96
117
|
NotImplementedError
|
|
97
118
|
From :class:`~simcardemsx.transfer_plan.TransferPlan`, if the EP ODE space is
|
|
98
119
|
neither P1 nor DG0.
|
|
@@ -101,7 +122,7 @@ class SimulationController:
|
|
|
101
122
|
def __init__(
|
|
102
123
|
self,
|
|
103
124
|
mechanics: MechanicsDriver | pulse.StaticProblem,
|
|
104
|
-
ep_solver: beat.
|
|
125
|
+
ep_solver: beat.SplittingSolver,
|
|
105
126
|
backend: CoupledBackend,
|
|
106
127
|
ode_modules: ODEModules,
|
|
107
128
|
dt_mech: float,
|
|
@@ -151,11 +172,7 @@ class SimulationController:
|
|
|
151
172
|
|
|
152
173
|
# beat types this as its generic ODE-solver protocol. The transfer plan needs
|
|
153
174
|
# the one-model solver: it writes into its missing_variables and parameters arrays.
|
|
154
|
-
ode = ep_solver
|
|
155
|
-
if not isinstance(ode, beat.odesolver.DolfinODESolver):
|
|
156
|
-
raise TypeError(
|
|
157
|
-
f"ep_solver.ode must be a beat.odesolver.DolfinODESolver, got {type(ode).__name__}",
|
|
158
|
-
)
|
|
175
|
+
ode = dolfin_ode_solver(ep_solver)
|
|
159
176
|
|
|
160
177
|
self.ep_solver = ep_solver
|
|
161
178
|
self.backend = backend
|