API Reference
This page contains the complete API documentation for MiniPIC.jl.
Simulation
MiniPIC.Parameters — Type
Parameters(; mesh_length=1, num_cells, time_step, num_steps,
charge=-ELEMENTARY_CHARGE, mass=ELECTRON_MASS,
weighting=1, permittivity=VACUUM_PERMITTIVITY,
do_MC_PIC=true)A struct to hold simulation parameters.
Arguments
mesh_length::Number=1: Length of the computational domainnum_cells::Integer: Number of cells used to divide the domaintime_step::Number: Simulation time stepnum_steps::Integer: Total number of time steps in the simulationcharge::Number=-ELEMENTARY_CHARGE: Species chargemass::Number=ELECTRON_MASS: Species massweighting::Number=1: Particle weighting, number of physical particles per simulation particlepermittivity::Number=VACUUM_PERMITTIVITY: Absolute permittivity used to solve the Poisson equationdo_MC_PIC::Bool=true: If true, use (standard) MC-PIC scheme, else use EC-PIC scheme
MiniPIC.simulate! — Function
simulate!(x, v; parameters, file_name, write_interval=1, write_particles=false, show_progress=true)Run a 1D electrostatic particle-in-cell simulation with periodic boundary conditions.
This function evolves the particle positions x and velocities v in-place using the leapfrog integration scheme. The electric field is computed self-consistently by solving the Poisson equation with a second-order finite difference method.
A uniform neutralizing background charge is automatically included for quasi-neutrality.
Arguments
x::AbstractVector: Initial particle positions (modified in-place, non-dimensionalized during simulation)v::AbstractVector: Initial particle velocities (modified in-place, non-dimensionalized during simulation)
Keyword Arguments
parameters::Parameters: Simulation parameters (required)file_name::String: Base name for output files (required). Createsfile_name.csvandfile_name.jld2write_interval::Integer=1: Number of time steps between diagnostic outputswrite_particles::Bool=false: Iftrue, write particle data at each output interval; particle data is always written at the first and last time stepshow_progress::Bool=true: Iftrue, display a progress bar
Output Files
file_name.csv: Time series of kinetic, potential energy, mean velocity, and temperaturefile_name.jld2: HDF5-compatible file containing simulation parameters and particle data
Example
using MiniPIC
# Initialize particles
Nₚ = 10000
x = rand(Nₚ) * 2π # Uniform in [0, 2π]
v = randn(Nₚ) # Maxwellian velocity distribution
# Set up parameters
p = Parameters(
mesh_length = 2π,
num_cells = 64,
time_step = 0.1,
num_steps = 100
)
# Run simulation
simulate!(x, v; parameters=p, file_name="my_simulation")See also: Parameters, read_particles, read_parameters
Input/Output
MiniPIC.read_particles — Function
read_particles(file_name::String, iter::Integer) -> (x, v)Read particle positions and velocities from a simulation output file.
Arguments
file_name::String: Base name of the output file (without.jld2extension)iter::Integer: Time step index to read (0 for initial conditions)
Returns
x::Vector{Float64}: Particle positions at the specified time stepv::Vector{Float64}: Particle velocities at the specified time step
Example
# Read initial conditions
x0, v0 = read_particles("my_simulation", 0)
# Read final state (assuming 100 time steps)
x_final, v_final = read_particles("my_simulation", 100)See also: simulate!, read_parameters
MiniPIC.read_parameters — Function
read_parameters(file_name::String) -> ParametersRead simulation parameters from an output file.
Arguments
file_name::String: Base name of the output file (without.jld2extension)
Returns
parameters::Parameters: The simulation parameters used in the run
Example
# Read parameters from a previous simulation
p = read_parameters("my_simulation")
println("Time step: ", p.time_step)
println("Number of cells: ", p.num_cells)See also: simulate!, read_particles, Parameters
Physical Constants
The following physical constants are provided for convenience when setting up simulations with physical units.
MiniPIC.BOLTZMANN_CONSTANT — Constant
BOLTZMANN_CONSTANTBoltzmann constant in SI units (J/K).
$k_B = 1.380649 \times 10^{-23}$ J/K
MiniPIC.VACUUM_PERMITTIVITY — Constant
VACUUM_PERMITTIVITYVacuum permittivity (electric constant) in SI units (F/m).
$\varepsilon_0 = 8.8541878128 \times 10^{-12}$ F/m
MiniPIC.ELEMENTARY_CHARGE — Constant
ELEMENTARY_CHARGEElementary charge in SI units (C).
$e = 1.60217663 \times 10^{-19}$ C
MiniPIC.ELECTRON_MASS — Constant
ELECTRON_MASSElectron mass in SI units (kg).
$m_e = 9.1093837 \times 10^{-31}$ kg