.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/structured/plot_0_averagedfield.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_0_averagedfield.py: Spatially averaged profile ========================== This example reads and plots a spatially averaged profile of the first component of an OpenFoam vector field from a structured mesh .. GENERATED FROM PYTHON SOURCE LINES 10-15 First reads 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-23 .. code-block:: Python # import readmesh function from fluidfoam package from fluidfoam import readmesh sol = '../../output_samples/box/' x, y, z = readmesh(sol, structured=True) .. 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 .. GENERATED FROM PYTHON SOURCE LINES 24-29 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 29-36 .. 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 37-40 Averaging along x and z axis (1 and 3) -------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 40-44 .. code-block:: Python import numpy as np vel_averaged = np.mean(np.mean(vel, 3), 1) .. GENERATED FROM PYTHON SOURCE LINES 45-48 Now plots the profile of the averaged first velocity component -------------------------------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 48-60 .. code-block:: Python import matplotlib.pyplot as plt plt.figure() plt.plot(vel_averaged[0], y[0, :, 0]) #Setting axis labels plt.xlabel('U (m/s)') plt.ylabel('y (m)') # add grid plt.grid() .. image-sg:: /auto_examples/structured/images/sphx_glr_plot_0_averagedfield_001.png :alt: plot 0 averagedfield :srcset: /auto_examples/structured/images/sphx_glr_plot_0_averagedfield_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 1.114 seconds) .. _sphx_glr_download_auto_examples_structured_plot_0_averagedfield.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_0_averagedfield.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_0_averagedfield.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_0_averagedfield.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_