-
Notifications
You must be signed in to change notification settings - Fork 1
/
base.jl
311 lines (240 loc) · 8.1 KB
/
base.jl
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
function [ tb,qb,qbs,tbv,pisfc, pib, rhou, rhow,rhb, ub,um,u ] = ...
base( profile_method,nx,nz,dz,psurf,qsurf,q4km,ztr,temptr,ttr,tsurf,p0,cp,g,...
rd,xk,c_v,zu,rhow,rhou,tb,tbv,qb,qbs,rhb,pib,ub,um,u)
#UNTITLED5 Summary of this function goes here
# Detailed explanation goes here
if profile_method == 1
#########################################
# Define a dry and neutral environment
# Set base state theta to 300 K and mixing ratio to 0 kg/kg
for k = 2 : nz - 1
tb[k] = 300.0;
qb[k] = 0.0;
tbv[k] = tb(k)*(1 + 0.61*qb(k));
end
# Assign pi
pisfc = (psurf / p0)^xk;
pib[2] = pisfc - g*0.5*dz/(cp*tbv(2));
for k = 3 : nz - 1
tbvavg[k] = 0.5*(tbv(k) + tbv(k-1));
pib[k] = pib(k-1) - g*dz/(cp*tbvavg(k));
end
for k = 2 : nz - 1
# Assign mean state density at u point
rhou[k] = (p0*pib(k)^(c_v/rd))/(rd*tbv(k));
# Assign mean state density at w point
rhow[k] = 0.5*(rhou(k) + rhou(k-1));
end
#Ensure there is no gradient at the boundaries
tb[1] = tb(2);
tb[nz] = tb(nz-1);
pib[1] = pib(2);
pib[nz] = pib(nz-1);
rhou[1] = rhou(2);
rhou[nz] = rhou(nz-1);
rhow[2] = 1.15;
rhow[1] = rhow(2);
rhow[nz] = rhow(nz-1);
elseif profile_method == 2
## fovellwk82soundingdef
# define a sounding on the u/scalar points
# Assign Values to vertical grid
for k = 2 : nz - 1
# Assign water vapor mixing ratio
if(zu[k] <= 4000.0)
qb[k] = qsurf - (qsurf - q4km)*zu(k)/4000.0;
elseif (zu[k] <= 8000.0)
qb[k] = q4km - q4km*(zu(k)-4000.0)/4000.0;
else
qb[k] = 0.0;
end
# Assign potential temperature
if(zu[k]<= ztr)
tb[k] = tsurf + (ttr - tsurf)*(zu(k)/ztr)^1.25;
else
tb[k] = ttr*exp(g*(zu(k) - ztr)/(cp*temptr));
end
# Assign virtual potential temperature
tbv[k] = tb(k)*(1 + 0.61*qb(k));
end
# Assign pi
pisfc = (psurf / p0)^xk;
pib[2] = pisfc - g*0.5*dz/(cp*tbv(2));
for k = 3 : nz - 1
tbvavg[k] = 0.5*(tbv(k) + tbv(k-1));
pib[k] = pib(k-1) - g*dz/(cp*tbvavg(k));
end
# Assign mean state density at u point
for k = 2 : nz-1
rhou[k] = (p0*pib(k)^(c_v/rd))/(rd*tbv(k));
# Assign mean water vapor saturation mixing ratio
t[k] = tb(k)*pib(k);
p[k] = p0*pib(k)^(cp/rd);
qbs[k] = (380.0/p(k))*exp(17.27*(t(k)-273.0)/(t(k)-36.0));
# Calculate and Assign RH
rhb[k] = qb(k)/qbs(k);
end
# define density at the true surface from known information
pisfc = (psurf/p0)^xk;
rhow[2] = p0*(pisfc^(c_v/rd))/(rd*tsurf);
# define density at the other w points by interpolating from u/scalar points
for k=3:nz-1
rhow[k] = 0.5*(rhou(k) + rhou(k-1));
end
elseif profile_method == 3
# define the Weisman Klemp sounding on the u/scalar points
for k=2 : nz-1
# assign potential temperatures and relative humidities
if zu[k]<= ztr
tb[k] = tsurf + (ttr-tsurf)*(zu[k]/ztr)^1.25;
rhb[k] = 1 - 0.02*(zu[k]/ztr)^1.25;
elseif zu[k] > ztr
tb[k] = ttr*exp(g*(zu[k]-ztr)/(cp*temptr));
rhb[k] = 0.98;
end
# first guess sans moisture
tbv[k] = tb[k];
end
# compute the non-dimensional pressure profile as a first guess
# (needed for qvs below)
pisfc = (psurf / p0)^xk;
pib[2] = pisfc - g*0.5*dz/(cp*tbv[2]);
for k = 3 : nz - 1
tbvavg = 0.5*(tbv[k] + tbv[k-1]);
pib[k] = pib[k-1] - g*dz/(cp*tbvavg);
end
# convert to mixing ratios
for k=2 : nz-1
p = p0*pib[k]^(cp/rd);
temp = tb[k]*pib[k];
qvs = (380.0/p) * exp((17.27*(temp-273.0))/(temp-36.0));
# if zu(k) < 20000
qb[k] = min(qsurf,qvs*rhb[k]);
# else
# qb(k) = 0;
# end
# define virtual potential temperatures
tbv[k] = tb[k]*(1 + 0.61*qb[k]);
# if k==98 || k == 99 || k == 100
# display(k)
# display(p)
# display(temp)
# display(qvs)
# display('qb')
# display(qb(k))
# display('tbv')
# display(tbv(k))
# display('rhb')
# display(rhb(k))
# end
# end
# go back and recompute the non-dimensional pressure profile now that
# we have humidity included
pisfc = (psurf / p0)^xk;
pib[2] = pisfc - g*0.5*dz/(cp*tbv[2]);
for k = 3 : nz - 1
tbvavg = 0.5*(tbv[k] + tbv[k-1]);
pib[k] = pib[k-1] - g*dz/(cp*tbvavg);
end
# compute the density profile
pisfc = (psurf/p0)^xk;
rhow[2] = p0*(pisfc^(c_v/rd))/(rd*tsurf);
# define density at the other w points by interpolating from u/scalar points
# define density at u/scalar points
for k=2:nz-1
rhou[k] = p0*(pib[k]^(c_v/rd))/(rd*tbv[k]);
end
# define density at the true surface from known information
pisfc = (psurf/p0)^xk;
rhow[2] = p0*(pisfc^(c_v/rd))/(rd*tsurf);
# define density at the other w points by interpolating from u/scalar points
for k=3:nz-1
rhow[k] = 0.5*(rhou[k] + rhou[k-1]);
end
# compute the profiles of saturation mixing ratio and relative humidity
# define saturation mixing ratio on u/scalar points
for k=2: nz-1
p = p0*pib[k]^(cp/rd);
temp = tb[k]*pib[k];
# use Teten's formula (see Pielke's text, 2nd ed., p. 257-258 for more info)
qbs[k] = (380.0/p) * exp((17.27*(temp-273.0))/(temp-36.0));
rhb[k] = qb[k] / qbs[k];
end
end # End Method If Statement
#Ensure there is no gradient at the boundaries
tb[1] = tb[2];
tb[nz] = tb[nz-1];
tbv[1] = tbv[2];
tbv[nz] = tbv[nz-1];
pib[1] = pib[2];
pib[nz] = pib[nz-1];
rhou[1] = rhou[2];
rhou[nz] = rhou[nz-1];
rhow[1] = rhow[2];
rhow[nz] = rhow[nz-1];
qb[1] = qb[2];
qb[nz] = qb[nz-1];
## Define U base
# Uniform Flow
ub[:] .= -10;
um[:,:] .= -10;
u[:,:] .= -10;
############################################################
# High Surface Wind decreasing as altitude increases
# usfc=-10.0; # u-wind at the surface (m/s)
# # * for initwinds=1 (only)
# deltau=10.0; # u-wind change over the layer (m/s)
# # * for initwinds=1 (only)
# shrdepth=3000.0; # depth of deltau layer (m)
# # * for initwinds=1 (only)
#
#
# for k=2:nz-1
# # assign base state values
# if zu(k)<shrdepth
# ub(k) = usfc + zu(k)*deltau/shrdepth;
# else
# ub(k) = usfc + deltau;
# end
# for i= 1 :nx
# # copy base state values into prognosed u array
# u(i,k) = ub(k);
# um(i,k) = ub(k);
# end
# end
###################################################################
# Low-Level Jet at a given z height (given by shrdepth)
#
# usfc=0; # u-wind at the surface (m/s)
# # * for initwinds=1 (only)
# deltau=-10.0; # u-wind change over the layer (m/s)
# # * for initwinds=1 (only)
# shrdepth=2000.0; # depth of deltau layer (m)
# # * for initwinds=1 (only)
#
# for k=2:nz-1
# # assign base state values
# if zu(k)<=shrdepth
# ub(k) = usfc + zu(k)*deltau/shrdepth;
# elseif zu(k) <= 2*shrdepth
# ub(k) = 2*deltau - deltau*(zu(k)/(shrdepth));
# else
# ub(k) = 0;
# end
# for i= 1 :nx
# # copy base state values into prognosed u array
# u(i,k) = ub(k);
# um(i,k) = ub(k);
# end
# end
######################################################################
# handle boundaries
for i=1:nx
u[i,1] = ub[2];
up[i,1] = ub[2];
um[i,1] = ub[2];
u[i,nz] = ub[nz-1];
up[i,nz] = ub[nz-1];
um[i,nz] = ub[nz-1];
end
end