TMA4215 β Numerical Mathematics | NTNU Fall 2025
Symplectic integrators for simulating charged particle trajectories in magnetic fields, with applications to tokamak fusion reactor geometries.
Symmetric 9-step multistep integrator with standard initial velocityβshowing the banana orbit trajectory used throughout the project
Fourth-order Runge-Kutta with enhanced initial velocity (
Guiding center trajectories showing characteristic banana orbits in tokamak geometry using standard initial velocity
These banana orbits represent the actual particle behavior studied throughout this project. The guiding center approximation reduces the 6D phase space to 4D by separating fast cyclotron motion from slow drift dynamics, enabling 100-200Γ larger timesteps while capturing the essential physicsβa key validation of our tokamak simulation accuracy.
Key Observations:
- Boris & Multistep (Symplectic): Bounded errors over long-term simulations
- RK4: Higher accuracy short-term but growing errors over time
- Periodic Behavior: All methods show oscillating errors due to trajectory periodicity
This project implements and analyzes numerical integration methods for charged particle motion in magnetic fields:
-
Boris Method (2nd order, symplectic)
- Specialized velocity-Verlet variant for Lorentz force
- Excellent long-term energy conservation
- Industry standard for plasma physics simulations
-
Runge-Kutta 4 (4th order, non-symplectic)
- High accuracy for smooth problems
- Energy drift over long timescales
- Reference method for comparison
-
9-Step Symmetric Multistep (4th order, symplectic)
- Implicit multistep with analytical Jacobians
-
$\sim 10\times$ speedup vs autograd - Excellent energy conservation (validates Hairer-Lubich theorem 3.2)
-
ABM4 Guiding Center (4th order predictor-corrector)
- Adams-Bashforth-Moulton for reduced 4D guiding center equations
- Enables
$100\text{-}200\times$ larger timesteps - Exact energy conservation in tokamak (
$U=0$ )
- 2D Magnetic Field: Simplified model with analytical solutions
- Tokamak Geometry: Realistic fusion reactor magnetic field configuration
- Guiding Center Approximation: Reduced model separating fast gyromotion from slow drift
- β Boris: 2nd order convergence confirmed
- β RK4: 4th order convergence confirmed
- β Multistep: 4th order convergence confirmed
- β All methods validated against DOP853 reference solutions
-
Symplectic methods: Energy errors bounded within
$O(h^p)$ over$O(h^{-p-2})$ timescales - RK4: Linear energy drift observed
- Guiding center: Exact conservation in tokamak (theoretical prediction confirmed)
- Multistep with analytical Jacobians:
$\sim 10\times$ faster than autograd version - Guiding center:
$100\text{-}200\times$ larger timesteps while maintaining accuracy - Work-precision diagrams show multistep as most efficient method
git clone https://github.com/Endregb/tma4215-project2.git
cd tma4215-project2
pip install -r requirements.txt# Run individual system examples
python examples/run_2d_system.py
python examples/run_tokamak.py
# Compare all methods
python examples/compare_methods.py
# Generate animations (saves to results/animations/)
python examples/create_animations.pyOpen notebooks/notebook.ipynb for complete analysis including:
- Trajectory visualizations
- Error analysis and convergence studies
- Energy conservation plots
- Work-precision diagrams
- Guiding center implementation
tma4215-project2/
βββ src/
β βββ methods/ # Numerical integrators
β β βββ boris.py # Boris method
β β βββ rk4.py # Runge-Kutta 4
β β βββ multistep.py # 9-step symmetric method
β β βββ abm4.py # ABM4 guiding center
β βββ systems/ # Physical systems
β β βββ system_2d.py # 2D magnetic field
β β βββ tokamak.py # Tokamak geometry
β β βββ guiding_center.py # Guiding center models
β βββ utils/ # Analysis and plotting
β βββ analysis.py # Error computation, reference solutions
β βββ plotting.py # Visualization functions
βββ examples/ # Example scripts
βββ notebooks/ # Jupyter notebooks
βββ tests/ # Unit tests
βββ results/ # Generated figures and animations
pytest tests/Tests include:
- Method accuracy validation
- Energy conservation checks
- Convergence order verification
- Guiding center reference solutions
- Hairer & Lubich (2017) - Energy conservation of symplectic methods
- Qin & Guan (2008) - Symplectic methods for charged particle dynamics
- Hoppe, Iantchenko & Stranberg (2015) - Guiding center dynamics in tokamaks
This project is licensed under the MIT License - see the LICENSE file for details.
- Live Demo - Interactive GitHub Pages site
- Jupyter Notebook - Complete analysis
- GitHub Repository - Source code

