Module em1ds
1D spectral EM-PIC code
1D, 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
Simulation
object.See Also
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 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
Simulation
object.See Also
Instance variables
var Jx
-
Jx current density component
Grid of (scalar) Jx field values excluding guard cells
Returns
Jx
:numpy.array, (nx)
- 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.array, (nx)
- 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.array, (nx)
- 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, 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
offloat
- 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
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 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
Simulation
object.See Also
Instance variables
var Bx
-
Bx field component
Grid of (scalar) Bx field values excluding guard cells
Returns
Bx
:numpy.array, (nx)
- X component values of the magnetic field.
var By
-
By field component
Grid of (scalar) By field values excluding guard cells
Returns
By
:numpy.array, (nx)
- Y component values of the magnetic field.
var Bz
-
Bz field component
Grid of (scalar) Bz field values excluding guard cells
Returns
Bz
:numpy.array, (nx)
- Z component values of the magnetic field.
var Ex
-
Ex field component
Grid of (scalar) Ex field values excluding guard cells
Returns
Ex
:numpy.array, (nx)
- X component values of the electric field.
var Ey
-
Ey field component
Grid of (scalar) Ey field values excluding guard cells
Returns
Ey
:numpy.array, (nx)
- Y component values of the electric field.
var Ez
-
Ez field component
Grid of (scalar) Ey field values excluding guard cells
Returns
Ez
:numpy.array, (nx)
- Z component values of the electric field.
var box
-
Simulation box physical size
Returns
box
:float
- Simulation box size
var dx
-
Cell size used for the EMF object
Returns
dx
:int
- Cell size
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 :int
- Number of grid cells for the simulation
var solver_type
-
Field solver algorithm used
Returns
solver
:'PSTD', 'PSATD'
- Field solver in use, either 'PSTD' (pseudo-spectral time domain) or 'PSATD' (pseudo-spectral analytical time domain)
Methods
def init_fld(init)
-
Sets initial EM field values. This method can only be called before the simulation starts.
Parameters
init
:InitialField
- Initial field parameters
See Also
Note
Use of this function has been deprecated and will be removed soon. Use the
init_fld
parameter of theSimulation
class instead. 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)
fc
:{0,1,2}
- Field component to save, must be one of 0 (x), 1 (y) or 2 (z)
def set_ext_fld(ext)
-
Sets external EM field values. This method can only be called before the simulation starts.
Parameters
ext
:ExternalField
- External field parameters
See Also
Note
Use of this function has been deprecated and will be removed soon. Use the
ext_fld
parameter of theSimulation
class instead.
class ExternalField (E_type='none', B_type='none', E_0=[0.0, 0.0, 0.0], B_0=[0.0, 0.0, 0.0], E_custom=None, B_custom=None)
-
Used for defining external EM fields in the simulation
Parameters
E_type
:{'none','uniform','custom'}
, optional- Type of external electric field to use, must be one of 'none' (no external field), 'uniform' (uniform external field) or 'custom' (custom external field defined by a function), defaults to 'none'
B_type
:{'none','uniform','custom'}
, optional- Type of magnetic electric field to use, must be one of 'none' (no external field), 'uniform' (uniform external field) or 'custom' (custom external field defined by a function), defaults to 'none'
E_0
:list
offloat
, optional- 3 element list specifying electric field value for 'uniform' external field type, defaults to [0.,0.,0.]
B_0
:list
offloat
, optional- 3 element list specifying magnetic field value for 'uniform' external field type, defaults to [0.,0.,0.]
E_custom
: `function``- Python function for calculating all 3 components of external electric field at every cell
B_custom
: `function``- Python function for calculating all 3 components of external magnetic field at every cell
Instance variables
var B_0
-
Magnetic field value for 'uniform' external field type
Returns
B0
:numpy.ndarray, (3)
- Vector field value for 'uniform' external field type
var B_custom
-
Python function used for 'custom' external B field type
Returns
func
:function
- Python function for calculating all 3 components of external magnetic field at every cell
var B_type
-
Type of external B field
Returns
type
:{'none','uniform','custom'}
- Type of external field
var E_0
-
Electric field value for 'uniform' external field type
Returns
E0
:numpy.ndarray, (3)
- Vector field value for 'uniform' external field type
var E_custom
-
Python function used for 'custom' external E field type
Returns
func
:function
- Python function for calculating all 3 components of external electric field at every cell
var E_type
-
Type of external E field
Returns
type
:{'none','uniform','custom'}
- Type of external field
Methods
def copy()
-
Object copy.
class InitialField (E_type='none', B_type='none', E_0=[0.0, 0.0, 0.0], B_0=[0.0, 0.0, 0.0], E_custom=None, B_custom=None)
-
Used for defining initial EM fields in the simulation
Parameters
E_type
:{'none','uniform','custom'}
, optional- Type of initial electric field to use, must be one of 'none' (no initial field), 'uniform' (uniform initial field) or 'custom' (custom initial field defined by a function), defaults to 'none'
B_type
:{'none','uniform','custom'}
, optional- Type of initial electric field to use, must be one of 'none' (no initial field), 'uniform' (uniform initial field) or 'custom' (custom initial field defined by a function), defaults to 'none'
E_0
:list
offloat
, optional- 3 element list specifying electric field value for 'uniform' initial field type, defaults to [0.,0.,0.]
B_0
:list
offloat
, optional- 3 element list specifying magnetic field value for 'uniform' initial field type, defaults to [0.,0.,0.]
E_custom
: `function``- Python function for calculating all 3 components of initial electric field at every cell
B_custom
: `function``- Python function for calculating all 3 components of initial magnetic field at every cell
Instance variables
var B_0
-
Magnetic field value for 'uniform' initial field type
Returns
E0
:numpy.ndarray, (3)
- Vector field value for 'uniform' initial field type
var B_custom
-
Python function used for 'custom' initial B field type
Returns
func
:function
- Python function for calculating all 3 components of initial magnetic field at every cell
var B_type
-
Type of initial B field
Returns
type
:{'none','uniform','custom'}
- Type of initial field
var E_0
-
Electric field value for 'uniform' initial field type
Returns
E0
:numpy.ndarray, (3)
- Vector field value for 'uniform' initial field type
var E_custom
-
Return an attribute of instance, which is of type owner.
var E_type
-
Type of initial E field
Returns
type
:{'none','uniform','custom'}
- Type of initial field
Methods
def copy()
-
Object copy.
class Laser (start=0.0, fwhm=0.0, rise=0.0, flat=0.0, fall=0.0, a0=0.0, omega0=0.0, polarization=0.0)
-
Class representing laser pulses. Laser pulses are added to the simulation using the
Simulation.add_laser()
method.Parameters
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
, andfall
parameters, 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
See Also
Instance variables
var a0
-
Normalized vector potential value at peak intensity of the laser pulse
Returns
a0
:float
- Normalized vector potential value
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 fwhm
-
Return an attribute of instance, which is of type owner.
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, init_fld=None, ext_fld=None, neutral_bkg=False)
-
ZPIC EM1DS 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
orlist
ofSpecies
, 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
init_fld
:InitialField
, optional- Initial EM fields for the simulation, defaults to None (0 initial fields)
ext_fld
:ExternalField
, optional- External EM fields for the simulation, 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
:float
- 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 dt
-
Time step used for the simulation
Returns
dt :float
- Time step
var dx
-
Cell sizes used for the simulation
Returns
dx
:float
- Cell size
var emf
var 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
: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
var 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_bkg
parameter of theSimulation
class instead. def filter_set(type, ck=0.0)
-
Sets spectral filtering parameters
Parameters
type
:{'none', 'gaussian', 'sharp'}
- Type of spectral filtering to use, must be one of 'none' (no filtering), 'gaussian' (gaussian shaped transfer function), or 'sharp' (perfect low pass filter)
ck
:float
- Filter parameter for 'gaussian' and 'sharp' filters, for 'sharp' filtering this value must be in the ]0.0,1.0[ range (cutoff frequecny in units of the Nyquist frequency) and for 'gaussian' filtering, this value must be > 0.0.
def iter()
-
Advance simulation 1 iteration.
def run(tmax)
-
Advance simulation up to time
tmax
. If specified earlier, thereport
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, 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
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]
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
Density
object. Defaults toNone
which 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 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, 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[3]
- New particle (generalized 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
ofstr
- 2 element list of quantities to use for "pha" diagnostics. Each quantity must be one of 'x1', 'u1', 'u2' or 'u3'
pha_nx
:list
ofint
, optional- 2 element list specifying the size of the phasespace grid
pha_range
:list
offloat
, 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', 'u1', 'u2' or 'u3'
pha_nx
:list
ofint
, optional- 2 element list specifying the size of the phasespace grid
pha_range
:list
offloat
, optional- 2x2 element list specifying the physical limits of the phasespace grid in the form [[xmin,xmax],[ymin,ymax]]