{ "cells": [ { "cell_type": "markdown", "id": "0d658cf3", "metadata": {}, "source": [ "# Busbar analysis" ] }, { "cell_type": "markdown", "id": "5db933c4", "metadata": {}, "source": [ "This example shows how to use PyAEDT to create a busbar design in\n", "Q3D Extractor and run a simulation.\n", "\n", "Keywords: **Q3D**, **EMC*, **busbar**." ] }, { "cell_type": "markdown", "id": "b9ce54dc", "metadata": {}, "source": [ "## Perform imports and define constants\n", "\n", "Perform required imports." ] }, { "cell_type": "code", "execution_count": null, "id": "2541536b", "metadata": {}, "outputs": [], "source": [ "import os\n", "import tempfile\n", "import time" ] }, { "cell_type": "code", "execution_count": null, "id": "00e794fa", "metadata": {}, "outputs": [], "source": [ "import ansys.aedt.core" ] }, { "cell_type": "markdown", "id": "db4780cc", "metadata": {}, "source": [ "Define constants." ] }, { "cell_type": "code", "execution_count": null, "id": "784c1e61", "metadata": {}, "outputs": [], "source": [ "AEDT_VERSION = \"2024.2\"\n", "NUM_CORES = 4\n", "NG_MODE = False" ] }, { "cell_type": "markdown", "id": "1f0af20c", "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": "f5a35eea", "metadata": {}, "outputs": [], "source": [ "temp_folder = tempfile.TemporaryDirectory(suffix=\".ansys\")" ] }, { "cell_type": "markdown", "id": "a0991c6d", "metadata": {}, "source": [ "## Launch AEDT and Q3D Extractor\n", "\n", "Launch AEDT 2024 R2 in graphical mode and launch Q3D Extractor. This example uses SI units." ] }, { "cell_type": "code", "execution_count": null, "id": "0fc421ec", "metadata": {}, "outputs": [], "source": [ "q3d = ansys.aedt.core.Q3d(\n", " project=os.path.join(temp_folder.name, \"busbar.aedt\"),\n", " version=AEDT_VERSION,\n", " non_graphical=NG_MODE,\n", " new_desktop=True,\n", ")" ] }, { "cell_type": "markdown", "id": "e17095ba", "metadata": {}, "source": [ "## Create and set up the Q3D model\n", "\n", "Create polylines for three busbars and a box for the substrate." ] }, { "cell_type": "code", "execution_count": null, "id": "c044b2bd", "metadata": {}, "outputs": [], "source": [ "b1 = q3d.modeler.create_polyline(\n", " points=[[0, 0, 0], [-100, 0, 0]],\n", " name=\"Bar1\",\n", " material=\"copper\",\n", " xsection_type=\"Rectangle\",\n", " xsection_width=\"5mm\",\n", " xsection_height=\"1mm\",\n", ")\n", "q3d.modeler[\"Bar1\"].color = (255, 0, 0)\n", "\n", "q3d.modeler.create_polyline(\n", " points=[[0, -15, 0], [-150, -15, 0]],\n", " name=\"Bar2\",\n", " material=\"aluminum\",\n", " xsection_type=\"Rectangle\",\n", " xsection_width=\"5mm\",\n", " xsection_height=\"1mm\",\n", ")\n", "q3d.modeler[\"Bar2\"].color = (0, 255, 0)\n", "\n", "q3d.modeler.create_polyline(\n", " points=[[0, -30, 0], [-175, -30, 0], [-175, -10, 0]],\n", " name=\"Bar3\",\n", " material=\"copper\",\n", " xsection_type=\"Rectangle\",\n", " xsection_width=\"5mm\",\n", " xsection_height=\"1mm\",\n", ")\n", "q3d.modeler[\"Bar3\"].color = (0, 0, 255)\n", "\n", "q3d.modeler.create_box(\n", " origin=[50, 30, -0.5],\n", " sizes=[-250, -100, -3],\n", " name=\"substrate\",\n", " material=\"FR4_epoxy\",\n", ")\n", "q3d.modeler[\"substrate\"].color = (128, 128, 128)\n", "q3d.modeler[\"substrate\"].transparency = 0.8\n", "\n", "q3d.plot(\n", " show=False,\n", " output_file=os.path.join(temp_folder.name, \"Q3D.jpg\"),\n", " plot_air_objects=False,\n", ")" ] }, { "cell_type": "markdown", "id": "74dd929f", "metadata": {}, "source": [ "Identify nets and assign sources and sinks to all nets.\n", "There is a source and sink for each busbar." ] }, { "cell_type": "code", "execution_count": null, "id": "a47342b9", "metadata": {}, "outputs": [], "source": [ "q3d.auto_identify_nets()\n", "\n", "q3d.source(assignment=\"Bar1\", direction=q3d.AxisDir.XPos, name=\"Source1\")\n", "q3d.sink(assignment=\"Bar1\", direction=q3d.AxisDir.XNeg, name=\"Sink1\")\n", "\n", "q3d.source(assignment=\"Bar2\", direction=q3d.AxisDir.XPos, name=\"Source2\")\n", "q3d.sink(assignment=\"Bar2\", direction=q3d.AxisDir.XNeg, name=\"Sink2\")\n", "q3d.source(assignment=\"Bar3\", direction=q3d.AxisDir.XPos, name=\"Source3\")\n", "bar3_sink = q3d.sink(assignment=\"Bar3\", direction=q3d.AxisDir.YPos, name=\"Sink3\")" ] }, { "cell_type": "markdown", "id": "8216c474", "metadata": {}, "source": [ "Print information about nets and terminal assignments." ] }, { "cell_type": "code", "execution_count": null, "id": "7ef77c5b", "metadata": {}, "outputs": [], "source": [ "print(q3d.nets)\n", "print(q3d.net_sinks(\"Bar1\"))\n", "print(q3d.net_sinks(\"Bar2\"))\n", "print(q3d.net_sinks(\"Bar3\"))\n", "print(q3d.net_sources(\"Bar1\"))\n", "print(q3d.net_sources(\"Bar2\"))\n", "print(q3d.net_sources(\"Bar3\"))" ] }, { "cell_type": "markdown", "id": "7e4fa526", "metadata": {}, "source": [ "Create the solution setup and define the frequency range for the solution." ] }, { "cell_type": "code", "execution_count": null, "id": "02b73ed2", "metadata": {}, "outputs": [], "source": [ "setup1 = q3d.create_setup(props={\"AdaptiveFreq\": \"100MHz\"})\n", "sweep = setup1.add_sweep()\n", "sweep.props[\"RangeStart\"] = \"1MHz\"\n", "sweep.props[\"RangeEnd\"] = \"100MHz\"\n", "sweep.props[\"RangeStep\"] = \"5MHz\"\n", "sweep.update()" ] }, { "cell_type": "markdown", "id": "b7830731", "metadata": {}, "source": [ "### Set up for postprocessing\n", "\n", "Specify the traces to display after solving the model." ] }, { "cell_type": "code", "execution_count": null, "id": "61398729", "metadata": {}, "outputs": [], "source": [ "data_plot_self = q3d.matrices[0].get_sources_for_plot(\n", " get_self_terms=True, get_mutual_terms=False\n", ")\n", "data_plot_mutual = q3d.get_traces_for_plot(\n", " get_self_terms=False, get_mutual_terms=True, category=\"C\"\n", ")" ] }, { "cell_type": "markdown", "id": "4b16358b", "metadata": {}, "source": [ "Define a plot and a data table in AEDT for visualizing results." ] }, { "cell_type": "code", "execution_count": null, "id": "302dc4d3", "metadata": {}, "outputs": [], "source": [ "q3d.post.create_report(expressions=data_plot_self)\n", "q3d.post.create_report(\n", " expressions=data_plot_mutual, context=\"Original\", plot_type=\"Data Table\"\n", ")" ] }, { "cell_type": "markdown", "id": "0b3cebc8", "metadata": {}, "source": [ "## Analyze\n", "\n", "Solve the setup." ] }, { "cell_type": "code", "execution_count": null, "id": "ab2da07e", "metadata": {}, "outputs": [], "source": [ "q3d.analyze(cores=NUM_CORES)\n", "q3d.save_project()" ] }, { "cell_type": "markdown", "id": "fc0bd910", "metadata": {}, "source": [ "Retrieve solution data for processing in Python." ] }, { "cell_type": "code", "execution_count": null, "id": "61dadf4d", "metadata": {}, "outputs": [], "source": [ "data = q3d.post.get_solution_data(expressions=data_plot_self, context=\"Original\")\n", "data.data_magnitude()\n", "data.plot()" ] }, { "cell_type": "markdown", "id": "75d0c9db", "metadata": {}, "source": [ "## Release AEDT" ] }, { "cell_type": "code", "execution_count": null, "id": "5f9c7f80", "metadata": {}, "outputs": [], "source": [ "q3d.save_project()\n", "q3d.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": "0896c12b", "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": "ad8e08fe", "metadata": {}, "outputs": [], "source": [ "temp_folder.cleanup()" ] } ], "metadata": { "jupytext": { "cell_metadata_filter": "-all", "main_language": "python", "notebook_metadata_filter": "-all" } }, "nbformat": 4, "nbformat_minor": 5 }