Skip to content

Class pylset_grid

Provides the fixed Cartesian grid in 2D or 3D and the boundary conditions along each axis.

Methods:

__init__

__init__(domain_size: Union[List[float], ndarray], ndiv: Union[List[int], ndarray], bc: Sequence[str] = ('Periodic', 'Periodic', 'Periodic')) -> None

Initialize a fixed Cartesian grid in 2D or 3D.

The dimensionality is set by the length of ndiv (2 or 3). Level set values are stored at cell centers, so grid point i along an axis sits at x_i = (i + 0.5)*dx, and interfaces taken from voxel data lie on cell faces.

Parameters:

Name Type Description Default
domain_size array_like of float, shape (ndim,)

Physical size of the domain along each axis, [Lx, Ly] or [Lx, Ly, Lz].

required
ndiv array_like of int, shape (ndim,)

Number of grid points (cells) along each axis, [nx, ny] or [nx, ny, nz].

required
bc sequence of str

Boundary condition along each axis, 'Periodic' or 'Mirror'. Only the first ndim entries are used.

('Periodic', 'Periodic', 'Periodic')

Raises:

Type Description
ValueError

If the dimensionality is not 2 or 3, if domain_size and ndiv differ in length, if any grid size is smaller than 3 or if a boundary condition is not recognized.

get_bc

get_bc() -> List[str]

Get the boundary conditions along each axis.

Returns:

Name Type Description
bc list of str

'PERIODIC' or 'MIRROR' for each axis.

get_coordinates

get_coordinates(axis: int) -> np.ndarray

Get the cell center coordinates along one axis.

Parameters:

Name Type Description Default
axis int

Axis index, 0 for x, 1 for y and 2 for z.

required

Returns:

Name Type Description
x ndarray of float, shape (ndiv[axis],)

Coordinates (i + 0.5)*ddiv[axis].

get_ddiv

get_ddiv() -> np.ndarray

Get the grid spacing along each axis.

Returns:

Name Type Description
ddiv ndarray of float, shape (ndim,)

Grid spacing along each axis.

get_domain_size

get_domain_size() -> np.ndarray

Get the physical size of the domain.

Returns:

Name Type Description
domain_size ndarray of float, shape (ndim,)

Size of the domain along each axis.

get_meshgrid

get_meshgrid() -> List[np.ndarray]

Get cell center coordinate arrays for the full grid.

Returns:

Name Type Description
coords list of ndarray

One array of shape ndiv per axis, with 'ij' indexing.

get_ndim

get_ndim() -> int

Get the dimensionality of the grid.

Returns:

Name Type Description
ndim int

2 or 3.

get_ndiv

get_ndiv() -> np.ndarray

Get the number of grid points along each axis.

Returns:

Name Type Description
ndiv ndarray of int, shape (ndim,)

Number of grid points along each axis.

get_periodic

get_periodic() -> List[bool]

Get a flag for each axis telling whether the axis is periodic.

Returns:

Name Type Description
periodic list of bool

True for periodic axes.

set_bc

set_bc(bc: Sequence[str]) -> None

Set the boundary conditions along each axis.

Parameters:

Name Type Description Default
bc sequence of str

Boundary condition along each axis, 'Periodic' or 'Mirror' (case insensitive). At least ndim entries must be given.

required

Raises:

Type Description
ValueError

If too few entries are given or a boundary condition is not recognized.

set_ndiv

set_ndiv(ndiv: Union[List[int], ndarray]) -> None

Set the number of grid points along each axis, keeping the domain size.

Parameters:

Name Type Description Default
ndiv array_like of int, shape (ndim,)

Number of grid points along each axis.

required

Raises:

Type Description
ValueError

If the number of entries differs from the current dimensionality.