Skip to content

Commit 3446b3c

Browse files
committed
Warn when mode solver pml covers a significant portion of the mode plane
1 parent 42afa41 commit 3446b3c

File tree

4 files changed

+294
-62
lines changed

4 files changed

+294
-62
lines changed

Diff for: CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1717
- Bug in `LayerRefinementSpec` that refines grids outside the layer region when one in-plane dimension is of size infinity.
1818
- Querying tasks was sometimes erroring unexpectedly.
1919
- Fixed automatic creation of missing output directories.
20+
- Warn when mode solver pml covers a significant portion of the mode plane.
2021

2122
## [2.8.0] - 2025-03-04
2223

Diff for: tests/test_components/test_simulation.py

+81-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from tidy3d.components.scene import MAX_GEOMETRY_COUNT, MAX_NUM_MEDIUMS
1111
from tidy3d.components.simulation import MAX_NUM_SOURCES
1212
from tidy3d.exceptions import SetupError, Tidy3dError, Tidy3dKeyError
13+
from tidy3d.plugins.mode import ModeSolver
1314

1415
from ..utils import (
1516
SIM_FULL,
@@ -2543,7 +2544,11 @@ def test_sim_subsection(unstructured, nz):
25432544
sim_red = SIM_FULL.subsection(
25442545
region=region, boundary_spec=td.BoundarySpec.all_sides(td.Periodic())
25452546
)
2546-
sim_red = SIM_FULL.subsection(region=region, sources=[], grid_spec=td.GridSpec.uniform(dl=20))
2547+
sim_red = SIM_FULL.subsection(
2548+
region=region,
2549+
sources=[],
2550+
grid_spec=td.GridSpec.uniform(dl=20),
2551+
)
25472552
assert len(sim_red.sources) == 0
25482553
sim_red = SIM_FULL.subsection(region=region, monitors=[])
25492554
assert len(sim_red.monitors) == 0
@@ -3085,6 +3090,81 @@ def test_validate_sources_monitors_in_bounds():
30853090
)
30863091

30873092

3093+
def test_mode_pml_warning():
3094+
sim_size = (3, 3, 3)
3095+
lambda0 = 1.55
3096+
freq0 = td.C_0 / lambda0
3097+
si = td.material_library["cSi"]["Li1993_293K"]
3098+
sio2 = td.material_library["SiO2"]["Horiba"]
3099+
wg = td.Structure(geometry=td.Box(size=(0.22, 0.5, td.inf)), medium=si)
3100+
mode_plane = td.Box(size=(2, 2, 0))
3101+
mode_spec = td.ModeSpec(num_pml=(22, 22))
3102+
grid_spec = td.GridSpec.auto(wavelength=lambda0, min_steps_per_wvl=30)
3103+
symmetry = (0, 0, 0)
3104+
with AssertLogLevel(None):
3105+
sim = td.Simulation(
3106+
size=sim_size,
3107+
medium=sio2,
3108+
structures=[wg],
3109+
grid_spec=grid_spec,
3110+
run_time=1e-30,
3111+
monitors=[
3112+
td.ModeSolverMonitor(
3113+
size=(2, 2, 0),
3114+
name="mode",
3115+
freqs=[freq0],
3116+
mode_spec=mode_spec.updated_copy(num_pml=(10, 10)),
3117+
)
3118+
],
3119+
symmetry=symmetry,
3120+
)
3121+
with AssertLogLevel("WARNING", contains_str="covers more than"):
3122+
sim = td.Simulation(
3123+
size=sim_size,
3124+
medium=sio2,
3125+
structures=[wg],
3126+
grid_spec=grid_spec,
3127+
run_time=1e-30,
3128+
monitors=[
3129+
td.ModeSolverMonitor(
3130+
size=(2, 2, 0), name="mode", freqs=[freq0], mode_spec=mode_spec
3131+
)
3132+
],
3133+
symmetry=symmetry,
3134+
)
3135+
with AssertLogLevel("WARNING", contains_str="covers more than"):
3136+
sim = td.Simulation(
3137+
size=sim_size,
3138+
medium=sio2,
3139+
structures=[wg],
3140+
grid_spec=grid_spec,
3141+
run_time=1e-30,
3142+
sources=[
3143+
td.ModeSource(
3144+
size=(2, 2, 0),
3145+
direction="+",
3146+
source_time=td.GaussianPulse(freq0=freq0, fwidth=0.1 * freq0),
3147+
mode_spec=mode_spec,
3148+
)
3149+
],
3150+
symmetry=symmetry,
3151+
)
3152+
with AssertLogLevel("WARNING", contains_str="covers more than"):
3153+
mode_solver = ModeSolver(
3154+
simulation=sim, plane=mode_plane, mode_spec=mode_spec, freqs=[freq0]
3155+
)
3156+
with AssertLogLevel("WARNING", contains_str="covers more than"):
3157+
mode_sim = td.ModeSimulation(
3158+
size=sim_size,
3159+
medium=sio2,
3160+
structures=[wg],
3161+
grid_spec=grid_spec,
3162+
plane=mode_plane,
3163+
mode_spec=mode_spec,
3164+
freqs=[freq0],
3165+
)
3166+
3167+
30883168
def test_fixed_angle_sim():
30893169
wvl_um = 1.0
30903170
freq0 = td.C_0 / wvl_um

0 commit comments

Comments
 (0)