Skip to content

Commit 07648ad

Browse files
committed
Geometry.zero_dims method that speeds up the validator for zero-sized geometries
1 parent c3d1b7b commit 07648ad

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77
## [Unreleased]
88

99
### Added
10+
- `Geometry.zero_dims` method that uses `Geometry.bounds` and speeds up the validator for zero-sized geometries.
1011

1112
### Changed
1213
- Limited number of distinct sources to 1000. In cases where a complicated spatial dependence of the source is desired, a ``CustomFieldSource`` or a ``CustomCurrentSource`` can be used instead of multiple distinct sources.

tidy3d/components/geometry/base.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,15 @@ def bounding_box(self):
272272
"""
273273
return Box.from_bounds(*self.bounds)
274274

275+
@cached_property
276+
def zero_dims(self) -> List[Axis]:
277+
"""A list of axes along which the :class:`Geometry` is zero-sized based on its bounds."""
278+
zero_dims = []
279+
for dim in range(3):
280+
if self.bounds[1][dim] == self.bounds[0][dim]:
281+
zero_dims.append(dim)
282+
return zero_dims
283+
275284
def _pop_bounds(self, axis: Axis) -> Tuple[Coordinate2D, Tuple[Coordinate2D, Coordinate2D]]:
276285
"""Returns min and max bounds in plane normal to and tangential to ``axis``.
277286

tidy3d/components/simulation.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -527,11 +527,11 @@ def _validate_2d_geometry_has_2d_medium(cls, val, values):
527527
if isinstance(structure.medium, Medium2D):
528528
continue
529529
for geom in flatten_groups(structure.geometry):
530-
zero_axes = [ind for ind, ele in enumerate(geom.bounding_box.size) if ele == 0.0]
531-
if len(zero_axes) > 0:
530+
zero_dims = geom.zero_dims
531+
if len(zero_dims) > 0:
532532
log.warning(
533533
f"Structure at 'structures[{i}]' has geometry with zero size along "
534-
f"dimensions {zero_axes}, and with a medium that is not a 'Medium2D'. "
534+
f"dimensions {zero_dims}, and with a medium that is not a 'Medium2D'. "
535535
"This is probably not correct, since the resulting simulation will "
536536
"depend on the details of the numerical grid. Consider either "
537537
"giving the geometry a nonzero thickness or using a 'Medium2D'."

0 commit comments

Comments
 (0)