In a plane channel the momentum balance gives the position of the yield surface directly, . In a duct of square cross-section it does not: the yielded and unyielded regions are part of the solution. A plug moves in the centre, and the fluid in the four corners is at rest. A plane channel flows at any Bingham number below 1, while a square duct stops at , a result of Mosolov and Miasnikov (1965).
The flow minimizes a functional that is not differentiable where the rate of strain is zero. The augmented Lagrangian method (reviewed by Dean, Glowinski and Guidoboni, 2007; the same algorithm is known in optimization as the alternating direction method of multipliers, ADMM) splits the minimization into a linear Poisson problem and a local step with a solution in closed form, and needs no regularization. This lecture derives the method and applies it to the square duct.
Learning objectives¶
Write Bingham flow in a duct as a minimization problem and derive the three steps of the augmented Lagrangian method: a Poisson problem solved with the discrete sine transform, a shrinkage step, and an update of the multiplier (
viscoplastic_admm.solve_2d_duct_bingham_admm).Check the Newtonian limit () against the series solution for a square duct, .
Compute the central plug and the stagnant corners at .
Check that the flow stops at (
MOSOLOV_SQUARE_DUCT_BN_CRIT).
Time: about 60 min
try: # use the installed package, or the copy in this repository
import engcomprheo
except ImportError:
import pathlib, subprocess, sys
for _root in [pathlib.Path.cwd(), *pathlib.Path.cwd().parents]:
if (_root / "engcomprheo" / "__init__.py").exists():
sys.path.insert(0, str(_root))
break
else: # on Google Colab: install from GitHub
subprocess.run([sys.executable, "-m", "pip", "install", "-q",
"git+https://github.com/ktwyw/engcomprheo.git"], check=True)
import engcomprheo
import inspect
import math
import numpy as np
import matplotlib.pyplot as plt
from engcomprheo import (brownian_chains, constants_benchmarks, entangled_tubes, mesoscopic_suspensions_dpd,
microrheology_rheoml, shear_banding_instabilities, tensors_kinematics,
viscoelastic_fvm_2d, viscoplastic_admm)
from engcomprheo.plotting import label_panels, log_ticks, panel_label, use_style
use_style()
trapezoid = getattr(np, "trapezoid", None) or np.trapz # NumPy 2 renamed trapz to trapezoid
def show_source(obj):
"""Return the source code of a function or class of the package."""
return inspect.getsource(obj)
def heading(text):
print(f"\n{text}\n" + "=" * len(text))1. The augmented Lagrangian method and its three steps¶
The axial velocity of steady Bingham flow in a square duct , with on the walls, is the unique minimizer of a convex functional that is not differentiable where the rate of strain vanishes:
The augmented Lagrangian method introduces the rate of strain as a separate field, , with a multiplier , which is the stress, and a penalty parameter . The nonlinearity is then separated from the differential operator, and each iteration has three steps:
Velocity. Solve the linear problem , which has constant coefficients, with one two-dimensional discrete sine transform.
Rate of strain. At each point, without regularization:
Multiplier. .
Wherever , the second step sets to exactly zero: this is how the method represents unyielded material.
The first test is the Newtonian case, (), on with and , for which the flow rate is known as a series:
heading("Demonstration 1: Newtonian flow in a square duct against the series solution")
m_idx = np.arange(0, 40, dtype=float)
odd = 2.0 * m_idx + 1.0
q_boussinesq = (16.0 / 12.0) * (1.0 - (192.0 / (math.pi**5)) * float(np.sum(np.tanh(0.5 * math.pi * odd) / (odd**5))))
grids = [16, 32, 64]
q_errs = []
for ng in grids:
sol0 = viscoplastic_admm.solve_2d_duct_bingham_admm(nx=ng, ny=ng, H_half=1.0, dpdz_neg=1.0, tau_y=0.0, eta_p=1.0, r_aug=0.05, max_iter=25, tol=1e-10)
err = abs(sol0["flow_rate"] - q_boussinesq) / q_boussinesq
q_errs.append(err)
print(f"Grid {ng:2d}x{ng:2d} | ADMM Q = {sol0['flow_rate']:.7f} | series solution = {q_boussinesq:.7f} | rel err = {err:.3e}")
order_h = math.log(q_errs[0] / q_errs[2]) / math.log((64 + 1) / (16 + 1))
print(f"Observed spatial convergence order p = {order_h:.2f} (expected 2nd-order Q1 accuracy ~ 2.0)")
assert q_errs[-1] < 5e-4
assert 1.85 < order_h < 2.15
fig, axes = plt.subplots(1, 2, figsize=(10.2, 4.0))
im0 = axes[0].contourf(sol0["x"], sol0["y"], sol0["u"].T, levels=18, cmap="Blues")
plt.colorbar(im0, ax=axes[0], label="Velocity $u(x, y)$")
axes[0].set_aspect("equal")
axes[0].set_xlabel("$x / H$")
axes[0].set_ylabel("$y / H$")
axes[0].set_title(r"Newtonian velocity in a square duct")
h_vals = 2.0 / (np.array(grids) + 1.0)
axes[1].loglog(h_vals, q_errs, "ro-", lw=2.1, ms=7, label=f"Error of the flow rate (slope $= {order_h:.2f}$)")
axes[1].loglog(h_vals, q_errs[0] * ((h_vals / h_vals[0]) ** 2), "k--", lw=1.5, label=r"Reference $\mathcal{O}(h^2)$")
axes[1].set_xlabel("Grid spacing $h / H$")
axes[1].set_ylabel("Relative volumetric flux error")
axes[1].set_title(r"Error of the flow rate")
axes[1].legend(fontsize=8)
log_ticks(axes[1], "x", [0.03, 0.06, 0.12])
label_panels(fig)
plt.show()
Demonstration 1: Newtonian flow in a square duct against the series solution
============================================================================
Grid 16x16 | ADMM Q = 0.5611207 | series solution = 0.5623081 | rel err = 2.112e-03
Grid 32x32 | ADMM Q = 0.5619917 | series solution = 0.5623081 | rel err = 5.626e-04
Grid 64x64 | ADMM Q = 0.5622256 | series solution = 0.5623081 | rel err = 1.466e-04
Observed spatial convergence order p = 1.99 (expected 2nd-order Q1 accuracy ~ 2.0)

