tidy3d.Grid#

class Grid[source]#

Bases: Tidy3dBaseModel

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

Parameters:
  • attrs (dict = {}) – Dictionary storing arbitrary metadata for a Tidy3D object. This dictionary can be freely used by the user for storing data without affecting the operation of Tidy3D as it is not used internally. Note that, unlike regular Tidy3D fields, attrs are mutable. For example, the following is allowed for setting an attr obj.attrs['foo'] = bar. Also note that Tidy3D` will raise a TypeError if attrs contain objects that can not be serialized. One can check if attrs are serializable by calling obj.json().

  • 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.

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.

attrs

Methods

discretize_inds(box[, extend])

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.

Inherited Common Usage

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 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
__getitem__(coord_key)[source]#

quickly get the grid element by grid[key].

discretize_inds(box, extend=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.

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

__hash__()#

Hash method.