.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/LinearizedElasticity/MeshOptim0.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_LinearizedElasticity_MeshOptim0.py: MeshOptim0 ========== Optimization of a happy mesh with quality criteria. .. GENERATED FROM PYTHON SOURCE LINES 11-100 .. tab-set:: .. tab-item:: Static Scene .. image-sg:: /examples/LinearizedElasticity/images/sphx_glr_MeshOptim0_001.png :alt: MeshOptim0 :srcset: /examples/LinearizedElasticity/images/sphx_glr_MeshOptim0_001.png :class: sphx-glr-single-img .. tab-item:: Interactive Scene .. offlineviewer:: /home/docs/checkouts/readthedocs.org/user_builds/easyfea/checkouts/v1.6.0/docs/examples/LinearizedElasticity/images/sphx_glr_MeshOptim0_001.vtksz .. tab-set:: .. tab-item:: Static Scene .. image-sg:: /examples/LinearizedElasticity/images/sphx_glr_MeshOptim0_002.png :alt: MeshOptim0 :srcset: /examples/LinearizedElasticity/images/sphx_glr_MeshOptim0_002.png :class: sphx-glr-single-img .. tab-item:: Interactive Scene .. offlineviewer:: /home/docs/checkouts/readthedocs.org/user_builds/easyfea/checkouts/v1.6.0/docs/examples/LinearizedElasticity/images/sphx_glr_MeshOptim0_002.vtksz .. tab-set:: .. tab-item:: Static Scene .. image-sg:: /examples/LinearizedElasticity/images/sphx_glr_MeshOptim0_003.png :alt: MeshOptim0 :srcset: /examples/LinearizedElasticity/images/sphx_glr_MeshOptim0_003.png :class: sphx-glr-single-img .. tab-item:: Interactive Scene .. offlineviewer:: /home/docs/checkouts/readthedocs.org/user_builds/easyfea/checkouts/v1.6.0/docs/examples/LinearizedElasticity/images/sphx_glr_MeshOptim0_003.vtksz .. image-sg:: /examples/LinearizedElasticity/images/sphx_glr_MeshOptim0_004.png :alt: ratio = 66.809 % :srcset: /examples/LinearizedElasticity/images/sphx_glr_MeshOptim0_004.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none ratio = 37.500 % ratio = 57.143 % ratio = 66.809 % /home/docs/checkouts/readthedocs.org/user_builds/easyfea/checkouts/v1.6.0/examples/LinearizedElasticity/MeshOptim0.py:94: MatplotlibDeprecationWarning: Passing the range parameter of hist() positionally is deprecated since Matplotlib 3.10; the parameter will become keyword-only in 3.12. axHist.hist(qual_e, 11, (0, 1)) | .. code-block:: Python :lineno-start: 12 from EasyFEA import Display, Folder, plt, np, Mesher, ElemType, Mesh, PyVista from EasyFEA.Geoms import Point, Circle, CircleArc, Contour from EasyFEA.fem import Mesh_Optim if __name__ == "__main__": Display.Clear() # ---------------------------------------------- # Configuration # ---------------------------------------------- # outputs folder = Folder.Join(Folder.RESULTS_DIR, "Meshes", "Optim2D", mkdir=True) # geom D = 1 r = D * 1 / 4 e = 0.1 b = D * 0.1 # criteria criteria = "aspect" quality = 0.8 # lower bound of the target quality ratio = 0.6 # the ratio of mesh elements that must satisfy the target iterMax = 20 # Maximum number of iterations coef = 1 / 2 # Scaling coefficient for the optimization process # ---------------------------------------------- # Mesh # ---------------------------------------------- elemType = ElemType.TRI3 mS = e / 3 * 10 # face circle = Circle(Point(), D, mS) # eyes theta = 45 * np.pi / 180 sin = np.sin(theta) cos = np.cos(theta) eye1 = Circle(Point(-r * sin, r * cos), e, mS) eye2 = Circle(Point(r * sin, r * cos), e, mS) # happy smile s = (D * 0.6) / 2 s1 = CircleArc(Point(-s), Point(s), Point(), coef=-1, meshSize=mS) s2 = CircleArc(Point(s), Point(s - e), Point(s - e / 2), coef=-1, meshSize=mS) s3 = CircleArc(Point(s - e), Point(-s + e), Point(), meshSize=mS) s4 = CircleArc(Point(-s + e), Point(-s), Point(-s + e / 2), coef=-1, meshSize=mS) happy = Contour([s1, s2, s3, s4]) inclusions = [eye1, eye2, happy] def DoMesh(refineGeom=None) -> Mesh: """Function used for mesh generation""" return Mesher().Mesh_2D(circle, inclusions, elemType, [], [refineGeom]) # Construct the initial mesh mesh = DoMesh() PyVista.Plot_Mesh(mesh).show() mesh, ratio = Mesh_Optim(DoMesh, folder, criteria, quality, ratio) # ---------------------------------------------- # Plot # ---------------------------------------------- qual_e = mesh.Get_Quality(criteria, False) PyVista.Plot_Mesh(mesh).show() PyVista.Plot( mesh, qual_e, nodeValues=False, plotMesh=True, clim=(0, quality), cmap="viridis", ).show() axHist = Display.Init_Axes() axHist.hist(qual_e, 11, (0, 1)) axHist.set_xlabel("quality") axHist.set_ylabel("elements") axHist.set_title(f"ratio = {ratio * 100:.3f} %") axHist.vlines([quality], [0], [ratio * mesh.Ne], color="red") plt.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.981 seconds) .. _sphx_glr_download_examples_LinearizedElasticity_MeshOptim0.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: MeshOptim0.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: MeshOptim0.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: MeshOptim0.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_