Skip to content

Commit 392a871

Browse files
renaming and tests
1 parent 99589ea commit 392a871

File tree

6 files changed

+170
-68
lines changed

6 files changed

+170
-68
lines changed

tests/test_components/test_absorbers.py

Lines changed: 56 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ def test_port_absorbers_simulations():
133133
td.InternalAbsorber(
134134
size=(0.4, 0.5, 0),
135135
direction="-",
136-
boundary_spec=td.ModeABCBoundary(plane=td.Box(size=(1, 1, 0)), frequency=freq0),
136+
boundary_spec=td.ModeABCBoundary(plane=td.Box(size=(1, 1, 0)), freq_spec=freq0),
137137
)
138138
],
139139
)
@@ -207,31 +207,31 @@ def test_abc_boundaries_alone():
207207
plane=td.Box(size=(1, 1, 0)),
208208
mode_spec=td.ModeSpec(num_modes=2),
209209
mode_index=1,
210-
frequency=freq0,
210+
freq_spec=freq0,
211211
)
212212

213213
with pytest.raises(pydantic.ValidationError):
214214
_ = td.ModeABCBoundary(
215215
plane=td.Box(size=(1, 1, 0)),
216216
mode_spec=td.ModeSpec(num_modes=2),
217217
mode_index=1,
218-
frequency=-1,
218+
freq_spec=-1,
219219
)
220220

221221
with pytest.raises(pydantic.ValidationError):
222222
_ = td.ModeABCBoundary(
223223
plane=td.Box(size=(1, 1, 0)),
224224
mode_spec=td.ModeSpec(num_modes=2),
225225
mode_index=-1,
226-
frequency=freq0,
226+
freq_spec=freq0,
227227
)
228228

229229
with pytest.raises(pydantic.ValidationError):
230230
_ = td.ModeABCBoundary(
231231
plane=td.Box(size=(1, 1, 1)),
232232
mode_spec=td.ModeSpec(num_modes=2),
233233
mode_index=0,
234-
frequency=freq0,
234+
freq_spec=freq0,
235235
)
236236

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

@@ -263,11 +263,11 @@ def test_abc_boundaries_alone():
263263
plane=td.Box(size=(1, 1, 0)),
264264
mode_spec=td.ModeSpec(num_modes=2),
265265
mode_index=1,
266-
frequency=freq0,
266+
freq_spec=freq0,
267267
)
268268
abc_boundary_from_source = td.Boundary.mode_abc_from_source(mode_source)
269269
abc_boundary_from_monitor = td.Boundary.mode_abc_from_monitor(
270-
mode_monitor, mode_index=1, frequency=freq0
270+
mode_monitor, mode_index=1, freq_spec=freq0
271271
)
272272
assert abc_boundary == abc_boundary_from_source
273273
assert abc_boundary == abc_boundary_from_monitor
@@ -430,7 +430,7 @@ def test_abc_boundaries_simulations():
430430
sources=[],
431431
run_time=1e-20,
432432
boundary_spec=td.BoundarySpec.all_sides(
433-
td.ModeABCBoundary(plane=td.Box(size=(1, 1, 0)), frequency=freq0)
433+
td.ModeABCBoundary(plane=td.Box(size=(1, 1, 0)), freq_spec=freq0)
434434
),
435435
)
436436
# or at least one source
@@ -533,3 +533,50 @@ def test_abc_boundaries_simulations():
533533
td.ABCBoundary(permittivity=2, conductivity=1e-5)
534534
),
535535
)
536+
537+
538+
def test_abc_boundaries_broadband():
539+
# test broadband fitter params
540+
fitter_params = td.BroadbandModeABCFitterParam(
541+
max_num_poles=10, tolerance_rms=1e-4, frequency_sampling_points=10
542+
)
543+
544+
# test max num poles > 0
545+
with pytest.raises(pydantic.ValidationError):
546+
_ = td.BroadbandModeABCFitterParam(max_num_poles=0)
547+
# test max num poles <= 10
548+
with pytest.raises(pydantic.ValidationError):
549+
_ = td.BroadbandModeABCFitterParam(max_num_poles=11)
550+
551+
# test tolerance rms >= 0
552+
with pytest.raises(pydantic.ValidationError):
553+
_ = td.BroadbandModeABCFitterParam(tolerance_rms=-1)
554+
555+
# test frequency sampling points > 0
556+
with pytest.raises(pydantic.ValidationError):
557+
_ = td.BroadbandModeABCFitterParam(frequency_sampling_points=0)
558+
# test frequency sampling points <= 21
559+
with pytest.raises(pydantic.ValidationError):
560+
_ = td.BroadbandModeABCFitterParam(frequency_sampling_points=22)
561+
562+
# test basic instance
563+
fmin = 100e12
564+
fmax = 200e12
565+
abc_boundary = td.BroadbandModeABCSpec(frequency_range=(fmin, fmax))
566+
567+
# test max frequency > min frequency
568+
with pytest.raises(pydantic.ValidationError):
569+
_ = td.BroadbandModeABCSpec(frequency_range=(fmax, fmin))
570+
571+
# test min frequency > 0
572+
with pytest.raises(pydantic.ValidationError):
573+
_ = td.BroadbandModeABCSpec(frequency_range=(0, fmax))
574+
575+
# test from_wavelength_range
576+
wvl_min = td.C_0 / fmax
577+
wvl_max = td.C_0 / fmin
578+
abc_boundary = td.BroadbandModeABCSpec.from_wavelength_range(
579+
wavelength_range=(wvl_min, wvl_max), fit_param=fitter_params
580+
)
581+
assert abc_boundary.frequency_range == (fmin, fmax)
582+
assert abc_boundary.fit_param == fitter_params

tidy3d/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from __future__ import annotations
44

5-
from tidy3d.components.boundary import BroadbandModeABCSpec
5+
from tidy3d.components.boundary import BroadbandModeABCFitterParam, BroadbandModeABCSpec
66
from tidy3d.components.material.multi_physics import MultiPhysicsMedium
77
from tidy3d.components.material.tcad.charge import (
88
ChargeConductorMedium,
@@ -429,7 +429,6 @@ def set_logging_level(level: str) -> None:
429429
"ABCBoundary",
430430
"Absorber",
431431
"AbsorberParams",
432-
"BroadbandModeABCSpec",
433432
"AbstractFieldProjectionData",
434433
"AbstractMedium",
435434
"AdmittanceNetwork",
@@ -448,6 +447,8 @@ def set_logging_level(level: str) -> None:
448447
"BoundaryEdgeType",
449448
"BoundarySpec",
450449
"Box",
450+
"BroadbandModeABCFitterParam",
451+
"BroadbandModeABCSpec",
451452
"CaugheyThomasMobility",
452453
"CellDataArray",
453454
"ChargeConductorMedium",

0 commit comments

Comments
 (0)