.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples\07-TwinBuilder\03-Dynamic_ROM_Creation_And_Visualization.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_03-Dynamic_ROM_Creation_And_Visualization.py: Twin Builder: dynamic ROM creation and simulation (2023 R2 beta) ---------------------------------------------------------------- This example shows how you can use PyAEDT to create a dynamic ROM in Twin Builder and run a Twin Builder time-domain simulation. .. note:: This example uses functionality only available in Twin Builder 2023 R2 and later. For 2023 R2, the build date must be 8/7/2022 or later. .. GENERATED FROM PYTHON SOURCE LINES 13-16 Perform required imports ~~~~~~~~~~~~~~~~~~~~~~~~ Perform required imports. .. GENERATED FROM PYTHON SOURCE LINES 16-26 .. code-block:: Python import os import shutil import matplotlib.pyplot as plt from pyaedt import TwinBuilder from pyaedt import generate_unique_project_name from pyaedt import generate_unique_folder_name from pyaedt import downloads from pyaedt import settings .. GENERATED FROM PYTHON SOURCE LINES 27-30 Set AEDT version ~~~~~~~~~~~~~~~~ Set AEDT version. .. GENERATED FROM PYTHON SOURCE LINES 30-33 .. code-block:: Python aedt_version = "2024.1" .. GENERATED FROM PYTHON SOURCE LINES 34-43 Select version and set launch options ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Select the Twin Builder version and set launch options. The following code launches Twin Builder 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 43-47 .. code-block:: Python non_graphical = False new_thread = True .. GENERATED FROM PYTHON SOURCE LINES 48-51 Set up input data ~~~~~~~~~~~~~~~~~ Define needed file name .. GENERATED FROM PYTHON SOURCE LINES 51-70 .. code-block:: Python source_snapshot_data_zipfilename = "Ex1_Mechanical_DynamicRom.zip" source_build_conf_file = "dynarom_build.conf" # Download data from example_data repository temp_folder = generate_unique_folder_name() source_data_folder = downloads.download_twin_builder_data(source_snapshot_data_zipfilename, True, temp_folder) source_data_folder = downloads.download_twin_builder_data(source_build_conf_file, True, temp_folder) # Toggle these for local testing # source_data_folder = "D:\\Scratch\\TempDyn" data_folder = os.path.join(source_data_folder, "Ex03") # Unzip training data and config file downloads.unzip(os.path.join(source_data_folder, source_snapshot_data_zipfilename), data_folder) shutil.copyfile(os.path.join(source_data_folder, source_build_conf_file), os.path.join(data_folder, source_build_conf_file)) .. rst-class:: sphx-glr-script-out .. code-block:: none 'D:\\Temp\\pyaedt_prj_WBV\\twin_builder\\Ex03\\dynarom_build.conf' .. GENERATED FROM PYTHON SOURCE LINES 71-75 Launch Twin Builder and build ROM component ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Launch Twin Builder using an implicit declaration and add a new design with a default setup for building the dynamic ROM component. .. GENERATED FROM PYTHON SOURCE LINES 75-107 .. code-block:: Python tb = TwinBuilder(projectname=generate_unique_project_name(), specified_version=aedt_version, non_graphical=non_graphical, new_desktop_session=new_thread) # Switch the current desktop configuration and the schematic environment to "Twin Builder". # The Dynamic ROM feature is only available with a twin builder license. # This and the restoring section at the end are not needed if the desktop is already configured as "Twin Builder". current_desktop_config = tb._odesktop.GetDesktopConfiguration() current_schematic_environment = tb._odesktop.GetSchematicEnvironment() tb._odesktop.SetDesktopConfiguration("Twin Builder") tb._odesktop.SetSchematicEnvironment(1) # Get the dynamic ROM builder object rom_manager = tb._odesign.GetROMManager() dynamic_rom_builder = rom_manager.GetDynamicROMBuilder() # Build the dynamic ROM with specified configuration file conf_file_path = os.path.join(data_folder, source_build_conf_file) dynamic_rom_builder.Build(conf_file_path.replace('\\', '/')) # Test if ROM was created successfully dynamic_rom_path = os.path.join(data_folder, 'DynamicRom.dyn') if os.path.exists(dynamic_rom_path): tb._odesign.AddMessage("Info", "path exists: {}".format(dynamic_rom_path.replace('\\', '/')), "") else: tb._odesign.AddMessage("Info", "path does not exist: {}".format(dynamic_rom_path), "") # Create the ROM component definition in Twin Builder rom_manager.CreateROMComponent(dynamic_rom_path.replace('\\', '/'), 'dynarom') .. rst-class:: sphx-glr-script-out .. code-block:: none C:\actions-runner\_work\_tool\Python\3.10.9\x64\lib\subprocess.py:1072: ResourceWarning: subprocess 10884 is still running _warn("subprocess %s is still running" % self.pid, C:\actions-runner\_work\pyaedt\pyaedt\testenv\lib\site-packages\pyaedt\generic\settings.py:383: ResourceWarning: unclosed file <_io.TextIOWrapper name='D:\\Temp\\pyaedt_ansys.log' mode='a' encoding='cp1252'> self._logger = val .. GENERATED FROM PYTHON SOURCE LINES 108-111 Create schematic ~~~~~~~~~~~~~~~~ Place components to create a schematic. .. GENERATED FROM PYTHON SOURCE LINES 111-135 .. code-block:: Python # Define the grid distance for ease in calculations G = 0.00254 # Place a dynamic ROM component rom1 = tb.modeler.schematic.create_component("ROM1", "", "dynarom", [36 * G, 28 * G]) # Place two excitation sources source1 = tb.modeler.schematic.create_periodic_waveform_source(None, "PULSE", 190, 0.002, "300deg", 210, 0, [20 * G, 29 * G]) source2 = tb.modeler.schematic.create_periodic_waveform_source(None, "PULSE", 190, 0.002, "300deg", 210, 0, [20 * G, 25 * G]) # Connect components with wires tb.modeler.schematic.create_wire([[22 * G, 29 * G], [33 * G, 29 * G]]) tb.modeler.schematic.create_wire([[22 * G, 25 * G], [30 * G, 25 * G], [30 * G, 28 * G], [33 * G, 28 * G]]) # Zoom to fit the schematic tb.modeler.zoom_to_fit() .. GENERATED FROM PYTHON SOURCE LINES 136-139 Parametrize transient setup ~~~~~~~~~~~~~~~~~~~~~~~~~~~ Parametrize the default transient setup by setting the end time. .. GENERATED FROM PYTHON SOURCE LINES 139-144 .. code-block:: Python tb.set_end_time("1000s") tb.set_hmin("1s") tb.set_hmax("1s") .. rst-class:: sphx-glr-script-out .. code-block:: none True .. GENERATED FROM PYTHON SOURCE LINES 145-148 Solve transient setup ~~~~~~~~~~~~~~~~~~~~~ Solve the transient setup. .. GENERATED FROM PYTHON SOURCE LINES 148-151 .. code-block:: Python tb.analyze_setup("TR") .. rst-class:: sphx-glr-script-out .. code-block:: none True .. GENERATED FROM PYTHON SOURCE LINES 152-157 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 output of the dynamic ROM. .. GENERATED FROM PYTHON SOURCE LINES 157-171 .. code-block:: Python input_excitation = "PULSE1.VAL" x = tb.post.get_solution_data(input_excitation, "TR", "Time") plt.plot(x.intrinsics["Time"], x.data_real(input_excitation)) output_temperature = "ROM1.Temperature_history" x = tb.post.get_solution_data(output_temperature, "TR", "Time") plt.plot(x.intrinsics["Time"], x.data_real(output_temperature)) plt.grid() plt.xlabel("Time") plt.ylabel("Temperature History Variation with Input Temperature Pulse") plt.show() .. image-sg:: /examples/07-TwinBuilder/images/sphx_glr_03-Dynamic_ROM_Creation_And_Visualization_001.png :alt: 03 Dynamic ROM Creation And Visualization :srcset: /examples/07-TwinBuilder/images/sphx_glr_03-Dynamic_ROM_Creation_And_Visualization_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 172-176 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 176-185 .. code-block:: Python # Clean up the downloaded data shutil.rmtree(source_data_folder) # Restore earlier desktop configuration and schematic environment tb._odesktop.SetDesktopConfiguration(current_desktop_config) tb._odesktop.SetSchematicEnvironment(current_schematic_environment) tb.release_desktop() .. rst-class:: sphx-glr-script-out .. code-block:: none True .. rst-class:: sphx-glr-timing **Total running time of the script:** (1 minutes 21.037 seconds) .. _sphx_glr_download_examples_07-TwinBuilder_03-Dynamic_ROM_Creation_And_Visualization.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: 03-Dynamic_ROM_Creation_And_Visualization.ipynb <03-Dynamic_ROM_Creation_And_Visualization.ipynb>` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: 03-Dynamic_ROM_Creation_And_Visualization.py <03-Dynamic_ROM_Creation_And_Visualization.py>` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_