Skip to content

Commit 0836bfb

Browse files
yaugenst-flexdaquinteroflex
authored andcommitted
fix(monitor_data): use coords_interp for symmetry expansion coordinate check
1 parent e58a259 commit 0836bfb

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

tests/test_data/test_monitor_data.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,10 @@
3838
FIELD_MONITOR_2D,
3939
FIELD_TIME_MONITOR,
4040
FIELD_TIME_MONITOR_2D,
41+
FIELDS,
4142
FLUX_MONITOR,
4243
FLUX_TIME_MONITOR,
44+
FREQS,
4345
MEDIUM_MONITOR,
4446
MODE_MONITOR,
4547
MODE_MONITOR_WITH_FIELDS,
@@ -1133,3 +1135,39 @@ def test_from_zbf_dimsfail(self, tmp_path, field_data, dim1, dim2):
11331135
# this should fail
11341136
with pytest.raises(ValueError) as e:
11351137
_ = td.FieldDataset.from_zbf(filename=zbf_filename, dim1=dim1, dim2=dim2)
1138+
1139+
1140+
def test_symmetry_expansion_no_interpolation_warning():
1141+
"""Regression test: symmetry_expanded_copy should not warn when monitor is on
1142+
the negative side of the symmetry center. Bug was using coords[-1] (negative)
1143+
instead of coords_interp[-1] (positive) for coordinate matching."""
1144+
# Monitor entirely on negative y side (need size > 0 for multiple coords)
1145+
monitor = td.FieldMonitor(
1146+
size=(2, 0.5, 5), center=(0, -1.0, 0), fields=FIELDS, name="field", freqs=FREQS
1147+
)
1148+
sim = SIM_SYM.updated_copy(monitors=[monitor], symmetry=(0, -1, 0))
1149+
grid = sim.discretize_monitor(monitor)
1150+
1151+
# Grid y coords are negative; data stored at mirrored positive coords
1152+
y_grid = grid["Ex"].y
1153+
assert len(y_grid) > 1 and all(y < 0 for y in y_grid)
1154+
y_data = [-y for y in y_grid]
1155+
1156+
data = td.ScalarFieldDataArray(
1157+
np.ones((len(grid["Ex"].x), len(y_data), len(grid["Ex"].z), len(FREQS))) + 0j,
1158+
coords={"x": grid["Ex"].x, "y": y_data, "z": grid["Ex"].z, "f": FREQS},
1159+
)
1160+
field_data = FieldData(
1161+
monitor=monitor,
1162+
Ex=data,
1163+
Ey=data,
1164+
Ez=data,
1165+
Hx=data,
1166+
Hz=data,
1167+
symmetry=sim.symmetry,
1168+
symmetry_center=sim.center,
1169+
grid_expanded=grid,
1170+
)
1171+
1172+
with AssertLogLevel(None):
1173+
_ = field_data.symmetry_expanded_copy

tidy3d/components/data/monitor_data.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ def _symmetry_update_dict(self) -> dict:
309309
# then we need to interpolate, which is slower.
310310
use_sel = (
311311
len(scalar_data.coords[dim_name]) == 1
312-
or coords[-1] in scalar_data.coords[dim_name]
312+
or coords_interp[-1] in scalar_data.coords[dim_name]
313313
)
314314
if use_sel:
315315
scalar_data = scalar_data.sel(**{dim_name: coords_interp}, method="nearest")

0 commit comments

Comments
 (0)