Relativistic vs Non-relativistic Tracing
This example compares the particle trajectories of trace! (non-relativistic) and relativistic (RelativisticOrbit) equations. We demonstrate three cases:
Uniform magnetic field (Cyclotron motion)
Uniform ExB field (ExB drift)
Force-free relativistic ExB beam (Boris vs Vay vs Higuera-Cary)
Relativistic effects become significant when the particle velocity approaches the speed of light
using TestParticle
using BorisPushers
using OrdinaryDiffEqVerner
using StaticArrays
using CairoMakieCase 1: Pure Magnetic Field (Cyclotron Motion)
We trace protons in a uniform magnetic field
Field and Particle Setup
const B0 = 1.0 # [T]
getB1(x) = SA[0.0, 0.0, B0]
m = TestParticle.mᵢ
q = TestParticle.qᵢ
c = TestParticle.c
param = prepare(; B = getB1, species = Proton);Initial velocities to test: 10%, 50%, and 90% of speed of light
rats = [0.1, 0.5, 0.9]
v_ratios = [rat * c for rat in rats]
labels = ["0.1c", "0.5c", "0.9c"]
colors = [:darkcyan, :orange, :red];Time span: enough for a few gyro-periods. Using the non-relativistic cyclotron period as a baseline reference.
Ω_non = q * B0 / m
T_non = 2π / Ω_non
tspan = (0.0, 4 * T_non);Simulation and Plotting
f1 = Figure(size = (600, 600), fontsize = 20)
ax1 = Axis(
f1[1, 1],
title = "Trajectory comparison (XY plane)",
xlabel = "x [m]", ylabel = "y [m]", aspect = DataAspect()
)
for (i, v_mag) in enumerate(v_ratios)
# Let's start at same point (0,0,0) with v in x-dir.
r0 = [0.0, 0.0, 0.0]
v0 = [v_mag, 0.0, 0.0]
# Non-relativistic initial state: [r, v]
u0_non = [r0..., v0...]
prob_non = TraceProblem(u0_non, tspan, param)
sol_non = solve(prob_non, Vern7())
# Relativistic initial state: [r, γv]
γ = 1 / sqrt(1 - (v_mag / c)^2)
u0_rel = [r0..., (γ * v0)...]
prob_rel = TraceProblem{RelativisticOrbit}(u0_rel, tspan, param)
sol_rel = solve(prob_rel, Vern7())
# Plot
lines!(
ax1, sol_non; idxs = (1, 2), linestyle = :dash,
color = colors[i], label = "Non-rel $(labels[i])"
)
lines!(
ax1, sol_rel; idxs = (1, 2), linestyle = :solid,
color = colors[i], label = "Rel $(labels[i])"
)
end
axislegend(ax1; position = :rt, backgroundcolor = :transparent)
Observation: At 0.1c, the dashed and solid lines almost overlap. At 0.9c, the relativistic trajectory (solid) has a significantly larger radius, consistent with the factor of γ ≈ 2.29 increase in effective mass.
Case 2: ExB Drift
We add a uniform electric field
const E0 = 0.5 * c * B0 # strong electric field, v_drift = 0.5c
getB2(x) = SA[0.0, 0.0, B0]
getE2(x) = SA[0.0, E0, 0.0]
param2 = prepare(; E = getE2, B = getB2, species = Proton);Test with a single high initial velocity perpendicular to drift to see the cycloid differences. Starting from rest: Non-relativistic: cycloid with peak velocity 2*v_drift. Relativistic: should also drift but with different dynamics.
v_init_mag = 0.0 # start from rest
r0 = [0.0, 0.0, 0.0]
v0 = [0.0, v_init_mag, 0.0];Non-relativistic
u0_non = [r0..., v0...]
prob_non_drift = TraceProblem(u0_non, tspan, param2)
sol_non_drift = solve(prob_non_drift, Vern7());Relativistic if v=0, γ=1
u0_rel = [r0..., v0...]
prob_rel_drift = TraceProblem{RelativisticOrbit}(u0_rel, tspan, param2)
sol_rel_drift = solve(prob_rel_drift, Vern7());Trajectory comparison
f2 = Figure(size = (1000, 300), fontsize = 20)
ax2 = Axis(
f2[1, 1],
title = "ExB Drift comparison (XY plane)",
xlabel = "x [m]", ylabel = "y [m]", aspect = DataAspect()
)
lines!(
ax2, sol_non_drift; idxs = (1, 2), linestyle = :dash,
color = :darkcyan, label = "Non-rel drift"
)
lines!(
ax2, sol_rel_drift; idxs = (1, 2), linestyle = :solid,
color = :darkorange, label = "Rel drift"
)
axislegend(ax2; position = :rb, backgroundcolor = :transparent)
Case 3: Relativistic Pusher Comparison (Boris vs Vay vs Higuera-Cary)
When tracing a fast beam across perpendicular Boris() scheme introduces a slight phase mismatch between the electric acceleration and the magnetic rotation, generating spurious transverse motion, whereas Vay() and HigueraCary() cancel the crossed-field forces exactly.
const v_beam = 0.9 * c
getB3(x) = SA[0.0, 0.0, B0]
getE3(x) = SA[0.0, v_beam * B0, 0.0]
param3 = prepare(; E = getE3, B = getB3, species = Proton)
γ_beam = 1 / sqrt(1 - (v_beam / c)^2)
u0_beam = [0.0, 0.0, 0.0, γ_beam * v_beam, 0.0, 0.0]
dt_rel = T_non / 5
tspan_beam = (0.0, 10 * T_non)
prob_beam = TraceProblem{RelativisticOrbit}(u0_beam, tspan_beam, param3)
sol_boris_rel = solve(prob_beam, Boris(); dt = dt_rel)
sol_vay_rel = solve(prob_beam, Vay(); dt = dt_rel)
sol_hc_rel = solve(prob_beam, HigueraCary(); dt = dt_rel);Extract the transverse velocity error
function transverse_speed_error(sol, c)
return map(sol.u) do state
ux, uy, uz = state[4], state[5], state[6]
γ = hypot(ux, uy, uz, c) / c
return max(abs(uy / γ) / c, 1.0e-16)
end
end
f3 = Figure(size = (800, 400), fontsize = 20)
ax3 = Axis(
f3[1, 1];
title = "Force-free relativistic E×B beam (v = 0.9c)",
xlabel = "t / T_non",
ylabel = "|v_y| / c",
yscale = log10
)
lines!(
ax3, sol_boris_rel.t ./ T_non, transverse_speed_error(sol_boris_rel, c);
color = :crimson, linewidth = 2, label = "Boris"
)
lines!(
ax3, sol_vay_rel.t ./ T_non, transverse_speed_error(sol_vay_rel, c);
color = :darkcyan, linewidth = 2, label = "Vay"
)
lines!(
ax3, sol_hc_rel.t ./ T_non, transverse_speed_error(sol_hc_rel, c);
color = :darkorange, linestyle = :dash, linewidth = 2, label = "HigueraCary"
)
axislegend(ax3; position = :rc, backgroundcolor = :transparent)
Choosing a relativistic solver:
HigueraCary()(orAdaptiveHigueraCary()): Recommended general default for relativisticand fields—volume-preserving, energy-conserving in pure , and exact for force-free drift.Vay()(orAdaptiveVay()): Well suited for ultra-relativistic beams and strong cancellation.Boris()/MultistepBoris6(; n = 4): Best when and pure-magnetic gyrophase accuracy or minimum per-step cost is the priority.
Summary
Case 1: Relativistic particles have larger gyroradii due to the relativistic factor
. Case 2: Under strong electric fields, relativistic kinematics limit the velocity to
, whereas non-relativistic dynamics would predict velocities exceeding (if is large enough or during the gyro-phase). Case 3: In force-free crossed fields (
),Vay()andHigueraCary()maintain machine-precision cancellation whileBoris()develops spurious transverse velocity at finite.