Download this example

Download this example as a Jupyter Notebook or as a Python script.


Wiring of a rectifier with a capacitor filter#

This example shows how to use PyAEDT to create a Twin Builder design and run a Twin Builder time-domain simulation.

25368cb18e034e7eb4ce26357ad68a93

Keywords: Twin Builder, rectifier, filter.

Perform imports and define constants#

Perform required imports.

[1]:
import os
import tempfile
import time
[2]:
import ansys.aedt.core
import matplotlib.pyplot as plt

Define constants.

[3]:
AEDT_VERSION = "2024.2"
NUM_CORES = 4
NG_MODE = False  # Open AEDT UI when it is launched.

Create temporary directory#

Create a temporary directory where downloaded data or dumped data can be stored. If you’d like to retrieve the project data for subsequent use, the temporary folder name is given by temp_folder.name.

[4]:
temp_folder = tempfile.TemporaryDirectory(suffix=".ansys")

Launch Twin Builder#

Launch Twin Builder using an implicit declaration and add a new design with the default setup.

[5]:
project_name = os.path.join(temp_folder.name, "TB_Rectifier_Demo.aedt")
tb = ansys.aedt.core.TwinBuilder(
    project=project_name,
    version=AEDT_VERSION,
    non_graphical=NG_MODE,
    new_desktop=True,
)
PyAEDT INFO: Python version 3.10.11 (tags/v3.10.11:7d4cc5a, Apr  5 2023, 00:38:17) [MSC v.1929 64 bit (AMD64)]
PyAEDT INFO: PyAEDT version 0.12.dev0.
PyAEDT INFO: Initializing new Desktop session.
PyAEDT INFO: Log on console is enabled.
PyAEDT INFO: Log on file C:\Users\ansys\AppData\Local\Temp\pyaedt_ansys_aef46dc6-7a76-4931-af4a-8ddb0553b0f6.log is enabled.
PyAEDT INFO: Log on AEDT is enabled.
PyAEDT INFO: Debug logger is disabled. PyAEDT methods will not be logged.
PyAEDT INFO: Launching PyAEDT with gRPC plugin.
PyAEDT INFO: New AEDT session is starting on gRPC port 52605
PyAEDT INFO: AEDT installation Path C:\Program Files\AnsysEM\v242\Win64
PyAEDT INFO: Ansoft.ElectronicsDesktop.2024.2 version started with process ID 6952.
PyAEDT INFO: Project TB_Rectifier_Demo has been created.
PyAEDT INFO: No design is present. Inserting a new design.
PyAEDT INFO: Added design 'Twin Builder_49B' of type Twin Builder.
PyAEDT INFO: Aedt Objects correctly read

Create components#

Place components for a bridge rectifier and a capacitor filter in the schematic editor.

Specify the grid spacing to use for placement of components in the schematic editor. Components are placed using the named argument location as a list of [x, y] values in millimeters.

[6]:
G = 0.00254

Create an AC sinosoidal voltage source.

[7]:
source = tb.modeler.schematic.create_voltage_source(
    "V_AC", "ESINE", 100, 50, location=[-1 * G, 0]
)
PyAEDT INFO: ModelerCircuit class has been initialized! Elapsed time: 0m 0sec
PyAEDT INFO: ModelerTwinBuilder class has been initialized!

Place the four diodes of the bridge rectifier. The named argument angle is the rotation angle of the component in radians.

[8]:
diode1 = tb.modeler.schematic.create_diode(
    name="D1", location=[10 * G, 6 * G], angle=270
)
diode2 = tb.modeler.schematic.create_diode(
    name="D2", location=[20 * G, 6 * G], angle=270
)
diode3 = tb.modeler.schematic.create_diode(
    name="D3", location=[10 * G, -4 * G], angle=270
)
diode4 = tb.modeler.schematic.create_diode(
    name="D4", location=[20 * G, -4 * G], angle=270
)

Place a capacitor filter.

[9]:
capacitor = tb.modeler.schematic.create_capacitor(
    name="C_FILTER", value=1e-6, location=[29 * G, -10 * G]
)

Place a load resistor.

[10]:
resistor = tb.modeler.schematic.create_resistor(
    name="RL", value=100000, location=[39 * G, -10 * G]
)

Place the ground component.

[11]:
gnd = tb.modeler.components.create_gnd(location=[5 * G, -16 * G])

Connect components#

Connect components with wires, and connect the diode pins to create the bridge.

