Skip to content

Fix EME port modes symmetry expansion #2605

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed
- Arrow lengths are now scaled consistently in the X and Y directions, and their lengths no longer exceed the height of the plot window.
- Bug in `PlaneWave` defined with a negative `angle_theta` which would lead to wrong injection.
- `EMESimulationData.port_modes_tuple` is now symmetry-expanded.

### Changed
- `GaussianBeam` and `AstigmaticGaussianBeam` default `num_freqs` reset to 1 (it was set to 3 in v2.8.0) and a warning is issued for a broadband, angled beam for which `num_freqs` may not be sufficiently large.
Expand Down
12 changes: 6 additions & 6 deletions tests/test_components/test_eme.py
Original file line number Diff line number Diff line change
Expand Up @@ -967,14 +967,14 @@ def test_eme_sim_data():
port_modes = _get_eme_port_modes()
smatrix = _get_eme_smatrix_dataset(num_modes_1=5, num_modes_2=5)

sim_data = td.EMESimulationData(simulation=sim, data=data, smatrix=smatrix, port_modes=None)
sim_data = td.EMESimulationData(simulation=sim, data=data, smatrix=smatrix, port_modes_raw=None)
with pytest.raises(SetupError):
_ = sim_data.port_modes_tuple
with pytest.raises(SetupError):
_ = sim_data.port_modes_list_sweep

sim_data = td.EMESimulationData(
simulation=sim, data=data, smatrix=smatrix, port_modes=port_modes
simulation=sim, data=data, smatrix=smatrix, port_modes_raw=port_modes
)
_ = sim_data.port_modes_tuple
_ = sim_data.port_modes_list_sweep
Expand Down Expand Up @@ -1028,11 +1028,11 @@ def test_eme_sim_data():
assert len(smatrix_in_basis.S22.coords) == 1

with pytest.raises(SetupError):
_ = sim_data.updated_copy(port_modes=None).smatrix_in_basis(
_ = sim_data.updated_copy(port_modes_raw=None).smatrix_in_basis(
modes1=modes_in_data, modes2=modes_out_data
)
with pytest.raises(SetupError):
_ = sim_data.updated_copy(port_modes=None).field_in_basis(
_ = sim_data.updated_copy(port_modes_raw=None).field_in_basis(
field=sim_data["field"], modes=modes_in_data, port_index=0
)

Expand Down Expand Up @@ -1092,7 +1092,7 @@ def test_eme_sim_data():
smatrix = _get_eme_smatrix_dataset(num_modes_1=5, num_modes_2=5, num_sweep=10)
sim = sim.updated_copy(sweep_spec=td.EMELengthSweep(scale_factors=np.linspace(1, 2, 10)))
sim_data = td.EMESimulationData(
simulation=sim, data=data, smatrix=smatrix, port_modes=port_modes
simulation=sim, data=data, smatrix=smatrix, port_modes_raw=port_modes
)

# test smatrix_in_basis
Expand Down Expand Up @@ -1172,7 +1172,7 @@ def test_eme_sim_data():
sim = sim.updated_copy(sweep_spec=td.EMEFreqSweep(freq_scale_factors=np.linspace(1, 2, 10)))
port_modes = _get_eme_port_modes(num_sweep=10)
sim_data = td.EMESimulationData(
simulation=sim, data=data, smatrix=smatrix, port_modes=port_modes
simulation=sim, data=data, smatrix=smatrix, port_modes_raw=port_modes
)
with pytest.raises(SetupError):
_ = sim_data.port_modes_tuple
Expand Down
22 changes: 19 additions & 3 deletions tidy3d/components/eme/data/sim_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,23 @@ class EMESimulationData(AbstractYeeGridSimulationData):
None, title="S Matrix", description="Scattering matrix of the EME simulation."
)

port_modes: Optional[EMEModeSolverData] = pd.Field(
port_modes_raw: Optional[EMEModeSolverData] = pd.Field(
None,
title="Port Modes",
description="Modes associated with the two ports of the EME device. "
"The scattering matrix is expressed in this basis.",
"The scattering matrix is expressed in this basis. "
"Note: these modes are not symmetry expanded; use 'port_modes' instead.",
)

@cached_property
def port_modes(self):
"""Modes associated with the two ports of the EME device.
The scattering matrix is expressed in this basis.
Note: these modes are symmetry expanded."""
if self.port_modes_raw is None:
return None
return self.port_modes_raw.symmetry_expanded_copy

def _extract_mode_solver_data(
self, data: EMEModeSolverData, eme_cell_index: int, sweep_index: Optional[int] = None
) -> ModeSolverData:
Expand Down Expand Up @@ -89,7 +99,13 @@ def _extract_mode_solver_data(
"certain derived quantities, like the flux."
)
grid_expanded = self.simulation.discretize_monitor(monitor=monitor)
return ModeSolverData(**update_dict, monitor=monitor, grid_expanded=grid_expanded)
return ModeSolverData(
**update_dict,
monitor=monitor,
grid_expanded=grid_expanded,
symmetry=data.symmetry,
symmetry_center=data.symmetry_center,
)

@cached_property
def port_modes_tuple(self) -> tuple[ModeSolverData, ModeSolverData]:
Expand Down