pyLEAFS.grid module
Shared spatial grid.
The domain is a D-dimensional box partitioned into a regular array of cubical
regions of side length L, with periodic (toroidal) boundaries. Every field
and population in a simulation references one Grid, so geometry,
neighbour lookups, and coordinate conventions are defined in exactly one place.
The grid is dimension-agnostic: D = 2 or D = 3 is chosen by the length
of the shape argument. Positions are always (n, D) arrays in physical
units; region indices are (n, D) integer arrays.
- class pyLEAFS.grid.Grid(shape, L=1.0)[source]
Bases:
objectA toroidal box partitioned into cubical regions.
- Parameters:
shape (tuple of int) – Number of regions along each axis, e.g.
(5, 5)for a 2d grid or(5, 5, 5)for 3d. Its length sets the dimensionD.L (float, optional) – Side length of one region in physical units (default 1.0).
- shape
Regions per axis.
- Type:
tuple of int
- D
Spatial dimension.
- Type:
int
- L
Region side length.
- Type:
float
- n_regions
Total number of regions,
prod(shape).- Type:
int
- offsets
Moore-neighbourhood offsets, the centre cell
(0, ..., 0)first.
Examples
>>> g = Grid((5, 5), L=10.0) >>> g.D, g.n_regions (2, 25) >>> g.region_of(np.array([[12.0, 3.0]])) array([[1, 0]])
- region_id(region_idx)[source]
Flatten
(n, D)region indices to linear ids(n,).Uses row-major (C) order consistent with
numpy.ravel_multi_index.