Skip to content

Commit b8cd3b1

Browse files
PR comments
1 parent 97fab18 commit b8cd3b1

File tree

4 files changed

+42
-57
lines changed

4 files changed

+42
-57
lines changed

tests/test_components/test_layerrefinement.py

+3-11
Original file line numberDiff line numberDiff line change
@@ -369,9 +369,7 @@ def test_dl_min_from_smallest_feature():
369369
axis=2,
370370
size=(td.inf, td.inf, 2),
371371
corner_finder=td.CornerFinderSpec(
372-
dl_min_spec=td.SmallestFeatureSpec(
373-
convex_resolution=10, concave_resolution=0, mixed_resolution=0
374-
)
372+
convex_resolution=10,
375373
),
376374
)
377375
dl_min = layer_spec._dl_min_from_smallest_feature([structure])
@@ -380,11 +378,7 @@ def test_dl_min_from_smallest_feature():
380378
layer_spec = td.LayerRefinementSpec(
381379
axis=2,
382380
size=(td.inf, td.inf, 2),
383-
corner_finder=td.CornerFinderSpec(
384-
dl_min_spec=td.SmallestFeatureSpec(
385-
convex_resolution=0, concave_resolution=0, mixed_resolution=10
386-
)
387-
),
381+
corner_finder=td.CornerFinderSpec(mixed_resolution=10),
388382
)
389383
dl_min = layer_spec._dl_min_from_smallest_feature([structure])
390384
assert np.allclose(0.2 / 10, dl_min)
@@ -393,9 +387,7 @@ def test_dl_min_from_smallest_feature():
393387
axis=2,
394388
size=(td.inf, td.inf, 2),
395389
corner_finder=td.CornerFinderSpec(
396-
dl_min_spec=td.SmallestFeatureSpec(
397-
convex_resolution=0, concave_resolution=10, mixed_resolution=0
398-
)
390+
concave_resolution=10,
399391
),
400392
)
401393
dl_min = layer_spec._dl_min_from_smallest_feature([structure])

tidy3d/__init__.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@
201201
from .components.geometry.mesh import TriangleMesh
202202
from .components.geometry.polyslab import PolySlab
203203
from .components.geometry.primitives import Cylinder, Sphere
204-
from .components.grid.corner_finder import CornerFinderSpec, SmallestFeatureSpec
204+
from .components.grid.corner_finder import CornerFinderSpec
205205
from .components.grid.grid import Coords, Coords1D, FieldGrid, Grid, YeeGrid
206206
from .components.grid.grid_spec import (
207207
AutoGrid,
@@ -402,7 +402,6 @@ def set_logging_level(level: str) -> None:
402402
"LayerRefinementSpec",
403403
"GridRefinement",
404404
"CornerFinderSpec",
405-
"SmallestFeatureSpec",
406405
"Box",
407406
"Sphere",
408407
"Cylinder",

tidy3d/components/grid/corner_finder.py

+29-35
Original file line numberDiff line numberDiff line change
@@ -16,36 +16,6 @@
1616
CORNER_ANGLE_THRESOLD = 0.1 * np.pi
1717

1818

19-
class SmallestFeatureSpec(Tidy3dBaseModel):
20-
"""Specification for automatic detection of smallest geometric features in layered structures."""
21-
22-
concave_resolution: pd.NonNegativeInt = pd.Field(
23-
2,
24-
title="Concave Region Resolution.",
25-
description="Specifies number of steps to use for determining `dl_min` based on concave featues."
26-
"If set to 0, then the corresponding `dl_min` reduction is not applied.",
27-
)
28-
convex_resolution: pd.NonNegativeInt = pd.Field(
29-
0,
30-
title="Concave Region Resolution.",
31-
description="Specifies number of steps to use for determining `dl_min` based on convex featues."
32-
"If set to 0, then the corresponding `dl_min` reduction is not applied.",
33-
)
34-
35-
mixed_resolution: pd.NonNegativeInt = pd.Field(
36-
0,
37-
title="Concave Region Resolution.",
38-
description="Specifies number of steps to use for determining `dl_min` based on mixed featues."
39-
"If set to 0, then the corresponding `dl_min` reduction is not applied.",
40-
)
41-
42-
@cached_property
43-
def _no_restriction(self):
44-
return not any(
45-
(self.concave_resolution != 0, self.convex_resolution != 0, self.mixed_resolution != 0)
46-
)
47-
48-
4919
class CornerFinderSpec(Tidy3dBaseModel):
5020
"""Specification for corner detection on a 2D plane."""
5121

@@ -74,13 +44,37 @@ class CornerFinderSpec(Tidy3dBaseModel):
7444
"is below the threshold value based on Douglas-Peucker algorithm, the vertex is disqualified as a corner.",
7545
)
7646

