Worked solutions to the three exercises of Lecture 9. Each solution is computed here and checked with assert statements against an exact identity or an independent calculation. The first code cell sets up the notebook and runs Demonstration 1 of the lecture without showing its output, because some of the solutions use its variables.
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))
# Demonstration 1 of the lecture, run without output: the solutions use its variables.
import contextlib, io
_show, plt.show = plt.show, lambda *args, **kwargs: None
_stdout = contextlib.redirect_stdout(io.StringIO()); _stdout.__enter__()
heading("Demonstration 1: exact Bingham profiles in a plane channel and in a pipe")
y_slit = np.linspace(-1.0, 1.0, 201)
r_pipe = np.linspace(0.0, 1.0, 121)
slit_yielded = viscoplastic_admm.buckingham_reiner_exact_1d(y_slit, dpdz_neg=2.0, H_or_R=1.0, tau_y=0.7, eta_p=1.0, geometry="planar")
slit_arrest = viscoplastic_admm.buckingham_reiner_exact_1d(y_slit, dpdz_neg=0.6, H_or_R=1.0, tau_y=0.7, eta_p=1.0, geometry="planar")
pipe_yielded = viscoplastic_admm.buckingham_reiner_exact_1d(r_pipe, dpdz_neg=4.0, H_or_R=1.0, tau_y=0.7, eta_p=1.0, geometry="pipe")
print(f"Planar slit (tau_w=2.0 > tau_y=0.7): plug y_p = {slit_yielded['plug_half_width']:.3f}, flux Q = {slit_yielded['flow_rate']:.5f}")
print(f"Planar slit (tau_w=0.6 < tau_y=0.7): plug y_p = {slit_arrest['plug_half_width']:.3f}, flux Q = {slit_arrest['flow_rate']:.5f} (no flow)")
print(f"Circular pipe (tau_w=2.0 > tau_y=0.7): plug r_p = {pipe_yielded['plug_half_width']:.3f}, flux Q = {pipe_yielded['flow_rate']:.5f}")
# Verify exact flat velocity inside [-y_p, +y_p] and exact zero velocity below yield:
plug_mask = np.abs(y_slit) <= slit_yielded["plug_half_width"] - 1e-12
assert np.max(np.abs(np.diff(slit_yielded["velocity"][plug_mask]))) < 1e-15
assert np.all(slit_arrest["velocity"] == 0.0) and slit_arrest["flow_rate"] == 0.0
xi_sweep = np.linspace(0.0, 1.25, 126)
q_norm_slit = [
viscoplastic_admm.buckingham_reiner_exact_1d(np.array([0.0]), dpdz_neg=2.0, H_or_R=1.0, tau_y=2.0 * x, eta_p=1.0, geometry="planar")["flow_rate"] / (4.0 / 3.0)
for x in xi_sweep
]
q_norm_pipe = [
viscoplastic_admm.buckingham_reiner_exact_1d(np.array([0.0]), dpdz_neg=4.0, H_or_R=1.0, tau_y=2.0 * x, eta_p=1.0, geometry="pipe")["flow_rate"] / (math.pi / 2.0)
for x in xi_sweep
]
assert np.all(np.array(q_norm_slit)[xi_sweep >= 1.0] == 0.0)
assert np.all(np.array(q_norm_pipe)[xi_sweep >= 1.0] == 0.0)
fig, axes = plt.subplots(1, 2, figsize=(10.2, 4.0))
axes[0].plot(slit_yielded["velocity"], y_slit, color="#2166AC", lw=2.3, label=r"Yielded ($\tau_w = 2.0, y_p = 0.35$)")
axes[0].plot(slit_arrest["velocity"], y_slit, "k--", lw=2.0, label=r"Sub-yield ($\tau_w = 0.6 < \tau_y$, $u \equiv 0$)")
axes[0].axhspan(-0.35, 0.35, color="#d4e6f1", alpha=0.55, label="Exact rigid plug ($\\dot{\\gamma} \\equiv 0$)")
axes[0].set_xlabel("Axial velocity $u(y)$")
axes[0].set_ylabel("Channel coordinate $y / H$")
axes[0].set_title(r"Velocity in a plane channel")
axes[0].legend(fontsize=8, loc="upper center", bbox_to_anchor=(0.5, -0.17), ncol=1)
axes[1].plot(xi_sweep, q_norm_slit, color="#2166AC", lw=2.2, label=r"Planar slit $1 - \frac{3}{2}\xi + \frac{1}{2}\xi^3$")
axes[1].plot(xi_sweep, q_norm_pipe, color="#C0392B", lw=2.2, label=r"Circular pipe $1 - \frac{4}{3}\xi + \frac{1}{3}\xi^4$")
axes[1].axvline(1.0, color="black", ls=":", lw=1.3, label=r"No flow at $\xi = \tau_y/\tau_w = 1$")
axes[1].set_xlabel(r"Dimensionless yield ratio $\xi = \tau_y / \tau_w$")
axes[1].set_ylabel(r"Normalized flux $Q / Q_{\mathrm{Newtonian}}$")
axes[1].set_title(r"Flow rate against $\tau_y/\tau_w$")
axes[1].legend(fontsize=8)
label_panels(fig)
plt.show()
_stdout.__exit__(None, None, None); plt.show = _show; plt.close("all")Exercise 1¶
Problem. Check the Buckingham–Reiner flow rate in a pipe, with the ratio of the yield stress to the wall stress, by numerical integration of for . Compare the fraction of the cross-section occupied by the plug in a pipe and in a plane channel at the same .
heading("Exercise 1: the Buckingham-Reiner flow rate by quadrature")
r_dense = np.linspace(0.0, 1.0, 4001)
G_p, R_p, eta_p_e1 = 4.0, 1.0, 1.0 # tau_w = 0.5 * G * R = 2.0
xi_tests = [0.0, 0.25, 0.50, 0.80, 1.05]
q_formula, q_quad = [], []
for xi_v in xi_tests:
ty = xi_v * (0.5 * G_p * R_p)
res_p = viscoplastic_admm.buckingham_reiner_exact_1d(r_dense, dpdz_neg=G_p, H_or_R=R_p, tau_y=ty, eta_p=eta_p_e1, geometry="pipe")
q_num = float(2.0 * math.pi * trapezoid(r_dense * res_p["velocity"], r_dense))
q_formula.append(res_p["flow_rate"])
q_quad.append(q_num)
print(f"xi = {xi_v:4.2f} | Buckingham-Reiner Q = {res_p['flow_rate']:8.5f} | 2*pi*int(r*u dr) = {q_num:8.5f} | plug area frac = {min(1.0, xi_v)**2:.3f}")
assert np.allclose(q_formula, q_quad, rtol=1e-6, atol=1e-8)
assert q_formula[-1] == 0.0
xi_c = np.linspace(0.0, 1.0, 200)
fig, axes = plt.subplots(1, 2, figsize=(9.8, 3.8))
for xv in [0.0, 0.35, 0.70]:
rp_prof = viscoplastic_admm.buckingham_reiner_exact_1d(r_dense, dpdz_neg=G_p, H_or_R=R_p, tau_y=2.0 * xv, eta_p=1.0, geometry="pipe")
axes[0].plot(r_dense, rp_prof["velocity"], lw=2.0, label=f"$\\xi = {xv:.2f}$ ($r_p = {xv:.2f}$)")
axes[0].set_xlabel("Radial coordinate $r / R$")
axes[0].set_ylabel("Axial pipe velocity $u(r)$")
axes[0].set_title(r"Velocity in a pipe")
axes[0].legend(fontsize=8)
axes[1].plot(xi_c, xi_c, "b-", lw=2.0, label=r"Planar plug fraction $y_p / H = \xi$")
axes[1].plot(xi_c, xi_c**2, "r-", lw=2.0, label=r"Pipe plug area fraction $(r_p/R)^2 = \xi^2$")
axes[1].set_xlabel(r"Yield ratio $\xi = \tau_y / \tau_w$")
axes[1].set_ylabel("Unyielded cross-sectional area fraction")
axes[1].set_title(r"Unyielded fraction of the cross-section")
axes[1].legend(fontsize=8)
label_panels(fig)
plt.show()
Exercise 1: the Buckingham-Reiner flow rate by quadrature
=========================================================
xi = 0.00 | Buckingham-Reiner Q = 1.57080 | 2*pi*int(r*u dr) = 1.57080 | plug area frac = 0.000
xi = 0.25 | Buckingham-Reiner Q = 1.04924 | 2*pi*int(r*u dr) = 1.04924 | plug area frac = 0.062
xi = 0.50 | Buckingham-Reiner Q = 0.55632 | 2*pi*int(r*u dr) = 0.55632 | plug area frac = 0.250
xi = 0.80 | Buckingham-Reiner Q = 0.10975 | 2*pi*int(r*u dr) = 0.10975 | plug area frac = 0.640
xi = 1.05 | Buckingham-Reiner Q = 0.00000 | 2*pi*int(r*u dr) = 0.00000 | plug area frac = 1.000

