simcardemsx 0.2.0__tar.gz → 0.3.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.
Files changed (67) hide show
  1. {simcardemsx-0.2.0/src/simcardemsx.egg-info → simcardemsx-0.3.0}/PKG-INFO +10 -3
  2. {simcardemsx-0.2.0 → simcardemsx-0.3.0}/README.md +3 -1
  3. {simcardemsx-0.2.0 → simcardemsx-0.3.0}/pyproject.toml +29 -3
  4. {simcardemsx-0.2.0 → simcardemsx-0.3.0}/src/simcardemsx/controller.py +23 -6
  5. {simcardemsx-0.2.0 → simcardemsx-0.3.0/src/simcardemsx.egg-info}/PKG-INFO +10 -3
  6. {simcardemsx-0.2.0 → simcardemsx-0.3.0}/src/simcardemsx.egg-info/SOURCES.txt +1 -0
  7. {simcardemsx-0.2.0 → simcardemsx-0.3.0}/src/simcardemsx.egg-info/requires.txt +6 -1
  8. {simcardemsx-0.2.0 → simcardemsx-0.3.0}/tests/test_biv_example.py +68 -2
  9. {simcardemsx-0.2.0 → simcardemsx-0.3.0}/tests/test_checkpoint.py +27 -4
  10. simcardemsx-0.3.0/tests/test_reaction_eikonal.py +129 -0
  11. {simcardemsx-0.2.0 → simcardemsx-0.3.0}/tests/test_rodero_example.py +75 -1
  12. {simcardemsx-0.2.0 → simcardemsx-0.3.0}/tests/test_rollback.py +43 -2
  13. {simcardemsx-0.2.0 → simcardemsx-0.3.0}/tests/test_slab_example.py +37 -0
  14. {simcardemsx-0.2.0 → simcardemsx-0.3.0}/LICENSE +0 -0
  15. {simcardemsx-0.2.0 → simcardemsx-0.3.0}/setup.cfg +0 -0
  16. {simcardemsx-0.2.0 → simcardemsx-0.3.0}/src/simcardemsx/__init__.py +0 -0
  17. {simcardemsx-0.2.0 → simcardemsx-0.3.0}/src/simcardemsx/averaging.py +0 -0
  18. {simcardemsx-0.2.0 → simcardemsx-0.3.0}/src/simcardemsx/backends/__init__.py +0 -0
  19. {simcardemsx-0.2.0 → simcardemsx-0.3.0}/src/simcardemsx/backends/base.py +0 -0
  20. {simcardemsx-0.2.0 → simcardemsx-0.3.0}/src/simcardemsx/backends/generated.py +0 -0
  21. {simcardemsx-0.2.0 → simcardemsx-0.3.0}/src/simcardemsx/backends/segregated.py +0 -0
  22. {simcardemsx-0.2.0 → simcardemsx-0.3.0}/src/simcardemsx/backends/zeta_split.py +0 -0
  23. {simcardemsx-0.2.0 → simcardemsx-0.3.0}/src/simcardemsx/checkpoint.py +0 -0
  24. {simcardemsx-0.2.0 → simcardemsx-0.3.0}/src/simcardemsx/config.py +0 -0
  25. {simcardemsx-0.2.0 → simcardemsx-0.3.0}/src/simcardemsx/datacollector.py +0 -0
  26. {simcardemsx-0.2.0 → simcardemsx-0.3.0}/src/simcardemsx/interpolation.py +0 -0
  27. {simcardemsx-0.2.0 → simcardemsx-0.3.0}/src/simcardemsx/mechanics.py +0 -0
  28. {simcardemsx-0.2.0 → simcardemsx-0.3.0}/src/simcardemsx/ode_model.py +0 -0
  29. {simcardemsx-0.2.0 → simcardemsx-0.3.0}/src/simcardemsx/provenance.py +0 -0
  30. {simcardemsx-0.2.0 → simcardemsx-0.3.0}/src/simcardemsx/py.typed +0 -0
  31. {simcardemsx-0.2.0 → simcardemsx-0.3.0}/src/simcardemsx/results.py +0 -0
  32. {simcardemsx-0.2.0 → simcardemsx-0.3.0}/src/simcardemsx/transfer_plan.py +0 -0
  33. {simcardemsx-0.2.0 → simcardemsx-0.3.0}/src/simcardemsx/units.py +0 -0
  34. {simcardemsx-0.2.0 → simcardemsx-0.3.0}/src/simcardemsx/utils.py +0 -0
  35. {simcardemsx-0.2.0 → simcardemsx-0.3.0}/src/simcardemsx/zero_d.py +0 -0
  36. {simcardemsx-0.2.0 → simcardemsx-0.3.0}/src/simcardemsx.egg-info/dependency_links.txt +0 -0
  37. {simcardemsx-0.2.0 → simcardemsx-0.3.0}/src/simcardemsx.egg-info/top_level.txt +0 -0
  38. {simcardemsx-0.2.0 → simcardemsx-0.3.0}/tests/test_averaging.py +0 -0
  39. {simcardemsx-0.2.0 → simcardemsx-0.3.0}/tests/test_backends.py +0 -0
  40. {simcardemsx-0.2.0 → simcardemsx-0.3.0}/tests/test_checkpoint_backends.py +0 -0
  41. {simcardemsx-0.2.0 → simcardemsx-0.3.0}/tests/test_checkpoint_circulation.py +0 -0
  42. {simcardemsx-0.2.0 → simcardemsx-0.3.0}/tests/test_circulation.py +0 -0
  43. {simcardemsx-0.2.0 → simcardemsx-0.3.0}/tests/test_coupled_backend.py +0 -0
  44. {simcardemsx-0.2.0 → simcardemsx-0.3.0}/tests/test_coupled_system.py +0 -0
  45. {simcardemsx-0.2.0 → simcardemsx-0.3.0}/tests/test_crossbridge_coupling.py +0 -0
  46. {simcardemsx-0.2.0 → simcardemsx-0.3.0}/tests/test_cycle_coupling.py +0 -0
  47. {simcardemsx-0.2.0 → simcardemsx-0.3.0}/tests/test_datacollector.py +0 -0
  48. {simcardemsx-0.2.0 → simcardemsx-0.3.0}/tests/test_demo_io.py +0 -0
  49. {simcardemsx-0.2.0 → simcardemsx-0.3.0}/tests/test_dynamic_coupling.py +0 -0
  50. {simcardemsx-0.2.0 → simcardemsx-0.3.0}/tests/test_generated_activation.py +0 -0
  51. {simcardemsx-0.2.0 → simcardemsx-0.3.0}/tests/test_interpolation.py +0 -0
  52. {simcardemsx-0.2.0 → simcardemsx-0.3.0}/tests/test_isolated_ep.py +0 -0
  53. {simcardemsx-0.2.0 → simcardemsx-0.3.0}/tests/test_isolated_mechanics.py +0 -0
  54. {simcardemsx-0.2.0 → simcardemsx-0.3.0}/tests/test_mechanics_drivers.py +0 -0
  55. {simcardemsx-0.2.0 → simcardemsx-0.3.0}/tests/test_monolithic_coupling.py +0 -0
  56. {simcardemsx-0.2.0 → simcardemsx-0.3.0}/tests/test_ode_model.py +0 -0
  57. {simcardemsx-0.2.0 → simcardemsx-0.3.0}/tests/test_provenance.py +0 -0
  58. {simcardemsx-0.2.0 → simcardemsx-0.3.0}/tests/test_results.py +0 -0
  59. {simcardemsx-0.2.0 → simcardemsx-0.3.0}/tests/test_rodero_case.py +0 -0
  60. {simcardemsx-0.2.0 → simcardemsx-0.3.0}/tests/test_round_trip.py +0 -0
  61. {simcardemsx-0.2.0 → simcardemsx-0.3.0}/tests/test_scheme_comparison.py +0 -0
  62. {simcardemsx-0.2.0 → simcardemsx-0.3.0}/tests/test_scheme_report.py +0 -0
  63. {simcardemsx-0.2.0 → simcardemsx-0.3.0}/tests/test_segregated_backend.py +0 -0
  64. {simcardemsx-0.2.0 → simcardemsx-0.3.0}/tests/test_stability.py +0 -0
  65. {simcardemsx-0.2.0 → simcardemsx-0.3.0}/tests/test_transfer_plan.py +0 -0
  66. {simcardemsx-0.2.0 → simcardemsx-0.3.0}/tests/test_zero_d_coupling.py +0 -0
  67. {simcardemsx-0.2.0 → simcardemsx-0.3.0}/tests/test_zero_mech_reference.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: simcardemsx
