How the Pulsar Simulator Works

This page gives the equations behind each part of A Pulsar, Ray Traced, the simplifications we made, and the tests the code passes. The simulator, its test programs and this write-up were built with Claude Opus 5.5. It assumes some familiarity with general relativity and electromagnetism; the main page explains the same ideas without equations.

We use geometrized units, G = c = 1, with lengths and times in units of the star's mass M (1 M = GM/c2 = 2.07 km, or 6.9 µs, for 1.4 suns), and write u = M/r. The spin axis is +y; the magnetic axis is tilted by χ from it, and the observer is at angle ζ from it.

Light Bending: One Table for Every Ray

Outside a non-rotating, spherical star, spacetime is described by the Schwarzschild metric, as around the black hole on our companion page. Every light ray stays in a plane through the centre, and its path depends on one number, the impact parameter b. A photon leaving radius r at angle α from the outward radial direction, as measured by an observer at rest there, has

b = r sin α / √(1 − 2u).

On the black hole page each pixel's ray is integrated step by step. Here the star blocks every ray that would come close to the photon sphere (we keep R ≥ 3.6 M), so a faster route is possible. We tabulate two functions once, at start-up, and build every ray from them.

Swept angle. The angle a photon sweeps around the centre as it travels outward from r to infinity is

F(α, u) = ∫0u b dw / √(1 − b2w2(1 − 2w)),   0 ≤ α ≤ π/2.

Travel time. The coordinate time for the same trip diverges, so we tabulate a regularized version, from which every finite time difference follows:

T(α, u) = ∫r∞ [ 1 / ((1 − 2/r′) √(1 − b2(1 − 2/r′)/r′2)) − 1 − 2/r′ ] dr′ − r − 2 ln r.

Both integrals have an integrable singularity where the ray is tangential (α → π/2). The substitution w = u(1 − t2), t = (cos α / √k) sinh z, with k = 2 sin2α (1 − 3u)/(1 − 2u), makes the integrand smooth, and 60-point Gauss–Legendre quadrature then gives F to 3 × 10−6 rad. The table holds F and S = T + r cos α + 2 ln r, which stays finite as r → ∞, on a 512 × 512 grid in α and u ∈ [0, 1/3.2]. A Web Worker builds it in about a second and a half, and the graphics card reads it as a floating-point texture.

Any ray from the table. For a ray between radius r and a camera at rc, with the camera seeing it at angle θ (sin θ = b √(1 − 2uc)/rc):

outward from the start:   Φ = F(α, u) − F(θ, uc)
inward first, through periapsis up:   Φ = 2F(π/2, up) − F(π − α, u) − F(θ, uc)

with up the root of u2(1 − 2u) = 1/b2 below 1/3, and the same combinations of T for arrival times. In flat space F(α, u) = α, and both formulas reduce to straight lines.

Where a point appears. A point at radius r, at angle ψ from the direction to the camera, has two images. The primary image is made by a ray that sweeps Φ = ψ and appears on the point's side of the star. The secondary image is made by a ray that sweeps 2π − ψ around the other side. Φ increases monotonically with the emission angle (we check this numerically). So each image is found by bisection on α between 0 and the grazing angle αlim = π − arcsin(bR √(1 − 2u) u), where bR = R/√(1 − 2/R). If Φ(αlim) is less than the target, the star hides that image. Rays that would loop round the star more than once are blocked by its surface when R > 3 M, so these two images are the only ones.

The graphics card runs this bisection (26 steps) for every vertex of every field line, every frame, in a separate render pass that writes screen positions into a texture. The line pass then draws each segment as a screen-space quad. Segments are dropped where an image jumps across the axis behind the star, which is where the primary and secondary images swap sides.

The Star's Surface

The camera is a static observer at rc looking at the star's centre. A pixel at angle θ from the centre has b = rc sin θ / √(1 − 2/rc). If b < bR, its ray reaches the surface, leaving it at emission angle sin α = b √(1 − 2/R)/R and at angle

