get_stretched_h

emg3d.meshes.get_stretched_h(min_width, domain, nx, x0=0, x1=None, resp_domain=False)[source]

Return cell widths for a stretched grid within the domain.

Returns nx cell widths within domain, where the minimum cell width is min_width. The cells are not stretched within x0 and x1, and outside uses a power-law stretching. The actual stretching factor and the number of cells left and right of x0 and x1 are found in a minimization process.

The domain is not completely respected. The starting point of the domain is, but the endpoint of the domain might slightly shift (this is more likely the case for small nx, for big nx the shift should be small). The new endpoint can be obtained with domain[0]+np.sum(hx). If you want the domain to be respected absolutely, set resp_domain=True. However, be aware that 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.

Parameters:
min_width : float

Minimum cell width. If x1 is provided, the actual minimum cell width might be smaller than min_width.

domain : list

[start, end] of model domain.

nx : int

Number of cells.

x0 : float

Center of the grid. x0 is restricted to domain. Default is 0.

x1 : float

If provided, then no stretching is applied between x0 and x1. The non-stretched part starts at x0 and stops at the first possible location at or after x1. x1 is restricted to domain. This will min_width so that an integer number of cells fit within x0 and x1.

resp_domain : bool

If False (default), then the domain-end might shift slightly to assure that the same stretching factor is applied throughout. If set to True, 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.

See also

get_hx_x0
Get hx and x0 for a flexible number of nx with given bounds.