The simulations of Part II resolve the distribution of molecular extensions, but they are too expensive to run in every cell of a flow calculation, where one would prefer to transport a single tensor . For the FENE spring no closed equation for exists: the nonlinear force couples the second moment of the extension to all higher moments. A closure approximation replaces the average of the force by the force at the average extension, . This gives the FENE-P model (the approximation of Peterlin) and its variant FENE-CR (Chilcott and Rallison), which has a constant shear viscosity.
This lecture derives both models and compares FENE-P with the Brownian dynamics simulation that it approximates; in start-up of shear the closure overestimates the peak of the stress (Keunings, 1997). It then adds a drag that depends on the conformation, which leads to the coil–stretch hysteresis predicted by de Gennes (1974).
Learning objectives¶
Derive the function , with , and compare the FENE-P and FENE-CR models in shear (
entangled_tubes.solve_fenep_fenecr).Check the cubic equation of steady shear for FENE-P, and the constant shear viscosity of FENE-CR.
Measure the error of the closure in start-up of shear against a Brownian dynamics simulation of FENE dumbbells (
brownian_chains.simulate_dumbbell_bd).Compute the coil–stretch hysteresis in planar extension with a conformation-dependent drag (
entangled_tubes.fenep_planar_extension_hysteresis).
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. Closure approximations: FENE-P and FENE-CR¶
The equation for the second moment of the connector of a FENE dumbbell contains the average , which is not a function of the second moment. This lecture uses the normalization in which the conformation tensor at equilibrium is , so that . The approximation of Peterlin replaces in the denominator of the spring force by its average, which is proportional to , with a factor chosen so that :
Two models follow, depending on whether the term of the relaxation is also multiplied by :
| Model | Evolution equation | Polymer stress | Shear viscosity |
|---|---|---|---|
| FENE-P (Peterlin, 1966; Bird et al., 1980) | decreases: at high | ||
| FENE-CR (Chilcott and Rallison, 1988) | constant: |
In steady simple shear (, ) the components of can be eliminated from the FENE-P equations, which leaves a cubic equation for the steady value of :
heading("Demonstration 1: steady shear of the FENE-P and FENE-CR models")
b_demo1 = 50.0
lam_d1, eta_p_d1 = 1.0, 1.0
wi_sweep = np.geomspace(0.25, 14.0, 9)
eta_fp, eta_fcr, eta_fp_exact = [], [], []
n1_fp, n1_fcr = [], []
for wi_val in wi_sweep:
t_end = max(10.0, 18.0 / min(1.0, wi_val))
t_g = np.linspace(0.0, t_end, 220)
L_sh = lambda _t, g=wi_val: np.array([[0.0, g, 0.0], [0.0, 0.0, 0.0], [0.0, 0.0, 0.0]])
sol_p = entangled_tubes.solve_fenep_fenecr(L_sh, t_g, lam=lam_d1, eta_p=eta_p_d1, b_ext=b_demo1, variant="fenep")
sol_cr = entangled_tubes.solve_fenep_fenecr(L_sh, t_g, lam=lam_d1, eta_p=eta_p_d1, b_ext=b_demo1, variant="fenecr")
eta_fp.append(float(sol_p["tau_p"][-1, 0, 1] / wi_val))
eta_fcr.append(float(sol_cr["tau_p"][-1, 0, 1] / wi_val))
n1_fp.append(float(sol_p["tau_p"][-1, 0, 0] - sol_p["tau_p"][-1, 1, 1]))
n1_fcr.append(float(sol_cr["tau_p"][-1, 0, 0] - sol_cr["tau_p"][-1, 1, 1]))
# Exact real root >= 1 of f^3 - f^2 - 2*Wi^2/b = 0:
roots = np.roots([1.0, -1.0, 0.0, -2.0 * (wi_val**2) / b_demo1])
f_real = float(np.max(roots[np.isclose(roots.imag, 0.0)].real))
eta_fp_exact.append(eta_p_d1 / f_real)
eta_fp = np.array(eta_fp)
eta_fcr = np.array(eta_fcr)
eta_fp_exact = np.array(eta_fp_exact)
print(f"{'Wi':>6s} | {'eta_p (FENE-P)':>15s} | {'Exact Cubic':>12s} | {'eta_p (FENE-CR)':>16s} | {'N1 (FENE-P)':>12s}")
print("-" * 72)
for w, ep, ex, ecr, n1v in zip(wi_sweep, eta_fp, eta_fp_exact, eta_fcr, n1_fp):
print(f"{w:6.2f} | {ep:15.5f} | {ex:12.5f} | {ecr:16.5f} | {n1v:12.4f}")
assert np.allclose(eta_fcr, eta_p_d1, rtol=2e-3, atol=2e-3)
assert np.allclose(eta_fp, eta_fp_exact, rtol=4e-3, atol=4e-3)
assert eta_fp[-1] < 0.45 * eta_p_d1
fig, axes = plt.subplots(1, 2, figsize=(10.2, 4.0))
axes[0].semilogx(wi_sweep, eta_fcr, "s-", color="#2166AC", lw=2.0, label="FENE-CR (constant $\\eta_p$)")
axes[0].semilogx(wi_sweep, eta_fp, "o-", color="#C0392B", lw=2.0, label="FENE-P (log-$\\mathbf{C}$ RK2)")
axes[0].semilogx(wi_sweep, eta_fp_exact, "k--", lw=1.5, label="Exact cubic $f^3 - f^2 = 2\\mathrm{Wi}^2/b$")
axes[0].set_xlabel(r"Weissenberg number $\mathrm{Wi} = \lambda\dot{\gamma}$")
axes[0].set_ylabel(r"Normalized polymer viscosity $\eta_p / \eta_{p,0}$")
axes[0].set_title(r"Polymer viscosity ($b = 50$)")
axes[0].legend(fontsize=8)
axes[1].loglog(wi_sweep, n1_fcr, "s-", color="#2166AC", lw=2.0, label="FENE-CR $N_1$")
axes[1].loglog(wi_sweep, n1_fp, "o-", color="#C0392B", lw=2.0, label="FENE-P $N_1$")
axes[1].set_xlabel(r"Weissenberg number $\mathrm{Wi} = \lambda\dot{\gamma}$")
axes[1].set_ylabel(r"First normal stress difference $N_1 / G_0$")
axes[1].set_title(r"First normal stress difference")
axes[1].legend(fontsize=8)
label_panels(fig)
plt.show()
Demonstration 1: steady shear of the FENE-P and FENE-CR models
==============================================================
Wi | eta_p (FENE-P) | Exact Cubic | eta_p (FENE-CR) | N1 (FENE-P)
------------------------------------------------------------------------
0.25 | 0.99752 | 0.99752 | 1.00000 | 0.1244
0.41 | 0.99330 | 0.99330 | 1.00000 | 0.3374
0.68 | 0.98227 | 0.98227 | 1.00000 | 0.9025
1.13 | 0.95537 | 0.95537 | 1.00000 | 2.3356
1.87 | 0.89846 | 0.89846 | 1.00000 | 5.6506
3.09 | 0.80225 | 0.80225 | 1.00000 | 12.3245
5.12 | 0.67615 | 0.67615 | 1.00000 | 23.9483
8.46 | 0.54248 | 0.54248 | 1.00000 | 42.1698
14.00 | 0.41983 | 0.41983 | 1.00000 | 69.0944

