{ "cells": [ { "cell_type": "markdown", "id": "8dceea27", "metadata": {}, "source": [ "# HFSS-Mechanical multiphysics analysis\n", "\n", "This example shows how to use PyAEDT to create a multiphysics workflow that\n", "includes Circuit, HFSS, and Mechanical.\n", "\n", "Keywords: **Multiphysics**, **HFSS**, **Mechanical AEDT**, **Circuit**." ] }, { "cell_type": "markdown", "id": "f1dd40d6", "metadata": {}, "source": [ "## Perform imports and define constants\n", "\n", "Perform required imports." ] }, { "cell_type": "code", "execution_count": null, "id": "d47019e4", "metadata": {}, "outputs": [], "source": [ "import tempfile\n", "import time\n", "\n", "import ansys.aedt.core\n" ] }, { "cell_type": "markdown", "id": "62624d59", "metadata": {}, "source": [ "Define constants." ] }, { "cell_type": "code", "execution_count": null, "id": "20747e4c", "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": "b572014a", "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": "786cf297", "metadata": {}, "outputs": [], "source": [ "temp_folder = tempfile.TemporaryDirectory(suffix=\".ansys\")" ] }, { "cell_type": "markdown", "id": "ad5f0eb6", "metadata": {}, "source": [ "## Download and open project\n", "\n", "Download and open the project. Save it to the temporary folder." ] }, { "cell_type": "code", "execution_count": null, "id": "0db19cda", "metadata": {}, "outputs": [], "source": [ "project_name = ansys.aedt.core.downloads.download_via_wizard(\n", " destination=temp_folder.name\n", ")" ] }, { "cell_type": "markdown", "id": "d7110e16", "metadata": {}, "source": [ "## Start HFSS\n", "\n", "Initialize HFSS." ] }, { "cell_type": "code", "execution_count": null, "id": "34efeb8f", "metadata": {}, "outputs": [], "source": [ "hfss = ansys.aedt.core.Hfss(\n", " project=project_name,\n", " version=AEDT_VERSION,\n", " non_graphical=NG_MODE,\n", " new_desktop=True,\n", ")\n", "hfss.change_material_override(True)" ] }, { "cell_type": "markdown", "id": "f4330961", "metadata": {}, "source": [ "## Initialize Circuit\n", "\n", "Initialize Circuit and add the HFSS dynamic link component." ] }, { "cell_type": "code", "execution_count": null, "id": "f8c35a03", "metadata": {}, "outputs": [], "source": [ "circuit = ansys.aedt.core.Circuit(version=AEDT_VERSION)\n", "hfss_comp = circuit.modeler.schematic.add_subcircuit_dynamic_link(pyaedt_app=hfss)" ] }, { "cell_type": "markdown", "id": "8e23852e", "metadata": {}, "source": [ "## Set up dynamic link options\n", "\n", "Set up dynamic link options. The argument for the ``set_sim_option_on_hfss_subcircuit()``\n", "method can be the component name, component ID, or component object." ] }, { "cell_type": "code", "execution_count": null, "id": "332ea774", "metadata": {}, "outputs": [], "source": [ "circuit.modeler.schematic.refresh_dynamic_link(name=hfss_comp.composed_name)\n", "circuit.modeler.schematic.set_sim_option_on_hfss_subcircuit(component=hfss_comp)\n", "hfss_setup_name = hfss.setups[0].name + \" : \" + hfss.setups[0].sweeps[0].name\n", "circuit.modeler.schematic.set_sim_solution_on_hfss_subcircuit(\n", " component=hfss_comp.composed_name, solution_name=hfss_setup_name\n", ")" ] }, { "cell_type": "markdown", "id": "5b3f0594", "metadata": {}, "source": [ "## Create ports and excitations\n", "\n", "Create ports and excitations. Find component pin locations and create interface\n", "ports on them. Define the voltage source on the input port." ] }, { "cell_type": "code", "execution_count": null, "id": "a9921412", "metadata": {}, "outputs": [], "source": [ "circuit.modeler.schematic.create_interface_port(\n", " name=\"Excitation_1\",\n", " location=[hfss_comp.pins[0].location[0], hfss_comp.pins[0].location[1]],\n", ")\n", "circuit.modeler.schematic.create_interface_port(\n", " name=\"Excitation_2\",\n", " location=[hfss_comp.pins[1].location[0], hfss_comp.pins[1].location[1]],\n", ")\n", "circuit.modeler.schematic.create_interface_port(\n", " name=\"Port_1\",\n", " location=[hfss_comp.pins[2].location[0], hfss_comp.pins[2].location[1]],\n", ")\n", "circuit.modeler.schematic.create_interface_port(\n", " name=\"Port_2\",\n", " location=[hfss_comp.pins[3].location[0], hfss_comp.pins[3].location[1]],\n", ")\n", "\n", "ports_list = [\"Excitation_1\", \"Excitation_2\"]\n", "source = circuit.assign_voltage_sinusoidal_excitation_to_ports(ports_list)\n", "source.ac_magnitude = 1\n", "source.phase = 0" ] }, { "cell_type": "markdown", "id": "48400323", "metadata": {}, "source": [ "## Create setup" ] }, { "cell_type": "code", "execution_count": null, "id": "74240cf9", "metadata": {}, "outputs": [], "source": [ "setup_name = \"MySetup\"\n", "LNA_setup = circuit.create_setup(name=setup_name)\n", "sweep_list = [\"LINC\", str(4.3) + \"GHz\", str(4.4) + \"GHz\", str(1001)]\n", "LNA_setup.props[\"SweepDefinition\"][\"Data\"] = \" \".join(sweep_list)" ] }, { "cell_type": "markdown", "id": "766c5b86", "metadata": {}, "source": [ "## Solve and push excitations\n", "\n", "Solve the circuit and push excitations to the HFSS model to calculate the\n", "correct value of losses." ] }, { "cell_type": "code", "execution_count": null, "id": "62a4e30f", "metadata": {}, "outputs": [], "source": [ "circuit.analyze(cores=NUM_CORES)\n", "circuit.push_excitations(instance=\"S1\", setup=setup_name)" ] }, { "cell_type": "markdown", "id": "4bda695f", "metadata": {}, "source": [ "## Start Mechanical\n", "\n", "Start Mechanical and copy bodies from the HFSS project." ] }, { "cell_type": "code", "execution_count": null, "id": "9db6b281", "metadata": {}, "outputs": [], "source": [ "mech = ansys.aedt.core.Mechanical(version=AEDT_VERSION)\n", "mech.copy_solid_bodies_from(design=hfss)\n", "mech.change_material_override(True)" ] }, { "cell_type": "markdown", "id": "041ba14c", "metadata": {}, "source": [ "## Get losses from HFSS and assign convection to Mechanical" ] }, { "cell_type": "code", "execution_count": null, "id": "96e0c973", "metadata": {}, "outputs": [], "source": [ "mech.assign_em_losses(\n", " design=hfss.design_name,\n", " setup=hfss.setups[0].name,\n", " sweep=\"LastAdaptive\",\n", " map_frequency=hfss.setups[0].props[\"Frequency\"],\n", " surface_objects=hfss.get_all_conductors_names(),\n", ")\n", "diels = [\"1_pd\", \"2_pd\", \"3_pd\", \"4_pd\", \"5_pd\"]\n", "for el in diels:\n", " mech.assign_uniform_convection(\n", " assignment=[mech.modeler[el].top_face_y, mech.modeler[el].bottom_face_y],\n", " convection_value=3,\n", " )" ] }, { "cell_type": "markdown", "id": "b0258dc7", "metadata": {}, "source": [ "## Solve and plot thermal results" ] }, { "cell_type": "code", "execution_count": null, "id": "0fcb0665", "metadata": {}, "outputs": [], "source": [ "mech.create_setup()\n", "mech.save_project()\n", "mech.analyze(cores=NUM_CORES)\n", "surfaces = []\n", "for name in mech.get_all_conductors_names():\n", " surfaces.extend(mech.modeler.get_object_faces(name))\n", "mech.post.create_fieldplot_surface(assignment=surfaces, quantity=\"Temperature\")" ] }, { "cell_type": "markdown", "id": "6dc66de9", "metadata": {}, "source": [ "## Release AEDT\n", "\n", "Release AEDT and close the example." ] }, { "cell_type": "code", "execution_count": null, "id": "adc42b90", "metadata": {}, "outputs": [], "source": [ "mech.save_project()\n", "mech.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": "9614cd7e", "metadata": {}, "source": [ "## Clean up\n", "\n", "All project files are saved in the folder ``temp_folder.name``. If you've run this example as a Jupyter notebook, you\n", "can retrieve those project files. The following cell removes all temporary files, including the project folder." ] }, { "cell_type": "code", "execution_count": null, "id": "0d050461", "metadata": {}, "outputs": [], "source": [ "temp_folder.cleanup()" ] } ], "metadata": { "jupytext": { "cell_metadata_filter": "-all", "main_language": "python", "notebook_metadata_filter": "-all" } }, "nbformat": 4, "nbformat_minor": 5 }