Skip to content

Commit 72ece1f

Browse files
committed
Auto-detect bdf_blend: 1.0 for pure VE, 0.75 for VEP
The previous default (0.5) degraded order-2 VE accuracy. Now: - bdf_blend defaults to None (auto-detect) - Pure VE (yield_stress = oo): uses 1.0 (pure BDF-k, full accuracy) - VEP (finite yield_stress): uses 0.75 (stable, near-optimal accuracy) - Users can still override explicitly with stokes.constitutive_model.bdf_blend = value Also fixes _update_bdf_coefficients to read the property (self.bdf_blend) instead of the backing field (self._bdf_blend) so auto-detect works. Test test_1051 no longer needs explicit bdf_blend — auto-detect gives 1.0 for its pure VE setup. Underworld development team with AI support from Claude Code
1 parent 35d2c40 commit 72ece1f

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

src/underworld3/constitutive_models.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1112,7 +1112,7 @@ def __init__(self, unknowns, order=1, material_name: str = None):
11121112
self._order = order
11131113
self._yield_mode = "smooth" # "min", "harmonic", "smooth", or "softmin"
11141114
self._yield_softness = 0.5 # δ parameter for "softmin" mode
1115-
self._bdf_blend = 0.5 # blend O1/O2 coefficients: 0=pure O1, 1=pure O2
1115+
self._bdf_blend = None # auto: 1.0 for VE, 0.75 for VEP
11161116

11171117
# Timestep — set by the solver before each solve(). Not a user parameter.
11181118
# Initialised to oo (viscous limit). The solver overwrites this with the
@@ -1363,7 +1363,7 @@ def _update_bdf_coefficients(self):
13631363

13641364
# Blend with O1 coefficients for stability
13651365
# 0 = pure O1, 0.5 = balanced (default), 1 = pure requested order
1366-
alpha = self._bdf_blend
1366+
alpha = self.bdf_blend # property resolves None → auto-detect
13671367
if 0 < alpha < 1 and order >= 2:
13681368
coeffs_o1 = _bdf_coefficients(1, dt_current, dt_history)
13691369
while len(coeffs_o1) < len(coeffs):
@@ -1761,9 +1761,12 @@ def bdf_blend(self):
17611761
Blends O1 and O2 BDF coefficients: ``c = (1-α)·c_O1 + α·c_O2``.
17621762
17631763
- ``α = 0``: pure BDF-1 (most stable, first-order accurate)
1764-
- ``α = 0.5`` (default): balanced blend (stable, improved accuracy)
1765-
- ``α = 1``: pure BDF-2 (second-order, can be unstable for VEP)
1764+
- ``α = 0.75``: default for VEP (stable, near-optimal accuracy)
1765+
- ``α = 1``: pure BDF-2 (default for pure VE, second-order accurate)
1766+
- ``None`` (default): auto-detect — 1.0 for VE, 0.75 for VEP
17661767
"""
1768+
if self._bdf_blend is None:
1769+
return 0.75 if self.is_viscoplastic else 1.0
17671770
return self._bdf_blend
17681771

17691772
@bdf_blend.setter

tests/test_1051_VE_shear_box.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def _run_ve_shear(order, n_steps, dt_over_tr):
7777
stokes.constitutive_model.Parameters.shear_viscosity_0 = ETA
7878
stokes.constitutive_model.Parameters.shear_modulus = MU
7979
stokes.constitutive_model.Parameters.dt_elastic = dt
80-
stokes.constitutive_model.bdf_blend = 1.0 # pure BDF-k (no O1/O2 blending)
80+
# bdf_blend auto-detects: 1.0 for pure VE, 0.75 for VEP
8181

8282
stokes.add_dirichlet_bc((V0, 0.0), "Top")
8383
stokes.add_dirichlet_bc((-V0, 0.0), "Bottom")

0 commit comments

Comments
 (0)