Worked solutions to the three exercises of Lecture 7. 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: start-up of shear of the Rolie-Poly model (PS_MELT_RP)")
ps_db = constants_benchmarks.BENCHMARK_FLUIDS_DB["PS_MELT_RP"]
G0_ps = ps_db["G0_Pa"]
tau_d_ps = ps_db["tau_d_s"]
tau_R_ps = ps_db["tau_R_s"]
# Three canonical shear rates spanning Wi_d < 1, Wi_d > 1 > Wi_R, and Wi_R > 1:
regimes = [
("Reptation (Wi_d=0.5, Wi_R=0.015)", 0.5 / tau_d_ps, "#2166AC"),
("Orientation/CCR (Wi_d=12, Wi_R=0.35)", 12.0 / tau_d_ps, "#E08214"),
("Rouse stretch (Wi_d=72, Wi_R=2.10)", 2.1 / tau_R_ps, "#C0392B"),
]
fig, axes = plt.subplots(1, 2, figsize=(10.2, 4.0))
peak_stretches = []
for label, gdot_val, col in regimes:
t_span = np.linspace(0.0, min(28.0, max(2.5, 10.0 / gdot_val)), 75)
L_fn = lambda _t, g=gdot_val: np.array([[0.0, g, 0.0], [0.0, 0.0, 0.0], [0.0, 0.0, 0.0]])
rp = entangled_tubes.solve_rolie_poly(
L_fn, t_span, G0=G0_ps, tau_d=tau_d_ps, tau_R=tau_R_ps, beta_ccr=ps_db["beta_ccr"], delta_ccr=ps_db["delta_ccr"]
)
eta_plus = rp["tau_xy"] / gdot_val
lam_max = float(np.max(rp["stretch_lambda"]))
peak_stretches.append(lam_max)
strain_axis = gdot_val * t_span
print(f"{label:38s} | peak stretch lambda = {lam_max:5.3f} | steady eta = {eta_plus[-1]:9.1f} Pa*s")
axes[0].loglog(t_span[1:], eta_plus[1:], lw=2.0, color=col, label=label)
axes[1].plot(strain_axis, rp["stretch_lambda"], lw=2.0, color=col, label=label)
# Linear viscoelastic Maxwell envelope G0 * tau_d * (1 - exp(-t / tau_d)):
t_env = np.geomspace(1e-2, 28.0, 120)
axes[0].loglog(t_env, G0_ps * tau_d_ps * (1.0 - np.exp(-t_env / tau_d_ps)), "k--", lw=1.4, label=r"Linear viscoelastic $G_0\tau_d(1-e^{-t/\tau_d})$")
axes[0].set_xlabel("Time $t$ [s]")
axes[0].set_ylabel(r"Transient viscosity $\eta^+(t) = \tau_{xy}/\dot{\gamma}$ [Pa$\cdot$s]")
axes[0].set_title(r"Transient viscosity")
axes[0].legend(fontsize=7.5)
axes[1].set_xlim(0.0, 16.0)
axes[1].set_xlabel(r"Shear strain $\gamma = \dot{\gamma} t$")
axes[1].set_ylabel(r"Tube stretch ratio $\lambda = \sqrt{\operatorname{tr}\mathbf{C}/3}$")
axes[1].set_title(r"Chain stretch")
axes[1].legend(fontsize=7.5)
label_panels(fig)
plt.show()
assert peak_stretches[0] < 1.02
assert peak_stretches[2] > 1.35 * peak_stretches[1]
_stdout.__exit__(None, None, None); plt.show = _show; plt.close("all")Exercise 1¶
Problem. Check that solve_pom_pom_melt at follows the linear viscoelastic start-up . Then check, in uniaxial extension with an orientation time much longer than the stretch time (, , ), that the steady stretch is for and equals above this value.
heading("Exercise 1: linear viscoelastic limit and steady stretch of the Pom-Pom model")
# 1. LVE limit check at Wi_b = 0.01:
G0_e1, tb_e1, ts_e1, q_e1 = 1.0e4, 3.0, 0.5, 5
gdot_lve = 0.01 / tb_e1
t_lve = np.linspace(0.0, 10.0, 70)
pp_lve = entangled_tubes.solve_pom_pom_melt(
lambda _t: np.array([[0.0, gdot_lve, 0.0], [0.0, 0.0, 0.0], [0.0, 0.0, 0.0]]),
t_lve, G0=G0_e1, tau_b=tb_e1, tau_s=ts_e1, q_arms=q_e1
)
eta_lve_num = pp_lve["tau_xy"] / gdot_lve
eta_lve_ex = G0_e1 * tb_e1 * (1.0 - np.exp(-t_lve / tb_e1))
assert np.allclose(eta_lve_num[1:], eta_lve_ex[1:], rtol=6e-3, atol=30.0)
# 2. High-Wi_b uniaxial stretch law: when S_xx -> 1, d(lam)/dt = lam*edot - (lam - 1)/tau_s == 0 -> lam = min(q, 1/(1 - Wi_s))
tb_long, ts_short = 40.0, 0.5
wis_grid = np.array([0.20, 0.45, 0.65, 0.85, 1.25])
lam_num = []
for wis in wis_grid:
ed = wis / ts_short
tg = np.linspace(0.0, max(8.0, 7.0 / ed), 75)
sol = entangled_tubes.solve_pom_pom_melt(
lambda _t, e=ed: np.diag([e, -0.5 * e, -0.5 * e]),
tg, G0=G0_e1, tau_b=tb_long, tau_s=ts_short, q_arms=q_e1
)
lam_num.append(float(sol["lambda_stretch"][-1]))
lam_num = np.array(lam_num)
lam_theory = np.where(wis_grid < 1.0 - 1.0 / q_e1, 1.0 / (1.0 - wis_grid), float(q_e1))
print(f"{'Wi_s':>6s} | {'Numerical lambda':>17s} | {'Exact min(q, 1/(1-Wi_s))':>25s}")
print("-" * 56)
for w, ln, lt in zip(wis_grid, lam_num, lam_theory):
print(f"{w:6.2f} | {ln:17.4f} | {lt:25.4f}")
assert np.allclose(lam_num, lam_theory, rtol=0.025)
fig, axes = plt.subplots(1, 2, figsize=(9.8, 3.8))
axes[0].plot(t_lve, eta_lve_ex / 1e3, "k-", lw=2.2, label=r"Exact Maxwell $G_0\tau_b(1-e^{-t/\tau_b})$")
axes[0].plot(t_lve[::8], eta_lve_num[::8] / 1e3, "ro", ms=5, label=r"Pom-Pom ($\mathrm{Wi}_b = 0.01$)")
axes[0].set_xlabel("Time $t$ [s]")
axes[0].set_ylabel(r"$\eta^+(t)$ [kPa$\cdot$s]")
axes[0].set_title(r"Transient viscosity at a low rate")
axes[0].legend(fontsize=8)
w_fine = np.linspace(0.0, 1.8, 300)
l_fine = np.where(w_fine < 1.0 - 1.0 / q_e1, 1.0 / np.maximum(1.0 - w_fine, 1e-6), float(q_e1))
axes[1].plot(w_fine, l_fine, "k--", lw=1.8, label=r"Analytical $\min(q, (1-\mathrm{Wi}_s)^{-1})$")
axes[1].plot(wis_grid, lam_num, "bs", ms=6, label="Simulated steady stretch")
axes[1].axvline(1.0 - 1.0 / q_e1, color="#C0392B", ls=":", lw=1.4, label=r"Arm withdrawal $\mathrm{Wi}_s = 1 - 1/q$")
axes[1].set_xlabel(r"$\mathrm{Wi}_s = \dot{\varepsilon}\tau_s$")
axes[1].set_ylabel(r"Steady stretch $\bar{\lambda}_\infty$")
axes[1].set_title(r"Steady stretch in extension")
axes[1].legend(fontsize=8)
label_panels(fig)
plt.show()
Exercise 1: linear viscoelastic limit and steady stretch of the Pom-Pom model
=============================================================================
Wi_s | Numerical lambda | Exact min(q, 1/(1-Wi_s))
--------------------------------------------------------
0.20 | 1.2500 | 1.2500
0.45 | 1.8178 | 1.8182
0.65 | 2.8471 | 2.8571
0.85 | 5.0000 | 5.0000
1.25 | 5.0000 | 5.0000

