.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/howto_postprocessing/plot_ipdata.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_auto_examples_howto_postprocessing_plot_ipdata.py: Analyzing integration point data ================================ This examples shall demonstrate how we can better visualize integration point data (raw data used in OGS's equation system assembly without output related artefacts), by tesselating elements in such a way that each integration point is represented by one subsection of a cell. .. GENERATED FROM PYTHON SOURCE LINES 12-19 For brevity of this example we wrap the entire workflow from meshing and simulation to plotting in a parameterized function. The main function of importance is :meth:`~ogstools.meshlib.mesh.Mesh.to_ip_mesh`. We will use this function to show the tessellated visualization of the integration point data for different element and integration point orders and element types. Note, you can also tessellate an entire MeshSeries via :meth:`~ogstools.meshlib.mesh_series.MeshSeries.ip_tesselated` .. GENERATED FROM PYTHON SOURCE LINES 19-73 .. code-block:: Python from pathlib import Path from tempfile import mkdtemp import pyvista as pv import ogstools as ot from ogstools import examples from ogstools.meshlib.gmsh_meshing import rect ot.plot.setup.dpi = 75 ot.plot.setup.show_element_edges = True sigma_ip = ot.variables.stress.replace( data_name="sigma_ip", output_name="IP_stress" ) tmp_dir = Path(mkdtemp()) msh_path = tmp_dir / "mesh.msh" def simulate_and_plot(elem_order: int, quads: bool, intpt_order: int): rect( lengths=1, n_edge_cells=6, structured_grid=quads, order=elem_order, out_name=msh_path, ) meshes = ot.meshes_from_gmsh(msh_path, log=False) for name, mesh in meshes.items(): pv.save_meshio(Path(tmp_dir, name + ".vtu"), mesh) model = ot.Project( output_file=tmp_dir / "default.prj", input_file=examples.prj_mechanics, ) model.replace_text(intpt_order, xpath=".//integration_order") model.write_input() model.run_model(write_logs=True, args=f"-m {tmp_dir} -o {tmp_dir}") mesh = ot.MeshSeries(tmp_dir / "mesh.pvd").mesh(-1) int_pts = mesh.to_ip_point_cloud() ip_mesh = mesh.to_ip_mesh() fig = mesh.plot_contourf(ot.variables.stress) fig.axes[0].scatter( int_pts.points[:, 0], int_pts.points[:, 1], color="k", s=10 ) fig = ip_mesh.plot_contourf(sigma_ip) fig.axes[0].scatter( int_pts.points[:, 0], int_pts.points[:, 1], color="k", s=10 ) .. GENERATED FROM PYTHON SOURCE LINES 74-86 Triangles with increasing integration point order ------------------------------------------------- .. dropdown:: Why does the stress not change with the integration point order? In linear triangular finite elements, the shape functions used to interpolate displacements are linear functions of the coordinates. As this is a linear elastic example, the displacements are linear. The strain, which is obtained by differentiating the displacement, will thus be constant throughout the element. The stress, which is related to the strain through a constitutive relationship will also be constant throughout the element. Thus, the stress is not affected by the integration point order. .. GENERATED FROM PYTHON SOURCE LINES 86-89 .. code-block:: Python simulate_and_plot(elem_order=1, quads=False, intpt_order=2) .. rst-class:: sphx-glr-horizontal * .. image-sg:: /auto_examples/howto_postprocessing/images/sphx_glr_plot_ipdata_001.png :alt: plot ipdata :srcset: /auto_examples/howto_postprocessing/images/sphx_glr_plot_ipdata_001.png :class: sphx-glr-multi-img * .. image-sg:: /auto_examples/howto_postprocessing/images/sphx_glr_plot_ipdata_002.png :alt: plot ipdata :srcset: /auto_examples/howto_postprocessing/images/sphx_glr_plot_ipdata_002.png :class: sphx-glr-multi-img .. rst-class:: sphx-glr-script-out .. code-block:: none OGS finished with project file /tmp/tmp3h034nx9/default.prj. Execution took 0.13461017608642578 s Project file written to output. /builds/ogs/tools/ogstools/.venv-devcontainer/lib/python3.10/site-packages/pyvista/core/pointset.py:843: PyVistaDeprecationWarning: `PolyData` constructor parameter `n_faces` is deprecated and no longer used. warnings.warn( .. GENERATED FROM PYTHON SOURCE LINES 90-92 .. code-block:: Python simulate_and_plot(elem_order=1, quads=False, intpt_order=3) .. rst-class:: sphx-glr-horizontal * .. image-sg:: /auto_examples/howto_postprocessing/images/sphx_glr_plot_ipdata_003.png :alt: plot ipdata :srcset: /auto_examples/howto_postprocessing/images/sphx_glr_plot_ipdata_003.png :class: sphx-glr-multi-img * .. image-sg:: /auto_examples/howto_postprocessing/images/sphx_glr_plot_ipdata_004.png :alt: plot ipdata :srcset: /auto_examples/howto_postprocessing/images/sphx_glr_plot_ipdata_004.png :class: sphx-glr-multi-img .. rst-class:: sphx-glr-script-out .. code-block:: none OGS finished with project file /tmp/tmp3h034nx9/default.prj. Execution took 0.13778448104858398 s Project file written to output. /builds/ogs/tools/ogstools/.venv-devcontainer/lib/python3.10/site-packages/pyvista/core/pointset.py:843: PyVistaDeprecationWarning: `PolyData` constructor parameter `n_faces` is deprecated and no longer used. warnings.warn( .. GENERATED FROM PYTHON SOURCE LINES 93-95 .. code-block:: Python simulate_and_plot(elem_order=1, quads=False, intpt_order=4) .. rst-class:: sphx-glr-horizontal * .. image-sg:: /auto_examples/howto_postprocessing/images/sphx_glr_plot_ipdata_005.png :alt: plot ipdata :srcset: /auto_examples/howto_postprocessing/images/sphx_glr_plot_ipdata_005.png :class: sphx-glr-multi-img * .. image-sg:: /auto_examples/howto_postprocessing/images/sphx_glr_plot_ipdata_006.png :alt: plot ipdata :srcset: /auto_examples/howto_postprocessing/images/sphx_glr_plot_ipdata_006.png :class: sphx-glr-multi-img .. rst-class:: sphx-glr-script-out .. code-block:: none OGS finished with project file /tmp/tmp3h034nx9/default.prj. Execution took 0.13907265663146973 s Project file written to output. /builds/ogs/tools/ogstools/.venv-devcontainer/lib/python3.10/site-packages/pyvista/core/pointset.py:843: PyVistaDeprecationWarning: `PolyData` constructor parameter `n_faces` is deprecated and no longer used. warnings.warn( .. GENERATED FROM PYTHON SOURCE LINES 96-98 Quadratic triangles ------------------- .. GENERATED FROM PYTHON SOURCE LINES 98-101 .. code-block:: Python simulate_and_plot(elem_order=2, quads=False, intpt_order=4) .. rst-class:: sphx-glr-horizontal * .. image-sg:: /auto_examples/howto_postprocessing/images/sphx_glr_plot_ipdata_007.png :alt: plot ipdata :srcset: /auto_examples/howto_postprocessing/images/sphx_glr_plot_ipdata_007.png :class: sphx-glr-multi-img * .. image-sg:: /auto_examples/howto_postprocessing/images/sphx_glr_plot_ipdata_008.png :alt: plot ipdata :srcset: /auto_examples/howto_postprocessing/images/sphx_glr_plot_ipdata_008.png :class: sphx-glr-multi-img .. rst-class:: sphx-glr-script-out .. code-block:: none OGS finished with project file /tmp/tmp3h034nx9/default.prj. Execution took 0.14670896530151367 s Project file written to output. /builds/ogs/tools/ogstools/.venv-devcontainer/lib/python3.10/site-packages/pyvista/core/pointset.py:843: PyVistaDeprecationWarning: `PolyData` constructor parameter `n_faces` is deprecated and no longer used. warnings.warn( .. GENERATED FROM PYTHON SOURCE LINES 102-111 Quadrilaterals with increasing integration point order ------------------------------------------------------ .. dropdown:: Why does the stress change here? In contrast to triangular elements, quadrilateral elements use bilinear shape functions. Thus, the differentiation of the displacement leads to bilinear strain. The stress in turn is bilinear as well and can change within the elements. The number of integration points consequently affects the resulting stress field. .. GENERATED FROM PYTHON SOURCE LINES 111-114 .. code-block:: Python simulate_and_plot(elem_order=1, quads=True, intpt_order=2) .. rst-class:: sphx-glr-horizontal * .. image-sg:: /auto_examples/howto_postprocessing/images/sphx_glr_plot_ipdata_009.png :alt: plot ipdata :srcset: /auto_examples/howto_postprocessing/images/sphx_glr_plot_ipdata_009.png :class: sphx-glr-multi-img * .. image-sg:: /auto_examples/howto_postprocessing/images/sphx_glr_plot_ipdata_010.png :alt: plot ipdata :srcset: /auto_examples/howto_postprocessing/images/sphx_glr_plot_ipdata_010.png :class: sphx-glr-multi-img .. rst-class:: sphx-glr-script-out .. code-block:: none OGS finished with project file /tmp/tmp3h034nx9/default.prj. Execution took 0.1366407871246338 s Project file written to output. /builds/ogs/tools/ogstools/.venv-devcontainer/lib/python3.10/site-packages/pyvista/core/pointset.py:843: PyVistaDeprecationWarning: `PolyData` constructor parameter `n_faces` is deprecated and no longer used. warnings.warn( .. GENERATED FROM PYTHON SOURCE LINES 115-117 .. code-block:: Python simulate_and_plot(elem_order=1, quads=True, intpt_order=3) .. rst-class:: sphx-glr-horizontal * .. image-sg:: /auto_examples/howto_postprocessing/images/sphx_glr_plot_ipdata_011.png :alt: plot ipdata :srcset: /auto_examples/howto_postprocessing/images/sphx_glr_plot_ipdata_011.png :class: sphx-glr-multi-img * .. image-sg:: /auto_examples/howto_postprocessing/images/sphx_glr_plot_ipdata_012.png :alt: plot ipdata :srcset: /auto_examples/howto_postprocessing/images/sphx_glr_plot_ipdata_012.png :class: sphx-glr-multi-img .. rst-class:: sphx-glr-script-out .. code-block:: none OGS finished with project file /tmp/tmp3h034nx9/default.prj. Execution took 0.13556790351867676 s Project file written to output. /builds/ogs/tools/ogstools/.venv-devcontainer/lib/python3.10/site-packages/pyvista/core/pointset.py:843: PyVistaDeprecationWarning: `PolyData` constructor parameter `n_faces` is deprecated and no longer used. warnings.warn( .. GENERATED FROM PYTHON SOURCE LINES 118-120 .. code-block:: Python simulate_and_plot(elem_order=1, quads=True, intpt_order=4) .. rst-class:: sphx-glr-horizontal * .. image-sg:: /auto_examples/howto_postprocessing/images/sphx_glr_plot_ipdata_013.png :alt: plot ipdata :srcset: /auto_examples/howto_postprocessing/images/sphx_glr_plot_ipdata_013.png :class: sphx-glr-multi-img * .. image-sg:: /auto_examples/howto_postprocessing/images/sphx_glr_plot_ipdata_014.png :alt: plot ipdata :srcset: /auto_examples/howto_postprocessing/images/sphx_glr_plot_ipdata_014.png :class: sphx-glr-multi-img .. rst-class:: sphx-glr-script-out .. code-block:: none OGS finished with project file /tmp/tmp3h034nx9/default.prj. Execution took 0.13827919960021973 s Project file written to output. /builds/ogs/tools/ogstools/.venv-devcontainer/lib/python3.10/site-packages/pyvista/core/pointset.py:843: PyVistaDeprecationWarning: `PolyData` constructor parameter `n_faces` is deprecated and no longer used. warnings.warn( .. GENERATED FROM PYTHON SOURCE LINES 121-123 Quadratic quadrilateral ----------------------- .. GENERATED FROM PYTHON SOURCE LINES 123-125 .. code-block:: Python simulate_and_plot(elem_order=2, quads=True, intpt_order=4) .. rst-class:: sphx-glr-horizontal * .. image-sg:: /auto_examples/howto_postprocessing/images/sphx_glr_plot_ipdata_015.png :alt: plot ipdata :srcset: /auto_examples/howto_postprocessing/images/sphx_glr_plot_ipdata_015.png :class: sphx-glr-multi-img * .. image-sg:: /auto_examples/howto_postprocessing/images/sphx_glr_plot_ipdata_016.png :alt: plot ipdata :srcset: /auto_examples/howto_postprocessing/images/sphx_glr_plot_ipdata_016.png :class: sphx-glr-multi-img .. rst-class:: sphx-glr-script-out .. code-block:: none OGS finished with project file /tmp/tmp3h034nx9/default.prj. Execution took 0.1413569450378418 s Project file written to output. /builds/ogs/tools/ogstools/.venv-devcontainer/lib/python3.10/site-packages/pyvista/core/pointset.py:843: PyVistaDeprecationWarning: `PolyData` constructor parameter `n_faces` is deprecated and no longer used. warnings.warn( .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 7.168 seconds) .. _sphx_glr_download_auto_examples_howto_postprocessing_plot_ipdata.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_ipdata.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_ipdata.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_ipdata.zip `