Skip to content

Commit

Permalink
fixed 2d projection monitor intersection error
Browse files Browse the repository at this point in the history
  • Loading branch information
QimingFlex committed Aug 16, 2024
1 parent 526f04f commit 4588a6e
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion tidy3d/components/simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -2692,6 +2692,15 @@ def _projection_monitors_homogeneous(cls, val, values):
if val is None:
return val

sim_size = values.get("size")

# Validation if is 2D simulation and find the index of 0
is_2d = False
zero_dim_index = None
if sim_size.count(0.0) == 1:
is_2d = True
zero_dim_index = sim_size.index(0.0)

# list of structures including background as a Box()
structure_bg = Structure(
geometry=Box(
Expand All @@ -2707,7 +2716,13 @@ def _projection_monitors_homogeneous(cls, val, values):
with log as consolidated_logger:
for monitor_ind, monitor in enumerate(val):
if isinstance(monitor, (AbstractFieldProjectionMonitor, DiffractionMonitor)):
mediums = Scene.intersecting_media(monitor, total_structures)
if is_2d and zero_dim_index is not None:
modified_size = list(monitor.size)
modified_size[zero_dim_index] = inf
modified_monitor = monitor.updated_copy(size=modified_size)
mediums = Scene.intersecting_media(modified_monitor, total_structures)
else:
mediums = Scene.intersecting_media(monitor, total_structures)
# make sure there is no more than one medium in the returned list
if len(mediums) > 1:
raise SetupError(
Expand Down

0 comments on commit 4588a6e

Please sign in to comment.