Skip to content

TestParticle.jl

TestParticle.jl is a flexible tool for tracing charged particles in electromagnetic or body force fields. It supports three-dimensional particle tracking in both relativistic and non-relativistic regimes.

The package handles field definitions in two ways:

  • Analytical Fields: User-defined functions that calculate field values at specific spatial coordinates.

  • Numerical Fields: Discretized fields constructed directly with coordinates or using Meshes.jl and interpolated via FastInterpolations.jl.

The core trajectory integration is powered by and tight to the DifferentialEquations.jl ecosystem, solving the Ordinary Differential Equations (ODEs) of motion.

To accommodate different performance needs, the API provides:

  • In-place versions: Functions ending in !.

  • Out-of-place versions: Functions optimized with StaticArrays. Note that this requires the initial conditions to be passed as a static vector.

For a theoretical background on the physics involved, please refer to Single-Particle Motions.

Installation

julia
julia> ]
pkg> add TestParticle

Usage

Familiarity with the DifferentialEquations.jl workflow is recommended, as TestParticle.jl builds directly upon its ecosystem.

The primary role of this package is to automate the construction of the ODE system based on Newton's second law. This allows users to focus on defining the field configurations and particle initial conditions. For practical demonstrations, please refer to the examples.

In addition to standard integrators, TestParticle.jl includes a native implementation of the Boris solver. It exposes an interface similar to DifferentialEquations.jl for ease of adoption. Further details are provided in the subsequent sections. Check more in examples.

Performance and Scaling

Tracing many particles can be computationally intensive. TestParticle.jl is designed to scale across multiple cores and machines using Julia's built-in parallel computing capabilities.

Serial Performance

The following table compares the performance of TestParticle's Boris solver against standard ODE solvers from DifferentialEquations.jl for a single particle simulation.

Benchmark Configuration:

  • Hardware: Intel Ultra 7 265K

  • Task: Simulating 1 particle for 0.1 second with dt=1 ns (108 steps).

SolverMedian TimeSpeedupAllocationsMemory
TestParticle Boris923 ms1.0x855.12 KiB
ODE Tsit5 (fixed)15773 ms17x slower643.74 KiB
ODE Vern9 (fixed)39555 ms43x slower724.35 KiB

Parallel Scaling

TestParticle.jl supports both multithreading and distributed computing for ensemble simulations. The following results were obtained on a Perlmutter 1 CPU node (2x AMD EPYC 7763). The multithreading performance is measured using EnsembleThreads(), while the distributed performance is measured using EnsembleDistributed().

Presentations

For interactive presentations and educational materials, please check out these Pluto notebooks:

Publications

  • Zijin Zhang, Anton V. Artemyev, and Vassilis Angelopoulos, 2025, "Quantification of ion scattering by solar-wind current sheets: Pitch-angle diffusion rates", Phys. Rev. E, https://doi.org/10.1103/pkzv-k5t3

  • Chi Zhang, Hongyang Zhou, Chuanfei Dong, Yuki Harada, Masatoshi Yamauchi, Shaosui Xu, Hans Nilsson, et al. 2024. “Source of Drift-Dispersed Electrons in Martian Crustal Magnetic Fields”, The Astrophysical Journal, https://doi.org/10.3847/1538-4357/ad64d5.

Acknowledgement

TestParticle.jl is acknowledged by citing the Zenodo DOI: DOI.

Nothing can be done such easily without the support of the Julia community. We appreciate all the contributions from developers around the world.