"""Core numerics for the v2 worked example (Arscott 1963, Sec. 6) in the paper's notation. Geometry: b=3, c=1 (as in Sec. 5). Omega = {nu > nu0 = 0, mu < mu0 = 6}: inside the upward paraboloid nu=0 (x^2/b + y^2/c = 4z) and below the downward paraboloid mu=mu0. V=0 on mu=mu0, V prescribed on nu=nu0. Arscott variables: mu = b+(b-c)sinh^2(alpha), lambda = c+(b-c)cos^2(beta), nu = c-(b-c)sinh^2(gamma). Mathieu constants: a = 4 alpha2 - 2 alpha3 (b+c), q = alpha3 (b-c) (Arscott (4.2)-(4.4)). Only modes even in x and y are needed (data even in x, y): order 2n, functions ce_2n, Ce_2n, CE_2n. """ import numpy as np from scipy.linalg import eigh_tridiagonal from scipy.integrate import solve_ivp from scipy.optimize import brentq b, c = 3.0, 1.0 mu0, nu0 = 6.0, 0.0 cA = b - c alpha0 = np.arcsinh(np.sqrt((mu0 - b) / cA)) gamma0 = np.arcsinh(np.sqrt((c - nu0) / cA)) def ce_coeffs(n2, q, N=None): """Fourier coefficients A_{2r} of ce_{n2}(z,q), n2 even, normalized 2A0^2+sum A^2 = 1 (i.e. int_0^{2pi} ce^2 = pi), sign fixed by ce(0,q) > 0. Returns (a, A).""" assert n2 % 2 == 0 if N is None: N = int(40 + 4*np.sqrt(abs(q)) + n2) d = (2.0*np.arange(N))**2 e = np.full(N-1, float(q)); e[0] = np.sqrt(2)*q w, v = eigh_tridiagonal(d, e, select='i', select_range=(n2//2, n2//2)) vec = v[:, 0].copy(); vec[0] /= np.sqrt(2) if vec.sum() < 0: vec = -vec return w[0], vec def ce(z, A): # angular ce_2n(z) = sum A_2r cos 2rz r = np.arange(len(A)); z = np.asarray(z, float) return np.cos(2*np.multiply.outer(z, r)) @ A def radial(a, q, y0, kind, tmax, dense=True): """kind 'A': A''=(a-2q cosh2t)A [Ce, Arscott (4.2a)]; kind 'C': C''=(a+2q cosh2t)C [CE, (4.2c)].""" s = -1.0 if kind == 'A' else 1.0 f = lambda t, Y: [Y[1], (a + s*2*q*np.cosh(2*t))*Y[0]] return solve_ivp(f, (0, tmax), [y0, 0.0], method='DOP853', rtol=1e-13, atol=1e-15*abs(y0), dense_output=dense) def Ce_at(n2, q, alpha): a, A = ce_coeffs(n2, q) sol = radial(a, q, A.sum(), 'A', alpha, dense=False) return sol.y[0, -1], sol.y[1, -1] def roots_q(n2, qmax, dq=0.25, rel=0.0): """Roots q of Ce_{n2}(alpha0, q) = 0 in (0, qmax] by scanning + Brent (method 1: ODE shooting). Scan step max(dq, rel*q).""" f = lambda q: Ce_at(n2, q, alpha0)[0] qs = [dq] while qs[-1] < qmax: qs.append(qs[-1] + max(dq, rel*qs[-1])) vals = [f(q) for q in qs]; out = [] for i in range(len(qs)-1): if np.sign(vals[i]) != np.sign(vals[i+1]): out.append(brentq(f, qs[i], qs[i+1], xtol=1e-14, rtol=1e-14)) return out class Mode: """u = Ce_2n(alpha,q) ce_2n(beta,q), times CE_2n(gamma,q)/CE_2n(gamma0,q).""" def __init__(self, n2, q): self.n2, self.q = n2, q self.a, self.A = ce_coeffs(n2, q) self.solA = radial(self.a, q, self.A.sum(), 'A', alpha0*1.0000001) self.solC = radial(self.a, q, (self.A*(-1.0)**np.arange(len(self.A))).sum(), 'C', gamma0*1.0000001) self.C0 = self.solC.sol(gamma0)[0] def Afun(self, al): return self.solA.sol(np.asarray(al))[0] def dA(self, al): return self.solA.sol(np.asarray(al))[1] def Bfun(self, be): return ce(be, self.A) def Cratio(self, ga): return self.solC.sol(np.asarray(ga))[0] / self.C0 # in the paper's coordinates (mode is even in x and y, so it depends on lambda only through cos^2 beta) def V(self, mu, nu, la): al = np.arcsinh(np.sqrt(np.clip((mu-b)/cA, 0, None))) be = np.arccos(np.sqrt(np.clip((la-c)/cA, 0, 1))) ga = np.arcsinh(np.sqrt(np.clip((c-nu)/cA, 0, None))) return self.Afun(al)*self.Bfun(be)*self.Cratio(ga) def coords(x, y, z): """(mu, nu, lambda) from Cartesian: roots of x^2/(b-s)+y^2/(c-s)=4(z-s), i.e. of 4 s^3 - 4(z+b+c) s^2 + [4(zb+zc+bc) - x^2 - y^2] s - 4zbc + x^2 c + y^2 b = 0 (vectorized, trig form).""" x, y, z = np.broadcast_arrays(np.asarray(x, float), np.asarray(y, float), np.asarray(z, float)) p2 = -(z+b+c); p1 = (4*(z*b+z*c+b*c) - x**2 - y**2)/4; p0 = (-4*z*b*c + x**2*c + y**2*b)/4 sh = -p2/3; P = p1 - p2**2/3; Q = 2*p2**3/27 - p2*p1/3 + p0 m = 2*np.sqrt(np.clip(-P/3, 0, None)) arg = np.clip(3*Q/(P*m + 1e-300), -1, 1) th = np.arccos(arg)/3 r = np.stack([m*np.cos(th - 2*np.pi*k/3) + sh for k in range(3)]) r.sort(axis=0) return r[2], r[0], r[1] # mu (largest), nu (smallest), lambda (middle)