Skip to content

Commit 2562038

Browse files
minor edits
1 parent b2f4608 commit 2562038

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
@@ -380,51 +380,9 @@ def inv(matrix: DataArray):
380380
def _shift_value_signed(self, port: Union[Port, WavePort]) -> float:
381381
"""How far (signed) to shift the source from the monitor."""
382382

383-
# get the grid boundaries and sizes along port normal from the simulation
384-
normal_axis = port.size.index(0.0)
385-
grid = self.simulation.grid
386-
grid_boundaries = grid.boundaries.to_list[normal_axis]
387-
grid_centers = grid.centers.to_list[normal_axis]
388-
389-
# get the index of the grid cell where the port lies
390-
port_position = port.center[normal_axis]
391-
port_pos_gt_grid_bounds = np.argwhere(port_position > grid_boundaries)
392-
393-
# no port index can be determined
394-
if len(port_pos_gt_grid_bounds) == 0:
395-
raise SetupError(f"Port position '{port_position}' outside of simulation bounds.")
396-
port_index = port_pos_gt_grid_bounds[-1]
397-
398-
# shift the port to the left
399-
if port.direction == "+":
400-
shifted_index = port_index - 2
401-
if (
402-
shifted_index < 0
403-
or grid_centers[shifted_index] <= self.simulation.bounds[0][normal_axis]
404-
):
405-
raise SetupError(
406-
f"Port {port.name} normal is less than 2 cells to the boundary "
407-
f"on -{'xyz'[normal_axis]} side. "
408-
"Please either increase the mesh resolution near the port or "
409-
"move the port away from the boundary."
410-
)
411-
412-
# shift the port to the right
413-
else:
414-
shifted_index = port_index + 2
415-
if (
416-
shifted_index >= len(grid_centers)
417-
or grid_centers[shifted_index] >= self.simulation.bounds[1][normal_axis]
418-
):
419-
raise SetupError(
420-
f"Port {port.name} normal is tless than 2 cells to the boundary "
421-
f"on +{'xyz'[normal_axis]} side."
422-
"Please either increase the mesh resolution near the port or "
423-
"move the port away from the boundary."
424-
)
425-
426-
new_pos = grid_centers[shifted_index]
427-
return new_pos - port_position
383+
return self.simulation._shift_value_signed(
384+
obj=port, direction=port.direction, shift=-2, name=f"Port {port.name}"
385+
)
428386

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

0 commit comments

Comments
 (0)