3
- Version: 0.2.0
3
+ Version: 0.3.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
@@ -18,7 +18,7 @@ Description-Content-Type: text/markdown
18
18
  License-File: LICENSE
19
19
  Requires-Dist: fenics-dolfinx
20
20
  Requires-Dist: fenicsx-pulse>=0.11.1
21
- Requires-Dist: fenicsx-beat>=0.9.0
21
+ Requires-Dist: fenicsx-beat>=0.13.0
22
22
  Requires-Dist: crossbridge>=0.3.4
23
23
  Requires-Dist: io4dolfinx[h5py]
24
24
  Requires-Dist: scipy
@@ -54,6 +54,11 @@ Requires-Dist: ipykernel; extra == "docs"
54
54
  Requires-Dist: jupyter-server; extra == "docs"
55
55
  Requires-Dist: griffe>=2; extra == "docs"
56
56
  Requires-Dist: zero-mech>=0.3.0; extra == "docs"
57
+ Requires-Dist: odezoo; extra == "docs"
58
+ Requires-Dist: gotranx>=2.11.0; extra == "docs"
59
+ Requires-Dist: pyvista; extra == "docs"
60
+ Requires-Dist: imageio; extra == "docs"
61
+ Requires-Dist: trame-vtk>=2.11.15; extra == "docs"
57
62
  Requires-Dist: simcardemsx[demo]; extra == "docs"
58
63
  Provides-Extra: benchmark
59
64
  Requires-Dist: pytest-codspeed; extra == "benchmark"
@@ -175,7 +180,7 @@ coupled slab.
175
180
 
176
181
  ## Examples
177
182
 
