A constitutive equation for the conformation tensor is an average over polymer molecules that are moved by the flow and by thermal collisions with the solvent. The average can also be computed directly, by simulating many model molecules. The simplest model is a dumbbell: two beads joined by a spring, whose connector vector obeys a stochastic differential equation.
For a spring of finite length (the FENE spring, whose force diverges at the length ) the explicit Euler scheme fails: a random displacement can carry the connector beyond , where the force changes sign. The semi-implicit scheme of Öttinger evaluates the spring force at the new length. This leads to a cubic equation with exactly one root below , for any time step. The lecture derives the scheme and uses it to compute viscometric functions.
Learning objectives¶
Write the dimensionless stochastic differential equation of a dumbbell with a Hookean, a FENE and a wormlike-chain spring.
Derive the cubic equation of the semi-implicit scheme, show that it has one root in , and solve it with
brownian_chains.solve_fene_cubic_radial.Compare the explicit scheme (
explicit_unsafe=True) with the semi-implicit scheme (explicit_unsafe=False) inbrownian_chains.simulate_dumbbell_bd.Compute the viscosity and the first normal stress coefficient in shear, and the stretch in extension above .
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. Stochastic differential equations of dumbbells, and spring laws¶
Lengths are scaled by , the root-mean-square length of one component of the connector of a Hookean dumbbell at equilibrium, and times by the relaxation time . The connector vector then obeys the stochastic differential equation
in which is the increment of a Wiener process. For a spring of finite length, is the square of the dimensionless maximum length, so that . Three spring laws are used:
The Hookean spring has no maximum length. The FENE spring describes flexible polymers, and the wormlike-chain (WLC) spring describes semiflexible ones such as DNA; its force diverges more steeply at full extension.
The semi-implicit scheme of Öttinger is a predictor–corrector method. The predictor gives a vector . In the corrector the spring force is evaluated at the new time, which makes the new connector parallel to the predictor, , and leaves one scalar equation for the new length , with :
Because and , the cubic has exactly one root in , however large the predictor is.
heading("Demonstration 1: spring laws and the root of the cubic equation")
b_demo = 49.0 # sqrt(b) = 7.0
r_grid = np.linspace(0.0, 6.85, 200)
x_rel = r_grid / math.sqrt(b_demo)
f_hook = r_grid
f_fene = r_grid / (1.0 - (r_grid**2) / b_demo)
f_wlc = np.where(x_rel < 1e-7, r_grid, (2.0 / 3.0) * (1.0 / ((1.0 - x_rel) ** 2) - 1.0 + 4.0 * x_rel) / np.maximum(x_rel, 1e-12) * (r_grid / math.sqrt(b_demo)))
Y_sweep = np.logspace(-2, 2.5, 60)
R_cubic = brownian_chains.solve_fene_cubic_radial(Y_sweep, b_ext=b_demo, coeff_alpha=0.25)
res_alg = R_cubic * (1.0 + 0.25 / (1.0 - (R_cubic**2) / b_demo)) - Y_sweep
print(f"Max algebraic residual across Y in [1e-2, 316]: {np.max(np.abs(res_alg)):.3e}")
print(f"At extreme RHS Y = {Y_sweep[-1]:.1f} -> R = {R_cubic[-1]:.8f} < sqrt(b) = {math.sqrt(b_demo):.1f}")
assert np.max(np.abs(res_alg)) < 1e-11
assert np.all((R_cubic >= 0.0) & (R_cubic < math.sqrt(b_demo)))
assert brownian_chains.solve_fene_cubic_radial(np.array([0.0]), b_ext=b_demo, coeff_alpha=0.25)[0] == 0.0
fig, axes = plt.subplots(1, 2, figsize=(10.5, 3.8))
axes[0].semilogy(x_rel[1:], f_hook[1:], "--", color="gray", lw=1.8, label="Hookean $Q$")
axes[0].semilogy(x_rel[1:], f_fene[1:], "-", color="#2166AC", lw=2.1, label="FENE $(1 - Q^2/b)^{-1}$")
axes[0].semilogy(x_rel[1:], f_wlc[1:], "-", color="#C0392B", lw=2.1, label="Wormlike chain $(1 - Q/\\sqrt{b})^{-2}$")
axes[0].axvline(1.0, color="k", ls=":", label="Maximum length $Q / \\sqrt{b} = 1$")
axes[0].set_xlabel(r"Fractional extension $Q / \sqrt{b}$")
axes[0].set_ylabel(r"Dimensionless spring force $|\mathbf{F}(Q)|$")
axes[0].set_title(r"Spring forces")
axes[0].legend(fontsize=8)
axes[1].semilogx(Y_sweep, R_cubic, "-o", color="#2E8B57", ms=3.5, lw=2.0, label=r"Cubic root $R(\|\mathbf{Y}\|)$")
axes[1].axhline(math.sqrt(b_demo), color="#C0392B", ls="--", lw=1.8, label=rf"Maximum length $\sqrt{{b}} = {math.sqrt(b_demo):.1f}$")
axes[1].set_xlabel(r"Length of the predictor $\|\mathbf{Y}\|$")
axes[1].set_ylabel(r"New length $R \in [0, \sqrt{b})$")
axes[1].set_title(r"Root of the cubic equation")
axes[1].legend(fontsize=8.5)
label_panels(fig)
plt.show()
Demonstration 1: spring laws and the root of the cubic equation
===============================================================
Max algebraic residual across Y in [1e-2, 316]: 8.129e-12
At extreme RHS Y = 316.2 -> R = 6.98022188 < sqrt(b) = 7.0

