Skip to content

Commit ee60faa

Browse files
authored
Merge pull request #137 from finsberg/less-logging-in-demos
Less logging in demos
2 parents 8763d18 + 682cd47 commit ee60faa

14 files changed

Lines changed: 45 additions & 34 deletions

demo/benchmark/problem2.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import pulse
3434

3535
logging.basicConfig(level=logging.INFO)
36+
logging.getLogger("scifem").setLevel(logging.WARNING)
3637

3738
# ## 1. Geometry
3839
#
@@ -66,6 +67,7 @@
6667
)
6768

6869
# We convert to `pulse.Geometry`. We assume the mesh units are mm (consistent with parameters).
70+
6971
geometry = pulse.Geometry.from_cardiac_geometries(geo, metadata={"quadrature_degree": 4})
7072

7173
# ## 2. Constitutive Model
@@ -74,6 +76,7 @@
7476
# By setting $b_f = b_t = b_{fs} = 1.0$, the exponent $Q$ becomes $Q = (E_{11}^2 + E_{22}^2 + E_{33}^2 + 2E_{12}^2 + \dots) = \text{tr}(\mathbf{E}^2)$, making the model isotropic.
7577
# For an isotropic material, the fiber direction vectors don't affect the energy (as b parameters are equal),
7678
# but the class requires them. We can use dummy fields or the ones from the mesh.
79+
7780
material = pulse.Guccione(
7881
C=pulse.Variable(dolfinx.fem.Constant(geometry.mesh, dolfinx.default_scalar_type(10.0)), "kPa"),
7982
bf=pulse.Variable(dolfinx.fem.Constant(geometry.mesh, dolfinx.default_scalar_type(1.0)), "dimensionless"),

demo/benchmark/problem3.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
import cardiac_geometries
3838
import pulse
3939

40-
log.set_log_level(log.LogLevel.INFO)
40+
# log.set_log_level(log.LogLevel.INFO)
4141

4242
# ## 1. Geometry and Fibers
4343
# We regenerate the mesh with the specific fiber angles required for Problem 3 ($+90^\circ$ to $-90^\circ$).

demo/biv_ellipsoid.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343

4444
# We enable info logging to track solver progress.
4545

46-
log.set_log_level(log.LogLevel.INFO)
46+
# log.set_log_level(log.LogLevel.INFO)
4747

4848
# ## Geometry and Microstructure
4949
#

demo/lv_ellipsoid.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,6 @@
157157
parameters={"base_bc": pulse.BaseBC.fixed},
158158
)
159159

160-
# We initialize the solver log level to INFO to track convergence.
161-
162-
log.set_log_level(log.LogLevel.INFO)
163-
164160
# ### Phase 1: Passive Inflation
165161
# We first solve the passive mechanics by increasing the endocardial pressure.
166162
# We initialize a VTX writer to save the displacement field for visualization.

demo/lv_ellipsoid_fixed_x.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
# (Holzapfel-Ogden with Active Stress) as in the [base example](lv_ellipsoid.ipynb).
3030

3131
# 1. Generate Mesh
32+
3233
outdir = Path("lv_ellipsoid_custom_bcs")
3334
outdir.mkdir(parents=True, exist_ok=True)
3435
geodir = outdir / "geometry"
@@ -41,13 +42,15 @@
4142
)
4243

4344
# 2. Load Geometry
45+
4446
geo = cardiac_geometries.geometry.Geometry.from_folder(
4547
comm=MPI.COMM_WORLD,
4648
folder=geodir,
4749
)
4850
geometry = pulse.Geometry.from_cardiac_geometries(geo, metadata={"quadrature_degree": 4})
4951

5052
# 3. Define Constitutive Model
53+
5154
material_params = pulse.HolzapfelOgden.transversely_isotropic_parameters()
5255
material = pulse.HolzapfelOgden(f0=geo.f0, s0=geo.s0, **material_params)
5356

demo/maths.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,10 @@
2020

2121
logging.basicConfig(level=logging.INFO)
2222
logger = logging.getLogger("pulse")
23+
for lib in ["trame_server", "wslink"]:
24+
logging.getLogger(lib).setLevel(logging.WARNING)
2325
logger.setLevel(logging.DEBUG)
24-
dolfinx.log.set_log_level(dolfinx.log.LogLevel.INFO)
26+
# dolfinx.log.set_log_level(dolfinx.log.LogLevel.INFO)
2527

2628
# %% [markdown]
2729
# ## 1. Geometry and Mesh

demo/prestress_biv.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,14 @@
7171

7272
comm = MPI.COMM_WORLD
7373
logging.basicConfig(level=logging.INFO)
74-
dolfinx.log.set_log_level(dolfinx.log.LogLevel.INFO)
74+
logging.getLogger("scifem").setLevel(logging.WARNING)
7575

7676
# ## 1. Geometry Generation (Target Configuration)
7777
#
78-
# We generate an idealized Bi-Ventricular (BiV) geometry using `cardiac-geometries` which represents our **target**
79-
# geometry (e.g., the end-diastolic state). This includes both the Left Ventricle (LV) and Right Ventricle (RV).
80-
# We also generate the fiber architecture.
78+
# We generate an Bi-Ventricular (BiV) geometry using `cardiac-geometries` which represents our **target**
79+
# geometry (e.g., the end-diastolic state). This geometry is generated from the mean shape of an
80+
# [atlas from the UK Biobank](https://github.com/ComputationalPhysiology/ukb-atlas).
81+
# We also generate the fiber architecture using a [rule-based method](https://github.com/finsberg/fenicsx-ldrb).
8182

