diff --git a/tidy3d/components/simulation.py b/tidy3d/components/simulation.py index 4b3b1e82f0..4d668735aa 100644 --- a/tidy3d/components/simulation.py +++ b/tidy3d/components/simulation.py @@ -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( @@ -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(