.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/MeshGeneration/demo_heart.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_MeshGeneration_demo_heart.py: Implicit Heart ============== This example generates a surface mesh of an implicit function and then performs Laplacian smoothing on it. Defining an implicit function ----------------------------- Implicit functions are defined as functions of three arguments (x, y, z), which can handle vectorized inputs. .. GENERATED FROM PYTHON SOURCE LINES 15-21 .. code-block:: Python from mymesh import implicit, mesh, improvement def heart(x, y, z): # Taubin's Heart Surface return (x**2 + 9/4*y**2 + z**2 -1)**3 - x**2*z**3 - 9/80*y**2*z**3 .. GENERATED FROM PYTHON SOURCE LINES 22-24 Creating a Surface ------------------ .. GENERATED FROM PYTHON SOURCE LINES 24-29 .. code-block:: Python bounds = [-1.5, 1.5, -1.5, 1.5, -1.5, 1.5] h = 0.05 # element size Heart = implicit.SurfaceMesh(heart, bounds, h) Heart.plot(bgcolor='white', color='red') .. image-sg:: /examples/MeshGeneration/images/sphx_glr_demo_heart_001.png :alt: demo heart :srcset: /examples/MeshGeneration/images/sphx_glr_demo_heart_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none RFBOutputContext() .. GENERATED FROM PYTHON SOURCE LINES 30-35 Smoothing --------- The heart surface has a bit of a ridge in the middle, this can be eliminated by smoothing the mesh. This will also improve the quality of the elements in the mesh and more evenly distribute the nodes. .. GENERATED FROM PYTHON SOURCE LINES 35-39 .. code-block:: Python Heart = improvement.LocalLaplacianSmoothing(Heart) Heart.plot(bgcolor='white', color='red') .. image-sg:: /examples/MeshGeneration/images/sphx_glr_demo_heart_002.png :alt: demo heart :srcset: /examples/MeshGeneration/images/sphx_glr_demo_heart_002.png :class: sphx-glr-single-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() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.608 seconds) .. _sphx_glr_download_examples_MeshGeneration_demo_heart.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: demo_heart.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: demo_heart.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: demo_heart.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_