-
Notifications
You must be signed in to change notification settings - Fork 5
/
make_fig_interac.py
executable file
·212 lines (174 loc) · 8.33 KB
/
make_fig_interac.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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
interactive making figures script
"""
import numpy as np
import matplotlib
matplotlib.use('PDF') # AGG for png ?
import matplotlib.pyplot as plt
# default setting for figures
from matplotlib import rc
plt.rcParams["font.size"] = 20
rc('text', usetex=True)
from OFpost import main_post
import driver_BOGP as D
from gpOptim import gpOpt_TBL
# %% global variables
# %% funcs
def make_patch_spines_invisible(ax):
ax.set_frame_on(True)
ax.patch.set_visible(False)
for sp in ax.spines.values():
sp.set_visible(False)
def read_npy(dataName, n, path2data=D.PATH2DATA): # Re_theta, beta, deltaStar, dpdx
data = np.empty(0)
for i in range(n):
fileName = path2data + "/%s%02d.npy" % (dataName, i+1)
data = np.append(data, np.load(fileName))
data = data.reshape([n,-1])
return data
def beta_components_fig(xc, x, delta99_in, U_infty, deltaStar, dpdx, tau_w, in_exc, out_exc, \
iMain, deltaStarBound, dpdxBound, tau_wBound, path2figs=D.PATH2FIGS):
# use log so that it's easier to see the superposition
Nx = np.size(xc)
xc_delta = xc/delta99_in
x_delta = x/delta99_in
ymin = min(deltaStarBound[0]/delta99_in, dpdxBound[0]*2*delta99_in/U_infty**2, \
tau_wBound[0]*2/U_infty**2)
ymax = max(deltaStarBound[1]/delta99_in, dpdxBound[1]*2*delta99_in/U_infty**2, \
tau_wBound[1]*2/U_infty**2)
ymin2 = deltaStarBound[0]/delta99_in
ymax2 = deltaStarBound[1]/delta99_in
ymin1 = dpdxBound[0]*2*delta99_in/U_infty**2
ymax1 = dpdxBound[1]*2*delta99_in/U_infty**2
ymin3 = tau_wBound[0]*2/U_infty**2
ymax3 = tau_wBound[1]*2/U_infty**2
fig = plt.figure()
fig.subplots_adjust(right=0.75)
ax1 = fig.add_subplot(111)
ax2 = ax1.twinx()
ax3 = ax1.twinx()
# only right axis visible
ax3.spines["right"].set_position(("axes", 1.2))
make_patch_spines_invisible(ax3)
ax3.spines["right"].set_visible(True)
# plot
ln2, = ax2.plot(xc_delta, deltaStar/delta99_in, "C2", label=r"$\delta^* / \delta_{99}^{\rm in}$")
ln1, = ax1.plot(x_delta[1:-1], dpdx*2*delta99_in/U_infty**2, "C1", \
label=r"$\frac{dP}{dx} \left( \frac{\delta_{99}^{\rm in}} {\frac{1}{2}\rho U_e^{{\rm in}^2}} \right)$")
ln3, = ax3.plot(xc_delta, 2*tau_w/U_infty**2, "C3", label=r"$c_f$")
ax1.vlines([x[int(Nx*in_exc)]/delta99_in,x[-int(Nx*out_exc)-1]/delta99_in], \
ymin,ymax,'k',linestyles='dashdot')
h1, l1 = ax1.get_legend_handles_labels()
h2, l2 = ax2.get_legend_handles_labels()
h3, l3 = ax3.get_legend_handles_labels()
ax1.legend(h1+h2+h3, l1+l2+l3, bbox_to_anchor=(0., 1.02, 1., 1.02), \
loc='lower left', ncol=3, mode="expand", fontsize=15)
ax1.set_xlabel(r'$x/\delta_{99}^{\rm in}$')
ax2.set_ylabel(r'$\delta^*/\delta_{99}^{\rm in}$')
ax1.set_ylabel(r'$\frac{dp}{dx} \left( \frac{\delta_{99}^{\rm in}} {\frac{1}{2}\rho U_e^{{\rm in}^2}} \right)$')
ax3.set_ylabel(r"$c_f$")
ax1.set_xlim(x_delta[0],x_delta[-1])
ax1.set_ylim(ymin1,ymax1)
ax2.set_ylim(ymin2,ymax2)
ax3.set_ylim(ymin3,ymax3)
ax1.yaxis.label.set_color(ln1.get_color())
ax2.yaxis.label.set_color(ln2.get_color())
ax3.yaxis.label.set_color(ln3.get_color())
ax1.tick_params(axis='y', colors=ln1.get_color())
ax2.tick_params(axis='y', colors=ln2.get_color())
ax3.tick_params(axis='y', colors=ln3.get_color())
ax1.grid(True)
saveFileName = "/comp_%02d" % iMain
fig.savefig(path2figs + saveFileName + ".pdf",bbox_inches="tight")
# logger.info("save beta figure as %s%s.pdf" % (D.PATH2FIGS, saveFileName))
print("save comp figure as %s%s.pdf" % (path2figs, saveFileName))
# %% ################## main ###########################
if __name__ == '__main__':
isCurrentCase = False # IF FALSE, CHECK FOLLOWING IF STATEMENT CAREFULLY !!!!!
if isCurrentCase:
# setting from driver
in_exc = D.in_exc
out_exc = D.out_exc
U_infty, delta99_in, Nx, Ny, Nz = D.U_infty, D.delta99_in, D.Nx, D.Ny, D.Nz
# paths
path2data = D.PATH2DATA
path2figs = D.PATH2FIGS
path2OFcase = D.PATH2OFCASE
path2gpList = D.PATH2GPLIST
# from gpOpt_TBL.py
gpBounds = gpOpt_TBL.qBound #BOUNDS #[(40,50),(40,50)]
else:
# setting from driver
in_exc = 0.15
out_exc = 0.05
U_infty, delta99_in, Nx, Ny, Nz = D.U_infty, D.delta99_in, D.Nx, D.Ny, D.Nz
# paths
PATH2CASE = "/scratch/morita/OpenFOAM/morita-7/run/pgTBL_optim/storage/wing_8D"
path2data = PATH2CASE + "/data"
path2figs = "/scratch/morita/OpenFOAM/morita-7/run/pgTBL_optim/storage/paperFigs"
path2OFcase = PATH2CASE + "/1" # for grid
path2gpList = PATH2CASE + "/gpList.dat"
# from gpOpt_TBL.py
gpBounds = [(0,70),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0),(0,0)]
# gp fig
[xList,yList] = gpOpt_TBL.read_available_GPsamples(path2gpList, \
nPar_=np.shape(gpBounds)[0])
nData = np.size(yList)
Rlim = [0, np.max(yList)]
# xc, yc, x, y = main_post.load_grid(Nx, Ny, Nz, path2OFcase) # needs to be overwritten
# load *.npy
Re_thetaList = read_npy("Re_theta", nData, path2data)
betaList = read_npy("beta", nData, path2data)
deltaStarList = read_npy("deltaStar", nData, path2data)
dpdxList = read_npy("dpdx", nData, path2data)
tau_wList = read_npy("tau_w", nData, path2data)
delta99List = read_npy("delta99_", nData, path2data)
UList = read_npy("U", nData, path2data)
UList = UList.reshape([nData, Ny, Nx])
Re_thetaBound = [np.min(Re_thetaList), np.max(Re_thetaList)]
betaBound = [np.min(betaList), np.max(betaList)]
deltaStarBound = [np.min(deltaStarList), np.max(deltaStarList)]
dpdxBound = [np.min(dpdxList), np.max(dpdxList)]
tau_wBound = [np.min(tau_wList), np.max(tau_wList)]
delta99_Bound = [np.min(delta99List), np.max(delta99List)]
# if delta99_Bound[1] >= D.Ly/2:
# print("Warning: delta99 >= Ly/2")
# overwrite
betaBound[0] = 0
betaBound[1] = 1.2
# gp final
# xList=np.fliplr(xList)
# gpOpt_TBL.gpSurface_plot(xList[:nData], yList[:nData], nData, path2figs=path2figs+"/", \
# Rlim=None, bounds=gpBounds,var=False,final=True)
# gpOpt_TBL.gpSurface_plot(xList[:nData], yList[:nData], nData, path2figs=path2figs+"/", \
# bounds=gpBounds,var=True,final=True)
for i in range(51,52):
# comp*.pdf
# beta_components_fig(xc, x, delta99_in, U_infty, deltaStarList[i], dpdxList[i], \
# tau_wList[i], in_exc, out_exc, \
# i+1, deltaStarBound, dpdxBound, tau_wBound, path2figs)
# update beta figs
# obj = main_post.calc_obj(betaList[i], beta_t, in_exc, out_exc)
# obj = yList[i]
# main_post.save_beta_fig(i+1, x, betaList[i], delta99_in, in_exc,
# out_exc, obj, betaMin=betaBound[0],
# betaMax=betaBound[1], path2figs=path2figs)
#main_post.save_beta_fig(i+1, x, betaList[i], delta99_in, in_exc,
# out_exc, obj,
# path2figs=path2figs)
# update gp figs
# gpOpt_TBL.gpSurface_plot(xList[:i+1], yList[:i+1], i+1, path2figs=path2figs, \
# bounds=gpBounds,var=False)
#gpOpt_TBL.gpSurface_plot(xList[:i+1], yList[:i+1], i+1, path2figs=path2figs,
# bounds=gpBounds,var=True)
# update convergence plot
# gpOpt_TBL.my_convergence_plot(xList[:i+1], yList[:i+1], gpOpt_TBL.whichOptim, \
# path2figs, 'bo_convergence_%02d' % (i+1))
# update U figs
xc, yc, x, y = main_post.load_grid(Nx, Ny, Nz, PATH2CASE+"/%d" % (i+1))
main_post.save_Ucontour(x/delta99_in, y/delta99_in, xc/delta99_in,
yc/delta99_in, UList[i], delta99List[i]/delta99_in,
i+1, in_exc, out_exc, xList[i], ymax=np.max(gpBounds),
path2figs=path2figs)