Skip to content

Latest commit

 

History

14 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Cylindrical Magnetron Electron Simulator

A Rust simulation of an electron moving through the crossed electric and magnetic fields of a cylindrical magnetron (modeled on the 2D2S direct-heated vacuum diode), built to reproduce the classic "magnetron method" laboratory measurement of the electron's specific charge (e/m) and initial thermal velocity (v0) from the Hull cutoff condition - and to go meaningfully further than the textbook idealization, into self-consistent space charge and the diocotron instability that actually shapes the experimental data.

Live demo: https://magsim.markooba.com

Origin

This started as my school scientific work five years ago, measuring the electron's specific charge with a real 2D2S tube using the magnetron method. I've come back to it now with AI assistance to dig into the physics more seriously and build a far more physically accurate simulation of the effect than the original lab writeup attempted - going past the idealized cold-beam, no-space-charge model into the self-consistent and turbulent behavior that the real tube actually exhibits.

Physical accuracy is the priority

This project's explicit goal is to be the most physically accurate version of this simulation that's reasonably achievable, not a simplified demo that trades correctness for a smooth browser experience. Concretely, that means:

  • Convergence-validated, not asserted. Every numerical knob - timestep, particle count, field-grid resolution, Poisson-solver tolerance - is chosen by running an actual convergence study (vary it, confirm the result of interest stops changing) and the evidence is checked into data/convergence_reports/. Nothing is "probably fine."
  • Validated against closed-form theory wherever theory exists. The idealized Hull-cutoff case is checked against the analytic cutoff formula; the space-charge-limited regime is checked against the Langmuir-Blodgett law; the diocotron instability's growth rate is checked against a known linear-theory benchmark profile before the code is trusted on the full, no-closed-form self-consistent case.
  • A structure-preserving relativistic integrator (the Higuera-Cary correction to the Boris algorithm), full Biot-Savart magnetic field modeling (not just the on-axis approximation) precomputed as an exact lookup table, and a multigrid/PCG Poisson solver with an explicit Debye-length grid-resolution requirement.
  • Fixed-Timestep-with-Accumulator loop. The interactive explorer decouples playback speed and rendering frame rate from the simulation's integration timestep. The physics runs on a strict, validated FIXED_DT (calculated from steps_per_gyroperiod), integrated inside an accumulator loop to maintain perfect physical accuracy and energy conservation regardless of visual speed settings or frame rate drops. Smooth visual interpolation is used to blend frames at low speeds.

Frontend

The web frontend is a modern single-page application built in Rust using Dioxus v0.7:

  • Design System: Strict, flat, gradient-free, light-mode design using soft cool whites (#F8FAFC), borders of (#E2E8F0), slate text (#334155), and flat pastel buttons/sliders.
  • Interactive Controls: Real-time sliders adjusting geometry (anode/cathode radius, solenoid turns), fields (anode voltage, solenoid current, filament voltage), emission swarm count, initial thermal velocity, and simulation/visual controls (time flow rate, trace tail length).
  • Physics Diagnostics: Real-time rendering of electron trajectories and traces, combined with live calculations of the magnetic field ($B$), Hull critical cutoff limit ($B_c$), collected anode current ($I_a$), step count, and active particle counters.

Architecture

magnetron/
├── crates/
│   ├── core/            # all physics - no platform dependencies, shared by both tracks
│   ├── reference-cli/   # native binary: runs convergence studies, produces validated datasets
│   └── ui/              # Dioxus v0.7 frontend: WebAssembly canvas visualization & interactive controls
├── data/
│   ├── convergence_reports/   # evidence backing every accuracy claim above
│   └── runs/                  # validated trajectories, sweep curves, regression results
└── target/              # compilation output

How it works: The core mathematics of the simulation are completely isolated in crates/core with no WASM/platform dependencies. The crates/ui crate references the core package, compiles it to WebAssembly via the Dioxus toolchain, and renders the real-time simulation on an HTML5 canvas using native web-sys operations.

Physics implemented

  • Relativistic electron dynamics via the Higuera-Cary Boris pusher, in normalized (dimensionless) units for floating-point precision.
  • Exact magnetic field of the finite solenoid via Biot-Savart/elliptic-integral evaluation, precomputed as an interpolated lookup table (off-axis and end-fringing effects included, not just the on-axis center value).
  • Idealized coaxial radial electric field, plus the direct-heating-induced axial potential gradient along the cathode (full 3D particle tracking).
  • Self-consistent space charge: charge-conserving particle deposition, a multigrid/PCG Poisson solver, and space-charge-limited (SCL) cathode emission.
  • The diocotron instability: full azimuthal field resolution, thermal-noise seeding, and growth-rate validation against a closed-form linear-theory benchmark before trusting the self-consistent run.
  • Synthetic diagnostics matching the real experiment: a virtual anode-current meter, automated voltage/current sweeps, inflection-point detection, and least-squares regression recovering e/m and v0 from the simulated data.

Building and running

Prerequisites: recent Rust toolchain, Dioxus CLI (dx).

Run the native reference simulator (the accurate, slow path):

cargo run --release -p reference-cli -- sweep --mode idealized

Build and serve the web frontend:

cargo install dioxus-cli
cd crates/ui
dx serve

This will compile the UI project to WASM and host the development server on http://localhost:8080.

Run the physics test suite (native, fast):

cargo test --release

Background

This simulation digitizes the magnetron method for measuring an electron's specific charge: an electron emitted from a heated cathode wire is pulled outward by a radial electric field while an axial magnetic field (from a surrounding solenoid) curves its path into an azimuthal orbit. Above a critical magnetic field - the Hull cutoff - the electron's trajectory becomes tangent to the anode and never arrives, causing the measured anode current to drop. Sweeping the magnetic field and anode voltage and tracking where that drop occurs lets you solve for e/m and the electron's initial thermal velocity. Real tubes don't show a perfectly sharp drop, though - space charge and the diocotron instability smear it into the gradual descending curve seen experimentally, which is why this project doesn't stop at the idealized textbook model.

About

Rust based simulator for demonstration of the Magnetron Effect

Resources

Stars

0 stars

Watchers

0 watching

Forks

Contributors

Languages