WarpX
|
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_boosted, dt, psatd_order, v_gal, nx=None) |
def | compute_guard_cells (errmin, errmax, stencil) |
def | plot_stencil (cells, stencil_nodal, stencil_stagg, label, path, name) |
def | run_main (dims, dx_boosted, dt, psatd_order, gamma=1., galilean=False, path='.', name='') |
Variables | |
sp = np.finfo(np.float32).eps | |
dp = np.finfo(np.float64).eps | |
parser = argparse.ArgumentParser() | |
help | |
args = parser.parse_args() | |
input_file = args.input_file | |
input_dict = parse_input_file(input_file) | |
dims = int(input_dict['geometry.dims'][0]) | |
nx = np.array([int(w) for w in input_dict['amr.n_cell']]) | |
xmin = np.array([float(w) for w in input_dict['geometry.prob_lo']]) | |
xmax = np.array([float(w) for w in input_dict['geometry.prob_hi']]) | |
tuple | dx = (xmax-xmin) / nx |
lab frame More... | |
int | gamma = 1. |
boosted frame More... | |
beta = np.sqrt(1. - 1./gamma**2) | |
dx_boosted = np.copy(dx) | |
float | cfl = 0.999 |
float | dt = cfl * np.min(dx_boosted) / c |
psatd_order = np.full(shape=dims, fill_value=16) | |
bool | galilean = False |
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 How to run the script: $ python stencil.py --input_file path_to_input_file or, using IPython, $ run stencil.py --input_file path_to_input_file
def stencil.compute_all | ( | dx_boosted, | |
dt, | |||
psatd_order, | |||
v_gal, | |||
nx = None |
|||
) |
Compute nodal and staggered stencils along all directions. Parameters ---------- dx_boosted : np.ndarray (float) Cell size along each direction. dt : float Time step. psatd_order : np.ndarray (int) Spectral order along each direction. v_gal : float Galilean velocity. nx : np.ndarray (int), optional (default = 256 in each direction) Number of mesh points along each direction. Returns ------- stencils : list List of nodal and staggered stencils along all directions.
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 : tuple Min and max number of cells.
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, 2 or -1 (the z axis for both 2D and 3D)). Returns ------- stencils : dictionary Dictionary of nodal and staggered stencils along a given direction.
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.
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.
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.
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.
def stencil.run_main | ( | dims, | |
dx_boosted, | |||
dt, | |||
psatd_order, | |||
gamma = 1. , |
|||
galilean = False , |
|||
path = '.' , |
|||
name = '' |
|||
) |
Main function. Parameters ---------- dims : int Number of dimensions. dx_boosted : numpy.ndarray (float) Cell size along each direction. dt : float Time step. psatd_order : numpy.ndarray (int) Spectral order along each direction. 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.
stencil.args = parser.parse_args() |
stencil.cfl = 0.999 |
stencil.dims = int(input_dict['geometry.dims'][0]) |
stencil.dp = np.finfo(np.float64).eps |
float stencil.dt = cfl * np.min(dx_boosted) / c |
stencil.galilean = False |
stencil.gamma = 1. |
boosted frame
stencil.help |
stencil.input_dict = parse_input_file(input_file) |
stencil.input_file = args.input_file |
stencil.nx = np.array([int(w) for w in input_dict['amr.n_cell']]) |
stencil.parser = argparse.ArgumentParser() |
stencil.psatd_order = np.full(shape=dims, fill_value=16) |
stencil.sp = np.finfo(np.float32).eps |
stencil.xmax = np.array([float(w) for w in input_dict['geometry.prob_hi']]) |
stencil.xmin = np.array([float(w) for w in input_dict['geometry.prob_lo']]) |