Figure 10.1. (a) Newtonian velocity from the discrete sine transform solver. (b) Relative error of the flow rate against the series solution for a square duct; the fitted order is 1.99.
What Demonstration 1 shows. The discrete operator , inverted with the sine transform, reproduces the flow rate of the series solution to 0.015 % on a grid of cells, with second-order convergence.
2. Yielded and unyielded regions in a square duct¶
The second test has a yield stress, at (nx=36, ny=36, r_aug=0.14). In a square duct the shear stress vanishes at the centre and also at the four corners . The solution therefore has five unyielded regions, in which :
a plug in the centre, which moves at the largest velocity, and
four stagnant regions in the corners, which are attached to the walls and do not move.
heading("Demonstration 2: Bingham flow in a square duct at Bn = 0.32")
duct32 = viscoplastic_admm.solve_2d_duct_bingham_admm(
nx=36, ny=36, H_half=1.0, dpdz_neg=1.0, tau_y=0.32, eta_p=1.0, r_aug=0.14, max_iter=260, tol=1e-7
)
mask_u = duct32["unyielded_mask"]
mid_i = mask_u.shape[0] // 2
corners_arrested = [
bool(mask_u[0, 0]),
bool(mask_u[0, -1]),
bool(mask_u[-1, 0]),
bool(mask_u[-1, -1]),
]
center_plug = bool(mask_u[mid_i, mid_i])
wall_mid_yielded = not bool(mask_u[mid_i, 0])
print(f"Bingham number Bn = {duct32['bingham_number']:.2f} | flow rate Q = {duct32['flow_rate']:.5f} | unyielded area frac = {duct32['unyielded_area_fraction']:.3f}")
print(f"Central floating plug arrested? {center_plug} | wall midpoint yielded? {wall_mid_yielded} | 4 corners arrested? {corners_arrested}")
assert center_plug is True
assert all(corners_arrested) is True
assert wall_mid_yielded is True
assert 0.20 < duct32["unyielded_area_fraction"] < 0.45
xc = np.linspace(-1.0 + 1.0 / 37.0, 1.0 - 1.0 / 37.0, 37)
fig, axes = plt.subplots(1, 2, figsize=(10.4, 4.3))
im_u = axes[0].contourf(duct32["x"], duct32["y"], duct32["u"].T, levels=18, cmap="magma")
plt.colorbar(im_u, ax=axes[0], label="Axial velocity $u(x, y)$")
axes[0].set_aspect("equal")
axes[0].set_xlabel("$x / H$")
axes[0].set_ylabel("$y / H$")
axes[0].set_title(r"Velocity ($\mathrm{Bn} = 0.32$)")
axes[1].contourf(xc, xc, np.log10(duct32["d_mag"].T + 1e-6), levels=18, cmap="viridis")
axes[1].contour(xc, xc, mask_u.T.astype(float), levels=[0.5], colors="white", linewidths=2.0)
axes[1].set_aspect("equal")
axes[1].set_xlabel("$x / H$")
axes[1].set_ylabel("$y / H$")
axes[1].set_title(r"Rate of strain")
label_panels(fig)
plt.show()
Demonstration 2: Bingham flow in a square duct at Bn = 0.32
===========================================================
Bingham number Bn = 0.32 | flow rate Q = 0.13869 | unyielded area frac = 0.305
Central floating plug arrested? True | wall midpoint yielded? True | 4 corners arrested? [True, True, True, True]

