使用PyAEDT复现超表面论文

前言

相较于Ansys Electronics自带的脚本功能,PyAEDT能提供更灵活的操作方式。PyAEDT的官方介绍中对它的描述如下:

PyAEDT 是一个直接与 AEDT API 交互的 Python 库。使最终用户的脚本编写更简易。它的框架可重复使用,适用于所有 AEDT 3D 产品(HFSS、Icepak、Maxwell 3D 和 Q3D Extractor)、2D tools 和 Ansys Mechanical。它支持像 Nexxim 这样的电路工具和 Twin Builder 这样的系统模拟工具。最后它为 HFSS 3D Layout 和 EDB 等 Ansys 布局工具提供脚本功能。它的类方法结构简化了最终用户的操作,同时尽可能在整个 API 中复用信息。

遵循官方文档的步骤,在Anaconda中安装PyAEDT后就可以使用了。

论文1

使用如下代码,完成建模。

from ansys.aedt.core.hfss import Hfss
from ansys.aedt.core import constants

constants.PLANE

P = 16
D1 = D2 = 15
D = 5
W = 0.2
G = 1.8
S = 1.6

Ls = (9.89, 10.48, 11.19, 12.37, 13.31, 13.71)

with Hfss() as hfss:
    modeler = hfss.modeler
    for obj in modeler.object_list:
        if obj.name.find("__") == 0:
            print("deleted", obj.name)
            obj.delete()

    for idx, L in enumerate(Ls):
        substrate = modeler.create_box(
            [-P / 2, -P / 2, 0], [P, P, -D], f"__Substrate_{idx}", "FR4_epoxy"
        )
        substrate.color = (153, 204, 255)
        substrate.transparency = 0.7
        line_A = modeler.create_rectangle(
            "XY", [0, -D2 / 2, 0], [D1 / 2, -W], f"__Line_A_{idx}"
        )
        line_B = modeler.create_rectangle(
            "XY", [D1 / 2, -D2 / 2, 0], [-W, D2], f"__Line_B_{idx}"
        )
        line_C = modeler.create_rectangle(
            "XY", [D1 / 2, D2 / 2, 0], [-G - W * 2, W], f"__Line_C_{idx}"
        )
        line_D = modeler.create_rectangle(
            "XY", [D1 / 2 - G - W * 2, D2 / 2, 0], [W, -L], f"__Line_D_{idx}"
        )
        line_E = modeler.create_rectangle(
            "XY", [D1 / 2 - G - W * 2, D2 / 2 - L, 0], [-G, W], f"__Line_E_{idx}"
        )
        line_F = modeler.create_rectangle(
            "XY", [D1 / 2 - G * 2 - W * 2, D2 / 2 + -L, 0], [-W, L], f"__Line_F_{idx}"
        )
        line_G = modeler.create_rectangle(
            "XY",
            [D1 / 2 - G * 2 - W * 2, D2 / 2, 0],
            [-G - W * 2, W],
            f"__Line_G_{idx}",
        )
        line_H = modeler.create_rectangle(
            "XY",
            [D1 / 2 - G * 3 - W * 4, D2 / 2, 0],
            [W, -L],
            f"__Line_H_{idx}",
        )
        modeler.unite([line_A, line_B, line_C, line_D, line_E, line_F, line_G, line_H])
        line_plus = line_A
        line_plus.name = f"__Lines_plus_X_{idx}"
        mirrored_lines = modeler.duplicate_and_mirror(line_A, [0, 0, 0], [-1, 0, 0])
        line_minus = modeler[mirrored_lines[0]]
        line_minus.name = f"__Lines_minus_X_{idx}"
        modeler.unite([line_plus, line_minus])
        united_line = line_plus
        ground = modeler.create_rectangle(
            "XY", [-P / 2, -P / 2, -D], [P, P], f"__Ground_{idx}"
        )
        united_line.color = (255, 255, 0)
        ground.color = (255, 255, 0)
        if idx > 0:
            modeler.move([united_line, ground, substrate], [0, -P * idx, 0])
        hfss.assign_perfect_e(united_line, name=f"__United_Lines_{idx}")
        hfss.assign_perfect_e(ground, name=f"__Ground_{idx}")

