Skip to content

Commit 2156051

Browse files
committed
Set minimum PML layers to 6
1 parent 2490f92 commit 2156051

File tree

6 files changed

+61
-56
lines changed

6 files changed

+61
-56
lines changed

CHANGELOG.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1515
- `@scalar_objective` decorator in `tidy3d.plugins.autograd` that wraps objective functions to ensure they return a scalar value and performs additional checks to ensure compatibility of objective functions with autograd. Used by default in `tidy3d.plugins.autograd.value_and_grad` as well as `tidy3d.plugins.autograd.grad`.
1616
- Autograd support for simulations without adjoint sources in `run` as well as `run_async`, which will not attempt to run the simulation but instead return zero gradients. This can sometimes occur if the objective function gradient does not depend on some simulations, for example when using `min` or `max` in the objective.
1717

18-
1918
### Changed
2019
- `CustomMedium` design regions require far less data when performing inverse design by reducing adjoint field monitor size for dims with one pixel.
21-
- Calling `.values` on `DataArray` no longer raises a `DeprecationWarning` during automatic differentiation
20+
- Calling `.values` on `DataArray` no longer raises a `DeprecationWarning` during automatic differentiation.
21+
- Minimum number of PML layers set to 6.
2222

2323
### Fixed
2424
- Regression in local field projection leading to incorrect results for `far_field_approx=True`.

tests/test_components/test_grid.py

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ def test_sim_nonuniform_small():
108108
# tests when the nonuniform grid does not cover the simulation size
109109

