-
Notifications
You must be signed in to change notification settings - Fork 24
/
MakeInput.py
executable file
·311 lines (254 loc) · 10.3 KB
/
MakeInput.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
#!/usr/bin/env python3
import argparse
import sys
import os
import json
import numpy as np
import h5py
from random import *
from scipy.integrate import odeint
from scipy.optimize import fsolve
from joblib import Parallel, delayed
import pandas
# load HTR modules
sys.path.insert(0, os.path.expandvars("$HTR_DIR/scripts/modules"))
import gridGen
import HTRrestart
parser = argparse.ArgumentParser()
parser.add_argument('--np', nargs='?', default=1, type=int,
help='number of cores')
parser.add_argument('base_json', type=argparse.FileType('r'), default='base.json')
args = parser.parse_args()
##############################################################################
# Read similarity solution #
##############################################################################
CBL = pandas.read_csv("SimilaritySolution.dat")
etaB = CBL["eta"][:].values
fB = CBL["f"][:].values
uB = CBL["u"][:].values
TB = CBL["T"][:].values
N2B = CBL["X_N2"][:].values
O2B = CBL["X_O2"][:].values
NOB = CBL["X_NO"][:].values
NB = CBL["X_N" ][:].values
OB = CBL["X_O" ][:].values
muB = CBL["mu"][:].values
rhoB = CBL["rho"][:].values
cB = CBL["SoS"][:].values
Rex0 = CBL["Rex"][0]
x0 = Rex0*muB[-1]/(uB[-1]*rhoB[-1])
deltaStarIn = 0.0
for i in range(uB.size-1):
deltaStarIn += 0.5*((1.0 - uB[i+1]*rhoB[i+1]/(uB[-1]*rhoB[-1]))*rhoB[-1]/rhoB[i+1] +
(1.0 - uB[i ]*rhoB[i ]/(uB[-1]*rhoB[-1]))*rhoB[-1]/rhoB[i ] )*(etaB[i+1] - etaB[i])
deltaStarIn *= x0*np.sqrt(2.0/Rex0)
print("Re_delta0 = ", uB[-1]*rhoB[-1]*deltaStarIn/muB[-1])
yB = np.zeros(etaB.size)
for i in range(etaB.size):
if (i != 0) :
rhoMid = 0.5*(rhoB[i ] + rhoB[i-1])
dyB = x0*np.sqrt(2/Rex0)*rhoB[-1]/rhoMid*(etaB[i] - etaB[i-1])
yB[i] = yB[i-1] + dyB
vB = 0.5*yB/x0*uB - rhoB[-1]/rhoB*1.0/np.sqrt(2*Rex0)*fB
##############################################################################
# Setup Case #
##############################################################################
# Read base config
config = json.load(args.base_json)
ReIn = config["Case"]["ReInlet"]
MaInf = config["Case"]["MaInf"]
TInf = config["Case"]["TInf"]
PInf = config["Case"]["PInf"]
TwOvT = config["Case"]["TwOvTInf"]
xTurb = config["Case"]["xTurb"]
yPlus = config["Case"]["yPlus"]
FTT = config["Case"]["FlowThroughTimesNoStat"]
FTTS = config["Case"]["FlowThroughTimesStat"]
# Read properties
Pr = 0.71
gamma = 1.4
R = 287.15
# Simulation setup
assert config["Flow"]["turbForcing"]["type"] == "OFF"
assert config["Flow"]["initCase"]["type"] == "Restart"
restartDir = "InitialCase"
config["Flow"]["initCase"]["restartDir"] = restartDir
# Free-stream mixture properties
cInf = cB[-1]
muInf = muB[-1]
# Free-stream conditions
assert abs(TB[-1] - TInf) < 1e-3
UInf = uB[-1]
rhoInf = rhoB[-1]
TInf = TB[-1]
assert abs(UInf/cInf - MaInf) < 1e-3
# Inlet displacement thickness
assert abs(deltaStarIn -muInf*ReIn/(UInf*rhoInf)) < 1e-3
# Wall properties
Tw = TB[0]
muW = muB[0]
rhoW = rhoB[0]
assert abs(Tw/TB[-1] - TwOvT) < 1e-3
##############################################################################
# Compute similarity solution #
##############################################################################
# Reference friction coefficient
def getCfTurb(xGrid):
def VanDriestII(Cf):
Rexv = (xGrid-xTurb)*ReIn
r = Pr**(1.0/3.0)
Taw = TInf*(1.0 + r*0.5*(gamma - 1.0)*MaInf**2)
a = np.sqrt(r*0.5*(gamma - 1.0)*MaInf**2*TInf/Tw)
b = (Taw/Tw - 1.0)
A = (2*a**2 - b)/np.sqrt(b**2 + 4*a**2)
B = b /np.sqrt(b**2 + 4*a**2)
res = (np.arcsin(A) + np.arcsin(B))/np.sqrt(Cf*(Taw/TInf - 1.0))
res-= 4.15*np.log10(Rexv*Cf*muInf/muW)
res-= 1.7
return res
cf = fsolve(VanDriestII, 1e-4, xtol=1e-10)
return cf
Cf = getCfTurb(config["Grid"]["GridInput"]["width"][0]+x0/deltaStarIn)
TauW = Cf*(rhoInf*UInf**2)*0.5
uTau = np.sqrt(TauW/rhoW)
deltaNu = muW/(uTau*rhoW)
tNu = deltaNu**2*rhoW/muW
# Get VorticityScale
delta = 0.0
for i in range(len(uB)):
if (uB[i] > 0.99*UInf):
delta = yB[i]
break
# Normalization scales
LRef = config["Flow"]["mixture"]["LRef"] = deltaStarIn
TRef = config["Flow"]["mixture"]["TRef"] = TInf
PRef = config["Flow"]["mixture"]["PRef"] = PInf
rhoRef = rhoInf
uRef = np.sqrt(PRef/rhoRef)
config["Flow"]["mixture"]["XiRef"]["Species"] = [
{"Name" : "N2", "MolarFrac" : N2B[-1]},
{"Name" : "O2", "MolarFrac" : O2B[-1]},
{"Name" : "NO", "MolarFrac" : NOB[-1]},
{"Name" : "O", "MolarFrac" : OB[-1]},
{"Name" : "N", "MolarFrac" : NB[-1]}]
# Normalize everything
TInf = 1.0
PInf = 1.0
rhoInf = 1.0
UInf /= uRef
cInf /= uRef
muInf /= np.sqrt(config["Flow"]["mixture"]["PRef"]*rhoRef)*LRef
Tw /= config["Flow"]["mixture"]["TRef"]
muW /= np.sqrt(config["Flow"]["mixture"]["PRef"]*rhoRef)*LRef
rhoW /= rhoRef
delta /= config["Flow"]["mixture"]["LRef"]
config["Integrator"]["EulerScheme"]["vorticityScale"] = UInf/delta
x0 /= LRef
deltaStarIn /= LRef
deltaNu /= LRef
config["Grid"]["GridInput"]["origin"][0] = x0
yB /= LRef
uB /= uRef
vB /= uRef
TB /= TRef
rhoB /= rhoRef
##############################################################################
# Boundary conditions #
##############################################################################
assert config["BC"]["xBCLeft"]["type"] == "NSCBC_Inflow"
assert config["BC"]["xBCLeft"]["VelocityProfile"]["type"] == "File"
config["BC"]["xBCLeft"]["VelocityProfile"]["FileDir"] = restartDir
assert config["BC"]["xBCLeft"]["TemperatureProfile"]["type"] == "File"
config["BC"]["xBCLeft"]["TemperatureProfile"]["FileDir"] = restartDir
assert config["BC"]["xBCLeft"]["MixtureProfile"]["type"] == "File"
config["BC"]["xBCLeft"]["MixtureProfile"]["FileDir"] = restartDir
config["BC"]["xBCLeft"]["P"] = PInf
assert config["BC"]["xBCRight"]["type"] == "NSCBC_Outflow"
config["BC"]["xBCRight"]["P"] = PInf
assert config["BC"]["yBCLeft"]["type"] == "SuctionAndBlowingWall"
assert config["BC"]["yBCLeft"]["TemperatureProfile"]["type"] == "Constant"
config['BC']["yBCLeft"]["TemperatureProfile"]["temperature"] = Tw
config["BC"]["yBCLeft"]["Xmin"] = 15*deltaStarIn + x0
config["BC"]["yBCLeft"]["Xmax"] = 20*deltaStarIn + x0
config["BC"]["yBCLeft"]["X0"] = 0.5*(config["BC"]["yBCLeft"]["Xmin"] + config["BC"]["yBCLeft"]["Xmax"])
config["BC"]["yBCLeft"]["sigma"] = 0.3*(config["BC"]["yBCLeft"]["X0"] - config["BC"]["yBCLeft"]["Xmin"])
config["BC"]["yBCLeft"]["Zw"] = 0.1*config["Grid"]["GridInput"]["width"][2]
config["BC"]["yBCLeft"]["A"] = [ 0.05*UInf, 0.05*UInf]
config["BC"]["yBCLeft"]["omega"] = [ 0.9*cInf/deltaStarIn, 0.9*cInf/deltaStarIn]
config["BC"]["yBCLeft"]["beta"] = [ 0.3/deltaStarIn, -0.3/deltaStarIn]
assert config["BC"]["yBCRight"]["type"] == "NSCBC_Outflow"
config["BC"]["yBCRight"]["P"] = PInf
##############################################################################
# Generate Grid #
##############################################################################
xGrid, yGrid, zGrid, dx, dy, dz = gridGen.getCellCenters(config, dyMinus = yPlus*deltaNu)
print(" L_x x L_y x L_z")
print(config["Grid"]["GridInput"]["width"][0]/deltaNu, " x ",
config["Grid"]["GridInput"]["width"][1]/deltaNu, " x ",
config["Grid"]["GridInput"]["width"][2]/deltaNu)
print(dx[0]/deltaNu, " x ",
dy[1]/deltaNu, " x ",
dz[0]/deltaNu)
# Set maxTime
config["Integrator"]["maxTime"] = config["Grid"]["GridInput"]["width"][0]/UInf*FTT
with open("NoStats.json", 'w') as fout:
json.dump(config, fout, indent=3)
config["Integrator"]["maxTime"] = config["Grid"]["GridInput"]["width"][0]/UInf*FTT + FTTS*2*np.pi/config["BC"]["yBCLeft"]["omega"][0]
# Setup averages
config["IO"]["YZAverages"] = [{"fromCell" : [0, 0, 0], "uptoCell" : [config["Grid"]["xNum"]+1, 0, config["Grid"]["zNum"]]}]
with open("Stats.json", 'w') as fout:
json.dump(config, fout, indent=3)
##############################################################################
# Produce restart and profile files #
##############################################################################
shape2D = (xGrid.size, yGrid.size)
u = np.ndarray(shape2D)
v = np.ndarray(shape2D)
T = np.ndarray(shape2D)
N2= np.ndarray(shape2D)
O2= np.ndarray(shape2D)
NO= np.ndarray(shape2D)
N = np.ndarray(shape2D)
O = np.ndarray(shape2D)
for i,x in enumerate(xGrid):
Re = rhoInf*UInf*xGrid[i]/muInf
yB1 = yB*np.sqrt(Re/Rex0)
vB1 = vB*np.sqrt(Rex0/Re)
u[i,:] = np.interp(yGrid, yB1, uB)
v[i,:] = np.interp(yGrid, yB1, vB1)
T[i,:] = np.interp(yGrid, yB1, TB)
N2[i,:] = np.interp(yGrid, yB1, N2B)
O2[i,:] = np.interp(yGrid, yB1, O2B)
NO[i,:] = np.interp(yGrid, yB1, NOB)
N [i,:] = np.interp(yGrid, yB1, NB)
O [i,:] = np.interp(yGrid, yB1, OB)
def pressure(lo_bound, hi_bound, shape):
return PInf
def temperature(lo_bound, hi_bound, shape):
tt = np.transpose(T[lo_bound[0]:hi_bound[0]+1,
lo_bound[1]:hi_bound[1]+1])
return np.reshape([tt[:,:]
for k in range(lo_bound[2], hi_bound[2]+1)],
(shape[0], shape[1], shape[2]))
def MolarFracs(lo_bound, hi_bound, shape):
Xi = [[N2[i,j], O2[i,j], NO[i,j], N[i,j], O[i,j]]
for j in range(lo_bound[1], hi_bound[1]+1)
for i in range(lo_bound[0], hi_bound[0]+1)]
return np.reshape([Xi for k in range(lo_bound[2], hi_bound[2]+1)],
(shape[0], shape[1], shape[2], 5))
def velocity(lo_bound, hi_bound, shape):
vv = [[u[i,j], v[i,j], 0.0]
for j in range(lo_bound[1], hi_bound[1]+1)
for i in range(lo_bound[0], hi_bound[0]+1)]
return np.reshape([vv for k in range(lo_bound[2], hi_bound[2]+1)],
(shape[0], shape[1], shape[2], 3))
restart = HTRrestart.HTRrestart(config)
restart.write_fast(restartDir, 5,
pressure,
temperature,
MolarFracs,
velocity,
T_p = temperature,
Xi_p = MolarFracs,
U_p = velocity,
nproc = args.np)