Skip to content

Commit 3058747

Browse files
remove internal absorbers in reduced_simulation_copy
1 parent 8edc753 commit 3058747

File tree

2 files changed

+13
-14
lines changed

2 files changed

+13
-14
lines changed

tests/test_plugins/test_mode_solver.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,8 @@ def check_ms_reduction(ms):
253253
assert np.allclose(grids_1d.z, grids_1d_red.z)
254254
modes_red = ms.solve()
255255
assert np.allclose(ms.data.n_eff.values, modes_red.n_eff.values)
256+
assert len(ms_red.simulation.sources) == 0
257+
assert len(ms_red.simulation.internal_absorbers) == 0
256258

257259

258260
def test_mode_solver_validation():

tidy3d/components/mode/mode_solver.py

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -569,15 +569,7 @@ def rotated_mode_solver_data(self) -> ModeSolverData:
569569
# # if self.mode_spec.bend_radius is None, use this instead
570570
# solver_ref_data_straight = self._ref_data_straight(mode_solver_data=solver_ref_data)
571571

572-
try:
573-
solver = self.reduced_simulation_copy
574-
except Exception as e:
575-
solver = self
576-
log.warning(
577-
"Mode solver reduced_simulation_copy failed. "
578-
"Falling back to non-reduced simulation, which may be slower. "
579-
f"Exception: {e!s}"
580-
)
572+
solver = self._reduced_simulation_copy_with_fallback
581573

582574
# Compute the mode solution by rotating the reference data to the monitor plane
583575
rotated_mode_fields = self._mode_rotation(
@@ -1128,22 +1120,26 @@ def bend_center(self) -> list:
11281120

11291121
return bend_center
11301122

1131-
def _data_on_yee_grid(self) -> ModeSolverData:
1132-
"""Solve for all modes, and construct data with fields on the Yee grid."""
1133-
1123+
@cached_property
1124+
def _reduced_simulation_copy_with_fallback(self) -> ModeSolver:
1125+
"""Try to get a reduced simulation copy. If it fails, fall back to the non-reduced simulation."""
11341126
# we try to do reduced simulation copy for efficiency
11351127
# it should never fail -- if it does, this is likely due to an oversight
11361128
# in the Simulation.subsection method. but falling back to non-reduced
11371129
# simulation prevents unneeded errors in this case
11381130
try:
1139-
solver = self.reduced_simulation_copy
1131+
return self.reduced_simulation_copy
11401132
except Exception as e:
1141-
solver = self
11421133
log.warning(
11431134
"Mode solver reduced_simulation_copy failed. "
11441135
"Falling back to non-reduced simulation, which may be slower. "
11451136
f"Exception: {e!s}"
11461137
)
1138+
return self
1139+
1140+
def _data_on_yee_grid(self) -> ModeSolverData:
1141+
"""Solve for all modes, and construct data with fields on the Yee grid."""
1142+
solver = self._reduced_simulation_copy_with_fallback
11471143

11481144
_, _solver_coords = solver.plane.pop_axis(
11491145
solver._solver_grid.boundaries.to_list, axis=solver.normal_axis
@@ -2609,6 +2605,7 @@ def reduced_simulation_copy(self):
26092605
region=new_sim_box,
26102606
monitors=[],
26112607
sources=[],
2608+
internal_absorbers=[],
26122609
warn_symmetry_expansion=False, # we already warn upon mode solver creation
26132610
grid_spec="identical",
26142611
boundary_spec=new_bspec,

0 commit comments

Comments
 (0)