Skip to content

Commit b3d2f82

Browse files
committed
improved test coverage of microstrip plugin and removed deprecated typing
1 parent d1fc216 commit b3d2f82

File tree

3 files changed

+81
-7
lines changed

3 files changed

+81
-7
lines changed

tests/test_plugins/test_microwave.py

Lines changed: 78 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
1+
"""Test the microwave plugin."""
2+
13
import pytest
24
import numpy as np
5+
import pydantic.v1 as pydantic
6+
7+
from skrf import Frequency
8+
from skrf.media import MLine
39

410
import tidy3d as td
511
from tidy3d import FieldData
@@ -9,11 +15,12 @@
915
CurrentIntegralAxisAligned,
1016
ImpedanceCalculator,
1117
)
12-
import pydantic.v1 as pydantic
18+
19+
from tidy3d.plugins.microwave.models import microstrip, coupled_microstrip
20+
1321
from tidy3d.exceptions import DataError
1422
from ..utils import run_emulated
1523

16-
1724
# Using similar code as "test_data/test_data_arrays.py"
1825
MON_SIZE = (2, 1, 0)
1926
FIELDS = ("Ex", "Ey", "Hx", "Hy")
@@ -112,6 +119,7 @@ def make_field_data():
112119

113120
@pytest.mark.parametrize("axis", [0, 1, 2])
114121
def test_voltage_integral_axes(axis):
122+
"""Check VoltageIntegralAxisAligned runs."""
115123
length = 0.5
116124
size = [0, 0, 0]
117125
size[axis] = length
@@ -127,6 +135,7 @@ def test_voltage_integral_axes(axis):
127135

128136
@pytest.mark.parametrize("axis", [0, 1, 2])
129137
def test_current_integral_axes(axis):
138+
"""Check CurrentIntegralAxisAligned runs."""
130139
length = 0.5
131140
size = [length, length, length]
132141
size[axis] = 0.0
@@ -140,6 +149,7 @@ def test_current_integral_axes(axis):
140149

141150

142151
def test_voltage_integral_toggles():
152+
"""Check VoltageIntegralAxisAligned runs with toggles."""
143153
length = 0.5
144154
size = [0, 0, 0]
145155
size[0] = length
@@ -155,6 +165,7 @@ def test_voltage_integral_toggles():
155165

156166

157167
def test_current_integral_toggles():
168+
"""Check CurrentIntegralAxisAligned runs with toggles."""
158169
length = 0.5
159170
size = [length, length, length]
160171
size[0] = 0.0
@@ -170,6 +181,7 @@ def test_current_integral_toggles():
170181

171182

172183
def test_voltage_missing_fields():
184+
"""Check validation of VoltageIntegralAxisAligned with missing fields."""
173185
length = 0.5
174186
size = [0, 0, 0]
175187
size[1] = length
@@ -185,6 +197,7 @@ def test_voltage_missing_fields():
185197

186198

187199
def test_current_missing_fields():
200+
"""Check validation of CurrentIntegralAxisAligned with missing fields."""
188201
length = 0.5
189202
size = [length, length, length]
190203
size[0] = 0.0
@@ -200,6 +213,7 @@ def test_current_missing_fields():
200213

201214

202215
def test_time_monitor_voltage_integral():
216+
"""Check VoltageIntegralAxisAligned runs on time domain data."""
203217
length = 0.5
204218
size = [0, 0, 0]
205219
size[1] = length
@@ -214,6 +228,7 @@ def test_time_monitor_voltage_integral():
214228

215229

216230
def test_mode_solver_monitor_voltage_integral():
231+
"""Check VoltageIntegralAxisAligned runs on mode solver data."""
217232
length = 0.5
218233
size = [0, 0, 0]
219234
size[1] = length
@@ -228,6 +243,7 @@ def test_mode_solver_monitor_voltage_integral():
228243

229244

230245
def test_tiny_voltage_path():
246+
"""Check VoltageIntegralAxisAligned runs when given a very short path."""
231247
length = 0.02
232248
size = [0, 0, 0]
233249
size[1] = length
@@ -240,11 +256,13 @@ def test_tiny_voltage_path():
240256

241257

242258
def test_impedance_calculator():
259+
"""Check validation of ImpedanceCalculator when integrals are missing."""
243260
with pytest.raises(pydantic.ValidationError):
244261
_ = ImpedanceCalculator(voltage_integral=None, current_integral=None)
245262

246263

247264
def test_impedance_calculator_on_time_data():
265+
"""Check ImpedanceCalculator runs on time domain data."""
248266
# Setup path integrals
249267
length = 0.5
250268
size = [0, length, 0]
@@ -269,6 +287,7 @@ def test_impedance_calculator_on_time_data():
269287

270288

