The critical mass of the Townes soliton
Find a closed form for the critical mass N_c ≈ 11.7008965246 of the Townes soliton, the collapse threshold of the 2D cubic NLS.

| 1 | """The Townes profile Q, computed here by shooting: Q'' + Q'/r - Q + Q^3 = 0, Q'(0) = 0, Q -> 0, integrated with RK4 |
| 2 | 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: |
| 3 | the volume under it is the critical mass N_c = 2 pi int Q^2 r dr, checked against the README's 11.70089652...""" |
| 4 | import math |
| 5 | from pathlib import Path |
| 6 | |
| 7 | import kit |
| 8 | |
| 9 | 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 |
| 10 | |
| 11 | |
| 12 | def shoot(a): |
| 13 | """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 |
| 14 | turned back up first (a too small).""" |
| 15 | r, q, p = H, a + (a - a ** 3) / 4 * H * H, (a - a ** 3) / 2 * H # Q''(0) = (a - a^3) / 2 |
| 16 | rhs = lambda r, q, p: (p, -p / r + q - q ** 3) |
| 17 | out = [(0.0, a), (r, q)] |
| 18 | while r < R_END: |
| 19 | k1 = rhs(r, q, p) |
| 20 | k2 = rhs(r + H / 2, q + H / 2 * k1[0], p + H / 2 * k1[1]) |
| 21 | k3 = rhs(r + H / 2, q + H / 2 * k2[0], p + H / 2 * k2[1]) |
| 22 | k4 = rhs(r + H, q + H * k3[0], p + H * k3[1]) |
| 23 | q += H / 6 * (k1[0] + 2 * k2[0] + 2 * k3[0] + k4[0]) |
| 24 | p += H / 6 * (k1[1] + 2 * k2[1] + 2 * k3[1] + k4[1]) |
| 25 | r += H |
| 26 | if q < 0: |
| 27 | return out, 1 |
| 28 | if p > 0: |
| 29 | return out, -1 |
| 30 | out.append((r, q)) |
| 31 | return out, 0 |
| 32 | |
| 33 | |
| 34 | lo, hi = 2.0, 2.5 |
| 35 | for _ in range(60): |
| 36 | mid = (lo + hi) / 2 |
| 37 | if shoot(mid)[1] > 0: |
| 38 | hi = mid |
| 39 | else: |
| 40 | lo = mid |
| 41 | prof, _ = shoot(lo) # reaches R_END, where Q is below 1e-5: the tail adds nothing at this precision |
| 42 | nc = 2 * math.pi * sum((r1 - r0) * (r0 * q0 * q0 + r1 * q1 * q1) / 2 for (r0, q0), (r1, q1) in zip(prof, prof[1:])) |
| 43 | assert abs(nc - 11.70089652455965) < 1e-6, nc |
| 44 | assert prof[-1][0] > 7 and prof[-1][1] < 1e-3, prof[-1] |
| 45 | Q = lambda r: prof[min(round(r / H), len(prof) - 1)][1] # samples far finer than a pixel |
| 46 | |
| 47 | # 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) |
| 48 | E, s, k, cx, base = math.radians(14), 104, 35, kit.W / 2, 200 |
| 49 | sy, kz = s * math.sin(E), k * math.cos(E) |
| 50 | 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)]] |
| 51 | foot, ground = 2.3, 2.7 # Q(2.3)^2 < 0.04: the bump has met the plane |
| 52 | 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 |
| 53 | body = kit.polyline(arc(ground, 0, 2 * math.pi), 'faint-s', 2) # the plane, a circle around the beam |
| 54 | body += kit.polygon(top + arc(foot, 0, math.pi), 'f-soft') |
| 55 | for r in (0.45, 0.9, 1.35): # rings of equal height, their front halves |
| 56 | body += kit.polyline(arc(r, 0, math.pi), 'f-s', 2) |
| 57 | body += kit.polyline(top, 'ink-s', 3) |
| 58 | kit.write(__file__, 'physics-astronomy', body, label=f'Townes beam Q² · volume = critical mass ≈ {nc:.2f}') |