ψ = F(α, 1/R) − F(θ, 1/rc)

from the sub-camera point, in the direction of the pixel. θ is computed as arctan(tan(1/2FOV) |ndc|) rather than from a dot product, because a star 3,000 M away subtends milliradians and arccos loses precision near 1 in single precision. The surface point is looked up at its retarded time, rotation phase φobs − Ω Δt, with Δt from the T table relative to the ray from the sub-camera point.

Frequency shift. The surface element moves at speed β = ΩR sin θspin / √(1 − 2/R), as measured by a static observer there. With k the photon's direction in that observer's frame and v the surface velocity,

δ = 1 / (γ(1 − β k·v̂)),   g = νobs/νemit = δ √(1 − 2/R) / √(1 − 2/rc),   cos α′ = δ cos α.

The last factor is the static camera's own gravitational blueshift. Because Iν/ν3 is conserved along a ray, a blackbody at temperature T is seen as a blackbody at gT, scaled by the beaming function evaluated at the comoving emission angle α′: either 1 (isotropic) or (1 + 2.06 cos α′)/1.687, the electron-scattering limb darkening of Chandrasekhar (1960), normalized to the same total flux. Colors come from the CIE 1931 color-matching functions, as on the black hole page. The hot spots are drawn at 8,000 K and the rest of the surface at a chosen fraction of that, as a visible stand-in for the X-ray temperatures. The “brightness” color mode instead shows g4I′ on a false-color scale.

Hot spots. Each spot is a circle of fixed angular radius in the co-rotating frame. By default the radius is that of the open-field polar cap of a flat-space dipole, sin2θpc = R/RLC with RLC = c/Ω (Goldreich & Julian 1969). Plasma-filled solutions have more open magnetic flux, so their polar caps are somewhat wider (Contopoulos et al. 1999).

The Magnetic Field

Rotating dipole in vacuum. A point magnetic dipole m(t) turning at Ω about +y produces the field (Jackson 1999, §9.3, in its magnetic form)

B = [3n(n·m) − m]/r3 + [3n(n·ṁ) − ṁ]/r2 + [n(n·m̈) − m̈]/r,

with every m evaluated at the retarded time t − r. This is an exact solution of Maxwell's equations in empty space. We check numerically that ∇·B = 0 and that B satisfies the wave equation. Deutsch (1955) solved the problem for a conducting sphere of radius R. Outside the star his field differs from the point dipole's by terms of relative size (R/RLC)2, under 4% even for the 716 Hz pulsar, and much less for slower ones. The pattern is stationary in the rotating frame, so field lines are traced once, from footpoints on the surface, by fourth-order Runge–Kutta on dx/ds = B̂ with steps of 2.5% of r (at most 0.06 RLC), and then rotated rigidly each frame. Footpoints are chosen so that the static-dipole loop through each would cross the magnetic equator at radii spaced geometrically from 1.7 R to 2.4 RLC.

Static dipole. The first term alone, turned rigidly. Lines are colored by whether their equatorial radius lies inside the light cylinder.

Plasma-filled sketch. A real magnetosphere is filled with plasma that carries currents (Goldreich & Julian 1969). The resulting “force-free” field has no closed-form solution for a tilted star; the standard results are numerical (Contopoulos et al. 1999 for the aligned case, Spitkovsky 2006 for tilted ones). The sketch is built from three pieces, only two of which are calculations:

  • Inside the light cylinder, lines whose dipole loop closes within it (equatorial radius req < RLC) are drawn as static dipole loops.
  • Far outside, the field is Bogovalov's (1999) exact oblique split monopole, the tilted generalization of Michel (1973). Field lines are Archimedean spirals on cones, φ = φ0 − Ω(r − R), and lines from the two magnetic hemispheres are separated by a current sheet on the surface m̂(t − r + R)·n = 0. Each open line is assigned an asymptotic magnetic colatitude Θ by conserving its share of the open flux, 1 − cos Θ = RLC/req, which spreads the open flux evenly over each hemisphere as in the split monopole.
  • Between 0.5 and 1.5 RLC, each open line's colatitude and twist are blended smoothly (a cubic smoothstep) from the dipole to the monopole. This part is an interpolation, not a solution of any equation. The real field there contains a separatrix, a Y-shaped point where the closed zone meets the sheet, and currents that this sketch does not have.

