.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples_mesh/example_generate_mesh.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note Click :ref:`here ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_mesh_example_generate_mesh.py: ================================================================================ Generate meshes from .geo files with Gmsh ================================================================================ Meshes are built with gmsh from `.geo` files then loaded into freshkiss3d. .. GENERATED FROM PYTHON SOURCE LINES 9-14 .. code-block:: default import os import numpy as np import matplotlib.pyplot as plt import freshkiss3d as fk .. GENERATED FROM PYTHON SOURCE LINES 15-48 Generate meshes from .geo -------------------------- Meshes are generated with gmsh thanks to a ``.geo`` file. The ``.geo`` contains all information gmsh needs to generate a Delaunay triangulation. You can specify the number of nodes on boundaries with the `Transfinite` option. .. note:: .geo files can be generated with gsmh and are easy to script for simple geometries. Here is an example of a simple canal geometry: .. code-block:: bash Lx = 25.0; Ly = 1.0; Point(1) = {0, 0, 0, 1}; Point(2) = {Lx, 0, 0, 1}; Point(3) = {Lx, Ly, 0, 1}; Point(4) = {0, Ly, 0, 1}; Line(1) = {1, 2}; Line(2) = {2, 3}; Line(3) = {3, 4}; Line(4) = {4, 1}; Line Loop(5) = {3, 4, 1, 2}; Plane Surface(0) = {5}; Physical Line(1) = {4}; Physical Line(2) = {2}; Physical Line(3) = {3}; Physical Line(4) = {1}; Transfinite Line {3, 1} = 50 Using Progression 1; Transfinite Line {4, 2} = 3 Using Progression 1; Physical Surface(0) = {0}; .. GENERATED FROM PYTHON SOURCE LINES 51-52 Gmsh can be called via simple commands to generate meshes: .. GENERATED FROM PYTHON SOURCE LINES 53-57 .. code-block:: default os.system('gmsh -2 -format msh2 inputs/bump0.geo -o inputs/bump0.msh') os.system('gmsh -2 -format msh2 inputs/bump1.geo -o inputs/bump1.msh') .. rst-class:: sphx-glr-script-out .. code-block:: none 0 .. GENERATED FROM PYTHON SOURCE LINES 58-61 Construct a TriangularMesh ------------------------------ .. GENERATED FROM PYTHON SOURCE LINES 62-67 .. code-block:: default triangular_mesh_1 = fk.TriangularMesh.from_msh_file('inputs/bump0.msh') triangular_mesh_2 = fk.TriangularMesh.from_msh_file('inputs/bump1.msh') .. GENERATED FROM PYTHON SOURCE LINES 68-71 Basic plot -------------------- .. GENERATED FROM PYTHON SOURCE LINES 72-100 .. code-block:: default TG = triangular_mesh_1.triangulation x = np.asarray(TG.x) y = np.asarray(TG.y) trivtx = np.asarray(TG.trivtx) TG_r = triangular_mesh_2.triangulation x_r = np.asarray(TG_r.x) y_r = np.asarray(TG_r.y) trivtx_r = np.asarray(TG_r.trivtx) plt.rcParams["figure.figsize"]=[20,6] fig = plt.figure() # Plot ax1 = fig.add_subplot(211) ax1.triplot(x, y, trivtx, color='r') ax1.set_title("Mesh 1") # Plot refined mesh ax2 = fig.add_subplot(212) ax2.triplot(x_r, y_r, trivtx_r) ax2.set_title("Mesh 2") plt.show() #os.system('rm inputs/bump0.msh') #os.system('rm inputs/bump1.msh') .. image-sg:: /auto_examples_mesh/images/sphx_glr_example_generate_mesh_001.png :alt: Mesh 1, Mesh 2 :srcset: /auto_examples_mesh/images/sphx_glr_example_generate_mesh_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** ( 0 minutes 0.444 seconds) .. _sphx_glr_download_auto_examples_mesh_example_generate_mesh.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: example_generate_mesh.py ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: example_generate_mesh.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_