.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples\07-TwinBuilder\02-Wiring_A_Rectifier.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_02-Wiring_A_Rectifier.py: Twin Builder: wiring a rectifier with a capacitor filter --------------------------------------------------------- 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-17 .. code-block:: default import math import matplotlib.pyplot as plt import pyaedt .. GENERATED FROM PYTHON SOURCE LINES 18-27 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 27-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-44 .. 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 ) .. rst-class:: sphx-glr-script-out .. code-block:: none Initializing new desktop! C:\actions-runner\_work\_tool\Python\3.10.5\x64\lib\subprocess.py:1070: ResourceWarning: subprocess 9352 is still running _warn("subprocess %s is still running" % self.pid, .. GENERATED FROM PYTHON SOURCE LINES 45-48 Create components for bridge rectifier ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Create components for a bridge rectifier with a capacitor filter. .. GENERATED FROM PYTHON SOURCE LINES 48-76 .. code-block:: default # Define the grid distance for ease in calculations. G = 0.00254 # Create an AC sinosoidal source component. source = tb.modeler.schematic.create_voltage_source("V_AC", "ESINE", 100, 50, [-1 * G, 0]) # Create the four diodes of the bridge rectifier. diode1 = tb.modeler.schematic.create_diode(compname="D1", location=[10 * G, 6 * G], angle=3 * math.pi / 2) diode2 = tb.modeler.schematic.create_diode(compname="D2", location=[20 * G, 6 * G], angle=3 * math.pi / 2) diode3 = tb.modeler.schematic.create_diode(compname="D3", location=[10 * G, -4 * G], angle=3 * math.pi / 2) diode4 = tb.modeler.schematic.create_diode(compname="D4", location=[20 * G, -4 * G], angle=3 * math.pi / 2) # Create a capacitor filter. capacitor = tb.modeler.schematic.create_capacitor(compname="C_FILTER", value=1e-6, location=[29 * G, -10 * G]) # Create a load resistor. resistor = tb.modeler.schematic.create_resistor(compname="RL", value=100000, location=[39 * G, -10 * G]) # Create a ground. gnd = tb.modeler.components.create_gnd(location=[5 * G, -16 * G]) .. GENERATED FROM PYTHON SOURCE LINES 77-80 Connect components ~~~~~~~~~~~~~~~~~~ Connect components with wires. .. GENERATED FROM PYTHON SOURCE LINES 80-107 .. code-block:: default # Wire the diode bridge. tb.modeler.schematic.create_wire(points_array=[diode1.pins[0].location, diode3.pins[0].location]) tb.modeler.schematic.create_wire(points_array=[diode2.pins[1].location, diode4.pins[1].location]) tb.modeler.schematic.create_wire(points_array=[diode1.pins[1].location, diode2.pins[0].location]) tb.modeler.schematic.create_wire(points_array=[diode3.pins[1].location, diode4.pins[0].location]) # Wire the AC source. tb.modeler.schematic.create_wire(points_array=[source.pins[1].location, [0, 10 * G], [15 * G, 10 * G], [15 * G, 5 * G]]) tb.modeler.schematic.create_wire(points_array=[source.pins[0].location, [0, -10 * G], [15 * G, -10 * G], [15 * G, -5 * G]]) # Wire the filter capacitor and load resistor. tb.modeler.schematic.create_wire(points_array=[resistor.pins[0].location, [40 * G, 0], [22 * G, 0]]) tb.modeler.schematic.create_wire(points_array=[capacitor.pins[0].location, [30 * G, 0]]) # Wire the ground. tb.modeler.schematic.create_wire(points_array=[resistor.pins[1].location, [40 * G, -15 * G], gnd.pins[0].location]) tb.modeler.schematic.create_wire(points_array=[capacitor.pins[1].location, [30 * G, -15 * G]]) tb.modeler.schematic.create_wire(points_array=[gnd.pins[0].location, [5 * G, 0], [8 * G, 0]]) # Zoom to fit the schematic tb.modeler.zoom_to_fit() .. GENERATED FROM PYTHON SOURCE LINES 108-111 Parametrize transient setup ~~~~~~~~~~~~~~~~~~~~~~~~~~~ Parametrize the default transient setup by setting the end time. .. GENERATED FROM PYTHON SOURCE LINES 111-114 .. code-block:: default tb.set_end_time("100ms") .. rst-class:: sphx-glr-script-out .. code-block:: none True .. GENERATED FROM PYTHON SOURCE LINES 115-118 Solve transient setup ~~~~~~~~~~~~~~~~~~~~~ Solve the transient setup. .. GENERATED FROM PYTHON SOURCE LINES 118-122 .. code-block:: default tb.analyze_setup("TR") .. rst-class:: sphx-glr-script-out .. code-block:: none True .. GENERATED FROM PYTHON SOURCE LINES 123-128 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 128-142 .. code-block:: default E_Value = "V_AC.V" x = tb.post.get_solution_data(E_Value, "TR", "Time") plt.plot(x.intrinsics["Time"], x.data_real(E_Value)) R_Value = "RL.V" x = tb.post.get_solution_data(R_Value, "TR", "Time") plt.plot(x.intrinsics["Time"], x.data_real(R_Value)) plt.grid() plt.xlabel("Time") plt.ylabel("AC to DC Conversion using Rectifier") plt.show() .. image-sg:: /examples/07-TwinBuilder/images/sphx_glr_02-Wiring_A_Rectifier_001.png :alt: 02 Wiring A Rectifier :srcset: /examples/07-TwinBuilder/images/sphx_glr_02-Wiring_A_Rectifier_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 143-147 Close Twin Builder ~~~~~~~~~~~~~~~~~~ After the simulation is completed, you can close Twin Builder or release it. All methods provide for saving the project before closing. .. GENERATED FROM PYTHON SOURCE LINES 147-149 .. 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 53.186 seconds) .. _sphx_glr_download_examples_07-TwinBuilder_02-Wiring_A_Rectifier.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: 02-Wiring_A_Rectifier.py <02-Wiring_A_Rectifier.py>` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: 02-Wiring_A_Rectifier.ipynb <02-Wiring_A_Rectifier.ipynb>` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_