The sheet is drawn out to 6 RLC, about one wavelength of the striped wind (2πRLC), as a translucent surface between 48 spiral spokes.

Gravity and the field. All three fields are flat-space solutions. In Schwarzschild spacetime a static dipole's vector potential becomes

Aφ ∝ −(3 sin2θ / 8) r2 [ ln(1 − 2/r) + 2/r + 2/r2 ]

(Wasserman & Shapiro 1983). For a fixed dipole moment, this makes the field at the surface of a 1.4-sun, 12 km star 1.36 times stronger in its radial component and 1.50 times stronger in its tangential component than the flat-space field. The field lines near the surface would therefore lean slightly more toward the equator. We have not included this. Frame dragging, which also alters the near field, is omitted too.

X-ray Pulse Profiles

The observed flux at a given moment is the sum over the visible surface of the observed intensity times the solid angle each element subtends. For an observer at distance D → ∞, the light-bending map gives the solid angle directly (Pechenick et al. 1983; Beloborodov 2002):

dF = g4 I′(α′) cos α (d cos α / d cos ψ) dS / ((1 − 2/R) D2),

where dS is the coordinate area of a fixed patch of the static sphere and I′ the bolometric intensity in the frame moving with the surface. ψ(α) and its derivative come from a 2,048-point evaluation of F(α, 1/R), resampled onto a uniform grid in ψ.

We integrate over a fixed grid on each spot in the co-rotating frame (14 rings by 40 sectors of equal area) at 384 rotation phases. Each contribution is placed at its arrival phase φ + Ω Δt by linear interpolation into 128 bins. This handles light-travel time correctly. Spreading contributions by arrival time automatically supplies the factor dtemit/dtobs that turns δ4 in the intensity into the δ5 of Poutanen & Gierliński (2003), so it is not applied twice. The rest of the surface, at uniform temperature, adds a constant (a uniform sphere looks the same at every phase). This is the “Schwarzschild + Doppler” approximation of Miller & Lamb (1998), without the oblateness correction used in NICER analyses (Bogdanov et al. 2019).

As a check, we also compute the profile by brute force. We trace 360,000 rays from a distant observer, each assigned an equal share of the image disk, and sum the observed intensity of the surface points they hit at their retarded times. The two methods agree to 0.15% of the peak (below).

The Radio Beam and Its Polarization

How pulsars generate coherent radio emission is an open problem, but the geometry of the beam is well tested. We follow Blaskiewicz, Cordes & Wasserman (1991) and compute it numerically rather than with their first-order formulas:

  1. Emission points. 28 × 120 points per pole on the sphere of radius rem, inside the open-field boundary sin2θm = rem/RLC. Each point is weighted by a brightness pattern in q = θm/θopen: a conal ring (Gaussian at q = 0.72, width 0.11), a core (Gaussian at 0, width 0.22), or uniform.
  2. Beam direction. Charges slide along the static-dipole field line while co-rotating. Their velocity is v = κB̂ + Ω × r / √(1 − 2/r), with κ fixed by |v| = c. Highly relativistic charges radiate along v.
  3. Polarization. Curvature radiation is polarized along the component of the charge's acceleration perpendicular to v. The acceleration is (dv/ds) κ + Ω × v: the change along the field line, by central differences, plus the rotation of the frame.
  4. Light bending. With bending on, the ray's direction at infinity is the emission direction rotated within its plane through the centre by F(α, uem) − α. The polarization vector is parallel-transported: its components perpendicular to and within that plane are preserved. The arrival time is T(α, uem). With bending off, it is −r·k̂.
  5. Observation. At each of 1,440 rotation phases, every emission direction within 5° of the line of sight contributes intensity and the Stokes parameters Q and U, weighted by a Gaussian of width 1°, at its arrival phase. The real beaming angle, about 1/γ, is far smaller. The width is a smoothing kernel that keeps the sampled curves continuous. The plotted angle is ½ arctan(U/Q), shown where the intensity exceeds 3% of the peak.

