Skip to content

Commit 4da1b44

Browse files
committed
add example
1 parent e3f4165 commit 4da1b44

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

doc/conf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@
6565
]
6666

6767
sphinx_gallery_conf = {
68+
'filename_pattern': '/',
6869
# path to your examples scripts
6970
'examples_dirs': '../examples',
7071
# path where to save gallery generated examples

examples/calc_0_avgfield.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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

Comments
 (0)