Does light charge the quons? › Files cited on the page › check_reflection_fable/
check_time_fable.py
"""check_time_fable.py - the seventh reviewer's own time runs for trial 5's R4 (own Ewald forces from fable_tools.py, own
integrator, own random start). Three runs:
1. one cell, N = 2 stack, no friction: the growth rate of a small disturbance against sqrt(-lambda_min) of the
mass-weighted Phi(Gamma) (the trial's R4b);
2. one cell, friction zeta = 1, to t = 100: where the finer quons go (the trial's R4d), and the end state's hold;
3. a 2 x 2 x 2 supercell (8 quons, 64 finer quons), friction zeta = 1: the same fall with the unstable waves at X, M, R
allowed, which one periodic cell forbids. Does every quon still end with eight finer quons (a lattice of identical
Thomson atoms), or do the cells end charged?
Run: ~/aspden-review-venv/bin/python3 check_time_fable.py > check_time_fable_out.txt
"""
import itertools, math, time
import numpy as np
from fable_tools import Ewald, stack
t0 = time.time()
NSS = 0.32169013
pos0, q, s = stack(2, NSS)
n = len(q)
mass = np.concatenate([[1.0], np.full(8, 1 / 8)])
ew = Ewald(1.0, q, s, eta=2.2, rcells=3, gmax=9)
print("Seventh reviewer: own time runs (N = 2 stack, K_T = 1/3; masses 1 and 1/8 as the trial's [M])\n")
# ---------------------------------------------------------------- growth rate predicted from my Phi(Gamma)
PG = ew.phi(pos0, np.zeros(3)).real
PG = 0.5 * (PG + PG.T)
Minv = np.repeat(1 / np.sqrt(mass), 3)
lmw = np.linalg.eigvalsh(Minv[:, None] * PG * Minv[None, :])
gam = math.sqrt(-lmw[0])
print(f"mass-weighted Phi(Gamma): lowest {lmw[0]:+.6e} -> growth rate {gam:.6f} (trial: -3.031054e+01, 5.505501)")
def run(ewald, x0, masses, zeta, tmax, dt, stop_rms=None, seed=5, amp=1e-7, every=1):
rng = np.random.default_rng(seed)
u = rng.standard_normal(x0.shape)
u -= (masses[:, None] * u).sum(0) / masses.sum()
u *= amp / math.sqrt(np.mean(np.sum(u * u, 1)))
x = x0 + u
v = np.zeros_like(x)
ef = ewald.energy_forces_fast if getattr(ewald, 'fast', False) else ewald.energy_forces
E, F = ef(x)
hist = []
nstep = int(round(tmax / dt))
nq = int(np.sum(masses == 1.0))
for it in range(nstep + 1):
t = it * dt
disp = x[nq:] - x0[nq:]
rms = math.sqrt(np.mean(np.sum(disp * disp, 1)))
ke = 0.5 * np.sum(masses[:, None] * v * v)
if it % every == 0:
hist.append((t, rms, E, ke))
if stop_rms is not None and rms > stop_rms:
break
if it == nstep:
break
# velocity Verlet with linear friction, semi-implicit in v (my own; the same scheme family as the trial's)
a = F / masses[:, None] - zeta * v
vh = v + 0.5 * dt * a
x = x + dt * vh
E, F = ef(x)
v = (vh + 0.5 * dt * F / masses[:, None]) / (1 + 0.5 * zeta * dt)
return np.array(hist), x
# ---------------------------------------------------------------- 1. growth rate
h, x = run(ew, pos0, mass, 0.0, 50.0, 0.002, stop_rms=0.02)
tt, rr = h[:, 0], h[:, 1]
win = (rr > 1e-5) & (rr < 1e-3)
gfit = np.polyfit(tt[win], np.log(rr[win]), 1)[0]
etot = h[:, 2] + h[:, 3]
print(f"\n1. Free run (dt = 0.002, start rms 1e-7, my seed): stopped at t = {tt[-1]:.3f}; fitted growth rate in 1e-5 < rms < 1e-3: {gfit:.6f}; "
f"/ predicted - 1 = {gfit/gam - 1:+.2e}; energy drift / final KE = {np.max(np.abs(etot - etot[0]))/h[-1, 3]:.1e}")
# a second dt as a check of the integrator
h2, _ = run(ew, pos0, mass, 0.0, 50.0, 0.001, stop_rms=0.02)
tt2, rr2 = h2[:, 0], h2[:, 1]
win2 = (rr2 > 1e-5) & (rr2 < 1e-3)
print(f" dt = 0.001: fitted rate {np.polyfit(tt2[win2], np.log(rr2[win2]), 1)[0]:.6f}")
# ---------------------------------------------------------------- 2. friction, one cell
h4, x4 = run(ew, pos0, mass, 1.0, 100.0, 0.002, every=100)
dq = x4[1:] - x4[0]
dq -= np.round(dq)
dist = np.linalg.norm(dq, axis=1)
S2 = s[0] ** 2 + s[1] ** 2
sig = 0.0
for R in itertools.product((-1, 0, 1), repeat=3):
dd = dq - np.array(R, float)
sig += np.sum((1 / 8) * (2 * np.pi * S2) ** -1.5 * np.exp(-np.sum(dd * dd, 1) / (2 * S2)))
print(f"\n2. One cell with friction zeta = 1 to t = 100: finer quons' distances from the quon: rms {math.sqrt(np.mean(dist**2)):.4f}, "
f"min {dist.min():.4f}, max {dist.max():.4f} (trial: rms 0.1934, largest 0.1957); final KE {h4[-1, 3]:.1e}; "
f"electric energy start {h4[0, 2]:+.6f} end {h4[-1, 2]:+.6f} (trial: -0.031759 -> -0.747421; constants differ between codes)")
print(f" end state's K_T by the overlap rule, (sigma_at - 1)/3: {(sig - 1)/3:+.4f} (trial: +2.1355); quons' share 1/(1+K_T) = {1/(1 + (sig-1)/3):.3f}")
# the end state as 8 charges in a Gaussian well: the Thomson problem in a harmonic trap -> is it a cube or an antiprism? pair distances
pd = np.array([np.linalg.norm(dq[i] - dq[j]) for i in range(8) for j in range(i + 1, 8)])
print(f" pairwise distances among the 8 finer quons: min {pd.min():.4f}, max {pd.max():.4f}; distinct values (rounded 1e-3): {sorted(set(np.round(pd, 3)))}")
# where does a single finer quon rest in the quon's Gaussian well plus the 7 others? the equilibrium radius: the Gaussian's pull
# q q_f erf(r/b)/r ... just report the quon's Gaussian weight at r
print(f" the quon's Gaussian (s1 = {s[0]:.4f}) at r = {dist.mean():.3f}: exp(-r^2/(2 s1^2)) = {math.exp(-dist.mean()**2/(2*s[0]**2)):.3f} of the peak; "
f"charge of the quon within that radius: {1 - math.exp(-dist.mean()**2/(2*s[0]**2))*(1 + dist.mean()**2/(2*s[0]**2)) if False else 'see below'}")
from scipy.special import gammainc
rm = dist.mean()
print(f" fraction of the quon's charge inside r = {rm:.3f}: {gammainc(1.5, rm**2/(2*s[0]**2)):.3f}")
# comparison the trial prints: Thomson's (1/y - 1)/3 with y = 8 pi^1.5 s1^3
y_th = 8 * math.pi ** 1.5 * s[0] ** 3
print(f" the trial's 'Thomson' comparison: y = 8 pi^1.5 s1^3 = {y_th:.4f}, (1/y - 1)/3 = {(1/y_th - 1)/3:+.4f}: this y is the volume whose uniform")
print(f" density equals the self-overlap of the quon's Gaussian, i.e. the hold if the finer charge were spread as the quon's own Gaussian;")
print(f" it is not row 6's 'ball filling a share y of the cell' and the end state is not expected to match it (it does not: 2.1 vs 1.8).")
# ---------------------------------------------------------------- 3. the 2 x 2 x 2 supercell with friction
print("\n3. A 2 x 2 x 2 supercell (8 quons, 64 finer quons), friction zeta = 1, dt = 0.002, to t = 40, start rms 1e-7 (random, all 72 charges):")
L = 2.0
cells = np.array(list(itertools.product(range(2), repeat=3)), float)
posS = np.vstack([pos0 + c for c in cells])
qS = np.tile(q, 8)
sS = np.tile(s, 8)
massS = np.tile(mass, 8)
ewS = Ewald(L, qS, sS, eta=2.2, rcells=2, gmax=14)
E0, F0 = ewS.energy_forces(posS)
print(f" largest force at the start {np.max(np.abs(F0)):.1e}")
rngc = np.random.default_rng(2)
xc = posS + 0.04 * rngc.standard_normal(posS.shape)
Ea, Fa = ewS.energy_forces(xc)
Eb, Fb = ewS.energy_forces_fast(xc)
print(f" vectorised forces vs the pair-loop version at a random configuration: |dE| = {abs(Ea-Eb):.1e}, max |dF| = {np.max(np.abs(Fa-Fb)):.1e}")
ewS.fast = True
PGS = None
tS = time.time()
hS, xS = run(ewS, posS, massS, 1.0, 40.0, 0.002, seed=11, every=200)
print(f" ran to t = {hS[-1, 0]:.1f} in {time.time() - tS:.0f} s; final KE {hS[-1, 3]:.1e}; electric energy start {hS[0, 2]:+.5f} end {hS[-1, 2]:+.5f}")
quons = xS[massS == 1.0]
fins = xS[massS != 1.0]
# assign each finer quon to the nearest quon (minimum image in the supercell)
counts = np.zeros(len(quons), int)
dmin = []
for f in fins:
d = f[None, :] - quons
d -= L * np.round(d / L)
r = np.linalg.norm(d, axis=1)
j = int(np.argmin(r))
counts[j] += 1
dmin.append(r[j])
dmin = np.array(dmin)
print(f" finer quons per quon at the end (nearest quon): {counts.tolist()} (8 each = a lattice of identical, neutral Thomson atoms)")
print(f" distance of each finer quon from its quon: min {dmin.min():.4f}, rms {math.sqrt(np.mean(dmin**2)):.4f}, max {dmin.max():.4f}")
# did the quons stay on their lattice sites?
dqn = quons - posS[massS == 1.0]
dqn -= L * np.round(dqn / L)
print(f" quons' displacement from their sites: rms {math.sqrt(np.mean(np.sum(dqn**2, 1))):.4f}, max {np.max(np.linalg.norm(dqn, axis=1)):.4f}")
# history of the rms distance of the finer quons from the nearest quon at a few times
print(" time rms displacement of the finer quons from their start electric energy")
for row in hS[:: max(1, len(hS) // 12)]:
print(f" {row[0]:6.1f} {row[1]:.4e} {row[2]:+.5f}")
print(f"\nrun time {time.time() - t0:.0f} s")