{ "cells": [ { "cell_type": "markdown", "id": "c45a0269", "metadata": {}, "source": [ "# Schematic subcircuit management\n", "\n", "This example shows how to add a subcircuit to a circuit design.\n", "It changes the focus within the hierarchy between\n", "the child subcircuit and the parent design.\n", "\n", "Keywords: **Circuit**, **EMC**, **schematic**." ] }, { "cell_type": "markdown", "id": "e962e43f", "metadata": {}, "source": [ "## Perform imports and define constants\n", "\n", "Perform required imports." ] }, { "cell_type": "code", "execution_count": null, "id": "59ee7bef", "metadata": {}, "outputs": [], "source": [ "import os\n", "import tempfile\n", "import time" ] }, { "cell_type": "code", "execution_count": null, "id": "84b5e59d", "metadata": {}, "outputs": [], "source": [ "import ansys.aedt.core" ] }, { "cell_type": "markdown", "id": "a1abb134", "metadata": {}, "source": [ "Define constants." ] }, { "cell_type": "code", "execution_count": null, "id": "3698eb23", "metadata": {}, "outputs": [], "source": [ "AEDT_VERSION = \"2024.2\"\n", "NG_MODE = False # Open AEDT UI when it is launched." ] }, { "cell_type": "markdown", "id": "b4c46ac4", "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": "3b29ad90", "metadata": {}, "outputs": [], "source": [ "temp_folder = tempfile.TemporaryDirectory(suffix=\".ansys\")" ] }, { "cell_type": "markdown", "id": "e9e90751", "metadata": {}, "source": [ "## Launch AEDT with Circuit\n", "\n", "Launch AEDT in graphical mode. Instantite an instance of the ``Circuit`` class." ] }, { "cell_type": "code", "execution_count": null, "id": "45731ce1", "metadata": {}, "outputs": [], "source": [ "circuit = ansys.aedt.core.Circuit(\n", " project=os.path.join(temp_folder.name, \"SubcircuitExampl.aedt\"),\n", " design=\"SimpleExample\",\n", " version=AEDT_VERSION,\n", " non_graphical=NG_MODE,\n", " new_desktop=True,\n", ")\n", "circuit.modeler.schematic_units = \"mil\"" ] }, { "cell_type": "markdown", "id": "c25fb407", "metadata": {}, "source": [ "## Add subcircuit\n", "\n", "Add a new subcircuit to the previously created circuit design, creating a\n", "child circuit. Push this child circuit down into the child subcircuit." ] }, { "cell_type": "code", "execution_count": null, "id": "922255f5", "metadata": {}, "outputs": [], "source": [ "subcircuit = circuit.modeler.schematic.create_subcircuit(location=[0.0, 0.0])\n", "subcircuit_name = subcircuit.composed_name\n", "circuit.push_down(subcircuit)" ] }, { "cell_type": "markdown", "id": "d4d8efe5", "metadata": {}, "source": [ "## Parametrize subcircuit\n", "\n", "Parametrize the subcircuit and add a resistor, inductor, and a capacitor with\n", "parameter values. Components are connected in series,\n", "and the focus is changed to the parent schematic using\n", "the ``pop_up()`` method." ] }, { "cell_type": "code", "execution_count": null, "id": "e655cc38", "metadata": {}, "outputs": [], "source": [ "circuit.variable_manager.set_variable(name=\"R_val\", expression=\"35ohm\")\n", "circuit.variable_manager.set_variable(name=\"L_val\", expression=\"1e-7H\")\n", "circuit.variable_manager.set_variable(name=\"C_val\", expression=\"5e-10F\")\n", "p1 = circuit.modeler.schematic.create_interface_port(name=\"In\")\n", "r1 = circuit.modeler.schematic.create_resistor(value=\"R_val\")\n", "l1 = circuit.modeler.schematic.create_inductor(value=\"L_val\")\n", "c1 = circuit.modeler.schematic.create_capacitor(value=\"C_val\")\n", "p2 = circuit.modeler.schematic.create_interface_port(name=\"Out\")\n", "circuit.modeler.schematic.connect_components_in_series(\n", " assignment=[p1, r1, l1, c1, p2], use_wire=True\n", ")\n", "circuit.pop_up()" ] }, { "cell_type": "markdown", "id": "6dd8bfb0", "metadata": {}, "source": [ "## Release AEDT\n", "\n", "Release AEDT and close the example." ] }, { "cell_type": "code", "execution_count": null, "id": "9df7f935", "metadata": {}, "outputs": [], "source": [ "circuit.save_project()\n", "circuit.release_desktop()\n", "# Wait 5 seconds to allow AEDT to shut down before cleaning the temporary directory.\n", "time.sleep(5)" ] }, { "cell_type": "markdown", "id": "86f9e6ab", "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": "6544fcb7", "metadata": {}, "outputs": [], "source": [ "temp_folder.cleanup()" ] } ], "metadata": { "jupytext": { "cell_metadata_filter": "-all", "main_language": "python", "notebook_metadata_filter": "-all" } }, "nbformat": 4, "nbformat_minor": 5 }