Figure S7.1. (a) At the Pom-Pom shear viscosity follows the single-mode Maxwell curve. (b) Steady backbone stretch in uniaxial extension against , with .
Explanation. When the backbone is aligned with the direction of extension (), the stretch equation becomes , with the steady state . This reaches the maximum stretch at . The computed stretches are 1.2500, 1.8178 and 2.8471, against 1.2500, 1.8182 and 2.8571 from the formula, below this value, and 5.0000 above it. Computed values slightly below the formula are expected when is slightly smaller than 1.
Exercise 2¶
Problem. Show two ways in which a tube model fails when one of its terms is left out. (1) Run solve_pom_pom_melt with the parameters LDPE_IUPAC_A in uniaxial extension at for 6 s with enforce_arm_cap=False and with True, and compare the stretch and the tensile stress. (2) Run solve_rolie_poly with the parameters PS_MELT_RP with and with 0.5, and find whether the steady shear stress decreases with shear rate.
heading("Exercise 2: the Pom-Pom model without the stretch limit, and Rolie-Poly without constraint release")
ldpe_e2 = constants_benchmarks.BENCHMARK_FLUIDS_DB["LDPE_IUPAC_A"]
t_e2 = np.linspace(0.0, 6.0, 75)
edot_e2 = 2.2
L_u_e2 = lambda _t: np.diag([edot_e2, -0.5 * edot_e2, -0.5 * edot_e2])
pp_ok = entangled_tubes.solve_pom_pom_melt(
L_u_e2, t_e2, G0=ldpe_e2["G0_Pa"], tau_b=ldpe_e2["tau_b_s"], tau_s=ldpe_e2["tau_s_s"], q_arms=ldpe_e2["q_arms"], enforce_arm_cap=True
)
pp_bad = entangled_tubes.solve_pom_pom_melt(
L_u_e2, t_e2, G0=ldpe_e2["G0_Pa"], tau_b=ldpe_e2["tau_b_s"], tau_s=ldpe_e2["tau_s_s"], q_arms=ldpe_e2["q_arms"], enforce_arm_cap=False
)
sig_ok = float(pp_ok["tau_p"][-1, 0, 0] - pp_ok["tau_p"][-1, 1, 1])
sig_bad = float(pp_bad["tau_p"][-1, 0, 0] - pp_bad["tau_p"][-1, 1, 1])
print(f"Pom-Pom with stretch limit : final stretch = {pp_ok['lambda_stretch'][-1]:6.2f}, tensile stress = {sig_ok/1e6:8.3f} MPa")
print(f"Pom-Pom without stretch limit: final stretch = {pp_bad['lambda_stretch'][-1]:6.2f}, tensile stress = {sig_bad/1e6:8.3f} MPa ({sig_bad/sig_ok:.0f} times larger)")
assert pp_ok["lambda_stretch"][-1] <= ldpe_e2["q_arms"] + 1e-12
assert pp_bad["lambda_stretch"][-1] > 10.0 * ldpe_e2["q_arms"]
assert sig_bad > 100.0 * sig_ok
# Zero-CCR Rolie-Poly audit across intermediate window:
ps_e2 = constants_benchmarks.BENCHMARK_FLUIDS_DB["PS_MELT_RP"]
g_win = np.geomspace(0.08, 2.5, 5)
txy_bad = [
float(entangled_tubes.solve_rolie_poly(
lambda _t, gv=g: np.array([[0.0, gv, 0.0], [0.0, 0.0, 0.0], [0.0, 0.0, 0.0]]),
np.linspace(0.0, min(28.0, max(4.0, 11.0 / g)), 65),
G0=ps_e2["G0_Pa"], tau_d=ps_e2["tau_d_s"], tau_R=ps_e2["tau_R_s"], beta_ccr=0.0
)["tau_xy"][-1])
for g in g_win
]
txy_good = [
float(entangled_tubes.solve_rolie_poly(
lambda _t, gv=g: np.array([[0.0, gv, 0.0], [0.0, 0.0, 0.0], [0.0, 0.0, 0.0]]),
np.linspace(0.0, min(28.0, max(4.0, 11.0 / g)), 65),
G0=ps_e2["G0_Pa"], tau_d=ps_e2["tau_d_s"], tau_R=ps_e2["tau_R_s"], beta_ccr=0.5
)["tau_xy"][-1])
for g in g_win
]
print(f"Rolie-Poly min d(tau_xy) : beta_CCR=0 -> {min(np.diff(txy_bad)):+.1f} Pa against beta_CCR=0.5 -> {min(np.diff(txy_good)):+.1f} Pa")
assert min(np.diff(txy_bad)) < 0.0 and min(np.diff(txy_good)) > 0.0
fig, axes = plt.subplots(1, 2, figsize=(9.8, 3.8))
axes[0].semilogy(t_e2, pp_bad["lambda_stretch"], "r--", lw=2.0, label="Without the limit")
axes[0].semilogy(t_e2, pp_ok["lambda_stretch"], "b-", lw=2.2, label="With the limit $\\bar{\\lambda}\\leq 5$")
axes[0].set_xlabel("Time $t$ [s]")
axes[0].set_ylabel(r"Backbone stretch $\bar{\lambda}(t)$")
axes[0].set_title(r"Backbone stretch with and without the limit $q$")
axes[0].legend(fontsize=8)
axes[1].semilogx(g_win * ps_e2["tau_d_s"], np.array(txy_bad) / 1e3, "rs--", lw=2.0, label=r"$\beta_{\mathrm{CCR}} = 0$ (non-monotonic)")
axes[1].semilogx(g_win * ps_e2["tau_d_s"], np.array(txy_good) / 1e3, "bo-", lw=2.0, label=r"$\beta_{\mathrm{CCR}} = 0.5$ (monotonic)")
axes[1].set_xlabel(r"$\mathrm{Wi}_d = \dot{\gamma}\tau_d$")
axes[1].set_ylabel(r"Steady $\tau_{xy}$ [kPa]")
axes[1].set_title(r"Rolie-Poly steady shear stress")
axes[1].legend(fontsize=8)
label_panels(fig)
plt.show()
Exercise 2: the Pom-Pom model without the stretch limit, and Rolie-Poly without constraint release
==================================================================================================
Pom-Pom with stretch limit : final stretch = 5.00, tensile stress = 1.125 MPa
Pom-Pom without stretch limit: final stretch = 83.25, tensile stress = 311.860 MPa (277 times larger)
Rolie-Poly min d(tau_xy) : beta_CCR=0 -> -14839.0 Pa against beta_CCR=0.5 -> +4684.2 Pa

