.. 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-71 .. code-block:: Python from pathlib import Path from tempfile import mkdtemp import ogstools as ogs from ogstools import examples from ogstools.meshlib.gmsh_meshing import rect from ogstools.msh2vtu import msh2vtu ogs.plot.setup.dpi = 75 ogs.plot.setup.show_element_edges = True sigma_ip = ogs.variables.stress.replace( data_name="sigma_ip", output_name="IP_stress" ) tmp_dir = Path(mkdtemp()) mesh_path = tmp_dir / "mesh.msh" vtu_path = tmp_dir / "mesh_domain.vtu" 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=mesh_path, ) msh2vtu(mesh_path, tmp_dir, log_level="ERROR") model = ogs.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 = ogs.MeshSeries(tmp_dir / "mesh.pvd").mesh(-1) int_pts = mesh.to_ip_point_cloud() ip_mesh = mesh.to_ip_mesh() fig = mesh.plot_contourf(ogs.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 72-84 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 84-87 .. 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/tmpqsj0ziqt/default.prj. Execution took 0.13379430770874023 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 88-90 .. 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/tmpqsj0ziqt/default.prj. Execution took 0.12834572792053223 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 91-93 .. 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/tmpqsj0ziqt/default.prj. Execution took 0.12471961975097656 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 94-96 Quadratic triangles ------------------- .. GENERATED FROM PYTHON SOURCE LINES 96-99 .. 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/tmpqsj0ziqt/default.prj. Execution took 0.13060855865478516 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 100-109 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 109-112 .. 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/tmpqsj0ziqt/default.prj. Execution took 0.1233828067779541 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 113-115 .. 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/tmpqsj0ziqt/default.prj. Execution took 0.1320326328277588 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 116-118 .. 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/tmpqsj0ziqt/default.prj. Execution took 0.12302374839782715 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 119-121 Quadratic quadrilateral ----------------------- .. GENERATED FROM PYTHON SOURCE LINES 121-123 .. 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/tmpqsj0ziqt/default.prj. Execution took 0.1406400203704834 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 4.637 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 `