Postprocessing example : Spatial average

This example doesn’t do much, it reads and makes a spatial average of OpenFoam fields

First read the fields

Note

It just reads a scalar and vector field and store it in variables

import readfield function from fluidfoam package

from fluidfoam import readfield, getVolumes

sol = '../output_samples/bin/'
timename = '0'

alpha = readfield(sol, timename, 'alpha')
U = readfield(sol, timename, 'U')
Reading file ../output_samples/bin/0/alpha
Reading file ../output_samples/bin/0/U

Now read the dV from the mesh

centr,dV = getVolumes(sol)
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

Finally calculate the average of the fields

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)
Mean value of the alpha field =  1.1000502463688941
Mean value of the velocity vectorfield =  [0.00502464 1.30653203 1.40703449]

Total running time of the script: (0 minutes 0.014 seconds)

Gallery generated by Sphinx-Gallery