110110
size_x = 18
111-
num_layers_pml_x = 2
111+
num_layers_pml_x = 6
112112
grid_size_x = [2, 1, 3]
113113
sim = td.Simulation(
114114
center=(1, 0, 0),
@@ -153,15 +153,12 @@ def test_sim_nonuniform_small():
153153
for dl in dls:
154154
assert dl in grid_size_x
155155

156-
# tests that it gives exactly what we expect
157-
assert np.all(bound_coords == np.array([-12, -10, -8, -6, -4, -2, 0, 1, 4, 7, 10, 13, 16]))
158-
159156

160157
def test_sim_nonuniform_large():
161158
# tests when the nonuniform grid extends beyond the simulation size
162159

163160
size_x = 18
164-
num_layers_pml_x = 2
161+
num_layers_pml_x = 6
165162
grid_size_x = [2, 3, 4, 1, 2, 1, 3, 1, 2, 3, 4]
166163
sim = td.Simulation(
167164
center=(1, 0, 0),
@@ -230,9 +227,9 @@ def test_sim_symmetry_grid():
230227
size=(11, 11, 11),
231228
grid_spec=td.GridSpec(grid_x=grid_1d, grid_y=grid_1d, grid_z=grid_1d),
232229
boundary_spec=td.BoundarySpec(
233-
x=td.Boundary.pml(num_layers=2),
234-
y=td.Boundary.pml(num_layers=2),
235-
z=td.Boundary.pml(num_layers=2),
230+
x=td.Boundary.pml(num_layers=6),
231+
y=td.Boundary.pml(num_layers=6),
232+
z=td.Boundary.pml(num_layers=6),
236233
),
237234
symmetry=(0, 1, -1),
238235
run_time=1e-12,
@@ -257,20 +254,20 @@ def test_sim_pml_grid():
257254
size=(4, 4, 4),
258255
grid_spec=td.GridSpec.uniform(1.0),
259256
boundary_spec=td.BoundarySpec(
260-
x=td.Boundary.pml(num_layers=2),
261-
y=td.Boundary.absorber(num_layers=2),
262-
z=td.Boundary.stable_pml(num_layers=2),
257+
x=td.Boundary.pml(num_layers=6),
258+
y=td.Boundary.absorber(num_layers=6),
259+
z=td.Boundary.stable_pml(num_layers=6),
263260
),
264261
run_time=1e-12,
265262
)
266263

267264
for dim in "xyz":
268265
c = sim.grid.centers.dict()[dim]
269-
assert np.all(c == np.array([-3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5]))
266+
assert np.all(c == np.arange(-7.5, 8, 1))
270267

271268
for dim in "xyz":
272269
b = sim.grid.boundaries.dict()[dim]
273-
assert np.all(b == np.array([-4, -3, -2, -1, 0, 1, 2, 3, 4]))
270+
assert np.all(b == np.arange(-8, 8.5, 1))
274271

275272

276273
def test_sim_discretize_vol():

tests/test_components/test_grid_spec.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -171,9 +171,9 @@ def test_autogrid_2dmaterials():
171171
structures=[box],
172172
sources=[src],
173173
boundary_spec=td.BoundarySpec(
174-
x=td.Boundary.pml(num_layers=5),
175-
y=td.Boundary.pml(num_layers=5),
176-
z=td.Boundary.pml(num_layers=5),
174+
x=td.Boundary.pml(num_layers=6),
175+
y=td.Boundary.pml(num_layers=6),
176+
z=td.Boundary.pml(num_layers=6),
177177
),
178178
grid_spec=td.GridSpec.auto(),
179179
run_time=1e-12,
@@ -192,9 +192,9 @@ def test_autogrid_2dmaterials():
192192
structures=[box2],
193193
sources=[src],
194194
boundary_spec=td.BoundarySpec(
195-
x=td.Boundary.pml(num_layers=5),
196-
y=td.Boundary.pml(num_layers=5),
197-
z=td.Boundary.pml(num_layers=5),
195+
x=td.Boundary.pml(num_layers=6),
196+
y=td.Boundary.pml(num_layers=6),
197+
z=td.Boundary.pml(num_layers=6),
198198
),
199199
grid_spec=td.GridSpec.auto(),
200200
run_time=1e-12,
@@ -211,9 +211,9 @@ def test_autogrid_2dmaterials():
211211
structures=[box, box2],
212212
sources=[src],
213213
boundary_spec=td.BoundarySpec(
214-
x=td.Boundary.pml(num_layers=5),
215-
y=td.Boundary.pml(num_layers=5),
216-
z=td.Boundary.pml(num_layers=5),
214+
x=td.Boundary.pml(num_layers=6),
215+
y=td.Boundary.pml(num_layers=6),
216+
z=td.Boundary.pml(num_layers=6),
217217
),
218218
grid_spec=td.GridSpec.auto(),
219219
run_time=1e-12,

tests/test_components/test_simulation.py

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -832,9 +832,9 @@ def test_sim_structure_gap(log_capture, box_size, log_level):
832832
structures=[box],
833833
sources=[src],
834834
boundary_spec=td.BoundarySpec(
835-
x=td.Boundary.pml(num_layers=5),
836-
y=td.Boundary.pml(num_layers=5),
837-
z=td.Boundary.pml(num_layers=5),
835+
x=td.Boundary.pml(num_layers=6),
836+
y=td.Boundary.pml(num_layers=6),
837+
z=td.Boundary.pml(num_layers=6),
838838
),
839839
run_time=1e-12,
840840
)
@@ -2047,9 +2047,9 @@ def test_sim_volumetric_structures(log_capture, tmp_path):
20472047
structures=[struct],
20482048
sources=[src],
20492049
boundary_spec=td.BoundarySpec(
2050-
x=td.Boundary.pml(num_layers=5),
2051-
y=td.Boundary.pml(num_layers=5),
2052-
z=td.Boundary.pml(num_layers=5),
2050+
x=td.Boundary.pml(num_layers=6),
2051+
y=td.Boundary.pml(num_layers=6),
2052+
z=td.Boundary.pml(num_layers=6),
20532053
),
20542054
grid_spec=td.GridSpec.uniform(dl=grid_dl),
20552055
run_time=1e-12,
@@ -2089,9 +2089,9 @@ def test_sim_volumetric_structures(log_capture, tmp_path):
20892089
sources=[src],
20902090
monitors=[monitor],
20912091
boundary_spec=td.BoundarySpec(
2092-
x=td.Boundary.pml(num_layers=5),
2093-
y=td.Boundary.pml(num_layers=5),
2094-
z=td.Boundary.pml(num_layers=5),
2092+
x=td.Boundary.pml(num_layers=6),
2093+
y=td.Boundary.pml(num_layers=6),
2094+
z=td.Boundary.pml(num_layers=6),
20952095
),
20962096
grid_spec=td.GridSpec.uniform(dl=grid_dl),
20972097
run_time=1e-12,
@@ -2114,9 +2114,9 @@ def test_sim_volumetric_structures(log_capture, tmp_path):
21142114
sources=[src],
21152115
monitors=[monitor],
21162116
boundary_spec=td.BoundarySpec(
2117-
x=td.Boundary.pml(num_layers=5),
2118-
y=td.Boundary.pml(num_layers=5),
2119-
z=td.Boundary.pml(num_layers=5),
2117+
x=td.Boundary.pml(num_layers=6),
2118+
y=td.Boundary.pml(num_layers=6),
2119+
z=td.Boundary.pml(num_layers=6),
21202120
),
21212121
grid_spec=td.GridSpec.uniform(dl=grid_dl),
21222122
run_time=1e-12,
@@ -2145,9 +2145,9 @@ def test_sim_volumetric_structures(log_capture, tmp_path):
21452145
structures=[below_half, box],
21462146
sources=[src],
21472147
boundary_spec=td.BoundarySpec(
2148-
x=td.Boundary.pml(num_layers=5),
2149-
y=td.Boundary.pml(num_layers=5),
2150-
z=td.Boundary.pml(num_layers=5),
2148+
x=td.Boundary.pml(num_layers=6),
2149+
y=td.Boundary.pml(num_layers=6),
2150+
z=td.Boundary.pml(num_layers=6),
21512151
),
21522152
grid_spec=td.GridSpec.uniform(dl=grid_dl),
21532153
run_time=1e-12,
@@ -2161,9 +2161,9 @@ def test_sim_volumetric_structures(log_capture, tmp_path):
21612161
structures=[box, below],
21622162
sources=[src],
21632163
boundary_spec=td.BoundarySpec(
2164-
x=td.Boundary.pml(num_layers=5),
2165-
y=td.Boundary.pml(num_layers=5),
2166-
z=td.Boundary.pml(num_layers=5),
2164+
x=td.Boundary.pml(num_layers=6),
2165+
y=td.Boundary.pml(num_layers=6),
2166+
z=td.Boundary.pml(num_layers=6),
21672167
),
21682168
grid_spec=td.GridSpec.uniform(dl=grid_dl),
21692169
run_time=1e-12,
@@ -2179,9 +2179,9 @@ def test_sim_volumetric_structures(log_capture, tmp_path):
21792179
sources=[src],
21802180
medium=box.medium,
21812181
boundary_spec=td.BoundarySpec(
2182-
x=td.Boundary.pml(num_layers=5),
2183-
y=td.Boundary.pml(num_layers=5),
2184-
z=td.Boundary.pml(num_layers=5),
2182+
x=td.Boundary.pml(num_layers=6),
2183+
y=td.Boundary.pml(num_layers=6),
2184+
z=td.Boundary.pml(num_layers=6),
21852185
),
21862186
grid_spec=td.GridSpec.uniform(dl=grid_dl),
21872187
run_time=1e-12,
@@ -2208,9 +2208,9 @@ def test_sim_volumetric_structures(log_capture, tmp_path):
22082208
structures=[struct],
22092209
sources=[src],
22102210
boundary_spec=td.BoundarySpec(
2211-
x=td.Boundary.pml(num_layers=5),
2212-
y=td.Boundary.pml(num_layers=5),
2213-
z=td.Boundary.pml(num_layers=5),
2211+
x=td.Boundary.pml(num_layers=6),
2212+
y=td.Boundary.pml(num_layers=6),
2213+
z=td.Boundary.pml(num_layers=6),
22142214
),
22152215
grid_spec=td.GridSpec.uniform(dl=grid_dl),
22162216
run_time=1e-12,
@@ -2928,9 +2928,9 @@ def test_validate_low_num_cells_in_mode_objects():
29282928
grid_spec=td.GridSpec(wavelength=1.0),
29292929
sources=[mode_source],
29302930
boundary_spec=td.BoundarySpec(
2931-
x=td.Boundary.pml(num_layers=5),
2931+
x=td.Boundary.pml(num_layers=6),
29322932
y=td.Boundary.pec(),
2933-
z=td.Boundary.pml(num_layers=5),
2933+
z=td.Boundary.pml(num_layers=6),
29342934
),
29352935
)
29362936
sim2d._validate_num_cells_in_mode_objects()

