.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "tutorials\plot\plot_mesh_scopings.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_tutorials_plot_plot_mesh_scopings.py: .. _ref_tutorials_plot_mesh_scopings: Plot mesh scopings ================== This tutorial shows different commands for plotting mesh entities targeted by mesh scopings. A mesh scoping is a :class:`Scoping` with a location related to mesh entities. The entities shown correspond to the intersection of the IDs in the scoping of the mesh and the IDs in the provided scoping. If the scoping and the mesh do not have entity IDs in common, nothing is shown. For example, a scoping on elements associated to a mesh without elements results in an empty plot. A scoping on node IDs 1 to 2 associated to a mesh whose node IDs start at 3 results in an empty plot. .. note:: Scopings of faces are not supported. PyDPF-Core has a variety of plotting methods for generating 3D plots with Python. These methods use VTK and leverage the `PyVista `_ library. .. GENERATED FROM PYTHON SOURCE LINES 52-54 Load data to plot ------------------ .. GENERATED FROM PYTHON SOURCE LINES 54-63 .. code-block:: Python import ansys.dpf.core as dpf from ansys.dpf.core import examples import ansys.dpf.core.operators as ops result_file_path_1 = examples.download_piston_rod() model_1 = dpf.Model(data_sources=result_file_path_1) mesh_1 = model_1.metadata.meshed_region .. GENERATED FROM PYTHON SOURCE LINES 64-72 Plot a single mesh scoping --------------------------- Create a single :class:`Scoping` and plot the targeted entities when applied to a single :class:`MeshedRegion`. Node scoping: .. GENERATED FROM PYTHON SOURCE LINES 72-76 .. code-block:: Python node_scoping = dpf.Scoping(location=dpf.locations.nodal, ids=mesh_1.nodes.scoping.ids[0:100]) node_scoping.plot(mesh=mesh_1, color="red", show_mesh=True) .. image-sg:: /tutorials/plot/images/sphx_glr_plot_mesh_scopings_001.png :alt: plot mesh scopings :srcset: /tutorials/plot/images/sphx_glr_plot_mesh_scopings_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none ([], ) .. GENERATED FROM PYTHON SOURCE LINES 77-78 Element scoping: .. GENERATED FROM PYTHON SOURCE LINES 78-84 .. code-block:: Python element_scoping = dpf.Scoping( location=dpf.locations.elemental, ids=mesh_1.elements.scoping.ids[0:100] ) element_scoping.plot(mesh=mesh_1, color="green", show_mesh=True) .. image-sg:: /tutorials/plot/images/sphx_glr_plot_mesh_scopings_002.png :alt: plot mesh scopings :srcset: /tutorials/plot/images/sphx_glr_plot_mesh_scopings_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none ([], ) .. GENERATED FROM PYTHON SOURCE LINES 85-92 Plot a collection of mesh scopings ------------------------------------ Create a :class:`ScopingsContainer` with several mesh scopings and plot targeted entities of a :class:`MeshedRegion`. .. GENERATED FROM PYTHON SOURCE LINES 92-101 .. code-block:: Python node_scoping_1 = dpf.Scoping(location=dpf.locations.nodal, ids=mesh_1.nodes.scoping.ids[0:100]) node_scoping_2 = dpf.Scoping(location=dpf.locations.nodal, ids=mesh_1.nodes.scoping.ids[300:400]) node_sc = dpf.ScopingsContainer() node_sc.add_label(label="scoping", default_value=1) node_sc.add_scoping(label_space={"scoping": 1}, scoping=node_scoping_1) node_sc.add_scoping(label_space={"scoping": 2}, scoping=node_scoping_2) node_sc.plot(mesh=mesh_1, show_mesh=True) .. image-sg:: /tutorials/plot/images/sphx_glr_plot_mesh_scopings_003.png :alt: plot mesh scopings :srcset: /tutorials/plot/images/sphx_glr_plot_mesh_scopings_003.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none ([], ) .. GENERATED FROM PYTHON SOURCE LINES 102-105 Plot the ``ScopingsContainer`` applied to a :class:`MeshesContainer` with similarly labeled meshes. .. GENERATED FROM PYTHON SOURCE LINES 105-123 .. code-block:: Python meshes: dpf.MeshesContainer = ops.mesh.split_mesh(mesh=mesh_1, property="mat").eval() node_scoping_3 = dpf.Scoping( location=dpf.locations.nodal, ids=meshes.get_mesh({"mat": 1, "body": 1}).nodes.scoping.ids[0:100], ) node_scoping_4 = dpf.Scoping( location=dpf.locations.nodal, ids=meshes.get_mesh({"mat": 2, "body": 2}).nodes.scoping.ids[0:100], ) node_sc_2 = dpf.ScopingsContainer() node_sc_2.add_label(label="mat") node_sc_2.add_label(label="body") node_sc_2.add_scoping(label_space={"mat": 1, "body": 1}, scoping=node_scoping_3) node_sc_2.add_scoping(label_space={"mat": 2, "body": 2}, scoping=node_scoping_4) node_sc_2.plot(mesh=meshes) .. image-sg:: /tutorials/plot/images/sphx_glr_plot_mesh_scopings_004.png :alt: plot mesh scopings :srcset: /tutorials/plot/images/sphx_glr_plot_mesh_scopings_004.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none ([], ) .. GENERATED FROM PYTHON SOURCE LINES 124-131 Use ``DpfPlotter.add_scoping`` -------------------------------- Use :py:meth:`DpfPlotter.add_scoping()` to add scopings applied to a :class:`MeshedRegion` to a scene. .. GENERATED FROM PYTHON SOURCE LINES 131-145 .. code-block:: Python node_scoping = dpf.Scoping(location=dpf.locations.nodal, ids=mesh_1.nodes.scoping.ids[0:100]) element_scoping = dpf.Scoping( location=dpf.locations.elemental, ids=mesh_1.elements.scoping.ids[0:100] ) from ansys.dpf.core.plotter import DpfPlotter dpf_plt = DpfPlotter() # Show the mesh associated with the first scoping dpf_plt.add_scoping(node_scoping, mesh_1, show_mesh=True, color="red") # Do not show the mesh again for the second scoping (same mesh) dpf_plt.add_scoping(element_scoping, mesh_1, color="green") dpf_plt.show_figure() .. image-sg:: /tutorials/plot/images/sphx_glr_plot_mesh_scopings_005.png :alt: plot mesh scopings :srcset: /tutorials/plot/images/sphx_glr_plot_mesh_scopings_005.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none ([], ) .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 11.700 seconds) .. _sphx_glr_download_tutorials_plot_plot_mesh_scopings.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_mesh_scopings.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_mesh_scopings.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_mesh_scopings.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_