ARTEMIS
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 (errmin, errmax, 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, path='.', name='')
 

Variables

 sp = np.finfo(np.float32).eps
 
 dp = np.finfo(np.float64).eps
 
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
 
string path = '.'
 
string name = 'test'
 

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://doi.org/10.1016/j.cpc.2022.108457

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 (   errmin,
  errmax,
  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 (must be 0, 1, or 2).

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,
  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.
path : str, optional (default = '.')
    Path where figures are saved.
name : str, optional (default = '')
    Common label for figure names.

Variable Documentation

◆ dp

stencil.dp = np.finfo(np.float64).eps

◆ dt

int stencil.dt = 1e-14

◆ dx

int stencil.dx = 1e-06

◆ dy

int stencil.dy = 1e-06

◆ dz

int stencil.dz = 2e-06

◆ 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 = '.'

◆ sp

stencil.sp = np.finfo(np.float32).eps