{ "cells": [ { "cell_type": "markdown", "id": "f1c2ea6a", "metadata": {}, "source": [ "# Spiral inductor\n", "\n", "This example shows how to use PyAEDT to create a spiral inductor, solve it, and plot results.\n", "\n", "Keywords: **HFSS**, **spiral**, **inductance**, **output variable**." ] }, { "cell_type": "markdown", "id": "1ee8801a", "metadata": {}, "source": [ "## Perform imports and define constants\n", "\n", "Perform required imports." ] }, { "cell_type": "code", "execution_count": null, "id": "7edad4d4", "metadata": {}, "outputs": [], "source": [ "import os\n", "import tempfile\n", "import time\n", "\n", "import ansys.aedt.core" ] }, { "cell_type": "markdown", "id": "418ec1ba", "metadata": {}, "source": [ "Define constants." ] }, { "cell_type": "code", "execution_count": null, "id": "c7af80da", "metadata": {}, "outputs": [], "source": [ "AEDT_VERSION = \"2025.1\"\n", "NUM_CORES = 4\n", "NG_MODE = False # Open AEDT UI when it is launched." ] }, { "cell_type": "markdown", "id": "6761f399", "metadata": {}, "source": [ "## Create temporary directory\n", "\n", "Create a temporary directory where downloaded data or\n", "dumped data can be stored.\n", "If you'd like to retrieve the project data for subsequent use,\n", "the temporary folder name is given by ``temp_folder.name``." ] }, { "cell_type": "code", "execution_count": null, "id": "f017df05", "metadata": {}, "outputs": [], "source": [ "temp_folder = tempfile.TemporaryDirectory(suffix=\".ansys\")" ] }, { "cell_type": "markdown", "id": "473d669f", "metadata": {}, "source": [ "## Launch HFSS\n", "\n", "Create an HFSS design and change the units to microns." ] }, { "cell_type": "code", "execution_count": null, "id": "c076e50c", "metadata": {}, "outputs": [], "source": [ "project_name = os.path.join(temp_folder.name, \"spiral.aedt\")\n", "hfss = ansys.aedt.core.Hfss(\n", " project=project_name,\n", " version=AEDT_VERSION,\n", " non_graphical=NG_MODE,\n", " design=\"A1\",\n", " new_desktop=True,\n", " solution_type=\"Modal\",\n", ")\n", "hfss.modeler.model_units = \"um\"" ] }, { "cell_type": "markdown", "id": "cabcf348", "metadata": {}, "source": [ "## Define variables\n", "\n", "Define input variables. You can use the values that follow or edit\n", "them." ] }, { "cell_type": "code", "execution_count": null, "id": "c0607e74", "metadata": {}, "outputs": [], "source": [ "rin = 10\n", "width = 2\n", "spacing = 1\n", "thickness = 1\n", "Np = 8\n", "Nr = 10\n", "gap = 3\n", "hfss[\"Tsub\"] = \"6\" + hfss.modeler.model_units\n", "hfss[\"thickness\"] = f\"{thickness} {hfss.modeler.model_units}\"" ] }, { "cell_type": "markdown", "id": "0d2cc559", "metadata": { "lines_to_next_cell": 2 }, "source": [ "## Standardize polyline\n", "\n", "Define a function that creates a polyline using the ``create_line()`` method. This\n", "function creates a polyline having a fixed width, thickness, and material." ] }, { "cell_type": "code", "execution_count": null, "id": "d904cffb", "metadata": {}, "outputs": [], "source": [ "def create_line(pts):\n", " hfss.modeler.create_polyline(\n", " pts,\n", " xsection_type=\"Rectangle\",\n", " xsection_width=width,\n", " xsection_height=thickness,\n", " material=\"copper\",\n", " )" ] }, { "cell_type": "markdown", "id": "e3dbeab1", "metadata": {}, "source": [ "## Create spiral inductor\n", "\n", "Create the spiral inductor. This spiral inductor is not\n", "parametric, but you could parametrize it later." ] }, { "cell_type": "code", "execution_count": null, "id": "5fc115c9", "metadata": { "lines_to_next_cell": 2 }, "outputs": [], "source": [ "ind = hfss.modeler.create_spiral(\n", " internal_radius=rin,\n", " width=width,\n", " spacing=spacing,\n", " turns=Nr,\n", " faces=Np,\n", " thickness=thickness,\n", " material=\"copper\",\n", " name=\"Inductor1\",\n", ")" ] }, { "cell_type": "markdown", "id": "d072d231", "metadata": {}, "source": [ "## Center return path\n", "\n", "Center the return path." ] }, { "cell_type": "code", "execution_count": null, "id": "924c5cf0", "metadata": {}, "outputs": [], "source": [ "x0, y0, z0 = ind.points[0]\n", "x1, y1, z1 = ind.points[-1]\n", "create_line([(x0 - width / 2, y0, -gap), (abs(x1) + 5, y0, -gap)])\n", "hfss.modeler.create_box(\n", " [x0 - width / 2, y0 - width / 2, -gap - thickness / 2],\n", " [width, width, gap + thickness],\n", " material=\"copper\",\n", ")" ] }, { "cell_type": "markdown", "id": "e97cc287", "metadata": {}, "source": [ "Create port 1." ] }, { "cell_type": "code", "execution_count": null, "id": "93ebc255", "metadata": {}, "outputs": [], "source": [ "hfss.modeler.create_rectangle(\n", " orientation=ansys.aedt.core.constants.PLANE.YZ,\n", " origin=[abs(x1) + 5, y0 - width / 2, -gap - thickness / 2],\n", " sizes=[width, \"-Tsub+{}{}\".format(gap, hfss.modeler.model_units)],\n", " name=\"port1\",\n", ")\n", "hfss.lumped_port(assignment=\"port1\", integration_line=ansys.aedt.core.constants.AXIS.Z)" ] }, { "cell_type": "markdown", "id": "cf160bcf", "metadata": {}, "source": [ "Create port 2." ] }, { "cell_type": "code", "execution_count": null, "id": "90910283", "metadata": {}, "outputs": [], "source": [ "create_line([(x1 + width / 2, y1, 0), (x1 - 5, y1, 0)])\n", "hfss.modeler.create_rectangle(\n", " ansys.aedt.core.constants.PLANE.YZ,\n", " [x1 - 5, y1 - width / 2, -thickness / 2],\n", " [width, \"-Tsub\"],\n", " name=\"port2\",\n", ")\n", "hfss.lumped_port(assignment=\"port2\", integration_line=ansys.aedt.core.constants.AXIS.Z)" ] }, { "cell_type": "markdown", "id": "aa7e9906", "metadata": {}, "source": [ "Create the silicon substrate and the ground plane." ] }, { "cell_type": "code", "execution_count": null, "id": "85c09b3a", "metadata": {}, "outputs": [], "source": [ "hfss.modeler.create_box(\n", " [x1 - 20, x1 - 20, \"-Tsub-thickness/2\"],\n", " [-2 * x1 + 40, -2 * x1 + 40, \"Tsub\"],\n", " material=\"silicon\",\n", ")\n", "\n", "hfss.modeler.create_box(\n", " [x1 - 20, x1 - 20, \"-Tsub-thickness/2\"],\n", " [-2 * x1 + 40, -2 * x1 + 40, -0.1],\n", " material=\"PEC\",\n", ")" ] }, { "cell_type": "markdown", "id": "887b2797", "metadata": {}, "source": [ "## Set up model\n", "\n", "Create the air box and radiation boundary condition." ] }, { "cell_type": "code", "execution_count": null, "id": "aaf4a1f8", "metadata": {}, "outputs": [], "source": [ "box = hfss.modeler.create_box(\n", " [\n", " x1 - 20,\n", " x1 - 20,\n", " \"-Tsub-thickness/2 - 0.1{}\".format(hfss.modeler.model_units),\n", " ],\n", " [-2 * x1 + 40, -2 * x1 + 40, 100],\n", " name=\"airbox\",\n", " material=\"air\",\n", ")\n", "\n", "hfss.assign_radiation_boundary_to_objects(\"airbox\")" ] }, { "cell_type": "markdown", "id": "a21e916b", "metadata": {}, "source": [ "Assign a material override that allows object intersections,\n", "assigning conductors higher priority than insulators." ] }, { "cell_type": "code", "execution_count": null, "id": "5c4903d7", "metadata": {}, "outputs": [], "source": [ "hfss.change_material_override()" ] }, { "cell_type": "markdown", "id": "9b08a82e", "metadata": {}, "source": [ "View the model." ] }, { "cell_type": "code", "execution_count": null, "id": "ee434aca", "metadata": {}, "outputs": [], "source": [ "hfss.plot(\n", " show=False,\n", " output_file=os.path.join(hfss.working_directory, \"Image.jpg\"),\n", " plot_air_objects=False,\n", ")" ] }, { "cell_type": "markdown", "id": "81487527", "metadata": {}, "source": [ "## Generate the solution\n", "\n", "Create the setup, including a frequency sweep. Then, solve the project." ] }, { "cell_type": "code", "execution_count": null, "id": "b4019c37", "metadata": {}, "outputs": [], "source": [ "setup1 = hfss.create_setup(name=\"setup1\")\n", "setup1.props[\"Frequency\"] = \"10GHz\"\n", "hfss.create_linear_count_sweep(\n", " setup=\"setup1\",\n", " units=\"GHz\",\n", " start_frequency=1e-3,\n", " stop_frequency=50,\n", " num_of_freq_points=451,\n", " sweep_type=\"Interpolating\",\n", ")\n", "hfss.save_project()\n", "hfss.analyze(cores=NUM_CORES)" ] }, { "cell_type": "markdown", "id": "c4ea6f14", "metadata": {}, "source": [ "## Postprocess\n", "\n", "Get report data and use the following formulas to calculate\n", "the inductance and quality factor." ] }, { "cell_type": "code", "execution_count": null, "id": "804a8ae5", "metadata": {}, "outputs": [], "source": [ "L_formula = \"1e9*im(1/Y(1,1))/(2*pi*freq)\"\n", "Q_formula = \"im(Y(1,1))/re(Y(1,1))\"" ] }, { "cell_type": "markdown", "id": "ec0e2035", "metadata": {}, "source": [ "Define the inductance as a postprocessing variable." ] }, { "cell_type": "code", "execution_count": null, "id": "6aa3c5ec", "metadata": {}, "outputs": [], "source": [ "hfss.create_output_variable(\"L\", L_formula, solution=\"setup1 : LastAdaptive\")" ] }, { "cell_type": "markdown", "id": "6713fe0d", "metadata": {}, "source": [ "Plot the results using Matplotlib." ] }, { "cell_type": "code", "execution_count": null, "id": "8651cbd8", "metadata": {}, "outputs": [], "source": [ "data = hfss.post.get_solution_data([L_formula, Q_formula])\n", "data.plot(\n", " curves=[L_formula, Q_formula], formula=\"re\", x_label=\"Freq\", y_label=\"L and Q\"\n", ")" ] }, { "cell_type": "markdown", "id": "151514fa", "metadata": {}, "source": [ "Export results to a CSV file" ] }, { "cell_type": "code", "execution_count": null, "id": "ab59438b", "metadata": {}, "outputs": [], "source": [ "data.export_data_to_csv(os.path.join(hfss.toolkit_directory, \"output.csv\"))" ] }, { "cell_type": "markdown", "id": "3926f9e1", "metadata": {}, "source": [ "## Save project and close AEDT\n", "\n", "Save the project and close AEDT." ] }, { "cell_type": "code", "execution_count": null, "id": "437519f4", "metadata": {}, "outputs": [], "source": [ "hfss.save_project()\n", "hfss.release_desktop()\n", "# Wait 3 seconds to allow AEDT to shut down before cleaning the temporary directory.\n", "time.sleep(3)" ] }, { "cell_type": "markdown", "id": "b7a207dd", "metadata": {}, "source": [ "## Clean up\n", "\n", "All project files are saved in the folder ``temp_folder.name``.\n", "If you've run this example as a Jupyter notebook, you\n", "can retrieve those project files. The following cell removes\n", "all temporary files, including the project folder." ] }, { "cell_type": "code", "execution_count": null, "id": "f7ef6065", "metadata": {}, "outputs": [], "source": [ "temp_folder.cleanup()" ] } ], "metadata": { "jupytext": { "cell_metadata_filter": "-all", "main_language": "python", "notebook_metadata_filter": "-all" } }, "nbformat": 4, "nbformat_minor": 5 }