tidy3d.GridSpec#
- class GridSpec[source]#
Bases:
Tidy3dBaseModelCollective grid specification for all three dimensions.
- 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,
attrsare mutable. For example, the following is allowed for setting anattrobj.attrs['foo'] = bar. Also note that Tidy3D` will raise aTypeErrorifattrscontain objects that can not be serialized. One can check ifattrsare serializable by callingobj.json().grid_x (Union[UniformGrid, CustomGrid, AutoGrid, CustomGridBoundaries, QuasiUniformGrid] = AutoGrid(attrs={}, type='AutoGrid', max_scale=1.4, mesher=GradedMesher(attrs={},, type='GradedMesher'), dl_min=None, min_steps_per_wvl=10.0, min_steps_per_sim_size=10.0)) – Grid specification along x-axis
grid_y (Union[UniformGrid, CustomGrid, AutoGrid, CustomGridBoundaries, QuasiUniformGrid] = AutoGrid(attrs={}, type='AutoGrid', max_scale=1.4, mesher=GradedMesher(attrs={},, type='GradedMesher'), dl_min=None, min_steps_per_wvl=10.0, min_steps_per_sim_size=10.0)) – Grid specification along y-axis
grid_z (Union[UniformGrid, CustomGrid, AutoGrid, CustomGridBoundaries, QuasiUniformGrid] = AutoGrid(attrs={}, type='AutoGrid', max_scale=1.4, mesher=GradedMesher(attrs={},, type='GradedMesher'), dl_min=None, min_steps_per_wvl=10.0, min_steps_per_sim_size=10.0)) – Grid specification along z-axis
wavelength (Optional[float] = None) – [units = um]. 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[Annotated[Union[tidy3d.components.structure.Structure, tidy3d.components.structure.MeshOverrideStructure], FieldInfo(default=PydanticUndefined, discriminator='type', extra={})], ...] = ()) – 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
AutoGridorQuasiUniformGrid.snapping_points (Tuple[Tuple[float, float, float], ...] = ()) – 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
AutoGridorQuasiUniformGrid.
Example
>>> 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)
See also
UniformGridUniform 1D grid.
AutoGridSpecification for non-uniform grid along a given dimension.
- Notebooks:
- Lectures:
Attributes
True if any of the three dimensions uses
AutoGrid.True if any of the three dimensions uses
CustomGrid.Along each axis,
Trueif any override structure is used.Methods
auto([wavelength, min_steps_per_wvl, ...])Use the same
AutoGridalong each of the three directions.from_grid(grid)Import grid directly from another simulation, e.g.
grid_spec = GridSpec.from_grid(sim.grid).make_grid(structures, symmetry, periodic, ...)Make the entire simulation grid based on some simulation parameters.
quasiuniform(dl[, max_scale, ...])Use the same
QuasiUniformGridalong each of the three directions.uniform(dl)Use the same
UniformGridalong each of the three directions.wavelength_from_sources(sources)Define a wavelength based on supplied sources.
Inherited Common Usage
- grid_x#
- grid_y#
- grid_z#
- wavelength#
- override_structures#
- snapping_points#
- property custom_grid_used#
True if any of the three dimensions uses
CustomGrid.
- static wavelength_from_sources(sources)[source]#
Define a wavelength based on supplied sources. Called if auto mesh is used and
self.wavelength is None.
- property override_structures_used#
Along each axis,
Trueif any override structure is used. However, it is stillFalseif onlyMeshOverrideStructureis supplied, and theirdl[axis]all take theNonevalue.
- make_grid(structures, symmetry, periodic, sources, num_pml_layers)[source]#
Make the entire simulation grid based on some simulation parameters.
- Parameters:
structures (List[Structure]) – List of structures present in the simulation. The first structure must be the simulation geometry with the simulation background medium.
symmetry (Tuple[Symmetry, Symmetry, Symmetry]) – Reflection symmetry across a plane bisecting the simulation domain normal to each of the three axes.
sources (List[SourceType]) – List of sources.
num_pml_layers (List[Tuple[float, float]]) – List containing the number of absorber layers in - and + boundaries.
- Returns:
Entire simulation grid.
- Return type:
- classmethod from_grid(grid)[source]#
Import grid directly from another simulation, e.g.
grid_spec = GridSpec.from_grid(sim.grid).
- classmethod auto(wavelength=None, min_steps_per_wvl=10.0, max_scale=1.4, override_structures=(), snapping_points=(), dl_min=0.0, min_steps_per_sim_size=10.0, mesher=GradedMesher(attrs={}, type='GradedMesher'))[source]#
Use the same
AutoGridalong each of the three directions.- Parameters:
wavelength (pd.PositiveFloat, optional) – 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.
min_steps_per_wvl (pd.PositiveFloat, optional) – Minimal number of steps per wavelength in each medium.
max_scale (pd.PositiveFloat, optional) – Sets the maximum ratio between any two consecutive grid steps.
override_structures (List[StructureType]) – A list 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.
snapping_points (Tuple[Coordinate, ...]) – A set of points that enforce grid boundaries to pass through them.
dl_min (pd.NonNegativeFloat) – Lower bound of grid size.
min_steps_per_sim_size (pd.PositiveFloat, optional) – Minimal number of steps per longest edge length of simulation domain.
mesher (MesherType = GradedMesher()) – The type of mesher to use to generate the grid automatically.
- Returns:
GridSpecwith the same automatic nonuniform grid settings in each direction.- Return type:
- classmethod uniform(dl)[source]#
Use the same
UniformGridalong each of the three directions.
- classmethod quasiuniform(dl, max_scale=1.4, override_structures=(), snapping_points=(), mesher=GradedMesher(attrs={}, type='GradedMesher'))[source]#
Use the same
QuasiUniformGridalong each of the three directions.- Parameters:
dl (float) – Grid size for quasi-uniform grid generation.
max_scale (pd.PositiveFloat, optional) – Sets the maximum ratio between any two consecutive grid steps.
override_structures (List[StructureType]) – A list of structures that is added on top of the simulation structures in the process of generating the grid. This can be used to snap grid points to the bounding box boundary.
snapping_points (Tuple[Coordinate, ...]) – A set of points that enforce grid boundaries to pass through them.
mesher (MesherType = GradedMesher()) – The type of mesher to use to generate the grid automatically.
- Returns:
GridSpecwith the same uniform grid size in each direction.- Return type:
- __hash__()#
Hash method.