.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples\00-basic\09-results_over_space_subset.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_00-basic_09-results_over_space_subset.py: .. _ref_results_over_space: Scope results over custom space domains ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The :class:`Result ` class, which are instances created by the :class:`Model `, give access to helpers for requesting results on specific mesh and time scopings. With these helpers, working on a spatial subset of the model is straightforward. In this example, different ways to choose the spatial subset to evaluate a result are exposed Import necessary modules: .. GENERATED FROM PYTHON SOURCE LINES 38-42 .. code-block:: Python from ansys.dpf import core as dpf from ansys.dpf.core import examples .. GENERATED FROM PYTHON SOURCE LINES 43-44 Create a model object to establish a connection with an example result file: .. GENERATED FROM PYTHON SOURCE LINES 44-47 .. code-block:: Python model = dpf.Model(examples.download_all_kinds_of_complexity()) print(model) .. rst-class:: sphx-glr-script-out .. code-block:: none DPF Model ------------------------------ Static analysis Unit system: MKS: m, kg, N, s, V, A, degC Physics Type: Mechanical Available results: - thickness: Elemental thickness - beam_s_bending_moment: ElementalNodal Beam S/Y Bending Moment - beam_t_bending_moment: ElementalNodal Beam T/Z Bending Moment - beam_s_shear_force: ElementalNodal Beam S/Y Shear Force - beam_axial_total_strain: ElementalNodal Beam X Axial Total strain - beam_axial_stress: ElementalNodal Beam X Axial Stress - beam_axial_force: ElementalNodal Beam X Axial Force - beam_torsional_moment: ElementalNodal Beam Torsional Moment - beam_t_shear_force: ElementalNodal Beam T/Z Shear Force - node_orientations: Nodal Node Euler Angles - displacement: Nodal Displacement - nodal_rotation: Nodal Rotation - reaction_force: Nodal Reaction Force - reaction_moment: Nodal Reaction Moment - smisc: Elemental Elemental Summable Miscellaneous Data - element_nodal_forces: ElementalNodal Element Nodal Forces - element_nodal_moments: ElementalNodal Element Nodal Moments - stress: ElementalNodal Stress - elemental_volume: Elemental Volume - stiffness_matrix_energy: Elemental Energy-stiffness matrix - artificial_hourglass_energy: Elemental Hourglass Energy - kinetic_energy: Elemental Kinetic Energy - co_energy: Elemental co-energy - incremental_energy: Elemental incremental energy - thermal_dissipation_energy: Elemental thermal dissipation energy - elastic_strain: ElementalNodal Strain - elastic_strain_eqv: ElementalNodal Strain eqv - thermal_strain: ElementalNodal Thermal Strains - thermal_strains_eqv: ElementalNodal Thermal Strains eqv - swelling_strains: ElementalNodal Swelling Strains - element_orientations: ElementalNodal Element Euler Angles - nmisc: Elemental Elemental Non Summable Miscellaneous Data - structural_temperature: ElementalNodal Structural temperature - contact_status: ElementalNodal Contact Status - contact_penetration: ElementalNodal Contact Penetration - contact_pressure: ElementalNodal Contact Pressure - contact_friction_stress: ElementalNodal Contact Friction Stress - contact_total_stress: ElementalNodal Contact Total Stress - contact_sliding_distance: ElementalNodal Contact Sliding Distance - contact_gap_distance: ElementalNodal Contact Gap Distance - contact_surface_heat_flux: ElementalNodal Total heat flux at contact surface - num_surface_status_changes: ElementalNodal Contact status changes - contact_fluid_penetration_pressure: ElementalNodal Fluid Penetration Pressure ------------------------------ DPF Meshed Region: 15129 nodes 10497 elements Unit: m With solid (3D) elements, shell (2D) elements, shell (3D) elements, beam (1D) elements ------------------------------ DPF Time/Freq Support: Number of sets: 1 Cumulative Time (s) LoadStep Substep 1 1.000000 1 1 .. GENERATED FROM PYTHON SOURCE LINES 48-52 Choose specific nodes ~~~~~~~~~~~~~~~~~~~~~ If some nodes or elements are specifically of interest, a nodal ``mesh_scoping`` can be connected. .. GENERATED FROM PYTHON SOURCE LINES 52-56 .. code-block:: Python nodes_scoping = dpf.mesh_scoping_factory.nodal_scoping(range(400, 500)) print(nodes_scoping) .. rst-class:: sphx-glr-script-out .. code-block:: none DPF Scoping: with Nodal location and 100 entities .. GENERATED FROM PYTHON SOURCE LINES 57-58 or .. GENERATED FROM PYTHON SOURCE LINES 58-61 .. code-block:: Python nodes_scoping = dpf.Scoping(ids=range(400, 500), location=dpf.locations.nodal) print(nodes_scoping) .. rst-class:: sphx-glr-script-out .. code-block:: none DPF Scoping: with Nodal location and 100 entities .. GENERATED FROM PYTHON SOURCE LINES 62-67 .. code-block:: Python disp = model.results.displacement.on_mesh_scoping(nodes_scoping).eval() model.metadata.meshed_region.plot(disp) .. tab-set:: .. tab-item:: Static Scene .. image-sg:: /examples/00-basic/images/sphx_glr_09-results_over_space_subset_001.png :alt: 09 results over space subset :srcset: /examples/00-basic/images/sphx_glr_09-results_over_space_subset_001.png :class: sphx-glr-single-img .. tab-item:: Interactive Scene .. offlineviewer:: D:\a\pydpf-core\pydpf-core\doc\source\examples\00-basic\images\sphx_glr_09-results_over_space_subset_001.vtksz .. rst-class:: sphx-glr-script-out .. code-block:: none ([], ) .. GENERATED FROM PYTHON SOURCE LINES 68-69 Equivalent to: .. GENERATED FROM PYTHON SOURCE LINES 69-73 .. code-block:: Python disp_op = model.results.displacement() disp_op.inputs.mesh_scoping(nodes_scoping) disp = disp_op.outputs.fields_container() .. GENERATED FROM PYTHON SOURCE LINES 74-75 Equivalent to: .. GENERATED FROM PYTHON SOURCE LINES 75-77 .. code-block:: Python disp = model.results.displacement(mesh_scoping=nodes_scoping).eval() .. GENERATED FROM PYTHON SOURCE LINES 78-82 Choose specific elements ~~~~~~~~~~~~~~~~~~~~~~~~ If some elements are specifically of interest, an elemental ``mesh_scoping`` can be connected. .. GENERATED FROM PYTHON SOURCE LINES 82-94 .. code-block:: Python elements_scoping = dpf.mesh_scoping_factory.elemental_scoping(range(500, 5000)) print(elements_scoping) # or elements_scoping = dpf.Scoping(ids=range(500, 5000), location=dpf.locations.elemental) print(elements_scoping) volume = model.results.elemental_volume.on_mesh_scoping(elements_scoping).eval() model.metadata.meshed_region.plot(volume) .. tab-set:: .. tab-item:: Static Scene .. image-sg:: /examples/00-basic/images/sphx_glr_09-results_over_space_subset_002.png :alt: 09 results over space subset :srcset: /examples/00-basic/images/sphx_glr_09-results_over_space_subset_002.png :class: sphx-glr-single-img .. tab-item:: Interactive Scene .. offlineviewer:: D:\a\pydpf-core\pydpf-core\doc\source\examples\00-basic\images\sphx_glr_09-results_over_space_subset_002.vtksz .. rst-class:: sphx-glr-script-out .. code-block:: none DPF Scoping: with Elemental location and 4500 entities DPF Scoping: with Elemental location and 4500 entities ([], ) .. GENERATED FROM PYTHON SOURCE LINES 95-96 Equivalent to: .. GENERATED FROM PYTHON SOURCE LINES 96-100 .. code-block:: Python volume_op = model.results.elemental_volume() volume_op.inputs.mesh_scoping(elements_scoping) volume = volume_op.outputs.fields_container() .. GENERATED FROM PYTHON SOURCE LINES 101-102 Equivalent to: .. GENERATED FROM PYTHON SOURCE LINES 102-104 .. code-block:: Python volume = model.results.elemental_volume(mesh_scoping=elements_scoping).eval() .. GENERATED FROM PYTHON SOURCE LINES 105-111 Choose specific named selections ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Named selections (also known as components) can be selected to create a spatial domain for a result. A ``mesh_scoping`` can be created with a named selection. To know the available named selections in the result file, use: .. GENERATED FROM PYTHON SOURCE LINES 111-114 .. code-block:: Python print(model.metadata.available_named_selections) .. rst-class:: sphx-glr-script-out .. code-block:: none ['_CM82', '_CM86UX_XP', '_DISPNONZEROUX', '_DISPZEROUZ', '_ELMISC', '_FIXEDSU'] .. GENERATED FROM PYTHON SOURCE LINES 115-116 Get the ``mesh_scoping`` of a named selection: .. GENERATED FROM PYTHON SOURCE LINES 116-120 .. code-block:: Python mesh_scoping = model.metadata.named_selection("_CM82") print(mesh_scoping) .. rst-class:: sphx-glr-script-out .. code-block:: none DPF Scoping: with Elemental location and 8709 entities .. GENERATED FROM PYTHON SOURCE LINES 121-122 Connect this ``mesh_scoping`` to the result provider .. GENERATED FROM PYTHON SOURCE LINES 122-125 .. code-block:: Python volume = model.results.elemental_volume(mesh_scoping=mesh_scoping).eval() model.metadata.meshed_region.plot(volume) .. tab-set:: .. tab-item:: Static Scene .. image-sg:: /examples/00-basic/images/sphx_glr_09-results_over_space_subset_003.png :alt: 09 results over space subset :srcset: /examples/00-basic/images/sphx_glr_09-results_over_space_subset_003.png :class: sphx-glr-single-img .. tab-item:: Interactive Scene .. offlineviewer:: D:\a\pydpf-core\pydpf-core\doc\source\examples\00-basic\images\sphx_glr_09-results_over_space_subset_003.vtksz .. rst-class:: sphx-glr-script-out .. code-block:: none ([], ) .. GENERATED FROM PYTHON SOURCE LINES 126-127 Equivalent to: .. GENERATED FROM PYTHON SOURCE LINES 127-129 .. code-block:: Python volume = model.results.elemental_volume.on_named_selection("_CM82") .. GENERATED FROM PYTHON SOURCE LINES 130-131 Equivalent to: .. GENERATED FROM PYTHON SOURCE LINES 131-138 .. code-block:: Python ns_provider = dpf.operators.scoping.on_named_selection( requested_location=dpf.locations.elemental, named_selection_name="_CM82", data_sources=model, ) volume = model.results.elemental_volume(mesh_scoping=ns_provider).eval() .. GENERATED FROM PYTHON SOURCE LINES 139-149 Split results depending on spatial properties ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ For many applications, it can be useful to request results on different subsets of the model. The ``ScopingsContainer`` entity contains different ``Scopings`` and can be connected to any result provider to get results split with the same partition as the input ``ScopingsContainer``. For example, some application require to get results split by body, by material, by element types. It might also be necessary to get results by element shape types, such as shell, solid, or beam, to average data properly. Customers might also require split by entirely custom spatial domains. .. GENERATED FROM PYTHON SOURCE LINES 152-153 Split results by element shapes .. GENERATED FROM PYTHON SOURCE LINES 153-162 .. code-block:: Python stress = model.results.stress.split_by_shape.on_location(dpf.locations.nodal).eval() print(stress) shell_stresses = stress.shell_fields() model.metadata.meshed_region.plot(shell_stresses[0]) solid_stresses = stress.solid_fields() model.metadata.meshed_region.plot(solid_stresses[0]) .. tab-set:: .. tab-item:: Static Scene .. image-sg:: /examples/00-basic/images/sphx_glr_09-results_over_space_subset_004.png :alt: 09 results over space subset :srcset: /examples/00-basic/images/sphx_glr_09-results_over_space_subset_004.png :class: sphx-glr-single-img .. tab-item:: Interactive Scene .. offlineviewer:: D:\a\pydpf-core\pydpf-core\doc\source\examples\00-basic\images\sphx_glr_09-results_over_space_subset_004.vtksz .. tab-set:: .. tab-item:: Static Scene .. image-sg:: /examples/00-basic/images/sphx_glr_09-results_over_space_subset_005.png :alt: 09 results over space subset :srcset: /examples/00-basic/images/sphx_glr_09-results_over_space_subset_005.png :class: sphx-glr-single-img .. tab-item:: Interactive Scene .. offlineviewer:: D:\a\pydpf-core\pydpf-core\doc\source\examples\00-basic\images\sphx_glr_09-results_over_space_subset_005.vtksz .. rst-class:: sphx-glr-script-out .. code-block:: none DPF stress(s)Fields Container with 5 field(s) defined on labels: elshape time with: - field 0 {elshape: 1, time: 1} with Nodal location, 6 components and 240 entities. - field 1 {elshape: 2, time: 1} with Nodal location, 6 components and 14826 entities. - field 2 {elshape: 3, time: 1} with Nodal location, 6 components and 0 entities. - field 3 {elshape: 0, time: 1} with Nodal location, 6 components and 0 entities. - field 4 {elshape: 12, time: 1} with Nodal location, 6 components and 0 entities. ([], ) .. GENERATED FROM PYTHON SOURCE LINES 163-164 Split results by bodies .. GENERATED FROM PYTHON SOURCE LINES 164-173 .. code-block:: Python stress = model.results.stress.split_by_body.on_location(dpf.locations.nodal).eval() print(stress) for body_id in stress.get_mat_scoping().ids: fields = stress.get_fields_by_mat_id(body_id) for field in fields: if field.elementary_data_count > 0: model.metadata.meshed_region.plot(field) .. tab-set:: .. tab-item:: Static Scene .. image-sg:: /examples/00-basic/images/sphx_glr_09-results_over_space_subset_006.png :alt: 09 results over space subset :srcset: /examples/00-basic/images/sphx_glr_09-results_over_space_subset_006.png :class: sphx-glr-single-img .. tab-item:: Interactive Scene .. offlineviewer:: D:\a\pydpf-core\pydpf-core\doc\source\examples\00-basic\images\sphx_glr_09-results_over_space_subset_006.vtksz .. tab-set:: .. tab-item:: Static Scene .. image-sg:: /examples/00-basic/images/sphx_glr_09-results_over_space_subset_007.png :alt: 09 results over space subset :srcset: /examples/00-basic/images/sphx_glr_09-results_over_space_subset_007.png :class: sphx-glr-single-img .. tab-item:: Interactive Scene .. offlineviewer:: D:\a\pydpf-core\pydpf-core\doc\source\examples\00-basic\images\sphx_glr_09-results_over_space_subset_007.vtksz .. tab-set:: .. tab-item:: Static Scene .. image-sg:: /examples/00-basic/images/sphx_glr_09-results_over_space_subset_008.png :alt: 09 results over space subset :srcset: /examples/00-basic/images/sphx_glr_09-results_over_space_subset_008.png :class: sphx-glr-single-img .. tab-item:: Interactive Scene .. offlineviewer:: D:\a\pydpf-core\pydpf-core\doc\source\examples\00-basic\images\sphx_glr_09-results_over_space_subset_008.vtksz .. rst-class:: sphx-glr-script-out .. code-block:: none DPF stress(s)Fields Container with 3 field(s) defined on labels: elshape mat time with: - field 0 {elshape: 2, mat: 1, time: 1} with Nodal location, 6 components and 1856 entities. - field 1 {elshape: 10, mat: 1, time: 1} with Nodal location, 6 components and 240 entities. - field 2 {elshape: 2, mat: 2, time: 1} with Nodal location, 6 components and 12970 entities. .. GENERATED FROM PYTHON SOURCE LINES 174-175 Create a custom spatial split .. GENERATED FROM PYTHON SOURCE LINES 175-186 .. code-block:: Python scopings_container = dpf.ScopingsContainer() scopings_container.add_label("custom_split") scopings_container.add_scoping( {"custom_split": 1}, dpf.Scoping(ids=range(100, 500), location=dpf.locations.elemental), ) scopings_container.add_scoping( {"custom_split": 2}, dpf.Scoping(ids=range(500, 5000), location=dpf.locations.elemental), ) .. GENERATED FROM PYTHON SOURCE LINES 187-194 .. code-block:: Python elemental_stress = model.results.stress.on_location(dpf.locations.elemental)( mesh_scoping=scopings_container ).eval() print(elemental_stress) for field in elemental_stress: model.metadata.meshed_region.plot(field) .. tab-set:: .. tab-item:: Static Scene .. image-sg:: /examples/00-basic/images/sphx_glr_09-results_over_space_subset_009.png :alt: 09 results over space subset :srcset: /examples/00-basic/images/sphx_glr_09-results_over_space_subset_009.png :class: sphx-glr-single-img .. tab-item:: Interactive Scene .. offlineviewer:: D:\a\pydpf-core\pydpf-core\doc\source\examples\00-basic\images\sphx_glr_09-results_over_space_subset_009.vtksz .. tab-set:: .. tab-item:: Static Scene .. image-sg:: /examples/00-basic/images/sphx_glr_09-results_over_space_subset_010.png :alt: 09 results over space subset :srcset: /examples/00-basic/images/sphx_glr_09-results_over_space_subset_010.png :class: sphx-glr-single-img .. tab-item:: Interactive Scene .. offlineviewer:: D:\a\pydpf-core\pydpf-core\doc\source\examples\00-basic\images\sphx_glr_09-results_over_space_subset_010.vtksz .. rst-class:: sphx-glr-script-out .. code-block:: none DPF stress(s)Fields Container with 2 field(s) defined on labels: custom_split time with: - field 0 {custom_split: 1, time: 1} with Elemental location, 6 components and 400 entities. - field 1 {custom_split: 2, time: 1} with Elemental location, 6 components and 4500 entities. .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 13.516 seconds) .. _sphx_glr_download_examples_00-basic_09-results_over_space_subset.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: 09-results_over_space_subset.ipynb <09-results_over_space_subset.ipynb>` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: 09-results_over_space_subset.py <09-results_over_space_subset.py>` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: 09-results_over_space_subset.zip <09-results_over_space_subset.zip>` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_