{ "cells": [ { "cell_type": "markdown", "id": "c45c0435", "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": "70ac27a3", "metadata": {}, "source": [ "## Perform imports and define constants\n", "\n", "Perform required imports." ] }, { "cell_type": "code", "execution_count": null, "id": "02254de2", "metadata": {}, "outputs": [], "source": [ "import os\n", "import tempfile\n", "import time" ] }, { "cell_type": "code", "execution_count": null, "id": "fac2d30f", "metadata": {}, "outputs": [], "source": [ "import ansys.aedt.core" ] }, { "cell_type": "markdown", "id": "eb198b70", "metadata": {}, "source": [ "Define constants." ] }, { "cell_type": "code", "execution_count": null, "id": "768c1b7b", "metadata": {}, "outputs": [], "source": [ "AEDT_VERSION = \"2024.2\"\n", "NUM_CORES = 4\n", "NG_MODE = False # Open AEDT UI when it is launched." ] }, { "cell_type": "markdown", "id": "3793f48f", "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": "1ff8a3ff", "metadata": {}, "outputs": [], "source": [ "temp_folder = tempfile.TemporaryDirectory(suffix=\".ansys\")" ] }, { "cell_type": "markdown", "id": "f91a2014", "metadata": {}, "source": [ "## Launch HFSS\n", "\n", "Create an HFSS design and change the units to microns." ] }, { "cell_type": "code", "execution_count": null, "id": "21b27e50", "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": "ef653fc1", "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": "c3e49ae2", "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" ] }, { "cell_type": "markdown", "id": "e3cc4f57", "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": "8ef36f3f", "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": "5e5aff63", "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": "939dc4fd", "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": "632ec5a6", "metadata": {}, "source": [ "## Center return path\n", "\n", "Center the return path." ] }, { "cell_type": "code", "execution_count": null, "id": "90aa67bc", "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", " matname=\"copper\",\n", ")" ] }, { "cell_type": "markdown", "id": "7f43de05", "metadata": {}, "source": [ "Create port 1." ] }, { "cell_type": "code", "execution_count": null, "id": "a15fbfac", "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": "272857b9", "metadata": {}, "source": [ "Create port 2." ] }, { "cell_type": "code", "execution_count": null, "id": "5bd62bb8", "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": "167258fd", "metadata": {}, "source": [ "Create the silicon substrate and the ground plane." ] }, { "cell_type": "code", "execution_count": null, "id": "eddf0895", "metadata": {}, "outputs": [], "source": [ "hfss.modeler.create_box(\n", " [x1 - 20, x1 - 20, \"-Tsub-{}{}/2\".format(thickness, hfss.modeler.model_units)],\n", " [-2 * x1 + 40, -2 * x1 + 40, \"Tsub\"],\n", " material=\"silicon\",\n", ")\n", "\n", "hfss.modeler.create_box(\n", " [x1 - 20, x1 - 20, \"-Tsub-{}{}/2\".format(thickness, hfss.modeler.model_units)],\n", " [-2 * x1 + 40, -2 * x1 + 40, -0.1],\n", " material=\"PEC\",\n", ")" ] }, { "cell_type": "markdown", "id": "8110382a", "metadata": {}, "source": [ "## Set up model\n", "\n", "Create the air box and radiation boundary condition." ] }, { "cell_type": "code", "execution_count": null, "id": "36d3b058", "metadata": {}, "outputs": [], "source": [ "box = hfss.modeler.create_box(\n", " [\n", " x1 - 20,\n", " x1 - 20,\n", " \"-Tsub-{}{}/2 - 0.1{}\".format(\n", " thickness, hfss.modeler.model_units, hfss.modeler.model_units\n", " ),\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": "1086952f", "metadata": {}, "source": [ "Assign a material override that allows object intersections,\n", "assigning conductors higher priority than insulators." ] }, { "cell_type": "code", "execution_count": null, "id": "7c6b7e48", "metadata": {}, "outputs": [], "source": [ "hfss.change_material_override()" ] }, { "cell_type": "markdown", "id": "3e52c460", "metadata": {}, "source": [ "View the model." ] }, { "cell_type": "code", "execution_count": null, "id": "21c9b68b", "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": "4c14f89e", "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": "b55940a6", "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": "e00e3c83", "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": "153194b7", "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": "47cbae3d", "metadata": {}, "source": [ "Define the inductance as a postprocessing variable." ] }, { "cell_type": "code", "execution_count": null, "id": "ab709511", "metadata": {}, "outputs": [], "source": [ "hfss.create_output_variable(\"L\", L_formula, solution=\"setup1 : LastAdaptive\")" ] }, { "cell_type": "markdown", "id": "c3766d2f", "metadata": {}, "source": [ "Plot the results using Matplotlib." ] }, { "cell_type": "code", "execution_count": null, "id": "5ed95f16", "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": "32860441", "metadata": {}, "source": [ "Export results to a CSV file" ] }, { "cell_type": "code", "execution_count": null, "id": "501e4aa9", "metadata": {}, "outputs": [], "source": [ "data.export_data_to_csv(os.path.join(hfss.toolkit_directory, \"output.csv\"))" ] }, { "cell_type": "markdown", "id": "cc4d100e", "metadata": {}, "source": [ "## Save project and close AEDT\n", "\n", "Save the project and close AEDT." ] }, { "cell_type": "code", "execution_count": null, "id": "8a17b869", "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": "16c530fc", "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": "06d21bef", "metadata": {}, "outputs": [], "source": [ "temp_folder.cleanup()" ] } ], "metadata": { "jupytext": { "cell_metadata_filter": "-all", "main_language": "python", "notebook_metadata_filter": "-all" } }, "nbformat": 4, "nbformat_minor": 5 }