Figure 3.1. (a) Magnitude of the Hookean, FENE and wormlike-chain spring forces against the fractional extension. (b) The root of the cubic equation of the semi-implicit step against the norm of its right-hand side: it stays below for every input.
2. The explicit Euler scheme against the semi-implicit scheme¶
The explicit Euler–Maruyama scheme (explicit_unsafe=True) fails for FENE springs in two ways. Near the restoring displacement is either
too small to compensate the displacement by the flow and by the noise, , so that ; there , and the spring force points outwards; or
too large, so that the connector is carried through the origin and beyond the maximum length on the other side.
The demonstration runs the same ensemble (n_trajectories = 700, seed = 7) with both schemes in shear at with the step (b_ext = 25).
heading("Demonstration 2: explicit and semi-implicit schemes at Wi = 8 and dt = 0.1")
L_wi8 = np.array([[0.0, 8.0, 0.0], [0.0, 0.0, 0.0], [0.0, 0.0, 0.0]])
t_coarse_bd = np.linspace(0.0, 2.0, 21) # dt = 0.10
t_fine_bd = np.linspace(0.0, 2.0, 81) # dt = 0.025 reference
bd_safe_8 = brownian_chains.simulate_dumbbell_bd(
lambda _t: L_wi8, t_coarse_bd, model="fene", b_ext=25.0, n_trajectories=700, explicit_unsafe=False, seed=7
)
bd_unsafe_8 = brownian_chains.simulate_dumbbell_bd(
lambda _t: L_wi8, t_coarse_bd, model="fene", b_ext=25.0, n_trajectories=700, explicit_unsafe=True, seed=7
)
bd_ref_8 = brownian_chains.simulate_dumbbell_bd(
lambda _t: L_wi8, t_fine_bd, model="fene", b_ext=25.0, n_trajectories=1000, explicit_unsafe=False, seed=17
)
print(f"Explicit Euler (dt=0.10): overstretched events = {bd_unsafe_8['overstretched_count']}, max <Q^2> = {np.max(bd_unsafe_8['mean_Q2']):.2f}")
print(f"Semi-implicit (dt=0.10): overstretched events = {bd_safe_8['overstretched_count']}, max <Q^2> = {np.max(bd_safe_8['mean_Q2']):.2f} (< b=25)")
assert bd_safe_8["overstretched_count"] == 0
assert bd_unsafe_8["overstretched_count"] > 0
assert float(np.max(bd_safe_8["mean_Q2"])) < 25.0
fig, axes = plt.subplots(1, 2, figsize=(10.5, 3.8))
axes[0].plot(t_fine_bd, bd_ref_8["mean_Q2"], "k-", lw=2.0, label=r"Fine reference ($\Delta t=0.0125$)")
axes[0].plot(t_coarse_bd, bd_safe_8["mean_Q2"], "-o", color="#2E8B57", lw=2.0, ms=4.5, label=r"Semi-implicit ($\Delta t=0.10$, 0 violations)")
axes[0].plot(t_coarse_bd, np.clip(bd_unsafe_8["mean_Q2"], 0.0, 45.0), "--s", color="#C0392B", lw=1.9, ms=4.5, label=r"Explicit Euler (overstretches $Q \geq \sqrt{b}$)")
axes[0].axhline(25.0, color="gray", ls=":", lw=1.5, label="Limit $b = 25$")
axes[0].set_xlabel(r"Dimensionless time $t / \lambda_H$")
axes[0].set_ylabel(r"Mean-square extension $\langle Q^2 \rangle$")
axes[0].set_title(r"Mean-square extension ($\mathrm{Wi} = 8$, $\Delta t = 0.1$)")
axes[0].legend(fontsize=8, loc="upper center", bbox_to_anchor=(0.5, -0.17), ncol=2)
axes[1].plot(t_fine_bd, bd_ref_8["tau_xy"], "k-", lw=2.0, label="Fine reference $\\tau_{xy}$")
axes[1].plot(t_coarse_bd, bd_safe_8["tau_xy"], "-o", color="#2166AC", lw=2.0, ms=4.5, label="Semi-implicit $\\tau_{xy}$")
axes[1].set_xlabel(r"Dimensionless time $t / \lambda_H$")
axes[1].set_ylabel(r"Dimensionless shear stress $\tau_{xy} / (n_p k_B T)$")
axes[1].set_title(r"Shear stress")
axes[1].legend(fontsize=8.5)
label_panels(fig)
plt.show()
Demonstration 2: explicit and semi-implicit schemes at Wi = 8 and dt = 0.1
==========================================================================
Explicit Euler (dt=0.10): overstretched events = 744, max <Q^2> = 947.71
Semi-implicit (dt=0.10): overstretched events = 0, max <Q^2> = 9.35 (< b=25)

