Grid¶
Functions for creating regular grids of cell centers in 1D, 2D, and 3D domains.
- smudgy.grid.create_grid_1d(n_cells: int, boxsize: float | Sequence[float] | ArrayLike) ndarray[tuple[Any, ...], dtype[float32]][source]¶
Generate 1D grid cell centers. Calls
create_grid_ndwith 1D parameters.- Parameters:
n_cells – Number of cells along the axis.
boxsize – Physical size of the domain (scalar).
- Returns:
Float32 array of shape
(n_cells, 1)with cell-center coordinates.- Return type:
numpy.ndarray
- smudgy.grid.create_grid_2d(n_cells: int | Sequence[int] | ArrayLike, boxsize: float | Sequence[float] | ArrayLike) ndarray[tuple[Any, ...], dtype[float32]][source]¶
Generate 2D grid cell centers. Calls
create_grid_ndwith 2D parameters.- Parameters:
n_cells – Scalar or
(2,)iterable with counts per axis.boxsize – Scalar or
(2,)iterable with domain lengths.
- Returns:
Float32 array of shape
(n_cells[0] * n_cells[1], 2)containing cell centers.- Return type:
numpy.ndarray
- smudgy.grid.create_grid_3d(n_cells: int | Sequence[int] | ArrayLike, boxsize: float | Sequence[float] | ArrayLike) ndarray[tuple[Any, ...], dtype[float32]][source]¶
Generate 3D grid cell centers. Calls
create_grid_ndwith 3D parameters.- Parameters:
n_cells – Scalar or
(3,)iterable with counts per axis.boxsize – Scalar or
(3,)iterable with domain lengths.
- Returns:
Float32 array of shape
(n_cells[0] * n_cells[1] * n_cells[2], 3)containing cell centers.- Return type:
numpy.ndarray
- smudgy.grid.grid_lines(edges, nx, ny=None, include_edges=True)[source]¶
Create 2D grid lines for plotting.
- Parameters:
edges – Tuple of (xmin, xmax, ymin, ymax) defining the rectangular domain.
nx – Number of vertical lines to draw.
ny – Number of horizontal lines to draw. If None, defaults to nx.
include_edges – If True, lines include the edges (using np.linspace); if False, lines are interior-only (exclude endpoints).
- Returns:
(vlines, hlines, (xmin, xmax, ymin, ymax)) where vlines and hlines are 1D arrays of line positions.
- Return type:
tuple