8283
mode = -1
8384
std = 0

demo/prestress_fixedpoint_unloader.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
# acquired geometry and the known end-diastolic pressure. This process is often called "pre-stressing" or
99
# "inverse mechanics".
1010
#
11-
# In this demo, we solve the inverse problem using a **Fixed-Point Iteration** (also known as the Backward Displacement Method).
11+
# In this demo, we solve the inverse problem using a **Fixed-Point Iteration** (also known as the Backward Displacement Method o
12+
# Sellier's method) {cite}`SELLIER20111461`.
1213
# Unlike the Inverse Elasticity Problem (IEP) which formulates equilibrium on the target configuration, this method
1314
# iteratively updates the reference coordinates $\mathbf{X}$ by subtracting the displacement $\mathbf{u}$ computed from a
1415
# forward solve.
@@ -23,7 +24,7 @@
2324
# 2. For iteration $k=0, 1, \dots$:
2425
# a. Solve the **Forward** mechanics problem on the geometry defined by $\mathbf{X}_k$ to get displacement $\mathbf{u}_k$.
2526
# b. Update the reference geometry:
26-
# $$ \mathbf{X}_{k+1} = \mathbf{x}_{target} - \mathbf{u}_k $$
27+
# $ \mathbf{X}_{k+1} = \mathbf{x}_{target} - \mathbf{u}_k $
2728
# c. Check convergence: $||\mathbf{X}_{k+1} - \mathbf{X}_k|| < \text{tol}$.
2829
#
2930
# In `fenicsx-pulse`, the `FixedPointUnloader` class automates this iterative process.

demo/time_dependent_bestel_biv.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626

2727
logging.basicConfig(level=logging.INFO)
28+
logger = logging.getLogger("pulse")
2829
comm = MPI.COMM_WORLD
2930

3031
outdir = Path("time-dependent-bestel-biv")
@@ -124,7 +125,7 @@
124125
problem = pulse.problem.DynamicProblem(model=model, geometry=geometry, bcs=bcs)
125126

126127

127-
log.set_log_level(log.LogLevel.INFO)
128+
# log.set_log_level(log.LogLevel.INFO)
128129
problem.solve()
129130

130131
dt = problem.parameters["dt"].to_base_units()

demo/time_dependent_bestel_lv.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@
199199
# Next we set up the logging and the MPI communicator
200200

201201
logging.basicConfig(level=logging.INFO)
202+
logger = logging.getLogger("pulse")
202203
comm = MPI.COMM_WORLD
203204

204205
# and create an output directory
@@ -277,11 +278,11 @@
277278
#
278279

279280
alpha_epi = pulse.Variable(
280-
dolfinx.fem.Constant(geometry.mesh, dolfinx.default_scalar_type(1e8)), "Pa / m",
281+
dolfinx.fem.Constant(geometry.mesh, dolfinx.default_scalar_type(1e8)), "Pa / m",
281282
)
282283
robin_epi_u = pulse.RobinBC(value=alpha_epi, marker=geometry.markers["EPI"][0])
283284
beta_epi = pulse.Variable(
284-
dolfinx.fem.Constant(geometry.mesh, dolfinx.default_scalar_type(5e3)), "Pa s/ m",
285+
dolfinx.fem.Constant(geometry.mesh, dolfinx.default_scalar_type(5e3)), "Pa s/ m",
285286
)
286287
robin_epi_v = pulse.RobinBC(value=beta_epi, marker=geometry.markers["EPI"][0], damping=True)
287288

@@ -290,7 +291,7 @@
290291
)
291292
robin_base_u = pulse.RobinBC(value=alpha_base, marker=geometry.markers["BASE"][0])
292293
beta_base = pulse.Variable(
293-
dolfinx.fem.Constant(geometry.mesh, dolfinx.default_scalar_type(5e3)), "Pa s/ m",
294+
dolfinx.fem.Constant(geometry.mesh, dolfinx.default_scalar_type(5e3)), "Pa s/ m",
294295
)
295296
robin_base_v = pulse.RobinBC(value=beta_base, marker=geometry.markers["BASE"][0], damping=True)
296297

@@ -305,7 +306,7 @@
305306

306307
# Note that we also specify that the base is free to move, meaning that there will be no Dirichlet boundary conditions on the base. Now we can do an initial solve the problem
307308

308-
log.set_log_level(log.LogLevel.INFO)
309+
# log.set_log_level(log.LogLevel.INFO)
309310
problem.solve()
310311

311312
# The next step is to get the activation and pressure as a function of time. For this we use the time step from the problem parameters
@@ -357,13 +358,13 @@
357358

358359
volume_form = dolfinx.fem.form(geometry.volume_form(u=problem.u) * geometry.ds(geometry.markers["ENDO"][0]))
359360
initial_volume = geo.mesh.comm.allreduce(dolfinx.fem.assemble_scalar(volume_form))
360-
print(f"Initial volume: {initial_volume}")
361+
logger.info(f"Initial volume: {initial_volume}")
361362

362363
# and then loop over the time steps and solve the problem for each time step
363364

364365
volumes = []
365366
for i, (tai, pi, ti) in enumerate(zip(activation, pressure, times)):
366-
print(f"Solving for time {ti}, activation {tai}, pressure {pi}")
367+
logger.info(f"Solving for time {ti}, activation {tai}, pressure {pi}")
367368
traction.assign(pi)
368369
Ta.assign(tai)
369370
problem.solve()

0 commit comments

Comments
 (0)