Figure S7.2. (a) Without the limit the backbone stretch grows exponentially in extension. (b) Rolie-Poly steady shear stress with , which decreases at high rates, and with 0.5.
Explanation. Without the limit the stretch grows exponentially whenever , as in the Oldroyd-B model. After 6 s it is 83 instead of 5, and the tensile stress, which is proportional to , is 312 MPa instead of 1.1 MPa, a factor of 277. In the Rolie-Poly model without convective constraint release the steady shear stress decreases with shear rate over a range of rates (the most negative increment between neighbouring rates is -14.8 kPa); with it increases everywhere (the smallest increment is +4.7 kPa). A flow curve that decreases leads to shear banding, the subject of Lecture 8.
Exercise 3¶
Problem. Write solve_multimode_pom_pom(L_fn, t_grid, modes) for three modes that stand for the levels of a branched molecule: outer arms (), an intermediate level () and the innermost segments (). Check that start-up of shear at a very low rate follows , and find how the stretch of each mode depends on the extension rate relative to .
heading("Exercise 3: a Pom-Pom model with three modes")
def solve_multimode_pom_pom(L_fn, t_grid: np.ndarray, modes: list[dict]) -> dict:
"""Superpose N_m differential Pom-Pom modes representing hierarchical core-to-skin branching."""
tau_total = np.zeros((t_grid.size, 3, 3), dtype=float)
mode_stretches = []
for m in modes:
res_m = entangled_tubes.solve_pom_pom_melt(
L_fn, t_grid, G0=m["G0"], tau_b=m["tau_b"], tau_s=m["tau_s"], q_arms=m["q"], enforce_arm_cap=True
)
tau_total += res_m["tau_p"]
mode_stretches.append(res_m["lambda_stretch"])
return {"t": t_grid, "tau_p": tau_total, "mode_stretches": np.array(mode_stretches)}
spectrum_ldpe = [
{"name": "Outer arms (q=2)", "G0": 2.4e4, "tau_b": 0.4, "tau_s": 0.12, "q": 2},
{"name": "Mid branch (q=5)", "G0": 1.2e4, "tau_b": 2.5, "tau_s": 0.55, "q": 5},
{"name": "Innermost segments (q=9)", "G0": 0.4e4, "tau_b": 12.0, "tau_s": 2.20, "q": 9},
]
eta0_spec = sum(m["G0"] * m["tau_b"] for m in spectrum_ldpe)
# 1. Verify exact multi-mode LVE superposition at very low shear rate:
t_sp = np.linspace(0.0, 6.0, 81)
g_low = 1e-3
lve_sp = solve_multimode_pom_pom(lambda _t: np.array([[0.0, g_low, 0.0], [0.0, 0.0, 0.0], [0.0, 0.0, 0.0]]), t_sp, spectrum_ldpe)
eta_lve_sp = lve_sp["tau_p"][:, 0, 1] / g_low
eta_lve_exact = sum(m["G0"] * m["tau_b"] * (1.0 - np.exp(-t_sp / m["tau_b"])) for m in spectrum_ldpe)
assert np.allclose(eta_lve_sp[1:], eta_lve_exact[1:], rtol=5e-3, atol=30.0)
# 2. Sequential uniaxial strain-hardening activation across edot = 0.8 and 3.0 s^-1:
t_ext = np.linspace(0.0, 6.0, 70)
fig, axes = plt.subplots(1, 2, figsize=(10.0, 3.9))
axes[0].loglog(np.maximum(t_ext, 2e-2), 3.0 * sum(m["G0"] * m["tau_b"] * (1.0 - np.exp(-t_ext / m["tau_b"])) for m in spectrum_ldpe) + 1.0, "k--", lw=1.6, label=r"Multi-mode $3\eta_{\mathrm{LVE}}^+(t)$")
for ed_val, col in [(0.8, "#2166AC"), (3.0, "#C0392B")]:
out_e = solve_multimode_pom_pom(lambda _t, e=ed_val: np.diag([e, -0.5 * e, -0.5 * e]), t_ext, spectrum_ldpe)
eta_e = (out_e["tau_p"][:, 0, 0] - out_e["tau_p"][:, 1, 1]) / ed_val
axes[0].loglog(np.maximum(t_ext, 2e-2), np.maximum(eta_e, 10.0), lw=2.1, color=col, label=f"$\\dot{{\\varepsilon}} = {ed_val:.1f}\\,\\mathrm{{s}}^{{-1}}$")
print(f"edot = {ed_val:.1f} s^-1 | final stretches [skin, mid, core] = {out_e['mode_stretches'][:, -1].round(2).tolist()} | peak eta_E = {np.max(eta_e)/1e3:.1f} kPa*s")
if ed_val == 0.8:
# At edot=0.8: edot*tau_s = [0.096, 0.44, 1.76] -> inner core stretches strongly while outer skin stays near 1
assert out_e["mode_stretches"][2, -1] > 4.0 and out_e["mode_stretches"][0, -1] < 1.25
else:
for idx_m, m in enumerate(spectrum_ldpe):
assert out_e["mode_stretches"][idx_m, -1] <= m["q"] + 1e-12
for idx_m, m in enumerate(spectrum_ldpe):
axes[1].plot(t_ext, out_e["mode_stretches"][idx_m], lw=2.0, label=f"{m['name']} ($\\bar{{\\lambda}}\\leq {m['q']}$)")
axes[0].set_xlabel("Time $t$ [s]")
axes[0].set_ylabel(r"Extensional viscosity $\eta_E^+(t)$ [Pa$\cdot$s]")
axes[0].set_title(r"Extensional viscosity of three modes")
axes[0].legend(fontsize=8)
axes[1].set_xlabel("Time $t$ [s]")
axes[1].set_ylabel(r"Mode stretch $\bar{\lambda}_m(t)$")
axes[1].set_title(r"Stretch of each mode")
axes[1].legend(fontsize=8, loc="lower right", bbox_to_anchor=(1.0, 0.17))
label_panels(fig)
plt.show()
Exercise 3: a Pom-Pom model with three modes
============================================
edot = 0.8 s^-1 | final stretches [skin, mid, core] = [1.05, 1.78, 9.0] | peak eta_E = 1403.1 kPa*s
edot = 3.0 s^-1 | final stretches [skin, mid, core] = [1.56, 5.0, 9.0] | peak eta_E = 682.6 kPa*s

Figure S7.3. Three Pom-Pom modes (assumed parameters). (a) Transient extensional viscosity at two rates, with the linear envelope. (b) Stretch of each mode at : each stops at its own limit .
Explanation. A mode stretches when the extension rate exceeds the inverse of its stretch time. The innermost mode has the longest stretch time and the largest maximum stretch: at it has reached its maximum of 9 while the other two modes are at 1.05 and 1.78, and at the intermediate mode has reached its maximum of 5 as well. The peak extensional viscosity is lower at the higher rate (683 against 1403 kPa·s): the stretch is limited, and the viscosity is the stress divided by the rate. A model with several modes of this kind was fitted to low-density polyethylene by Inkson, McLeish, Harlen and Groves (1999).