"""The Townes profile Q, computed here by shooting: Q'' + Q'/r - Q + Q^3 = 0, Q'(0) = 0, Q -> 0, integrated with RK4 and bisected on Q(0). Drawn as the beam it is, the radial bump Q(|x|)^2 over the plane seen from above at an angle: the volume under it is the critical mass N_c = 2 pi int Q^2 r dr, checked against the README's 11.70089652...""" import math from pathlib import Path import kit H, R_END = 2.5e-4, 12.0 # the error in N_c goes as H^2 (the 1/r at the start): 2e-7 here def shoot(a): """Integrates from r = 0 with Q(0) = a; returns the samples (r, Q) and +1 if Q crossed zero (a too big), -1 if it turned back up first (a too small).""" r, q, p = H, a + (a - a ** 3) / 4 * H * H, (a - a ** 3) / 2 * H # Q''(0) = (a - a^3) / 2 rhs = lambda r, q, p: (p, -p / r + q - q ** 3) out = [(0.0, a), (r, q)] while r < R_END: k1 = rhs(r, q, p) k2 = rhs(r + H / 2, q + H / 2 * k1[0], p + H / 2 * k1[1]) k3 = rhs(r + H / 2, q + H / 2 * k2[0], p + H / 2 * k2[1]) k4 = rhs(r + H, q + H * k3[0], p + H * k3[1]) q += H / 6 * (k1[0] + 2 * k2[0] + 2 * k3[0] + k4[0]) p += H / 6 * (k1[1] + 2 * k2[1] + 2 * k3[1] + k4[1]) r += H if q < 0: return out, 1 if p > 0: return out, -1 out.append((r, q)) return out, 0 lo, hi = 2.0, 2.5 for _ in range(60): mid = (lo + hi) / 2 if shoot(mid)[1] > 0: hi = mid else: lo = mid prof, _ = shoot(lo) # reaches R_END, where Q is below 1e-5: the tail adds nothing at this precision nc = 2 * math.pi * sum((r1 - r0) * (r0 * q0 * q0 + r1 * q1 * q1) / 2 for (r0, q0), (r1, q1) in zip(prof, prof[1:])) assert abs(nc - 11.70089652455965) < 1e-6, nc assert prof[-1][0] > 7 and prof[-1][1] < 1e-3, prof[-1] Q = lambda r: prof[min(round(r / H), len(prof) - 1)][1] # samples far finer than a pixel # the plane seen from elevation E: a point (x, y, z) lands at (cx + s x, base + s y sin E - k z cos E) E, s, k, cx, base = math.radians(14), 104, 35, kit.W / 2, 200 sy, kz = s * math.sin(E), k * math.cos(E) arc = lambda r, a, b: [(cx + s * r * math.cos(t), base + sy * r * math.sin(t) - kz * Q(r) ** 2) for t in [a + (b - a) * i / 80 for i in range(81)]] foot, ground = 2.3, 2.7 # Q(2.3)^2 < 0.04: the bump has met the plane top = [(cx + s * x, base - kz * Q(abs(x)) ** 2) for x in [foot * i / 200 for i in range(-200, 201)]] # the profile through the centre body = kit.polyline(arc(ground, 0, 2 * math.pi), 'faint-s', 2) # the plane, a circle around the beam body += kit.polygon(top + arc(foot, 0, math.pi), 'f-soft') for r in (0.45, 0.9, 1.35): # rings of equal height, their front halves body += kit.polyline(arc(r, 0, math.pi), 'f-s', 2) body += kit.polyline(top, 'ink-s', 3) kit.write(__file__, 'physics-astronomy', body, label=f'Townes beam Q² · volume = critical mass ≈ {nc:.2f}')