Download this example

Download this example as a Jupyter Notebook or as a Python script.


Flex cable CPWG#

This example shows how to use PyAEDT to create a flex cable CPWG (coplanar waveguide with ground).

Keywords: HFSS, flex cable, CPWG.

Perform imports and define constants#

Perform required imports.

[1]:
import os
import tempfile
from math import cos, radians, sin, sqrt
[2]:
import ansys.aedt.core
from ansys.aedt.core.generic.general_methods import generate_unique_name

Define constants.

[3]:
AEDT_VERSION = "2024.2"

Set non-graphical mode#

Set non-graphical mode. You can set non_graphical either to True or False.

[4]:
non_graphical = False

Create temporary directory#

Create a temporary directory where downloaded data or dumped data can be stored. If you’d like to retrieve the project data for subsequent use, the temporary folder name is given by temp_folder.name.

[5]:
temp_folder = tempfile.TemporaryDirectory(suffix=".ansys")

Launch AEDT#

Launch AEDT, create an HFSS design, and save the project.

[6]:
hfss = ansys.aedt.core.Hfss(
    version=AEDT_VERSION,
    solution_type="DrivenTerminal",
    new_desktop=True,
    non_graphical=non_graphical,
)
hfss.save_project(
    os.path.join(temp_folder.name, generate_unique_name("example") + ".aedt")
)
PyAEDT INFO: Python version 3.10.11 (tags/v3.10.11:7d4cc5a, Apr  5 2023, 00:38:17) [MSC v.1929 64 bit (AMD64)]
PyAEDT INFO: PyAEDT version 0.12.dev0.
PyAEDT INFO: Initializing new Desktop session.
PyAEDT INFO: Log on console is enabled.
PyAEDT INFO: Log on file C:\Users\ansys\AppData\Local\Temp\pyaedt_ansys_d26aa191-6de8-4067-8cba-069fd3394be5.log is enabled.
PyAEDT INFO: Log on AEDT is enabled.
PyAEDT INFO: Debug logger is disabled. PyAEDT methods will not be logged.
PyAEDT INFO: Launching PyAEDT with gRPC plugin.
PyAEDT INFO: New AEDT session is starting on gRPC port 60816
PyAEDT INFO: AEDT installation Path C:\Program Files\AnsysEM\v242\Win64
PyAEDT INFO: Ansoft.ElectronicsDesktop.2024.2 version started with process ID 1904.
PyAEDT INFO: Project Project1 has been created.
PyAEDT INFO: No design is present. Inserting a new design.
PyAEDT INFO: Added design 'HFSS_93Y' of type HFSS.
PyAEDT INFO: Aedt Objects correctly read
PyAEDT INFO: Project example_CVEB4E Saved correctly
[6]:
True

Modify design settings#

Modify some design settings.

[7]:
hfss.change_material_override(True)
hfss.change_automatically_use_causal_materials(True)
hfss.create_open_region("100GHz")
hfss.modeler.model_units = "mil"
hfss.mesh.assign_initial_mesh_from_slider(applycurvilinear=True)
PyAEDT INFO: Enabling Material Override
PyAEDT INFO: Enabling Automatic use of causal materials
PyAEDT INFO: Open Region correctly created.
PyAEDT INFO: Project example_CVEB4E Saved correctly
PyAEDT INFO: Modeler class has been initialized! Elapsed time: 0m 1sec
PyAEDT INFO: Mesh class has been initialized! Elapsed time: 0m 0sec
PyAEDT INFO: Mesh class has been initialized! Elapsed time: 0m 0sec
[7]:
True

Create variables#

Create input variables for creating the flex cable CPWG.

[8]:
total_length = 300
theta = 120
r = 100
width = 3
height = 0.1
spacing = 1.53
gnd_width = 10
gnd_thickness = 2

xt = (total_length - r * radians(theta)) / 2

Create bend#

The create_bending() method creates a list of points for the bend based on the curvature radius and extension.

[9]:
def create_bending(radius, extension=0):
    points = [(-xt, 0, -radius), (0, 0, -radius)]

    for i in [radians(i) for i in range(theta)] + [radians(theta + 0.000000001)]:
        points.append((radius * sin(i), 0, -radius * cos(i)))

    x1, y1, z1 = points[-1]
    x0, y0, z0 = points[-2]

    scale = (xt + extension) / sqrt((x1 - x0) ** 2 + (z1 - z0) ** 2)
    x, y, z = (x1 - x0) * scale + x0, 0, (z1 - z0) * scale + z0

    points[-1] = (x, y, z)
    return points

Draw signal line#

Draw a signal line to create a bent signal wire.

[10]:
points = create_bending(r, 1)
line = hfss.modeler.create_polyline(
    points=points,
    xsection_type="Rectangle",
    xsection_width=height,
    xsection_height=width,
    material="copper",
)
PyAEDT INFO: Materials class has been initialized! Elapsed time: 0m 0sec

Draw ground line#