Figure 6.1. Steady shear. (a) Polymer viscosity: constant for FENE-CR, shear thinning for FENE-P, where the integration agrees with the root of the cubic . (b) First normal stress difference of the two models.
What Demonstration 1 shows. The FENE-CR model multiplies both relaxation terms by , so that in simple shear and the shear viscosity is constant, , as in a Boger fluid. The FENE-P model follows the cubic equation to within 0.2 %.
2. The error of the closure: FENE-P against Brownian dynamics¶
The FENE-P model does not reproduce the Brownian dynamics simulation in all flows. In a fast start-up () the dumbbells of the simulation have a broad distribution of lengths . Those that stretch first reach the steep part of the spring force, , and resist further stretching while the others are still short. In the FENE-P model every dumbbell has the stiffness of the average extension, . The model is therefore too soft early in the start-up, until approaches , and its stress then overshoots that of the simulation (Keunings, 1997; Herrchen and Öttinger, 1997).
heading("Demonstration 2: start-up of shear: FENE-P against Brownian dynamics of FENE dumbbells")
b_d2 = 50.0
wi_d2 = 6.0
t_d2 = np.linspace(0.0, 5.0, 201)
L_startup = lambda _t: np.array([[0.0, wi_d2, 0.0], [0.0, 0.0, 0.0], [0.0, 0.0, 0.0]])
# Match exact zero-shear FENE dumbbell viscosity eta_p0 = b / (b + 5) in dimensionless BD units:
eta_match = b_d2 / (b_d2 + 5.0)
fp_start = entangled_tubes.solve_fenep_fenecr(
L_startup, t_d2, lam=1.0, eta_p=eta_match, b_ext=b_d2, variant="fenep"
)
bd_start = brownian_chains.simulate_dumbbell_bd(
L_startup, t_d2, model="fene", b_ext=b_d2, n_trajectories=1800, control_variate=True, seed=42
)
txy_fp_t = fp_start["tau_p"][:, 0, 1]
txy_bd_t = bd_start["tau_xy"]
peak_fp = float(np.max(txy_fp_t))
peak_bd = float(np.max(txy_bd_t))
steady_fp = float(txy_fp_t[-1])
steady_bd = float(np.mean(txy_bd_t[-25:]))
overshoot_excess_pct = 100.0 * (peak_fp - peak_bd) / peak_bd
print(f"Peak transient shear stress : FENE-P = {peak_fp:.4f} against FENE Brownian dynamics = {peak_bd:.4f} (+{overshoot_excess_pct:.1f}% closure overshoot)")
print(f"Steady-state shear stress : FENE-P = {steady_fp:.4f} against FENE Brownian dynamics = {steady_bd:.4f}")
print(f"FENE BD overstretched springs: {bd_start['overstretched_count']} (strictly < sqrt(b) = {math.sqrt(b_d2):.2f})")
assert bd_start["overstretched_count"] == 0
assert peak_fp > 1.07 * peak_bd
assert abs(steady_fp - steady_bd) / steady_bd < 0.05
fig, axes = plt.subplots(1, 2, figsize=(10.2, 4.0))
axes[0].plot(t_d2, txy_fp_t, color="#C0392B", lw=2.2, label="Pre-averaged FENE-P closure")
axes[0].plot(t_d2, txy_bd_t, color="#2166AC", lw=1.9, label="FENE Brownian dynamics ($N=1800$, CV)")
axes[0].fill_between(
t_d2,
txy_bd_t - 1.96 * bd_start["std_err_tau_xy"],
txy_bd_t + 1.96 * bd_start["std_err_tau_xy"],
color="#2166AC",
alpha=0.20,
label="BD 95% CI",
)
axes[0].set_xlabel(r"Dimensionless time $t / \lambda$")
axes[0].set_ylabel(r"Shear stress $\tau_{xy} / (n k_B T)$")
axes[0].set_title(r"Shear stress in start-up ($\mathrm{Wi} = 6$, $b = 50$)")
axes[0].legend(fontsize=8)
axes[1].plot(t_d2, fp_start["trace_C"] * (b_d2 / (b_d2 + 5.0)), color="#C0392B", lw=2.2, label=r"FENE-P scaled $\operatorname{tr}\mathbf{C}$")
axes[1].plot(t_d2, bd_start["mean_Q2"], color="#2166AC", lw=1.9, label=r"FENE Brownian dynamics $\langle Q^2\rangle$")
axes[1].axhline(b_d2, color="black", ls=":", lw=1.2, label=f"Limit $b = {b_d2:.0f}$")
axes[1].set_xlabel(r"Dimensionless time $t / \lambda$")
axes[1].set_ylabel(r"Mean-square extension $\langle Q^2\rangle$")
axes[1].set_title(r"Mean-square extension")
axes[1].legend(fontsize=8)
label_panels(fig)
plt.show()
Demonstration 2: start-up of shear: FENE-P against Brownian dynamics of FENE dumbbells
======================================================================================
Peak transient shear stress : FENE-P = 4.7060 against FENE Brownian dynamics = 4.2993 (+9.5% closure overshoot)
Steady-state shear stress : FENE-P = 3.4528 against FENE Brownian dynamics = 3.4140
FENE BD overstretched springs: 0 (strictly < sqrt(b) = 7.07)