[12]:
tb.modeler.schematic.create_wire(
    points=[diode1.pins[0].location, diode3.pins[0].location]
)
tb.modeler.schematic.create_wire(
    points=[diode2.pins[1].location, diode4.pins[1].location]
)
tb.modeler.schematic.create_wire(
    points=[diode1.pins[1].location, diode2.pins[0].location]
)
tb.modeler.schematic.create_wire(
    points=[diode3.pins[1].location, diode4.pins[0].location]
)
[12]:
<ansys.aedt.core.modeler.circuits.object_3d_circuit.Wire at 0x2f4d9f0e9b0>

Connect the voltage source to the bridge.

[13]:
tb.modeler.schematic.create_wire(
    points=[source.pins[1].location, [0, 10 * G], [15 * G, 10 * G], [15 * G, 5 * G]]
)
tb.modeler.schematic.create_wire(
    points=[source.pins[0].location, [0, -10 * G], [15 * G, -10 * G], [15 * G, -5 * G]]
)
[13]:
<ansys.aedt.core.modeler.circuits.object_3d_circuit.Wire at 0x2f4d9f0ee30>

Connect the filter capacitor and load resistor.

[14]:
tb.modeler.schematic.create_wire(
    points=[resistor.pins[0].location, [40 * G, 0], [22 * G, 0]]
)
tb.modeler.schematic.create_wire(points=[capacitor.pins[0].location, [30 * G, 0]])
[14]:
<ansys.aedt.core.modeler.circuits.object_3d_circuit.Wire at 0x2f4d9f91240>

Add the ground connection.

[15]:
tb.modeler.schematic.create_wire(
    points=[resistor.pins[1].location, [40 * G, -15 * G], gnd.pins[0].location]
)
tb.modeler.schematic.create_wire(points=[capacitor.pins[1].location, [30 * G, -15 * G]])
tb.modeler.schematic.create_wire(points=[gnd.pins[0].location, [5 * G, 0], [8 * G, 0]])
[15]:
<ansys.aedt.core.modeler.circuits.object_3d_circuit.Wire at 0x2f4d9f0f7c0>
[16]:
# Zoom to fit the schematic
tb.modeler.zoom_to_fit()

The circuit schematic should now be visible in the Twin Builder schematic editor and look like the image shown at the beginning of the example.

Run the simulation#

Update the total time to be simulated and run the analysis.

[17]:
tb.set_end_time("100ms")
tb.analyze_setup("TR")
PyAEDT INFO: Key Desktop/ActiveDSOConfigurations/Twin Builder correctly changed.
PyAEDT INFO: Solving design setup TR
PyAEDT INFO: Key Desktop/ActiveDSOConfigurations/Twin Builder correctly changed.
PyAEDT INFO: Design setup TR solved correctly in 0.0h 0.0m 7.0s
[17]:
True

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.

[18]:
src_name = source.InstanceName + ".V"
x = tb.post.get_solution_data(src_name, "TR", "Time")
plt.plot(x.intrinsics["Time"], x.data_real(src_name))
plt.grid()
plt.xlabel("Time")
plt.ylabel("AC Voltage")
plt.show()
PyAEDT INFO: Post class has been initialized! Elapsed time: 0m 0sec
PyAEDT INFO: Solution Data Correctly Loaded.
../../../../_images/examples_low_frequency_general_twin_builder_rectifier_34_1.png
[19]:
r_voltage = resistor.InstanceName + ".V"
x = tb.post.get_solution_data(r_voltage, "TR", "Time")
plt.plot(x.intrinsics["Time"], x.data_real(r_voltage))
plt.grid()
plt.xlabel("Time")
plt.ylabel("AC to DC Conversion using Rectifier")
plt.show()
PyAEDT INFO: Solution Data Correctly Loaded.
../../../../_images/examples_low_frequency_general_twin_builder_rectifier_35_1.png

Release AEDT#

Release AEDT and close the example.

[20]:
tb.save_project()
tb.release_desktop()
# Wait 3 seconds to allow AEDT to shut down before cleaning the temporary directory.
time.sleep(3)
PyAEDT INFO: Project TB_Rectifier_Demo Saved correctly
PyAEDT INFO: Desktop has been released and closed.

Clean up#

All project files are saved in the folder temp_folder.name. If you’ve run this example as a Jupyter notebook, you can retrieve those project files. The following cell removes all temporary files, including the project folder.

[21]:
temp_folder.cleanup()

Download this example

Download this example as a Jupyter Notebook or as a Python script.