Skip to content

ABC broadband #2721

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 3 commits 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
65 changes: 56 additions & 9 deletions tests/test_components/test_absorbers.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def test_port_absorbers_simulations():
td.InternalAbsorber(
size=(0.4, 0.5, 0),
direction="-",
boundary_spec=td.ModeABCBoundary(plane=td.Box(size=(1, 1, 0)), frequency=freq0),
boundary_spec=td.ModeABCBoundary(plane=td.Box(size=(1, 1, 0)), freq_spec=freq0),
)
],
)
Expand Down Expand Up @@ -207,31 +207,31 @@ def test_abc_boundaries_alone():
plane=td.Box(size=(1, 1, 0)),
mode_spec=td.ModeSpec(num_modes=2),
mode_index=1,
frequency=freq0,
freq_spec=freq0,
)

with pytest.raises(pydantic.ValidationError):
_ = td.ModeABCBoundary(
plane=td.Box(size=(1, 1, 0)),
mode_spec=td.ModeSpec(num_modes=2),
mode_index=1,
frequency=-1,
freq_spec=-1,
)

with pytest.raises(pydantic.ValidationError):
_ = td.ModeABCBoundary(
plane=td.Box(size=(1, 1, 0)),
mode_spec=td.ModeSpec(num_modes=2),
mode_index=-1,
frequency=freq0,
freq_spec=freq0,
)

with pytest.raises(pydantic.ValidationError):
_ = td.ModeABCBoundary(
plane=td.Box(size=(1, 1, 1)),
mode_spec=td.ModeSpec(num_modes=2),
mode_index=0,
frequency=freq0,
freq_spec=freq0,
)

# from mode source
Expand All @@ -250,7 +250,7 @@ def test_abc_boundaries_alone():
size=(1, 1, 0), mode_spec=td.ModeSpec(num_modes=2), freqs=[freq0], name="mnt"
)
mode_abc_from_monitor = td.ModeABCBoundary.from_monitor(
mode_monitor, mode_index=1, frequency=freq0
mode_monitor, mode_index=1, freq_spec=freq0
)
assert mode_abc == mode_abc_from_monitor

Expand All @@ -263,11 +263,11 @@ def test_abc_boundaries_alone():
plane=td.Box(size=(1, 1, 0)),
mode_spec=td.ModeSpec(num_modes=2),
mode_index=1,
frequency=freq0,
freq_spec=freq0,
)
abc_boundary_from_source = td.Boundary.mode_abc_from_source(mode_source)
abc_boundary_from_monitor = td.Boundary.mode_abc_from_monitor(
mode_monitor, mode_index=1, frequency=freq0
mode_monitor, mode_index=1, freq_spec=freq0
)
assert abc_boundary == abc_boundary_from_source
assert abc_boundary == abc_boundary_from_monitor
Expand Down Expand Up @@ -430,7 +430,7 @@ def test_abc_boundaries_simulations():
sources=[],
run_time=1e-20,
boundary_spec=td.BoundarySpec.all_sides(
td.ModeABCBoundary(plane=td.Box(size=(1, 1, 0)), frequency=freq0)
td.ModeABCBoundary(plane=td.Box(size=(1, 1, 0)), freq_spec=freq0)
),
)
# or at least one source
Expand Down Expand Up @@ -533,3 +533,50 @@ def test_abc_boundaries_simulations():
td.ABCBoundary(permittivity=2, conductivity=1e-5)
),
)


def test_abc_boundaries_broadband():
# test broadband fitter params
fitter_params = td.BroadbandModeABCFitterParam(
max_num_poles=10, tolerance_rms=1e-4, frequency_sampling_points=10
)

# test max num poles > 0
with pytest.raises(pydantic.ValidationError):
_ = td.BroadbandModeABCFitterParam(max_num_poles=0)
# test max num poles <= 10
with pytest.raises(pydantic.ValidationError):
_ = td.BroadbandModeABCFitterParam(max_num_poles=11)

# test tolerance rms >= 0
with pytest.raises(pydantic.ValidationError):
_ = td.BroadbandModeABCFitterParam(tolerance_rms=-1)

# test frequency sampling points > 0
with pytest.raises(pydantic.ValidationError):
_ = td.BroadbandModeABCFitterParam(frequency_sampling_points=0)
# test frequency sampling points <= 21
with pytest.raises(pydantic.ValidationError):
_ = td.BroadbandModeABCFitterParam(frequency_sampling_points=102)

