.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/structured/plot_1_contour.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_structured_plot_1_contour.py: Contour from a slice in domain ============================== This example reads and plots a contour of the first component of an OpenFoam vector field from a structured mesh .. GENERATED FROM PYTHON SOURCE LINES 10-15 First reads the mesh and print the shape/size of the mesh --------------------------------------------------------- .. note:: It reads the mesh coordinates for a structured mesh (argument True) and stores them in variables x, y and z .. GENERATED FROM PYTHON SOURCE LINES 15-26 .. code-block:: Python # import readmesh function from fluidfoam package from fluidfoam import readmesh sol = '../../output_samples/box/' x, y, z = readmesh(sol, structured=True) nx, ny, nz = x.shape print("Nx = ", nx, "Ny = ", ny, "Nz = ", nz) .. rst-class:: sphx-glr-script-out .. code-block:: none Reading file ../../output_samples/box//constant/polyMesh/owner Reading file ../../output_samples/box//constant/polyMesh/faces Reading file ../../output_samples/box//constant/polyMesh/points Reading file ../../output_samples/box//constant/polyMesh/neighbour Nx = 20 Ny = 24 Nz = 15 .. GENERATED FROM PYTHON SOURCE LINES 27-32 Reads a vector field -------------------- .. note:: It reads a vector field from a structured mesh and stores it in vel variable .. GENERATED FROM PYTHON SOURCE LINES 32-39 .. code-block:: Python # import readvector function from fluidfoam package from fluidfoam import readvector timename = '0' vel = readvector(sol, timename, 'U', structured=True) .. rst-class:: sphx-glr-script-out .. code-block:: none Reading file ../../output_samples/box/0/U Reading file ../../output_samples/box//constant/polyMesh/owner Reading file ../../output_samples/box//constant/polyMesh/faces Reading file ../../output_samples/box//constant/polyMesh/points Reading file ../../output_samples/box//constant/polyMesh/neighbour .. GENERATED FROM PYTHON SOURCE LINES 40-44 Now plots the contour of the first velocity component at a given z position --------------------------------------------------------------------------- .. note:: Here the position z is the middle (// is used to have an integer) .. GENERATED FROM PYTHON SOURCE LINES 44-57 .. code-block:: Python import matplotlib.pyplot as plt import numpy as np plt.figure() levels = np.arange(0, 0.178, 0.001) plt.contourf(x[:, :, nz//2], y[:, :, nz//2], vel[0, :, :, nz//2], levels=levels) # Setting axis labels plt.xlabel('x (m)') plt.ylabel('y (m)') .. image-sg:: /auto_examples/structured/images/sphx_glr_plot_1_contour_001.png :alt: plot 1 contour :srcset: /auto_examples/structured/images/sphx_glr_plot_1_contour_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none Text(33.972222222222214, 0.5, 'y (m)') .. GENERATED FROM PYTHON SOURCE LINES 58-61 Now add on the same plot the velocity vectors --------------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 61-72 .. code-block:: Python plt.figure() plt.contourf(x[:, :, nz//2], y[:, :, nz//2], vel[0, :, :, nz//2], levels=levels) # Setting axis labels plt.xlabel('x (m)') plt.ylabel('y (m)') plt.quiver(x[:, :, nz//2], y[:, :, nz//2], vel[0, :, :, nz//2], vel[1, :, :, nz//2]) .. image-sg:: /auto_examples/structured/images/sphx_glr_plot_1_contour_002.png :alt: plot 1 contour :srcset: /auto_examples/structured/images/sphx_glr_plot_1_contour_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 1.228 seconds) .. _sphx_glr_download_auto_examples_structured_plot_1_contour.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_1_contour.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_1_contour.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_1_contour.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_