Skip to content

Commit 710f8c3

Browse files
committed
Fixing PEC boundary condition handling
1 parent b673c62 commit 710f8c3

File tree

3 files changed

+143
-94
lines changed

3 files changed

+143
-94
lines changed

tests/test_plugins/test_mode_solver.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1241,7 +1241,7 @@ def test_high_order_mode_normalization():
12411241
def test_mode_solver_angle_symmetry():
12421242
# Angle to test
12431243
theta = np.pi / 180
1244-
theta = np.pi / 6
1244+
# theta = np.pi / 6
12451245

12461246
# Other parameters
12471247
plane = td.Box(center=(0, 0, 0), size=(5, 0, 8))
@@ -1269,7 +1269,7 @@ def test_mode_solver_angle_symmetry():
12691269
# grid_spec=td.GridSpec.uniform(dl=0.04),
12701270
structures=[wg],
12711271
run_time=1e-12,
1272-
symmetry=(0, 0, -1),
1272+
symmetry=(-1, 0, 0),
12731273
sources=[src],
12741274
# medium=td.Medium(permittivity=4.5),
12751275
)
@@ -1295,13 +1295,13 @@ def test_mode_solver_angle_symmetry():
12951295
ms_angle = ms.updated_copy(mode_spec=mode_spec, simulation=simulation)
12961296
modes_angle = ms_angle.solve()
12971297

1298-
import matplotlib.pyplot as plt
1298+
# import matplotlib.pyplot as plt
12991299

1300-
fig, ax = plt.subplots(1, 3)
1301-
simulation.plot(x=0, ax=ax[0])
1302-
simulation.plot(y=0, ax=ax[1])
1303-
simulation.plot(z=0, ax=ax[2])
1304-
plt.show()
1300+
# fig, ax = plt.subplots(1, 3)
1301+
# simulation.plot(x=0, ax=ax[0])
1302+
# simulation.plot(y=0, ax=ax[1])
1303+
# simulation.plot(z=0, ax=ax[2])
1304+
# plt.show()
13051305

13061306
# Plot the mode_index = 0 mode for both
13071307
_, ax = plt.subplots(1, 2)
@@ -1312,7 +1312,10 @@ def test_mode_solver_angle_symmetry():
13121312
print(modes_zero.n_complex.values)
13131313
print(modes_angle.n_complex.values)
13141314

1315-
assert np.allclose(modes_zero.n_complex.values, modes_angle.n_complex.values, atol=3e-2)
1315+
# Modes with and without an angle are close
1316+
assert np.allclose(modes_zero.n_complex.values, modes_angle.n_complex.values, atol=2e-2)
1317+
# Modes with angle (tensorial mode solver) have a small k_eff
1318+
assert np.all(np.abs(modes_angle.k_eff) < 1e-10)
13161319

13171320

13181321
def test_gauge_robustness():
@@ -1364,3 +1367,7 @@ def test_translated_dot():
13641367

13651368
assert np.allclose(data2.outer_dot(data_translated), data2.outer_dot(data2), atol=atol)
13661369
assert np.allclose(data_translated.outer_dot(data2), data2.outer_dot(data2), atol=atol)
1370+
1371+
1372+
if __name__ == "__main__":
1373+
test_mode_solver_angle_symmetry()

tidy3d/components/mode/derivatives.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,9 @@ def make_cxf(dls, shape, pmc):
261261

262262
def make_cxb(dls, shape, pmc):
263263
"""Backward colocation in x."""
264+
265+
# return make_cxf(dls, shape, pmc).T
266+
264267
import scipy.sparse as sp
265268

266269
Nx, Ny = shape
@@ -307,6 +310,9 @@ def make_cyf(dls, shape, pmc):
307310

308311
def make_cyb(dls, shape, pmc):
309312
"""Backward colocation in y."""
313+
314+
# return make_cyf(dls, shape, pmc).T
315+
310316
import scipy.sparse as sp
311317

312318
Nx, Ny = shape

0 commit comments

Comments
 (0)