Skip to content

Commit

Permalink
improved test coverage of microstrip plugin and removed deprecated ty…
Browse files Browse the repository at this point in the history
…ping
  • Loading branch information
dmarek-flex committed May 24, 2024
1 parent 38b9f93 commit 1b80432
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 7 deletions.
66 changes: 64 additions & 2 deletions tests/test_plugins/test_microwave.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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")
Expand Down Expand Up @@ -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)
5 changes: 2 additions & 3 deletions tidy3d/plugins/microwave/models/coupled_microstrip.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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].
Expand Down
3 changes: 1 addition & 2 deletions tidy3d/plugins/microwave/models/microstrip.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import numpy as np

from ....constants import ETA_0
from typing import Tuple


def _f(normalized_width: float) -> float:
Expand Down Expand Up @@ -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].
Expand Down

0 comments on commit 1b80432

Please sign in to comment.