.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gallery/verification/example_verify_patch_test.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_gallery_verification_example_verify_patch_test.py: Irons constant-strain patch test ================================ The canonical FE consistency test: a 2×2×2 hex patch with an interior node displaced from its regular position, subjected to boundary displacements :math:`u = \varepsilon_0\, x` consistent with a uniform axial strain field, must recover :math:`\varepsilon = \varepsilon_0` everywhere to **machine precision**. Reference: Irons, B. M. and Razzaque, A. (1972) "Experience with the patch test for convergence of finite elements," *The Mathematical Foundations of the Finite Element Method*, pp. 557-587. A discretisation that fails this test cannot pass the inf-sup / consistency conditions and therefore cannot converge at the optimal rate. A pass at machine precision says the element kernel is wiring :math:`B`, :math:`D`, and the isoparametric mapping correctly under non-trivial geometry. .. GENERATED FROM PYTHON SOURCE LINES 23-31 .. code-block:: Python from __future__ import annotations import numpy as np import pyvista as pv from femorph_solver.validation.problems import IronsPatchTest .. GENERATED FROM PYTHON SOURCE LINES 32-33 Problem statement .. GENERATED FROM PYTHON SOURCE LINES 33-41 .. code-block:: Python problem = IronsPatchTest() pv_ = problem.published_values[0] print(f"{problem.name}: {problem.description}") print(f"\n source : {pv_.source}") print(f" formula: {pv_.formula}") print(f" target : {pv_.value} (tolerance {pv_.tolerance:.0e})") .. rst-class:: sphx-glr-script-out .. code-block:: none patch_test: Irons constant-strain patch test: prescribed linear boundary displacement must reproduce a uniform strain to machine precision. source : Irons & Razzaque 1972 formula: max_e |eps_xx^h(x_e) - eps0| == 0 (machine precision) target : 0.0 (tolerance 1e-09) .. GENERATED FROM PYTHON SOURCE LINES 42-43 Run the check — single-shot ``validate()`` .. GENERATED FROM PYTHON SOURCE LINES 43-49 .. code-block:: Python results = problem.validate() r = results[0] print(f"\n computed max_strain_error: {r.computed:.3e}") print(f" passes tolerance : {r.passed}") .. rst-class:: sphx-glr-script-out .. code-block:: none computed max_strain_error: 8.132e-20 passes tolerance : True .. GENERATED FROM PYTHON SOURCE LINES 50-56 Figure — the distorted patch ---------------------------- The validation's ``build_model`` offsets the single interior node by 10 % of the edge length so the isoparametric mapping is non-trivial; rendering the resulting mesh is a nice sanity check that the geometry actually has the promised distortion. .. GENERATED FROM PYTHON SOURCE LINES 56-70 .. code-block:: Python m = problem.build_model() plotter = pv.Plotter(off_screen=True) plotter.add_mesh(m.grid, show_edges=True, opacity=0.7, color="#b8cde3") plotter.add_points( np.asarray(m.grid.points), render_points_as_spheres=True, point_size=12, color="red", ) plotter.view_isometric() plotter.camera.zoom(1.1) plotter.show() .. image-sg:: /gallery/verification/images/sphx_glr_example_verify_patch_test_001.png :alt: example verify patch test :srcset: /gallery/verification/images/sphx_glr_example_verify_patch_test_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 71-76 Acceptance ---------- The 1e-9 tolerance is conservative — we measure ~1e-19 on this build. A regression above 1e-12 would indicate a precision-dropping change in the assembly / solve pipeline. .. GENERATED FROM PYTHON SOURCE LINES 76-78 .. code-block:: Python assert r.passed, f"patch test failed: {r.computed:.3e} > {pv_.tolerance:.1e}" .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.221 seconds) .. _sphx_glr_download_gallery_verification_example_verify_patch_test.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: example_verify_patch_test.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: example_verify_patch_test.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: example_verify_patch_test.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_