Module es1d

1D electrostatic PIC code

1D, electrostatic, Particle-in-Cell code, using a spectral EM field solver

Classes

class Charge

Electric charge density class

This class allows access to the electric chrage density data structures in the simulation. An object of this class is created automatically when creating a Simulation object.

See Also

Simulation

Instance variables

var rho

Charge density

Grid of charge density values excluding guard cells

Returns

rho : numpy.array, (nx)
Charge density values

Methods

def report()

Save charge density information to disk. Files will be saved in the CHARGE directory below the current working directory.

class Density (type='uniform', start=0.0, end=0.0, n=1.0, ramp=[0.0, 0.0], custom=None)

Class representing charge density profiles for particle species initialization

Parameters

type : str, optional
Density profile type, one of "uniform", "empty", "step", "slab" or "custom", defaults to "uniform"
start : float, optional
Position of the plasma start position for "step", "slab" or "ramp" profiles, defaults to 0.0
end : float, optional
Position of the plasma end position for the "slab" or "ramp" profiles, defaults to 0.0
n : float, optional
Reference density to use, multiplies density profile value, defaults to 1.0
ramp : list of float
2 element list specifying the required density at the start and end positions for the "ramp" density profile, defaults to [0.,0.]
custom : function, optional
Custom density function, defaults to None

See Also

Species

Instance variables

var end

Position of the plasma end position for "slab" or "ramp" profiles

Returns

end : float
Position of the plasma end position
var n

Reference density to use

Returns

n : float
Reference density to use
var ramp

Initial and final density values for the "ramp" profile

Returns

ramp : numpy.array, (2)
[start,end] density values
var start

Position of the plasma start position for "step", "slab" or "ramp" profiles

Returns

start : float
Position of the plasma start position
var type

Density profile type

Returns

type : {'uniform', 'empty', 'step', 'slab', 'ramp','custom'}
Density profile type

Methods

def copy()

Object copy.

class Field

Electric fields class

This class allows access to the electric field data structures in the simulation. An object of this class is created automatically when creating a Simulation object.

See Also

Simulation

Instance variables

var E

Electric field

Grid of (scalar) Electric field values excluding guard cells

Returns

E : numpy.array, (nx)
Electric field values.
var box

Simulation box physical size

Returns

box : float
Simulation box size
var dx

Cell size used for the Field object

Returns

dx : int
Cell size
var nx

Grid size used for the Field object

Returns

nx :int
Number of grid cells for the simulation

Methods

def report()

Save diagnostic field information to disk. Files will be saved in the "field" directory below the current working directory.

class Simulation (nx, box, dt, species=None, report=None, init_fld=None, ext_fld=None, neutral_bkg=False)

ZPIC ES1D Simulation class

Parameters

nx : int
Number of grid cells for the simulation
box : float
Simulation box (phyiscal) size, in simulation units
dt : float
Simulation time step, in simulation units
species : Species or list of Species, optional
Particle species to use in the simulation, defaults to None (no particles)
report : function, optional
Python function used for simulation reporting, defaults to None
neutral_bkg : bool, optional
Controls adding a neutralizing charge background to the simulation at initialization, defaults to False.

See Also

Species

Instance variables

var box

Simulation box physical size

Returns

box : float
Simulation box size
var charge

Simulation electric charge density object

Returns

current : Charge
Simulation electric charge density object
var dx

Cell size used for the simulation

Returns

dx : float
Cell size
var field

Simulation Electric field object

Returns

field : Field
Simulation Electric field object
var n

Current simulation iteration number

This number is advanced automatically by calls to the iter() and run() methods

Returns

n : int
Current simulation iteration number
var nx

Grid size used for the simulation

Returns

nx : int
Number of grid cells for the simulation
var report

Report function for the simulation

This function will be called once before each time step when using the run() method.

Returns

report : function
Report function for the simulation
var species

Simulation particle species list

Returns

species : list of Species
Simulation particle species list
var t

Current simulation time value

This value is advanced automatically by calls to the iter() and run() methods

Returns

t : float
Current simulation simulation time

Methods

def add_neutral_bkg()

Adds a (initial) neutralizing charge background to the simulation

Note

Use of this function has been deprecated and will be removed soon. Use the neutral_bkg parameter of the Simulation class instead.

def iter()

Advance simulation 1 iteration.

def run(tmax)

Advance simulation up to time tmax. If specified earlier, the report function will be called before each iteration.

Parameters

tmax : float
Intended final simulation time. If smaller than current simulation time, a warning message will be displayed
class Species (name, m_q, ppc, vfl=0.0, vth=0.0, density=None, n_sort=16)

Class representing particle species. Particle data can be accessed (read/write) using the particles property.

Parameters

name : str
Name used to identify the particle species
m_q : float
Mass over charge ration in for particles in the species in simulaition units (e.g. for electrons use -1)
ppc : list
Number of particles per cell in the form [nx,ny]
vfl : float, optional
Initial fluid (generalized) velocity for the particles, defaults to 0 (no fluid velocity)
vth : float, optional
Initial thermal velocity for the particles, defaults to 0 (no thermal velocity).
density : Density, optional
Density profile for the particle species specified as using a Density object. Defaults to None which corresponds to a uniform density of value 1
n_sort : int, optional
Number of iterations between particle sort, defaults to 16

See Also

Density

Instance variables

var dt

Time step used for advancing the species

Returns

dt : float
Time step in simulation units
var dx

Cell size used for the species

Returns

dx :float
Cell size
var energy

Total kinetic energy of particle species

Returns

ene : float
Time-centered total kinetic energy of particle species

Note

To ensure the correct time-centering the particle kinetic energy is calculated during the particle advance, so it will be 0 before the first iteration is completed

var iter

Last iteration completed by the particle species

Returns

iter : int
Iteration number
var n_sort

Number of iterations between sorting particle data buffer

Returns

n_sort : int
Number of iteration between sorts
var particles

ndarray of particle data

Allows full read/write access to particle data

var ppc

Number of particles per cell used for initializing new particles from density profile.

Returns

ppc : float
Number of particles per cell

Methods

def add(ix, x, vx)

Adds a new particle to the particle buffer

Parameters

ix : int
New particle cell index
x : float
New particle position inside the cell
vx : float
New particle velocity
def charge()

Calculate charge density of particle species

Returns

n : numpy.array, (nx)
Charge density of particle species. Array will jhave the same shape as the simulation grid
def phasespace(quants, pha_nx, pha_range)

Calculate phasespace density of particle species

Parameters

quants : list of str
2 element list of quantities to use for "pha" diagnostics. Each quantity must be one of 'x1' or 'v1'
pha_nx : list of int, optional
2 element list specifying the size of the phasespace grid
pha_range : list of float, optional
2x2 element list specifying the physical limits of the phasespace grid in the form [[xmin,xmax],[ymin,ymax]]

Returns

pha : numpy.ndarray, (pha_nx[0],pha_nx[1])
Phasespace density of particle species.
def report(type, quants=[], pha_nx=[], pha_range=[])

Saves diagnostic information to disk

Parameters

type : {"charge", "pha", "particles"}
Type of information to save, must be one of "charge" (charge density), "pha" (phasespace density), or "particles" (raw particle data)
quants : list, optional
2 element list of quantities to use for "pha" diagnostics. Each quantity must be one of 'x1' or 'v1'
pha_nx : list of int, optional
2 element list specifying the size of the phasespace grid
pha_range : list of float, optional
2x2 element list specifying the physical limits of the phasespace grid in the form [[xmin,xmax],[ymin,ymax]]