Figure 10.2. Bingham flow in a square duct from the augmented Lagrangian method. (a) Axial velocity. (b) Magnitude of the rate of strain ; the white contour bounds the central plug, and the corners are also unyielded.
What Demonstration 2 shows. Without any threshold on the viscosity, the method gives the moving plug in the centre and the four stagnant regions in the corners.
3. The critical Bingham number of Mosolov and Miasnikov¶
As the Bingham number increases, the central plug and the four stagnant regions grow. When they meet at the middle of the walls, the flow stops everywhere. Mosolov and Miasnikov (1965) showed by a variational argument that the yield surface at this point consists of four quarter circles of radius joined by straight segments along the walls, which gives the critical Bingham number
heading("Demonstration 3: flow rate against Bingham number and the critical value")
bn_crit = constants_benchmarks.MOSOLOV_SQUARE_DUCT_BN_CRIT
bn_sweep = np.array([0.0, 0.16, 0.32, 0.46, 0.58, 0.64])
q_sweep, uny_sweep = [], []
for bn_v in bn_sweep:
r_pen = 0.18 if bn_v < 0.52 else 2.2
res_b = viscoplastic_admm.solve_2d_duct_bingham_admm(
nx=26, ny=26, H_half=1.0, dpdz_neg=1.0, tau_y=float(bn_v), eta_p=1.0, r_aug=r_pen, max_iter=210, tol=1e-8
)
q_sweep.append(res_b["flow_rate"])
uny_sweep.append(res_b["unyielded_area_fraction"])
print(f"Bn = {bn_v:5.3f} (Bn/Bn_crit = {bn_v/bn_crit:5.3f}) | flow rate Q = {res_b['flow_rate']:.6f} | unyielded frac = {res_b['unyielded_area_fraction']:.4f}")
q_sweep = np.array(q_sweep)
uny_sweep = np.array(uny_sweep)
assert np.all(q_sweep[bn_sweep < 0.48] > 1e-3)
assert np.all(q_sweep[bn_sweep > bn_crit + 0.015] == 0.0)
assert np.all(uny_sweep[bn_sweep > bn_crit + 0.015] == 1.0)
fig, axes = plt.subplots(1, 2, figsize=(10.2, 4.0))
axes[0].plot(bn_sweep, q_sweep, "bo-", lw=2.2, ms=6, label="Flow rate $Q(\\mathrm{Bn})$")
axes[0].axvline(bn_crit, color="#C0392B", ls="--", lw=1.8, label=f"Critical $\\mathrm{{Bn}}_{{\\mathrm{{crit}}}} = {bn_crit:.4f}$")
axes[0].set_xlabel(r"Bingham number $\mathrm{Bn} = \tau_y / (G H)$")
axes[0].set_ylabel(r"Volumetric flow rate $Q$")
axes[0].set_title(r"Flow rate against Bingham number")
axes[0].legend(fontsize=8)
axes[1].plot(bn_sweep, uny_sweep, "rs-", lw=2.2, ms=6, label="Unyielded area fraction")
axes[1].axvline(bn_crit, color="#C0392B", ls="--", lw=1.8, label=r"$2 / (2 + \sqrt{\pi}) \approx 0.5302$")
axes[1].set_xlabel(r"Bingham number $\mathrm{Bn} = \tau_y / (G H)$")
axes[1].set_ylabel("Unyielded area fraction")
axes[1].set_title(r"Unyielded area fraction")
axes[1].legend(fontsize=8)
label_panels(fig)
plt.show()
Demonstration 3: flow rate against Bingham number and the critical value
========================================================================
Bn = 0.000 (Bn/Bn_crit = 0.000) | flow rate Q = 0.561837 | unyielded frac = 0.0014
Bn = 0.160 (Bn/Bn_crit = 0.302) | flow rate Q = 0.339977 | unyielded frac = 0.0672
Bn = 0.320 (Bn/Bn_crit = 0.604) | flow rate Q = 0.138493 | unyielded frac = 0.2977
Bn = 0.460 (Bn/Bn_crit = 0.868) | flow rate Q = 0.019251 | unyielded frac = 0.6433
Bn = 0.580 (Bn/Bn_crit = 1.094) | flow rate Q = 0.000000 | unyielded frac = 1.0000
Bn = 0.640 (Bn/Bn_crit = 1.207) | flow rate Q = 0.000000 | unyielded frac = 1.0000

