HaomingLuo's picture
Release v0.1 verified programmable rod data and native FE checks
07af0b5 verified
Raw History Blame Contribute Delete
3.82 kB
"""Published reduced-order reference equations for Ye et al. (2026), Fig. 9."""
from __future__ import annotations
import numpy as np
from scipy.integrate import solve_bvp
from scipy.optimize import root
N_CELLS = 15
CHI = 1.0e-4
DELTA = 0.1
H = 0.01
LOADS = np.asarray([-0.017159, -0.016428, -0.016316])
def critical_load_continuum() -> float:
discriminant = 1.0 - np.pi**2 * CHI + 16.0 * H * DELTA
return -0.5 * (1.0 + 4.0 * H - np.sqrt(discriminant))
def critical_load_discrete() -> float:
omega2 = 4.0 * np.sin(np.pi / (2.0 * (2 * N_CELLS - 1))) ** 2
discriminant = 1.0 - 4.0 * CHI * N_CELLS**2 * omega2 + 16.0 * H * DELTA
return -0.5 * (1.0 + 4.0 * H - np.sqrt(discriminant))
def discrete_residual(unknown: np.ndarray, p: float) -> np.ndarray:
theta = np.concatenate(([0.0], np.asarray(unknown, dtype=float)))
epsilon = (p + 2.0 * H) * np.cos(theta)
l0 = 1.0 / N_CELLS
kr = CHI / l0
force_term = (
p * l0 * (1.0 + epsilon)
+ 2.0 * H * l0 * (1.0 - 2.0 * DELTA + epsilon)
) * np.sin(theta)
residual = np.empty(N_CELLS - 1)
for i in range(1, N_CELLS - 1):
residual[i - 1] = (
kr * (theta[i + 1] - 2.0 * theta[i] + theta[i - 1])
- force_term[i]
)
residual[-1] = kr * (-theta[-1] + theta[-2]) - force_term[-1]
return residual
def solve_discrete(p: float):
index = np.arange(1, N_CELLS)
mode = np.sin(np.pi * index / (2 * N_CELLS - 1))
accepted = []
for amplitude in (0.25, 0.5, 0.9, 1.4, 2.0, 2.7):
solved = root(discrete_residual, amplitude * mode, args=(p,), tol=1.0e-11)
if solved.success and np.linalg.norm(discrete_residual(solved.x, p), ord=np.inf) < 1.0e-8:
if np.max(np.abs(solved.x)) > 1.0e-3:
accepted.append(solved.x)
if not accepted:
raise RuntimeError(f"No nontrivial discrete equilibrium for p={p}")
accepted.sort(key=lambda value: np.max(np.abs(value)))
selected = accepted[0]
if np.mean(selected) > 0.0:
selected = -selected
theta = np.concatenate(([0.0], selected))
epsilon = (p + 2.0 * H) * np.cos(theta)
segment = (1.0 / N_CELLS) * (1.0 + epsilon)
x = np.concatenate(([0.0], np.cumsum(segment * np.cos(theta))))
y = np.concatenate(([0.0], np.cumsum(segment * np.sin(theta))))
return theta, x, y
def solve_continuum(p: float):
xi = np.linspace(0.0, 1.0, 401)
a = p + 2.0 * H
def ode(_, state):
theta, curvature, _, _ = state
stretch = 1.0 + a * np.cos(theta)
coefficient = (a + a**2 * np.cos(theta) - 4.0 * H * DELTA) / CHI
return np.vstack(
(
curvature,
coefficient * np.sin(theta),
stretch * np.cos(theta),
stretch * np.sin(theta),
)
)
def boundary(left, right):
return np.asarray([left[0], right[1], left[2], left[3]])
candidates = []
for amplitude in (0.35, 0.7, 1.2, 1.8, 2.5, 3.0):
initial = np.zeros((4, xi.size))
initial[0] = -amplitude * np.sin(0.5 * np.pi * xi)
initial[1] = -amplitude * 0.5 * np.pi * np.cos(0.5 * np.pi * xi)
initial[2] = xi
initial[3] = -0.15 * amplitude * xi**2
solved = solve_bvp(ode, boundary, xi, initial, tol=2.0e-8, max_nodes=30000)
if solved.success and np.max(np.abs(solved.y[0])) > 1.0e-3:
candidates.append(solved)
if not candidates:
raise RuntimeError(f"No nontrivial continuum equilibrium for p={p}")
candidates.sort(key=lambda item: np.max(np.abs(item.y[0])))
dense = np.linspace(0.0, 1.0, 601)
theta, _, x, y = candidates[0].sol(dense)
if y[-1] >= 0.0:
raise RuntimeError("Expected a genuinely downward BVP solution")
return dense, theta, x, y