Beam display. The drawn beam uses the brightest ring of emission directions (q = 0.72, or the cap edge for a uniform beam), 40 per pole, from the same calculation. The cone draws each direction as a straight line out to RLC. “Light in flight” draws where that light is at one instant. A photon emitted a time a ago from x along k̂ is now at Roty(x + ak̂, φ − Ωa). In the co-rotating frame this is the fixed curve Roty(x + ak̂, −Ωa), an Archimedean spiral with one turn per c P, drawn for ages up to 1.5 P. “Textbook beams” is not computed: it draws two rigid 4° cones along the magnetic axis, of the same length, for comparison only. The photon paths are straight lines from the emission point; bending of the paths themselves is left out, although their images on screen are lensed like everything else.

The dashed comparison curve is the rotating vector model (Radhakrishnan & Cooke 1969):

tan PA = − sin χ sin φ / (sin ζ cos χ − cos ζ sin χ cos φ).

The sign and zero point of position angles vary between papers (Everett & Weisberg 2001). We measure the angle from the projected spin axis, with the sign matched to our numerical model in the low-altitude limit. For a beam emitted at height h, Blaskiewicz et al. predict to first order in h/RLC that the pulse centre moves earlier by 2h/RLC radians and the steepest point of the polarization swing later by the same amount, a total separation of 4h/RLC.

Catalogue Numbers

Periods P and spin-down rates Ṗ are from the ATNF Pulsar Catalogue, version 2.6 (Manchester et al. 2005). The fastest, PSR J1748−2446ad at 716 Hz, was discovered by Hessels et al. (2006); the catalogue lists no spin-down rate for it, so no field or age is quoted. The “This star” panel quotes three standard derived quantities, which assume a moment of inertia I = 1045 g cm2:

Ė = 4π2I Ṗ/P3,   B = 3.2 × 1019 √(P Ṗ) G,   τ = P/2Ṗ.

The field formula assumes a vacuum dipole at right angles to the spin axis, radiating L = (2/3) μ2Ω4 sin2χ / c3 (Ostriker & Gunn 1969). Plasma-filled magnetospheres lose energy at L ≈ μ2Ω4(1 + sin2χ)/c3 (Spitkovsky 2006). They spin down even when aligned, and the same Ṗ then implies a dipole moment smaller by a factor of 0.6 to 0.8, depending on χ. The catalogue value is a convention, not a measurement. Masses and radii of the three NICER pulsars are from Riley et al. (2019, 2021) and Choudhury et al. (2024). A later analysis of J0740+6620 with more data gives 12.49 km (Salmi et al. 2024).

Everyday numbers. The “In Everyday Terms” figures on the main page are for M = 1.4 suns and R = 12 km (R = 5.8 M). Mean density: M / (4πR3/3) = 3.9 × 1017 kg/m3, using the areal radius; a teaspoon is 5 mL, giving 1.9 × 1012 kg, against about 5 × 1011 kg for 8.1 billion people at a 62 kg average adult mass (an overestimate, since it counts children as adults). Surface gravity measured by an observer at rest on the surface: GM / (R2 √(1 − 2GM/Rc2)) = 1.6 × 1012 m/s2; impact speed from 1 m: √(2gh) ≈ 1,800 km/s. Clock rate at the surface: √(1 − 2GM/Rc2) = 0.81. Spin: 716 turns per second is 43,000 rpm, against roughly 20,000 rpm for a kitchen blender. Field: 1012 G = 108 T, against 3 T for a clinical MRI scanner.

Verification