Figure 10.3. (a) Flow rate against the Bingham number; it vanishes near the limit (dashed). (b) Fraction of the cross-section that is unyielded.
What Demonstration 3 shows. Above , solve_2d_duct_bingham_admm returns flow_rate == 0.0 and unyielded_area_fraction == 1.0; there is no creep below the yield stress.
4. The penalty parameter and convergence¶
The parameter of the Papanastasiou model changes the equations that are solved. The penalty parameter of the augmented Lagrangian method does not: the iteration converges to the same solution for every , and the parameter affects only the number of iterations. Convergence is fastest when the primal residual, , and the dual residual, , decrease at similar rates.
heading("Demonstration 4: convergence for several values of the penalty parameter")
r_candidates = [0.08, 0.22, 0.70, 2.00]
q_by_r, iters_by_r = [], []
fig, axes = plt.subplots(1, 2, figsize=(10.2, 4.0))
for rv in r_candidates:
sol_r = viscoplastic_admm.solve_2d_duct_bingham_admm(
nx=24, ny=24, H_half=1.0, dpdz_neg=1.0, tau_y=0.25, eta_p=1.0, r_aug=rv, max_iter=4000, tol=1e-9
)
q_by_r.append(sol_r["flow_rate"])
max_res = np.maximum(sol_r["primal_res_hist"], sol_r["dual_res_hist"])
below = np.nonzero(max_res < 1e-5)[0]
iters_by_r.append(int(below[0]) + 1 if below.size else max_res.size)
print(f"r_aug = {rv:4.2f} | converged Q = {sol_r['flow_rate']:.6f} | iterations to 1e-5 = {iters_by_r[-1]:4d} | residual after {max_res.size} = {max_res[-1]:.2e}")
axes[0].semilogy(max_res, lw=2.0, label=f"$r_{{\\mathrm{{aug}}}} = {rv:.2f}$")
q_spread = float(max(q_by_r) - min(q_by_r))
print(f"Physical flow-rate spread across 25x variation in r_aug: {q_spread:.3e} (r_aug-invariant)")
assert q_spread < 1e-4
axes[0].axhline(1e-5, color="black", ls=":", lw=1.2, label="$10^{-5}$")
axes[0].set_xlabel("Iteration $k$")
axes[0].set_ylabel("Larger of the primal and dual residuals")
axes[0].set_title(r"Residual history ($\mathrm{Bn} = 0.25$)")
axes[0].legend(fontsize=8)
axes[1].semilogx(r_candidates, iters_by_r, "ko-", lw=2.1, ms=7)
axes[1].set_xlabel(r"Augmented penalty $r_{\mathrm{aug}}$")
axes[1].set_ylabel("Iterations to reach $10^{-5}$")
axes[1].set_yscale("log")
axes[1].set_title(r"Iterations to reach $10^{-5}$")
label_panels(fig)
plt.show()
Demonstration 4: convergence for several values of the penalty parameter
========================================================================
r_aug = 0.08 | converged Q = 0.221541 | iterations to 1e-5 = 2054 | residual after 4000 = 1.01e-06
r_aug = 0.22 | converged Q = 0.221541 | iterations to 1e-5 = 748 | residual after 4000 = 7.73e-07
r_aug = 0.70 | converged Q = 0.221540 | iterations to 1e-5 = 236 | residual after 4000 = 3.84e-07
r_aug = 2.00 | converged Q = 0.221539 | iterations to 1e-5 = 84 | residual after 4000 = 1.17e-07
Physical flow-rate spread across 25x variation in r_aug: 2.431e-06 (r_aug-invariant)

