Skip to content

Commit d33e683

Browse files
minor edits
1 parent 54127cb commit d33e683

File tree

5 files changed

+29
-53
lines changed

5 files changed

+29
-53
lines changed

tidy3d/components/boundary.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,9 @@ class PortAbsorber(Box):
243243
shift: int = pd.Field(
244244
0,
245245
title="Absorber Shift",
246-
description="Displacement of absorber in the normal positive direction in number of cells.",
246+
description="Displacement of absorber in the normal positive direction in number of cells. "
247+
"This could be used to conveniently place an absorber right behind a source: "
248+
"one can use the same `size` and `center` as for the source and simply set `shift` to 1.",
247249
)
248250

249251
boundary_spec: Union[ModeABCBoundary, ABCBoundary] = pd.Field(

tidy3d/components/eme/simulation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ class EMESimulation(AbstractYeeGridSimulation):
212212
absorbers: tuple[()] = pd.Field(
213213
(),
214214
title="Port Absorbers",
215-
description="Absorbers based on the first order boundary conditions placed inside the computational domain.",
215+
description="Planes with the first order absorbing boundary conditions placed inside the computational domain.",
216216
)
217217

218218
grid_spec: GridSpec = pd.Field(

tidy3d/components/mode/simulation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ class ModeSimulation(AbstractYeeGridSimulation):
171171
absorbers: tuple[()] = pd.Field(
172172
(),
173173
title="Port Absorbers",
174-
description="Absorbers based on the first order boundary conditions placed inside the computational domain.",
174+
description="Planes with the first order absorbing boundary conditions placed inside the computational domain.",
175175
)
176176

177177
grid_spec: GridSpec = pd.Field(

tidy3d/components/simulation.py

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@
113113
Ax,
114114
Axis,
115115
CoordinateOptional,
116+
Direction,
116117
FreqBound,
117118
InterpMethod,
118119
PermittivityComponent,
@@ -368,7 +369,7 @@ class AbstractYeeGridSimulation(AbstractSimulation, ABC):
368369
absorbers: tuple[PortAbsorber, ...] = pydantic.Field(
369370
(),
370371
title="Port Absorbers",
371-
description="Absorbers based on the first order boundary conditions placed inside the computational domain.",
372+
description="Planes with the first order absorbing boundary conditions placed inside the computational domain.",
372373
)
373374

374375
@pydantic.validator("simulation_type", always=True)
@@ -558,6 +559,10 @@ def plot(
558559
Opacity of the monitors. If ``None``, uses Tidy3d default.
559560
lumped_element_alpha : float = None
560561
Opacity of the lumped elements. If ``None``, uses Tidy3d default.
562+
absorber_alpha : float = None
563+
Opacity of the port absorbers. If ``None``, uses Tidy3d default.
564+
absorber_actual_placement : bool = False
565+
Use the exact placement of port absorbers which take into account their ``shift`` values.
561566
ax : matplotlib.axes._subplots.Axes = None
562567
Matplotlib axes to plot on, if not specified, one is created.
563568
hlim : Tuple[float, float] = None
@@ -660,6 +665,10 @@ def plot_eps(
660665
Opacity of the monitors. If ``None``, uses Tidy3d default.
661666
lumped_element_alpha : float = None
662667
Opacity of the lumped elements. If ``None``, uses Tidy3d default.
668+
absorber_alpha : float = None
669+
Opacity of the port absorbers. If ``None``, uses Tidy3d default.
670+
absorber_actual_placement : bool = False
671+
Use the exact placement of port absorbers which take into account their ``shift`` values.
663672
ax : matplotlib.axes._subplots.Axes = None
664673
Matplotlib axes to plot on, if not specified, one is created.
665674
hlim : Tuple[float, float] = None
@@ -2080,8 +2089,15 @@ def _invalidate_solver_cache(self) -> None:
20802089
"""Clear cached attributes that become stale when subpixel changes."""
20812090
self._cached_properties.pop("_mode_solver", None)
20822091

2083-
def _shift_value_signed(self, obj, direction, shift) -> float:
2084-
"""How far (signed) to shift the source from the monitor."""
2092+
def _shift_value_signed(
2093+
self, obj: Box, direction: Direction, shift: int, name: Optional[str] = None
2094+
) -> float:
2095+
"""Calculate the signed distance corresponding to moving the object by ``shift`` number
2096+
of cells in the positive or negative ``direction`` along the dimension given by
2097+
``obj._normal_axis``.
2098+
"""
2099+
if name is None:
2100+
name = f"A '{obj.type}'"
20852101

20862102
# get the grid boundaries and sizes along port normal from the simulation
20872103
normal_axis = obj._normal_axis
@@ -2103,7 +2119,7 @@ def _shift_value_signed(self, obj, direction, shift) -> float:
21032119
shifted_index = port_index + signed_shift
21042120
if shifted_index < 0 or grid_centers[shifted_index] <= self.bounds[0][normal_axis]:
21052121
raise SetupError(
2106-
# f"Port {port.name} normal is less than 2 cells to the boundary "
2122+
f"{name} normal is less than 2 cells to the boundary "
21072123
f"on -{'xyz'[normal_axis]} side. "
21082124
"Please either increase the mesh resolution near the port or "
21092125
"move the port away from the boundary."
@@ -2117,7 +2133,7 @@ def _shift_value_signed(self, obj, direction, shift) -> float:
21172133
or grid_centers[shifted_index] >= self.bounds[1][normal_axis]
21182134
):
21192135
raise SetupError(
2120-
# f"Port {port.name} normal is tless than 2 cells to the boundary "
2136+
f"{name} normal is less than 2 cells to the boundary "
21212137
f"on +{'xyz'[normal_axis]} side."
21222138
"Please either increase the mesh resolution near the port or "
21232139
"move the port away from the boundary."

tidy3d/plugins/smatrix/component_modelers/base.py

Lines changed: 3 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -255,51 +255,9 @@ def inv(matrix: DataArray):
255255
def _shift_value_signed(self, port: Union[Port, WavePort]) -> float:
256256
"""How far (signed) to shift the source from the monitor."""
257257

258-
# get the grid boundaries and sizes along port normal from the simulation
259-
normal_axis = port.size.index(0.0)
260-
grid = self.simulation.grid
261-
grid_boundaries = grid.boundaries.to_list[normal_axis]
262-
grid_centers = grid.centers.to_list[normal_axis]
263-
264-
# get the index of the grid cell where the port lies
265-
port_position = port.center[normal_axis]
266-
port_pos_gt_grid_bounds = np.argwhere(port_position > grid_boundaries)
267-
268-
# no port index can be determined
269-
if len(port_pos_gt_grid_bounds) == 0:
270-
raise SetupError(f"Port position '{port_position}' outside of simulation bounds.")
271-
port_index = port_pos_gt_grid_bounds[-1]
272-
273-
# shift the port to the left
274-
if port.direction == "+":
275-
shifted_index = port_index - 2
276-
if (
277-
shifted_index < 0
278-
or grid_centers[shifted_index] <= self.simulation.bounds[0][normal_axis]
279-
):
280-
raise SetupError(
281-
f"Port {port.name} normal is less than 2 cells to the boundary "
282-
f"on -{'xyz'[normal_axis]} side. "
283-
"Please either increase the mesh resolution near the port or "
284-
"move the port away from the boundary."
285-
)
286-
287-
# shift the port to the right
288-
else:
289-
shifted_index = port_index + 2
290-
if (
291-
shifted_index >= len(grid_centers)
292-
or grid_centers[shifted_index] >= self.simulation.bounds[1][normal_axis]
293-
):
294-
raise SetupError(
295-
f"Port {port.name} normal is tless than 2 cells to the boundary "
296-
f"on +{'xyz'[normal_axis]} side."
297-
"Please either increase the mesh resolution near the port or "
298-
"move the port away from the boundary."
299-
)
300-
301-
new_pos = grid_centers[shifted_index]
302-
return new_pos - port_position
258+
return self.simulation._shift_value_signed(
259+
obj=port, direction=port.direction, shift=-2, name=f"Port {port.name}"
260+
)
303261

304262
def sim_data_by_task_name(self, task_name: str) -> SimulationData:
305263
"""Get the simulation data by task name, avoids emitting warnings from the ``Simulation``."""

0 commit comments

Comments
 (0)