This repository provides a modern and professional framework for simulating particle motion in electromagnetic fields. It leverages Julia for high-performance numerical simulations and Python for advanced visualization and data analysis. The project offers a streamlined workflow, from running simulations via a user-friendly terminal interface to analyzing results with detailed plots and visualizations.
- High-Performance Simulations: Utilizes Julia for efficient numerical computations.
- Interactive Visualization: Python-based tools for generating 2D and 3D plots, energy and momentum conservation analysis, and peak detection.
- User-Friendly Interface: A menu-driven terminal interface for running simulations and configuring parameters.
- Comprehensive Simulation Modes: Supports 1D, 2D, and 3D simulations in cylindrical coordinates.
- Adiabatic Invariants Analysis: Tools for detecting extrema and analyzing invariants in particle motion.
- Customizable Initial Conditions: Easily modify initial parameters without changing source code.
Ensure the following software is installed on your system:
- Julia: Download Julia
- Python: Download Python
- Pip: Install Pip
Use the provided Julia and Python scripts for automated package management by selecting the Package Management:
julia Start.jl
and when you run the visualization.py
it automatically check and install all requirements:
python3 visualization.py
Alternatively, install dependencies manually:
-
Julia Packages:
julia install_packages.jl
-
Python Packages:
python3 -m pip install -r requirements.txt
-
Launch the Simulator:
julia Start.jl
-
Select Simulation Mode:
- [1] 1D Simulation
- [2] 2D Simulation
- [3] 3D Simulation
-
Modify Initial Conditions: Update the
initial_conditions.txt
file to set parameters such as:theta_0 = π/60 alpha_0 = π/2 beta_0 = 0 phi_0 = 0 epsilon = 0.002 eps_phi = 0.0 kappa = 0.01 delta_star = 0.01 time_end = 300.0
-
Run Simulations: Monitor progress and receive completion feedback in the terminal.
Screen Recording:
julia_terminal.mp4
After running simulations, use the visualization.py
script for all visualization tasks. The available options include:
- Unified Terminal Interface: Run 1D, 2D, and 3D simulations directly from a Julia-based menu-driven UI.
- Interactive Parameter Configuration: Modify initial conditions and simulation settings without changing source code.
- Visualization Tools: Python scripts for generating 2D and 3D plots, analyzing energy and momentum conservation, and detecting peaks in particle trajectories.
- Comprehensive Simulation Modes:
- 1D Simulation: Particle motion along a single axis.
- 2D Simulation: Particle motion in a plane with radial and vertical dynamics.
- 3D Simulation: Full spatial dynamics in cylindrical coordinates.
- Peak Detection: Identify extrema and analyze adiabatic invariants in particle motion.
- Energy and Momentum Conservation: Visualize energy and momentum trends over time.
Example usage:
python3 visualization.py
Follow the interactive prompts to select the desired analysis or plotting mode.
Set initial conditions in the initial_conditions.txt
file. Key parameters include:
- theta_0: Initial trajectory angle in radians.
- alpha_0: Initial pitch angle in radians.
- beta_0: Initial azimuthal angle in radians.
- phi_0: Initial azimuthal position in radians.
- epsilon: Dimensionless parameter representing the initial velocity magnitude.
- eps_phi: Electric field perturbation parameter.
- kappa: Magnetic field gradient strength.
- delta_star: Drift correction factor.
- time_end: Total simulation duration.
The 2D simulation models particle motion in cylindrical coordinates (ρ
, z
, φ
). The key equations solved include:
- Equation of Motion for
ρ
andz
:
These describe the particle's motion in radial and vertical directions under the influence of electromagnetic fields.
The 3D simulation solves for radial distance (ρ
), vertical position (z
), and azimuthal angle (φ
). The key equations of motion involve:
This simulates the full trajectory in a 3D cylindrical coordinate system under magnetic and electric fields. The guiding center approximation can also be employed for specific scenarios.
-
Electric Potential Function:
$$\Phi = \kappa \Phi _0 \left(1-\delta_*^2 \left(1-\frac{z^2}{R^2+z^2}\right)\right) \ln \left(\frac{1}{R^2+z^2}\right)+\frac{1}{2} \phi _0 \left(1-\frac{z^2}{R^2+z^2}\right)$$ -
Expanded Derivatives:
Radial derivative:
$$\frac{\partial \Phi}{\partial R}=\frac{R \Phi _0 \left(-2 \kappa R^2+2 \delta_*^2 \kappa \left(R^2-z^2 \log \left(\frac{1}{R^2+z^2}\right)\right)+(1-2 \kappa ) z^2\right)}{\left(R^2+z^2\right)^2}$$ Vertical derivative:
$$\frac{\partial \Phi}{\partial z}=-\frac{z \Phi _0 \left((2 \kappa +1) R^2-2 \delta_*^2 \kappa R^2 \left(\log \left(\frac{1}{R^2+z^2}\right)+1\right)+2 \kappa z^2\right)}{\left(R^2+z^2\right)^2}$$
These equations describe the magnetic flux function and its derivatives in the radial and vertical directions, which are crucial for understanding the magnetic field structure in the simulation.
For additional information, refer to the documentation and examples provided in the repository.
- Shahab Bahreini Jangjoo