Skip to content

Commit 47a87cc

Browse files
committed
Merge remote-tracking branch 'origin/main' into active-dev
2 parents 8c21363 + f87c512 commit 47a87cc

20 files changed

Lines changed: 403 additions & 213 deletions

.github/workflows/test_package_coverage.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,9 @@ jobs:
3232
- name: Install development versions of dependencies
3333
if: ${{ matrix.container == 'ghcr.io/fenics/dolfinx/dolfinx:nightly' }}
3434
run: |
35-
python3 -m pip install git+https://github.com/jorgensd/adios4dolfinx.git
36-
python3 -m pip install git+https://github.com/scientificcomputing/scifem.git
35+
python3 -m pip install git+https://github.com/scientificcomputing/io4dolfinx.git
36+
python3 -m pip install git+https://github.com/scientificcomputing/scifem.git --no-build-isolation
37+
python3 -m pip install git+https://github.com/ComputationalPhysiology/cardiac-geometriesx.git
3738
3839
- name: Install package
3940
run: |

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ repos:
1414

1515
- repo: https://github.com/astral-sh/ruff-pre-commit
1616
# Ruff version.
17-
rev: 'v0.14.14'
17+
rev: 'v0.15.2'
1818
hooks:
1919
# Run the linter.
2020
- id: ruff
@@ -35,7 +35,7 @@ repos:
3535
- id: mypy
3636

3737
- repo: https://github.com/streetsidesoftware/cspell-cli
38-
rev: v9.6.0
38+
rev: v9.7.0
3939
hooks:
4040
- id: cspell
4141
files: src/|docs|tests|README.md

demo/benchmark/problem1.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
from mpi4py import MPI
2828
import numpy as np
2929
import dolfinx
30-
from dolfinx import log
3130
import pulse
3231

3332
# ## 1. Geometry and Mesh
@@ -119,8 +118,6 @@ def dirichlet_bc(V: dolfinx.fem.FunctionSpace):
119118

120119
problem = pulse.StaticProblem(model=model, geometry=geo, bcs=bcs)
121120

122-
log.set_log_level(log.LogLevel.INFO)
123-
124121
target_pressure = 0.004
125122
steps = [0.0005, 0.001, 0.002, 0.003, 0.004]
126123

@@ -129,8 +126,6 @@ def dirichlet_bc(V: dolfinx.fem.FunctionSpace):
129126
pressure.assign(p)
130127
problem.solve()
131128

132-
log.set_log_level(log.LogLevel.WARNING)
133-
134129
# ## 5. Post-processing
135130
#
136131
# We save the final displacement and evaluate the deflection at the specific target point $(10, 0.5, 1)$.

demo/benchmark/problem2.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424

2525
from pathlib import Path
2626
from mpi4py import MPI
27-
from dolfinx import log
2827
import logging
2928
import dolfinx
3029
import numpy as np
@@ -114,8 +113,6 @@
114113
model=model, geometry=geometry, bcs=bcs, parameters={"base_bc": pulse.BaseBC.fixed},
115114
)
116115

117-
log.set_log_level(log.LogLevel.INFO)
118-
119116
# ### Continuation Solver
120117
# We ramp the pressure up to 10 kPa. We use a custom continuation loop to handle the nonlinearity.
121118

demo/benchmark/problem3.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,12 @@
3030

3131
from pathlib import Path
3232
from mpi4py import MPI
33-
from dolfinx import log
3433
import dolfinx
3534
import numpy as np
3635
import math
3736
import cardiac_geometries
3837
import pulse
3938

40-
# log.set_log_level(log.LogLevel.INFO)
41-
4239
# ## 1. Geometry and Fibers
4340
# We regenerate the mesh with the specific fiber angles required for Problem 3 ($+90^\circ$ to $-90^\circ$).
4441

demo/bleeding_biv.py

Lines changed: 52 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import matplotlib.pyplot as plt
2121
import numpy as np
2222
import gotranx
23-
import adios4dolfinx
23+
import io4dolfinx
2424
import cardiac_geometries
2525
import cardiac_geometries.geometry
2626
import pulse
@@ -30,6 +30,7 @@
3030
def mmHg_to_kPa(x):
3131
return x * 0.133322
3232

33+
3334
def custom_json(obj):
3435
if isinstance(obj, np.float64):
3536
return float(obj)
@@ -141,8 +142,6 @@ def run_zenker(outdir: Path):
141142
history["before_index"] = before_index
142143
history["after_index"] = after_index
143144

144-
145-
146145
Path(zenker_file).write_text(json.dumps(history, indent=4, default=custom_json))
147146

148147
return json.loads(zenker_file.read_text())
@@ -202,7 +201,6 @@ def solve_beat(times, states, dt, p, V_index, Ca_index, Vs, Cais, Tas):
202201
monitor = mon(ti, states, p)
203202
Tas[i] = monitor[Ta_index]
204203