Figure S9.1. (a) Bingham velocity profiles in a pipe for three values of . (b) Fraction of the cross-section occupied by the plug: in a plane channel, in a pipe.
Explanation. Integration by parts gives . Evaluating at the two limits with gives . The quadrature reproduces the formula to the five digits printed, and the flow rate is zero for . The plug occupies the fraction of the cross-section of a pipe (0.25 at ) and the fraction of a plane channel.
Exercise 2¶
Problem. A layer of gel between vertical walls (, , ) is loaded by its own weight, , so that the wall stress is . A Bingham fluid does not move under this load. Compute the displacement of the centreline after that the Papanastasiou regularization predicts for .
heading("Exercise 2: creep of the regularized model below the yield stress")
H_col = 0.01 # [m]
tau_y_col = 45.0 # [Pa] (CARBOPOL_EVP)
eta_p_col = 12.0 # [Pa*s]
G_grav = 3600.0 # [N/m^3] -> tau_w = G_grav * H_col = 36.0 Pa == 0.8 * tau_y
t_hold = 7200.0 # 2 hours [s]
y_col = np.linspace(-H_col, H_col, 121)
ex_col = viscoplastic_admm.buckingham_reiner_exact_1d(y_col, dpdz_neg=G_grav, H_or_R=H_col, tau_y=tau_y_col, eta_p=eta_p_col, geometry="planar")
slump_exact_mm = float(np.max(ex_col["velocity"]) * t_hold * 1e3)
assert slump_exact_mm == 0.0
m_holds = [10.0, 50.0, 250.0]
slumps_mm = []
fig, axes = plt.subplots(1, 2, figsize=(9.8, 3.8))
axes[0].plot(ex_col["velocity"] * t_hold * 1e3, y_col * 1e3, "k-", lw=2.5, label="Exact Bingham (no displacement)")
for mv in m_holds:
pap_col = viscoplastic_admm.papanastasiou_1d_channel(y_col, dpdz_neg=G_grav, H_half=H_col, tau_y=tau_y_col, eta_p=eta_p_col, m_reg=mv)
disp_mm = pap_col["velocity"] * t_hold * 1e3
slumps_mm.append(float(np.max(disp_mm)))
print(f"Papanastasiou m = {mv:5.1f} s | 2-hour centreline slump = {np.max(disp_mm):7.2f} mm (true Bingham = 0.00 mm)")
axes[0].plot(disp_mm, y_col * 1e3, "--", lw=2.0, label=f"Papanastasiou $m = {mv:.0f}$ s")
assert slumps_mm[0] > 200.0 # Over 200 mm (20 cm) of false drainage at m = 10 s
assert slumps_mm[0] > slumps_mm[1] > slumps_mm[2] > 5.0
axes[0].set_xlabel("Displacement after 2 hours [mm]")
axes[0].set_ylabel("Slot transverse position $y$ [mm]")
axes[0].set_title(r"Displacement after 2 h")
axes[0].legend(fontsize=8, loc="upper center", bbox_to_anchor=(0.5, -0.17), ncol=2)
axes[1].bar([f"$m={m:.0f}$ s" for m in m_holds] + ["Exact\nBingham"], slumps_mm + [0.0], color=["#C0392B", "#E08214", "#F2C744", "#2E8B57"])
axes[1].set_ylabel("Centreline displacement after 2 hours [mm]")
axes[1].set_title(r"Centreline displacement")
label_panels(fig)
plt.show()
Exercise 2: creep of the regularized model below the yield stress
=================================================================
Papanastasiou m = 10.0 s | 2-hour centreline slump = 4026.86 mm (true Bingham = 0.00 mm)
Papanastasiou m = 50.0 s | 2-hour centreline slump = 848.49 mm (true Bingham = 0.00 mm)
Papanastasiou m = 250.0 s | 2-hour centreline slump = 171.63 mm (true Bingham = 0.00 mm)

