tidy3d.Grid#

class Grid[source]#

Bases: Tidy3dBaseModel

Contains all information about the spatial positions of the FDTD grid.

Parameters:

boundaries (Coords) – x,y,z coordinates of the boundaries between cells, defining the FDTD grid.

Example

>>> x = np.linspace(-1, 1, 10)
>>> y = np.linspace(-1, 1, 11)
>>> z = np.linspace(-1, 1, 12)
>>> coords = Coords(x=x, y=y, z=z)
>>> grid = Grid(boundaries=coords)
>>> centers = grid.centers
>>> sizes = grid.sizes
>>> yee_grid = grid.yee

Attributes

centers

Return centers of the cells in the Grid.

fine_mesh_info

Return locations where cell sizes are minimal or near-minimal.

info

Dictionary collecting various properties of the grids.

max_size

Return maximal cells size in all dimensions.

min_size

Return minimal cells size in all dimensions.

num_cells

Return sizes of the cells in the Grid.

sizes

Return sizes of the cells in the Grid.

yee

Return the YeeGrid defining the yee cell locations for this Grid.

boundaries

Methods

discretize_inds(box[, extend, relax_precision])

Start and stopping indexes for the cells that intersect with a Box.

extended_subspace(axis[, ind_beg, ind_end, ...])

Pick a subspace of 1D boundaries within range(ind_beg, ind_end).

snap_to_box_zero_dim(box)

Snap a grid to an exact box position for dimensions for which the box is size 0.

boundaries#
property centers#

Return centers of the cells in the Grid.

Returns:

centers of the FDTD cells in x,y,z stored as Coords object.

Return type:

Coords

Example

>>> x = np.linspace(-1, 1, 10)
>>> y = np.linspace(-1, 1, 11)
>>> z = np.linspace(-1, 1, 12)
>>> coords = Coords(x=x, y=y, z=z)
>>> grid = Grid(boundaries=coords)
>>> centers = grid.centers
property sizes#

Return sizes of the cells in the Grid.

Returns:

Sizes of the FDTD cells in x,y,z stored as Coords object.

Return type:

Coords

Example

>>> x = np.linspace(-1, 1, 10)
>>> y = np.linspace(-1, 1, 11)
>>> z = np.linspace(-1, 1, 12)
>>> coords = Coords(x=x, y=y, z=z)
>>> grid = Grid(boundaries=coords)
>>> sizes = grid.sizes
property num_cells#

Return sizes of the cells in the Grid.

Returns:

Number of cells in the grid in the x, y, z direction.

Return type:

tuple[int, int, int]

Example

>>> x = np.linspace(-1, 1, 10)
>>> y = np.linspace(-1, 1, 11)
>>> z = np.linspace(-1, 1, 12)
>>> coords = Coords(x=x, y=y, z=z)
>>> grid = Grid(boundaries=coords)
>>> Nx, Ny, Nz = grid.num_cells
property min_size#

Return minimal cells size in all dimensions.

Returns:

Minimal cells size in all dimensions.

Return type:

float

property fine_mesh_info#

Return locations where cell sizes are minimal or near-minimal.

Finds all grid cell centers where the cell size is within MIN_CELL_SIZE_TOLERANCE of the minimum cell size across all dimensions. Skips dimensions where cell sizes are nearly uniform (variation within MIN_CELL_SIZE_TOLERANCE). Returns at most MAX_MIN_SIZE_LOCATIONS entries.

Returns:

Dictionary mapping (dimension, location) tuples to cell sizes. Keys are tuples of (dimension, coordinate) where dimension is ‘x’, ‘y’, or ‘z’ and coordinate is the cell center position. Values are the corresponding cell sizes at those locations. Empty dict if all dimensions are nearly uniform.

Return type:

dict[tuple[str, float], float]

Example

>>> x = np.array([0, 0.01, 0.02, 0.1, 0.2])  # varying cell sizes
>>> y = np.linspace(-1, 1, 11)
>>> z = np.linspace(-1, 1, 12)
>>> coords = Coords(x=x, y=y, z=z)
>>> grid = Grid(boundaries=coords)
>>> min_locs = grid.fine_mesh_info
>>> # Returns dict like {('x', 0.005): 0.01, ('x', 0.015): 0.01, ...}
property max_size#

Return maximal cells size in all dimensions.

Returns:

Maximal cells size in all dimensions.

Return type:

float

property info#

Dictionary collecting various properties of the grids.

property yee#

Return the YeeGrid defining the yee cell locations for this Grid.

Returns:

Stores coordinates of all of the components on the yee lattice.

Return type:

YeeGrid

Example

>>> x = np.linspace(-1, 1, 10)
>>> y = np.linspace(-1, 1, 11)
>>> z = np.linspace(-1, 1, 12)
>>> coords = Coords(x=x, y=y, z=z)
>>> grid = Grid(boundaries=coords)
>>> yee_cells = grid.yee
>>> Ex_positions = yee_cells.E.x
discretize_inds(box, extend=False, relax_precision=False)[source]#

Start and stopping indexes for the cells that intersect with a Box.

Parameters:
  • box (Box) – Rectangular geometry within simulation to discretize.

  • extend (bool = False) – If True, ensure that the returned indexes extend sufficiently in every direction to be able to interpolate any field component at any point within the box, for field components sampled on the Yee grid.

  • relax_precision (bool = False) – If True, relax the precision of the discretization to allow for small numerical differences between the box boundaries and the cell boundaries.

Returns:

The (start, stop) indexes of the cells that intersect with box in each of the three dimensions.

Return type:

list[tuple[int, int]]

extended_subspace(axis, ind_beg=0, ind_end=0, periodic=True)[source]#

Pick a subspace of 1D boundaries within range(ind_beg, ind_end). If any indexes lie outside of the grid boundaries array, padding is used based on the boundary conditions. For periodic BCs, the zeroth and last element of the grid boundaries are identified. For other BCs, the zeroth and last element of the boundaries are a reflection plane.

Parameters:
  • axis (Axis) – Axis index along which to pick the subspace.

  • ind_beg (int = 0) – Starting index for the subspace.

  • ind_end (int = 0) – Ending index for the subspace.

  • periodic (bool = True) – Whether to pad out of bounds indexes with a periodic or reflected pattern.

Returns:

The subspace of the grid along axis.

Return type:

Coords1D

snap_to_box_zero_dim(box)[source]#

Snap a grid to an exact box position for dimensions for which the box is size 0. If the box location is outside of the grid, an error is raised.

Parameters:

box (Box) – Box to use for the zero dim check.

Returns:

class – Snapped copy of the grid.

Return type:

Grid