178
- [`examples/`](https://github.com/ComputationalPhysiology/simcardemsx/tree/main/examples) holds four short tutorials and four larger
183
+ [`examples/`](https://github.com/ComputationalPhysiology/simcardemsx/tree/main/examples) holds eight short tutorials and four larger
179
184
  applications:
180
185
 
181
186
  - an electro-mechanical slab, for any split, scheme or contraction model;
@@ -194,6 +199,8 @@ pre-commit run --all # ruff, mypy, cspell, …
194
199
 
195
200
  The documentation is built with [MyST](https://mystmd.org). See
196
201
  [`docs/README.md`](https://github.com/ComputationalPhysiology/simcardemsx/blob/main/docs/README.md).
202
+ [`CONTRIBUTING.md`](https://github.com/ComputationalPhysiology/simcardemsx/blob/main/CONTRIBUTING.md)
203
+ describes the development environment and how to open a pull request.
197
204
 
198
205
  ## References
199
206
 
@@ -108,7 +108,7 @@ coupled slab.
108
108
 
109
109
  ## Examples
110
110
 
111
- [`examples/`](https://github.com/ComputationalPhysiology/simcardemsx/tree/main/examples) holds four short tutorials and four larger
111
+ [`examples/`](https://github.com/ComputationalPhysiology/simcardemsx/tree/main/examples) holds eight short tutorials and four larger
112
112
  applications:
113
113
 
114
114
  - an electro-mechanical slab, for any split, scheme or contraction model;
@@ -127,6 +127,8 @@ pre-commit run --all # ruff, mypy, cspell, …
127
127
 
128
128
  The documentation is built with [MyST](https://mystmd.org). See
129
129
  [`docs/README.md`](https://github.com/ComputationalPhysiology/simcardemsx/blob/main/docs/README.md).
130
+ [`CONTRIBUTING.md`](https://github.com/ComputationalPhysiology/simcardemsx/blob/main/CONTRIBUTING.md)
131
+ describes the development environment and how to open a pull request.
130
132
 
131
133
  ## References
132
134
 
@@ -9,7 +9,7 @@ requires = [
9
9
 
10
10
  [project]
11
11
  name = "simcardemsx"
12
- version = "0.2.0"
12
+ version = "0.3.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"
@@ -30,7 +30,9 @@ dependencies = [
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
32
  "fenicsx-pulse>=0.11.1",
33
- "fenicsx-beat>=0.9.0",
33
+ # 0.11.0 is the first release with beat.reaction_eikonal.
34
+ # 0.13.0 adds FootCurrentODESolver(period=...), which the BiV and rodero_05 R-E options use.
35
+ "fenicsx-beat>=0.13.0",
34
36
  # crossbridge backs the Ca_i-split activation backend and is imported at
35
37
  # package import time via simcardemsx.backends. 0.3.3 is the first release whose
36
38
  # RDQ20MF can take a step longer than its 25 us RU step (gate X2), and 0.3.4 the
@@ -98,6 +100,18 @@ docs = [
98
100
  "griffe>=2",
99
101
  # Tutorial 5's independent 0D reference
100
102
  "zero-mech>=0.3.0",
103
+ # Tutorials 7 and 8 fetch their cell models
104
+ "odezoo",
105
+ # The first release with gotranx.compose, which tutorials 7 and 8 compose their models with
106
+ "gotranx>=2.11.0",
107
+ # Tutorials 7 and 8 render with pyvista, off screen: imageio writes the animations, and
108
+ # trame-vtk turns a scene into the standalone vtk.js page each interactive view embeds.
109
+ # Not through pyvista's export_html, which since pyvista 0.49 needs trame-pyvista, and
110
+ # that pins every trame package. trame-vtk 2.11.15 is the first that serializes VTK 9.7's
111
+ # scenes (trame-pyvista refuses an older one with VTK 9.7).
112
+ "pyvista",
113
+ "imageio",
114
+ "trame-vtk>=2.11.15",
101
115
  "simcardemsx[demo]",
102
116
  ]
103
117
  benchmark = [
@@ -137,6 +151,12 @@ testpaths = [
137
151
  ]
138
152
  markers = ["slow: takes more than a few seconds"]
139
153
 
154
+ [tool.coverage.run]
155
+ # Before Python 3.14 coverage defaults to the C tracer (sys.settrace), which slows every Python
156
+ # call in the process: CI's stable job (3.12) ran 7x longer than nightly (3.14). sys.monitoring
157
+ # works from 3.12 while branch coverage is off.
158
+ core = "sysmon"
159
+
140
160
 
141
161
  [[tool.mypy.overrides]]
142
162
  # scipy ships no types of its own. scipy-stubs would supply them, but it installs optype, and
@@ -156,6 +176,12 @@ ignore_missing_imports = true
156
176
  module = ["sympy", "sympy.*", "zero_mech", "zero_mech.*"]
157
177
  ignore_missing_imports = true
158
178
 
179
+ [[tool.mypy.overrides]]
180
+ # trame-vtk (the scene serializer of tutorials 7 and 8's interactive views) ships no py.typed
181
+ # marker.
182
+ module = ["trame_vtk", "trame_vtk.*"]
183
+ ignore_missing_imports = true
184
+
159
185
 
160
186
  [tool.ruff]
161
187
  # Exclude a variety of commonly ignored directories.
@@ -239,7 +265,7 @@ tag = true
239
265
  sign_tags = false
240
266
  tag_name = "v{new_version}"
241
267
  tag_message = "Bump version: {current_version} → {new_version}"
242
- current_version = "0.2.0"
268
+ current_version = "0.3.0"
243
269
 
244
270
 
245
271
  [[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 not a :class:`beat.odesolver.DolfinODESolver`.
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.
@@ -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.ode
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
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: simcardemsx
3
- Version: 0.2.0
3
+ Version: 0.3.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
@@ -18,7 +18,7 @@ Description-Content-Type: text/markdown
18
18
  License-File: LICENSE
19
19
  Requires-Dist: fenics-dolfinx
20
20
  Requires-Dist: fenicsx-pulse>=0.11.1
21
- Requires-Dist: fenicsx-beat>=0.9.0
21
+ Requires-Dist: fenicsx-beat>=0.13.0
22
22
  Requires-Dist: crossbridge>=0.3.4
23
23
  Requires-Dist: io4dolfinx[h5py]
24
24
  Requires-Dist: scipy
@@ -54,6 +54,11 @@ Requires-Dist: ipykernel; extra == "docs"
54
54
  Requires-Dist: jupyter-server; extra == "docs"
55
55
  Requires-Dist: griffe>=2; extra == "docs"
56
56
  Requires-Dist: zero-mech>=0.3.0; extra == "docs"
57
+ Requires-Dist: odezoo; extra == "docs"
58
+ Requires-Dist: gotranx>=2.11.0; extra == "docs"
59
+ Requires-Dist: pyvista; extra == "docs"
60
+ Requires-Dist: imageio; extra == "docs"
61
+ Requires-Dist: trame-vtk>=2.11.15; extra == "docs"
57
62
  Requires-Dist: simcardemsx[demo]; extra == "docs"
58
63
  Provides-Extra: benchmark
59
64
  Requires-Dist: pytest-codspeed; extra == "benchmark"
@@ -175,7 +180,7 @@ coupled slab.
175
180
 
176
181
  ## Examples
177
182
 
178
- [`examples/`](https://github.com/ComputationalPhysiology/simcardemsx/tree/main/examples) holds four short tutorials and four larger
183
+ [`examples/`](https://github.com/ComputationalPhysiology/simcardemsx/tree/main/examples) holds eight short tutorials and four larger
179
184
  applications:
180
185
 
181
186
  - an electro-mechanical slab, for any split, scheme or contraction model;
@@ -194,6 +199,8 @@ pre-commit run --all # ruff, mypy, cspell, …
194
199
 
195
200
  The documentation is built with [MyST](https://mystmd.org). See
196
201
  [`docs/README.md`](https://github.com/ComputationalPhysiology/simcardemsx/blob/main/docs/README.md).
202
+ [`CONTRIBUTING.md`](https://github.com/ComputationalPhysiology/simcardemsx/blob/main/CONTRIBUTING.md)
203
+ describes the development environment and how to open a pull request.
197
204
 
198
205
  ## References
199
206
 
@@ -49,6 +49,7 @@ tests/test_mechanics_drivers.py
49
49
  tests/test_monolithic_coupling.py
50
50
  tests/test_ode_model.py
51
51
  tests/test_provenance.py
52
+ tests/test_reaction_eikonal.py
52
53
  tests/test_results.py
53
54
  tests/test_rodero_case.py
54
55
  tests/test_rodero_example.py
@@ -1,6 +1,6 @@
1
1
  fenics-dolfinx
2
2
  fenicsx-pulse>=0.11.1
3
- fenicsx-beat>=0.9.0
3
+ fenicsx-beat>=0.13.0
4
4
  crossbridge>=0.3.4
5
5
  io4dolfinx[h5py]
6
6
  scipy
@@ -43,6 +43,11 @@ ipykernel
43
43
  jupyter-server
44
44
  griffe>=2
45
45
  zero-mech>=0.3.0
46
+ odezoo
47
+ gotranx>=2.11.0
48
+ pyvista
49
+ imageio
50
+ trame-vtk>=2.11.15
46
51
  simcardemsx[demo]
47
52
 
48
53
  [test]
@@ -29,7 +29,7 @@ def _physics(*argv: str) -> dict:
29
29
 
30
30
 
31
31
  #: The options that define the physics; every other option must be in ``NOT_PHYSICS``.
32
- PHYSICS_OPTIONS = {"tref", "scheme", "dt_mech"}
32
+ PHYSICS_OPTIONS = {"tref", "scheme", "dt_mech", "ep_mode"}
33
33
 
34
34
 
35
35
  def test_every_option_is_physics_or_not():
@@ -54,7 +54,7 @@ def test_every_option_is_physics_or_not():
54
54
 
55
55
  @pytest.mark.parametrize(
56
56
  "argv",
57
- [("--tref", "5"), ("--scheme", "stabilized"), ("--dt-mech", "1")],
57
+ [("--tref", "5"), ("--scheme", "stabilized"), ("--dt-mech", "1"), ("--ep", "re-")],
58
58
  ids=lambda argv: argv[0],
59
59
  )
60
60
  def test_physics_options_change_the_hash(argv):
@@ -185,3 +185,69 @@ def test_summarise_synthetic_columns():
185
185
  "failed_at_ms": 8.5,
186
186
  }
187
187
  assert summary["peak_Ta_mean_kPa"] == 5.0
188
+
189
+
190
+ def test_eikonal_settings_are_physics():
191
+ """The eikonal's velocities, sources and foot are in the physics, so a change to
192
+ them refuses a restart; CV_F sets the other two."""
193
+ eikonal = _physics()["ep"]["eikonal"]
194
+ assert eikonal["cv_m_per_s"]["fibre"] == biv.CV_F
195
+ assert eikonal["cv_m_per_s"]["sheet"] == pytest.approx(2 * biv.CV_F / 3)
196
+ assert eikonal["cv_m_per_s"]["normal"] == pytest.approx(biv.CV_F / 3)
197
+ assert eikonal["sources"] == ["LV", "RV"]
198
+ assert eikonal["period_ms"] == biv.PERIOD
199
+ assert eikonal["foot"]
200
+
201
+
202
+ def test_biv_eikonal_fibres_are_cell_averages():
203
+ """``cell_mean_vector`` gives each cell the mean of its quadrature values of a vector
204
+ field, which is what beat's eikonal reads at cell midpoints."""
205
+ from mpi4py import MPI
206
+
207
+ import basix.ufl
208
+ import dolfinx
209
+
210
+ mesh = dolfinx.mesh.create_box(
211
+ MPI.COMM_WORLD,
212
+ [[0.0, 0.0, 0.0], [1.0, 1.0, 1.0]],
213
+ [1, 1, 1],
214
+ dolfinx.mesh.CellType.tetrahedron,
215
+ )
216
+ degree = 2
217
+ element = basix.ufl.quadrature_element(mesh.basix_cell(), (3,), degree=degree)
218
+ space = dolfinx.fem.functionspace(mesh, element)
219
+ source = dolfinx.fem.Function(space)
220
+ rng = np.random.default_rng(0)
221
+ source.x.array[:] = rng.random(source.x.array.size)
222
+
223
+ mean = biv.cell_mean_vector(source, mesh, degree)
224
+
225
+ cells = mesh.topology.index_map(3).size_local
226
+ values = source.x.array.reshape(cells, -1, 3)
227
+ # Equal quadrature weights are not assumed: weight by the rule's own weights.
228
+ _, weights = basix.make_quadrature(mesh.basix_cell(), degree)
229
+ expected = (values * weights[None, :, None]).sum(axis=1) / weights.sum()
230
+ assert cells == 6
231
+ np.testing.assert_allclose(mean.x.array.reshape(cells, 3), expected, rtol=1e-12)
232
+
233
+
234
+ def test_summarise_reports_activation_time():
235
+ t = np.array([0.0, 2.0, 4.0])
236
+ columns = {
237
+ "t_ms": t,
238
+ "V_LV_mL": np.array([100.0, 90.0, 80.0]),
239
+ "p_LV_mmHg": np.array([10.0, 50.0, 90.0]),
240
+ "circuit_p_AR_SYS": np.full_like(t, 80.0),
241
+ "V_RV_mL": np.array([70.0, 71.0, 72.0]),
242
+ "p_RV_mmHg": np.array([4.0, 6.0, 8.0]),
243
+ "circuit_p_AR_PUL": np.full_like(t, 15.0),
244
+ "conservation_drift": np.zeros_like(t),
245
+ "Ta_mean_kPa": np.array([0.0, 1.0, 5.0]),
246
+ "newton_iterations": np.array([0.0, 3.0, 2.0]),
247
+ }
248
+ reaction_eikonal = post.summarise(columns, None, ep="re-", t_a=np.array([0.0, 79.5, 12.0]))
249
+ assert reaction_eikonal["ep"] == "re-"
250
+ assert reaction_eikonal["total_activation_ms"] == 79.5
251
+ synchronous = post.summarise(columns, None)
252
+ assert synchronous["ep"] == "synchronous"
253
+ assert "total_activation_ms" not in synchronous
@@ -34,7 +34,7 @@ import re
34
34
  from collections.abc import Callable
35
35
  from dataclasses import dataclass, field
36
36
  from pathlib import Path
37
- from typing import Any
37
+ from typing import Any, Literal
38
38
 
39
39
  from mpi4py import MPI
40
40
 
@@ -71,10 +71,17 @@ def _unit_cube(n: int) -> dolfinx.mesh.Mesh:
71
71
 
72
72
 
73
73
  @pytest.fixture
74
- def build(split_modules, make_ep_solver, make_mechanics, make_dynamic_mechanics):
74
+ def build(
75
+ split_modules,
76
+ make_ep_solver,
77
+ make_re_ep_solver,
78
+ make_mechanics,
79
+ make_dynamic_mechanics,
80
+ ):
75
81
  """``build(split, scheme, *, crossbridge=False, dynamic=False, dt_mech=DT_MECH)``:
76
82
  gate 5's controller, with every object new: the EP solver, the mechanics problem,
77
- the backend and the controller.
83
+ the backend and the controller. ``ep`` is the EP model: beat's monodomain
84
+ splitting solver, or reaction-eikonal with (``re+``) or without (``re-``) the PDE.
78
85
 
79
86
  ``crossbridge`` puts ``CrossbridgeSegregated`` Land2017 in place of the
80
87
  ``GeneratedActivation`` (X2's harness; ``scheme`` is then not read), and
@@ -90,6 +97,7 @@ def build(split_modules, make_ep_solver, make_mechanics, make_dynamic_mechanics)
90
97
  crossbridge: bool = False,
91
98
  dynamic: bool = False,
92
99
  dt_mech: float = DT_MECH,
100
+ ep: Literal["monodomain", "re+", "re-"] = "monodomain",
93
101
  ) -> SimulationController:
94
102
  modules = split_modules[split]
95
103
  ep_mesh = _unit_cube(3)
@@ -110,7 +118,10 @@ def build(split_modules, make_ep_solver, make_mechanics, make_dynamic_mechanics)
110
118
  _crossbridge_factory("Land2017", modules.mechanics) if crossbridge else None
111
119
  ),
112
120
  )
113
- ep_solver = make_ep_solver(modules.ep, ep_mesh)
121
+ if ep == "monodomain":
122
+ ep_solver = make_ep_solver(modules.ep, ep_mesh)
123
+ else:
124
+ ep_solver = make_re_ep_solver(modules.ep, ep_mesh, ep)
114
125
  return SimulationController(problem, ep_solver, backend, modules, dt_mech, DT_EP)
115
126
 
116
127
  return build
@@ -171,6 +182,18 @@ def _restart_matches_the_uninterrupted_run(
171
182
  _assert_same_state(_coupled_state(a), _coupled_state(c))
172
183
 
173
184
 
185
+ @pytest.mark.parametrize("ep", ["re+", "re-"])
186
+ def test_restart_matches_under_reaction_eikonal(tmp_path, build, ep):
187
+ """R1 under reaction-eikonal EP: ``t_a`` is rebuilt, not saved, and the foot current
188
+ and the transfer rows still continue bit for bit."""
189
+ _restart_matches_the_uninterrupted_run(
190
+ tmp_path,
191
+ lambda: build(ep=ep),
192
+ {**P, "ep": ep},
193
+ k=K,
194
+ )
195
+
196
+
174
197
  @pytest.mark.parametrize(
175
198
  "split, scheme",
176
199
  [
@@ -0,0 +1,129 @@
1
+ """The controller accepts beat's reaction-eikonal EP (``FootCurrentODESolver``)."""
2
+
3
+ from mpi4py import MPI
4
+
5
+ import dolfinx
6
+ import numpy as np
7
+ import pytest
8
+ from beat.eikonal import Source, solve_eikonal
9
+
10
+ from simcardemsx.controller import SimulationController, dolfin_ode_solver
11
+
12
+ DT_EP = 0.05
13
+ DT_MECH = 1.0
14
+
15
+
16
+ def _build(split_modules, make_mechanics, ep_solver_factory):
17
+ modules = split_modules["zetasplit"]
18
+ ep, mech = modules
19
+ ep_solver = ep_solver_factory(ep, dolfinx.mesh.create_unit_cube(MPI.COMM_WORLD, 3, 3, 3))
20
+ problem, backend = make_mechanics(
21
+ mech,
22
+ dolfinx.mesh.create_unit_cube(MPI.COMM_WORLD, 1, 1, 1),
23
+ quadrature_degree=2,
24
+ )
25
+ return modules, ep_solver, problem, backend
26
+
27
+
28
+ @pytest.mark.parametrize("mode", ["re+", "re-"])
29
+ def test_controller_accepts_reaction_eikonal(
30
+ mode,
31
+ split_modules,
32
+ make_re_ep_solver,
33
+ make_mechanics,
34
+ ):
35
+ modules, ep_solver, problem, backend = _build(
36
+ split_modules,
37
+ make_mechanics,
38
+ lambda ep, mesh: make_re_ep_solver(ep, mesh, mode),
39
+ )
40
+ controller = SimulationController(problem, ep_solver, backend, modules, DT_MECH, DT_EP)
41
+ assert controller.plan.ode is ep_solver.ode.ode
42
+
43
+
44
+ def test_dolfin_ode_solver_unwraps(split_modules, make_ep_solver, make_re_ep_solver):
45
+ ep = split_modules["zetasplit"].ep
46
+ mesh = dolfinx.mesh.create_unit_cube(MPI.COMM_WORLD, 3, 3, 3)
47
+ re = make_re_ep_solver(ep, mesh, "re+")
48
+ assert dolfin_ode_solver(re) is re.ode.ode
49
+ mono = make_ep_solver(ep, mesh)
50
+ assert dolfin_ode_solver(mono) is mono.ode
51
+
52
+
53
+ def test_refuses_a_foot_around_another_solver(split_modules, make_re_ep_solver, make_mechanics):
54
+ modules, ep_solver, problem, backend = _build(
55
+ split_modules,
56
+ make_mechanics,
57
+ lambda ep, mesh: make_re_ep_solver(ep, mesh, "re+"),
58
+ )
59
+ foot = ep_solver.ode
60
+ foot.ode = object()
61
+ with pytest.raises(TypeError, match="DolfinODESolver"):
62
+ SimulationController(problem, ep_solver, backend, modules, DT_MECH, DT_EP)
63
+
64
+
65
+ def _eikonal_times(mesh):
66
+ axes = tuple(
67
+ dolfinx.fem.Constant(mesh, np.array(e, dtype=dolfinx.default_scalar_type))
68
+ for e in ([1.0, 0, 0], [0, 1.0, 0], [0, 0, 1.0])
69
+ )
70
+ return solve_eikonal(
71
+ mesh,
72
+ (0.6, 0.3, 0.3),
73
+ axes,
74
+ [Source(lambda x: np.isclose(x[0], 0.0), 0.0)],
75
+ )
76
+
77
+
78
+ @pytest.mark.slow
79
+ @pytest.mark.parametrize("split", ["zetasplit", "caisplit"])
80
+ @pytest.mark.parametrize("mode", ["re+", "re-"])
81
+ def test_round_trip_under_reaction_eikonal(
82
+ split,
83
+ mode,
84
+ split_modules,
85
+ make_re_ep_solver,
86
+ make_mechanics,
87
+ ):
88
+ """Gate 5 under R-E: values cross both ways through the controller, and EP's nodes
89
+ activate when the eikonal times say."""
90
+ modules = split_modules[split]
91
+ ep_mesh = dolfinx.mesh.create_unit_cube(MPI.COMM_WORLD, 3, 3, 3)
92
+ t_a = _eikonal_times(ep_mesh)
93
+ ep_solver = make_re_ep_solver(modules.ep, ep_mesh, mode, t_a=t_a)
94
+ problem, backend = make_mechanics(
95
+ modules.mechanics,
96
+ dolfinx.mesh.create_unit_cube(MPI.COMM_WORLD, 1, 1, 1),
97
+ quadrature_degree=2,
98
+ )
99
+ controller = SimulationController(problem, ep_solver, backend, modules, DT_MECH, DT_EP)
100
+ ode = dolfin_ode_solver(ep_solver)
101
+ v = ode.v_ode.x.array
102
+ n = v.size
103
+ first = np.full(n, np.inf)
104
+ v_peak = np.full(n, -np.inf)
105
+ post_min = np.full(n, np.inf)
106
+
107
+ def record(t, i):
108
+ v_peak[:] = np.maximum(v_peak, v)
109
+ newly = (v > 0) & np.isinf(first)
110
+ first[newly] = t
111
+ late = t >= first + 1.0
112
+ post_min[late] = np.minimum(post_min[late], v[late])
113
+
114
+ for _ in range(10):
115
+ controller.step(ep_callback=record)
116
+
117
+ ta = t_a.x.array
118
+ assert np.all(np.isfinite(first))
119
+ assert np.all(first <= ta + 2.0)
120
+ # The foot never drives v twice: v stays physiological, and once an AP is a ms old its
121
+ # plateau holds above the foot's threshold (-30 mV), so the foot has no reason to fire.
122
+ assert np.all(v_peak < 60.0)
123
+ assert np.all(np.isfinite(post_min))
124
+ assert np.all(post_min > -30.0)
125
+ if mode == "re-":
126
+ assert np.all(first >= ta)
127
+ assert any(np.any(f.x.array != 0.0) for f in backend.inputs.values())
128
+ # The backward direction: mechanics' values reached EP (zeta: Zetas, Zetaw; Ca_i: J_TRPN).
129
+ assert np.ptp(ode.missing_variables, axis=1).max() > 0.0
@@ -32,7 +32,7 @@ finally:
32
32
  sys.path.remove(str(EXAMPLES))
33
33
 
34
34
  #: The options that define the physics; every other option must be in ``NOT_PHYSICS``.
35
- PHYSICS_OPTIONS = {"case_dir", "tref"}
35
+ PHYSICS_OPTIONS = {"case_dir", "tref", "ep_mode"}
36
36
 
37
37
 
38
38
  def _fake_case(folder: Path) -> Path:
@@ -417,3 +417,77 @@ def test_a_point_between_endo_and_mid_is_never_epi():
417
417
  DG1 = dolfinx.fem.functionspace(mesh, ("DG", 1))
418
418
  expected = [vertex_type(p) for p in DG1.tabulate_dof_coordinates()]
419
419
  np.testing.assert_array_equal(post.celltype_at_points(celltype, DG1), expected)
420
+
421
+
422
+ def test_ep_changes_the_hash(fake_case):
423
+ assert physics_hash(_physics(fake_case, "--ep", "re-")) != physics_hash(_physics(fake_case))
424
+ assert physics_hash(_physics(fake_case, "--ep", "re+")) != physics_hash(
425
+ _physics(fake_case, "--ep", "re-"),
426
+ )
427
+
428
+
429
+ def _tiny_case(ep_module, lat):
430
+ """A one-element case with the fields ``make_ep_solver`` reads: 8 P1 nodes."""
431
+ mesh = dolfinx.mesh.create_unit_cube(MPI.COMM_WORLD, 1, 1, 1)
432
+ f0 = dolfinx.fem.Function(dolfinx.fem.functionspace(mesh, ("DG", 0, (3,))))
433
+ f0.x.array[:] = np.tile([1.0, 0.0, 0.0], f0.x.array.size // 3)
434
+ names = {*ep_module.state, *ep_module.missing}
435
+ steady = {
436
+ name: float(ep_module.init_state_values()[ep_module.state[name]])
437
+ if name in ep_module.state
438
+ else 0.0
439
+ for name in names
440
+ }
441
+ return SimpleNamespace(
442
+ geometry=SimpleNamespace(mesh=mesh),
443
+ celltype=np.zeros(lat.size),
444
+ initial_states={c: steady for c in case_module.CELLTYPES},
445
+ lat_ms=lat,
446
+ f0=f0,
447
+ ep_scales={},
448
+ )
449
+
450
+
451
+ def test_re_takes_the_lat_as_activation_time(split_modules):
452
+ from beat.reaction_eikonal import FootCurrentODESolver
453
+
454
+ from simcardemsx.controller import dolfin_ode_solver
455
+
456
+ ep_module = split_modules["zetasplit"].ep
457
+ lat = np.arange(8, dtype=float) * 3.0
458
+ case = _tiny_case(ep_module, lat)
459
+ solver = rodero.make_ep_solver(case, ep_module, {}, "re-")
460
+ assert isinstance(solver.ode, FootCurrentODESolver)
461
+ assert solver.pde is None
462
+ np.testing.assert_array_equal(solver.ode._t_a, lat)
463
+ ode = dolfin_ode_solver(solver)
464
+ row = ode.parameters[ep_module.parameter_index("i_Stim_Amplitude")]
465
+ assert np.all(row == 0.0)
466
+ # re+ keeps the PDE; lat-stimulus is the plain monodomain solver, with its stimulus
467
+ assert rodero.make_ep_solver(case, ep_module, {}, "re+").pde is not None
468
+ plain = rodero.make_ep_solver(case, ep_module, {})
469
+ assert not isinstance(plain.ode, FootCurrentODESolver)
470
+ amplitude = plain.ode.parameters[ep_module.parameter_index("i_Stim_Amplitude")]
471
+ assert np.all(amplitude != 0.0)
472
+
473
+
474
+ @pytest.mark.slow
475
+ def test_re_fires_again_after_one_period(split_modules):
476
+ """Review Focus 5: with ``period=PCL_MS`` the foot current fires again 800 ms later."""
477
+ ep_module = split_modules["zetasplit"].ep
478
+ case = _tiny_case(ep_module, np.full(8, 10.0))
479
+ solver = rodero.make_ep_solver(case, ep_module, {}, "re-")
480
+ ode = solver.ode.ode
481
+ v_index = ep_module.state_index("v")
482
+ dt, t, rises = 0.05, 0.0, []
483
+ previous = ode.values[v_index].max()
484
+ while t < 815.0:
485
+ solver.ode.step(t, dt)
486
+ t += dt
487
+ v = ode.values[v_index].max()
488
+ if previous < 0.0 <= v:
489
+ rises.append(t)
490
+ previous = v
491
+ assert len(rises) == 2, rises
492
+ assert abs(rises[0] - 10.0) < 5.0
493
+ assert abs(rises[1] - rises[0] - case_module.PCL_MS) < 2.0
@@ -20,6 +20,7 @@ the backend and the cycle's mechanics; these check everything, EP included.
20
20
 
21
21
  import re
22
22
  from dataclasses import dataclass, field
23
+ from typing import Literal
23
24
 
24
25
  from mpi4py import MPI
25
26
 
@@ -67,11 +68,17 @@ def _controller(
67
68
  scheme: str = "monolithic",
68
69
  driver=None,
69
70
  dt_mech: float = DT_MECH,
71
+ ep: Literal["monodomain", "re+", "re-"] = "monodomain",
72
+ make_re_ep_solver=None,
70
73
  ) -> SimulationController:
71
74
  """Gate 5's controller. ``driver(problem)`` builds the mechanics driver; without it
72
- the controller wraps the problem in :class:`Solve`."""
75
+ the controller wraps the problem in :class:`Solve`. ``ep`` other than ``monodomain``
76
+ is reaction-eikonal, built by ``make_re_ep_solver``."""
73
77
  modules = split_modules[SPLIT]
74
- ep_solver = make_ep_solver(modules.ep, _unit_cube(3))
78
+ if ep == "monodomain":
79
+ ep_solver = make_ep_solver(modules.ep, _unit_cube(3))
80
+ else:
81
+ ep_solver = make_re_ep_solver(modules.ep, _unit_cube(3), ep)
75
82
  problem, backend = make_mechanics(
76
83
  modules.mechanics,
77
84
  _unit_cube(1),
@@ -181,6 +188,40 @@ def test_failed_step_rolls_everything_back_and_a_retry_matches(
181
188
  _assert_same_state(_coupled_state(controller), _coupled_state(uninterrupted))
182
189
 
183
190
 
191
+ def test_failed_step_rolls_back_under_reaction_eikonal(
192
+ split_modules,
193
+ make_ep_solver,
194
+ make_re_ep_solver,
195
+ make_mechanics,
196
+ ):
197
+ """R2 under R-E-: the foot current's own state, the transfer rows and everything
198
+ else come back bit for bit, and the retry matches the uninterrupted run."""
199
+ inner: list[_RecordingSolve] = []
200
+
201
+ def failing(problem):
202
+ inner.append(_RecordingSolve(problem))
203
+ return _FailOnce(inner[0], at_step=2)
204
+
205
+ kw = {"ep": "re-", "make_re_ep_solver": make_re_ep_solver}
206
+ controller = _controller(split_modules, make_ep_solver, make_mechanics, driver=failing, **kw)
207
+ controller.step()
208
+ before = _coupled_state(controller)
209
+
210
+ with pytest.raises(RuntimeError, match="did not converge"):
211
+ controller.step()
212
+ assert not np.array_equal(inner[0].u_after[-1], before[0]["mechanics/mechanics_u"])
213
+ _assert_same_state(_coupled_state(controller), before)
214
+ assert controller.t == 1.0
215
+ assert controller.t_failed == 2.0
216
+
217
+ controller.step()
218
+ controller.step()
219
+ uninterrupted = _controller(split_modules, make_ep_solver, make_mechanics, **kw)
220
+ for _ in range(3):
221
+ uninterrupted.step()
222
+ _assert_same_state(_coupled_state(controller), _coupled_state(uninterrupted))
223
+
224
+
184
225
  def test_interrupt_in_ep_micro_steps_rolls_back(split_modules, make_ep_solver, make_mechanics):
185
226
  controller = _controller(split_modules, make_ep_solver, make_mechanics)
186
227
  controller.step()
@@ -477,3 +477,40 @@ def test_slab_refuses_existing_results_without_flags(tmp_path):
477
477
  run = json.loads((output_dir / "run.json").read_text())
478
478
  assert run["reached_t_end"] is True
479
479
  assert len(run["history"]) == 1
480
+
481
+
482
+ def test_ep_option_is_physics():
483
+ """``--ep`` changes the EP model, so it moves the physics hash (and the setting is
484
+ not hidden behind the ``ep`` key of ``model_settings()``)."""
485
+ slab = _import("main")
486
+ BASE = ["--odefile", str(_odefile())]
487
+ default = physics_hash(slab.physics(slab.parse_args(BASE)))
488
+ assert physics_hash(slab.physics(slab.parse_args([*BASE, "--ep", "monodomain"]))) == default
489
+ for mode in ("re+", "re-"):
490
+ assert physics_hash(slab.physics(slab.parse_args([*BASE, "--ep", mode]))) != default
491
+
492
+
493
+ def test_eikonal_settings_are_physics():
494
+ slab = _import("main")
495
+ BASE = ["--odefile", str(_odefile())]
496
+ eikonal = slab.physics(slab.parse_args(BASE))["ep"]["eikonal"]
497
+ assert eikonal["cv_mm_per_ms"] == {
498
+ "fibre": slab.CV_F,
499
+ "sheet": slab.CV_S,
500
+ "normal": slab.CV_N,
501
+ }
502
+ assert eikonal["delay_ms"] == slab.STIM_DELAY_MS
503
+ assert eikonal["source"] == "stimulus box"
504
+ assert set(eikonal["foot"]) == {"A", "tau_F", "V_th", "duration"}
505
+
506
+
507
+ @pytest.mark.slow
508
+ @pytest.mark.parametrize("mode", ["re+", "re-"])
509
+ def test_slab_runs_reaction_eikonal(tmp_path, mode):
510
+ result = _run_slab("--ep", mode, "--t-end", "2", output_dir=tmp_path / "o")
511
+ assert result.returncode == 0, result.stderr[-3000:]
512
+ run = json.loads((tmp_path / "o" / "run.json").read_text())
513
+ assert run["reached_t_end"]
514
+ assert run["ep"] == mode
515
+ timings = json.loads((tmp_path / "o" / "timings.json").read_text())
516
+ assert (timings["ep_pde_s"] == 0.0) == (mode == "re-")
File without changes
File without changes