Module em2ds
2D spectral EM-PIC code
2D, electro-magnetic, fully relativistic, 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
Simulationobject.See Also
Instance variables
var rho-
Charge density
Grid of charge density values excluding guard cells
Returns
rho:numpy.ndarray, [nx,ny]- 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 Current-
Electric current density class
This class allows access to the electric current density data structures in the simulation. An object of this class is created automatically when creating a
Simulationobject.See Also
Instance variables
var Jx-
Jx current density component
Grid of (scalar) Jx field values excluding guard cells
Returns
Jx:numpy.ndarray, [nx,ny]- X component values of the current density
var Jy-
Jy current density component
Grid of (scalar) Jy field values excluding guard cells
Returns
Jy:numpy.ndarray, [nx,ny]- Y component values of the current density
var Jz-
Jz current density component
Grid of (scalar) Jz field values excluding guard cells
Returns
Jz:numpy.ndarray, [nx,ny]- Z component values of the current density
Methods
def report(jc)-
Save diagnostic information to disk. Files will be saved in the CURRENT directory below the current working directory.
Parameters
jc:{0,1,2}- Current density component to save, must be one of 0 (x), 1 (y) or 2 (z)
class Density (type='uniform', start=0.0, end=0.0, n=1.0)-
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" or "slab" profiles, defaults to 0.0
end:float, optional- Position of the plasma end position for the "slab" profiles, defaults to 0.0
n:float, optional- Reference density to use, multiplies density profile value, defaults to 1.0
See Also
Instance variables
var end-
Position of the plasma end position for "slab" profiles
Returns
end:float- Position of the plasma end position
var n-
Reference density to use
Returns
n:float- Reference density to use
var start-
Position of the plasma start position for "step" or "slab" profiles
Returns
start:float- Position of the plasma start position
var type-
Density profile type
Returns
type:{'uniform', 'empty', 'step', 'slab'}- Density profile type
Methods
def copy()-
Object copy.
class EMF-
Electro-Magnetic fields class
This class allows access to the EM field data structures in the simulation. An object of this class is created automatically when creating a
Simulationobject.See Also
Instance variables
var Bx-
Bx field component
Grid of (scalar) Bx field values excluding guard cells
Returns
Bx:numpy.ndarray, [nx,ny]- X component values of the magnetic field.
var By-
By field component
Grid of (scalar) By field values excluding guard cells
Returns
By:numpy.ndarray, [nx,ny]- Y component values of the magnetic field.
var Bz-
Bz field component
Grid of (scalar) Bz field values excluding guard cells
Returns
Bz:numpy.ndarray, [nx,ny]- Z component values of the magnetic field.
var Ex-
Ex field component
Grid of (scalar) Ex field values excluding guard cells
Returns
Ex:numpy.ndarray, [nx,ny]- X component values of the electric field.
var Ey-
Ey field component
Grid of (scalar) Ey field values excluding guard cells
Returns
Ey:numpy.ndarray, [nx,ny]- Y component values of the electric field.
var Ez-
Ez field component
Grid of (scalar) Ey field values excluding guard cells
Returns
Ez:numpy.ndarray, [nx,ny]- Z component values of the electric field.
var box-
Simulation box physical size
Returns
box:numpy.ndarray, float(2)- Simulation box size
var dx-
Cell sizes used for the EMF object
Returns
dx:numpy.ndarray, float(2)- Array of cell sizes
var energy-
EM field energy per field component
Returns
energy:numpy.array, (6)- Total energy in each field component. Electric field energy is in the first 3 values and magnetic field energy is in the last 3 values.
Note
These values are recalculated each time this function is called.
var nx-
Grid size used for the EMF object
Returns
nx:numpy.ndarray, int(2)- Number of grid cells [nx,ny] for the simulation
Methods
def report(type, fc)-
Save diagnostic information to disk. Files will be saved in the EMF directory below the current working directory.
Parameters
type:{'E','B'}- Type of data to save, must be one of 'E' (electric field), 'B' (magnetic field), 'Ep' (self-consistent + external electric field), 'Bp' (self-consistent + external magnetic field)
fc:{0,1,2}- Field component to save, must be one of 0 (x), 1 (y) or 2 (z)
class Laser (type='plane', start=0.0, fwhm=0.0, rise=0.0, flat=0.0, fall=0.0, a0=0.0, omega0=0.0, polarization=0.0, W0=0.0, focus=0.0, axis=0.0)-
Class representing laser pulses. Laser pulses are added to the simulation using the
Simulation.add_laser()method.Parameters
type:{'plane', 'gaussian'}, optional- Type of laser pulse to launch, defaults to 'plane'
start:float, optional- Position of the starting (leading) point for the laser envelope, defaults to 0.
fwhm:float, optional- Full width at half-max of the laser pulse. If set it overrides the
rise,flat, andfallparameters, defaults to 0 rise,flat,fall:float, optional- Rise time (
rise), flat time (flat) and fall time (fall) of the temporal envelope, default to 0 a0:float, optional- Normalized vector potential value at peak intensity of the laser pulse, default to 0
omega0:float, optional- Laser frequency in simulation units, defaults to 0
polarization:float, optional- Laser polarization in radians measured in reference to the y direction, defaults to 0
W0:float, optional- Gaussian pulse waist size in simulation units, defaults to 0
focus:float, optional- Position of focal plane for Gaussian pulse in simulation units, may be set outside of the simulation box, defaults to 0
axis:float, optional- y position of the propagation axis for Gaussian pulses in simulation units, defaults to 0.
See Also
Instance variables
var W0-
Gaussian pulse waist size in simulation units
Returns
W0:float- Gaussian envelope waist size
var a0-
Normalized vector potential value at peak intensity of the laser pulse
Returns
a0:float- Normalized vector potential value
var axis-
Y position of the propagation axis for Gaussian pulses
Returns
focus:float- Y axis position
var fall-
Fall length of laser envelope
Returns
fall:float- fall length of laser envelope
var flat-
Flat length of laser envelope
Returns
flat:float- flat length of laser envelope
var focus-
Position of focal plane for Gaussian pulse in simulation units
Returns
focus:float- Focal plane position
var fwhm-
FWHM of laser envelope
Returns
fwhm:float- Full width at half-max of the laser pulse
var omega0-
Laser frequency in simulation units
Returns
omega0:float- Laser frequency
var polarization-
Laser polarization in radians measured in reference to the y direction
Returns
pol:float- Polarization angle
var rise-
Rise length of laser envelope
Returns
rise:float- Rise length of laser envelope
var start-
Start position of laser envelope
Returns
start:float- Position of the starting (leading) point for the laser envelope
class Simulation (nx, box, dt, species=None, report=None, neutral_bkg=False)-
ZPIC EM2D Simulation class
Parameters
nx:listofint- Number of grid cells [nx,ny] for the simulation
box:listoffloat- Simulation box (phyiscal) size, in simulation units
dt:float- Simulation time step, in simulation units
species:SpeciesorlistofSpecies, 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
Instance variables
var box-
Simulation box physical size
Returns
box:numpy.ndarray, float(2)- Simulation box size
var charge-
Simulation electric charge density object
Returns
current:Charge- Simulation electric charge density object
var current-
Simulation electric current density object
Returns
current:Current- Simulation electric current density object
var dx-
Cell sizes used for the simulation
Returns
dx:numpy.ndarray, float(2)- Array of cell sizes
var emfvar n-
Current simulation iteration number
This number is advanced automatically by calls to the
iter()andrun()methodsReturns
n:int- Current simulation iteration number
var nx-
Grid size used for the simulation
Returns
nx:numpy.ndarray, int(2)- Number of grid cells [nx,ny] 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 speciesvar t-
Current simulation time value
This value is advanced automatically by calls to the
iter()andrun()methodsReturns
t:float- Current simulation simulation time
Methods
def add_laser(laser)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_bkgparameter of theSimulationclass instead. def iter()-
Advance simulation 1 iteration.
def run(tmax)-
Advance simulation up to time
tmax. If specified earlier, thereportfunction 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, ufl=[0.0, 0.0, 0.0], uth=[0.0, 0.0, 0.0], density=None, n_sort=16)-
Class representing particle species. Particle data can be accessed (read/write) using the
particlesproperty.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]
ufl:list, optional- Initial fluid (generalized) velocity for the particles, defaults to [0,0,0] (no fluid velocity)
uth:list, optional- Initial thermal velocity for the particles, defaults to [0,0,0] (no thermal velocity).
density:Density, optional- Density profile for the particle species specified as using a
Densityobject. Defaults toNonewhich corresponds to a uniform density of value 1 n_sort:int, optional- Number of iterations between particle sort, defaults to 16.
See Also
Instance variables
var dt-
Time step used for advancing the species
Returns
dt:float- Time step in simulation units
var dx-
Cell sizes used for the species
Returns
dx:numpy.ndarray, float(2)- Array of cell sizes
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:numpy.ndarray, (2)- Number of particles per cell along x and y
Methods
def add(ix, x, u)-
Adds a new particle to the particle buffer
Parameters
ix:int[:]- New particle cell index
x:float[:]- New particle position inside the cell
u:float[:]- New particle (generalized velocity)
def charge()-
Calculate charge density of particle species
Returns
n:numpy.ndarray, (nx,ny)- 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:listofstr- 2 element list of quantities to use for "pha" diagnostics. Each quantity must be one of 'x1', 'x2', 'u1', 'u2' or 'u3'
pha_nx:listofint, optional- 2 element list specifying the size of the phasespace grid
pha_range:listoffloat, 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', 'x2', 'u1', 'u2' or 'u3'
pha_nx:listofint, optional- 2 element list specifying the size of the phasespace grid
pha_range:listoffloat, optional- 2x2 element list specifying the physical limits of the phasespace grid in the form [[xmin,xmax],[ymin,ymax]]