WarpX
Functions | Variables
Stencil Namespace Reference

Functions

def get_Fornberg_coeffs (order, staggered)
 
def modified_k (kx, dx, order, staggered)
 
def func_cosine (om, w_c, dt)
 
def compute_stencils (coeff_nodal, coeff_stagg, axis)
 
def compute_all (dx, dy, dz, dt, nox, noy, noz, v_gal, nx=256, ny=256, nz=256)
 
def compute_guard_cells (error, stencil)
 
def plot_stencil (cells, stencil_nodal, stencil_stagg, label, path, name)
 
def run_main (dx, dy, dz, dt, nox, noy, noz, gamma=1., galilean=False, ex=1e-07, ey=1e-07, ez=1e-07, path='.', name='')
 

Variables

int dx = 1e-06
 
int dy = 1e-06
 
int dz = 2e-06
 
int dt = 1e-14
 
int nox = 8
 
int noy = 8
 
int noz = 16
 
int gamma = 30.
 
bool galilean = True
 
int ex = 1e-07
 
int ey = 1e-07
 
int ez = 1e-07
 
string path = '.'
 
string name = 'test'
 
def stencils
 
def sx_nodal = stencils['x']['nodal']
 
def sx_stagg = stencils['x']['stagg']
 
def sy_nodal = stencils['y']['nodal']
 
def sy_stagg = stencils['y']['stagg']
 
def sz_nodal = stencils['z']['nodal']
 
def sz_stagg = stencils['z']['stagg']
 

Detailed Description

Python script to compute the minimum number of guard cells for a given
error threshold, based on the measurement of the PSATD stencil extent
(that is, the minimum number of guard cells such that the stencil
measure is not larger than the error threshold).
Reference: https://arxiv.org/abs/2106.12919

Run the script simply with "python Stencil.py" (or with "run Stencil.py"
using IPython). The user can modify the input parameters set in the main
function at the end of the file.

Function Documentation

◆ compute_all()

def Stencil.compute_all (   dx,
  dy,
  dz,
  dt,
  nox,
  noy,
  noz,
  v_gal,
  nx = 256,
  ny = 256,
  nz = 256 
)
Compute nodal and staggered stencils along all directions.

Parameters
----------
dx : float
    Cell size along x.
dy : float
    Cell size along y.
dz : float
    Cell size along z.
dt : float
    Time step.
nox : int
    Spectral order along x.
noy : int
    Spectral order along y.
noz : int
    Spectral order along z.
v_gal : float
    Galilean velocity.
nx : int, optional (default = 256)
    Number of mesh points along x.
ny : int, optional (default = 256)
    Number of mesh points along y.
nz : int, optional (default = 256)
    Number of mesh points along z.

Returns
-------
(stencil_nodal, stencil_stagg) : tuple
    Nodal and staggered stencils along all directions.

◆ compute_guard_cells()

def Stencil.compute_guard_cells (   error,
  stencil 
)
Compute the minimum number of guard cells for a given
error threshold (number of guard cells such that the
stencil measure is not larger than the error threshold).

Parameters
----------
error : float
    Error threshold.
stencil : numpy.ndarray
    Stencil array.

Returns
-------
guard_cells : numpy.int64
    Number of cells.

◆ compute_stencils()

def Stencil.compute_stencils (   coeff_nodal,
  coeff_stagg,
  axis 
)
Compute nodal and staggered stencils along a given direction.

Parameters
----------
coeff_nodal : numpy.ndarray
    Leading spectral nodal coefficient of the general
    PSATD equations.
coeff_stagg : numpy.ndarray
    Leading spectral staggered coefficient of the general
    PSATD equations.
axis : int
    Axis or direction.

Returns
-------
(stencil_avg_nodal, stencil_avg_stagg) : tuple
    Nodal and staggered stencils along a given direction.

◆ func_cosine()

def Stencil.func_cosine (   om,
  w_c,
  dt 
)
Compute the leading spectral coefficient of the general
PSATD equations: theta_c**2*cos(om*dt), where
theta_c = exp(i*w_c*dt/2), w_c = v_gal*[kz]_c,
om_s = c*|[k]| (and [k] or [kz] denote the centered or
staggered modified wave vector or vector component).

Parameters
----------
om : numpy.ndarray
    Array of centered or staggered modified frequencies.
w_c : numpy.ndarray
    Array of values of v_gal * [kz]_c.
dt : float
    Time step.

Returns
-------
coeff : numpy.ndarray
    Leading spectral coefficient of the general PSATD equations.

◆ get_Fornberg_coeffs()

