.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples\02-tbrom_examples\05-TBROM_FEA_mesh_based_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_02-tbrom_examples_05-TBROM_FEA_mesh_based_visualization.py: .. _ref_example_TBROM_FEA_mesh_projection: 3D field ROM example with FEA mesh based visualization ------------------------------------------------------ This example shows how PyTwin can be used to load and evaluate a twin model, and visualize the ROM results on a FEA mesh. Once the twin model is evaluated, PyDPF is used to read in the FEA mesh on which the ROM results will be projected. PyVista is then used to perform the 3D visualization with different options. For more information, see the `PyDPF documentation `_ and `PyVista documentation `_. .. GENERATED FROM PYTHON SOURCE LINES 16-19 .. image:: /_static/TBROM_FEA_mesh_projection.png :width: 400pt :align: center .. GENERATED FROM PYTHON SOURCE LINES 19-22 .. code-block:: Python # sphinx_gallery_thumbnail_path = '_static/TBROM_FEA_mesh_projection' .. GENERATED FROM PYTHON SOURCE LINES 23-40 .. note:: This example uses PyDPF which requires a DPF server installation (version 2024 R1-pre0 or higher) as a first step. More information on how to download and install DPF server is available here : https://dpf.docs.pyansys.com/version/stable/getting_started/index.html#install-dpf-server To be able to use the functionalities to project an output field on a mesh, you must have a twin with one or more TBROMs. The output mode coefficients for the TBROMs must be enabled when exporting the TBROMs and connected to twin outputs following these conventions: - If there are multiple TBROMs in the twin, the format for the name of the twin output must be ``outField_mode_{mode_index}_{tbrom_name}``. - If there is a single TBROM in the twin, the format for the name of the twin output must be ``outField_mode_{mode_index}``. .. image:: /_static/snapshot_generation.png :width: 300pt :align: center .. GENERATED FROM PYTHON SOURCE LINES 42-49 .. note:: To be able to use the functionalities to project an output field on a mesh with interpolation, you need to have a Twin with 1 or more TBROM, for which its geometry is embedded when exporting the TBROMs to Twin Builder .. image:: /_static/point_generation.png :width: 200pt :align: center .. GENERATED FROM PYTHON SOURCE LINES 51-55 Perform required imports ~~~~~~~~~~~~~~~~~~~~~~~~ Perform required imports, which include downloading and importing the input files. .. GENERATED FROM PYTHON SOURCE LINES 55-63 .. code-block:: Python import ansys.dpf.core as dpf from pytwin import TwinModel, download_file import pyvista as pv twin_file = download_file("FEADeformationTBROM_23R2.twin", "twin_files", force_download=True) fea_file = download_file("FEA_deformation.rst", "other_files", force_download=True) .. GENERATED FROM PYTHON SOURCE LINES 64-67 Define ROM inputs ~~~~~~~~~~~~~~~~~ Define the ROM inputs. .. GENERATED FROM PYTHON SOURCE LINES 67-69 .. code-block:: Python rom_inputs = {"Force_X_Component": 101.471} .. GENERATED FROM PYTHON SOURCE LINES 70-73 Load the twin runtime and generate temperature results ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Load the twin runtime, initialize and extract ROM related information. .. GENERATED FROM PYTHON SOURCE LINES 73-79 .. code-block:: Python print("Initializing the Twin") twin_model = TwinModel(twin_file) twin_model.initialize_evaluation(inputs=rom_inputs) rom_name = twin_model.tbrom_names[0] named_selections = twin_model.get_named_selections(rom_name) .. rst-class:: sphx-glr-script-out .. code-block:: none Initializing the Twin .. GENERATED FROM PYTHON SOURCE LINES 80-83 Extract the FEA mesh information for projection ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Load the Mechanical rst file through PyDPF and extract the mesh .. GENERATED FROM PYTHON SOURCE LINES 83-92 .. code-block:: Python print("Reading the FEA mesh") ds = dpf.DataSources() ds.set_result_file_path(fea_file) streams = dpf.operators.metadata.streams_provider(data_sources=ds) # extracting the grid associated to the fea model whole_mesh = dpf.operators.mesh.mesh_provider(streams_container=streams).eval() target_mesh = whole_mesh.grid .. rst-class:: sphx-glr-script-out .. code-block:: none Reading the FEA mesh .. GENERATED FROM PYTHON SOURCE LINES 93-96 Project the TBROM field onto the targeted mesh ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The projection is performed without interpolation (i.e. direct mapping of data) .. GENERATED FROM PYTHON SOURCE LINES 96-99 .. code-block:: Python print("Projecting the results on target mesh") rom_on_fea_mesh = twin_model.project_tbrom_on_mesh(rom_name, target_mesh, False) .. rst-class:: sphx-glr-script-out .. code-block:: none Projecting the results on target mesh .. GENERATED FROM PYTHON SOURCE LINES 100-103 Post processing and field visualization using PyVista ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Creation of the scene and results to display .. GENERATED FROM PYTHON SOURCE LINES 103-116 .. code-block:: Python print("Post processing") plotter = pv.Plotter() plotter.set_background("white") plotter.add_axes() plotter.add_mesh(rom_on_fea_mesh, scalar_bar_args={"color": "black"}) # plotter.add_mesh(mesh_data, show_edges=True, scalar_bar_args={"color": "black"}) plotter.camera_position = [ (-0.03962092584614037, 0.013987037327583286, 0.10356162483172728), (0.015819278345, 0.0001320060299999995, 0.005), (0.05026854357305644, 0.9925208192698814, -0.11124521042672807), ] plotter.show() .. rst-class:: sphx-glr-script-out .. code-block:: none Post processing .. GENERATED FROM PYTHON SOURCE LINES 117-120 .. image:: /_static/TBROM_FEA_mesh_projection.png :width: 400pt :align: center .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 2.602 seconds) .. _sphx_glr_download_examples_02-tbrom_examples_05-TBROM_FEA_mesh_based_visualization.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: 05-TBROM_FEA_mesh_based_visualization.ipynb <05-TBROM_FEA_mesh_based_visualization.ipynb>` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: 05-TBROM_FEA_mesh_based_visualization.py <05-TBROM_FEA_mesh_based_visualization.py>` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_