Draw a ground line to create two bent ground wires.

[11]:
gnd_r = [(x, spacing + width / 2 + gnd_width / 2, z) for x, y, z in points]
gnd_l = [(x, -y, z) for x, y, z in gnd_r]

gnd_objs = []
for gnd in [gnd_r, gnd_l]:
    x = hfss.modeler.create_polyline(
        points=gnd,
        xsection_type="Rectangle",
        xsection_width=height,
        xsection_height=gnd_width,
        material="copper",
    )
    x.color = (255, 0, 0)
    gnd_objs.append(x)

Draw dielectric#

Draw a dielectric to create a dielectric cable.

[12]:
points = create_bending(r + (height + gnd_thickness) / 2)

fr4 = hfss.modeler.create_polyline(
    points=points,
    xsection_type="Rectangle",
    xsection_width=gnd_thickness,
    xsection_height=width + 2 * spacing + 2 * gnd_width,
    material="FR4_epoxy",
)

Create bottom metals#

Create the bottom metals.

[13]:
points = create_bending(r + height + gnd_thickness, 1)

bot = hfss.modeler.create_polyline(
    points=points,
    xsection_type="Rectangle",
    xsection_width=height,
    xsection_height=width + 2 * spacing + 2 * gnd_width,
    material="copper",
)

Create port interfaces#

Create port interfaces (PEC enclosures).

[14]:
port_faces = []
for face, blockname in zip([fr4.top_face_z, fr4.bottom_face_x], ["b1", "b2"]):
    xc, yc, zc = face.center
    positions = [i.position for i in face.vertices]

    port_sheet_list = [
        ((x - xc) * 10 + xc, (y - yc) + yc, (z - zc) * 10 + zc) for x, y, z in positions
    ]
    s = hfss.modeler.create_polyline(
        port_sheet_list, close_surface=True, cover_surface=True
    )
    center = [round(i, 6) for i in s.faces[0].center]

    port_block = hfss.modeler.thicken_sheet(s.name, -5)
    port_block.name = blockname
    for f in port_block.faces:

        if [round(i, 6) for i in f.center] == center:
            port_faces.append(f)

    port_block.material_name = "PEC"

    for i in [line, bot] + gnd_objs:
        i.subtract([port_block], True)

    print(port_faces)
PyAEDT INFO: Parsing design objects. This operation can take time
PyAEDT INFO: Parsing C:/Users/ansys/AppData/Local/Temp/tmp97609_2d.ansys/example_CVEB4E.aedt.
PyAEDT INFO: File C:/Users/ansys/AppData/Local/Temp/tmp97609_2d.ansys/example_CVEB4E.aedt correctly loaded. Elapsed time: 0m 0sec
PyAEDT INFO: aedt file load time 0.0
PyAEDT INFO: 3D Modeler objects parsed. Elapsed time: 0m 0sec
[7391]
[7391, 7586]

Create boundary condition#

Creates a Perfect E boundary condition.

[15]:
boundary = []
for face in [fr4.top_face_y, fr4.bottom_face_y]:
    s = hfss.modeler.create_object_from_face(face)
    boundary.append(s)
    hfss.assign_perfecte_to_sheets(s)
PyAEDT INFO: Boundary Perfect E PerfE_8FDR3G has been correctly created.
PyAEDT INFO: Boundary Perfect E PerfE_A9WIJW has been correctly created.

Create ports#

Create ports.

[16]:
for s, port_name in zip(port_faces, ["1", "2"]):
    reference = [i.name for i in gnd_objs + boundary + [bot]] + ["b1", "b2"]

    hfss.wave_port(s.id, name=port_name, reference=reference)
PyAEDT INFO: Boundary AutoIdentify 1 has been correctly created.
PyAEDT INFO: Boundary AutoIdentify 2 has been correctly created.

Create setup and sweep#

Create the setup and sweep.

[17]:
setup = hfss.create_setup("setup1")
setup["Frequency"] = "2GHz"
setup.props["MaximumPasses"] = 10
setup.props["MinimumConvergedPasses"] = 2
hfss.create_linear_count_sweep(
    setup="setup1",
    units="GHz",
    start_frequency=1e-1,
    stop_frequency=4,
    num_of_freq_points=101,
    name="sweep1",
    save_fields=False,
    sweep_type="Interpolating",
)
PyAEDT INFO: Linear count sweep sweep1 has been correctly created.
[17]:
<ansys.aedt.core.modules.solve_sweeps.SweepHFSS at 0x2e3441b1420>

Release AEDT#

[18]:
hfss.release_desktop()
PyAEDT INFO: Desktop has been released and closed.
[18]:
True

Clean up#

All project files are saved in the folder temp_folder.name. If you’ve run this example as a Jupyter notebook, you can retrieve those project files. The following cell removes all temporary files, including the project folder.

[19]:
temp_folder.cleanup()

Download this example

Download this example as a Jupyter Notebook or as a Python script.