Figure 3.2. FENE dumbbells () in start-up of shear. (a) Mean-square extension with the explicit Euler step, which exceeds , with the semi-implicit step at the same , and with a fine reference step. (b) Shear stress of the semi-implicit run against the fine reference.
3. Viscosity and normal stress coefficient in shear¶
For Hookean dumbbells the viscosity and the first normal stress coefficient do not depend on the shear rate. A finite length limits the stretch of a dumbbell along the axis of extension of the shear flow, at , before the rotation of the flow turns it towards the flow direction. FENE dumbbells therefore thin in shear, with decreasing approximately as at high . The simulation gives this result directly, without a closure approximation.
heading("Demonstration 3: viscosity and first normal stress coefficient against shear rate")
wi_list = np.array([0.4, 1.0, 2.0, 4.0, 7.0])
eta_fene_20, eta_fene_60, psi1_fene_20 = [], [], []
for wv in wi_list:
Lw = np.array([[0.0, float(wv), 0.0], [0.0, 0.0, 0.0], [0.0, 0.0, 0.0]])
t_w = np.linspace(0.0, 3.6, 55)
b20 = brownian_chains.simulate_dumbbell_bd(lambda _t, L=Lw: L, t_w, model="fene", b_ext=20.0, n_trajectories=900, seed=31)
b60 = brownian_chains.simulate_dumbbell_bd(lambda _t, L=Lw: L, t_w, model="fene", b_ext=60.0, n_trajectories=900, seed=31)
# Average over the steady tail:
eta_fene_20.append(float(np.mean(b20["tau_xy"][35:]) / wv))
eta_fene_60.append(float(np.mean(b60["tau_xy"][35:]) / wv))
psi1_fene_20.append(float(np.mean(b20["N1"][35:]) / (wv**2)))
print(f"FENE (b=20) viscosity drops from {eta_fene_20[0]:.3f} (Wi=0.4) to {eta_fene_20[-1]:.3f} (Wi=7.0)")
print(f"FENE (b=60) viscosity drops from {eta_fene_60[0]:.3f} (Wi=0.4) to {eta_fene_60[-1]:.3f} (Wi=7.0)")
assert eta_fene_20[-1] < 0.65 * eta_fene_20[0]
assert eta_fene_60[0] > eta_fene_20[0] # Larger b approaches Hookean limit eta_p -> 1
assert psi1_fene_20[-1] < 0.45 * psi1_fene_20[0]
fig, axes = plt.subplots(1, 2, figsize=(10.5, 3.8))
axes[0].loglog(wi_list, eta_fene_60, "-s", color="#2166AC", lw=2.0, ms=5, label="FENE BD ($b = 60$)")
axes[0].loglog(wi_list, eta_fene_20, "-o", color="#C0392B", lw=2.0, ms=5, label="FENE BD ($b = 20$)")
axes[0].axhline(1.0, color="gray", ls=":", label="Hookean limit $\\eta_p = 1$")
axes[0].set_xlabel(r"Weissenberg number $\mathrm{Wi} = \lambda_H\dot{\gamma}$")
axes[0].set_ylabel(r"Dimensionless viscosity $\eta_p(\mathrm{Wi})$")
axes[0].set_title(r"Polymer viscosity")
axes[0].legend(fontsize=8.5)
axes[1].loglog(wi_list, psi1_fene_20, "-^", color="#2E8B57", lw=2.0, ms=5.5, label=r"FENE BD $\Psi_1(\mathrm{Wi}) = N_1 / \mathrm{Wi}^2$ ($b=20$)")
axes[1].axhline(2.0, color="gray", ls=":", label=r"Hookean limit $\Psi_1 = 2$")
axes[1].set_xlabel(r"Weissenberg number $\mathrm{Wi} = \lambda_H\dot{\gamma}$")
axes[1].set_ylabel(r"First normal-stress coeff. $\Psi_1$")
axes[1].set_title(r"First normal stress coefficient")
axes[1].legend(fontsize=8.5)
log_ticks(axes[0], "x", [0.4, 1, 2, 4, 7])
log_ticks(axes[0], "y", [0.4, 0.6, 0.8, 1.0])
log_ticks(axes[1], "x", [0.4, 1, 2, 4, 7])
log_ticks(axes[1], "y", [0.3, 0.5, 1, 2])
label_panels(fig)
plt.show()
Demonstration 3: viscosity and first normal stress coefficient against shear rate
=================================================================================
FENE (b=20) viscosity drops from 0.753 (Wi=0.4) to 0.410 (Wi=7.0)
FENE (b=60) viscosity drops from 0.874 (Wi=0.4) to 0.541 (Wi=7.0)

