.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/MeshModification/demo_smoothing.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_MeshModification_demo_smoothing.py: Mesh Smoothing ============== This example illustrates the effects of different smoothing methods. Smoothing a mesh can serve two purposes - the first is to smooth the geometry, rounding out sharp features; the second is to redistribute nodes, often in pursuit of improved element quality. When attempting to improve element quality, often the goal is to redistribute the nodes while having a minimal effect on the geometry. Different smoothing methods have different effects on the geometry. .. GENERATED FROM PYTHON SOURCE LINES 14-17 .. code-block:: Python import mymesh from mymesh import improvement .. GENERATED FROM PYTHON SOURCE LINES 18-21 The Stanford Bunny ------------------ We'll use the `Stanford bunny `_ as an example .. GENERATED FROM PYTHON SOURCE LINES 21-24 .. code-block:: Python bunny = mymesh.demo_mesh('bunny') bunny.plot(view='xy') .. image-sg:: /examples/MeshModification/images/sphx_glr_demo_smoothing_001.png :alt: demo smoothing :srcset: /examples/MeshModification/images/sphx_glr_demo_smoothing_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none RFBOutputContext() Identifying mesh nodes...Done .. GENERATED FROM PYTHON SOURCE LINES 25-29 Local Laplacian Smoothing ------------------------- Laplacian smoothing is a classic smoothing method, but can lead to shrinkage of the overall geometry .. GENERATED FROM PYTHON SOURCE LINES 29-39 .. code-block:: Python bunny_laplacian10 = improvement.LocalLaplacianSmoothing(bunny, options=dict(iterate=10)) bunny_laplacian100 = improvement.LocalLaplacianSmoothing(bunny, options=dict(iterate=100)) # plotting fig2, ax1 = bunny_laplacian10.plot(view='xy', show=False, return_fig=True) ax1.set_title('10 Iterations') fig2, ax2 = bunny_laplacian100.plot(view='xy', show=False, return_fig=True) ax2.set_title('100 Iterations') .. rst-class:: sphx-glr-horizontal * .. image-sg:: /examples/MeshModification/images/sphx_glr_demo_smoothing_002.png :alt: 10 Iterations :srcset: /examples/MeshModification/images/sphx_glr_demo_smoothing_002.png :class: sphx-glr-multi-img * .. image-sg:: /examples/MeshModification/images/sphx_glr_demo_smoothing_003.png :alt: 100 Iterations :srcset: /examples/MeshModification/images/sphx_glr_demo_smoothing_003.png :class: sphx-glr-multi-img .. rst-class:: sphx-glr-script-out .. code-block:: none Identifying volume node neighbors...Done Identifying volume node element connectivity...Done Identifying boundary nodes... Identifying boundary...Done Done RFBOutputContext() Identifying mesh nodes...Done RFBOutputContext() Identifying mesh nodes...Done .. GENERATED FROM PYTHON SOURCE LINES 40-44 Tangential Laplacian Smoothing ------------------------------ To mitigate shrinkage and better preserve features, tangential Laplacian smoothing moves nodes only in the plane tangent to the surface. .. GENERATED FROM PYTHON SOURCE LINES 44-54 .. code-block:: Python bunny_tangential10 = improvement.TangentialLaplacianSmoothing(bunny, options=dict(iterate=10)) bunny_tangential100 = improvement.TangentialLaplacianSmoothing(bunny, options=dict(iterate=100)) # plotting fig2, ax1 = bunny_tangential10.plot(view='xy', show=False, return_fig=True) ax1.set_title('10 Iterations') fig2, ax2 = bunny_tangential100.plot(view='xy', show=False, return_fig=True) ax2.set_title('100 Iterations') .. rst-class:: sphx-glr-horizontal * .. image-sg:: /examples/MeshModification/images/sphx_glr_demo_smoothing_004.png :alt: 10 Iterations :srcset: /examples/MeshModification/images/sphx_glr_demo_smoothing_004.png :class: sphx-glr-multi-img * .. image-sg:: /examples/MeshModification/images/sphx_glr_demo_smoothing_005.png :alt: 100 Iterations :srcset: /examples/MeshModification/images/sphx_glr_demo_smoothing_005.png :class: sphx-glr-multi-img .. rst-class:: sphx-glr-script-out .. code-block:: none Calculating surface node normals... Identifying surface node element connectivity...Done Calculating surface element normals...Done Done RFBOutputContext() Identifying mesh nodes...Done RFBOutputContext() Identifying mesh nodes...Done .. GENERATED FROM PYTHON SOURCE LINES 55-61 Taubin Smoothing ---------------- Taubin smoothing essentially performs two passes of Laplacian smoothing, but weighted so that the shrinkage induced by the first pass is reversed by inflation in the second pass, leading to improved preservation of features and geometries. .. GENERATED FROM PYTHON SOURCE LINES 61-71 .. code-block:: Python bunny_taubin10 = improvement.TaubinSmoothing(bunny, options=dict(iterate=10)) bunny_taubin100 = improvement.TaubinSmoothing(bunny, options=dict(iterate=100)) # plotting fig2, ax1 = bunny_taubin10.plot(view='xy', show=False, return_fig=True) ax1.set_title('10 Iterations') fig2, ax2 = bunny_taubin100.plot(view='xy', show=False, return_fig=True) ax2.set_title('100 Iterations') .. rst-class:: sphx-glr-horizontal * .. image-sg:: /examples/MeshModification/images/sphx_glr_demo_smoothing_006.png :alt: 10 Iterations :srcset: /examples/MeshModification/images/sphx_glr_demo_smoothing_006.png :class: sphx-glr-multi-img * .. image-sg:: /examples/MeshModification/images/sphx_glr_demo_smoothing_007.png :alt: 100 Iterations :srcset: /examples/MeshModification/images/sphx_glr_demo_smoothing_007.png :class: sphx-glr-multi-img .. rst-class:: sphx-glr-script-out .. code-block:: none RFBOutputContext() Identifying mesh nodes...Done RFBOutputContext() Identifying mesh nodes...Done .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 15.594 seconds) .. _sphx_glr_download_examples_MeshModification_demo_smoothing.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: demo_smoothing.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: demo_smoothing.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: demo_smoothing.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_