.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/calc_0_avgfield.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_calc_0_avgfield.py: Postprocessing example : Spatial average ======================================== This example doesn't do much, it reads and makes a spatial average of OpenFoam fields .. GENERATED FROM PYTHON SOURCE LINES 10-16 First read the fields --------------------- .. note:: It just reads a scalar and vector field and store it in variables import readfield function from fluidfoam package .. GENERATED FROM PYTHON SOURCE LINES 16-24 .. code-block:: Python from fluidfoam import readfield, getVolumes sol = '../output_samples/bin/' timename = '0' alpha = readfield(sol, timename, 'alpha') U = readfield(sol, timename, 'U') .. rst-class:: sphx-glr-script-out .. code-block:: none Reading file ../output_samples/bin/0/alpha Reading file ../output_samples/bin/0/U .. GENERATED FROM PYTHON SOURCE LINES 25-28 Now read the dV from the mesh ----------------------------- .. GENERATED FROM PYTHON SOURCE LINES 28-30 .. code-block:: Python centr,dV = getVolumes(sol) .. rst-class:: sphx-glr-script-out .. code-block:: none Reading file ../output_samples/bin//constant/polyMesh/owner Reading file ../output_samples/bin//constant/polyMesh/faces Reading file ../output_samples/bin//constant/polyMesh/points Reading file ../output_samples/bin//constant/polyMesh/neighbour .. GENERATED FROM PYTHON SOURCE LINES 31-34 Finally calculate the average of the fields ------------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 34-40 .. code-block:: Python import numpy as np avgfield = np.sum(alpha*dV)/np.sum(dV) avgU = np.sum(U*dV, axis=1)/np.sum(dV) print("Mean value of the alpha field = ", avgfield) print("Mean value of the velocity vectorfield = ", avgU) .. rst-class:: sphx-glr-script-out .. code-block:: none Mean value of the alpha field = 1.1000502463688941 Mean value of the velocity vectorfield = [0.00502464 1.30653203 1.40703449] .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.014 seconds) .. _sphx_glr_download_auto_examples_calc_0_avgfield.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: calc_0_avgfield.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: calc_0_avgfield.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: calc_0_avgfield.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_