Figure 3.3. Steady shear of FENE dumbbells from Brownian dynamics. (a) Polymer viscosity for and 60. (b) First normal stress coefficient for . The dotted lines are the Hookean values.
4. Uniaxial extension: Hookean, FENE and wormlike-chain springs¶
In Lecture 1 the stress of the Oldroyd-B model diverged in uniaxial extension at . The demonstration follows the molecules above this value, at with . The extension of Hookean dumbbells grows exponentially without limit. FENE and wormlike-chain dumbbells reach a steady extension with .
heading("Demonstration 4: uniaxial extension at Wi_ext = 1.0")
L_ext_1 = np.diag([1.0, -0.5, -0.5])
t_ext_bd = np.linspace(0.0, 5.0, 61)
bd_ext_hook = brownian_chains.simulate_dumbbell_bd(lambda _t: L_ext_1, t_ext_bd, model="hookean", b_ext=30.0, n_trajectories=650, control_variate=False, seed=19)
bd_ext_fene = brownian_chains.simulate_dumbbell_bd(lambda _t: L_ext_1, t_ext_bd, model="fene", b_ext=30.0, n_trajectories=650, control_variate=False, seed=19)
bd_ext_wlc = brownian_chains.simulate_dumbbell_bd(lambda _t: L_ext_1, t_ext_bd, model="wlc", b_ext=30.0, n_trajectories=650, control_variate=False, seed=19)
print("At t=5.0 (Wi_ext=1.0, b=30):")
print(f" Hookean <Q^2> = {bd_ext_hook['mean_Q2'][-1]:.1f} (diverges exponentially >> b=30)")
print(f" FENE <Q^2> = {bd_ext_fene['mean_Q2'][-1]:.2f} (< 30.0, steady stretched plateau)")
print(f" WLC <Q^2> = {bd_ext_wlc['mean_Q2'][-1]:.2f} (< FENE due to stiffer (1 - Q/sqrt(b))^-2 force)")
assert bd_ext_hook["mean_Q2"][-1] > 40.0
assert 8.0 < bd_ext_fene["mean_Q2"][-1] < 30.0
assert 4.0 < bd_ext_wlc["mean_Q2"][-1] < bd_ext_fene["mean_Q2"][-1]
fig, axes = plt.subplots(1, 2, figsize=(10.5, 3.8))
axes[0].semilogy(t_ext_bd, bd_ext_hook["mean_Q2"], "--", color="gray", lw=2.0, label="Hookean (unbounded)")
axes[0].semilogy(t_ext_bd, bd_ext_fene["mean_Q2"], "-", color="#2166AC", lw=2.1, label="FENE ($b=30$)")
axes[0].semilogy(t_ext_bd, bd_ext_wlc["mean_Q2"], "-", color="#C0392B", lw=2.1, label="Wormlike chain ($b=30$)")
axes[0].axhline(30.0, color="k", ls=":", label="Limit $b = 30$")
axes[0].set_xlabel(r"Dimensionless time $t / \lambda_H$")
axes[0].set_ylabel(r"Mean-square extension $\langle Q^2 \rangle(t)$")
axes[0].set_title(r"Mean-square extension at $\mathrm{Wi}_{\mathrm{ext}} = 1$")
axes[0].legend(fontsize=8)
# Weak dt convergence check on FENE <Q^2>(t=1.2):
dt_weak = np.array([0.24, 0.12, 0.06, 0.03])
q2_ref = brownian_chains.simulate_dumbbell_bd(lambda _t: L_ext_1, np.linspace(0.0, 1.2, 121), model="fene", b_ext=30.0, n_trajectories=2200, control_variate=False, seed=55)["mean_Q2"][-1]
weak_errs = []
for dtw in dt_weak:
tw = np.linspace(0.0, 1.2, int(round(1.2 / dtw)) + 1)
val = brownian_chains.simulate_dumbbell_bd(lambda _t: L_ext_1, tw, model="fene", b_ext=30.0, n_trajectories=2200, control_variate=False, seed=55)["mean_Q2"][-1]
weak_errs.append(abs(val - q2_ref))
axes[1].loglog(dt_weak, weak_errs, "-o", color="#2E8B57", lw=2.0, ms=5.5, label=r"$|\langle Q^2\rangle_{\Delta t} - \langle Q^2\rangle_{\mathrm{ref}}|$")
axes[1].loglog(dt_weak, weak_errs[0] * (dt_weak / dt_weak[0]), "k--", lw=1.6, label=r"Weak $\mathcal{O}(\Delta t)$ reference")
axes[1].set_xlabel(r"Time step $\Delta t / \lambda_H$")
axes[1].set_ylabel(r"Weak observable error at $t = 1.5$")
axes[1].set_title(r"Error against the time step")
axes[1].legend(fontsize=8.5)
log_ticks(axes[1], "x", [0.03, 0.06, 0.12, 0.25])
label_panels(fig)
plt.show()
Demonstration 4: uniaxial extension at Wi_ext = 1.0
===================================================
At t=5.0 (Wi_ext=1.0, b=30):
Hookean <Q^2> = 311.4 (diverges exponentially >> b=30)
FENE <Q^2> = 11.51 (< 30.0, steady stretched plateau)
WLC <Q^2> = 11.11 (< FENE due to stiffer (1 - Q/sqrt(b))^-2 force)

