{ "cells": [ { "cell_type": "markdown", "id": "22e299b1", "metadata": {}, "source": [ "# Component antenna array" ] }, { "cell_type": "markdown", "id": "3eff10b9", "metadata": {}, "source": [ "This example shows how to use PyAEDT to create an example using a 3D component file. It sets\n", "up the analysis, solves it, and uses postprocessing functions to create plots using Matplotlib and\n", "PyVista without opening the HFSS user interface. This example runs only on Windows using CPython.\n", "\n", "Keywords: **HFSS**, **antenna array**, **3D components**, **far field**." ] }, { "cell_type": "markdown", "id": "d358e8c5", "metadata": {}, "source": [ "## Perform imports and define constants\n", "\n", "Perform required imports." ] }, { "cell_type": "code", "execution_count": null, "id": "d8807a16", "metadata": {}, "outputs": [], "source": [ "import os\n", "import tempfile\n", "import time" ] }, { "cell_type": "code", "execution_count": null, "id": "bbdc0562", "metadata": {}, "outputs": [], "source": [ "import ansys.aedt.core\n", "from ansys.aedt.core.visualization.advanced.farfield_visualization import \\\n", " FfdSolutionData" ] }, { "cell_type": "markdown", "id": "5848ed54", "metadata": {}, "source": [ "Define constants" ] }, { "cell_type": "code", "execution_count": null, "id": "428f6ef1", "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": "37abc9ed", "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": "46ba594d", "metadata": {}, "outputs": [], "source": [ "temp_folder = tempfile.TemporaryDirectory(suffix=\".ansys\")" ] }, { "cell_type": "markdown", "id": "641ce1e8", "metadata": {}, "source": [ "## Download 3D component\n", "Download the 3D component that is needed to run the example." ] }, { "cell_type": "code", "execution_count": null, "id": "07aa23d9", "metadata": {}, "outputs": [], "source": [ "example_path = ansys.aedt.core.downloads.download_3dcomponent(\n", " destination=temp_folder.name\n", ")" ] }, { "cell_type": "markdown", "id": "9abf4099", "metadata": {}, "source": [ "## Launch HFSS and open project\n", "\n", "Launch HFSS and open the project." ] }, { "cell_type": "code", "execution_count": null, "id": "0ec9f716", "metadata": {}, "outputs": [], "source": [ "project_name = os.path.join(temp_folder.name, \"array.aedt\")\n", "hfss = ansys.aedt.core.Hfss(\n", " project=project_name,\n", " version=AEDT_VERSION,\n", " design=\"Array_Simple\",\n", " non_graphical=NG_MODE,\n", " new_desktop=True,\n", ")\n", "\n", "print(\"Project name \" + project_name)" ] }, { "cell_type": "markdown", "id": "b2a9c4a6", "metadata": {}, "source": [ "## Read array definition\n", "\n", "Read array definition from the JSON file." ] }, { "cell_type": "code", "execution_count": null, "id": "c92e0595", "metadata": {}, "outputs": [], "source": [ "dict_in = ansys.aedt.core.general_methods.read_json(\n", " os.path.join(example_path, \"array_simple.json\")\n", ")" ] }, { "cell_type": "markdown", "id": "9461e02c", "metadata": {}, "source": [ "## Define 3D component\n", "\n", "Define the 3D component cell." ] }, { "cell_type": "code", "execution_count": null, "id": "78a0fac8", "metadata": {}, "outputs": [], "source": [ "dict_in[\"Circ_Patch_5GHz1\"] = os.path.join(example_path, \"Circ_Patch_5GHz.a3dcomp\")" ] }, { "cell_type": "markdown", "id": "4cd6587c", "metadata": {}, "source": [ "## Add 3D component array\n", "\n", "A 3D component array is created from the previous dictionary.\n", "If a 3D component is not available in the design, it is loaded\n", "into the dictionary from the path that you specify. The following\n", "code edits the dictionary to point to the location of the A3DCOMP file." ] }, { "cell_type": "code", "execution_count": null, "id": "1f04e824", "metadata": {}, "outputs": [], "source": [ "array = hfss.add_3d_component_array_from_json(dict_in)" ] }, { "cell_type": "markdown", "id": "3c3add1f", "metadata": {}, "source": [ "## Modify cells\n", "\n", "Make the center element passive and rotate the corner elements." ] }, { "cell_type": "code", "execution_count": null, "id": "62dced8b", "metadata": {}, "outputs": [], "source": [ "array.cells[1][1].is_active = False\n", "array.cells[0][0].rotation = 90\n", "array.cells[0][2].rotation = 90\n", "array.cells[2][0].rotation = 90\n", "array.cells[2][2].rotation = 90" ] }, { "cell_type": "markdown", "id": "1dc4b21c", "metadata": {}, "source": [ "## Set up simulation and analyze\n", "\n", "Set up a simulation and analyze it." ] }, { "cell_type": "code", "execution_count": null, "id": "d3a69fef", "metadata": { "lines_to_next_cell": 2 }, "outputs": [], "source": [ "setup = hfss.create_setup()\n", "setup.props[\"Frequency\"] = \"5GHz\"\n", "setup.props[\"MaximumPasses\"] = 3\n", "hfss.analyze(cores=NUM_CORES)" ] }, { "cell_type": "markdown", "id": "11262711", "metadata": {}, "source": [ "## Get far field data\n", "\n", "Get far field data. After the simulation completes, the far\n", "field data is generated port by port and stored in a data class." ] }, { "cell_type": "code", "execution_count": null, "id": "403e0719", "metadata": {}, "outputs": [], "source": [ "ffdata = hfss.get_antenna_data(setup=hfss.nominal_adaptive, sphere=\"Infinite Sphere1\")" ] }, { "cell_type": "markdown", "id": "f0acf688", "metadata": {}, "source": [ "## Generate contour plot\n", "\n", "Generate a contour plot. You can define the Theta scan and Phi scan." ] }, { "cell_type": "code", "execution_count": null, "id": "e52c639e", "metadata": {}, "outputs": [], "source": [ "ffdata.farfield_data.plot_contour(\n", " quantity=\"RealizedGain\",\n", " title=\"Contour at {}Hz\".format(ffdata.farfield_data.frequency),\n", ")" ] }, { "cell_type": "markdown", "id": "429b5108", "metadata": {}, "source": [ "## Release AEDT\n", "\n", "Release AEDT.\n", "You can perform far field postprocessing without AEDT because the data is stored." ] }, { "cell_type": "code", "execution_count": null, "id": "37bbab00", "metadata": {}, "outputs": [], "source": [ "metadata_file = ffdata.metadata_file\n", "working_directory = hfss.working_directory" ] }, { "cell_type": "code", "execution_count": null, "id": "9bacee3f", "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": "1cdab998", "metadata": {}, "source": [ "## Load far field data\n", "\n", "Load the stored far field data." ] }, { "cell_type": "code", "execution_count": null, "id": "e4f96521", "metadata": {}, "outputs": [], "source": [ "ffdata = FfdSolutionData(input_file=metadata_file)" ] }, { "cell_type": "markdown", "id": "6952b8a2", "metadata": {}, "source": [ "## Generate contour plot\n", "\n", "Generate a contour plot. You can define the Theta scan\n", "and Phi scan." ] }, { "cell_type": "code", "execution_count": null, "id": "70221e87", "metadata": {}, "outputs": [], "source": [ "ffdata.plot_contour(\n", " quantity=\"RealizedGain\", title=\"Contour at {}Hz\".format(ffdata.frequency)\n", ")" ] }, { "cell_type": "markdown", "id": "e0e51a00", "metadata": {}, "source": [ "## Generate 2D cutout plots\n", "\n", "Generate 2D cutout plots. You can define the Theta scan\n", "and Phi scan." ] }, { "cell_type": "code", "execution_count": null, "id": "f13b3597", "metadata": {}, "outputs": [], "source": [ "ffdata.plot_cut(\n", " quantity=\"RealizedGain\",\n", " primary_sweep=\"theta\",\n", " secondary_sweep_value=[-180, -75, 75],\n", " title=\"Azimuth at {}Hz\".format(ffdata.frequency),\n", " quantity_format=\"dB10\",\n", ")" ] }, { "cell_type": "code", "execution_count": null, "id": "2696e94c", "metadata": {}, "outputs": [], "source": [ "ffdata.plot_cut(\n", " quantity=\"RealizedGain\",\n", " primary_sweep=\"phi\",\n", " secondary_sweep_value=30,\n", " title=\"Elevation\",\n", " quantity_format=\"dB10\",\n", ")" ] }, { "cell_type": "markdown", "id": "c51cee76", "metadata": {}, "source": [ "## Generate 3D plot\n", "\n", "Generate 3D plots. You can define the Theta scan and Phi scan." ] }, { "cell_type": "code", "execution_count": null, "id": "a790d95e", "metadata": {}, "outputs": [], "source": [ "ffdata.plot_3d(\n", " quantity=\"RealizedGain\",\n", " output_file=os.path.join(working_directory, \"Image.jpg\"),\n", " show=False,\n", ")" ] }, { "cell_type": "markdown", "id": "4c4f7853", "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\n", "removes all temporary files, including the project folder." ] }, { "cell_type": "code", "execution_count": null, "id": "33acf814", "metadata": {}, "outputs": [], "source": [ "temp_folder.cleanup()" ] } ], "metadata": { "jupytext": { "cell_metadata_filter": "-all", "main_language": "python", "notebook_metadata_filter": "-all" } }, "nbformat": 4, "nbformat_minor": 5 }