Skip to content

Commit

Permalink
fix a sign
Browse files Browse the repository at this point in the history
  • Loading branch information
QimingFlex committed Oct 31, 2024
1 parent 44d781d commit 00976a1
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions tidy3d/plugins/mode/mode_solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
ArrayFloat1D,
Ax,
Axis,
Axis2D,
Direction,
EpsSpecType,
FreqArray,
Expand Down Expand Up @@ -181,6 +182,13 @@ def normal_axis(self) -> Axis:
"""Axis normal to the mode plane."""
return self.plane.size.index(0.0)

@cached_property
def normal_axis_2d(self) -> Axis2D:
"""Axis normal to the mode plane in a 2D plane that is normal to the bend_axis_3d."""
_, idx_plane = self.plane.pop_axis((0, 1, 2), axis=self.bend_axis_3d)

return idx_plane.index(self.normal_axis)

@cached_property
def solver_symmetry(self) -> Tuple[Symmetry, Symmetry]:
"""Get symmetry for solver for propagation along self.normal axis."""
Expand Down Expand Up @@ -489,6 +497,7 @@ def _car_2_cyn(
fields_at_point = {
field_name: getattr(mode_solver_data, field_name)
.sel(sel_coords, method="nearest")
.isel({cmp_1: 0, cmp_2: 0})
.values
for field_name in ("Ex", "Ey", "Ez", "Hx", "Hy", "Hz")
}
Expand Down Expand Up @@ -582,11 +591,14 @@ def _mode_rotation(
for comp in ["r", "theta", "axial"]
}

phase = (
np.exp(1j * theta_rel * beta)
if self.direction == "+"
else np.exp(-1j * theta_rel * beta)
)
# Determine the phase factor based on normal_axis_2d
sign = -1 if self.normal_axis_2d == 0 else 1
if (self.direction == "+" and self.mode_spec.bend_radius >= 0) or (
self.direction == "-" and self.mode_spec.bend_radius < 0
):
phase = np.exp(sign * 1j * theta_rel * beta)
else:
phase = np.exp(sign * -1j * theta_rel * beta)

# Set fixed index based on normal_axis
idx = [slice(None)] * 3
Expand Down

0 comments on commit 00976a1

Please sign in to comment.