Figure 6.2. Start-up of shear: the FENE-P closure against Brownian dynamics of FENE dumbbells (1800 trajectories, with control variate and 95 % interval). (a) The closure overshoots the peak stress by 9.5 % and agrees at steady state. (b) Mean-square extension.
What Demonstration 2 shows. With the zero-shear viscosity matched, , the FENE-P model overestimates the peak of the shear stress in start-up by about 10 %, and its steady value is within 2 % of that of the simulation.
3. Coil–stretch hysteresis with a conformation-dependent drag¶
In planar extension, , the FENE-P model with a constant friction coefficient passes smoothly and reversibly from the coiled to the stretched state near . Experiments on single DNA molecules (Schroeder, Babcock, Shaqfeh and Chu, 2003) showed hysteresis instead: over a range of a molecule can be either coiled or stretched, depending on its history.
De Gennes (1974) had predicted this. In a coil the outer segments shield the inner ones from the flow, and the drag is small. A stretched molecule exposes its whole length, and the drag is larger, for the fractional extension . The balance between the stretching by the flow and the spring force divided by this drag is
The steady states are . For this function is not monotonic, so that two stable states exist over a range of and a cycle of increasing and decreasing rate encloses a loop.
heading("Demonstration 3: coil-stretch hysteresis with a conformation-dependent drag")
wi_ext_grid = np.linspace(0.14, 0.72, 32)
b_d3 = 120.0
hys_drag = entangled_tubes.fenep_planar_extension_hysteresis(
wi_ext_grid, b_ext=b_d3, include_conformation_dependent_drag=True
)
hys_const = entangled_tubes.fenep_planar_extension_hysteresis(
wi_ext_grid, b_ext=b_d3, include_conformation_dependent_drag=False
)
max_gap_drag = float(np.max(hys_drag["trC_down"] - hys_drag["trC_up"]))
max_gap_const = float(np.max(np.abs(hys_const["trC_down"] - hys_const["trC_up"])))
print(f"Conformation-dependent drag ON : loop area = {hys_drag['hysteresis_area']:7.3f}, max branch gap = {max_gap_drag:6.2f}")
print(f"Constant bead friction (OFF) : loop area = {hys_const['hysteresis_area']:7.3f}, max branch gap = {max_gap_const:6.2f}")
assert hys_drag["hysteresis_area"] > 15.0
assert hys_const["hysteresis_area"] < 0.5
assert max_gap_drag > 0.65 * b_d3
fig, axes = plt.subplots(1, 2, figsize=(10.2, 4.0))
axes[0].plot(hys_drag["wi"], hys_drag["trC_up"] / b_d3, "o-", color="#2166AC", ms=4, lw=2.0, label="Up-sweep (coil $\\to$ stretch)")
axes[0].plot(hys_drag["wi"], hys_drag["trC_down"] / b_d3, "s--", color="#C0392B", ms=4, lw=2.0, label="Down-sweep (stretch $\\to$ coil)")
axes[0].fill_between(
hys_drag["wi"], hys_drag["trC_up"] / b_d3, hys_drag["trC_down"] / b_d3, color="#F2B8AE", alpha=0.35, label="Range with two stable states"
)
axes[0].axvline(0.5, color="gray", ls=":", lw=1.2, label=r"Coil$\to$stretch $\mathrm{Wi}_c = 0.5$")
axes[0].set_xlabel(r"Extensional Weissenberg number $\mathrm{Wi}_{\mathrm{ext}} = \lambda_0\dot{\varepsilon}$")
axes[0].set_ylabel(r"Fractional square stretch $\operatorname{tr}\mathbf{C} / b$")
axes[0].set_title(r"Drag that grows with extension")
axes[0].legend(fontsize=8, loc="upper center", bbox_to_anchor=(0.5, -0.17), ncol=2)
axes[1].plot(hys_const["wi"], hys_const["trC_up"] / b_d3, "o-", color="#2E8B57", ms=4, lw=2.0, label="Up-sweep (constant drag)")
axes[1].plot(hys_const["wi"], hys_const["trC_down"] / b_d3, "k--", lw=1.5, label="Down-sweep (constant drag)")
axes[1].axvline(0.5, color="gray", ls=":", lw=1.2)
axes[1].set_xlabel(r"Extensional Weissenberg number $\mathrm{Wi}_{\mathrm{ext}} = \lambda_0\dot{\varepsilon}$")
axes[1].set_ylabel(r"Fractional square stretch $\operatorname{tr}\mathbf{C} / b$")
axes[1].set_title(r"Constant drag")
axes[1].legend(fontsize=8)
label_panels(fig)
plt.show()
Demonstration 3: coil-stretch hysteresis with a conformation-dependent drag
===========================================================================
Conformation-dependent drag ON : loop area = 20.162, max branch gap = 94.27
Constant bead friction (OFF) : loop area = 0.185, max branch gap = 5.89

