#!/usr/bin/env python3 """Reproduce dimensionless compatibility-dark elastodynamic checks. Run: python verify_physics.py Requires: Python 3, numpy, scipy, matplotlib. Outputs: results/verification.json and figures/verification.{png,pdf}. These calculations verify identities and examples in ideal mathematical models. They are not measurements, finite-element validation, or a novelty assessment. The continuum example uses exact Bessel functions and the full three-dimensional transversely isotropic constitutive law on a z-independent invariant subspace. """ from pathlib import Path import json import platform import numpy as np import scipy from scipy.integrate import quad, quad_vec from scipy.linalg import block_diag from scipy.optimize import brentq from scipy.special import jv, jvp import matplotlib matplotlib.use("Agg") import matplotlib.pyplot as plt ROOT = Path(__file__).resolve().parent RESULTS = ROOT / "results" FIGURES = ROOT / "figures" RESULTS.mkdir(exist_ok=True) FIGURES.mkdir(exist_ok=True) RNG = np.random.default_rng(91472026) def hermitian(a): return (a + a.conj().T) / 2 def ceff(k, c, v, omega): d = k - omega**2 * np.eye(k.shape[0]) - 1j * omega * c r = np.linalg.solve(d, np.eye(k.shape[0])) answer = v @ r.conj().T @ c @ r @ v.T return hermitian(answer), r def positive_matrix(n, floor=0.2): a = RNG.normal(size=(n, n)) return a.T @ a + floor * np.eye(n) def spd_random_checks(count=150): worst_identity = 0.0 worst_power = 0.0 minimum_bound_eigenvalue = np.inf minimum_full_stiffness_eigenvalue = np.inf largest_scaled_excess = 0.0 for _ in range(count): nb, nd = 4, 2 k = positive_matrix(nb, 0.3) c = positive_matrix(nb, 0.2) v = 0.12 * RNG.normal(size=(nd, nb)) kd = v @ np.linalg.solve(k, v.T) + positive_matrix(nd, 0.4) full = np.block([[kd, v], [v.T, k]]) minimum_full_stiffness_eigenvalue = min( minimum_full_stiffness_eigenvalue, np.linalg.eigvalsh(full).min() ) omega = float(np.exp(RNG.uniform(np.log(0.07), np.log(6.0)))) effective, r = ceff(k, c, v, omega) sigma = v @ r @ v.T dissipative = (sigma - sigma.conj().T) / (2j * omega) denom = max(float(np.linalg.norm(effective)), 1e-15) worst_identity = max( worst_identity, float(np.linalg.norm(dissipative - effective) / denom) ) upper = v @ np.linalg.solve(c, v.T) / omega**2 gap = hermitian(upper - effective) minimum_bound_eigenvalue = min( minimum_bound_eigenvalue, np.linalg.eigvalsh(gap).min() ) largest_scaled_excess = max( largest_scaled_excess, max(0.0, -float(np.linalg.eigvalsh(gap).min())) / max(float(np.linalg.norm(upper)), 1e-15), ) q = RNG.normal(size=nd) + 1j * RNG.normal(size=nd) x = -r @ v.T @ q physical = float((omega**2 / 2 * x.conj().T @ c @ x).real) reduced = float((omega**2 / 2 * q.conj().T @ effective @ q).real) worst_power = max(worst_power, abs(physical - reduced) / max(physical, 1e-15)) assert worst_identity < 2e-10 assert worst_power < 2e-10 assert largest_scaled_excess < 2e-10 assert minimum_full_stiffness_eigenvalue > 0 return dict( cases=count, maximum_relative_schur_identity_error=worst_identity, maximum_relative_power_identity_error=worst_power, minimum_eigenvalue_bound_minus_effective=float(minimum_bound_eigenvalue), maximum_relative_bound_violation=largest_scaled_excess, minimum_full_stiffness_eigenvalue=float(minimum_full_stiffness_eigenvalue), ) def singular_covered_checks(count=100): maximum_coverage_error = 0.0 maximum_scaled_excess = 0.0 minimum_full_stiffness_eigenvalue = np.inf for _ in range(count): nb, nd, rank = 5, 2, 3 q, _ = np.linalg.qr(RNG.normal(size=(nb, nb))) eigenvalues = np.exp(RNG.uniform(-0.8, 0.8, rank)) c = q[:, :rank] @ np.diag(eigenvalues) @ q[:, :rank].T cp = q[:, :rank] @ np.diag(1 / eigenvalues) @ q[:, :rank].T v = 0.1 * RNG.normal(size=(nd, rank)) @ q[:, :rank].T maximum_coverage_error = max( maximum_coverage_error, float(np.linalg.norm(v @ q[:, rank:])) ) k = positive_matrix(nb, 0.4) kd = v @ np.linalg.solve(k, v.T) + np.eye(nd) full = np.block([[kd, v], [v.T, k]]) minimum_full_stiffness_eigenvalue = min( minimum_full_stiffness_eigenvalue, np.linalg.eigvalsh(full).min() ) omega = float(np.exp(RNG.uniform(np.log(0.1), np.log(5.0)))) effective, _ = ceff(k, c, v, omega) upper = v @ cp @ v.T / omega**2 gap = hermitian(upper - effective) maximum_scaled_excess = max( maximum_scaled_excess, max(0.0, -float(np.linalg.eigvalsh(gap).min())) / max(float(np.linalg.norm(upper)), 1e-15), ) assert maximum_coverage_error < 1e-12 assert maximum_scaled_excess < 2e-9 assert minimum_full_stiffness_eigenvalue > 0 return dict( cases=count, maximum_absolute_coverage_error=maximum_coverage_error, maximum_relative_bound_violation=maximum_scaled_excess, minimum_full_stiffness_eigenvalue=float(minimum_full_stiffness_eigenvalue), ) def uncovered_counterexample(): eps = np.geomspace(1e-3, 0.3, 100) g, omega = 0.2, 1.0 c = np.diag([1.0, 0.0]) v = np.array([[0.0, g]]) loss = [] min_stiffness = np.inf for e in eps: k = np.array([[1.0, e], [e, 1.0]]) full = np.block([[np.array([[1.0]]), v], [v.T, k]]) min_stiffness = min(min_stiffness, np.linalg.eigvalsh(full).min()) effective, _ = ceff(k, c, v, omega) loss.append(float(effective[0, 0].real)) loss = np.array(loss) target = g**2 / eps**2 error = float(np.max(np.abs(loss / target - 1))) slope = float(np.polyfit(np.log(eps), np.log(loss), 1)[0]) assert error < 1e-10 assert min_stiffness > 0 return dict( omega=omega, coupling=g, minimum_epsilon=float(eps.min()), maximum_relative_error_to_g_squared_over_epsilon_squared=error, fitted_log_log_slope=slope, minimum_full_stiffness_eigenvalue=float(min_stiffness), uncovered_pseudoinverse_bound_is_zero=True, interpretation="Effective damping at prescribed dark amplitude diverges; this is not a claim of infinite absorption at fixed external force.", ), eps, loss def sum_rule_checks(): scalar_g = 0.2 scalar_dampings = [0.05, 0.3, 2.0, 10.0] scalar_target = np.pi / 2 * scalar_g**2 scalar_results = [] for damping in scalar_dampings: fn = lambda w: scalar_g**2 * damping / ((1 - w**2)**2 + (damping * w)**2) area, estimate = quad(fn, 0.0, np.inf, epsabs=2e-11, epsrel=2e-11, limit=600) relative = abs(area - scalar_target) / scalar_target assert relative < 1e-8 scalar_results.append(dict( damping=damping, integral=area, target=float(scalar_target), relative_error=float(relative), quadrature_error_estimate=estimate, )) k = np.array([[2.0, 0.35], [0.35, 0.8]]) cbase = np.array([[0.7, 0.15], [0.15, 1.1]]) v = np.array([[0.15, 0.08], [-0.03, 0.12]]) target = np.pi / 2 * v @ np.linalg.solve(k, v.T) matrix_results = [] for scale in [0.08, 1.0, 8.0]: fn = lambda w: ceff(k, scale * cbase, v, w)[0].real area, estimate = quad_vec(fn, 0.0, np.inf, epsabs=2e-11, epsrel=2e-10, limit=1000) relative = float(np.linalg.norm(area - target) / np.linalg.norm(target)) assert relative < 1e-8 matrix_results.append(dict( damping_scale=scale, integral=area.tolist(), relative_frobenius_error=relative, quadrature_error_estimate=float(estimate), )) return dict( scalar_cases=scalar_results, matrix_target=target.tolist(), matrix_cases=matrix_results, convention="Classical two-sided angular-frequency force PSD S_eta=2*kB*T*C_eff; integral from 0 to infinity of C_eff=(pi/2)*V*K_b^-1*V.T.", ), scalar_g, scalar_dampings def continuum_check(): lam, mu, rho0, radius = 1.0, 1.0, 1.0, 1.0 a = np.array([0.2, 1.7, 5.0]) c33 = np.array([0.8, 2.5, 0.4]) c44 = np.array([0.3, 5.0, 1.2]) boundary = lambda x: (lam + 2 * mu) * x * jvp(1, x) + lam * jv(1, x) root = float(brentq(boundary, 1.85, 2.6, xtol=1e-14)) k = root / radius omega = k * np.sqrt((lam + 2 * mu) / rho0) r = np.linspace(0.0, radius, 501) shape = jv(1, k * r) normalization = float(np.max(np.abs(shape))) shape /= normalization rr = r[1:] q = jv(1, k * rr) / normalization qp = k * jvp(1, k * rr) / normalization qpp = k**2 * jvp(1, k * rr, 2) / normalization ode_residual = (lam + 2 * mu) * (qpp + qp / rr - q / rr**2) + rho0 * omega**2 * q absolute_residual = float(np.max(np.abs(ode_residual))) scaled_residual = absolute_residual / (rho0 * omega**2) outer_traction = float(((lam + 2 * mu) * k * jvp(1, root) + lam * jv(1, root) / radius) / normalization) min_eigs = [] for scale, axial, shear in zip(a, c33, c44): c = np.zeros((6, 6)) c[0, 0] = c[1, 1] = scale * (lam + 2 * mu) c[0, 1] = c[1, 0] = scale * lam c[2, 2] = axial c[3, 3] = c[4, 4] = shear c[5, 5] = scale * mu min_eigs.append(float(np.linalg.eigvalsh(c).min())) assert scaled_residual < 2e-10 assert abs(outer_traction) < 1e-10 assert min(min_eigs) > 0 return dict( model="Three-dimensional transversely isotropic free-face laminate; exact z-independent radial field.", reference_in_plane_lambda=lam, reference_in_plane_mu=mu, reference_density=rho0, radius=radius, layer_scale_factors=a.tolist(), layer_C33=c33.tolist(), layer_C44=c44.tolist(), all_C13=0.0, minimum_constitutive_eigenvalues=min_eigs, dimensionless_bessel_root_kR=root, angular_frequency=omega, maximum_absolute_ode_residual=absolute_residual, maximum_scaled_ode_residual=scaled_residual, reference_outer_radial_traction_residual=outer_traction, maximum_normalized_radial_displacement=float(np.max(np.abs(shape))), interfacial_shear_traction="Exactly zero by the full constitutive law: epsilon_xz=epsilon_yz=0.", interfacial_normal_traction="Exactly zero because C13=0 and epsilon_zz=0.", interfacial_displacement_jump="Exactly zero: all layers have the same nonzero radial field.", scope="This is an analytic continuum realization, not a numerical finite-element simulation or evidence that arbitrary isotropic materials satisfy these conditions.", ), r, shape, a def superposed_axial_transport(continuum): """Exact traveling axial field superposed on the shared radial eigenfield. The normal boundary phasors are those produced by the specified initial state. The example does not assume that the two axial end faces are free. Radial and axial fields share omega but are constitutively decoupled. """ omega = continuum["angular_frequency"] densities = np.array(continuum["layer_scale_factors"]) axial_moduli = np.array(continuum["layer_C33"]) thicknesses = np.array([0.35, 0.55, 0.60]) initial_impedance = float(np.sqrt(densities[0] * axial_moduli[0])) state = np.array([1.0 + 0j, 1j * omega * initial_impedance]) initial_flux = float(omega / 2 * np.imag(state[1] * state[0].conjugate())) flux_values = [] boundary_states = [state.copy()] max_traction_continuity_error = 0.0 max_displacement_continuity_error = 0.0 max_constitutive_cross_coupling = 0.0 for density, modulus, thickness in zip(densities, axial_moduli, thicknesses): k = omega * np.sqrt(density / modulus) ck = modulus * k start = state.copy() for z in np.linspace(0, thickness, 81): cosine, sine = np.cos(k * z), np.sin(k * z) transfer = np.array([[cosine, sine / ck], [-ck * sine, cosine]]) current = transfer @ start displacement, traction = current axial_strain = traction / modulus reconstructed_normal_traction = modulus * axial_strain max_constitutive_cross_coupling = max( max_constitutive_cross_coupling, float(abs(reconstructed_normal_traction - traction)), ) flux_values.append(float(omega / 2 * np.imag(traction * displacement.conjugate()))) state = current boundary_states.append(state.copy()) # The next layer uses this exact displacement and traction as its start. next_start = np.eye(2) @ state max_displacement_continuity_error = max( max_displacement_continuity_error, float(abs(next_start[0] - state[0])) ) max_traction_continuity_error = max( max_traction_continuity_error, float(abs(next_start[1] - state[1])) ) flux_values = np.asarray(flux_values) maximum_relative_flux_drift = float(np.max(np.abs(flux_values - initial_flux)) / abs(initial_flux)) assert initial_flux > 0 assert maximum_relative_flux_drift < 2e-12 assert max_traction_continuity_error < 1e-12 assert max_displacement_continuity_error < 1e-12 return dict( field="u=(v_x(x,y,t),v_y(x,y,t),w(z,t)); C13=0 gives exact linear decoupling.", angular_frequency=omega, layer_thicknesses=thicknesses.tolist(), positive_mean_axial_energy_flux=initial_flux, maximum_relative_axial_flux_drift=maximum_relative_flux_drift, maximum_interface_normal_traction_jump=max_traction_continuity_error, maximum_interface_axial_displacement_jump=max_displacement_continuity_error, maximum_normal_constitutive_reconstruction_error=max_constitutive_cross_coupling, horizontal_shear_tractions="Exactly zero because v is z-independent and w is x,y-independent.", scope="The axial branch carries nonzero normal power and can reflect at impedance changes. Only tangential interface channels are inactive; normal dissipation and radiation are not excluded. Axial end phasors are prescribed consistently, not both traction-free.", ) def create_plot(eps, loss, g, dampings, r, shape, scales): plt.rcParams.update({ "font.family": "DejaVu Sans", "font.size": 12.5, "axes.titlesize": 12, "axes.spines.top": False, "axes.spines.right": False, "axes.labelcolor": "#263746", "text.color": "#182d3c", "axes.titleweight": "semibold", "grid.alpha": 0.18, }) fig, axes = plt.subplots(2, 2, figsize=(10.5, 8.0), constrained_layout=True) blue, teal, orange, purple = "#24547a", "#008a87", "#d38035", "#80589b" w = np.geomspace(0.1, 3.0, 700) smallg, damping = 0.06, 0.2 value = smallg**2 * damping / ((1 - w**2)**2 + (damping * w)**2) bound = smallg**2 / (w**2 * damping) ax = axes[0, 0] ax.semilogy(w, bound, "--", color=orange, label="Sharp gap-independent bound") ax.semilogy(w, value, color=blue, lw=2, label="Effective damping") ax.axvline(1, color="#88949e", lw=0.9, ls=":") ax.set(xlabel="Frequency / auxiliary resonance", ylabel="Effective damping", title="A | Covered coupling: finite resonance bound") ax.legend(frameon=False, fontsize=11, loc="lower left") ax.grid(True) ax = axes[0, 1] ax.loglog(eps, loss, color=purple, lw=2, label="Uncovered bath direction") ax.loglog(eps[::9], (0.2**2 / eps**2)[::9], "o", ms=4, mfc="white", mec=purple, label="Exact 0.04 / epsilon squared") ax.set(xlabel=r"Relative-mode mixing $\epsilon$", ylabel=r"Effective damping at $\omega=1$", title="B | Uncovered coupling: no uniform bound") ax.legend(frameon=False, fontsize=11) ax.grid(True, which="both") ax = axes[1, 0] ws = np.geomspace(0.003, 30, 2200) for gamma, color in zip(dampings, [blue, teal, orange, purple]): curve = g**2 * gamma / ((1 - ws**2)**2 + (gamma * ws)**2) ax.semilogx(ws, curve, color=color, lw=1.7, label=rf"$\gamma={gamma:g}$") ax.set(xlabel="Angular frequency (log axis)", ylabel="Effective damping", title="C | Damping redistributes spectral weight") ax.text(0.03, 0.95, r"Each $\int_0^\infty C_{\rm eff}\,d\omega$ = 0.0628319", transform=ax.transAxes, va="top", fontsize=11) ax.legend(frameon=False, fontsize=11, loc="upper right") ax.grid(True) ax = axes[1, 1] for i, (scale, color) in enumerate(zip(scales, [blue, teal, orange])): if i == 0: ax.plot(r, shape, color=color, lw=2.4, label=f"Layer factor {scale:g}") else: idx = np.arange(15 + 11 * i, len(r), 55) ax.plot(r[idx], shape[idx], ["o", "s"][i-1], mfc="none", mec=color, ms=5, label=f"Layer factor {scale:g}") ax.set(xlabel="Radius / outer radius", ylabel="Normalized radial displacement", title="D | Radial motion; zero interface shear") ax.legend(frameon=False, fontsize=11, loc="lower right") ax.set_ylim(-0.04, 1.08) ax.grid(True) fig.suptitle("Elastic compatibility: exact model checks", fontsize=16, weight="semibold") fig.savefig(FIGURES / "verification.png", dpi=190) fig.savefig(FIGURES / "verification.pdf") plt.close(fig) def main(): spd = spd_random_checks() singular = singular_covered_checks() uncovered, eps, loss = uncovered_counterexample() sums, g, dampings = sum_rule_checks() continuum, r, shape, scales = continuum_check() axial_transport = superposed_axial_transport(continuum) create_plot(eps, loss, g, dampings, r, shape, scales) summary = { "status": "all assertions passed", "units": "dimensionless mathematical examples", "random_seed": 91472026, "software": dict(python=platform.python_version(), numpy=np.__version__, scipy=scipy.__version__, matplotlib=matplotlib.__version__), "spd_schur_power_and_bound": spd, "covered_singular_bound": singular, "uncovered_singular_counterexample": uncovered, "damping_independent_sum_rule": sums, "exact_continuum_bessel_example": continuum, "superposed_axial_transport": axial_transport, "interpretation": "Numerical reproduction supports the stated algebra and ideal-model examples. It does not establish experimental realization, nonlinear stability, novelty, or universal loss elimination.", } (RESULTS / "verification.json").write_text(json.dumps(summary, indent=2) + "\n", encoding="utf-8") print(json.dumps(summary, indent=2)) if __name__ == "__main__": main()