-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDragLength.py
211 lines (180 loc) · 6.84 KB
/
DragLength.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
import numpy
import math
import copy
"""
Calculate mixing length scale for the 1-D column model in the urban area
Developed by Negin Nazarian(1) and Scott Krayenhoff(2)
1.University of New South Wales, Sydney, Australia
2.University of Guelph, Guelph, Canada
Last update: February 2020
"""
# Calculate sectional drag coefficient (Cdrag) for buildings w/o trees(eq. 4.17, Krayenhoff, PhD thesis)
def Drag_Coef(nz,lambdaf,pb):
"""
-----
INPUT:
nz: Number of grid points in the urban area
lambdaf: Frontal area density
pb(z): Probability that a building has a height greater or equal to z
-------
OUTPUT:
Cdrag: Drag coefficient due to buildings [-]
"""
Cdrag = numpy.zeros(nz)
for i in range(0,nz):
if (lambdaf*pb[i+1]) <= 0.33:
Cdrag[i] = 7.3*((lambdaf*pb[i+1])**(0.62))
else:
Cdrag[i] = 3.67
return Cdrag
# Calculate turbulent and dissipation length scales
def Length_Scale(nz,z,lambdap,bldHeight,Ceps,Cmu,Ck):
"""
------
INPUT:
nz: Number of grid points in the urban area
z: Vertical distribution of grids [m]
lambdap: Plane area density
bldHeight: Building height [m]
Ceps: Coefficient for the destruction of turbulent dissipation rate
Cmu: Model constant
Ck: Model constant
-------
OUTPUT:
dls: Dissipation length scale [m]
dlk: Turbulent length scale [m]
"""
# Option 1:
# Eqs. 4.15 and 4.18, Krayenhoff, PhD thesis
#a1 = 1.95
#a2 = 1.07
# Option 2:
# Eq. 12 in "N. Nazarian et al., 2020"
a1 = 4
a2 = min(5,max(2,1.3*lambdap**(-0.45)))
# Calculate displacement height (eq. 4.19, Krayenhoff 2014, PhD thesis)
disp = bldHeight * (lambdap ** (0.15))
# Dissipation length scale [m]
dls = numpy.zeros(nz)
# Turbulent length scale [m]
dlk = numpy.zeros(nz)
for i in range(0,nz):
zc = (z[i]+z[i+1])/2
if bldHeight == 0:
dls[i] = Ceps*a2*zc[i]
elif (zc/bldHeight) <= 1:
dls[i] = Ceps*a1*(bldHeight-disp)
elif (zc/bldHeight) > 1 and (zc/bldHeight) <= 1.5:
dls[i] = Ceps*a1*(zc-disp)
elif (zc/bldHeight) > 1.5:
d2 = (1 - a1 / a2) * 1.5 * bldHeight + (a1 / a2) * disp
dls[i] = Ceps*a2*(zc-d2)
dlk[i] = Cmu[i]*dls[i]/(Ceps*Ck)
return dls,dlk
# Calculate turbulent and dissipation length scales
def Length_Scale_StabilityCorrection(nz,z,bldHeight,Ceps,Ck,hfx,vx_eq,vy_eq,VerticalProfUrban,lambdaf,disp,dz,vl):
"""
------
INPUT:
nz: Number of grid points in the urban area
z: Vertical distribution of grids [m]
bldHeight: Building height [m]
Ceps: Coefficient for the destruction of turbulent dissipation rate
Ck: Model constant
hfx: Total urban heat flux per unit flat area of the earth [W m^-2]
vx_eq: Terms in x-momentum equation
vy_eq: Terms in y-momentum equation
VerticalProfUrban: Vertical profile of temperature, humidity, wind speed, and turbulent kinetic energy from previous time step
lambdaf: Frontal area density
disp: Displacement height [m]
dz: Vertical resolution [m]
vl: Volume fraction of air in each urban unit cell [-]
-------
OUTPUT:
dls: Dissipation length scale [m]
dlk: Turbulent length scale [m]
"""
srim_vx_sav = copy.copy(vx_eq.srim)
srim_vy_sav = copy.copy(vy_eq.srim)
srex_vx_sav = copy.copy(vx_eq.srex)
srex_vy_sav = copy.copy(vy_eq.srex)
vx_sav = copy.copy(VerticalProfUrban.vx)
vy_sav = copy.copy(VerticalProfUrban.vy)
th0 = copy.copy(VerticalProfUrban.th_ref[0])
g = 9.81
dls = numpy.zeros(nz)
dlk = numpy.zeros(nz)
dls_neut = numpy.zeros(nz)
if hfx > 0:
sum_drag = 0
for iz in range(0,nz):
sum_drag = sum_drag+dz*vl[iz]*(abs(srim_vx_sav[iz]*vx_sav[iz]) + abs(srim_vy_sav[iz]*vy_sav[iz]) +
abs(srex_vx_sav[iz]) + abs(srex_vy_sav[iz]))
u_tau = numpy.sqrt(abs(sum_drag))
H_L = bldHeight/(u_tau**3.)/(g/th0)/abs(hfx)
a1 = 5.00
if lambdaf == 0:
a2 = 5.
else:
a2 = min(5.,max(2.,1.23*lambdaf**(-0.442)))
cmu_can = max(0.06,-1.3678*lambdaf**2.+0.658*lambdaf+0.0303)
cmu_above = 0.037
for iz in range(0,nz):
zc = (z[iz]+z[iz+1])/2
if bldHeight == 0:
dls[iz] = Ceps*a2*zc
cmu = cmu_can
dls_neut[iz] = dls[iz]
dls[iz] = dls[iz]*(1.+0.5*min(H_L,3.))
else:
if zc/bldHeight <= 1:
dls[iz] = Ceps*a1*(bldHeight-disp)
cmu = cmu_can
if zc/bldHeight > 0.9:
cmu = (cmu_can*(1.1-zc/bldHeight)+cmu_above*(zc/bldHeight-0.9))/0.2
dls_neut[iz] = dls[iz]
dls[iz] = dls[iz]*(1+(0.2+0.3*zc/bldHeight)*min(H_L,3.))
elif zc/bldHeight > 1 and zc/bldHeight <= 1.5:
dls[iz] = Ceps*a1*(zc-disp)
cmu = cmu_above
if zc/bldHeight < 1.25:
cmu = (cmu_can*(1.25-zc/bldHeight)+cmu_above*(zc/bldHeight-0.75))/0.5
dls_neut[iz] = dls[iz]
dls[iz] = dls[iz]*(1.+0.5*min(H_L,3.))
elif zc/bldHeight > 1.5:
d2 = (1.-a1/a2)*1.5*bldHeight+a1/a2*disp
dls[iz] = Ceps*a2*(zc-d2)
cmu = cmu_above
dls_neut[iz] = dls[iz]
dls[iz] = dls[iz]*(1.+0.5*min(H_L,3.))
dlk[iz] = cmu/(Ceps*Ck)*dls[iz]
else:
a1 = 5.00
if lambdaf == 0:
a2 = 5.
else:
a2 = min(5., max(2., 1.23 * lambdaf ** (-0.442)))
cmu_can = max(0.06, -1.3678 * lambdaf ** 2. + 0.658 * lambdaf + 0.0303)
cmu_above = 0.037
for iz in range(0, nz):
zc = (z[iz] + z[iz + 1]) / 2
if bldHeight == 0:
dls[iz] = Ceps * a2 * zc
cmu = cmu_can
else:
if zc / bldHeight <= 1:
dls[iz] = Ceps * a1 * (bldHeight - disp)
cmu = cmu_can
if zc / bldHeight > 0.9:
cmu = (cmu_can*(1.1-zc/bldHeight) + cmu_above*(zc/bldHeight-0.9))/0.2
elif zc / bldHeight > 1 and zc / bldHeight <= 1.5:
dls[iz] = Ceps * a1 * (zc - disp)
cmu = cmu_above
if zc / bldHeight < 1.1:
cmu = (cmu_can*(1.1-zc/bldHeight) + cmu_above*(zc/bldHeight-0.9))/0.2
elif zc / bldHeight > 1.5:
d2 = (1. - a1 / a2) * 1.5 * bldHeight + a1 / a2 * disp
dls[iz] = Ceps * a2 * (zc - d2)
cmu = cmu_above
dlk[iz] = cmu / (Ceps * Ck) * dls[iz]
return dls, dlk