205-
206204
nbeats = 10 if os.environ.get("CI") else 200
207205
times = np.arange(0, T, dt_cell)
208206
all_times = np.arange(0, T * nbeats, dt_cell)
@@ -261,7 +259,6 @@ def run_3D_model(
261259
mesh_unit: str = "m",
262260
volume2ml: float = 1000.0,
263261
):
264-
265262
geometry = pulse.HeartGeometry.from_cardiac_geometries(
266263
geo,
267264
metadata={"quadrature_degree": 6},
@@ -274,7 +271,8 @@ def run_3D_model(
274271
# We use an active stress approach with 30% transverse active stress (see {py:meth}`pulse.active_stress.transversely_active_stress`)
275272

276273
Ta = pulse.Variable(
277-
dolfinx.fem.Constant(geometry.mesh, dolfinx.default_scalar_type(0.0)), "kPa",
274+
dolfinx.fem.Constant(geometry.mesh, dolfinx.default_scalar_type(0.0)),
275+
"kPa",
278276
)
279277
active_model = pulse.ActiveStress(geo.f0, activation=Ta)
280278

@@ -312,11 +310,15 @@ def run_3D_model(
312310
robin = [robin_epi, robin_epi_perp, robin_base]
313311

314312
lvv_initial = comm.allreduce(geometry.volume("LV"), op=MPI.SUM)
315-
lv_volume = dolfinx.fem.Constant(geometry.mesh, dolfinx.default_scalar_type(lvv_initial))
313+
lv_volume = dolfinx.fem.Constant(
314+
geometry.mesh, dolfinx.default_scalar_type(lvv_initial),
315+
)
316316
lv_cavity = pulse.problem.Cavity(marker="LV", volume=lv_volume)
317317

318318
rvv_initial = comm.allreduce(geometry.volume("RV"), op=MPI.SUM)
319-
rv_volume = dolfinx.fem.Constant(geometry.mesh, dolfinx.default_scalar_type(rvv_initial))
319+
rv_volume = dolfinx.fem.Constant(
320+
geometry.mesh, dolfinx.default_scalar_type(rvv_initial),
321+
)
320322
rv_cavity = pulse.problem.Cavity(marker="RV", volume=rv_volume)
321323

322324
print("Initial volumes", lvv_initial * volume2ml, rvv_initial * volume2ml)
@@ -325,7 +327,11 @@ def run_3D_model(
325327
parameters = {"base_bc": pulse.problem.BaseBC.free, "mesh_unit": mesh_unit}
326328
bcs = pulse.BoundaryConditions(robin=robin)
327329
problem = pulse.problem.StaticProblem(
328-
model=model, geometry=geometry, bcs=bcs, cavities=cavities, parameters=parameters,
330+
model=model,
331+
geometry=geometry,
332+
bcs=bcs,
333+
cavities=cavities,
334+
parameters=parameters,
329335
)
330336

331337
problem.solve()
@@ -339,7 +345,7 @@ def run_3D_model(
339345
vtx.write(0.0)
340346

341347
filename = outdir / Path(f"function_checkpoint_{label}.bp")
342-
adios4dolfinx.write_mesh(filename, geometry.mesh)
348+
io4dolfinx.write_mesh(filename, geometry.mesh)
343349
output_file = outdir / f"output_{label}.json"
344350

345351
Ta_history = []
@@ -348,9 +354,9 @@ def callback(model, i: int, t: float, save=True):
348354
Ta_history.append(get_activation(t))
349355

350356
if save:
351-
adios4dolfinx.write_function(filename, problem.u, time=t, name="displacement")
357+
io4dolfinx.write_function(filename, problem.u, time=t, name="displacement")
352358
vtx.write(t)
353-
out = {k: v[:i+1] for k, v in model.history.items()}
359+
out = {k: v[: i + 1] for k, v in model.history.items()}
354360
out["Ta"] = Ta_history
355361
if comm.rank == 0:
356362
output_file.write_text(json.dumps(out, indent=4, default=custom_json))
@@ -396,7 +402,9 @@ def callback(model, i: int, t: float, save=True):
396402
def p_BiV_func(V_LV, V_RV, t):
397403
print("Calculating pressure at time", t)
398404
value = get_activation(t)
399-
print(f"Time{t} with activation: {value} and volumes: {V_LV} mL (LV) {V_RV} mL (RV)")
405+
print(
406+
f"Time{t} with activation: {value} and volumes: {V_LV} mL (LV) {V_RV} mL (RV)",
407+
)
400408
old_Ta = Ta.value.value
401409
dTa = value - old_Ta
402410

@@ -422,8 +430,12 @@ def p_BiV_func(V_LV, V_RV, t):
422430
Ta.assign(value)
423431
problem.solve()
424432

425-
lv_pendo_mmHg = circulation.units.kPa_to_mmHg(problem.cavity_pressures[0].x.array[0] * 1e-3)
426-
rv_pendo_mmHg = circulation.units.kPa_to_mmHg(problem.cavity_pressures[1].x.array[0] * 1e-3)
433+
lv_pendo_mmHg = circulation.units.kPa_to_mmHg(
434+
problem.cavity_pressures[0].x.array[0] * 1e-3,
435+
)
436+
rv_pendo_mmHg = circulation.units.kPa_to_mmHg(
437+
problem.cavity_pressures[1].x.array[0] * 1e-3,
438+
)
427439
print(f"Compute pressures: {lv_pendo_mmHg} mmHg (LV) {rv_pendo_mmHg} mmHg (RV)")
428440
return lv_pendo_mmHg, rv_pendo_mmHg
429441

@@ -432,19 +444,23 @@ def p_BiV_func(V_LV, V_RV, t):
432444
s = circulation.units.ureg("s")
433445
add_units = False
434446
lvv_init = (
435-
geo.mesh.comm.allreduce(geometry.volume("LV", u=problem.u), op=MPI.SUM) * 1e6 * 1.0
447+
geo.mesh.comm.allreduce(geometry.volume("LV", u=problem.u), op=MPI.SUM)
448+
* 1e6
449+
* 1.0
436450
)
437451
rvv_init = (
438-
geo.mesh.comm.allreduce(geometry.volume("RV", u=problem.u), op=MPI.SUM) * 1e6 * 1.0
452+
geo.mesh.comm.allreduce(geometry.volume("RV", u=problem.u), op=MPI.SUM)
453+
* 1e6
454+
* 1.0
439455
)
440456
print(f"Initial volume (LV): {lvv_init} mL and (RV): {rvv_init} mL")
441457
init_state = {
442458
"V_LV": lvv_initial * 1e6 * mL,
443459
"V_RV": rvv_initial * 1e6 * mL,
444-
'p_AR_PUL': p_AR_PUL * mmHg,
445-
'p_AR_SYS': p_AR_SYS * mmHg,
446-
'p_VEN_PUL': p_VEN_PUL * mmHg,
447-
'p_VEN_SYS': p_VEN_SYS * mmHg,
460+
"p_AR_PUL": p_AR_PUL * mmHg,
461+
"p_AR_SYS": p_AR_SYS * mmHg,
462+
"p_VEN_PUL": p_VEN_PUL * mmHg,
463+
"p_VEN_SYS": p_VEN_SYS * mmHg,
448464
}
449465

450466
regazzoni_parmeters = circulation.regazzoni2020.Regazzoni2020.default_parameters()
@@ -475,7 +491,9 @@ def p_BiV_func(V_LV, V_RV, t):
475491
)
476492
# Set end time for early stopping if running in CI
477493
end_time = 2 * dt if os.getenv("CI") else None
478-
regazzoni.solve(num_beats=num_beats, initial_state=init_state, dt=dt, T=end_time) #, checkpoint=RR)
494+
regazzoni.solve(
495+
num_beats=num_beats, initial_state=init_state, dt=dt, T=end_time,
496+
) # , checkpoint=RR)
479497
regazzoni.print_info()
480498

481499

@@ -534,10 +552,20 @@ def p_BiV_func(V_LV, V_RV, t):
534552
print(f"HR before: {HR_before}, HR after: {HR_after}")
535553

536554
get_activation_before = run_TorOrdLand(
537-
comm, outdir, HR_before, Ta_factor=1, label="before", dt=dt,
555+
comm,
556+
outdir,
557+
HR_before,
558+
Ta_factor=1,
559+
label="before",
560+
dt=dt,
538561
)
539562
get_activation_after = run_TorOrdLand(
540-
comm, outdir, HR_after, Ta_factor=C_PRSW_factor, label="after", dt=dt,
563+
comm,
564+
outdir,
565+
HR_after,
566+
Ta_factor=C_PRSW_factor,
567+
label="after",
568+
dt=dt,
541569
)
542570

543571
run_3D_model(

demo/boundary_conditions/lv_ellipsoid_fixed_x.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,6 @@ def dirichlet_bc(V: dolfinx.fem.FunctionSpace):
131131
bcs=bcs,
132132
)
133133

134-
log.set_log_level(log.LogLevel.INFO)
135-
136134
# ### Phase 1: Passive Inflation
137135

138136
vtx = dolfinx.io.VTXWriter(geometry.mesh.comm, outdir / "lv_displacement.bp", [problem.u], engine="BP4")

demo/boundary_conditions/ukb_bcs.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
from pathlib import Path
2424
from mpi4py import MPI
2525
import dolfinx
26-
from dolfinx import log
2726
import cardiac_geometries
2827
import cardiac_geometries.geometry
2928
import pulse
@@ -192,8 +191,6 @@ def dirichlet_bc(V: dolfinx.fem.FunctionSpace):
192191
bcs=bcs,
193192
)
194193

195-
log.set_log_level(log.LogLevel.INFO)
196-
197194
# ### Phase 1: Passive Inflation
198195
# We ramp up the pressure in both ventricles.
199196

demo/geometries/biv_ellipsoid.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,11 @@
3535
from mpi4py import MPI
3636
import numpy as np
3737
import dolfinx
38-
from dolfinx import log
3938
import ldrb
4039
import cardiac_geometries
4140
import cardiac_geometries.geometry
4241
import pulse
4342

44-
# We enable info logging to track solver progress.
45-
46-
# log.set_log_level(log.LogLevel.INFO)
47-
4843
# ## Geometry and Microstructure
4944
#
5045
# We generate the mesh and fibers if they don't already exist.

0 commit comments

Comments
 (0)