forked from petebachant/actuatorSurface-OpenFOAM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
plot.py
executable file
·329 lines (298 loc) · 11.2 KB
/
plot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
#!/usr/bin/env python
"""Processing and plotting for OpenFOAM actuatorSurface simulation."""
from __future__ import division, print_function
import matplotlib.pyplot as plt
import numpy as np
import os
import sys
import foampy
from subprocess import call
import pandas
from pxl.styleplot import set_sns
def styleplot():
plt.tight_layout()
exp_path = "/media/pete/External 2/Research/Experiments/2014 Spring RVAT Re dep"
# Some constants
R = 0.5
U = 1.0
H = 0.05
D = 1.0
A = H*D
rho = 1000.0
ylabels = {"meanu" : r"$U/U_\infty$",
"stdu" : r"$\sigma_u/U_\infty$",
"meanv" : r"$V/U_\infty$",
"meanw" : r"$W/U_\infty$",
"meanuv" : r"$\overline{u'v'}/U_\infty^2$"}
def resample_wake(x=1.0):
import gensampledict
gensampledict.main(x)
call(["sample", "-latestTime"])
def loadwake():
"""Loads wake data and returns y/R and statistics."""
folder = os.listdir("postProcessing/sets")[0]
flist = os.listdir("postProcessing/sets/"+folder)
flist.remove("streamwise_U.xy")
data = {}
for fname in flist:
fpath = "postProcessing/sets/"+folder+"/"+fname
z_H = float(fname.split("_")[1])
data_s = np.loadtxt(fpath, unpack=True)
data[z_H] = data_s
return data
def plotwake(plotlist=["meancontquiv"], save=False, savepath="figures",
savetype=".pdf", print_analysis=True):
data = loadwake()
y_R = data[0][0]/R
z_H = np.asarray(sorted(data.keys()))
# Assemble 2-D arrays
u = np.zeros((len(z_H), len(y_R)))
v = np.zeros((len(z_H), len(y_R)))
w = np.zeros((len(z_H), len(y_R)))
xvorticity = np.zeros((len(z_H), len(y_R)))
for n in range(len(z_H)):
u[n,:] = data[z_H[n]][1]
v[n,:] = data[z_H[n]][2]
w[n,:] = data[z_H[n]][3]
try:
xvorticity[n,:] = data[z_H[n]][4]
except IndexError:
pass
def turb_lines():
plt.hlines(0.5, -1, 1, linestyles='solid', linewidth=2)
plt.vlines(-1, 0, 0.5, linestyles='solid', linewidth=2)
plt.vlines(1, 0, 0.5, linestyles='solid', linewidth=2)
if "meanu" in plotlist or "all" in plotlist:
plt.figure(figsize=(10,5))
cs = plt.contourf(y_R, z_H, u, 20, cmap=plt.cm.coolwarm)
plt.xlabel(r'$y/R$')
plt.ylabel(r'$z/H$')
cb = plt.colorbar(cs, shrink=1, extend='both',
orientation='horizontal', pad=0.2)
cb.set_label(r'$U/U_{\infty}$')
turb_lines()
ax = plt.axes()
ax.set_aspect(2)
plt.grid(True)
plt.yticks([0,0.13,0.25,0.38,0.5,0.63])
styleplot()
if "meanv" in plotlist or "all" in plotlist:
plt.figure(figsize=(10,5))
cs = plt.contourf(y/0.5, z, v, 20, cmap=plt.cm.coolwarm)
plt.xlabel(r'$y/R$')
plt.ylabel(r'$z/H$')
styleplot()
cb = plt.colorbar(cs, shrink=1, extend='both',
orientation='horizontal', pad=0.3)
cb.set_label(r'$V/U_{\infty}$')
#turb_lines()
ax = plt.axes()
ax.set_aspect(2)
plt.grid(True)
plt.yticks([0,0.13,0.25,0.38,0.5,0.63])
if "v-wquiver" in plotlist or "all" in plotlist:
# Make quiver plot of v and w velocities
plt.figure(figsize=(10,5))
Q = plt.quiver(y_R, z_H, v, w, angles='xy')
plt.xlabel(r'$y/R$')
plt.ylabel(r'$z/H$')
plt.ylim(-0.2, 0.78)
plt.xlim(-3.2, 3.2)
plt.quiverkey(Q, 0.75, 0.2, 0.1, r'$0.1$ m/s',
labelpos='E',
coordinates='figure',
fontproperties={'size': 'small'})
plt.tight_layout()
plt.hlines(0.5, -1, 1, linestyles='solid', colors='r',
linewidth=2)
plt.vlines(-1, -0.2, 0.5, linestyles='solid', colors='r',
linewidth=2)
plt.vlines(1, -0.2, 0.5, linestyles='solid', colors='r',
linewidth=2)
ax = plt.axes()
ax.set_aspect(2)
plt.yticks([0,0.13,0.25,0.38,0.5,0.63])
if save:
plt.savefig(savepath+'v-wquiver'+savetype)
if "xvorticity" in plotlist or "all" in plotlist:
plt.figure(figsize=(10,5))
cs = plt.contourf(y_R, z_H, xvorticity, 10, cmap=plt.cm.coolwarm)
plt.xlabel(r'$y/R$')
plt.ylabel(r'$z/H$')
cb = plt.colorbar(cs, shrink=1, extend='both',
orientation='horizontal', pad=0.26)
cb.set_label(r"$\Omega_x$")
turb_lines()
ax = plt.axes()
ax.set_aspect(2)
plt.yticks([0,0.13,0.25,0.38,0.5,0.63])
styleplot()
if save:
plt.savefig(savepath+'/xvorticity_AD'+savetype)
if "meancontquiv" in plotlist or "all" in plotlist:
plt.figure(figsize=(7.5, 4.8))
# Add contours of mean velocity
cs = plt.contourf(y_R, z_H, u, np.arange(0.15, 1.25, 0.05),
cmap=plt.cm.coolwarm)
cb = plt.colorbar(cs, shrink=1, extend="both",
orientation="vertical", pad=0.02)
cb.set_label(r'$U/U_{\infty}$')
plt.hold(True)
# Make quiver plot of v and w velocities
Q = plt.quiver(y_R, z_H, v, w, width=0.0022, edgecolor="none",
scale=3.0)
plt.xlabel(r'$y/R$')
plt.ylabel(r'$z/H$')
#plt.ylim(-0.2, 0.78)
#plt.xlim(-3.2, 3.2)
plt.xlim(-3.66, 3.66)
plt.ylim(-1.22, 1.22)
plt.quiverkey(Q, 0.65, 0.055, 0.1, r"$0.1 U_\infty$",
labelpos="E",
coordinates="figure",
fontproperties={"size": "small"})
plt.hlines(0.5, -1, 1, linestyles='solid', colors='gray',
linewidth=2)
plt.hlines(-0.5, -1, 1, linestyles='solid', colors='gray',
linewidth=2)
plt.vlines(-1, -0.5, 0.5, linestyles='solid', colors='gray',
linewidth=2)
plt.vlines(1, -0.5, 0.5, linestyles='solid', colors='gray',
linewidth=2)
ax = plt.axes()
ax.set_aspect(2.0)
plt.xlim((-3, 3))
plt.ylim((-1.125, 1.125))
plt.yticks(np.around(np.arange(-1.125, 1.126, 0.125), decimals=2))
styleplot()
if save:
plt.savefig(os.path.join(savepath, "meancontquiv" + savetype))
if print_analysis:
print("Spatial average of U =", u.mean())
def plotexpwake(Re_D, quantity, z_H=0.0, save=False, savepath="",
savetype=".pdf", newfig=True, marker="--ok",
fill="none", figsize=(10, 5)):
"""Plots the transverse wake profile of some quantity. These can be
* meanu
* meanv
* meanw
* stdu
"""
U = Re_D/1e6
label = "Exp."
folder = exp_path + "/Wake/U_" + str(U) + "/Processed/"
z_H_arr = np.load(folder + "z_H.npy")
i = np.where(z_H_arr==z_H)
q = np.load(folder + quantity + ".npy")[i]
y_R = np.load(folder + "y_R.npy")[i]
if newfig:
plt.figure(figsize=figsize)
plt.plot(y_R, q/U, marker, markerfacecolor=fill, label=label)
plt.xlabel(r"$y/R$")
plt.ylabel(ylabels[quantity])
plt.grid(True)
styleplot()
def set_funky_plane(x=1.0):
foampy.dictionaries.replace_value("system/funkyDoCalcDict", "basePoint",
"({}".format(x))
def read_funky_log():
with open("log.funkyDoCalc") as f:
for line in f.readlines():
try:
line = line.replace("=", " ")
line = line.split()
if line[0] == "planeAverageAdvectionY":
y_adv = float(line[-1])
elif line[0] == "weightedAverage":
z_adv = float(line[-1])
elif line[0] == "planeAverageTurbTrans":
turb_trans = float(line[-1])
elif line[0] == "planeAverageViscTrans":
visc_trans = float(line[-1])
elif line[0] == "planeAveragePressureGradient":
pressure_trans = float(line[-1])
except IndexError:
pass
return {"y_adv" : y_adv, "z_adv" : z_adv, "turb_trans" : turb_trans,
"visc_trans" : visc_trans, "pressure_trans" : pressure_trans}
def run_funky_batch():
xlist = [-1.99, -1.5, -1.0, -0.75, -0.5, -0.25, 0.0, 0.25, 0.5, 0.75,
1.0, 1.5, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 7.99]
df = pandas.DataFrame()
for x in xlist:
print("Setting measurement plane to x =", x)
set_funky_plane(x)
call(["./Allrun.post"])
dfi = pandas.DataFrame(read_funky_log(), index=[x])
df = df.append(dfi)
if not os.path.isdir("processed"):
os.mkdir("processed")
df.index.name = "x"
print(df)
df.to_csv("processed/mom_transport.csv", index_label="x")
def make_momentum_trans_bargraph(print_analysis=True):
data = read_funky_log()
y_adv = data["y_adv"]
z_adv = data["z_adv"]
turb_trans = data["turb_trans"]
visc_trans = data["visc_trans"]
pressure_trans = data["pressure_trans"]
plt.figure(figsize=(6,4))
ax = plt.gca()
ax.bar(range(5), [y_adv, z_adv, turb_trans, visc_trans, pressure_trans],
color="gray", edgecolor="black", hatch="//", width=0.5)
ax.set_xticks(np.arange(5)+0.25)
ax.set_xticklabels(["$y$-adv.", "$z$-adv.",
"Turb.", "Visc.", "Press."])
plt.ylabel(r"$\frac{U \, \mathrm{ transport}}{UU_\infty D^{-1}}$")
plt.tight_layout()
if print_analysis:
sum = y_adv + z_adv + turb_trans + visc_trans + pressure_trans
print("Momentum recovery = {:.3f}% per turbine diameter".format(sum))
def plot_mom_transport():
df = pandas.read_csv("processed/mom_transport.csv")
plt.plot(df.x, df.y_adv, "-o", label=r"$-V \partial U / \partial y$")
plt.plot(df.x, df.z_adv, "-s", label=r"$-W \partial U / \partial z$")
plt.plot(df.x, df.turb_trans, "-^", label=r"$\nu_t \nabla^2 U$")
plt.plot(df.x, df.visc_trans, "->", label=r"$\nu \nabla^2 U$")
plt.plot(df.x, df.pressure_trans/10, "-<", label=r"$-\partial P / \partial x$ ($\times 10^{-1}$)")
plt.legend(loc="lower right", ncol=1)
plt.xlabel("$x/D$")
plt.ylabel(r"$\frac{U \, \mathrm{ transport}}{UU_\infty D^{-1}}$")
plt.grid()
plt.tight_layout()
def plot_U_streamwise():
times = os.listdir("postProcessing/sets")
times.sort()
latest = times[-1]
filepath = os.path.join("postProcessing", "sets", latest,
"streamwise_U.xy")
x, u, v, w = np.loadtxt(filepath, unpack=True)
plt.plot(x, u, "k")
plt.xlabel("$x/D$")
plt.ylabel(r"$U/U_\infty$")
plt.grid()
plt.tight_layout()
def plot_streamwise(save=False, savepath="figures"):
plt.figure(figsize=(7.5, 4))
plt.subplot(121)
plot_U_streamwise()
plt.subplot(122)
plot_mom_transport()
plt.tight_layout()
if save:
plt.savefig(os.path.join(savepath, "streamwise.pdf"))
def main():
if not os.path.isdir("figures"):
os.mkdir("figures")
set_sns()
#resample_wake(x=1.0)
plotwake(plotlist=["meancontquiv"], save=True)
#make_momentum_trans_bargraph()
if not os.path.isfile("processed/mom_transport.csv"):
run_funky_batch()
#plot_mom_transport()
plot_streamwise(save=True)
plt.show()
if __name__ == "__main__":
main()