Skip to content

Commit 3cba218

Browse files
caseyflexmomchil-flex
authored andcommitted
Stricter validation for mode solver bend radius
1 parent 4a21d3f commit 3cba218

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

CHANGELOG.md

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

1818
### Fixed
19+
- Stricter validation for `bend_radius` in mode simulations, preventing the bend center from coinciding with the simulation boundary.
1920

2021

2122
## [v2.10.0rc1] - 2025-09-11

tests/test_plugins/test_mode_solver.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1171,6 +1171,14 @@ def test_mode_small_bend_radius_fail():
11711171
mode_spec=td.ModeSpec(num_modes=1, bend_radius=1, bend_axis=0),
11721172
simulation=simulation,
11731173
)
1174+
# also error when bend radius is exactly aligned with simulation boundary
1175+
with pytest.raises(ValueError):
1176+
ms = ModeSolver(
1177+
plane=PLANE,
1178+
freqs=np.linspace(1e14, 2e14, 100),
1179+
mode_spec=td.ModeSpec(num_modes=1, bend_radius=1.5, bend_axis=0),
1180+
simulation=simulation,
1181+
)
11741182
# should work for infinite mode plane
11751183
ms = ModeSolver(
11761184
plane=td.Box(center=(0, 0, 0), size=(td.inf, 0, td.inf)),

tidy3d/components/mode/mode_solver.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
validate_freqs_not_empty,
6161
)
6262
from tidy3d.components.viz import make_ax, plot_params_pml
63-
from tidy3d.constants import C_0
63+
from tidy3d.constants import C_0, fp_eps
6464
from tidy3d.exceptions import SetupError, ValidationError
6565
from tidy3d.log import log
6666
from tidy3d.packaging import supports_local_subpixel, tidy3d_extras
@@ -299,7 +299,7 @@ def _validate_mode_plane_radius(cls, mode_spec: ModeSpec, plane: Box, sim_geom:
299299
_, plane_axs = mode_plane.pop_axis([0, 1, 2], mode_plane.size.index(0.0))
300300
radial_ax = plane_axs[(mode_spec.bend_axis + 1) % 2]
301301

302-
if np.abs(mode_spec.bend_radius) < mode_plane.size[radial_ax] / 2:
302+
if np.abs(mode_spec.bend_radius) <= mode_plane.size[radial_ax] / 2 + fp_eps:
303303
raise ValueError(
304304
"Mode solver bend radius is smaller than half the mode plane size "
305305
"along the radial axis, which can produce wrong results."

0 commit comments

Comments
 (0)