仿真结果如下图所示。

Snipaste_2025-10-24_07-59-19

论文2

代码

from ansys.aedt.core.hfss import Hfss

Ls_Num = [
    (6, 2),
    (5, 3),
    (4, 2),
    (3, 3),
    (2, 7),
]
W = 2
G = 0.8
H = 50e-6

Rows = 60


def model():
    with Hfss() as hfss:
        modeler = hfss.modeler
        for obj in modeler.object_list:
            if obj.name.find("__") == 0:
                print("deleted", obj.name)
                obj.delete()
        x_length = 0
        pixels = []
        for i, (L, N) in enumerate(Ls_Num):
            for j in range(N):
                pixel_unit = modeler.create_rectangle(
                    "XY", [-L / 2, -W / 2, 0], [L, W], f"__Pixel_{i}_{j}_A"
                )
                pixel_unit.transparency = 0
                pixels.append(pixel_unit)
                # hfss.assign_perfect_e(pixel_unit, name=f"__Pixel_{i}_{j}_A")
                pixel_unit.color = (200, 200, 0)
                if i == 0 and j == 0:
                    x_length += L / 2 + G
                else:
                    modeler.move(pixel_unit, (x_length + L / 2, 0, 0))
                    pixel_unit_B = modeler.create_rectangle(
                        "XY", [-L / 2, -W / 2, 0], [L, W], f"__Pixel_{i}_{j}_B"
                    )
                    pixel_unit_B.transparency = 0
                    pixels.append(pixel_unit_B)
                    pixel_unit_B.color = (200, 200, 0)
                    modeler.move(pixel_unit_B, (-(x_length + L / 2), 0, 0))
                    # hfss.assign_perfect_e(pixel_unit_B, name=f"__Pixel_{i}_{j}_B")
                    x_length += L + G
                    pixels.append(pixel_unit_B)
        united_pixels = modeler[modeler.unite(pixels)]
        united_pixels.name = "__United_Pixels"
        modeler.duplicate_along_line(united_pixels, [0, W + G, 0], Rows, True)
        # modeler.duplicate_along_line(united_pixels, [0, 0, -H], Rows, True)
        hfss.assign_perfect_e(united_pixels, name="__United_Pixels")
        substrate = modeler.create_box(
            [-x_length + G / 2, -W / 2 - G / 2, 0],
            [x_length * 2 - G, (W + G) * Rows, -H],
            "__Substrate",
            "polyimide",
        )
        substrate.color = (0, 0, 250)
        substrate.transparency = 0.95

        region = modeler.create_box(
            [-x_length + G / 2, -W / 2 - G / 2, 20],
            [x_length * 2 - G, (W + G) * Rows, -20 - H - 10],
            "__Region",
        )
        region.transparency = 1


if __name__ == "__main__":
    model()

结果如图
image

参考文献

Y. Fan et al., "In-Plane Feed Antennas Based on Phase Gradient Metasurface," in IEEE Transactions on Antennas and Propagation, vol. 64, no. 9, pp. 3760-3765, Sept. 2016, doi: 10.1109/TAP.2016.2583472.
A. Hossain, S. Pancrazio, T. Kelley and A. -V. Pham, "A Compact and Low-Profile High-Gain Multilayer Vivaldi Antenna Based on Gradient Metasurface Superstrates," in IEEE Antennas and Wireless Propagation Letters, vol. 24, no. 6, pp. 1537-1541, June 2025, doi: 10.1109/LAWP.2025.3542315.
https://github.com/ansys/pyaedt/blob/main/README_CN.md
https://aedt.docs.pyansys.com/version/stable/API/index.html

posted @ 2025-10-24 08:44  GongYeSUDA  阅读(31)  评论(0)    收藏  举报