def Stencil.get_Fornberg_coeffs (   order,
  staggered 
)
Compute the centered or staggered
Fornberg coefficients at finite order.

Parameters
----------
order : int
    Finite order of the approximation.
staggered : bool
    Whether to compute the centered or staggered
    Fornberg coefficients.

Returns
-------
coeffs : numpy.ndarray
    Array of centered or staggered Fornberg coefficients.

◆ modified_k()

def Stencil.modified_k (   kx,
  dx,
  order,
  staggered 
)
Compute the centered or staggered
modified wave vector at finite order.

Parameters
----------
kx : numpy.ndarray
    Standard wave vector.
dx : float
    Cell size in real space.
order : int
    Finite order of the approximation.
staggered : bool
    Whether to compute the centered or staggered
    modified wave vector.

Returns
-------
k_mod : numpy.ndarray
    Centered or staggered modified wave vector.

◆ plot_stencil()

def Stencil.plot_stencil (   cells,
  stencil_nodal,
  stencil_stagg,
  label,
  path,
  name 
)
Plot stencil extent for nodal and staggered/hybrid solver,
as a function of the number of cells.

Parameters
----------
cells : numpy.ndarray
    Array of cell numbers.
stencil_nodal : numpy.ndarray
    Stencil array for the nodal solver.
stencil_stagg : numpy.ndarray
    Stencil array for the staggered or hybrid solver.
label : str
    Label for plot annotations.
name : str
    Label for figure name.

◆ run_main()

def Stencil.run_main (   dx,
  dy,
  dz,
  dt,
  nox,
  noy,
  noz,
  gamma = 1.,
  galilean = False,
  ex = 1e-07,
  ey = 1e-07,
  ez = 1e-07,
  path = '.',
  name = '' 
)
Main function.

Parameters
----------
dx : float
    Cell size along x.
dy : float
    Cell size along y.
dz : float
    Cell size along z.
dt : float
    Time step.
nox : int
    Spectral order along x.
noy : int
    Spectral order along y.
noz : int
    Spectral order along z.
gamma : float, optional (default = 1.)
    Lorentz factor.
galilean : bool, optional (default = False)
    Galilean scheme.
ex : float, optional (default = 1e-07)
    Error threshold along x.
ey : float, optional (default = 1e-07)
    Error threshold along y.
ez : float, optional (default = 1e-07)
    Error threshold along z.
path : str, optional (default = '.')
    Path where figures are saved.
name : str, optional (default = '')
    Common label for figure names.

Returns
-------
stencils : dict
    Dictionary of nodal and staggered stencils along all directions.
    Its element of the dictionary is a dictionary itself,
    containing numpy.ndarray objects.
    Keys: stencils.keys() = dict_keys(['x', 'y', 'z'])
          stencils['x'].keys() = dict_keys(['nodal', 'stagg'])
          stencils['y'].keys() = dict_keys(['nodal', 'stagg'])
          stencils['z'].keys() = dict_keys(['nodal', 'stagg'])

Variable Documentation

◆ dt

int Stencil.dt = 1e-14

◆ dx

int Stencil.dx = 1e-06

◆ dy

int Stencil.dy = 1e-06

◆ dz

int Stencil.dz = 2e-06

◆ ex

int Stencil.ex = 1e-07

◆ ey

int Stencil.ey = 1e-07

◆ ez

int Stencil.ez = 1e-07

◆ galilean

bool Stencil.galilean = True

◆ gamma

int Stencil.gamma = 30.

◆ name

string Stencil.name = 'test'

◆ nox

int Stencil.nox = 8

◆ noy

int Stencil.noy = 8

◆ noz

int Stencil.noz = 16

◆ path

string Stencil.path = '.'

◆ stencils

def Stencil.stencils
Initial value:
1 = run_main(dx, dy, dz, dt, nox, noy, noz, gamma,
2  galilean, ex, ey, ez, path, name)
def run_main(dx, dy, dz, dt, nox, noy, noz, gamma=1., galilean=False, ex=1e-07, ey=1e-07, ez=1e-07, path='.', name='')
Definition: Stencil.py:310

◆ sx_nodal

def Stencil.sx_nodal = stencils['x']['nodal']

◆ sx_stagg

def Stencil.sx_stagg = stencils['x']['stagg']

◆ sy_nodal

def Stencil.sy_nodal = stencils['y']['nodal']

◆ sy_stagg

def Stencil.sy_stagg = stencils['y']['stagg']

◆ sz_nodal

def Stencil.sz_nodal = stencils['z']['nodal']

◆ sz_stagg

def Stencil.sz_stagg = stencils['z']['stagg']