.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/unstructured/plot_2D_mesh.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_auto_examples_unstructured_plot_2D_mesh.py: Create vectorised visualisations of the mesh ============================================ This example shows how to use MeshVisu object to plot vectorised images of 2D planar meshes. .. GENERATED FROM PYTHON SOURCE LINES 10-16 First create a visualisable mesh object with MeshVisu -------------------------------------------------------------- .. note:: This class allows you to create a list of edges contained inside a box. This list of edges will then be ploted. .. GENERATED FROM PYTHON SOURCE LINES 16-29 .. code-block:: Python # import the class MeshVisu from fluidfoam import MeshVisu # path to the simulation to load path = '../../output_samples/pipeline' # Load mesh and create an object called myMesh # The box by default is egal to the mesh dimension myMesh = MeshVisu( path = '../../output_samples/pipeline') .. rst-class:: sphx-glr-script-out .. code-block:: none Reading file ../../output_samples/pipeline/constant/polyMesh/faces Reading file ../../output_samples/pipeline/constant/polyMesh/points Box set to mesh size: (minx, miny, minz) = (np.float64(-0.75), np.float64(-0.1), np.float64(-0.001)) (maxx, maxy, maxz) = (np.float64(1.0), np.float64(0.205), np.float64(0.0)) .. GENERATED FROM PYTHON SOURCE LINES 30-33 Plot the whole mesh -------------------------------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 33-58 .. code-block:: Python import matplotlib.pyplot as plt from matplotlib.collections import LineCollection # compute mesh aspect ratio: xmin, xmax = myMesh.get_xlim() ymin, ymax = myMesh.get_ylim() AR = (ymax - ymin) / (xmax - xmin) fig, ax = plt.subplots( figsize = (8,8*AR)) # create a collection with edges and print it ln_coll = LineCollection(myMesh.get_all_edgesInBox(), linewidths = 0.25, colors = 'brown') ax.add_collection(ln_coll, autolim=True) # impose the dimensions of the box as the limits of the figure ax.set_xlim(myMesh.get_xlim()) ax.set_ylim(myMesh.get_ylim()) # to avoid distorting the mesh: ax.set_aspect('equal') # to don't print axis: ax.axis('off') .. image-sg:: /auto_examples/unstructured/images/sphx_glr_plot_2D_mesh_001.png :alt: plot 2D mesh :srcset: /auto_examples/unstructured/images/sphx_glr_plot_2D_mesh_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none (np.float64(-0.75), np.float64(1.0), np.float64(-0.1), np.float64(0.205)) .. GENERATED FROM PYTHON SOURCE LINES 59-61 Update the box to zoom on the cylinder and save figure -------------------------------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 61-82 .. code-block:: Python myMesh.update_box(((0, 0, -1), (0.03, 0.03, 1))) fig, ax = plt.subplots( figsize = (8,8)) # create a collection with edges and print it ln_coll = LineCollection(myMesh.get_all_edgesInBox(), linewidths = 0.25, colors = 'black') ax.add_collection(ln_coll, autolim=True) # Set box dimensions as the figures's limits ax.set_xlim(myMesh.get_xlim()) ax.set_ylim(myMesh.get_ylim()) # to avoid distorting the mesh: ax.set_aspect('equal') # to don't print axis: ax.axis('off') # to save the figure in pdf or svg format, uncomment one of the following two lines: # plt.savefig('./myCylinderZomm.pdf', dpi=fig.dpi, transparent = True, bbox_inches = 'tight') # plt.savefig('./myCylinderZomm.svg', dpi=fig.dpi, transparent = True, bbox_inches = 'tight') .. image-sg:: /auto_examples/unstructured/images/sphx_glr_plot_2D_mesh_002.png :alt: plot 2D mesh :srcset: /auto_examples/unstructured/images/sphx_glr_plot_2D_mesh_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none (np.float64(0.0), np.float64(0.03), np.float64(0.0), np.float64(0.03)) .. GENERATED FROM PYTHON SOURCE LINES 83-85 Visualisation of dynamic case in xz plane -------------------------------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 85-121 .. code-block:: Python # path to the simulation to load: mypath = '../../output_samples/darrieus' # time folder for which you want to display the mesh: mytime = '0.1' # plane in which the mesh is contained, either: # 'xy': the xy-plane of outgoing normal z (default value) # 'xz': the xz-plane of outgoing normal -y # 'yz': the yz-plane of outgoing normal x myplane = 'xz' # box to zoom in on for mesh display: mybox = ((-1.2, -1, -1.2), (1.2, 1, 1.2)) # Load mesh and create an object called myOtherMesh: myOtherMesh = MeshVisu(path = mypath, box = mybox, time_name = mytime, plane = myplane) # The next line sets the thumbnail for the last figure in the gallery # sphinx_gallery_thumbnail_number = -1 fig, ax = plt.subplots( figsize = (8,8)) # create a collection with edges and print it ln_coll = LineCollection(myOtherMesh.get_all_edgesInBox(), linewidths = 0.25, colors = 'black') ax.add_collection(ln_coll, autolim=True) # Set box dimensions as the figures's limits ax.set_xlim(myOtherMesh.get_xlim()) ax.set_ylim(myOtherMesh.get_zlim()) # to avoid distorting the mesh: ax.set_aspect('equal') # to don't print axis: ax.axis('off') .. image-sg:: /auto_examples/unstructured/images/sphx_glr_plot_2D_mesh_003.png :alt: plot 2D mesh :srcset: /auto_examples/unstructured/images/sphx_glr_plot_2D_mesh_003.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none Reading file ../../output_samples/darrieus/constant/polyMesh/faces Reading file ../../output_samples/darrieus/0.1/polyMesh/points (np.float64(-1.2), np.float64(1.2), np.float64(-1.2), np.float64(1.2)) .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 34.163 seconds) .. _sphx_glr_download_auto_examples_unstructured_plot_2D_mesh.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_2D_mesh.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_2D_mesh.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_2D_mesh.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_