Skip to content

flex_rf.tidy3d.GridSpec

Type: class Base(s): Tidy3dBaseModel

Collective grid specification for all three dimensions.

Practical Advice

When using AutoGrid, the wavelength parameter determines the scale for automatic meshing. If omitted, it is inferred from sources in the simulation. For simulations without sources or where finer control is needed, set it explicitly:

grid_spec = GridSpec.auto(min_steps_per_wvl=20, wavelength=1.55)
uniform = UniformGrid(dl=0.1)
custom = CustomGrid(dl=[0.2, 0.2, 0.1, 0.1, 0.1, 0.2, 0.2])
auto = AutoGrid(min_steps_per_wvl=12)
grid_spec = GridSpec(grid_x=uniform, grid_y=custom, grid_z=auto, wavelength=1.5)
grid_x [GridType] = factory: AutoGrid

Grid specification along x-axis

grid_y [GridType] = factory: AutoGrid

Grid specification along y-axis

grid_z [GridType] = factory: AutoGrid

Grid specification along z-axis

wavelength [PositiveFloat | None] = None

Free-space wavelength for automatic nonuniform grid. It can be None if there is at least one source in the simulation, in which case it is defined by the source central frequency. Note: it only takes effect when at least one of the three dimensions uses AutoGrid.

override_structures [tuple[discriminated_union(StructureType), ...]] = ()

A set of structures that is added on top of the simulation structures in the process of generating the grid. This can be used to refine the grid or make it coarser depending than the expected need for higher/lower resolution regions. Note: it only takes effect when at least one of the three dimensions uses AutoGrid or QuasiUniformGrid.

snapping_points [tuple[CoordinateOptional, ...]] = ()

A set of points that enforce grid boundaries to pass through them. However, some points might be skipped if they are too close. When points are very close to override_structures, snapping_points have higher prioirty so that the structures might be skipped. Note: it only takes effect when at least one of the three dimensions uses AutoGrid or QuasiUniformGrid.

layer_refinement_specs [tuple[LayerRefinementSpec, ...]] = ()

Automatic mesh refinement according to layer specifications. The material distribution is assumed to be uniform inside the layer along the layer axis. Mesh can be refined around corners on the layer cross section, and around upper and lower bounds of the layer.

custom_grid_used [bool]

True if any of the three dimensions uses CustomGrid.

external_override_structures [list[StructureType]]

External supplied override structure list.

override_structures_used [tuple[bool, bool, bool]]

Along each axis, True if any override structure is used. However, it is still False if only MeshOverrideStructure is supplied, and their dl[axis] all take the None value.

snapping_points_used [tuple[bool, bool, bool]]

Along each axis, True if any snapping point is used. However, it is still False if all snapping points take value None along the axis.

all_override_structures(structures: list[Structure], wavelength: PositiveFloat, lumped_elements: list[LumpedElementType], boundary_types: tuple[tuple[str, str], tuple[str, str], tuple[str, str]], sim_bounds: tuple, structure_priority_mode: PriorityMode = 'equal', internal_override_structures: list[MeshOverrideStructure] | None = None)

Internal and external mesh override structures sorted based on their priority. By default, the priority of internal override structures is -1, and 0 for external ones.

all_snapping_points(structures: list[Structure], lumped_elements: list[LumpedElementType], boundary_types: tuple[tuple[str, str], tuple[str, str], tuple[str, str]], sim_bounds: tuple, internal_snapping_points: list[CoordinateOptional] | None = None)

Internal and external snapping points. External snapping points take higher priority. So far, internal snapping points are generated by layer_refinement_specs.

auto(wavelength: PositiveFloat = None, min_steps_per_wvl: PositiveFloat = 10.0, max_scale: PositiveFloat = 1.4, override_structures: list[StructureType] = (), snapping_points: tuple[CoordinateOptional, ...] = (), layer_refinement_specs: list[LayerRefinementSpec] = (), dl_min: NonNegativeFloat = 0.0, min_steps_per_sim_size: PositiveFloat = 10.0, mesher: MesherType = Undefined)

Use the same AutoGrid along each of the three directions.

auto_grid_used()

True if any of the three dimensions uses AutoGrid.

from_grid(grid: Grid)

Import grid directly from another simulation, e.g. grid_spec = GridSpec.from_grid(sim.grid).

get_wavelength(sources: list[SourceType])

Get wavelength for automatic mesh generation if needed.

internal_override_structures(structures: list[Structure], wavelength: PositiveFloat, sim_bounds: tuple, lumped_elements: list[LumpedElementType], boundary_types: tuple[tuple[str, str], tuple[str, str], tuple[str, str]], cached_corners_and_convexity: list[CornersAndConvexity] | None = None, cached_merged_geos: list[tuple[Any, Shapely]] | None = None)

Internal mesh override structures. So far, internal override structures are generated by layer_refinement_specs and lumped element.

internal_snapping_points(structures: list[Structure], lumped_elements: list[LumpedElementType], boundary_types: tuple[tuple[str, str], tuple[str, str], tuple[str, str]], sim_bounds: tuple, cached_corners_and_convexity: list[CornersAndConvexity] | None = None, cached_merged_geos: list[tuple[Any, Shapely]] | None = None)

Internal snapping points. So far, internal snapping points are generated by layer_refinement_specs and lumped element.

layer_refinement_used()

Whether layer_refiement_specs are applied.

make_grid(structures: list[Structure], symmetry: tuple[Symmetry, Symmetry, Symmetry], periodic: tuple[bool, bool, bool], sources: list[SourceType], num_pml_layers: list[tuple[NonNegativeInt, NonNegativeInt]], lumped_elements: list[LumpedElementType] = (), internal_override_structures: list[MeshOverrideStructure] | None = None, internal_snapping_points: list[CoordinateOptional] | None = None, boundary_types: tuple[tuple[str, str], tuple[str, str], tuple[str, str]] = [[None, None], [None, None], [None, None]], structure_priority_mode: PriorityMode = 'equal')

Make the entire simulation grid based on some simulation parameters.

quasiuniform(dl: float, max_scale: PositiveFloat = 1.4, override_structures: list[StructureType] = (), snapping_points: tuple[CoordinateOptional, ...] = (), mesher: MesherType = Undefined)

Use the same QuasiUniformGrid along each of the three directions.

snapped_grid_used()

True if any of the three dimensions uses AbstractAutoGrid that will adjust grid with snapping points and geometry boundaries.

uniform(dl: float)

Use the same UniformGrid along each of the three directions.

wavelength_from_sources(sources: list[SourceType])

Define a wavelength based on supplied sources. Called if auto mesh is used and self.wavelength is None.