.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples\07-TwinBuilder\01-RC_Circuit_Example.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_examples_07-TwinBuilder_01-RC_Circuit_Example.py: Twin Builder: RC circuit design anaysis --------------------------------------- This example shows how you can use PyAEDT to create a Twin Builder design and run a Twin Builder time-domain simulation. .. GENERATED FROM PYTHON SOURCE LINES 9-12 Perform required imports ~~~~~~~~~~~~~~~~~~~~~~~~ Perform required imports. .. GENERATED FROM PYTHON SOURCE LINES 12-16 .. code-block:: default import os import pyaedt .. GENERATED FROM PYTHON SOURCE LINES 17-26 Select version and set launch options ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Select the Twin Builder version and set the launch options. The following code launches Twin Builder 2023 R2 in graphical mode. You can change the Boolean parameter ``non_graphical`` to ``True`` to launch Twin Builder in non-graphical mode. You can also change the Boolean parameter ``new_thread`` to ``False`` to launch Twin Builder in an existing AEDT session if one is running. .. GENERATED FROM PYTHON SOURCE LINES 26-32 .. code-block:: default desktop_version = "2023.2" non_graphical = False new_thread = True .. GENERATED FROM PYTHON SOURCE LINES 33-37 Launch Twin Builder ~~~~~~~~~~~~~~~~~~~ Launch Twin Builder using an implicit declaration and add a new design with a default setup. .. GENERATED FROM PYTHON SOURCE LINES 37-45 .. code-block:: default tb = pyaedt.TwinBuilder(projectname=pyaedt.generate_unique_project_name(), specified_version=desktop_version, non_graphical=non_graphical, new_desktop_session=new_thread ) tb.modeler.schematic_units = "mil" .. rst-class:: sphx-glr-script-out .. code-block:: none Initializing new desktop! .. GENERATED FROM PYTHON SOURCE LINES 46-50 Create components for RC circuit ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Create components for an RC circuit driven by a pulse voltage source. Create components, such as a voltage source, resistor, and capacitor. .. GENERATED FROM PYTHON SOURCE LINES 50-55 .. code-block:: default source = tb.modeler.schematic.create_voltage_source("E1", "EPULSE", 10, 10, [0, 0]) resistor = tb.modeler.schematic.create_resistor("R1", 10000, [1000, 1000], 90) capacitor = tb.modeler.schematic.create_capacitor("C1", 1e-6, [2000, 0]) .. GENERATED FROM PYTHON SOURCE LINES 56-59 Create ground ~~~~~~~~~~~~~ Create a ground, which is needed for an analog analysis. .. GENERATED FROM PYTHON SOURCE LINES 59-62 .. code-block:: default gnd = tb.modeler.components.create_gnd([0, -1000]) .. GENERATED FROM PYTHON SOURCE LINES 63-66 Connect components ~~~~~~~~~~~~~~~~~~ Connects components with pins. .. GENERATED FROM PYTHON SOURCE LINES 66-72 .. code-block:: default source.pins[1].connect_to_component(resistor.pins[0]) resistor.pins[1].connect_to_component(capacitor.pins[0]) capacitor.pins[1].connect_to_component(source.pins[0]) source.pins[0].connect_to_component(gnd.pins[0]) .. rst-class:: sphx-glr-script-out .. code-block:: none True .. GENERATED FROM PYTHON SOURCE LINES 73-76 Parametrize transient setup ~~~~~~~~~~~~~~~~~~~~~~~~~~~ Parametrize the default transient setup by setting the end time. .. GENERATED FROM PYTHON SOURCE LINES 76-79 .. code-block:: default tb.set_end_time("300ms") .. rst-class:: sphx-glr-script-out .. code-block:: none True .. GENERATED FROM PYTHON SOURCE LINES 80-83 Solve transient setup ~~~~~~~~~~~~~~~~~~~~~ Solve the transient setup. .. GENERATED FROM PYTHON SOURCE LINES 83-87 .. code-block:: default tb.analyze_setup("TR") .. rst-class:: sphx-glr-script-out .. code-block:: none True .. GENERATED FROM PYTHON SOURCE LINES 88-93 Get report data and plot using Matplotlib ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Get report data and plot it using Matplotlib. The following code gets and plots the values for the voltage on the pulse voltage source and the values for the voltage on the capacitor in the RC circuit. .. GENERATED FROM PYTHON SOURCE LINES 93-102 .. code-block:: default E_Value = "E1.V" C_Value = "C1.V" x = tb.post.get_solution_data([E_Value, C_Value], "TR", "Time") x.plot([E_Value, C_Value], xlabel="Time", ylabel="Capacitor Voltage vs Input Pulse") tb.save_project() .. image-sg:: /examples/07-TwinBuilder/images/sphx_glr_01-RC_Circuit_Example_001.png :alt: Simulation Results Plot :srcset: /examples/07-TwinBuilder/images/sphx_glr_01-RC_Circuit_Example_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none True .. GENERATED FROM PYTHON SOURCE LINES 103-107 Close Twin Builder ~~~~~~~~~~~~~~~~~~ After the simulation completes, you can close Twin Builder or release it. All methods provide for saving the project before closing. .. GENERATED FROM PYTHON SOURCE LINES 107-109 .. code-block:: default tb.release_desktop() .. rst-class:: sphx-glr-script-out .. code-block:: none True .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 48.873 seconds) .. _sphx_glr_download_examples_07-TwinBuilder_01-RC_Circuit_Example.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: 01-RC_Circuit_Example.py <01-RC_Circuit_Example.py>` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: 01-RC_Circuit_Example.ipynb <01-RC_Circuit_Example.ipynb>` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_