# test basic instance
fmin = 100e12
fmax = 200e12
abc_boundary = td.BroadbandModeABCSpec(frequency_range=(fmin, fmax))

# test max frequency > min frequency
with pytest.raises(pydantic.ValidationError):
_ = td.BroadbandModeABCSpec(frequency_range=(fmax, fmin))

# test min frequency > 0
with pytest.raises(pydantic.ValidationError):
_ = td.BroadbandModeABCSpec(frequency_range=(0, fmax))

# test from_wavelength_range
wvl_min = td.C_0 / fmax
wvl_max = td.C_0 / fmin
abc_boundary = td.BroadbandModeABCSpec.from_wavelength_range(
wavelength_range=(wvl_min, wvl_max), fit_param=fitter_params
)
assert abc_boundary.frequency_range == (fmin, fmax)
assert abc_boundary.fit_param == fitter_params
43 changes: 43 additions & 0 deletions tests/test_plugins/smatrix/test_terminal_component_modeler.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import xarray as xr

import tidy3d as td
from tidy3d.components.boundary import BroadbandModeABCSpec
from tidy3d.components.data.data_array import FreqDataArray
from tidy3d.exceptions import SetupError, Tidy3dError, Tidy3dKeyError
from tidy3d.plugins.microwave import (
Expand Down Expand Up @@ -1296,3 +1297,45 @@ def check_S_matrix(S_computed, S_expected, tol=1e-12):
# Check power wave S matrix
S_computed = modeler._internal_construct_smatrix(batch_data, s_param_def="power").values
check_S_matrix(S_computed, S_power)


def test_wave_port_to_absorber(tmp_path):
"""Test that wave port absorber can be specified as a boolean, ABCBoundary, or ModeABCBoundary."""

# test automatic absorber
modeler = make_coaxial_component_modeler(
path_dir=str(tmp_path), port_types=(WavePort, WavePort)
)
sim = list(modeler.sim_dict.values())[0]

absorber = sim.internal_absorbers[0]

assert absorber.boundary_spec.mode_spec == modeler.ports[0].mode_spec
assert absorber.boundary_spec.mode_index == modeler.ports[0].mode_index
assert absorber.boundary_spec.plane == modeler.ports[0].geometry
assert absorber.boundary_spec.freq_spec == BroadbandModeABCSpec(
frequency_range=(np.min(modeler.freqs), np.max(modeler.freqs))
)

# test to_absorber()
absorber = modeler.ports[0].to_absorber(freq_spec=1e9)
assert absorber.boundary_spec.freq_spec == 1e9

absorber = modeler.ports[0].to_absorber(
freq_spec=BroadbandModeABCSpec(frequency_range=(1e9, 2e9))
)
assert absorber.boundary_spec.freq_spec == BroadbandModeABCSpec(frequency_range=(1e9, 2e9))

# test no automatic absorber
modeler = modeler.updated_copy(ports=[modeler.ports[0].updated_copy(absorber=False)])
sim = list(modeler.sim_dict.values())[0]
assert len(sim.internal_absorbers) == 0

# test custom boundary spec
custom_boundary_spec = td.ModeABCBoundary(plane=td.Box(size=(0.1, 0.1, 0)), freq_spec=1e9)
modeler = modeler.updated_copy(
ports=[modeler.ports[0].updated_copy(absorber=custom_boundary_spec)]
)
sim = list(modeler.sim_dict.values())[0]
absorber = sim.internal_absorbers[0]
assert absorber.boundary_spec == custom_boundary_spec
3 changes: 3 additions & 0 deletions tidy3d/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from __future__ import annotations

from tidy3d.components.boundary import BroadbandModeABCFitterParam, BroadbandModeABCSpec
from tidy3d.components.material.multi_physics import MultiPhysicsMedium
from tidy3d.components.material.tcad.charge import (
ChargeConductorMedium,
Expand Down Expand Up @@ -446,6 +447,8 @@ def set_logging_level(level: str) -> None:
"BoundaryEdgeType",
"BoundarySpec",
"Box",
"BroadbandModeABCFitterParam",
"BroadbandModeABCSpec",
"CaugheyThomasMobility",
"CellDataArray",
"ChargeConductorMedium",
Expand Down
Loading
Loading