271289
def test_impedance_accuracy():
290+
"""Test the accuracy of the ImpedanceCalculator."""
272291
field_data = make_field_data()
273292
# Setup path integrals
274293
size = [0, STRIP_HEIGHT / 2, 0]
@@ -303,3 +322,60 @@ def impedance_of_stripline(width, height):
303322
assert np.all(np.isclose(Z1, analytic_impedance, rtol=0.02))
304323
assert np.all(np.isclose(Z2, analytic_impedance, atol=3.5))
305324
assert np.all(np.isclose(Z3, analytic_impedance, atol=3.5))
325+
326+
327+
def test_microstrip_models():
328+
"""Test that the microstrip model computes transmission line parameters accurately."""
329+
width = 3.0
330+
height = 1.0
331+
thickness = 0.0
332+
eps_r = 4.4
333+
334+
# Check zero thickness parameters
335+
Z0, eps_eff = microstrip.compute_line_params(eps_r, width, height, thickness)
336+
freqs = Frequency(start=1, stop=1, npoints=1, unit="ghz")
337+
mline = MLine(frequency=freqs, w=width, h=height, t=thickness, ep_r=eps_r, disp="none")
338+
339+
assert np.isclose(Z0, mline.Z0[0])
340+
assert np.isclose(eps_eff, mline.ep_reff[0])
341+
342+
# Check end effect length computation
343+
dL = microstrip.compute_end_effect_length(eps_r, eps_eff, width, height)
344+
assert np.isclose(dL, 0.54, rtol=0.01)
345+
346+
# Check finite thickness parameters
347+
thickness = 0.1
348+
Z0, eps_eff = microstrip.compute_line_params(eps_r, width, height, thickness)
349+
mline = MLine(frequency=freqs, w=width, h=height, t=thickness, ep_r=eps_r, disp="none")
350+
351+
assert np.isclose(Z0, mline.Z0[0])
352+
assert np.isclose(eps_eff, mline.ep_reff[0])
353+
354+
355+
def test_coupled_microstrip_model():
356+
"""Test that the coupled microstrip model computes transmission line parameters accurately."""
357+
w1 = 1.416
358+
w2 = 2.396
359+
height = 1.56
360+
g1 = 0.134
361+
g2 = 0.386
362+
eps_r = 4.3
363+
# Compare to: Taoufik, Ragani, N. Amar Touhami, and M. Agoutane. "Designing a Microstrip coupled line bandpass filter."
364+
# International Journal of Engineering & Technology 2, no. 4 (2013): 266.
365+
# and notebook "CoupledLineBandpassFilter"
366+
367+
(Z_even, Z_odd, eps_even, eps_odd) = coupled_microstrip.compute_line_params(
368+
eps_r, w1, height, g1
369+
)
370+
assert np.isclose(Z_even, 101.5, rtol=0.01)
371+
assert np.isclose(Z_odd, 38.5, rtol=0.01)
372+
assert np.isclose(eps_even, 3.26, rtol=0.01)
373+
assert np.isclose(eps_odd, 2.71, rtol=0.01)
374+
375+
(Z_even, Z_odd, eps_even, eps_odd) = coupled_microstrip.compute_line_params(
376+
eps_r, w2, height, g2
377+
)
378+
assert np.isclose(Z_even, 71, rtol=0.01)
379+
assert np.isclose(Z_odd, 39, rtol=0.01)
380+
assert np.isclose(eps_even, 3.42, rtol=0.01)
381+
assert np.isclose(eps_odd, 2.80, rtol=0.01)

tidy3d/plugins/microwave/models/coupled_microstrip.py

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

1010
import numpy as np
1111
from . import microstrip
12-
from typing import Tuple
1312

1413

1514
def _epsilon_e_even(relative_permittivity: float, width: float, height: float, gap: float) -> float:
@@ -51,7 +50,7 @@ def _z0_even_odd(
5150
e_eff_odd: float,
5251
z0: float,
5352
e_eff: float,
54-
) -> Tuple[float, float]:
53+
) -> tuple[float, float]:
5554
"""Computes the characteristic impedance of the even and odd modes for coupled microstrip lines.
5655
Equations 8 and 9 [1]"""
5756
normalized_width = width / height
@@ -79,7 +78,7 @@ def _z0_even_odd(
7978

8079
def compute_line_params(
8180
relative_permittivity: float, width: float, height: float, gap: float
82-
) -> Tuple[float, float, float, float]:
81+
) -> tuple[float, float, float, float]:
8382
"""Computes an approximation for the parameters of coupled microstrip lines
8483
assuming the quasistatic regime and 0 thickness [1].
8584

tidy3d/plugins/microwave/models/microstrip.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import numpy as np
1515

1616
from ....constants import ETA_0
17-
from typing import Tuple
1817

1918

2019
def _f(normalized_width: float) -> float:
@@ -73,7 +72,7 @@ def _wcorr_mixed(width_correction_homo: float, relative_permittivity: float) ->
7372

7473
def compute_line_params(
7574
relative_permittivity: float, width: float, height: float, thickness: float
76-
) -> Tuple[float, float]:
75+
) -> tuple[float, float]:
7776
"""Computes an approximation for the characteristic impedance and effective
7877
electric permittivity of a microstrip line [1].
7978

0 commit comments

Comments
 (0)