{ "cells": [ { "cell_type": "markdown", "id": "daf111e7", "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": "e2f3397b", "metadata": {}, "source": [ "\n", "\n", "Keywords: **AEDT**, **Circuit**, **Schematic**." ] }, { "cell_type": "markdown", "id": "18476649", "metadata": {}, "source": [ "## Import packages and define constants\n", "\n", "Perform required imports." ] }, { "cell_type": "code", "execution_count": null, "id": "3ecb3f41", "metadata": {}, "outputs": [], "source": [ "import os\n", "import tempfile\n", "import time\n", "\n", "import ansys.aedt.core\n" ] }, { "cell_type": "markdown", "id": "f9d97f76", "metadata": {}, "source": [ "Define constants." ] }, { "cell_type": "code", "execution_count": null, "id": "0f479379", "metadata": {}, "outputs": [], "source": [ "AEDT_VERSION = \"2024.2\"\n", "NG_MODE = False # Open AEDT UI when it is launched." ] }, { "cell_type": "markdown", "id": "9c7bf810", "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": "60c5266d", "metadata": {}, "outputs": [], "source": [ "temp_folder = tempfile.TemporaryDirectory(suffix=\".ansys\")" ] }, { "cell_type": "markdown", "id": "b746271e", "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": "b606cb6d", "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": "a5abeab5", "metadata": {}, "source": [ "## Create circuit setup\n", "\n", "Create and customize a linear network analysis (LNA) setup." ] }, { "cell_type": "code", "execution_count": null, "id": "e35810d0", "metadata": {}, "outputs": [], "source": [ "setup1 = circuit.create_setup(\"MyLNA\")\n", "setup1.props[\"SweepDefinition\"][\"Data\"] = \"LINC 0GHz 4GHz 10001\"" ] }, { "cell_type": "markdown", "id": "379c5117", "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": "ee59f587", "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": "7c451f78", "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": "3e611971", "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": "f2866c5e", "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": "e999da9d", "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": "4b0b157e", "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": "b35347b8", "metadata": {}, "source": [ "## Create transient setup\n", "\n", "Create a transient setup." ] }, { "cell_type": "code", "execution_count": null, "id": "f0084001", "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": "74f513b8", "metadata": {}, "source": [ "## Solve transient setup\n", "\n", "Solve the transient setup." ] }, { "cell_type": "code", "execution_count": null, "id": "012a528e", "metadata": {}, "outputs": [], "source": [ "circuit.analyze_setup(\"MyLNA\")\n", "circuit.export_fullwave_spice()" ] }, { "cell_type": "markdown", "id": "67737a9c", "metadata": {}, "source": [ "## Create report\n", "\n", "Create a report displaying the scattering parameters." ] }, { "cell_type": "code", "execution_count": null, "id": "d5d00750", "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": "87bae44b", "metadata": {}, "source": [ "## Create plot\n", "\n", "Create a plot based on solution data." ] }, { "cell_type": "code", "execution_count": null, "id": "e1c926e0", "metadata": {}, "outputs": [], "source": [ "fig = solutions.plot()" ] }, { "cell_type": "markdown", "id": "09e1e3df", "metadata": {}, "source": [ "## Release AEDT\n", "\n", "Release AEDT and close the example." ] }, { "cell_type": "code", "execution_count": null, "id": "2cb140a0", "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": "ed602cb9", "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": "593c3891", "metadata": {}, "outputs": [], "source": [ "temp_folder.cleanup()" ] } ], "metadata": { "jupytext": { "cell_metadata_filter": "-all", "main_language": "python", "notebook_metadata_filter": "-all" } }, "nbformat": 4, "nbformat_minor": 5 }