get_hx

emg3d.meshes.get_hx(alpha, domain, nx, x0, resp_domain=True)[source]

Return cell widths for given input.

Find the number of cells left (nl) and right (nr) of the center x0 for the provided alpha. For this, we solve

\[\frac{x_\text{max}-x_0}{x_0-x_\text{min}} = \frac{a^\text{nr}-1}{a^\text{nl}-1}\]

where \(a = 1+\alpha\).

Parameters:
alpha : float

Stretching factor a is given by a=1+alpha.

domain : list

[x_min, x_max] of model domain.

nx : int

Number of cells.

x0 : float

Center of the grid. x0 is restricted to domain.

resp_domain : bool

If False, then the domain-end might shift slightly to assure that the same stretching factor is applied throughout. If set to True (default), however, the domain is respected absolutely. This will introduce one stretch-factor which is different from the other stretch factors, to accommodate the restriction. This one-off factor is between the left- and right-side of x0, or, if x1 is provided, just after x1.

Returns:
hx : ndarray

Cell widths of mesh. All points are given by np.r_[xmin, xmin+np.cumsum(hx)]