{ "cells": [ { "cell_type": "markdown", "id": "d9ef84b7", "metadata": {}, "source": [ "# Circuit schematic creation and analysis\n", "\n", "This example shows how to build a circuit schematic\n", "and run a transient circuit simulation." ] }, { "cell_type": "markdown", "id": "6205d544", "metadata": {}, "source": [ "\n", "\n", "Keywords: **AEDT**, **Circuit**, **Schematic**." ] }, { "cell_type": "markdown", "id": "0c255e85", "metadata": {}, "source": [ "## Import packages and define constants\n", "\n", "Perform required imports." ] }, { "cell_type": "code", "execution_count": null, "id": "fbc2eefa", "metadata": {}, "outputs": [], "source": [ "import os\n", "import tempfile\n", "import time\n", "\n", "import ansys.aedt.core\n", "from ansys.aedt.core.generic.constants import Setups\n" ] }, { "cell_type": "markdown", "id": "ea55e446", "metadata": {}, "source": [ "Define constants." ] }, { "cell_type": "code", "execution_count": null, "id": "c7ac4213", "metadata": {}, "outputs": [], "source": [ "AEDT_VERSION = \"2026.1\"\n", "NG_MODE = False # Open AEDT UI when it is launched." ] }, { "cell_type": "markdown", "id": "83823d38", "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": "34fd6a7f", "metadata": {}, "outputs": [], "source": [ "temp_folder = tempfile.TemporaryDirectory(suffix=\".ansys\")" ] }, { "cell_type": "markdown", "id": "22afa527", "metadata": {}, "source": [ "## Launch AEDT with Circuit\n", "\n", "Launch AEDT with Circuit. The [pyaedt.Desktop](\n", "https://aedt.docs.pyansys.com/version/stable/API/_autosummary/pyaedt.desktop.Desktop.html#pyaedt.desktop.Desktop)\n", "class initializes AEDT and starts the specified version in the specified mode." ] }, { "cell_type": "code", "execution_count": null, "id": "9f34979e", "metadata": {}, "outputs": [], "source": [ "\n", "circuit = ansys.aedt.core.Circuit(\n", " project=os.path.join(temp_folder.name, \"CircuitExample\"),\n", " design=\"Simple\",\n", " version=AEDT_VERSION,\n", " non_graphical=NG_MODE,\n", " new_desktop=True,\n", ")\n", "\n", "circuit.modeler.schematic.schematic_units = \"mil\"" ] }, { "cell_type": "markdown", "id": "669cca5f", "metadata": {}, "source": [ "## Create circuit setup\n", "\n", "Create and customize a linear network analysis (LNA) setup." ] }, { "cell_type": "code", "execution_count": null, "id": "ceccb24c", "metadata": {}, "outputs": [], "source": [ "setup1 = circuit.create_setup(\"MyLNA\")\n", "setup1.props[\"SweepDefinition\"][\"Data\"] = \"LINC 0GHz 4GHz 10001\"" ] }, { "cell_type": "markdown", "id": "3857580a", "metadata": {}, "source": [ "## Place components\n", "\n", "Place components such as an inductor, resistor, and capacitor. The ``location`` argument\n", "provides the ``[x, y]`` coordinates to place the component." ] }, { "cell_type": "code", "execution_count": null, "id": "444cb956", "metadata": {}, "outputs": [], "source": [ "inductor = circuit.modeler.schematic.create_inductor(name=\"L1\", value=1e-9, location=[0, 0])\n", "resistor = circuit.modeler.schematic.create_resistor(name=\"R1\", value=50, location=[500, 0])\n", "capacitor = circuit.modeler.schematic.create_capacitor(name=\"C1\", value=1e-12, location=[1000, 0])" ] }, { "cell_type": "markdown", "id": "af657693", "metadata": {}, "source": [ "## Get all pins\n", "\n", "The component pins are instances of the\n", "``ansys.aedt.core.modeler.circuits.objct3dcircuit.CircuitPins`` class and\n", "provide access to the\n", "pin location, net connectivity, and the ``connect_to_component()`` method, which\n", "can be used to connect components in the schematic\n", "as demonstrated in this example." ] }, { "cell_type": "markdown", "id": "a32b3141", "metadata": {}, "source": [ "## Place a port and ground\n", "\n", "Place a port and a ground in the schematic." ] }, { "cell_type": "code", "execution_count": null, "id": "b2a0ac9f", "metadata": {}, "outputs": [], "source": [ "port = circuit.modeler.schematic.create_interface_port(name=\"myport\", location=[-300, 50])\n", "gnd = circuit.modeler.schematic.create_gnd(location=[1200, -100])" ] }, { "cell_type": "markdown", "id": "6be55ad5", "metadata": {}, "source": [ "## Connect components\n", "\n", "Connect components with wires in the schematic. The ``connect_to_component()``\n", "method is used to create connections between pins." ] }, { "cell_type": "code", "execution_count": null, "id": "4f97b453", "metadata": {}, "outputs": [], "source": [ "port.pins[0].connect_to_component(assignment=inductor.pins[0], use_wire=True)\n", "inductor.pins[1].connect_to_component(assignment=resistor.pins[1], use_wire=True)\n", "resistor.pins[0].connect_to_component(assignment=capacitor.pins[0], use_wire=True)\n", "capacitor.pins[1].connect_to_component(assignment=gnd.pins[0], use_wire=True)" ] }, { "cell_type": "markdown", "id": "558d6053", "metadata": {}, "source": [ "## Create transient setup\n", "\n", "Create a transient setup." ] }, { "cell_type": "code", "execution_count": null, "id": "4ffe7fe8", "metadata": {}, "outputs": [], "source": [ "setup2 = circuit.create_setup(name=\"MyTransient\", setup_type=Setups.NexximTransient)\n", "setup2.props[\"TransientData\"] = [\"0.01ns\", \"200ns\"]\n", "setup3 = circuit.create_setup(name=\"MyDC\", setup_type=Setups.NexximDC)" ] }, { "cell_type": "markdown", "id": "75a41831", "metadata": {}, "source": [ "## Solve transient setup\n", "\n", "Solve the transient setup." ] }, { "cell_type": "code", "execution_count": null, "id": "756765cc", "metadata": {}, "outputs": [], "source": [ "circuit.analyze_setup(\"MyLNA\")\n", "circuit.export_fullwave_spice()" ] }, { "cell_type": "markdown", "id": "98e5e070", "metadata": {}, "source": [ "## Create report\n", "\n", "Create a report displaying the scattering parameters." ] }, { "cell_type": "code", "execution_count": null, "id": "d3421a38", "metadata": {}, "outputs": [], "source": [ "solutions = circuit.post.get_solution_data(\n", " expressions=circuit.get_traces_for_plot(category=\"S\"),\n", ")\n", "solutions.enable_pandas_output = True\n", "real, imag = solutions.full_matrix_real_imag\n", "print(real)" ] }, { "cell_type": "markdown", "id": "91eac103", "metadata": {}, "source": [ "## Create plot\n", "\n", "Create a plot based on solution data." ] }, { "cell_type": "code", "execution_count": null, "id": "dfcfdcca", "metadata": {}, "outputs": [], "source": [ "fig = solutions.plot()" ] }, { "cell_type": "markdown", "id": "d18c1ad7", "metadata": {}, "source": [ "## Release AEDT\n", "\n", "Release AEDT and close the example." ] }, { "cell_type": "code", "execution_count": null, "id": "3e7f6aba", "metadata": {}, "outputs": [], "source": [ "circuit.save_project()\n", "circuit.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": "824decb2", "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": "f4757238", "metadata": {}, "outputs": [], "source": [ "temp_folder.cleanup()" ] } ], "metadata": { "jupytext": { "cell_metadata_filter": "-all", "main_language": "python", "notebook_metadata_filter": "-all" } }, "nbformat": 4, "nbformat_minor": 5 }