Figure 10.4. (a) Larger of the primal and dual residuals against the iteration number for four values of the penalty . The flow rate is the same for all four to within 10-5. (b) Number of iterations needed to bring the residual below 10-5: about ten times fewer for the largest penalty than for the smallest.
Inside the algorithm¶
The function solve_2d_duct_bingham_admm inverts its linear problem exactly with one sine transform because of the way its two discrete operators are defined in viscoplastic_admm.py:
_grad_cell(u)takes the velocities at the interior nodes and returns the gradients at the cell centres, from a bilinear interpolation in each cell._neg_div_adj(px, py)is the exact transpose of this operator, . The product is a symmetric nine-point stencil whose eigenvectors are those of the discrete sine transform.
Check against the package¶
The cell below prints the source of solve_2d_duct_bingham_admm and checks (1) the adjoint identity to 1e-15, (2) the inversion with the sine transform, with a residual below 1e-14, and (3) the optimality condition of the shrinkage step.
heading("Inside the algorithm: the discrete gradient, its adjoint and the sine transform")
print(show_source(viscoplastic_admm.solve_2d_duct_bingham_admm))
nx_i, ny_i = 18, 22
hx_i, hy_i = 2.0 / (nx_i + 1.0), 2.0 / (ny_i + 1.0)
rng_a = np.random.default_rng(19)
u_rand = rng_a.normal(size=(nx_i, ny_i))
px_rand = rng_a.normal(size=(nx_i + 1, ny_i + 1))
py_rand = rng_a.normal(size=(nx_i + 1, ny_i + 1))
u_pad = np.pad(u_rand, 1, mode="constant", constant_values=0.0)
gx_r = 0.5 * ((u_pad[1:, :-1] + u_pad[1:, 1:]) - (u_pad[:-1, :-1] + u_pad[:-1, 1:])) / hx_i
gy_r = 0.5 * ((u_pad[:-1, 1:] + u_pad[1:, 1:]) - (u_pad[:-1, :-1] + u_pad[1:, :-1])) / hy_i
adj_u = (
0.5 * ((px_rand[:-1, :-1] + px_rand[:-1, 1:]) - (px_rand[1:, :-1] + px_rand[1:, 1:])) / hx_i
+ 0.5 * ((py_rand[:-1, :-1] + py_rand[1:, :-1]) - (py_rand[:-1, 1:] + py_rand[1:, 1:])) / hy_i
)
ip_cell = float(np.sum(gx_r * px_rand + gy_r * py_rand))
ip_node = float(np.sum(u_rand * adj_u))
adj_err = abs(ip_cell - ip_node)
# Verify DST-I eigenvalues invert -div_adj(grad_cell(u)) == rhs to 1e-14:
thx = math.pi * np.arange(1, nx_i + 1) / (nx_i + 1.0)
thy = math.pi * np.arange(1, ny_i + 1) / (ny_i + 1.0)
eig_q1 = (4.0 / hx_i**2) * (np.sin(0.5 * thx)[:, None] ** 2) * (np.cos(0.5 * thy)[None, :] ** 2) + (4.0 / hy_i**2) * (np.cos(0.5 * thx)[:, None] ** 2) * (np.sin(0.5 * thy)[None, :] ** 2)
lap_u = (
0.5 * ((gx_r[:-1, :-1] + gx_r[:-1, 1:]) - (gx_r[1:, :-1] + gx_r[1:, 1:])) / hx_i
+ 0.5 * ((gy_r[:-1, :-1] + gy_r[1:, :-1]) - (gy_r[:-1, 1:] + gy_r[1:, 1:])) / hy_i
)
u_rec = viscoplastic_admm._idst1_2d(viscoplastic_admm._dst1_2d(lap_u) / eig_q1)
spec_err = float(np.max(np.abs(u_rec - u_rand)))
print(f"Discrete adjoint identity error |<grad u, p> - <u, grad^T p>| = {adj_err:.3e}")
print(f"Exact DST-I Q1 Poisson inversion error max |u_rec - u| = {spec_err:.3e}")
assert adj_err < 1e-13
assert spec_err < 1e-13
Inside the algorithm: the discrete gradient, its adjoint and the sine transform
===============================================================================
def solve_2d_duct_bingham_admm(
nx: int = 44,
ny: int = 44,
H_half: float = 1.0,
dpdz_neg: float = 1.0,
tau_y: float = 0.25,
eta_p: float = 1.0,
r_aug: float = 1.0,
max_iter: int = 350,
tol: float = 1e-7,
) -> dict:
"""Bingham flow in a square duct with the augmented Lagrangian method; the Poisson step uses the discrete sine transform."""
if nx < 8 or ny < 8 or H_half <= 0.0 or eta_p <= 0.0 or tau_y < 0.0 or dpdz_neg < 0.0 or r_aug <= 0.0:
raise ValueError("Invalid parameters for solve_2d_duct_bingham_admm.")
# Interior nodal velocity u of shape (nx, ny) on [-H_half, +H_half]^2 with u = 0 on all 4 walls:
hx = (2.0 * float(H_half)) / (nx + 1.0)
hy = (2.0 * float(H_half)) / (ny + 1.0)
x_nodes = -float(H_half) + np.arange(1, nx + 1, dtype=float) * hx
y_nodes = -float(H_half) + np.arange(1, ny + 1, dtype=float) * hy
# Cell-centered bilinear Q1 gradient (gx, gy) on the (nx + 1, ny + 1) elements:
# Exact DST-I eigenvalues of -div_cell(grad_cell(u)) on interior nodes (p = 1..nx, q = 1..ny):
th_x = math.pi * np.arange(1, nx + 1, dtype=float) / (nx + 1.0)
th_y = math.pi * np.arange(1, ny + 1, dtype=float) / (ny + 1.0)
sx2 = np.sin(0.5 * th_x) ** 2
cx2 = np.cos(0.5 * th_x) ** 2
sy2 = np.sin(0.5 * th_y) ** 2
cy2 = np.cos(0.5 * th_y) ** 2
eig_lap = (4.0 / (hx**2)) * (sx2[:, None] * cy2[None, :]) + (4.0 / (hy**2)) * (cx2[:, None] * sy2[None, :])
denom_spec = (float(eta_p) + float(r_aug)) * eig_lap
def _grad_cell(u_in: np.ndarray) -> tuple[np.ndarray, np.ndarray]:
u_pad = np.pad(u_in, 1, mode="constant", constant_values=0.0)
gx = 0.5 * ((u_pad[1:, :-1] + u_pad[1:, 1:]) - (u_pad[:-1, :-1] + u_pad[:-1, 1:])) / hx
gy = 0.5 * ((u_pad[:-1, 1:] + u_pad[1:, 1:]) - (u_pad[:-1, :-1] + u_pad[1:, :-1])) / hy
return gx, gy
def _neg_div_adj(px: np.ndarray, py: np.ndarray) -> np.ndarray:
# Exact algebraic transpose grad_cell^T so grad_cell^T(grad_cell(u)) == -Lap_Q1(u) to 1e-16
tx = 0.5 * ((px[:-1, :-1] + px[:-1, 1:]) - (px[1:, :-1] + px[1:, 1:])) / hx
ty = 0.5 * ((py[:-1, :-1] + py[1:, :-1]) - (py[:-1, 1:] + py[1:, 1:])) / hy
return tx + ty
u = np.zeros((nx, ny), dtype=float)
dx = np.zeros((nx + 1, ny + 1), dtype=float)
dy = np.zeros((nx + 1, ny + 1), dtype=float)
lam_x = np.zeros_like(dx)
lam_y = np.zeros_like(dy)
f_source = np.full((nx, ny), float(dpdz_neg), dtype=float)
primal_hist: list[float] = []
dual_hist: list[float] = []
for _ in range(max_iter):
# 1. Exact O(N^2 log N) spectral velocity update: (eta_p + r)*(-Lap u) = dpdz_neg - grad^T(lam - r*d)
rhs = f_source - _neg_div_adj(lam_x - r_aug * dx, lam_y - r_aug * dy)
u = _idst1_2d(_dst1_2d(rhs) / denom_spec)
u = np.maximum(u, 0.0) if dpdz_neg >= 0.0 else u
# 2. Pointwise isotropic Euclidean soft-thresholding shrinkage for auxiliary strain rate d:
gx, gy = _grad_cell(u)
sx = lam_x + r_aug * gx
sy = lam_y + r_aug * gy
s_norm = np.hypot(sx, sy)
shrink = np.maximum(0.0, 1.0 - float(tau_y) / np.maximum(s_norm, 1e-30)) / float(r_aug)
dx_new = shrink * sx
dy_new = shrink * sy
# 3. Glowinski-Dean dual multiplier update (with over-relaxation alpha = 1.5):
rx = gx - dx_new
ry = gy - dy_new
gx_rel = 1.5 * gx - 0.5 * dx
gy_rel = 1.5 * gy - 0.5 * dy
lam_x = lam_x + r_aug * (gx_rel - dx_new)
lam_y = lam_y + r_aug * (gy_rel - dy_new)
p_res = float(math.sqrt(np.mean(rx**2 + ry**2)))
d_res = float(r_aug * math.sqrt(np.mean((dx_new - dx) ** 2 + (dy_new - dy) ** 2)))
dx, dy = dx_new, dy_new
primal_hist.append(p_res)
dual_hist.append(d_res)
if max(p_res, d_res) < tol:
break
raw_d = np.hypot(dx, dy)
d_mag = np.where(raw_d <= 1e-8, 0.0, raw_d)
# Integrate velocity over [-H, H]^2 using exact bilinear element average:
u_pad = np.pad(u, 1, mode="constant", constant_values=0.0)
u_cell = 0.25 * (u_pad[:-1, :-1] + u_pad[1:, :-1] + u_pad[:-1, 1:] + u_pad[1:, 1:])
q_flow = float(np.sum(u_cell) * hx * hy)
bn = float(tau_y / (dpdz_neg * H_half)) if dpdz_neg > 0.0 else math.inf
return {
"x": x_nodes,
"y": y_nodes,
"u": u,
"d_mag": d_mag,
"unyielded_mask": d_mag == 0.0,
"unyielded_area_fraction": float(np.mean(d_mag == 0.0)),
"flow_rate": q_flow,
"bingham_number": bn,
"mosolov_bn_crit": MOSOLOV_SQUARE_DUCT_BN_CRIT,
"primal_res_hist": np.array(primal_hist),
"dual_res_hist": np.array(dual_hist),
}
Discrete adjoint identity error |<grad u, p> - <u, grad^T p>| = 8.527e-14
Exact DST-I Q1 Poisson inversion error max |u_rec - u| = 2.776e-15
Exercises¶
Worked solutions are in 10_solutions.ipynb. The cell below the list is a short self-check to start from.
Verify a result. A region with rounded corners of radius inside a square duct of half-width has the area and the perimeter . Maximize over to obtain and , and explain why the square () and the inscribed circle () both give .
Find how it fails. For , , and (), compare the flow rate estimated from the plane-channel formula, , with the result of the two-dimensional solver for the square duct (
r_aug=2.0). Compute the smallest pressure gradient at which the duct flows, , and check that there is flow at .Implement it yourself. Write
solve_1d_channel_bingham_admm(nx, H_half, dpdz_neg, tau_y, eta_p, r_aug), the augmented Lagrangian method for a plane channel without regularization: a Poisson problem solved with the discrete sine transform, followed by the shrinkage step for the strain rate. Compare the velocity and the flow rate withbuckingham_reiner_exact_1dfor and , and check that the velocity is zero for .
heading("Self-check for the exercises")
assert q_errs[-1] < 5e-4 and 1.85 < order_h < 2.15
assert center_plug is True and all(corners_arrested) is True and wall_mid_yielded is True
assert np.all(q_sweep[bn_sweep > bn_crit + 0.015] == 0.0)
assert q_spread < 1e-4
assert adj_err < 1e-13 and spec_err < 1e-13
print("All checks passed.")
Self-check for the exercises
============================
All checks passed.