Figure 6.3. Steady planar extension of the FENE-P model () swept up and down in rate. (a) With the drag the two sweeps differ over a range of rates (shaded). (b) With constant drag the two sweeps nearly coincide.
What Demonstration 3 shows. With the conformation-dependent drag, a stretched molecule stays on the upper branch down to , well below the value at which a coil stretches, because the drag on the stretched molecule is larger by the factor .
4. Uniaxial extension: the effect of the extensibility ¶
In Lecture 1 the stress of the Oldroyd-B model diverged in uniaxial extension () for every . The demonstration computes start-up at for , 50 and 120, and shows that sets the plateau of the Trouton ratio, :
heading("Demonstration 4: start-up of uniaxial extension for several values of b")
wi_uni = 2.0
t_uni = np.linspace(0.0, 3.2, 220)
L_uni_fn = lambda _t: np.diag([wi_uni, -0.5 * wi_uni, -0.5 * wi_uni])
b_values = [20.0, 50.0, 120.0]
colors_b = ["#2166AC", "#E08214", "#C0392B"]
fig, axes = plt.subplots(1, 2, figsize=(10.2, 4.0))
trouton_meas, trouton_asymp = [], []
for b_val, col in zip(b_values, colors_b):
sol_u = entangled_tubes.solve_fenep_fenecr(L_uni_fn, t_uni, lam=1.0, eta_p=1.0, b_ext=b_val, variant="fenep")
eta_e_t = (sol_u["tau_p"][:, 0, 0] - sol_u["tau_p"][:, 1, 1]) / wi_uni
tr_max = float(np.max(sol_u["trace_C"]))
tr_plat = float(eta_e_t[-1])
# Exact high-Wi uniaxial balance: f * C_xx ~ 2 * Wi * C_xx -> f ~ 2*Wi, tr_C ~ b*(1 - (b-3)/(2*b*Wi))
f_exact_uni = 2.0 * wi_uni
c_xx_approx = b_val - (b_val - 3.0) / f_exact_uni
tr_theory = float(f_exact_uni * c_xx_approx / wi_uni)
trouton_meas.append(tr_plat)
trouton_asymp.append(2.0 * (b_val - 3.0))
print(f"b = {b_val:5.1f} | max(tr C) = {tr_max:6.2f} < b | Trouton eta_E/eta_p0 = {tr_plat:7.2f} (2*(b-3) ceiling = {2.0*(b_val-3.0):6.1f})")
assert tr_max < b_val
assert abs(tr_plat - tr_theory) / tr_theory < 0.08
axes[0].semilogy(t_uni, np.maximum(eta_e_t, 1e-2), lw=2.1, color=col, label=f"$b = {b_val:.0f}$ ($\\eta_E/\\eta_{{p,0}} \\to {tr_plat:.0f}$)")
axes[1].plot(t_uni, sol_u["trace_C"] / b_val, lw=2.1, color=col, label=f"$b = {b_val:.0f}$")
assert trouton_meas[0] < trouton_meas[1] < trouton_meas[2]
axes[0].axhline(3.0, color="black", ls=":", lw=1.2, label="Newtonian Trouton limit $3$")
axes[0].set_xlabel(r"Dimensionless time $t / \lambda$")
axes[0].set_ylabel(r"Transient extensional viscosity $\eta_E^+(t) / \eta_{p,0}$")
axes[0].set_title(r"Extensional viscosity at $\mathrm{Wi}_{\mathrm{ext}} = 2$")
axes[0].legend(fontsize=8)
axes[1].axhline(1.0, color="black", ls="--", lw=1.2, label=r"Finite extensibility bound $\operatorname{tr}\mathbf{C}/b = 1$")
axes[1].set_xlabel(r"Dimensionless time $t / \lambda$")
axes[1].set_ylabel(r"Normalized trace $\operatorname{tr}\mathbf{C}(t) / b$")
axes[1].set_title(r"Trace of $\mathbf{C}$ divided by $b$")
axes[1].legend(fontsize=8)
label_panels(fig)
plt.show()
Demonstration 4: start-up of uniaxial extension for several values of b
=======================================================================
b = 20.0 | max(tr C) = 15.82 < b | Trouton eta_E/eta_p0 = 31.14 (2*(b-3) ceiling = 34.0)
b = 50.0 | max(tr C) = 38.33 < b | Trouton eta_E/eta_p0 = 76.16 (2*(b-3) ceiling = 94.0)
b = 120.0 | max(tr C) = 90.83 < b | Trouton eta_E/eta_p0 = 181.16 (2*(b-3) ceiling = 234.0)

