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 domain
  • num_cells::Integer: Number of cells used to divide the domain
  • time_step::Number: Simulation time step
  • num_steps::Integer: Total number of time steps in the simulation
  • charge::Number=-ELEMENTARY_CHARGE: Species charge
  • mass::Number=ELECTRON_MASS: Species mass
  • weighting::Number=1: Particle weighting, number of physical particles per simulation particle
  • permittivity::Number=VACUUM_PERMITTIVITY: Absolute permittivity used to solve the Poisson equation
  • do_MC_PIC::Bool=true: If true, use (standard) MC-PIC scheme, else use EC-PIC scheme
source
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). Creates file_name.csv and file_name.jld2
  • write_interval::Integer=1: Number of time steps between diagnostic outputs
  • write_particles::Bool=false: If true, write particle data at each output interval; particle data is always written at the first and last time step
  • show_progress::Bool=true: If true, display a progress bar

Output Files

  • file_name.csv: Time series of kinetic, potential energy, mean velocity, and temperature
  • file_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

source

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 .jld2 extension)
  • iter::Integer: Time step index to read (0 for initial conditions)

Returns

  • x::Vector{Float64}: Particle positions at the specified time step
  • v::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

source
MiniPIC.read_parameters — Function
read_parameters(file_name::String) -> Parameters

Read simulation parameters from an output file.

Arguments

  • file_name::String: Base name of the output file (without .jld2 extension)

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

source

Physical Constants

The following physical constants are provided for convenience when setting up simulations with physical units.

MiniPIC.VACUUM_PERMITTIVITY — Constant
VACUUM_PERMITTIVITY

Vacuum permittivity (electric constant) in SI units (F/m).

$\varepsilon_0 = 8.8541878128 \times 10^{-12}$ F/m

source