77-
dl_min_spec: SmallestFeatureSpec = pd.Field(
78-
SmallestFeatureSpec(),
79-
title="Automatic `dl_min` Reduction",
80-
description="Specfication for automatic reduction of global `dl_min` based on "
81-
"autodetected smallest features.",
47+
concave_resolution: Optional[pd.PositiveInt] = pd.Field(
48+
2,
49+
title="Concave Region Resolution.",
50+
description="Specifies number of steps to use for determining `dl_min` based on concave featues."
51+
"If set to ``None``, then the corresponding `dl_min` reduction is not applied.",
52+
)
53+
54+
convex_resolution: Optional[pd.PositiveInt] = pd.Field(
55+
None,
56+
title="Convex Region Resolution.",
57+
description="Specifies number of steps to use for determining `dl_min` based on convex featues."
58+
"If set to ``None``, then the corresponding `dl_min` reduction is not applied.",
8259
)
8360

61+
mixed_resolution: Optional[pd.PositiveInt] = pd.Field(
62+
None,
63+
title="Mixed Region Resolution.",
64+
description="Specifies number of steps to use for determining `dl_min` based on mixed featues."
65+
"If set to ``None``, then the corresponding `dl_min` reduction is not applied.",
66+
)
67+
68+
@cached_property
69+
def _no_min_dl_override(self):
70+
return all(
71+
(
72+
self.concave_resolution is None,
73+
self.convex_resolution is None,
74+
self.mixed_resolution is None,
75+
)
76+
)
77+
8478
def _corners_and_convexity(
8579
self,
8680
normal_axis: Axis,

tidy3d/components/grid/grid_spec.py

+9-9
Original file line numberDiff line numberDiff line change
@@ -1295,7 +1295,7 @@ def suggested_dl_min(self, grid_size_in_vacuum: float, structures: List[Structur
12951295
dl_min = min(dl_min, self.corner_refinement._grid_size(grid_size_in_vacuum))
12961296

12971297
# min feature size
1298-
if self.corner_finder is not None and not self.corner_finder.dl_min_spec._no_restriction:
1298+
if self.corner_finder is not None and not self.corner_finder._no_min_dl_override:
12991299
dl_suggested = self._dl_min_from_smallest_feature(structures)
13001300
dl_min = min(dl_min, dl_suggested)
13011301

@@ -1375,32 +1375,32 @@ def _dl_min_from_smallest_feature(self, structure_list: List[Structure]):
13751375

13761376
dl_min = inf
13771377

1378-
if self.corner_finder is None or self.corner_finder.dl_min_spec._no_restriction:
1378+
if self.corner_finder is None or self.corner_finder._no_min_dl_override:
13791379
return dl_min
13801380

1381-
dl_min_spec = self.corner_finder.dl_min_spec
1381+
finder = self.corner_finder
13821382

13831383
for points, conv in zip(inplane_points, convexity):
13841384
conv_nei = np.roll(conv, -1)
13851385
lengths = np.linalg.norm(points - np.roll(points, axis=0, shift=-1), axis=-1)
13861386

1387-
if dl_min_spec.convex_resolution > 0:
1387+
if finder.convex_resolution is not None:
13881388
convex_features = np.logical_and(conv, conv_nei)
13891389
if np.any(convex_features):
13901390
min_convex_size = np.min(lengths[convex_features])
1391-
dl_min = min(dl_min, min_convex_size / dl_min_spec.convex_resolution)
1391+
dl_min = min(dl_min, min_convex_size / finder.convex_resolution)
13921392

1393-
if dl_min_spec.concave_resolution > 0:
1393+
if finder.concave_resolution is not None:
13941394
concave_features = np.logical_not(np.logical_or(conv, conv_nei))
13951395
if np.any(concave_features):
13961396
min_concave_size = np.min(lengths[concave_features])
1397-
dl_min = min(dl_min, min_concave_size / dl_min_spec.concave_resolution)
1397+
dl_min = min(dl_min, min_concave_size / finder.concave_resolution)
13981398

1399-
if dl_min_spec.mixed_resolution > 0:
1399+
if finder.mixed_resolution is not None:
14001400
mixed_features = np.logical_xor(conv, conv_nei)
14011401
if np.any(mixed_features):
14021402
min_mixed_size = np.min(lengths[mixed_features])
1403-
dl_min = min(dl_min, min_mixed_size / dl_min_spec.mixed_resolution)
1403+
dl_min = min(dl_min, min_mixed_size / finder.mixed_resolution)
14041404

14051405
return dl_min
14061406

0 commit comments

Comments
 (0)