{ "cells": [ { "cell_type": "markdown", "id": "d7955236", "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": "0129534b", "metadata": {}, "source": [ "\n", "\n", "Keywords: **AEDT**, **Circuit**, **Schematic**." ] }, { "cell_type": "markdown", "id": "56a648ad", "metadata": {}, "source": [ "## Import packages and define constants\n", "\n", "Perform required imports." ] }, { "cell_type": "code", "execution_count": null, "id": "6d898669", "metadata": {}, "outputs": [], "source": [ "import os\n", "import tempfile\n", "import time\n", "\n", "import ansys.aedt.core" ] }, { "cell_type": "markdown", "id": "fdf3807e", "metadata": {}, "source": [ "Define constants." ] }, { "cell_type": "code", "execution_count": null, "id": "fe96efd9", "metadata": {}, "outputs": [], "source": [ "AEDT_VERSION = \"2025.1\"\n", "NG_MODE = False # Open AEDT UI when it is launched." ] }, { "cell_type": "markdown", "id": "82c7be1b", "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": "53776052", "metadata": {}, "outputs": [], "source": [ "temp_folder = tempfile.TemporaryDirectory(suffix=\".ansys\")" ] }, { "cell_type": "markdown", "id": "33ea57e9", "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": "32484076", "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": "086f7851", "metadata": {}, "source": [ "## Create circuit setup\n", "\n", "Create and customize a linear network analysis (LNA) setup." ] }, { "cell_type": "code", "execution_count": null, "id": "f523511c", "metadata": {}, "outputs": [], "source": [ "setup1 = circuit.create_setup(\"MyLNA\")\n", "setup1.props[\"SweepDefinition\"][\"Data\"] = \"LINC 0GHz 4GHz 10001\"" ] }, { "cell_type": "markdown", "id": "e9309ab5", "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": "7f9a8438", "metadata": {}, "outputs": [], "source": [ "inductor = circuit.modeler.schematic.create_inductor(\n", " name=\"L1\", value=1e-9, location=[0, 0]\n", ")\n", "resistor = circuit.modeler.schematic.create_resistor(\n", " name=\"R1\", value=50, location=[500, 0]\n", ")\n", "capacitor = circuit.modeler.schematic.create_capacitor(\n", " name=\"C1\", value=1e-12, location=[1000, 0]\n", ")" ] }, { "cell_type": "markdown", "id": "d920ec49", "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": "bbae7bc1", "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": "321dfb4a", "metadata": {}, "outputs": [], "source": [ "port = circuit.modeler.components.create_interface_port(\n", " name=\"myport\", location=[-300, 50]\n", ")\n", "gnd = circuit.modeler.components.create_gnd(location=[1200, -100])" ] }, { "cell_type": "markdown", "id": "918c92d0", "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": "8657caec", "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": "d7eaf2f8", "metadata": {}, "source": [ "## Create transient setup\n", "\n", "Create a transient setup." ] }, { "cell_type": "code", "execution_count": null, "id": "62fca1f6", "metadata": {}, "outputs": [], "source": [ "setup2 = circuit.create_setup(\n", " name=\"MyTransient\", setup_type=circuit.SETUPS.NexximTransient\n", ")\n", "setup2.props[\"TransientData\"] = [\"0.01ns\", \"200ns\"]\n", "setup3 = circuit.create_setup(name=\"MyDC\", setup_type=circuit.SETUPS.NexximDC)" ] }, { "cell_type": "markdown", "id": "f4cdef29", "metadata": {}, "source": [ "## Solve transient setup\n", "\n", "Solve the transient setup." ] }, { "cell_type": "code", "execution_count": null, "id": "ecce4fea", "metadata": {}, "outputs": [], "source": [ "circuit.analyze_setup(\"MyLNA\")\n", "circuit.export_fullwave_spice()" ] }, { "cell_type": "markdown", "id": "e3b994b7", "metadata": {}, "source": [ "## Create report\n", "\n", "Create a report displaying the scattering parameters." ] }, { "cell_type": "code", "execution_count": null, "id": "a6a21177", "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": "d9d17f2f", "metadata": {}, "source": [ "## Create plot\n", "\n", "Create a plot based on solution data." ] }, { "cell_type": "code", "execution_count": null, "id": "ebbc273c", "metadata": {}, "outputs": [], "source": [ "fig = solutions.plot()" ] }, { "cell_type": "markdown", "id": "76074935", "metadata": {}, "source": [ "## Release AEDT\n", "\n", "Release AEDT and close the example." ] }, { "cell_type": "code", "execution_count": null, "id": "c7eb4797", "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": "4e71f3bc", "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": "d5f658c6", "metadata": {}, "outputs": [], "source": [ "temp_folder.cleanup()" ] } ], "metadata": { "jupytext": { "cell_metadata_filter": "-all", "main_language": "python", "notebook_metadata_filter": "-all" } }, "nbformat": 4, "nbformat_minor": 5 }