-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathset_vertical_bcs.AUSM
416 lines (342 loc) · 14.1 KB
/
set_vertical_bcs.AUSM
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
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
!\
! ------------------------------------------------------------
! set_boundary
! ------------------------------------------------------------
!/
subroutine set_vertical_bcs(LogRho,LogNS,Vel_GD,Temp, LogINS, iVel, VertVel)
! Fill in ghost cells at the top and bottom
use ModSizeGitm, only: nAlts
use ModPlanet, only: nSpecies, nIonsAdvect, Mass, nIons, &
IsEarth, iO_, iN2_,iNO_
use ModGITM, only: iEast_, iNorth_, iUp_
use ModInputs
use ModConstants
use ModTime, only: UTime, iJulianDay,currenttime
use ModVertical, only: Lat, Lon, Gravity_G, Altitude_G, dAlt_F
use ModIndicesInterfaces, only: get_HPI
use EUA_ModMsis90, ONLY: meter6
implicit none
real, intent(inout) :: &
LogRho(-1:nAlts+2), &
LogNS(-1:nAlts+2,nSpecies), &
LogINS(-1:nAlts+2,nIonsAdvect), &
Vel_GD(-1:nAlts+2,3), &
IVel(-1:nAlts+2,3), &
Temp(-1:nAlts+2), &
VertVel(-1:nAlts+2,nSpecies)
integer :: iSpecies, iAlt, iDir
real :: InvScaleHeightS, InvScaleHgt, Alt, Lst, Ap = 4.0, dn, dt
logical :: IsFirstTime = .true., UseMsisBCs = .false.
real :: HP
integer :: ierror
integer, dimension(25) :: sw
!! JMB Added 11-03-2014 (New BC Variables)
!! Useful for Upper Boundary Conditions--Hydrostatic
real :: InvAtmScaleHeight
real :: NS(-1:nAlts+2,1:nSpecies), NT(-1:nAlts+2)
real :: EffectiveGravity(-1:nAlts+2)
real :: MeanGravity, MeanMass, MeanTemp
logical :: IsHydrostatic(1:nSpecies), IsPhotoChemical(1:nSpecies)
! Gradient Terms
real :: dLogNS, dTemp, dVertVel
real :: dLogINS
!!! Use for 4-th Order Forward Differences
!!! Need a 5-point Stencil
real :: h1, h2, h3, h4
real :: MeshH1, MeshH2, MeshH3, MeshH4
real :: MeshCoef0, MeshCoef1, &
MeshCoef2, MeshCoef3, &
MeshCoef4
!!! Use for 4-th Order Backward Differences
!!! Need a 5-point Stencil
real :: hm1, hm2, hm3, hm4
real :: MeshHm1, MeshHm2, MeshHm3, MeshHm4
real :: MeshCoefm0, MeshCoefm1, &
MeshCoefm2, MeshCoefm3, &
MeshCoefm4
!-----------------------------------------------------------
! Bottom
!-----------------------------------------------------------
if (IsEarth) UseMsisBCs = UseMsis
if (IsFirstTime .and. UseMsisBCs) then
call meter6(.true.)
sw = 1
IsFirstTime = .true.
endif
if (UseMsisBCs) then
call get_HPI(CurrentTime, HP, iError)
if (iError > 0) hp = 40.0
Ap = min(200.,max(-40.72 + 1.3 * HP, 10.))
do iAlt = -1, 0
Alt = Altitude_G(iAlt)/1000.0
Lst = mod(UTime/3600.0+Lon/15.0,24.0)
call msis_bcs(iJulianDay,UTime,Alt,Lat,Lon,Lst, &
F107A,F107,AP,LogNS(iAlt,:), Temp(iAlt), &
LogRho(iAlt))
enddo
else
! do nothing - which means don't change the initial condition.
endif
! Let the winds blow !!!!
Vel_GD(-1:0,iEast_) = 0.0
Vel_GD(-1:0,iNorth_) = 0.0
! Vel_GD(-1:0,iUp_) = 0.0
! VertVel(-1:0,:) = 0.0
IVel(-1:0,iUp_) = 0.0
do iSpecies=1,nIonsAdvect
dn = (LogINS(2,iSpecies) - LogINS(1,iSpecies))
LogINS(0,iSpecies) = LogINS(1,iSpecies) - dn
LogINS(-1,iSpecies) = LogINS(0,iSpecies) - dn
enddo
! Calculate the non-uniform mesh coefficients
iAlt = -1
h1 = dAlt_F(iAlt+2) ! dAlt_F(1) = Alt(1) - Alt(0); h1 in notes
h2 = dAlt_F(iAlt+3) ! dAlt_F(2) = Alt(2) - Alt(1); h2 in notes
h3 = dAlt_F(iAlt+4) ! dAlt_F(3) = Alt(3) - Alt(2); h3 in notes
h4 = dAlt_F(iAlt+5) ! dAlt_F(4) = Alt(4) - Alt(3); h4 in notes
! Mesh Coefficients are summations over the individual mesh scales
MeshH1 = h1
MeshH2 = h1 + h2
MeshH3 = h1 + h2 + h3
MeshH4 = h1 + h2 + h3 + h4
!!! 3rd Order Mesh Coef
MeshCoef0 = -1.0*( MeshH2*MeshH3*MeshH4 + MeshH1*MeshH3*MeshH4 + &
MeshH1*MeshH2*MeshH4 + MeshH1*MeshH2*MeshH3)/&
(MeshH1*MeshH2*MeshH3*MeshH4)
MeshCoef1 = 1.0*( MeshH2*MeshH3*MeshH4)/(h1*h2*(h2 + h3)*(h2 + h3 + h4))
MeshCoef2 = -1.0*( MeshH1*MeshH3*MeshH4)/(MeshH2*h2*h3*(h3+h4))
MeshCoef3 = 1.0*( MeshH1*MeshH2*MeshH4)/(MeshH3*(h3+h2)*h3*h4)
MeshCoef4 = -1.0*( MeshH1*MeshH2*MeshH3)/(MeshH4*(h2+h3+h4)*(h3+h4)*h4)
do iSpecies = 1, nSpecies
dLogNS = MeshCoef0*LogNS(iAlt+1,iSpecies) + &
MeshCoef1*LogNS(iAlt+2,iSpecies) + &
MeshCoef2*LogNS(iAlt+3,iSpecies) + &
MeshCoef3*LogNS(iAlt+4,iSpecies) + &
MeshCoef4*LogNS(iAlt+5,iSpecies)
LogNS(iAlt,iSpecies) = LogNS(iAlt+1,iSpecies)&
- dAlt_F(iAlt+1)*dLogNS
enddo
! Let iO_ Be Photochemical
! Ion Lower Boundaries
! do iAlt = 0,-1,-1
!
! h1 = dAlt_F(iAlt+2) ! dAlt_F(1) = Alt(1) - Alt(0); h1 in notes
! h2 = dAlt_F(iAlt+3) ! dAlt_F(2) = Alt(2) - Alt(1); h2 in notes
! h3 = dAlt_F(iAlt+4) ! dAlt_F(3) = Alt(3) - Alt(2); h3 in notes
! h4 = dAlt_F(iAlt+5) ! dAlt_F(4) = Alt(4) - Alt(3); h4 in notes
!
! ! Mesh Coefficients are summations over the individual mesh scales
! MeshH1 = h1
! MeshH2 = h1 + h2
! MeshH3 = h1 + h2 + h3
! MeshH4 = h1 + h2 + h3 + h4
!
! !!! 3rd Order Mesh Coef
! MeshCoef0 = -1.0*( MeshH2*MeshH3*MeshH4 + MeshH1*MeshH3*MeshH4 + &
! MeshH1*MeshH2*MeshH4 + MeshH1*MeshH2*MeshH3)/&
! (MeshH1*MeshH2*MeshH3*MeshH4)
! MeshCoef1 = 1.0*( MeshH2*MeshH3*MeshH4)/(h1*h2*(h2 + h3)*(h2 + h3 + h4))
! MeshCoef2 = -1.0*( MeshH1*MeshH3*MeshH4)/(MeshH2*h2*h3*(h3+h4))
! MeshCoef3 = 1.0*( MeshH1*MeshH2*MeshH4)/(MeshH3*(h3+h2)*h3*h4)
! MeshCoef4 = -1.0*( MeshH1*MeshH2*MeshH3)/(MeshH4*(h2+h3+h4)*(h3+h4)*h4)
!
! ! Ions Float at the LBC
! iSpecies = iO_
! dLogNS = MeshCoef0*LogNS(iAlt+1,iSpecies) + & ! LogNS(0)
! MeshCoef1*LogNS(iAlt+2,iSpecies) + & ! LogNS(1)
! MeshCoef2*LogNS(iAlt+3,iSpecies) + & ! LogNS(2)
! MeshCoef3*LogNS(iAlt+4,iSpecies) + & ! LogNS(2)
! MeshCoef4*LogNS(iAlt+5,iSpecies) ! LogNS(2)
!
! ! Make sure that the ions decrease in the ghost cells!
! if (dLogNS .gt. 0.0) then
! LogNS(iAlt,iSpecies) = LogNS(iAlt+1,iSpecies)&
! - dAlt_F(iAlt+1)*dLogNS
! else
! LogNS(iAlt,iSpecies) = LogNS(iAlt+1,iSpecies)
! endif
! enddo !iAlt = 0,-1,-1
! Ion Lower Boundaries
do iAlt = 0,-1,-1
h1 = dAlt_F(iAlt+2) ! dAlt_F(1) = Alt(1) - Alt(0); h1 in notes
h2 = dAlt_F(iAlt+3) ! dAlt_F(2) = Alt(2) - Alt(1); h2 in notes
h3 = dAlt_F(iAlt+4) ! dAlt_F(3) = Alt(3) - Alt(2); h3 in notes
h4 = dAlt_F(iAlt+5) ! dAlt_F(4) = Alt(4) - Alt(3); h4 in notes
! Mesh Coefficients are summations over the individual mesh scales
MeshH1 = h1
MeshH2 = h1 + h2
MeshH3 = h1 + h2 + h3
MeshH4 = h1 + h2 + h3 + h4
!!! 3rd Order Mesh Coef
MeshCoef0 = -1.0*( MeshH2*MeshH3*MeshH4 + MeshH1*MeshH3*MeshH4 + &
MeshH1*MeshH2*MeshH4 + MeshH1*MeshH2*MeshH3)/&
(MeshH1*MeshH2*MeshH3*MeshH4)
MeshCoef1 = 1.0*( MeshH2*MeshH3*MeshH4)/(h1*h2*(h2 + h3)*(h2 + h3 + h4))
MeshCoef2 = -1.0*( MeshH1*MeshH3*MeshH4)/(MeshH2*h2*h3*(h3+h4))
MeshCoef3 = 1.0*( MeshH1*MeshH2*MeshH4)/(MeshH3*(h3+h2)*h3*h4)
MeshCoef4 = -1.0*( MeshH1*MeshH2*MeshH3)/(MeshH4*(h2+h3+h4)*(h3+h4)*h4)
! Ions Float at the LBC
do iSpecies = 1, nIonsAdvect
dLogINS = MeshCoef0*LogINS(iAlt+1,iSpecies) + & ! LogNS(0)
MeshCoef1*LogINS(iAlt+2,iSpecies) + & ! LogNS(1)
MeshCoef2*LogINS(iAlt+3,iSpecies) + & ! LogNS(2)
MeshCoef3*LogINS(iAlt+4,iSpecies) + & ! LogNS(2)
MeshCoef4*LogINS(iAlt+5,iSpecies) ! LogNS(2)
! Make sure that the ions decrease in the ghost cells!
if (dLogINS .gt. 0.0) then
LogINS(iAlt,iSpecies) = LogINS(iAlt+1,iSpecies)&
- dAlt_F(iAlt+1)*dLogINS
else
LogINS(iAlt,iSpecies) = LogINS(iAlt+1,iSpecies)
endif
enddo ! Ions Advect
do iSpecies = 1, nSpecies
! For Photochemical Species
! We enforce zero flux at the LBC
dVertVel = VertVel(iAlt+1,iSpecies)*MeshCoef0 + &
VertVel(iAlt+2,iSpecies)*MeshCoef1 + &
VertVel(iAlt+3,iSpecies)*MeshCoef2 + &
VertVel(iAlt+4,iSpecies)*MeshCoef3 + &
VertVel(iAlt+5,iSpecies)*MeshCoef4
VertVel(iAlt ,iSpecies) = VertVel(iAlt+1,iSpecies) - &
dAlt_F(iAlt+1)*dVertVel
enddo ! nSpecies
! Set the Bulk Winds
Vel_GD(iAlt,iUp_) = 0.0
do iSpecies = 1, nSpecies
Vel_GD(iAlt,iUp_) = Vel_GD(iAlt,iUp_) + &
NS(iAlt,iSpecies)*Mass(iSpecies)*&
VertVel(iAlt,iSpecies)/exp(LogRho(iAlt))
enddo
! Set the Ion Bulk Winds
do iDir = 1, 3
dVertVel = IVel(iAlt+1,iDir)*MeshCoef0 + &
IVel(iAlt+2,iDir)*MeshCoef1 + &
IVel(iAlt+3,iDir)*MeshCoef2 + &
IVel(iAlt+4,iDir)*MeshCoef3 + &
IVel(iAlt+5,iDir)*MeshCoef4
IVel(iAlt ,iDir) = IVel(iAlt+1,iDir) - &
dAlt_F(iAlt+1)*dVertVel
enddo ! iDir
enddo ! End Outer IAlt Loop (0, -1, -1)
!-----------------------------------------------------------
! Top
!-----------------------------------------------------------
! Slip flow at the top
Vel_GD(nAlts+1:nAlts+2,iEast_) = Vel_GD(nAlts,iEast_)
Vel_GD(nAlts+1:nAlts+2,iNorth_) = Vel_GD(nAlts,iNorth_)
IVel(nAlts+1:nAlts+2,iEast_) = IVel(nAlts,iEast_)
IVel(nAlts+1:nAlts+2,iNorth_) = IVel(nAlts,iNorth_)
! Things can go up or down in the ions
IVel(nAlts+1,iUp_) = IVel(nAlts,iUp_)
IVel(nAlts+2,iUp_) = IVel(nAlts-1,iUp_)
! We only let stuff flow out in the neutrals
if(Vel_GD(nAlts,iUp_)>0.)then
Vel_GD(nAlts+1:nAlts+2,iUp_) = Vel_GD(nAlts,iUp_)
VertVel(nAlts+1,:) = VertVel(nAlts,:)
VertVel(nAlts+2,:) = VertVel(nAlts,:)
else
! Vel_GD(nAlts+1:nAlts+2,iUp_) = 0.0 ! -Vel(nAlts)
Vel_GD(nAlts+1,iUp_) = -Vel_GD(nAlts,iUp_)
Vel_GD(nAlts+2,iUp_) = -Vel_GD(nAlts-1,iUp_)
VertVel(nAlts+1,:) = -VertVel(nAlts,:)
VertVel(nAlts+2,:) = -VertVel(nAlts-1,:)
endif
! Constant temperature (zero gradient)
Temp(nAlts+1) = Temp(nAlts)
Temp(nAlts+2) = Temp(nAlts)
dn = (LogRho(nAlts) - LogRho(nAlts-1))
LogRho(nAlts+1) = LogRho(nAlts) + dn
LogRho(nAlts+2) = LogRho(nAlts+1) + dn
! Limit the slope of the ion density
do iSpecies=1,nIonsAdvect
dn = (LogINS(nAlts,iSpecies) - LogINS(nAlts-1,iSpecies))
! if (dn < 0.75*LogINS(nAlts,iSpecies) .and. dn > 0) &
! dn = 0.75*LogINS(nAlts,iSpecies)
if (dn > 0) dn = -0.1*LogINS(nAlts,iSpecies)
LogINS(nAlts+1,iSpecies) = LogINS(nAlts,iSpecies) + dn
LogINS(nAlts+2,iSpecies) = LogINS(nAlts+1,iSpecies) + dn
enddo
! Hydrostatic pressure for the neutrals
!do iSpecies=1,nSpecies
! do iAlt = nAlts+1, nAlts+2
!
! InvScaleHeightS = -Gravity_G(iAlt) * &
! Mass(iSpecies) / (Temp(iAlt)*Boltzmanns_Constant)
! LogNS(iAlt,iSpecies) = &
! LogNS(iAlt-1,iSpecies) - dAlt_F(iAlt)*InvScaleHeightS
! if (LogNS(nAlts+1,iSpecies) > 75.0 .or. &
! LogNS(nAlts+2,iSpecies) > 75.0) then
! write(*,*) "======> bcs : ", iSpecies, 1.0e-3/InvScaleHeightS, &
! Gravity_G(nAlts), Mass(iSpecies), Temp(nAlts), &
! LogNS(nAlts,iSpecies), LogNS(nAlts+1,iSpecies), &
! dAlt_F(nAlts), LogNS(nAlts+2,iSpecies)
! endif
! enddo
! enddo
do iAlt = nAlts + 1, nAlts + 2
hm1 = dAlt_F(iAlt-1) !
hm2 = dAlt_F(iAlt-2) !
hm3 = dAlt_F(iAlt-3) !
hm4 = dAlt_F(iAlt-4) !
! Mesh Coefficients are summations over the individual mesh scales
MeshHm1 = hm1
MeshHm2 = hm1 + hm2
MeshHm3 = hm1 + hm2 + hm3
MeshHm4 = hm1 + hm2 + hm3 + hm4
!!! 3rd Order Mesh Coef
MeshCoefm0 = 1.0*( MeshHm2*MeshHm3*MeshHm4 + MeshHm1*MeshHm3*MeshHm4 + &
MeshHm1*MeshHm2*MeshHm4 + MeshHm1*MeshHm2*MeshHm3)/&
(MeshHm1*MeshHm2*MeshHm3*MeshHm4)
MeshCoefm1 = -1.0*( MeshHm2*MeshHm3*MeshHm4)/&
(hm1*hm2*(hm2 + hm3)*(hm2 + hm3 + hm4))
MeshCoefm2 = 1.0*( MeshHm1*MeshHm3*MeshHm4)/(MeshHm2*hm2*hm3*(hm3+hm4))
MeshCoefm3 = -1.0*( MeshHm1*MeshHm2*MeshHm4)/(MeshHm3*(hm3+hm2)*hm3*hm4)
MeshCoefm4 = 1.0*( MeshHm1*MeshHm2*MeshHm3)/&
(MeshHm4*(hm2+hm3+hm4)*(hm3+hm4)*hm4)
!
! do iSpecies=1,nIonsAdvect
! dn = MeshCoefm0*LogINS(iAlt-1,iSpecies) + &
! MeshCoefm1*LogINS(iAlt-2,iSpecies) + &
! MeshCoefm2*LogINS(iAlt-3,iSpecies) + &
! MeshCoefm3*LogINS(iAlt-4,iSpecies) + &
! MeshCoefm4*LogINS(iAlt-5,iSpecies)
!
! LogINS(iAlt,iSpecies) = LogINS(iAlt-1,iSpecies) + &
! dn*dAlt_F(iAlt)
! enddo
!
! enddo ! iAlt
dn = MeshCoefm0*LogRho(iAlt-1) + &
MeshCoefm1*LogRho(iAlt-2) + &
MeshCoefm2*LogRho(iAlt-3) + &
MeshCoefm3*LogRho(iAlt-4) + &
MeshCoefm4*LogRho(iAlt-5)
LogRho(iAlt) = LogRho(iAlt-1) + &
dAlt_F(iAlt)*dn
!
! do iSpecies=1,nIonsAdvect
! dn = MeshCoefm0*LogINS(iAlt-1,iSpecies) + &
! MeshCoefm1*LogINS(iAlt-2,iSpecies) + &
! MeshCoefm2*LogINS(iAlt-3,iSpecies) + &
! MeshCoefm3*LogINS(iAlt-4,iSpecies) + &
! MeshCoefm4*LogINS(iAlt-5,iSpecies)
!
!
!! if (dn > -0.25*LogINS(nAlts,iSpecies)/dAlt_F(nAlts)) &
!! dn = -0.25*LogINS(nAlts,iSpecies)/dAlt_F(nAlts)
! LogINS(iAlt,iSpecies) = LogINS(iAlt-1,iSpecies) + &
! dn*dAlt_F(iAlt)
! enddo
!
do iSpecies=1,nSpecies
dn = MeshCoefm0*LogNS(iAlt-1,iSpecies) + &
MeshCoefm1*LogNS(iAlt-2,iSpecies) + &
MeshCoefm2*LogNS(iAlt-3,iSpecies) + &
MeshCoefm3*LogNS(iAlt-4,iSpecies) + &
MeshCoefm4*LogNS(iAlt-5,iSpecies)
LogNS(iAlt,iSpecies) = LogNS(iAlt-1,iSpecies) + &
dn*dAlt_F(iAlt)
enddo
enddo
end subroutine set_vertical_bcs