Simulation of muscle contraction with a hyperelastic material model#
This demo simulates the active contraction of an idealized skeletal muscle.
We use a Transversely Isotropic Hyperelastic framework to capture the complex material behavior of muscle tissue:
Passive Elasticity: The passive resistance of the tissue to deformation.
Active Contraction: The force generated along muscle fibers when stimulated (\(\alpha > 0\)).
Incompressibility: Muscle volume remains constant during contraction (\(J=1\)).
In this demo, we will load an idealized muscle geometry, apply tendon-like boundary conditions, and simulate a contraction.
from pathlib import Path
import numpy as np
import dolfinx
import pyvista as pv
pv.set_jupyter_backend("static")
from musclex.geometry import IdealizedFusiform
from musclex.material import MuscleRohrle
from musclex.postprocess_mechanics import postprocess_from_file
# Set FEniCSx log level
# Set to INFO or DEBUG for more detailed logs
dolfinx.log.set_log_level(dolfinx.log.LogLevel.WARNING)
root_dir = Path("..")
config_path = root_dir / "config_files/material_rohrle.yml"
mesh_path = root_dir / "meshes/muscle-idealized/muscle-idealized.xdmf"
results_dir = root_dir / "results/demos/contraction_demo"
results_dir.mkdir(parents=True, exist_ok=True) # ensure it exists
Load geometry and fiber architecture#
Muscle tissue is highly anisotropic, meaning its mechanical properties depend on direction. The fiber field (\(a_0\)) defines the local orientation of muscle bundles. During contraction, active force is generated exclusively along these fibers.
Here, we load an idealized fusiform mesh where fibers follow the curvature of the muscle.
print(f"Loading mesh from: {mesh_path.name}...")
geometry = IdealizedFusiform(mesh_path)
geometry.info()
Loading mesh from: muscle-idealized.xdmf...
No fiber orientation file provided. Calculating analytical fiber direction.
--- Geometry info ---
Geometry type: idealized_fusiform
Mesh dimension: 3
Number of cells: 1997
Mesh size h_max: 1.88e-02, h_min: 7.19e-03
Volume: 2.39e-04 m^3
We can visualize the geometry, tagged boundary for boundary conditions, and fiber architecture:
geometry.plot(mode="all")
2026-01-09 15:13:17.957 ( 1.214s) [ 7FCE6C654140]vtkXOpenGLRenderWindow.:1458 WARN| bad X server connection. DISPLAY=:99.0
<pyvista.plotting.plotter.Plotter at 0x7fce05b02570>
Initialize material and boundary conditions#
We apply Robin boundary conditions at the muscle ends (insertion and origin). Instead of fixing the ends rigidly, this models the tendons as elastic springs. This allows the muscle to shorten realistically against a load, rather than just bulging in place.
material_model = MuscleRohrle(
geometry.domain, # The computational mesh
geometry.ft, # Facet tags marking boundaries
config_path, # Material parameters (stiffness, active force scale)
geometry.fibers, # Fiber orientation field
results_dir, # Output directory
clamp_type="robin", # Spring-like tendon boundaries
)
Setting up FEM...
dofs: 11303
Setup FEM finished in 0.02 seconds.
Run the simulation#
We simulate the contraction by ramping the activation parameter \(\alpha\) from 0.0 (Passive) to 1.0 (Fully Active).
The solver performs a quasi-static simulation, meaning it solves for static equilibrium at every step. This captures the sequence of deformed shapes as the muscle contracts.
steps = 21
alphas = np.linspace(0, 1.0, steps)
np.save(results_dir / "activation_levels.npy", alphas) # needed for postprocessing
# The solver handles the nonlinear Newton iterations for each load step
material_model.solve(alphas)
Applying Robin BC with k=100000.0.
Using 'robin' clamp type.
Starting simulation...
==================================================
Solving for activation level 0.0
0 SNES Function norm 2.095855802384e+01
Iteration 0 residual: 20.958558023838446
Residual norms for tmp_ solve.
0 KSP Residual norm 2.095855802384e+01
1 KSP Residual norm 1.632900641035e-14
1 SNES Function norm 2.382409490085e-14
Iteration 1 residual: 2.3824094900847193e-14
F_reac = -1.0000961710513829e-15
Output written for activation level 0.000 to ../results/demos/contraction_demo/output_pp.bp
==================================================
Solving for activation level 0.05
0 SNES Function norm 1.790694600201e+00
Iteration 0 residual: 1.7906946002013995
Residual norms for tmp_ solve.
0 KSP Residual norm 1.790694600201e+00
1 KSP Residual norm 8.564549639642e-14
1 SNES Function norm 4.639105245947e-01
Iteration 1 residual: 0.46391052459473925
Residual norms for tmp_ solve.
0 KSP Residual norm 4.639105245947e-01
1 KSP Residual norm 1.880766961910e-14
2 SNES Function norm 1.006263704313e-02
Iteration 2 residual: 0.01006263704312518
Residual norms for tmp_ solve.
0 KSP Residual norm 1.006263704313e-02
1 KSP Residual norm 4.960750547571e-16
3 SNES Function norm 7.203577371314e-06
Iteration 3 residual: 7.203577371313541e-06
Residual norms for tmp_ solve.
0 KSP Residual norm 7.203577371314e-06
1 KSP Residual norm 7.040143329855e-17
4 SNES Function norm 9.244966841387e-07
Iteration 4 residual: 9.244966841386661e-07
Residual norms for tmp_ solve.
0 KSP Residual norm 9.244966841387e-07
1 KSP Residual norm 4.461179168358e-19
5 SNES Function norm 3.715944395372e-11
Iteration 5 residual: 3.715944395372392e-11
F_reac = 0.4051886215037887
Output written for activation level 0.050 to ../results/demos/contraction_demo/output_pp.bp
==================================================
Solving for activation level 0.1
0 SNES Function norm 1.402344980360e+00
Iteration 0 residual: 1.4023449803597017
Residual norms for tmp_ solve.
0 KSP Residual norm 1.402344980360e+00
1 KSP Residual norm 5.506355771261e-14
1 SNES Function norm 1.550295636241e-01
Iteration 1 residual: 0.15502956362409737
Residual norms for tmp_ solve.
0 KSP Residual norm 1.550295636241e-01
1 KSP Residual norm 6.481658348061e-15
2 SNES Function norm 5.962986304102e-03
Iteration 2 residual: 0.005962986304102402
Residual norms for tmp_ solve.
0 KSP Residual norm 5.962986304102e-03
1 KSP Residual norm 1.089916613652e-16
3 SNES Function norm 8.962273277306e-06
Iteration 3 residual: 8.96227327730636e-06
Residual norms for tmp_ solve.
0 KSP Residual norm 8.962273277306e-06
1 KSP Residual norm 2.212573208021e-17
4 SNES Function norm 7.971576901187e-08
Iteration 4 residual: 7.971576901186772e-08
Residual norms for tmp_ solve.
0 KSP Residual norm 7.971576901187e-08
1 KSP Residual norm 1.346775743512e-20
5 SNES Function norm 5.324146332442e-14
Iteration 5 residual: 5.324146332442286e-14
F_reac = 0.5805958687244576
Output written for activation level 0.100 to ../results/demos/contraction_demo/output_pp.bp
==================================================
Solving for activation level 0.15000000000000002
0 SNES Function norm 1.123508834243e+00
Iteration 0 residual: 1.1235088342432986
Residual norms for tmp_ solve.
0 KSP Residual norm 1.123508834243e+00
1 KSP Residual norm 4.357780669412e-14
1 SNES Function norm 8.442461055045e-02
Iteration 1 residual: 0.08442461055044749
Residual norms for tmp_ solve.
0 KSP Residual norm 8.442461055045e-02
1 KSP Residual norm 2.298301204052e-15
2 SNES Function norm 1.790597421478e-04
Iteration 2 residual: 0.00017905974214784868
Residual norms for tmp_ solve.
0 KSP Residual norm 1.790597421478e-04
1 KSP Residual norm 6.195983637498e-17
3 SNES Function norm 4.549198257326e-07
Iteration 3 residual: 4.549198257326065e-07
Residual norms for tmp_ solve.
0 KSP Residual norm 4.549198257326e-07
1 KSP Residual norm 4.533959683649e-18
4 SNES Function norm 3.084214431366e-09
Iteration 4 residual: 3.084214431366224e-09
F_reac = 0.6708365696574521
Output written for activation level 0.150 to ../results/demos/contraction_demo/output_pp.bp
==================================================
Solving for activation level 0.2
0 SNES Function norm 9.330308321429e-01
Iteration 0 residual: 0.9330308321429046
Residual norms for tmp_ solve.
0 KSP Residual norm 9.330308321429e-01
1 KSP Residual norm 3.775403209246e-14
1 SNES Function norm 1.995031822625e-02
Iteration 1 residual: 0.01995031822625476
Residual norms for tmp_ solve.
0 KSP Residual norm 1.995031822625e-02
1 KSP Residual norm 3.021568220516e-16
2 SNES Function norm 1.152340808236e-05
Iteration 2 residual: 1.1523408082356401e-05
Residual norms for tmp_ solve.
0 KSP Residual norm 1.152340808236e-05
1 KSP Residual norm 5.295935124638e-17
3 SNES Function norm 3.405109669422e-07
Iteration 3 residual: 3.405109669421796e-07
Residual norms for tmp_ solve.
0 KSP Residual norm 3.405109669422e-07
1 KSP Residual norm 3.448842187366e-19
4 SNES Function norm 1.562121088300e-11
Iteration 4 residual: 1.5621210882995572e-11
F_reac = 0.7270228720595248
Output written for activation level 0.200 to ../results/demos/contraction_demo/output_pp.bp
==================================================
Solving for activation level 0.25
0 SNES Function norm 8.059460382498e-01
Iteration 0 residual: 0.8059460382498251
Residual norms for tmp_ solve.
0 KSP Residual norm 8.059460382498e-01
1 KSP Residual norm 3.081490514124e-14
1 SNES Function norm 1.368249674708e-02
Iteration 1 residual: 0.013682496747079933
Residual norms for tmp_ solve.
0 KSP Residual norm 1.368249674708e-02
1 KSP Residual norm 2.322263860669e-16
2 SNES Function norm 5.699141910422e-06
Iteration 2 residual: 5.699141910421809e-06
Residual norms for tmp_ solve.
0 KSP Residual norm 5.699141910422e-06
1 KSP Residual norm 4.698591523919e-17
3 SNES Function norm 2.656913480944e-07
Iteration 3 residual: 2.6569134809438145e-07
Residual norms for tmp_ solve.
0 KSP Residual norm 2.656913480944e-07
1 KSP Residual norm 1.060184148035e-19
4 SNES Function norm 1.247906669099e-12
Iteration 4 residual: 1.2479066690989739e-12
F_reac = 0.7654834338979024
Output written for activation level 0.250 to ../results/demos/contraction_demo/output_pp.bp
==================================================
Solving for activation level 0.30000000000000004
0 SNES Function norm 7.140476940687e-01
Iteration 0 residual: 0.7140476940687271
Residual norms for tmp_ solve.
0 KSP Residual norm 7.140476940687e-01
1 KSP Residual norm 2.586079639865e-14
1 SNES Function norm 1.025400375442e-02
Iteration 1 residual: 0.010254003754418537
Residual norms for tmp_ solve.
0 KSP Residual norm 1.025400375442e-02
1 KSP Residual norm 2.116339869098e-16
2 SNES Function norm 3.287322654195e-06
Iteration 2 residual: 3.2873226541947656e-06
Residual norms for tmp_ solve.
0 KSP Residual norm 3.287322654195e-06
1 KSP Residual norm 4.216175580128e-17
3 SNES Function norm 2.147428585677e-07
Iteration 3 residual: 2.1474285856767406e-07
Residual norms for tmp_ solve.
0 KSP Residual norm 2.147428585677e-07
1 KSP Residual norm 3.358323140786e-20
4 SNES Function norm 1.761521081078e-13
Iteration 4 residual: 1.7615210810782266e-13
F_reac = 0.7934096053458471
Output written for activation level 0.300 to ../results/demos/contraction_demo/output_pp.bp
==================================================
Solving for activation level 0.35000000000000003
0 SNES Function norm 6.438281241067e-01
Iteration 0 residual: 0.6438281241066679
Residual norms for tmp_ solve.
0 KSP Residual norm 6.438281241067e-01
1 KSP Residual norm 2.433332964452e-14
1 SNES Function norm 8.111651564421e-03
Iteration 1 residual: 0.008111651564421445
Residual norms for tmp_ solve.
0 KSP Residual norm 8.111651564421e-03
1 KSP Residual norm 2.004512911877e-16
2 SNES Function norm 2.097987670347e-06
Iteration 2 residual: 2.0979876703465525e-06
Residual norms for tmp_ solve.
0 KSP Residual norm 2.097987670347e-06
1 KSP Residual norm 4.192245647114e-17
3 SNES Function norm 1.761857677125e-07
Iteration 3 residual: 1.7618576771250182e-07
Residual norms for tmp_ solve.
0 KSP Residual norm 1.761857677125e-07
1 KSP Residual norm 1.094046285687e-20
4 SNES Function norm 1.436130270237e-13
Iteration 4 residual: 1.436130270236876e-13
F_reac = 0.8147058319440883
Output written for activation level 0.350 to ../results/demos/contraction_demo/output_pp.bp
==================================================
Solving for activation level 0.4
0 SNES Function norm 5.880636204001e-01
Iteration 0 residual: 0.5880636204001474
Residual norms for tmp_ solve.
0 KSP Residual norm 5.880636204001e-01
1 KSP Residual norm 2.182680495458e-14
1 SNES Function norm 6.658508062215e-03
Iteration 1 residual: 0.006658508062215043
Residual norms for tmp_ solve.
0 KSP Residual norm 6.658508062215e-03
1 KSP Residual norm 1.882339594510e-16
2 SNES Function norm 1.445415463309e-06
Iteration 2 residual: 1.4454154633092518e-06
Residual norms for tmp_ solve.
0 KSP Residual norm 1.445415463309e-06
1 KSP Residual norm 3.903170499640e-17
3 SNES Function norm 1.460297051302e-07
Iteration 3 residual: 1.4602970513023143e-07
Residual norms for tmp_ solve.
0 KSP Residual norm 1.460297051302e-07
1 KSP Residual norm 3.718336411409e-21
4 SNES Function norm 1.612358660284e-13
Iteration 4 residual: 1.6123586602844862e-13
F_reac = 0.8315823729958736
Output written for activation level 0.400 to ../results/demos/contraction_demo/output_pp.bp
==================================================
Solving for activation level 0.45
0 SNES Function norm 5.424938327768e-01
Iteration 0 residual: 0.542493832776811
Residual norms for tmp_ solve.
0 KSP Residual norm 5.424938327768e-01
1 KSP Residual norm 2.003325646639e-14
1 SNES Function norm 5.611918896710e-03
Iteration 1 residual: 0.005611918896709549
Residual norms for tmp_ solve.
0 KSP Residual norm 5.611918896710e-03
1 KSP Residual norm 1.774075301797e-16
2 SNES Function norm 1.056273741211e-06
Iteration 2 residual: 1.0562737412109924e-06
Residual norms for tmp_ solve.
0 KSP Residual norm 1.056273741211e-06
1 KSP Residual norm 3.629350431481e-17
3 SNES Function norm 1.217718929349e-07
Iteration 3 residual: 1.2177189293494326e-07
Residual norms for tmp_ solve.
0 KSP Residual norm 1.217718929349e-07
1 KSP Residual norm 2.306566316033e-21
4 SNES Function norm 1.768747382494e-13
Iteration 4 residual: 1.76874738249359e-13
F_reac = 0.8454059681788271
Output written for activation level 0.450 to ../results/demos/contraction_demo/output_pp.bp
==================================================
Solving for activation level 0.5
0 SNES Function norm 5.044228184745e-01
Iteration 0 residual: 0.5044228184745165
Residual norms for tmp_ solve.
0 KSP Residual norm 5.044228184745e-01
1 KSP Residual norm 1.862417032672e-14
1 SNES Function norm 4.824194513961e-03
Iteration 1 residual: 0.004824194513960801
Residual norms for tmp_ solve.
0 KSP Residual norm 4.824194513961e-03
1 KSP Residual norm 1.681799914768e-16
2 SNES Function norm 8.078488556831e-07
Iteration 2 residual: 8.07848855683131e-07
Residual norms for tmp_ solve.
0 KSP Residual norm 8.078488556831e-07
1 KSP Residual norm 3.305796711716e-17
3 SNES Function norm 1.019432908949e-07
Iteration 3 residual: 1.0194329089492768e-07
Residual norms for tmp_ solve.
0 KSP Residual norm 1.019432908949e-07
1 KSP Residual norm 2.523137479153e-21
4 SNES Function norm 1.842251261131e-13
Iteration 4 residual: 1.842251261131487e-13
F_reac = 0.8570630559996745
Output written for activation level 0.500 to ../results/demos/contraction_demo/output_pp.bp
==================================================
Solving for activation level 0.55
0 SNES Function norm 4.720512095972e-01
Iteration 0 residual: 0.47205120959719793
Residual norms for tmp_ solve.
0 KSP Residual norm 4.720512095972e-01
1 KSP Residual norm 1.778277732044e-14
1 SNES Function norm 4.211065744380e-03
Iteration 1 residual: 0.004211065744380464
Residual norms for tmp_ solve.
0 KSP Residual norm 4.211065744380e-03
1 KSP Residual norm 1.636249928887e-16
2 SNES Function norm 6.401519670719e-07
Iteration 2 residual: 6.401519670718903e-07
Residual norms for tmp_ solve.
0 KSP Residual norm 6.401519670719e-07
1 KSP Residual norm 3.330087889960e-17
3 SNES Function norm 8.557657055449e-08
Iteration 3 residual: 8.557657055449243e-08
Residual norms for tmp_ solve.
0 KSP Residual norm 8.557657055449e-08
1 KSP Residual norm 2.378489455074e-21
4 SNES Function norm 2.018822117617e-13
Iteration 4 residual: 2.0188221176174005e-13
F_reac = 0.8671504798820194
Output written for activation level 0.550 to ../results/demos/contraction_demo/output_pp.bp
==================================================
Solving for activation level 0.6000000000000001
0 SNES Function norm 4.441267365269e-01
Iteration 0 residual: 0.44412673652687407
Residual norms for tmp_ solve.
0 KSP Residual norm 4.441267365269e-01
1 KSP Residual norm 1.729321357015e-14
1 SNES Function norm 3.721137441180e-03
Iteration 1 residual: 0.0037211374411801547
Residual norms for tmp_ solve.
0 KSP Residual norm 3.721137441180e-03
1 KSP Residual norm 1.532398233245e-16
2 SNES Function norm 5.216240661180e-07
Iteration 2 residual: 5.216240661179823e-07
Residual norms for tmp_ solve.
0 KSP Residual norm 5.216240661180e-07
1 KSP Residual norm 2.968575769913e-17
3 SNES Function norm 7.198729268815e-08
Iteration 3 residual: 7.198729268815227e-08
Residual norms for tmp_ solve.
0 KSP Residual norm 7.198729268815e-08
1 KSP Residual norm 2.161379798060e-21
4 SNES Function norm 2.314010590889e-13
Iteration 4 residual: 2.3140105908886625e-13
F_reac = 0.8760823679869287
Output written for activation level 0.600 to ../results/demos/contraction_demo/output_pp.bp
==================================================
Solving for activation level 0.65
0 SNES Function norm 4.197479465739e-01
Iteration 0 residual: 0.4197479465739278
Residual norms for tmp_ solve.
0 KSP Residual norm 4.197479465739e-01
1 KSP Residual norm 1.636052255429e-14
1 SNES Function norm 3.321336672612e-03
Iteration 1 residual: 0.0033213366726121294
Residual norms for tmp_ solve.
0 KSP Residual norm 3.321336672612e-03
1 KSP Residual norm 1.489795102587e-16
2 SNES Function norm 4.346173072254e-07
Iteration 2 residual: 4.3461730722544145e-07
Residual norms for tmp_ solve.
0 KSP Residual norm 4.346173072254e-07
1 KSP Residual norm 2.846198371026e-17
3 SNES Function norm 6.066355739650e-08
Iteration 3 residual: 6.066355739650442e-08
Residual norms for tmp_ solve.
0 KSP Residual norm 6.066355739650e-08
1 KSP Residual norm 1.952951202745e-21
4 SNES Function norm 2.461222880126e-13
Iteration 4 residual: 2.4612228801263693e-13
F_reac = 0.8841532331321
Output written for activation level 0.650 to ../results/demos/contraction_demo/output_pp.bp
==================================================
Solving for activation level 0.7000000000000001
0 SNES Function norm 3.982475845539e-01
Iteration 0 residual: 0.3982475845538965
Residual norms for tmp_ solve.
0 KSP Residual norm 3.982475845539e-01
1 KSP Residual norm 1.563660813523e-14
1 SNES Function norm 2.989428518989e-03
Iteration 1 residual: 0.002989428518989193
Residual norms for tmp_ solve.
0 KSP Residual norm 2.989428518989e-03
1 KSP Residual norm 1.407360532222e-16
2 SNES Function norm 3.687288065361e-07
Iteration 2 residual: 3.687288065361453e-07
Residual norms for tmp_ solve.
0 KSP Residual norm 3.687288065361e-07
1 KSP Residual norm 2.656588798852e-17
3 SNES Function norm 5.120664723387e-08
Iteration 3 residual: 5.120664723386708e-08
Residual norms for tmp_ solve.
0 KSP Residual norm 5.120664723387e-08
1 KSP Residual norm 1.783757523712e-21
4 SNES Function norm 2.476397112561e-13
Iteration 4 residual: 2.4763971125606574e-13
F_reac = 0.8915768469750047
Output written for activation level 0.700 to ../results/demos/contraction_demo/output_pp.bp
==================================================
Solving for activation level 0.75
0 SNES Function norm 3.791200485727e-01
Iteration 0 residual: 0.3791200485727457
Residual norms for tmp_ solve.
0 KSP Residual norm 3.791200485727e-01
1 KSP Residual norm 1.638764132410e-14
1 SNES Function norm 2.709913911068e-03
Iteration 1 residual: 0.002709913911068466
Residual norms for tmp_ solve.
0 KSP Residual norm 2.709913911068e-03
1 KSP Residual norm 1.390741624043e-16
2 SNES Function norm 3.175349725882e-07
Iteration 2 residual: 3.175349725881695e-07
Residual norms for tmp_ solve.
0 KSP Residual norm 3.175349725882e-07
1 KSP Residual norm 2.518225902021e-17
3 SNES Function norm 4.329718420150e-08
Iteration 3 residual: 4.329718420150046e-08
Residual norms for tmp_ solve.
0 KSP Residual norm 4.329718420150e-08
1 KSP Residual norm 1.584637993628e-21
4 SNES Function norm 2.645027673132e-13
Iteration 4 residual: 2.645027673131597e-13
F_reac = 0.8985110562126504
Output written for activation level 0.750 to ../results/demos/contraction_demo/output_pp.bp
==================================================
Solving for activation level 0.8
0 SNES Function norm 3.619745040368e-01
Iteration 0 residual: 0.3619745040368446
Residual norms for tmp_ solve.
0 KSP Residual norm 3.619745040368e-01
1 KSP Residual norm 1.321483262378e-14
1 SNES Function norm 2.471657503356e-03
Iteration 1 residual: 0.002471657503356198
Residual norms for tmp_ solve.
0 KSP Residual norm 2.471657503356e-03
1 KSP Residual norm 1.349743837320e-16
2 SNES Function norm 2.769026504050e-07
Iteration 2 residual: 2.7690265040496484e-07
Residual norms for tmp_ solve.
0 KSP Residual norm 2.769026504050e-07
1 KSP Residual norm 2.574181222818e-17
3 SNES Function norm 3.667463125311e-08
Iteration 3 residual: 3.667463125310534e-08
Residual norms for tmp_ solve.
0 KSP Residual norm 3.667463125311e-08
1 KSP Residual norm 1.417111531595e-21
4 SNES Function norm 2.751417756994e-13
Iteration 4 residual: 2.75141775699445e-13
F_reac = 0.9050741094454148
Output written for activation level 0.800 to ../results/demos/contraction_demo/output_pp.bp
==================================================
Solving for activation level 0.8500000000000001
0 SNES Function norm 3.465035835174e-01
Iteration 0 residual: 0.3465035835173566
Residual norms for tmp_ solve.
0 KSP Residual norm 3.465035835174e-01
1 KSP Residual norm 1.449247528014e-14
1 SNES Function norm 2.266452081217e-03
Iteration 1 residual: 0.0022664520812173076
Residual norms for tmp_ solve.
0 KSP Residual norm 2.266452081217e-03
1 KSP Residual norm 1.325227173334e-16
2 SNES Function norm 2.440736073766e-07
Iteration 2 residual: 2.4407360737656025e-07
Residual norms for tmp_ solve.
0 KSP Residual norm 2.440736073766e-07
1 KSP Residual norm 2.127839506440e-17
3 SNES Function norm 3.112414576835e-08
Iteration 3 residual: 3.112414576835284e-08
Residual norms for tmp_ solve.
0 KSP Residual norm 3.112414576835e-08
1 KSP Residual norm 1.253557928241e-21
4 SNES Function norm 3.003347899564e-13
Iteration 4 residual: 3.0033478995639046e-13
F_reac = 0.9113556806065264
Output written for activation level 0.850 to ../results/demos/contraction_demo/output_pp.bp
==================================================
Solving for activation level 0.9
0 SNES Function norm 3.324619025074e-01
Iteration 0 residual: 0.33246190250744817
Residual norms for tmp_ solve.
0 KSP Residual norm 3.324619025074e-01
1 KSP Residual norm 1.248439630198e-14
1 SNES Function norm 2.088115185581e-03
Iteration 1 residual: 0.002088115185581482
Residual norms for tmp_ solve.
0 KSP Residual norm 2.088115185581e-03
1 KSP Residual norm 1.247285339694e-16
2 SNES Function norm 2.171468369233e-07
Iteration 2 residual: 2.17146836923253e-07
Residual norms for tmp_ solve.
0 KSP Residual norm 2.171468369233e-07
1 KSP Residual norm 1.999761046681e-17
3 SNES Function norm 2.646748817868e-08
Iteration 3 residual: 2.6467488178682756e-08
Residual norms for tmp_ solve.
0 KSP Residual norm 2.646748817868e-08
1 KSP Residual norm 1.181693459674e-21
4 SNES Function norm 3.146662047328e-13
Iteration 4 residual: 3.1466620473281145e-13
F_reac = 0.9174244808891873
Output written for activation level 0.900 to ../results/demos/contraction_demo/output_pp.bp
==================================================
Solving for activation level 0.9500000000000001
0 SNES Function norm 3.196509525566e-01
Iteration 0 residual: 0.3196509525565838
Residual norms for tmp_ solve.
0 KSP Residual norm 3.196509525566e-01
1 KSP Residual norm 1.216385023850e-14
1 SNES Function norm 1.931901166576e-03
Iteration 1 residual: 0.0019319011665758026
Residual norms for tmp_ solve.
0 KSP Residual norm 1.931901166576e-03
1 KSP Residual norm 1.230146752348e-16
2 SNES Function norm 1.947744960236e-07
Iteration 2 residual: 1.9477449602358033e-07
Residual norms for tmp_ solve.
0 KSP Residual norm 1.947744960236e-07
1 KSP Residual norm 1.844232609514e-17
3 SNES Function norm 2.255632147690e-08
Iteration 3 residual: 2.2556321476904183e-08
Residual norms for tmp_ solve.
0 KSP Residual norm 2.255632147690e-08
1 KSP Residual norm 1.109592387938e-21
4 SNES Function norm 3.217020281366e-13
Iteration 4 residual: 3.2170202813659733e-13
F_reac = 0.9233336195065661
Output written for activation level 0.950 to ../results/demos/contraction_demo/output_pp.bp
==================================================
Solving for activation level 1.0
0 SNES Function norm 3.079082515562e-01
Iteration 0 residual: 0.30790825155623475
Residual norms for tmp_ solve.
0 KSP Residual norm 3.079082515562e-01
1 KSP Residual norm 1.234226178145e-14
1 SNES Function norm 1.794107152318e-03
Iteration 1 residual: 0.0017941071523176228
Residual norms for tmp_ solve.
0 KSP Residual norm 1.794107152318e-03
1 KSP Residual norm 1.198493775604e-16
2 SNES Function norm 1.759769893762e-07
Iteration 2 residual: 1.7597698937616506e-07
Residual norms for tmp_ solve.
0 KSP Residual norm 1.759769893762e-07
1 KSP Residual norm 1.823446390863e-17
3 SNES Function norm 1.926708987555e-08
Iteration 3 residual: 1.9267089875549895e-08
Residual norms for tmp_ solve.
0 KSP Residual norm 1.926708987555e-08
1 KSP Residual norm 9.742502537687e-22
4 SNES Function norm 3.277975005995e-13
Iteration 4 residual: 3.277975005995015e-13
F_reac = 0.9291244452657159
Output written for activation level 1.000 to ../results/demos/contraction_demo/output_pp.bp
Simulation finished in 88.53 seconds.
(True,
[-1.0000961710513829e-15,
0.4051886215037887,
0.5805958687244576,
0.6708365696574521,
0.7270228720595248,
0.7654834338979024,
0.7934096053458471,
0.8147058319440883,
0.8315823729958736,
0.8454059681788271,
0.8570630559996745,
0.8671504798820194,
0.8760823679869287,
0.8841532331321,
0.8915768469750047,
0.8985110562126504,
0.9050741094454148,
0.9113556806065264,
0.9174244808891873,
0.9233336195065661,
0.9291244452657159])
Post-processing and visualization#
We generate 3D visualizations of the results. Key metrics to observe include:
Displacement: How much the muscle ends shorten.
Fiber Stretch (\(\lambda\)): Should decrease (\(\lambda < 1\)) as fibers contract.
Von-Mises stress: Internal tension generated by the active fibers.
postprocess_from_file(
output_dir=results_dir,
conf_file=config_path,
)
Initializing Post-Processor...
Reading mesh and facet tags from file...
Reading fiber direction from file...
Re-instantiating material model on loaded mesh...
Setting up FEM...
dofs: 11303
Setup FEM finished in 0.02 seconds.
Starting data processing...
- Processing frame 1/21...
- Processing frame 2/21...
- Processing frame 3/21...
- Processing frame 4/21...
- Processing frame 5/21...
- Processing frame 6/21...
- Processing frame 7/21...
- Processing frame 8/21...
- Processing frame 9/21...
- Processing frame 10/21...
- Processing frame 11/21...
- Processing frame 12/21...
- Processing frame 13/21...
- Processing frame 14/21...
- Processing frame 15/21...
- Processing frame 16/21...
- Processing frame 17/21...
- Processing frame 18/21...
- Processing frame 19/21...
- Processing frame 20/21...
- Processing frame 21/21...
Data processing complete. Global limits found:
- displacement: [0.0000e+00, 3.1817e-02]
- lambda: [6.4398e-01, 1.0179e+00]
- von_mises: [0.0000e+00, 1.9511e+04]
Generating force-activation plot...
- Plot saved to ../results/demos/contraction_demo_postprocessed/force-activation.png
Generating 3D plot frames from cached data...
- Plotting frame 1/21 (Activation: 0.000)...
- Plotting frame 2/21 (Activation: 0.050)...
- Plotting frame 3/21 (Activation: 0.100)...
- Plotting frame 4/21 (Activation: 0.150)...
- Plotting frame 5/21 (Activation: 0.200)...
- Plotting frame 6/21 (Activation: 0.250)...
- Plotting frame 7/21 (Activation: 0.300)...
- Plotting frame 8/21 (Activation: 0.350)...
- Plotting frame 9/21 (Activation: 0.400)...
- Plotting frame 10/21 (Activation: 0.450)...
- Plotting frame 11/21 (Activation: 0.500)...
- Plotting frame 12/21 (Activation: 0.550)...
- Plotting frame 13/21 (Activation: 0.600)...
- Plotting frame 14/21 (Activation: 0.650)...
- Plotting frame 15/21 (Activation: 0.700)...
- Plotting frame 16/21 (Activation: 0.750)...
- Plotting frame 17/21 (Activation: 0.800)...
- Plotting frame 18/21 (Activation: 0.850)...
- Plotting frame 19/21 (Activation: 0.900)...
- Plotting frame 20/21 (Activation: 0.950)...
- Plotting frame 21/21 (Activation: 1.000)...
Creating final media files (GIF and MP4)...
- Creating GIF for 'displacement'...
IMAGEIO FFMPEG_WRITER WARNING: input image is not divisible by macro_block_size=16, resizing from (1160, 1248) to (1168, 1248) to ensure video compatibility with most codecs and players. To prevent resizing, make your input image divisible by the macro_block_size or set the macro_block_size to 1 (risking incompatibility).
- Creating MP4 for 'displacement'...
[rawvideo @ 0x42cfc180] Stream #0: not enough frames to estimate rate; consider increasing probesize
- Creating GIF for 'lambda'...
IMAGEIO FFMPEG_WRITER WARNING: input image is not divisible by macro_block_size=16, resizing from (1160, 1248) to (1168, 1248) to ensure video compatibility with most codecs and players. To prevent resizing, make your input image divisible by the macro_block_size or set the macro_block_size to 1 (risking incompatibility).
- Creating MP4 for 'lambda'...
[rawvideo @ 0x26628180] Stream #0: not enough frames to estimate rate; consider increasing probesize
- Creating GIF for 'von_mises'...
IMAGEIO FFMPEG_WRITER WARNING: input image is not divisible by macro_block_size=16, resizing from (1160, 1248) to (1168, 1248) to ensure video compatibility with most codecs and players. To prevent resizing, make your input image divisible by the macro_block_size or set the macro_block_size to 1 (risking incompatibility).
- Creating MP4 for 'von_mises'...
[rawvideo @ 0x1ecc4180] Stream #0: not enough frames to estimate rate; consider increasing probesize
Post-processing complete. Videos and plots saved to: ../results/demos/contraction_demo_postprocessed
Below is the animation of the muscle contracting. Notice how the belly bulges outward as the ends shorten, preserving the total tissue volume.
