This project involves simulating particle dynamics in electromagnetic fields using Julia for the core numerical computations and Python for visualization and data analysis. It tracks particle motion under specific initial conditions and visualizes the system's behavior over time using various plotting techniques.
- Project Overview
- Installation
- Running the Simulation
- Plotting Options
- Peak Finder and Adiabatic Invariant Measurement (
peakfinder.py
) - Configuration
- Physics and Equations of Motion
- Contributors
This project simulates the behavior of particles in electromagnetic fields. The simulation integrates particle equations of motion and visualizes the results using various plotting techniques. The features include:
- Particle trajectory computation in an electromagnetic field.
- Energy and momentum conservation visualizations.
- 2D and 3D plot generation.
- Electric and magnetic field visualizations.
- Velocity component analysis.
- Peak detection in particle motion data.
You will need the following installed on your system:
- Python: Install Python.
- Pip: Install Pip.
- Julia: Install Julia.
Once the prerequisites are installed, use the following commands to set up the environment:
julia install_packages.jl
python3 -m pip install -r requirements.txt
Ensure that Julia is installed and used for the core numerical simulations, while Python handles the post-processing and visualization.
Modify the system's initial conditions in the initial_conditions.txt
file. Default conditions are as follows:
theta_0 = π/10
alpha_0 = π/2
beta_0 = 0
phi_0 = π/2
epsilon = 0.0005
eps_phi = 0.0
kappa = 0.0
delta_star = 1.0
number_of_trajectories = 10000
time_end = 50000.0
- Open a terminal and navigate to the directory where
Start.jl
and associated files are located. - Run the simulation using:
julia Start.jl
- Choose the type of simulation (3D or 2D) when prompted.
- Modify initial conditions as necessary in the
initial_conditions.txt
file.
Once the simulation is complete, use the following Python scripts to visualize the data:
-
2D Plotting:
python plotter_2D.py
-
3D Plotting:
python plotter_3D.py
-
Energy and Momentum Visualization:
python plotter_conservation.py
-
Electric Field Visualization:
python plotter_electricField.py
-
Magnetic Field Visualization:
python plotter_magneticField.py
-
Violation Analysis:
python plotter_violation.py
-
Velocity Components Analysis:
python plotter_velocity_components.py
-
Peak Detection:
python peakfinder.py
This script generates 2D plots from CSV data produced by the simulation.
- Single-file and Multi-file Support: Plot data from one or more CSV files.
- Dynamic Titles and Legends: Automatically generate LaTeX symbols for parameters.
- Sorted Legends: Sort the legend by a specific parameter (e.g.,
eps
). - Interactive File Selection: Select files from the current directory or a folder.
- Custom Axis Labels: Label axes with physical quantities (e.g.,
rho
,omega_rho
).
-
Single File Mode:
python plotter_2D.py
- Select the x-axis and y-axis from available options.
-
Multi-file Mode:
python plotter_2D.py
- Select multiple files and the script will group them by shared parameters (e.g.,
eps
).
- Select multiple files and the script will group them by shared parameters (e.g.,
Example output generated by plotter_2D.py
in multi-file mode with legend sorted by eps
:
This script visualizes particle trajectories in 3D space using the data from the CSV files.
- 3D Trajectory Plotting: Interactive 3D plots with rotation and zooming.
- Guiding Center Approximation: Option to enable guiding center approximation.
- Custom Color Themes: Customize the plot appearance with different themes.
- Subsampling: Reduces the size of large datasets for clearer visualizations.
python plotter_3D.py
- Select the files to plot and adjust the plot's visual settings.
Example output generated by plotter_3D.py
showing the particle's 3D trajectory:
This script visualizes the conservation of energy and momentum during the simulation.
- Energy Plot: Displays the total energy over time.
- Momentum Plot: Shows momentum in different directions.
python plotter_conservation.py
Example output visualizing energy conservation:
This script generates various plots for electric field distributions.
- 2D streamplot of electric field
- 3D quiver plot of electric field vectors
- 2D and 3D contour plots of electric field magnitude
- Customizable plot parameters and output options
python plotter_electricField.py
Creates plots for magnetic field distributions and vector fields.
- 2D streamplot of magnetic field lines
- 3D quiver plot of magnetic field vectors
- 2D and 3D contour plots of magnetic field strength
- 2D quiver plot of magnetic field vectors
- Customizable plot parameters and output options
python plotter_magneticField.py
Analyzes and plots the relative change ratio of magnetic moment.
- Calculates and plots Δ(μ)/μ against time
- Includes moving average calculation
- Identifies violation points where Δ(μ)/μ exceeds a threshold
- Interactive plot with customizable parameters
python plotter_violation.py
Plots parallel and perpendicular velocity components against time.
- Plots v_parallel and v_perpendicular against time
- Customizable plot styling and labels
- Option to add subtitle for additional information
python plotter_velocity_components.py
The peakfinder.py
script detects peaks in the simulation data, computes extrema, and visualizes them along with the particle motion.
- Peak Detection: Detects local maxima or minima in the particle motion data using algorithms like
find_peaks
fromscipy
andfindpeaks
. - Single and Multi-file Modes: Detect peaks for both single and multiple CSV files.
- Extremum Analysis: Analyze extrema for variables such as
rho
,z
, etc. - Adiabatic Invariant Calculation: Calculates and plots adiabatic invariants.
-
Magnetic Moment (
μ
) Method:Where:
-
Path Integral Method: There is another method available that is going to calculate adiabatic invariant quantity. This is based on the path integral of velocity in R direction on each cycle of gyration.
The script reads configurations from config.yaml
. Important configuration options include:
save_file_name
: Name for the saved output.extremum_of
: Variable on which extrema will be detected (e.g.,rho
,z
).plots_folder
: Directory where the plots will be saved.
-
Single File Mode:
python peakfinder.py
- Select the variable to analyze (e.g.,
rho
,z
). - The script will detect and plot the extrema.
- Select the variable to analyze (e.g.,
-
Multi-file Mode:
python peakfinder.py
- Select multiple files for batch processing.
- The script will process each file and plot the detected peaks.
Example output showing detected peaks in rho
:
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 the 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.
-
Magnetic Flux 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.
[List of contributors or link to contributors file]