Figure S9.2. A gel layer held for 2 h at a wall stress of . (a) Displacement profiles of the Papanastasiou model for three values of ; the Bingham material does not move. (b) Centreline displacement: 4.0 m, 0.85 m and 0.17 m.
Explanation. The regularized model has a finite viscosity of about at small shear rates and flows under any stress. In 2 h the centreline moves 4.0 m, 0.85 m and 0.17 m for the three values of : the displacement is roughly inversely proportional to and does not vanish. For a question in which the fluid has to stay at rest for a long time (storage, a pipeline that has been stopped, a printed layer before it sets), the regularized model gives a qualitatively wrong answer, and a method without regularization (Lecture 10) or an elastoviscoplastic model (Lecture 11) is needed.
Exercise 3¶
Problem. Write herschel_bulkley_planar_exact(y_grid, dpdz_neg, H_half, tau_y, K_hb, n_hb) in NumPy from the exact velocity profile of a Herschel–Bulkley fluid, , in a plane channel. Check that (1) it agrees with buckingham_reiner_exact_1d for , (2) the velocity is zero when , and (3) for the assumed parameters CARBOPOL_EVP () the plug has the expected width.
heading("Exercise 3: exact Herschel-Bulkley flow in a plane channel")
def herschel_bulkley_planar_exact(
y_grid: np.ndarray, dpdz_neg: float, H_half: float, tau_y: float, K_hb: float, n_hb: float
) -> dict:
"""Exact unregularized planar Herschel-Bulkley velocity & flux on [-H_half, +H_half]."""
y = np.asarray(y_grid, dtype=float).ravel()
G = float(dpdz_neg)
H = float(H_half)
tau_w = G * H
y_p = min(H, tau_y / G) if G > 0.0 else H
if tau_w <= tau_y or G == 0.0:
return {"y": y, "velocity": np.zeros_like(y), "plug_half_width": float(y_p), "flow_rate": 0.0}
p_exp = (n_hb + 1.0) / n_hb
pref = (n_hb / (n_hb + 1.0)) / (G * (K_hb ** (1.0 / n_hb)))
excess_wall = (tau_w - tau_y) ** p_exp
excess_y = (np.maximum(0.0, G * np.abs(y) - tau_y)) ** p_exp
u = pref * (excess_wall - excess_y)
# Exact integrated volumetric flow rate across [-H, +H]:
xi = tau_y / tau_w
q_flux = 2.0 * (n_hb / (n_hb + 1.0)) * (H**2) * (((tau_w - tau_y) / K_hb) ** (1.0 / n_hb)) * (
1.0 - (1.0 - xi) / ((2.0 * n_hb + 1.0) / n_hb)
) * (1.0 - xi) + 2.0 * y_p * float(pref * excess_wall)
# Verify/compute exact integral cleanly via analytical antiderivative of (excess_wall - excess_y):
q_exact = 2.0 * pref * (H * excess_wall - (n_hb / (2.0 * n_hb + 1.0)) * ((tau_w - tau_y) ** (p_exp + 1.0)) / G)
_ = q_flux
return {"y": y, "velocity": u, "plug_half_width": float(y_p), "flow_rate": float(q_exact)}
y_hb = np.linspace(-1.0, 1.0, 401)
# 1. Exact reduction to Bingham at n_hb == 1.0:
hb_n1 = herschel_bulkley_planar_exact(y_hb, dpdz_neg=2.5, H_half=1.0, tau_y=0.75, K_hb=1.4, n_hb=1.0)
br_ref = viscoplastic_admm.buckingham_reiner_exact_1d(y_hb, dpdz_neg=2.5, H_or_R=1.0, tau_y=0.75, eta_p=1.4, geometry="planar")
assert np.allclose(hb_n1["velocity"], br_ref["velocity"], rtol=1e-13, atol=1e-13)
assert np.isclose(hb_n1["flow_rate"], br_ref["flow_rate"], rtol=1e-13)
# 2. Exact sub-yield arrest:
hb_sub = herschel_bulkley_planar_exact(y_hb, dpdz_neg=0.5, H_half=1.0, tau_y=0.75, K_hb=1.4, n_hb=0.42)
assert np.all(hb_sub["velocity"] == 0.0) and hb_sub["flow_rate"] == 0.0
# 3. CARBOPOL_EVP benchmark comparison across power-law indices n in {0.42, 0.70, 1.0, 1.3}:
carb_db = constants_benchmarks.BENCHMARK_FLUIDS_DB["CARBOPOL_EVP"]
y_slot = np.linspace(-0.01, 0.01, 401)
fig, ax = plt.subplots(figsize=(7.4, 4.1))
for n_val, col in [(carb_db["n_hb"], "#C0392B"), (0.70, "#E08214"), (1.00, "#2166AC"), (1.30, "#2E8B57")]:
sol_n = herschel_bulkley_planar_exact(y_slot, dpdz_neg=9000.0, H_half=0.01, tau_y=carb_db["tau_y_Pa"], K_hb=carb_db["K_hb_Pasn"], n_hb=n_val)
q_trap = float(trapezoid(sol_n["velocity"], y_slot))
assert np.isclose(sol_n["flow_rate"], q_trap, rtol=1e-4)
u_norm = sol_n["velocity"] / np.max(sol_n["velocity"])
print(f"n_hb = {n_val:.2f} | plug half-width y_p = {sol_n['plug_half_width']*1e3:.2f} mm | exact flux Q = {sol_n['flow_rate']:.4e} m^2/s")
ax.plot(u_norm, y_slot * 1e3, lw=2.1, color=col, label=f"$n = {n_val:.2f}$ ($u_{{\\max}}={1e3*np.max(sol_n['velocity']):.1f}$ mm/s)")
ax.axhspan(-5.0, 5.0, color="#eaecee", alpha=0.6, label="Exact rigid plug ($y_p = 5.0$ mm)")
ax.set_xlabel(r"Normalized velocity $u(y) / u_{\max}$")
ax.set_ylabel("Slot coordinate $y$ [mm]")
ax.set_title(r"Herschel–Bulkley velocity profiles")
ax.legend(fontsize=8)
plt.show()
Exercise 3: exact Herschel-Bulkley flow in a plane channel
==========================================================
n_hb = 0.42 | plug half-width y_p = 5.00 mm | exact flux Q = 6.0964e-04 m^2/s
n_hb = 0.70 | plug half-width y_p = 5.00 mm | exact flux Q = 2.3240e-04 m^2/s
n_hb = 1.00 | plug half-width y_p = 5.00 mm | exact flux Q = 1.5625e-04 m^2/s
n_hb = 1.30 | plug half-width y_p = 5.00 mm | exact flux Q = 1.2803e-04 m^2/s

Figure S9.3. Exact velocity profiles of the Herschel–Bulkley model in a plane channel, divided by their maxima, for four power-law indices; is the assumed value of CARBOPOL_EVP. The plug (shaded) has the same width for all.
Explanation. The edge of the plug is where the shear stress equals the yield stress, mm here; it does not depend on or on . The index changes the flow outside the plug: at the same pressure gradient the flow rate per unit width is for and for .