|
| 1 | +""" |
| 2 | +Postprocessing example : Spatial average |
| 3 | +======================================== |
| 4 | + |
| 5 | +This example doesn't do much, it reads and makes a spatial average of OpenFoam |
| 6 | +fields |
| 7 | +""" |
| 8 | + |
| 9 | +############################################################################### |
| 10 | +# First read the fields |
| 11 | +# --------------------- |
| 12 | +# |
| 13 | +# .. note:: It just reads a scalar and vector field and store it in variables |
| 14 | +# |
| 15 | +# import readfield function from fluidfoam package |
| 16 | +from fluidfoam import readfield, getVolumes |
| 17 | + |
| 18 | +sol = '../output_samples/bin/' |
| 19 | +timename = '0' |
| 20 | + |
| 21 | +alpha = readfield(sol, timename, 'alpha') |
| 22 | +U = readfield(sol, timename, 'U') |
| 23 | + |
| 24 | +############################################################################### |
| 25 | +# Now read the dV from the mesh |
| 26 | +# ----------------------------- |
| 27 | +# |
| 28 | +centr,dV = getVolumes(sol) |
| 29 | + |
| 30 | +############################################################################### |
| 31 | +# Finally calculate the average of the fields |
| 32 | +# ------------------------------------------- |
| 33 | +# |
| 34 | +import numpy as np |
| 35 | +avgfield = np.sum(alpha*dV)/np.sum(dV) |
| 36 | +avgU = np.sum(U*dV, axis=1)/np.sum(dV) |
| 37 | + |
| 38 | +print("Mean value of the alpha field = ", avgfield) |
| 39 | +print("Mean value of the velocity vectorfield = ", avgU) |
0 commit comments