-
Notifications
You must be signed in to change notification settings - Fork 3
add q3d dynamic link comp to twinbuilder #447
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
gmalinve
wants to merge
5
commits into
main
Choose a base branch
from
q3d_dynamic_link_tb
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
4804d32
add q3d dynamic link comp to twinbuilder
gmalinve 70ecb63
comments
gmalinve fbbca3c
Merge branch 'refs/heads/main' into q3d_dynamic_link_tb
gmalinve 2b785e1
add post_processing spectral
gmalinve 7f2cf25
add export report and import dataset q3d
gmalinve File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
171 changes: 171 additions & 0 deletions
171
examples/low_frequency/general/twin_builder/3_phase_inverter.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,171 @@ | ||
| # # Title | ||
| # | ||
| # Description | ||
gmalinve marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| # | ||
| # Keywords: **DCLink**, **Twinbuilder**, **Q3D**. | ||
|
|
||
| # ## Perform imports and define constants | ||
| # | ||
| # Perform required imports. | ||
|
|
||
| import tempfile | ||
| import time | ||
|
|
||
| import ansys.aedt.core | ||
| from ansys.aedt.core import get_pyaedt_app | ||
| from ansys.aedt.core.examples.downloads import download_file | ||
|
|
||
| # ## Define constants | ||
| # | ||
| # Constants help ensure consistency and avoid repetition throughout the example. | ||
|
|
||
| AEDT_VERSION = "2025.2" | ||
| NUM_CORES = 4 | ||
| NG_MODE = False # Open AEDT UI when it is launched. | ||
|
|
||
| # ## Create temporary directory | ||
| # | ||
| # Create a temporary working directory. | ||
| # The name of the working folder is stored in ``temp_folder.name``. | ||
| # | ||
| # > **Note:** The final cell in the notebook cleans up the temporary folder. If you want to | ||
| # > retrieve the AEDT project and data, do so before executing the final cell in the notebook. | ||
|
|
||
| temp_folder = tempfile.TemporaryDirectory(suffix=".ansys") | ||
|
|
||
| # ## Download AEDT file | ||
| # | ||
| # Set the local temporary folder to export the AEDT file to. | ||
|
|
||
| project_path = download_file( | ||
| source="q3d_dynamic_link", | ||
| name="busbar_q3d_tb.aedt", | ||
| local_path=temp_folder.name, | ||
| ) | ||
|
|
||
| # ## Launch Maxwell AEDT | ||
| # | ||
| # Create an instance of the ``Twinbuilder`` class. | ||
| # The Ansys Electronics Desktop will be launched with the active Twinbuilder design. | ||
| # The ``tb`` object is subsequently used to create and simulate the model. | ||
|
|
||
| tb = ansys.aedt.core.TwinBuilder( | ||
| project=project_path, | ||
| design="3ph_circuit", | ||
| version=AEDT_VERSION, | ||
| non_graphical=NG_MODE, | ||
| new_desktop=True, | ||
| ) | ||
|
|
||
| # ## Add Q3D component to Twinbuilder schematic | ||
| # | ||
| # Add a Q3D dynamic link to the Twinbuilder schematic. | ||
|
|
||
| comp = tb.add_q3d_dynamic_component( | ||
| source_project=tb.project_name, source_design_name="q3d_3ph", setup="Setup1", sweep_name="Sweep1", coupling_matrix_name="Original", state_space_dynamic_link_type="RLGC" | ||
| ) | ||
|
|
||
| tb = get_pyaedt_app(tb.project_name, "3ph_circuit") | ||
|
|
||
| # ## Place component on schematic | ||
| # | ||
| # Place the dynamic component on the schematic at the desired location (expressed in mm). | ||
| # Add page ports and ammeters to each terminal of the component. | ||
|
|
||
| x_position = 0.05 | ||
| y_position = 0.05 | ||
| comp.location = [x_position, y_position] | ||
|
|
||
| ammeter_x_factor = 0 | ||
| previous_value = 0 | ||
| reset = False | ||
| for pin in comp.pins: | ||
| current_value = pin.angle | ||
| if current_value != previous_value: | ||
| if not reset: | ||
| ammeter_x_factor = 0 | ||
| reset = True | ||
| angle_page_port = 180 | ||
| angle_ammeter = 270 | ||
| ammeter_x_factor += 0.015 | ||
| label_position = "Right" | ||
| ammeter_y_factor = -0.002 | ||
| else: | ||
| angle_page_port = 0 | ||
| angle_ammeter = 90 | ||
| ammeter_x_factor -= 0.015 | ||
| label_position = "Left" | ||
| ammeter_y_factor = 0.002 | ||
|
|
||
| prefix_1 = "dc_plus" | ||
| prefix_2 = "dc_minus" | ||
| prefix = prefix_1 if pin.name.startswith(prefix_1) else prefix_2 | ||
| terminal = pin.name.split(prefix, 1)[1].lstrip("_") | ||
| ammeter = tb.modeler.schematic.create_component( | ||
| name=terminal, | ||
| component_library="Basic Elements\\Measurement\\Electrical", | ||
| component_name="AM", | ||
| location=[pin.location[0] + ammeter_x_factor, pin.location[1] - ammeter_y_factor], | ||
| angle=angle_ammeter, | ||
| ) | ||
| comp_page_port = tb.modeler.components.create_page_port(name=terminal, location=ammeter.pins[0].location, label_position=label_position, angle=angle_page_port) | ||
| tb.modeler.schematic.create_wire([ammeter.pins[1].location, pin.location]) | ||
|
|
||
| # ## Solve transient setup | ||
| # | ||
| # Solve the transient setup. | ||
|
|
||
| tb.analyze_setup("TR") | ||
|
|
||
| # Post-processing | ||
| # | ||
| # Create reports for the results of interest. | ||
|
|
||
| cap_currents = tb.post.create_report( | ||
| expressions=["Ca.I", "Cb.I", "Cc.I"], | ||
| primary_sweep_variable="Time", | ||
| plot_name="Capacitor Currents", | ||
| ) | ||
| # add markers at 10ms and 20ms | ||
| cap_currents.add_cartesian_x_marker("10ms") | ||
| cap_currents.add_cartesian_x_marker("20ms") | ||
|
|
||
| # Plot only between 10ms and 20ms | ||
| cap_currents_range = tb.post.create_report( | ||
| expressions=["Ca.I", "Cb.I", "Cc.I"], | ||
| primary_sweep_variable="Time", | ||
| plot_name="Capacitor Currents - [10ms-20ms]", | ||
| ) | ||
| cap_currents_range.edit_x_axis_scaling(min_scale="10ms", max_scale="20ms") | ||
|
|
||
| i_load = tb.post.create_report( | ||
| expressions=["L4.I", "L5.I", "L6.I"], | ||
| primary_sweep_variable="Time", | ||
| plot_name="Load Currents", | ||
| ) | ||
| i_dc = tb.post.create_report( | ||
| expressions=["dc_ground.I"], | ||
| primary_sweep_variable="Time", | ||
| plot_name="Idc", | ||
| ) | ||
| v_dc = tb.post.create_report( | ||
| expressions=["Vdc_minus.V", "Vdc_plus.V"], | ||
| primary_sweep_variable="Time", | ||
| plot_name="Vdc", | ||
| ) | ||
|
|
||
| # ## Release AEDT | ||
|
|
||
| tb.save_project() | ||
| tb.release_desktop() | ||
| # Wait 3 seconds to allow AEDT to shut down before cleaning the temporary directory. | ||
| time.sleep(3) | ||
|
|
||
| # ## 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. | ||
|
|
||
| temp_folder.cleanup() | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.