{ "cells": [ { "cell_type": "markdown", "id": "d479755e", "metadata": {}, "source": [ "# 3D component creation and reuse" ] }, { "cell_type": "markdown", "id": "2144cfc7", "metadata": {}, "source": [ "Here is a workflow for creating a 3D component and reusing it:\n", "\n", "Step 1: Create an antenna using PyAEDT and HFSS 3D Modeler. (The antenna can also be created using EDB and\n", "HFSS 3D Layout).\n", "\n", "Step 2. Store the object as a 3D component on the disk.\n", "\n", "Step 3. Reuse the 3D component in another project.\n", "\n", "Step 4. Parametrize and optimize the target design.\n", "\n", "Keywords: **AEDT**, **General**, **3D component**." ] }, { "cell_type": "markdown", "id": "549abb00", "metadata": {}, "source": [ "## Perform imports and define constants\n", "Import the required packages." ] }, { "cell_type": "code", "execution_count": null, "id": "c40b9afd", "metadata": {}, "outputs": [], "source": [ "import os\n", "import tempfile\n", "import time" ] }, { "cell_type": "code", "execution_count": null, "id": "badf0f6a", "metadata": {}, "outputs": [], "source": [ "from ansys.aedt.core import Hfss" ] }, { "cell_type": "markdown", "id": "552fa23c", "metadata": {}, "source": [ "Define constants." ] }, { "cell_type": "code", "execution_count": null, "id": "1d1a19e4", "metadata": {}, "outputs": [], "source": [ "AEDT_VERSION = \"2024.2\"\n", "NG_MODE = False # Open AEDT UI when it is launched." ] }, { "cell_type": "markdown", "id": "fcd2bc73", "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": "cc77c648", "metadata": {}, "outputs": [], "source": [ "temp_folder = tempfile.TemporaryDirectory(suffix=\".ansys\")" ] }, { "cell_type": "markdown", "id": "d71b92f1", "metadata": {}, "source": [ "Create an HFSS object." ] }, { "cell_type": "code", "execution_count": null, "id": "390a09ab", "metadata": {}, "outputs": [], "source": [ "hfss = Hfss(\n", " version=AEDT_VERSION,\n", " new_desktop=True,\n", " close_on_exit=True,\n", " non_graphical=NG_MODE,\n", " solution_type=\"Modal\",\n", ")\n", "hfss.save_project(os.path.join(temp_folder.name, \"example.aedt\"))" ] }, { "cell_type": "markdown", "id": "774b5381", "metadata": {}, "source": [ "## Define variables\n", "\n", "PyAEDT can create and store all variables available in AEDT (such as design, project,\n", "and postprocessing)." ] }, { "cell_type": "code", "execution_count": null, "id": "2bf8ec2f", "metadata": {}, "outputs": [], "source": [ "hfss[\"thick\"] = \"0.1mm\"\n", "hfss[\"width\"] = \"1mm\"" ] }, { "cell_type": "markdown", "id": "5774b29e", "metadata": {}, "source": [ "## Create modeler objects\n", "\n", "PyAEDT supports all modeler functionalities available in AEDT.\n", "You can create, delete, and modify objects using all available Boolean operations.\n", "PyAEDT can also fully access history." ] }, { "cell_type": "code", "execution_count": null, "id": "9ca3c8d7", "metadata": {}, "outputs": [], "source": [ "substrate = hfss.modeler.create_box(\n", " [\"-width\", \"-width\", \"-thick\"],\n", " [\"2*width\", \"2*width\", \"thick\"],\n", " material=\"FR4_epoxy\",\n", " name=\"sub\",\n", ")\n", "\n", "patch = hfss.modeler.create_rectangle(\n", " \"XY\", [\"-width/2\", \"-width/2\", \"0mm\"], [\"width\", \"width\"], name=\"patch1\"\n", ")\n", "\n", "via1 = hfss.modeler.create_cylinder(\n", " 2,\n", " [\"-width/8\", \"-width/4\", \"-thick\"],\n", " \"0.01mm\",\n", " \"thick\",\n", " material=\"copper\",\n", " name=\"via_inner\",\n", ")\n", "\n", "via_outer = hfss.modeler.create_cylinder(\n", " 2,\n", " [\"-width/8\", \"-width/4\", \"-thick\"],\n", " \"0.025mm\",\n", " \"thick\",\n", " material=\"Teflon_based\",\n", " name=\"via_teflon\",\n", ")" ] }, { "cell_type": "markdown", "id": "4e3ae4eb", "metadata": {}, "source": [ "## Assign bundaries\n", "\n", "Most of HFSS boundaries and excitations are already available in PyAEDT.\n", "You can easily assign a boundary to a face or to an object by taking advantage of\n", "Object-Oriented Programming (OOP) available in PyAEDT." ] }, { "cell_type": "markdown", "id": "82a92b5a", "metadata": {}, "source": [ "### Assign Perfect E boundary to sheets\n", "\n", "Assign a Perfect E boundary to sheets." ] }, { "cell_type": "code", "execution_count": null, "id": "e026323b", "metadata": {}, "outputs": [], "source": [ "hfss.assign_perfecte_to_sheets(patch)" ] }, { "cell_type": "markdown", "id": "553aa35e", "metadata": {}, "source": [ "### Assign boundaries to faces\n", "\n", "Assign boundaries to the top and bottom faces of an object." ] }, { "cell_type": "code", "execution_count": null, "id": "6b97112b", "metadata": {}, "outputs": [], "source": [ "side_face = [\n", " i\n", " for i in via_outer.faces\n", " if i.id not in [via_outer.top_face_z.id, via_outer.bottom_face_z.id]\n", "]\n", "\n", "hfss.assign_perfecte_to_sheets(side_face)\n", "hfss.assign_perfecte_to_sheets(substrate.bottom_face_z)" ] }, { "cell_type": "markdown", "id": "c239dcbb", "metadata": {}, "source": [ "## Create wave port\n", "\n", "You can assign a wave port to a sheet or to a face of an object." ] }, { "cell_type": "code", "execution_count": null, "id": "1440cdb5", "metadata": {}, "outputs": [], "source": [ "hfss.wave_port(\n", " via_outer.bottom_face_z,\n", " name=\"P1\",\n", ")" ] }, { "cell_type": "markdown", "id": "70d9d5bb", "metadata": {}, "source": [ "## Create 3D component\n", "\n", "Once the model is ready, you can create a 3D component.\n", "Multiple options are available to partially select objects, coordinate systems,\n", "boundaries, and mesh operations. You can also create encrypted 3D components." ] }, { "cell_type": "code", "execution_count": null, "id": "029754f1", "metadata": {}, "outputs": [], "source": [ "component_path = os.path.join(temp_folder.name, \"component_test.aedbcomp\")\n", "hfss.modeler.create_3dcomponent(component_path, \"patch_antenna\")" ] }, { "cell_type": "markdown", "id": "d6a8222b", "metadata": {}, "source": [ "## Manage multiple project\n", "\n", "PyAEDT lets you control multiple projects, designs, and solution types at the same time." ] }, { "cell_type": "code", "execution_count": null, "id": "dc4730d7", "metadata": {}, "outputs": [], "source": [ "new_project = os.path.join(temp_folder.name, \"new_project.aedt\")\n", "hfss2 = Hfss(\n", " version=AEDT_VERSION,\n", " project=new_project,\n", " design=\"new_design\",\n", " solution_type=\"Modal\",\n", ")" ] }, { "cell_type": "markdown", "id": "5d3e4d0c", "metadata": {}, "source": [ "## Insert 3D component\n", "\n", "You can insert a 3D component without supplying additional information.\n", "All needed information is read from the file itself." ] }, { "cell_type": "code", "execution_count": null, "id": "a338e57c", "metadata": {}, "outputs": [], "source": [ "hfss2.modeler.insert_3d_component(component_path)" ] }, { "cell_type": "markdown", "id": "f7c0af48", "metadata": {}, "source": [ "## Parametrize 3D components\n", "\n", "You can specify parameters for any 3D components." ] }, { "cell_type": "code", "execution_count": null, "id": "dcbc5951", "metadata": {}, "outputs": [], "source": [ "hfss2.modeler.user_defined_components[\"patch_antenna1\"].parameters\n", "hfss2[\"p_thick\"] = \"1mm\"\n", "hfss2.modeler.user_defined_components[\"patch_antenna1\"].parameters[\"thick\"] = \"p_thick\"" ] }, { "cell_type": "markdown", "id": "709596e4", "metadata": {}, "source": [ "## Insert multiple 3D components\n", "\n", "There is no limit to the number of 3D components that can be inserted in a design.\n", "These components can be the same or linked to different files." ] }, { "cell_type": "code", "execution_count": null, "id": "c60372a4", "metadata": {}, "outputs": [], "source": [ "hfss2.modeler.create_coordinate_system(origin=[20, 20, 10], name=\"Second_antenna\")\n", "ant2 = hfss2.modeler.insert_3d_component(\n", " component_path, coordinate_system=\"Second_antenna\"\n", ")" ] }, { "cell_type": "markdown", "id": "e58c1de2", "metadata": {}, "source": [ "## Move 3D components\n", "\n", "Move a 3D component by either changing its position or moving the relative coordinate system." ] }, { "cell_type": "code", "execution_count": null, "id": "5213ef19", "metadata": {}, "outputs": [], "source": [ "hfss2.modeler.coordinate_systems[0].origin = [10, 10, 3]" ] }, { "cell_type": "markdown", "id": "dc029487", "metadata": {}, "source": [ "## Create air region\n", "\n", "Create an air region and assign a boundary to a face or an object." ] }, { "cell_type": "code", "execution_count": null, "id": "bcca2290", "metadata": {}, "outputs": [], "source": [ "hfss2.modeler.create_air_region(30, 30, 30, 30, 30, 30)\n", "hfss2.assign_radiation_boundary_to_faces(hfss2.modeler[\"Region\"].faces)" ] }, { "cell_type": "markdown", "id": "4370becd", "metadata": {}, "source": [ "## Create setup and optimetrics analysis\n", "\n", "Once a project is ready to be solved, use PyAEDT to create a setup and parametrics analysis.\n", "All setup parameters can be edited." ] }, { "cell_type": "code", "execution_count": null, "id": "bf0e4b1e", "metadata": {}, "outputs": [], "source": [ "setup1 = hfss2.create_setup()\n", "optim = hfss2.parametrics.add(\"p_thick\", \"0.2mm\", \"1.5mm\", step=14)" ] }, { "cell_type": "markdown", "id": "eafc9e98", "metadata": {}, "source": [ "## Plot objects" ] }, { "cell_type": "code", "execution_count": null, "id": "90a855d6", "metadata": {}, "outputs": [], "source": [ "hfss2.modeler.fit_all()\n", "hfss2.plot(\n", " show=False,\n", " output_file=os.path.join(hfss.working_directory, \"Image.jpg\"),\n", " plot_air_objects=True,\n", ")" ] }, { "cell_type": "markdown", "id": "e96e6607", "metadata": {}, "source": [ "## Release AEDT" ] }, { "cell_type": "code", "execution_count": null, "id": "612e5bbd", "metadata": {}, "outputs": [], "source": [ "hfss2.save_project()\n", "hfss2.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": "0c00e63e", "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": "5e5c508e", "metadata": {}, "outputs": [], "source": [ "temp_folder.cleanup()" ] } ], "metadata": { "jupytext": { "cell_metadata_filter": "-all", "main_language": "python", "notebook_metadata_filter": "-all" } }, "nbformat": 4, "nbformat_minor": 5 }