Skip to content

Commit 7479f62

Browse files
committed
fix bug in TerminalComponentModeler.get_antenna_metrics_data
1 parent 9b686b9 commit 7479f62

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2929
- Removed sources from `sim_inf_structure` simulation object in `postprocess_adj` to avoid source and background medium validation errors.
3030
- Revert overly restrictive validation of `freqs` in the `ComponentModeler` and `TerminalComponentModeler`.
3131
- Fixed `ElectromagneticFieldData.to_zbf()` to support single frequency monitors and apply the correct flattening order.
32+
- Bug in `TerminalComponentModeler.get_antenna_metrics_data` when port amplitudes are set to zero.
3233

3334
## [2.9.0] - 2025-08-04
3435

tests/test_plugins/smatrix/test_terminal_component_modeler.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1141,6 +1141,15 @@ def test_get_combined_antenna_parameters_data(monkeypatch, tmp_path):
11411141
antenna_params.radiation_efficiency, single_port_params.radiation_efficiency
11421142
)
11431143

1144+
# Define port amplitudes
1145+
port_amplitudes = {modeler.ports[0].name: 1.0, modeler.ports[1].name: 0.0}
1146+
port2_zero_params = modeler.get_antenna_metrics_data(port_amplitudes)
1147+
# Should give idential results to only exciting one port
1148+
assert np.allclose(port2_zero_params.gain, single_port_params.gain)
1149+
assert np.allclose(
1150+
port2_zero_params.radiation_efficiency, single_port_params.radiation_efficiency
1151+
)
1152+
11441153

11451154
def test_run_only_and_element_mappings(monkeypatch, tmp_path):
11461155
"""Checks the terminal component modeler works when running with a subset of excitations."""

tidy3d/plugins/smatrix/component_modelers/terminal.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -808,9 +808,10 @@ def get_antenna_metrics_data(
808808
Parameters
809809
----------
810810
port_amplitudes : dict[str, complex] = None
811-
Dictionary mapping port names to their desired excitation amplitudes. For each port,
811+
Dictionary mapping port names to their desired excitation amplitudes, ``a``. For each port,
812812
:math:`\\frac{1}{2}|a|^2` represents the incident power from that port into the system.
813-
If None, uses only the first port without any scaling of the raw simulation data.
813+
If ``None``, uses only the first port without any scaling of the raw simulation data.
814+
When ``None`` is passed as a port amplitude, the raw simulation data is used for that port.
814815
Note that in this method ``a`` represents the incident wave amplitude
815816
using the power wave definition in [2].
816817
monitor_name : str = None
@@ -849,6 +850,8 @@ def get_antenna_metrics_data(
849850
# Retrieve associated simulation data
850851
combined_directivity_data = None
851852
for port, amplitude in port_dict.items():
853+
if amplitude == 0.0:
854+
continue
852855
sim_data_port = self.batch_data[self._task_name(port=port)]
853856
radiation_data = sim_data_port[rad_mon.name]
854857

0 commit comments

Comments
 (0)