From 1840742978a246f81737dad4877dad2b0dca25bd Mon Sep 17 00:00:00 2001 From: Gregory Roberts Date: Thu, 17 Jul 2025 23:58:13 +0200 Subject: [PATCH] fix[adjoint]: update polyslab in simulation bounds check to allow for slabs of zero thickness --- CHANGELOG.md | 3 +++ tidy3d/components/geometry/polyslab.py | 6 ++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2fca4ca471..312b71e26a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Fixed +- Updated the autograd check for if a `PolySlab` is inside the simulation bounds to work when the slab thickness is zero. + ## [2.9.0rc2] - 2025-07-17 ### Added diff --git a/tidy3d/components/geometry/polyslab.py b/tidy3d/components/geometry/polyslab.py index 41a7a2ebf3..8478cb70ec 100644 --- a/tidy3d/components/geometry/polyslab.py +++ b/tidy3d/components/geometry/polyslab.py @@ -1449,11 +1449,13 @@ def _compute_derivatives(self, derivative_info: DerivativeInfo) -> AutogradField sim_min, sim_max = map(np.asarray, derivative_info.bounds_intersect) extents = sim_max - sim_min - is_2d = np.isclose(extents[self.axis], 0.0) + polyslab_2d = np.isclose(np.diff(self.slab_bounds), 0.0) + sim_2d = np.isclose(extents[self.axis], 0.0) + is_2d = polyslab_2d and sim_2d # early return if polyslab is not in simulation domain slab_min, slab_max = self.slab_bounds - if (slab_max <= sim_min[self.axis]) or (slab_min >= sim_max[self.axis]): + if (slab_max < sim_min[self.axis]) or (slab_min > sim_max[self.axis]): log.warning( "'PolySlab' lies completely outside the simulation domain.", log_once=True,