The physics code runs unchanged in a test page, in headless Chrome. It is compared against an independent Python reference that uses adaptive quadrature (SciPy's quad), a direct ODE integration of the photon orbit equation u″ + u = 3u2, and a separate ray-shooting solver for image positions. The two share no code.

TestResult
Swept angle F, fixed quadrature vs. adaptive reference (25 rays, r = 3.6 to 400 M, including tangential rays)max error 2.6 × 10−6 rad
Swept angle from the 512 × 512 table, with interpolationmax error 7.9 × 10−6 rad
Arrival time T, quadrature and tablemax error 6.8 × 10−5 M
Primary and secondary image angles vs. ray shooting (20 cases, including hidden images)max relative error 1.3 × 10−6; all hidden/visible verdicts agree
Swept angle increases monotonically with emission angle (bisection relies on this)holds on 28,000 samples
Point directly behind the star: primary and secondary images coincide (Einstein ring)agree to 10−5
Weak-field deflection vs. 4M/b + 15πM2/4b2 at b = 200 to 5,000 Mmax difference 5.5 × 10−6 rad
Vacuum field: ∇·B = 0 by finite differences, inside and beyond the light cylinder|∇·B| h/|B| ≤ 8 × 10−9
Vacuum field: ∇2B = ∂2B/∂t2max relative residual 3.8 × 10−4 (finite-difference error)
Vacuum field reduces to the static dipole as Ω → 0relative difference < 10−6
X-ray profile: surface integral vs. 360,000-ray pixel sum (500 Hz, 20° spots, Doppler and delays on)max difference 0.15% of peak; pulse fractions 39.27% vs. 39.37%
X-ray profile, slow rotation and 1° spots, vs. Beloborodov's analytic formulamax difference 0.8% of peak
Radio polarization at low height vs. rotating vector model, after fitting its phasemax residual 3.4° (from the 1° kernel on a swing of 4.4° per degree)
Radio: separation of polarization centre and pulse centre vs. 4h/RLC at h = 0.03, 0.06, 0.10, 0.15 RLC0.135, 0.271, 0.440, 0.630 rad vs. 0.120, 0.240, 0.400, 0.600: within 13%

The radio results are a first-order formula tested against a calculation that includes all orders. The computed separation runs 5% to 13% above 4h/RLC, and splits unevenly: the polarization lag is 2.2h to 2.7h and the pulse lead 1.8h to 2.0h, against 2h each in the formula.

Two numbers we checked rather than assumed. Beloborodov's (2002) approximation, 1 − cos α = (1 − cos ψ)(1 − 2/R), is often quoted as accurate to about 1%. Against the exact sweep, its largest error in ψ is 0.49° at R = 7 M, 1.1° at 5.8 M and 2.4° at 5 M. At 4 M, the compactness of PSR J0740+6620, it fails near the limb by 27°. The simulator uses the exact table throughout. Second, the fraction of a 1.4-sun, 12 km star visible at once is 75.5% (ψmax = 120.6°).

References

  1. Beloborodov, A. M. (2002). Gravitational bending of light near compact objects. The Astrophysical Journal, 566, L85–L88. DOI
  2. Blaskiewicz, M., Cordes, J. M., & Wasserman, I. (1991). A relativistic model of pulsar polarization. The Astrophysical Journal, 370, 643–669. DOI
  3. Bogdanov, S., et al. (2019). Constraining the neutron star mass–radius relation and dense matter equation of state with NICER. II. Emission from hot spots on a rapidly rotating neutron star. The Astrophysical Journal Letters, 887, L26. DOI
  4. Bogovalov, S. V. (1999). On the physics of cold MHD winds from oblique rotators. Astronomy & Astrophysics, 349, 1017–1026. ADS
  5. Chandrasekhar, S. (1960). Radiative Transfer. Dover. ADS
  6. Choudhury, D., et al. (2024). A NICER view of the nearest and brightest millisecond pulsar: PSR J0437−4715. The Astrophysical Journal Letters, 971, L20. DOI
  7. Contopoulos, I., Kazanas, D., & Fendt, C. (1999). The axisymmetric pulsar magnetosphere. The Astrophysical Journal, 511, 351–358. DOI
  8. Deutsch, A. J. (1955). The electromagnetic field of an idealized star in rigid rotation in vacuo. Annales d'Astrophysique, 18, 1–10. ADS
  9. Everett, J. E., & Weisberg, J. M. (2001). Emission beam geometry of selected pulsars derived from average pulse polarization data. The Astrophysical Journal, 553, 341–357. DOI
  10. Goldreich, P., & Julian, W. H. (1969). Pulsar electrodynamics. The Astrophysical Journal, 157, 869. DOI
  11. Hessels, J. W. T., et al. (2006). A radio pulsar spinning at 716 Hz. Science, 311, 1901–1904. DOI
  12. Jackson, J. D. (1999). Classical Electrodynamics, 3rd ed., chapter 9. Wiley. Link
  13. Manchester, R. N., Hobbs, G. B., Teoh, A., & Hobbs, M. (2005). The Australia Telescope National Facility pulsar catalogue. The Astronomical Journal, 129, 1993–2006. DOI · Catalogue
  14. Michel, F. C. (1973). Rotating magnetospheres: an exact 3-D solution. The Astrophysical Journal, 180, L133. DOI
  15. Miller, M. C., & Lamb, F. K. (1998). Bounds on the compactness of neutron stars from brightness oscillations during X-ray bursts. The Astrophysical Journal, 499, L37–L40. DOI
  16. Miller, M. C., et al. (2019). PSR J0030+0451 mass and radius from NICER data and implications for the properties of neutron star matter. The Astrophysical Journal Letters, 887, L24. DOI
  17. Ostriker, J. P., & Gunn, J. E. (1969). On the nature of pulsars. I. Theory. The Astrophysical Journal, 157, 1395. DOI
  18. Pechenick, K. R., Ftaclas, C., & Cohen, J. M. (1983). Hot spots on neutron stars: the near-field gravitational lens. The Astrophysical Journal, 274, 846–857. DOI
  19. Poutanen, J., & Gierliński, M. (2003). On the nature of the X-ray emission from the accreting millisecond pulsar SAX J1808.4−3658. Monthly Notices of the Royal Astronomical Society, 343, 1301–1311. DOI
  20. Poutanen, J., & Beloborodov, A. M. (2006). Pulse profiles of millisecond pulsars and their Fourier amplitudes. Monthly Notices of the Royal Astronomical Society, 373, 836–844. DOI
  21. Radhakrishnan, V., & Cooke, D. J. (1969). Magnetic poles and the polarization structure of pulsar radiation. Astrophysical Letters, 3, 225. ADS
  22. Riley, T. E., et al. (2019). A NICER view of PSR J0030+0451: millisecond pulsar parameter estimation. The Astrophysical Journal Letters, 887, L21. DOI
  23. Riley, T. E., et al. (2021). A NICER view of the massive pulsar PSR J0740+6620 informed by radio timing and XMM-Newton spectroscopy. The Astrophysical Journal Letters, 918, L27. DOI
  24. Salmi, T., et al. (2024). The radius of the high-mass pulsar PSR J0740+6620 with 3.6 yr of NICER data. The Astrophysical Journal, 974, 294. DOI
  25. Spitkovsky, A. (2006). Time-dependent force-free pulsar magnetospheres: axisymmetric and oblique rotators. The Astrophysical Journal, 648, L51–L54. DOI
  26. Wasserman, I., & Shapiro, S. L. (1983). Masses, radii, and magnetic fields of pulsating X-ray sources: is the “standard” model self-consistent? The Astrophysical Journal, 265, 1036–1046. DOI
  27. AlGendy, M., & Morsink, S. M. (2014). Universality of the acceleration due to gravity on the surface of a rapidly rotating neutron star. The Astrophysical Journal, 791, 78. DOI
← Back to the simulator Black Hole → Dev Journal →