From 1b80432f91073aefea00a708b36fdc8db372d1a3 Mon Sep 17 00:00:00 2001 From: dmarek Date: Thu, 23 May 2024 14:28:10 -0400 Subject: [PATCH] improved test coverage of microstrip plugin and removed deprecated typing --- tests/test_plugins/test_microwave.py | 66 ++++++++++++++++++- .../microwave/models/coupled_microstrip.py | 5 +- tidy3d/plugins/microwave/models/microstrip.py | 3 +- 3 files changed, 67 insertions(+), 7 deletions(-) diff --git a/tests/test_plugins/test_microwave.py b/tests/test_plugins/test_microwave.py index bad8ff8941..2d8e8e1a66 100644 --- a/tests/test_plugins/test_microwave.py +++ b/tests/test_plugins/test_microwave.py @@ -1,5 +1,11 @@ +"""Test the microwave plugin.""" + import pytest import numpy as np +import pydantic.v1 as pydantic + +from skrf import Frequency +from skrf.media import MLine import tidy3d as td from tidy3d import FieldData @@ -9,11 +15,12 @@ CurrentIntegralAxisAligned, ImpedanceCalculator, ) -import pydantic.v1 as pydantic + +from tidy3d.plugins.microwave.models import microstrip, coupled_microstrip + from tidy3d.exceptions import DataError from ..utils import run_emulated - # Using similar code as "test_data/test_data_arrays.py" MON_SIZE = (2, 1, 0) FIELDS = ("Ex", "Ey", "Hx", "Hy") @@ -303,3 +310,58 @@ def impedance_of_stripline(width, height): assert np.all(np.isclose(Z1, analytic_impedance, rtol=0.02)) assert np.all(np.isclose(Z2, analytic_impedance, atol=3.5)) assert np.all(np.isclose(Z3, analytic_impedance, atol=3.5)) + + +def test_microstrip_models(): + width = 3.0 + height = 1.0 + thickness = 0.0 + eps_r = 4.4 + + # Check zero thickness parameters + Z0, eps_eff = microstrip.compute_line_params(eps_r, width, height, thickness) + freqs = Frequency(start=1, stop=1, npoints=1, unit="ghz") + mline = MLine(frequency=freqs, w=width, h=height, t=thickness, ep_r=eps_r, disp="none") + + assert np.isclose(Z0, mline.Z0[0]) + assert np.isclose(eps_eff, mline.ep_reff[0]) + + # Check end effect length computation + dL = microstrip.compute_end_effect_length(eps_r, eps_eff, width, height) + assert np.isclose(dL, 0.54, rtol=0.01) + + # Check finite thickness parameters + thickness = 0.1 + Z0, eps_eff = microstrip.compute_line_params(eps_r, width, height, thickness) + mline = MLine(frequency=freqs, w=width, h=height, t=thickness, ep_r=eps_r, disp="none") + + assert np.isclose(Z0, mline.Z0[0]) + assert np.isclose(eps_eff, mline.ep_reff[0]) + + +def test_coupled_microstrip_model(): + w1 = 1.416 + w2 = 2.396 + height = 1.56 + g1 = 0.134 + g2 = 0.386 + eps_r = 4.3 + # Compare to: Taoufik, Ragani, N. Amar Touhami, and M. Agoutane. "Designing a Microstrip coupled line bandpass filter." + # International Journal of Engineering & Technology 2, no. 4 (2013): 266. + # and notebook "CoupledLineBandpassFilter" + + (Z_even, Z_odd, eps_even, eps_odd) = coupled_microstrip.compute_line_params( + eps_r, w1, height, g1 + ) + assert np.isclose(Z_even, 101.5, rtol=0.01) + assert np.isclose(Z_odd, 38.5, rtol=0.01) + assert np.isclose(eps_even, 3.26, rtol=0.01) + assert np.isclose(eps_odd, 2.71, rtol=0.01) + + (Z_even, Z_odd, eps_even, eps_odd) = coupled_microstrip.compute_line_params( + eps_r, w2, height, g2 + ) + assert np.isclose(Z_even, 71, rtol=0.01) + assert np.isclose(Z_odd, 39, rtol=0.01) + assert np.isclose(eps_even, 3.42, rtol=0.01) + assert np.isclose(eps_odd, 2.80, rtol=0.01) diff --git a/tidy3d/plugins/microwave/models/coupled_microstrip.py b/tidy3d/plugins/microwave/models/coupled_microstrip.py index 8ce0e3a814..76467c911b 100644 --- a/tidy3d/plugins/microwave/models/coupled_microstrip.py +++ b/tidy3d/plugins/microwave/models/coupled_microstrip.py @@ -9,7 +9,6 @@ import numpy as np from . import microstrip -from typing import Tuple def _epsilon_e_even(relative_permittivity: float, width: float, height: float, gap: float) -> float: @@ -51,7 +50,7 @@ def _z0_even_odd( e_eff_odd: float, z0: float, e_eff: float, -) -> Tuple[float, float]: +) -> tuple[float, float]: """Computes the characteristic impedance of the even and odd modes for coupled microstrip lines. Equations 8 and 9 [1]""" normalized_width = width / height @@ -79,7 +78,7 @@ def _z0_even_odd( def compute_line_params( relative_permittivity: float, width: float, height: float, gap: float -) -> Tuple[float, float, float, float]: +) -> tuple[float, float, float, float]: """Computes an approximation for the parameters of coupled microstrip lines assuming the quasistatic regime and 0 thickness [1]. diff --git a/tidy3d/plugins/microwave/models/microstrip.py b/tidy3d/plugins/microwave/models/microstrip.py index 7f0ed096a6..aad29fd7d6 100644 --- a/tidy3d/plugins/microwave/models/microstrip.py +++ b/tidy3d/plugins/microwave/models/microstrip.py @@ -14,7 +14,6 @@ import numpy as np from ....constants import ETA_0 -from typing import Tuple def _f(normalized_width: float) -> float: @@ -73,7 +72,7 @@ def _wcorr_mixed(width_correction_homo: float, relative_permittivity: float) -> def compute_line_params( relative_permittivity: float, width: float, height: float, thickness: float -) -> Tuple[float, float]: +) -> tuple[float, float]: """Computes an approximation for the characteristic impedance and effective electric permittivity of a microstrip line [1].