tidy3d.Grid#
- class Grid[source]#
Bases:
Tidy3dBaseModelContains 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
Return centers of the cells in the
Grid.Return locations where cell sizes are minimal or near-minimal.
Dictionary collecting various properties of the grids.
Return maximal cells size in all dimensions.
Return minimal cells size in all dimensions.
Return sizes of the cells in the
Grid.Return sizes of the cells in the
Grid.Return the
YeeGriddefining the yee cell locations for thisGrid.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.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.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.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:
- 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_TOLERANCEof the minimum cell size across all dimensions. Skips dimensions where cell sizes are nearly uniform (variation withinMIN_CELL_SIZE_TOLERANCE). Returns at mostMAX_MIN_SIZE_LOCATIONSentries.- 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:
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:
- property info#
Dictionary collecting various properties of the grids.
- property yee#
Return the
YeeGriddefining the yee cell locations for thisGrid.- Returns:
Stores coordinates of all of the components on the yee lattice.
- Return type:
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 thebox, 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
boxin each of the three dimensions.- Return type:
- 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