Figure 6.4. Start-up of uniaxial extension of the FENE-P model for three values of . (a) Transient extensional viscosity divided by ; the dotted line is the Newtonian value 3. (b) , which stays below 1.
Inside the algorithm¶
The function entangled_tubes.solve_fenep_fenecr keeps positive definite and at high because it evolves with the decomposition of Lecture 2 (tensors_kinematics.log_conformation_decompose). Both relaxation terms, and , are isotropic functions of and commute with it. Their contribution to the equation for is therefore , which in the principal axes is a division of each diagonal entry by the eigenvalue.
Check against the package¶
The cell below prints the source of entangled_tubes.solve_fenep_fenecr, repeats its midpoint step of the log-conformation equation in NumPy, and checks that the two agree to rounding error (< 1e-13) in a flow that combines shear and planar extension.
heading("Inside the algorithm: a log-conformation solver for FENE-P and FENE-CR")
print(show_source(entangled_tubes.solve_fenep_fenecr))
def numpy_fenep_log_rk2(L_mat: np.ndarray, t_grid: np.ndarray, lam: float, eta_p: float, b_ext: float) -> np.ndarray:
"""This solver, NumPy log-conformation RK2 integrator for 3-D FENE-P."""
G0 = eta_p / lam
I3 = np.eye(3)
Psi = np.zeros((3, 3))
tau_out = np.zeros((t_grid.size, 3, 3))
def rhs(P: np.ndarray) -> np.ndarray:
ev_p, V_p = np.linalg.eigh(0.5 * (P + P.T))
C_m = (V_p * np.exp(ev_p)[None, :]) @ V_p.T
dec = tensors_kinematics.log_conformation_decompose(C_m, L_mat)
fp = (b_ext - 3.0) / (b_ext - float(np.trace(C_m)))
rel_c = -(fp * C_m - I3) / lam
R = dec["eigenvectors"]
ev = dec["eigenvalues"]
rel_psi = R @ ((1.0 / ev)[:, None] * (R.T @ rel_c @ R)) @ R.T
res = dec["dPsi_dt_kinematic"] + 0.5 * (rel_psi + rel_psi.T)
return 0.5 * (res + res.T)
for k in range(t_grid.size - 1):
dt = float(t_grid[k + 1] - t_grid[k])
k1 = rhs(Psi)
k2 = rhs(Psi + 0.5 * dt * k1)
Psi = Psi + dt * k2
ev_n, V_n = np.linalg.eigh(0.5 * (Psi + Psi.T))
C_n = (V_n * np.exp(ev_n)[None, :]) @ V_n.T
fp_n = (b_ext - 3.0) / (b_ext - float(np.trace(C_n)))
tau_out[k + 1] = G0 * (fp_n * C_n - I3)
return tau_out
L_mix = np.array([[0.8, 3.5, 0.0], [0.0, -0.8, 0.0], [0.0, 0.0, 0.0]])
t_in = np.linspace(0.0, 2.0, 101)
tau_hand = numpy_fenep_log_rk2(L_mix, t_in, lam=0.8, eta_p=1.6, b_ext=45.0)
tau_lib = entangled_tubes.solve_fenep_fenecr(lambda _t: L_mix, t_in, lam=0.8, eta_p=1.6, b_ext=45.0, variant="fenep")["tau_p"]
max_diff = float(np.max(np.abs(tau_hand - tau_lib)))
print(f"Max |NumPy - solve_fenep_fenecr| across all tensor components = {max_diff:.3e}")
assert np.allclose(tau_hand, tau_lib, rtol=1e-13, atol=1e-13)
Inside the algorithm: a log-conformation solver for FENE-P and FENE-CR
======================================================================
def solve_fenep_fenecr(
L_fn: Callable[[float], np.ndarray],
t_grid: np.ndarray,
lam: float = 1.0,
eta_p: float = 1.0,
b_ext: float = 50.0,
variant: str = "fenep",
) -> dict:
"""Integrate the FENE-P or the FENE-CR model in three dimensions in the log-conformation form."""
t = np.asarray(t_grid, dtype=float).ravel()
if t.size < 2 or np.any(np.diff(t) <= 0.0) or lam <= 0.0 or eta_p <= 0.0 or b_ext <= 3.0:
raise ValueError("Require increasing t_grid, lam > 0, eta_p > 0, and b_ext > 3.")
if variant not in ("fenep", "fenecr"):
raise ValueError("variant must be 'fenep' or 'fenecr'.")
# Equilibrium <tr C>_eq = 3 * b / (b + 5) in convention where F = f(C)*Q and tau_p = G0*(f(C)*C - I):
# Use standard Bird convention where C_eq = I and f(C) = (b - 3) / (b - tr(C)) so f(I) == 1
b = float(b_ext)
G0 = float(eta_p / lam)
I3 = np.eye(3, dtype=float)
def _f_peterlin(C_m: np.ndarray) -> float:
tr_c = float(np.trace(C_m))
return (b - 3.0) / max(1e-9, b - tr_c)
def _stress(C_m: np.ndarray) -> np.ndarray:
fp = _f_peterlin(C_m)
if variant == "fenep":
return G0 * (fp * C_m - I3)
return G0 * fp * (C_m - I3)
def _rhs_psi(Psi_cur: np.ndarray, tk: float) -> np.ndarray:
C_cur = exp_conformation(Psi_cur)
L_cur = np.asarray(L_fn(tk), dtype=float)
dec = log_conformation_decompose(C_cur, L_cur)
fp = _f_peterlin(C_cur)
rel_C = -(fp * C_cur - I3) / lam if variant == "fenep" else -fp * (C_cur - I3) / lam
ev = dec["eigenvalues"]
R = dec["eigenvectors"]
rel_psi = R @ ((1.0 / ev)[:, None] * (R.T @ rel_C @ R)) @ R.T
out = dec["dPsi_dt_kinematic"] + 0.5 * (rel_psi + rel_psi.T)
return 0.5 * (out + out.T)
Psi = np.zeros((3, 3), dtype=float)
C_hist = np.zeros((t.size, 3, 3), dtype=float)
tau_hist = np.zeros((t.size, 3, 3), dtype=float)
f_hist = np.ones(t.size, dtype=float)
C_hist[0] = I3
for k in range(t.size - 1):
dt = float(t[k + 1] - t[k])
tk = float(t[k])
k1 = _rhs_psi(Psi, tk)
k2 = _rhs_psi(Psi + 0.5 * dt * k1, tk + 0.5 * dt)
Psi = Psi + dt * k2
C_cur = exp_conformation(Psi)
C_hist[k + 1] = C_cur
tau_hist[k + 1] = _stress(C_cur)
f_hist[k + 1] = _f_peterlin(C_cur)
return {
"t": t,
"C": C_hist,
"tau_p": tau_hist,
"trace_C": np.trace(C_hist, axis1=1, axis2=2),
"peterlin_f": f_hist,
}
Max |NumPy - solve_fenep_fenecr| across all tensor components = 2.842e-14
Exercises¶
Worked solutions are in 06_solutions.ipynb. The cell below the list is a short self-check to start from.
Verify a result. Derive the cubic equation for in steady shear of the FENE-P model, compare
solve_fenep_fenecrwith its root for , and check the power laws at high Weissenberg number, and .Find how it fails. Reproduce two errors of implementation of the FENE-P model and correct them. (1) The function is used with the stress and the initial state , without flow (, ): compute the stress at rest, which should be zero, and follow . (2) The dependence of the drag on the conformation is left out of
fenep_planar_extension_hysteresis: compare the area of the hysteresis loop with and without it.Implement it yourself. Write
solve_scurve_all_branches(b_ext=120.0, kappa_drag=4.5)in NumPy to compute all steady states of the model with conformation-dependent drag as the curve , with the fractional extension between 0 and 1. Find the turning points, where , determine which states are stable, and plot the unstable branch together with the result offenep_planar_extension_hysteresis.
heading("Self-check for the exercises")
assert np.allclose(eta_fcr, eta_p_d1, rtol=2e-3, atol=2e-3)
assert np.allclose(eta_fp, eta_fp_exact, rtol=4e-3, atol=4e-3)
assert peak_fp > 1.07 * peak_bd
assert hys_drag["hysteresis_area"] > 15.0 and hys_const["hysteresis_area"] < 0.5
assert np.allclose(tau_hand, tau_lib, rtol=1e-13, atol=1e-13)
print("All checks passed.")
Self-check for the exercises
============================
All checks passed.