Figure 3.4. (a) Uniaxial extension above the coil–stretch transition: the Hookean dumbbells extend without bound, the FENE and wormlike-chain dumbbells () reach a plateau below . (b) Error of at against the time step; with this ensemble the statistical error hides the first-order trend (dashed).
Inside the algorithm¶
The cell below prints the source of brownian_chains.solve_fene_cubic_radial. The substitution reduces to with , which is negative for all . The cubic then has three real roots, . The function takes the middle root from the trigonometric formula for the roots of a cubic and improves it with one Newton step.
Check against the package¶
The check below computes the three roots of with np.roots for random values of , and verifies that exactly one of them lies in and that it agrees with solve_fene_cubic_radial to 10-13.
heading("Inside the algorithm: the root of the cubic equation against np.roots")
print(show_source(brownian_chains.solve_fene_cubic_radial))
rng_cub = np.random.default_rng(303)
Y_rand = rng_cub.uniform(0.01, 120.0, size=25)
b_rand = 36.0
alpha_rand = 0.18
R_vec = brownian_chains.solve_fene_cubic_radial(Y_rand, b_ext=b_rand, coeff_alpha=alpha_rand)
max_root_diff = 0.0
for idx, yv in enumerate(Y_rand):
coeffs = [1.0, -yv, -b_rand * (1.0 + alpha_rand), b_rand * yv]
roots_all = np.sort(np.real_if_close(np.roots(coeffs)))
# Verify exact root separation R_1 < 0 < R_2 < sqrt(b) < R_3:
assert roots_all[0] < 0.0 < roots_all[1] < math.sqrt(b_rand) < roots_all[2]
max_root_diff = max(max_root_diff, abs(float(roots_all[1]) - float(R_vec[idx])))
print("Verified root ordering R_1 < 0 < R_2 < sqrt(b) < R_3 across all 25 test cases.")
print(f"Max |R_viete_newton - np.roots middle root|: {max_root_diff:.3e}")
assert max_root_diff < 1e-13
Inside the algorithm: the root of the cubic equation against np.roots
=====================================================================
def solve_fene_cubic_radial(y_rhs_norm: np.ndarray, b_ext: float, coeff_alpha: float) -> np.ndarray:
"""Solve R * (1 + coeff_alpha / (1 - R^2 / b_ext)) = Y in closed form for the one root R in [0, sqrt(b_ext))."""
Y = np.asarray(y_rhs_norm, dtype=float)
if b_ext <= 0.0 or coeff_alpha <= 0.0 or np.any(Y < 0.0):
raise ValueError("Require b_ext > 0, coeff_alpha > 0, and non-negative radial norm Y >= 0.")
# Cubic R^3 - Y R^2 - b*(1 + alpha)*R + b*Y = 0; depress via R = x + Y/3 -> x^3 + p*x + q = 0:
b = float(b_ext)
a1 = -Y
a2 = -b * (1.0 + float(coeff_alpha))
a3 = b * Y
p = a2 - (a1**2) / 3.0
q = (2.0 * (a1**3)) / 27.0 - (a1 * a2) / 3.0 + a3
# Since 3 distinct real roots (-inf, 0), [0, sqrt(b)), (sqrt(b), +inf) always exist, p < 0 strictly:
r_trig = np.sqrt(np.maximum(-p / 3.0, 1e-30))
cos_arg = np.clip(-q / (2.0 * (r_trig**3)), -1.0, 1.0)
phi = np.arccos(cos_arg)
# Middle root k = 2 lies strictly in [0, sqrt(b)); polish once with exact Newton step for < 1e-14 residual:
r_est = 2.0 * r_trig * np.cos((phi - 2.0 * math.pi) / 3.0) - a1 / 3.0
r_est = np.where(Y == 0.0, 0.0, np.clip(r_est, 0.0, math.sqrt(b) * (1.0 - 1e-11)))
denom = np.maximum(1.0 - (r_est**2) / b, 1e-15)
f_val = r_est * (1.0 + float(coeff_alpha) / denom) - Y
df_dr = 1.0 + float(coeff_alpha) * (1.0 + (r_est**2) / b) / (denom**2)
r_refined = np.where(Y == 0.0, 0.0, r_est - f_val / df_dr)
return np.clip(r_refined, 0.0, math.sqrt(b) * (1.0 - 1e-14))
Verified root ordering R_1 < 0 < R_2 < sqrt(b) < R_3 across all 25 test cases.
Max |R_viete_newton - np.roots middle root|: 2.665e-15
Exercises¶
Worked solutions are in 03_solutions.ipynb. The cell below the list is a short self-check to start from.
Verify a result. Check by numerical quadrature, for between 6 and 200, that the equilibrium distribution of a FENE dumbbell gives , and compare with a Brownian dynamics simulation without flow (
simulate_dumbbell_bdwith ).Find how it fails. Run the explicit Euler–Maruyama scheme (
explicit_unsafe=True) and the semi-implicit scheme (explicit_unsafe=False) for and withb_ext = 25,n_trajectories = 500andt_end = 1.8, and count the events in which a connector reaches or exceeds its maximum length, .Implement it yourself. Write a vectorized semi-implicit Brownian dynamics solver for FENE dumbbells in NumPy (, , 3000 trajectories, ), and compare , and with
brownian_chains.simulate_dumbbell_bd; the two should agree within 3 %.
heading("Self-check for the exercises")
atlas_03 = [entry for entry in constants_benchmarks.RHEO_ATLAS_DB if entry["lecture"] == "03"]
assert len(atlas_03) == 1
assert bd_safe_8["overstretched_count"] == 0 and bd_unsafe_8["overstretched_count"] > 0
assert max_root_diff < 1e-13
print("All checks passed.")
Self-check for the exercises
============================
All checks passed.