tests/test_components/test_viz.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def test_2d_boundary_plot():
5656

5757
# Simulation details
5858
per_boundary = td.Boundary.periodic()
59-
pml_boundary = td.Boundary.pml(num_layers=2)
59+
pml_boundary = td.Boundary.pml(num_layers=6)
6060

6161
sim = td.Simulation(
6262
size=(0, 1, 1),

tidy3d/components/boundary.py

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
from .source import TFSF, GaussianBeam, ModeSource, PlaneWave
1717
from .types import TYPE_TAG_STR, Axis, Complex
1818

19+
MIN_NUM_PML_LAYERS = 6
20+
1921

2022
class BoundaryEdge(ABC, Tidy3dBaseModel):
2123
"""Electromagnetic boundary condition at a domain edge."""
@@ -260,10 +262,11 @@ class PMLParams(AbsorberParams):
260262
class AbsorberSpec(BoundaryEdge):
261263
"""Specifies the generic absorber properties along a single dimension."""
262264

263-
num_layers: pd.NonNegativeInt = pd.Field(
265+
num_layers: int = pd.Field(
264266
...,
265267
title="Number of Layers",
266268
description="Number of layers of standard PML.",
269+
ge=MIN_NUM_PML_LAYERS,
267270
)
268271
parameters: AbsorberParams = pd.Field(
269272
...,
@@ -376,10 +379,11 @@ class PML(AbsorberSpec):
376379
377380
"""
378381

379-
num_layers: pd.NonNegativeInt = pd.Field(
382+
num_layers: int = pd.Field(
380383
12,
381384
title="Number of Layers",
382385
description="Number of layers of standard PML.",
386+
ge=MIN_NUM_PML_LAYERS,
383387
)
384388

385389
parameters: PMLParams = pd.Field(
@@ -413,8 +417,11 @@ class StablePML(AbsorberSpec):
413417
* `Introduction to perfectly matched layer (PML) tutorial <https://www.flexcompute.com/fdtd101/Lecture-6-Introduction-to-perfectly-matched-layer/>`__
414418
"""
415419

416-
num_layers: pd.NonNegativeInt = pd.Field(
417-
40, title="Number of Layers", description="Number of layers of 'stable' PML."
420+
num_layers: int = pd.Field(
421+
40,
422+
title="Number of Layers",
423+
description="Number of layers of 'stable' PML.",
424+
ge=MIN_NUM_PML_LAYERS,
418425
)
419426

420427
parameters: PMLParams = pd.Field(
@@ -463,10 +470,11 @@ class Absorber(AbsorberSpec):
463470
* `How to troubleshoot a diverged FDTD simulation <../../notebooks/DivergedFDTDSimulation.html>`_
464471
"""
465472

466-
num_layers: pd.NonNegativeInt = pd.Field(
473+
num_layers: int = pd.Field(
467474
40,
468475
title="Number of Layers",
469476
description="Number of layers of absorber to add to + and - boundaries.",
477+
ge=MIN_NUM_PML_LAYERS,
470478
)
471479

472480
parameters: AbsorberParams = pd.Field(

0 commit comments

Comments
 (0)