GridBase#
- class grids.base.GridBase(coordinate_system: _CoordinateSystemBase, *args, units: Dict[str, str | Unit] | None = None, **kwargs)[source]#
Generic coordinate grid base class from which all PyMetric grid subclasses are descended.
This class serves as the foundational abstraction for all grid types used in PyMetric. It handles setup and storage of coordinate systems, domain dimensions, bounding boxes, boundary conditions, and ghost zones. Subclasses are responsible for implementing actual coordinate logic, spacing behavior, and field interactions.
Subclasses should override the initialization methods to define specific behavior for:
Setting up the coordinate system
Defining the domain and shape of the grid
Configuring boundaries and ghost cells
Notes
This class does not compute or store coordinates directly. It exists to manage the metadata and structure of the computational domain and should be extended to support concrete behavior.
Methods
__init__
(coordinate_system, *args[, units])Initialize a
GridBase
instance.broadcast_array_to_axes
(array, axes_in, ...)Reshape and broadcast an array aligned with axes_in so it is compatible with axes_out.
broadcast_arrays_to_axes
(arrays, axes_in, ...)Broadcast multiple arrays aligned to axes_in so they are compatible with axes_out.
broadcast_shape_to_axes
(shape, axes_in, axes_out)Expand an input shape aligned to axes_in so it is broadcastable against axes_out.
broadcast_shapes_to_axes
(shapes, axes_in, ...)Broadcast multiple input shapes aligned to axes_in so they are compatible with axes_out.
check_field_shape
(array_shape[, axes, ...])Validate that a field array shape is compatible with the grid over the specified axes.
compute_chunk_centers
(chunks[, axes, ...])Return coordinate center arrays for a specific chunk along the selected axes.
compute_chunk_coords
(chunks[, axes, ...])Compute physical coordinate arrays for a selected chunk region.
compute_chunk_edges
(chunks[, axes, ...])Return coordinate edge arrays for a specific chunk along the selected axes.
compute_chunk_mesh
(chunks[, axes, ...])Compute a meshgrid of physical coordinates over a selected chunk region.
compute_chunk_slice
(chunks[, axes, ...])Compute a global index-space slice corresponding to one or more chunks along selected axes, with optional ghost zones and halo padding.
compute_coords_from_index
(index, /[, axes, ...])Compute the physical coordinates at a specific grid index.
compute_coords_from_slices
(slices, /[, ...])Compute coordinate arrays over a region of the grid specified by slice objects.
compute_domain_centers
([axes, origin, ...])Return coordinate center arrays along each axis.
compute_domain_coords
([axes, origin, ...])Compute the 1D coordinate arrays for the full extent of the grid domain along the selected axes.
compute_domain_edges
([axes, origin, ...])Return coordinate edge arrays along each axis.
compute_domain_mesh
([axes, origin, __validate__])Compute a meshgrid of coordinate arrays spanning the full domain of the grid.
compute_domain_slice
([axes, include_ghosts, ...])Compute a slice representing the entire grid domain with some set of axes, halo offsets, and ghost zone behavior.
compute_function_on_grid
(func, /[, ...])Evaluate a coordinate-based function over the grid domain.
compute_mesh_from_slices
(slices, /[, axes, ...])Compute coordinate arrays over a region of the grid specified by slice objects.
construct_chunk_interpolator
(field, ...[, ...])Construct an interpolator for a specific chunk using SciPy's RegularGridInterpolator.
construct_domain_interpolator
(field, field_axes)Construct an interpolator object over the entire grid domain on a particular subset of axes.
dense_adjust_tensor_signature
(tensor_field, ...)Adjust the index signature of a tensor field by raising or lowering multiple indices.
dense_contract_with_metric
(tensor_field, ...)Contract a tensor index with the metric tensor or its inverse.
dense_contravariant_gradient
(tensor_field, ...)Compute the contravariant gradient of a dense-representation tensor field on a grid.
dense_covariant_gradient
(tensor_field, ...)Compute the covariant gradient of a dense-representation tensor field on a grid.
dense_element_wise_laplacian
(field, ...[, ...])Compute the element-wise Laplacian of an array-valued field on the grid.
Compute the element-wise partial derivatives of an array-valued field over the grid.
dense_gradient
(tensor_field, field_axes, /)Compute the element-wise gradient of a tensor field over a grid.
dense_lower_index
(tensor_field, field_axes, ...)Lower a single contravariant index of a tensor field.
dense_raise_index
(tensor_field, field_axes, ...)Raise a single covariant index of a tensor field.
dense_scalar_laplacian
(field, field_axes, /)Compute the element-wise Laplacian of a tensor field.
dense_vector_divergence
(vector_field, ...[, ...])Compute the divergence of a vector field, with automatic basis dispatching.
dense_vector_divergence_contravariant
(...[, ...])Compute the divergence of a contravariant vector field on a grid.
dense_vector_divergence_covariant
(...[, ...])Compute the divergence of a covariant vector field on a grid.
determine_domain_shape
([axes, ...])Compute the shape of the domain along specified axes, including ghost zones and optional halo padding.
empty
([element_shape, axes, include_ghosts, ...])Return an uninitialized array shaped to match a domain-aligned region of the grid.
empty_like_chunks
(chunks, /[, ...])Return an uninitialized array shaped to match a domain-aligned region of the grid.
extract_subgrid
(chunks[, axes, ...])Extract a subgrid (i.e., subdomain) from the current grid using a chunk specification.
from_hdf5
(filename[, group_name])Load a grid instance from an HDF5 file.
full
(fill_value, /[, element_shape, axes, ...])Return a constant-valued array shaped to match a domain-aligned region of the grid.
full_like_chunks
(chunks, fill_value, /[, ...])Return a constant-valued array shaped to match a domain-aligned region of the grid.
get_chunk_bbox
(chunks[, axes, ...])Return the physical bounding box (lower, upper) of a given chunk.
get_chunk_shape
(chunks[, axes, ...])Compute the shape of the buffer corresponding to a given chunk, including optional ghost zones and halo padding.
iter_chunk_coords
([axes, include_ghosts, ...])Efficiently iterate over physical coordinates for each chunk in the grid.
iter_chunk_indices
([axes, pbar, pbar_kwargs])Iterate over chunk indices for the grid along specified axes.
iter_chunk_slices
([axes, include_ghosts, ...])Efficiently iterate over chunk-wise slices in global index space.
ones
([element_shape, axes, include_ghosts, ...])Return an array of ones shaped to match a domain-aligned region of the grid.
ones_like_chunks
(chunks, /[, element_shape, ...])Return an array of ones shaped to match a domain-aligned region of the grid.
plot_chunk_lines
([grid_axes, ax, include_ghosts])Plot chunk boundaries along the specified 2D projection of the domain.
plot_ghost_zone_shading
([grid_axes, ax, ...])Shade the ghost zones in a 2D grid projection.
plot_grid_lines
([grid_axes, ax, include_ghosts])Plot coordinate grid lines along the specified 2D slice of the domain.
show
()Alias for summary() to allow interactive/quick display.
standardize_axes
([axes])Standardize the axes provided.
summary
()Print a summary of the grid structure, including domain shape, chunking, coordinate system, and ghost zone information.
tile_array_to_axes
(array, axes_in, axes_out, ...)Tile a lower-dimensional array across the full domain of the grid defined by axes_out.
to_hdf5
(filename[, group_name, overwrite])Save the grid to an HDF5 file.
zeros
([element_shape, axes, include_ghosts, ...])Return an array of zeros shaped to match a domain-aligned region of the grid.
zeros_like_chunks
(chunks, /[, ...])Return an array of zeros shaped to match a domain-aligned region of the grid.
Attributes
The names of the coordinate axes in this grid.
Units corresponding to each coordinate axis in the grid.
The physical bounding box of the grid (excluding ghost zones).
The shape of a single chunk, expressed in grid points.
Returns whether the grid is cell- or vertex-centered.
The size of each chunk along every axis, if chunking is enabled.
Whether chunking is enabled for this grid.
The coordinate system (e.g. a subclass of
OrthogonalCoordinateSystem
) which underlies this grid.The shape of the active grid (excluding ghost cells), expressed in grid points.
Dictionary of default fill values for each axis.
The full bounding box of the grid, including ghost regions.
The full grid dimensions, including ghost cells.
Number of ghost cells on either side of each axis.
Number of computational cells (excluding ghost zones).
The number of spatial dimensions in the grid.
Number of grid vertices (excluding ghost zones).
The shape of the grid (excluding ghost cells), as a tuple of point counts.
The unit system associated with the grid.