-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathvertical_solver.MarsDtIn
698 lines (544 loc) · 24.1 KB
/
vertical_solver.MarsDtIn
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
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
! Copyright (C) 2002 Regents of the University of Michigan, portions used with permission
! For more information, see http://csem.engin.umich.edu/tools/swmf
!\
! ------------------------------------------------------------
! advance
! ------------------------------------------------------------
!/
subroutine advance_vertical_1d
use ModVertical
use ModGITM, ONLY : Dt, iCommGITM, iProc, iEast_, iNorth_, iUp_
use ModInputs, only: UseBarriers, iDebugLevel
use ModPlanet, only: iN2_
implicit none
!-----------------------------------------------------------
integer :: iError, iAlt
real :: OrigLogNS(-1:nAlts+2,1:nSpecies)
real :: OrigLogINS(-1:nAlts+2,1:nIonsAdvect)
real :: OrigLogRho(-1:nAlts+2)
real :: OrigVel_GD(-1:nAlts+2,1:3)
real :: OrigTemp(-1:nAlts+2)
real :: OrigVS(-1:nAlts+2,1:nSpecies)
real :: Stage1LogNS(-1:nAlts+2,1:nSpecies)
real :: Stage1LogINS(-1:nAlts+2,1:nIonsAdvect)
real :: Stage1LogRho(-1:nAlts+2)
real :: Stage1Vel_GD(-1:nAlts+2,1:3)
real :: Stage1Temp(-1:nAlts+2)
real :: Stage1VS(-1:nAlts+2,1:nSpecies)
real :: Stage2LogNS(-1:nAlts+2,1:nSpecies)
real :: Stage2LogINS(-1:nAlts+2,1:nIonsAdvect)
real :: Stage2LogRho(-1:nAlts+2)
real :: Stage2Vel_GD(-1:nAlts+2,1:3)
real :: Stage2Temp(-1:nAlts+2)
real :: Stage2VS(-1:nAlts+2,1:nSpecies)
real :: Stage3LogNS(-1:nAlts+2,1:nSpecies)
real :: Stage3LogINS(-1:nAlts+2,1:nIonsAdvect)
real :: Stage3LogRho(-1:nAlts+2)
real :: Stage3Vel_GD(-1:nAlts+2,1:3)
real :: Stage3Temp(-1:nAlts+2)
real :: Stage3VS(-1:nAlts+2,1:nSpecies)
real :: FinalLogNS(-1:nAlts+2,1:nSpecies)
real :: FinalLogINS(-1:nAlts+2,1:nIonsAdvect)
real :: FinalLogRho(-1:nAlts+2)
real :: FinalVel_GD(-1:nAlts+2,1:3)
real :: FinalTemp(-1:nAlts+2)
real :: FinalVS(-1:nAlts+2,1:nSpecies)
real :: DtIn
if (UseBarriers) call MPI_BARRIER(iCommGITM,iError)
if (iDebugLevel > 6) write(*,*) "=======> vertical bcs 1", iproc
call set_vertical_bcs(LogRho,LogNS,Vel_GD,Temp,LogINS,IVel,VertVel)
!!! Set the Original State
OrigLogNS(-1:nAlts+2,1:nSpecies) = LogNS(-1:nAlts+2,1:nSpecies)
OrigLogINS(-1:nAlts+2,1:nIonsAdvect) = LogINS(-1:nAlts+2,1:nIonsAdvect)
OrigLogRho(-1:nAlts+2) = LogRho(-1:nAlts+2)
OrigVel_GD(-1:nAlts+2,1:3) = Vel_GD(-1:nAlts+2,1:3)
OrigTemp(-1:nAlts+2) = Temp(-1:nAlts+2)
OrigVS(-1:nAlts+2,1:nSpecies) = VertVel(-1:nAlts+2,1:nSpecies)
NewLogNS = LogNS
NewLogINS = LogINS
NewLogRho = LogRho
NewVel_GD = Vel_GD
NewTemp = Temp
NewVertVel = VertVel
DtIn = Dt/2.0
call advance_vertical_1stage(DtIn,&
LogRho, LogNS, Vel_GD, Temp, NewLogRho, NewLogNS, NewVel_GD, NewTemp, &
LogINS, NewLogINS, IVel, VertVel, NewVertVel)
if (UseBarriers) call MPI_BARRIER(iCommGITM,iError)
if (iDebugLevel > 7) write(*,*) "========> vertical bcs 3", iproc
!!! Set the Updated State: Stage 1
Stage1LogNS(1:nAlts,1:nSpecies) = OrigLogNS(1:nAlts,1:nSpecies) + &
(NewLogNS(1:nAlts,1:nSpecies) - LogNS(1:nAlts,1:nSpecies))
Stage1LogINS(1:nAlts,1:nIonsAdvect) = OrigLogINS(1:nAlts,1:nIonsAdvect) + &
(NewLogINS(1:nAlts,1:nIonsAdvect) - LogINS(1:nAlts,1:nIonsAdvect))
Stage1LogRho(1:nAlts) = OrigLogRho(1:nAlts) + (NewLogRho(1:nAlts) - LogRho(1:nAlts))
Stage1Vel_GD(1:nAlts,1:3) = OrigVel_GD(1:nAlts,1:3) + (NewVel_GD(1:nAlts,1:3) - Vel_GD(1:nAlts,1:3))
Stage1Temp(1:nAlts) = OrigTemp(1:nAlts) + (NewTemp(1:nAlts) - Temp(1:nAlts))
Stage1VS(1:nAlts,1:nSpecies) = OrigVS(1:nAlts,1:nSpecies) + &
(NewVertVel(1:nAlts,1:nSpecies) - VertVel(1:nAlts,1:nSpecies))
!!! Fill Bottom Cells with the Original State
Stage1LogNS(-1:0,1:nSpecies) = OrigLogNS(-1:0,1:nSpecies)
Stage1LogINS(-1:0,1:nIonsAdvect) = OrigLogINS(-1:0,1:nIonsAdvect)
Stage1LogRho(-1:0) = OrigLogRho(-1:0)
Stage1Vel_GD(-1:0,1:3) = OrigVel_GD(-1:0,1:3)
Stage1Temp(-1:0) = OrigTemp(-1:0)
Stage1VS(-1:0,1:nSpecies) = OrigVS(-1:0,1:nSpecies)
!!! UpdateStage 1 Upper Boundary
call set_vertical_bcs(Stage1LogRho, Stage1LogNS, Stage1Vel_GD, Stage1Temp, Stage1LogINS, IVel, Stage1VS)
LogNS = Stage1LogNS
LogINS = Stage1LogINS
LogRho = Stage1LogRho
Vel_GD = Stage1Vel_GD
Temp = Stage1Temp
VertVel = Stage1VS
NewLogNS = LogNS
NewLogINS = LogINS
NewLogRho = LogRho
NewVel_GD = Vel_GD
NewTemp = Temp
NewVertVel = VertVel
DtIn = Dt/2.0
call advance_vertical_1stage(DtIn,&
LogRho, LogNS, Vel_GD, Temp, NewLogRho, NewLogNS, NewVel_GD, NewTemp, &
LogINS, NewLogINS, IVel, VertVel, NewVertVel)
!!! Set the Updated State: Stage 2
Stage2LogNS(1:nAlts,1:nSpecies) = OrigLogNS(1:nAlts,1:nSpecies) + &
(NewLogNS(1:nAlts,1:nSpecies) - LogNS(1:nAlts,1:nSpecies))
Stage2LogINS(1:nAlts,1:nIonsAdvect) = OrigLogINS(1:nAlts,1:nIonsAdvect) + &
(NewLogINS(1:nAlts,1:nIonsAdvect) - LogINS(1:nAlts,1:nIonsAdvect))
Stage2LogRho(1:nAlts) = OrigLogRho(1:nAlts) + (NewLogRho(1:nAlts) - LogRho(1:nAlts))
Stage2Vel_GD(1:nAlts,1:3) = OrigVel_GD(1:nAlts,1:3) + (NewVel_GD(1:nAlts,1:3) - Vel_GD(1:nAlts,1:3))
Stage2Temp(1:nAlts) = OrigTemp(1:nAlts) + (NewTemp(1:nAlts) - Temp(1:nAlts))
Stage2VS(1:nAlts,1:nSpecies) = OrigVS(1:nAlts,1:nSpecies) +&
(NewVertVel(1:nAlts,1:nSpecies) - VertVel(1:nAlts,1:nSpecies))
!!! Fill Bottom Cells with the Original State
Stage2LogNS(-1:0,1:nSpecies) = OrigLogNS(-1:0,1:nSpecies)
Stage2LogINS(-1:0,1:nIonsAdvect) = OrigLogINS(-1:0,1:nIonsAdvect)
Stage2LogRho(-1:0) = OrigLogRho(-1:0)
Stage2Vel_GD(-1:0,1:3) = OrigVel_GD(-1:0,1:3)
Stage2Temp(-1:0) = OrigTemp(-1:0)
Stage2VS(-1:0,1:nSpecies) = OrigVS(-1:0,1:nSpecies)
call set_vertical_bcs(Stage2LogRho, Stage2LogNS, Stage2Vel_GD, Stage2Temp, Stage2LogINS, IVel, Stage2VS)
LogNS = Stage2LogNS
LogINS = Stage2LogINS
LogRho = Stage2LogRho
Vel_GD = Stage2Vel_GD
Temp = Stage2Temp
VertVel = Stage2VS
NewLogNS = LogNS
NewLogINS = LogINS
NewLogRho = LogRho
NewVel_GD = Vel_GD
NewTemp = Temp
NewVertVel = VertVel
DtIn = Dt
call advance_vertical_1stage(DtIn,&
LogRho, LogNS, Vel_GD, Temp, NewLogRho, NewLogNS, NewVel_GD, NewTemp, &
LogINS, NewLogINS, IVel, VertVel, NewVertVel)
!!! Set the Updated State: Stage 3
Stage3LogNS(1:nAlts,1:nSpecies) = OrigLogNS(1:nAlts,1:nSpecies) + &
(NewLogNS(1:nAlts,1:nSpecies) - LogNS(1:nAlts,1:nSpecies))
Stage3LogINS(1:nAlts,1:nIonsAdvect) = OrigLogINS(1:nAlts,1:nIonsAdvect) + &
(NewLogINS(1:nAlts,1:nIonsAdvect) - LogINS(1:nAlts,1:nIonsAdvect))
Stage3LogRho(1:nAlts) = OrigLogRho(1:nAlts) + (NewLogRho(1:nAlts) - LogRho(1:nAlts))
Stage3Vel_GD(1:nAlts,1:3) = OrigVel_GD(1:nAlts,1:3) + (NewVel_GD(1:nAlts,1:3) - Vel_GD(1:nAlts,1:3))
Stage3Temp(1:nAlts) = OrigTemp(1:nAlts) + (NewTemp(1:nAlts) - Temp(1:nAlts))
Stage3VS(1:nAlts,1:nSpecies) = OrigVS(1:nAlts,1:nSpecies) +&
(NewVertVel(1:nAlts,1:nSpecies) - VertVel(1:nAlts,1:nSpecies))
!!! Fill Bottom Cells with the Original State
Stage3LogNS(-1:0,1:nSpecies) = OrigLogNS(-1:0,1:nSpecies)
Stage3LogINS(-1:0,1:nIonsAdvect) = OrigLogINS(-1:0,1:nIonsAdvect)
Stage3LogRho(-1:0) = OrigLogRho(-1:0)
Stage3Vel_GD(-1:0,1:3) = OrigVel_GD(-1:0,1:3)
Stage3Temp(-1:0) = OrigTemp(-1:0)
Stage3VS(-1:0,1:nSpecies) = OrigVS(-1:0,1:nSpecies)
!!!! ====== Stage3
call set_vertical_bcs(Stage3LogRho, Stage3LogNS, Stage3Vel_GD, Stage3Temp, Stage3LogINS, IVel, Stage3VS)
LogNS = Stage3LogNS
LogINS = Stage3LogINS
LogRho = Stage3LogRho
Vel_GD = Stage3Vel_GD
Temp = Stage3Temp
VertVel = Stage3VS
NewLogNS = LogNS
NewLogINS = LogINS
NewLogRho = LogRho
NewVel_GD = Vel_GD
NewTemp = Temp
NewVertVel = VertVel
DtIn = Dt/2.0
call advance_vertical_1stage(DtIn,&
LogRho, LogNS, Vel_GD, Temp, NewLogRho, NewLogNS, NewVel_GD, NewTemp, &
LogINS, NewLogINS, IVel, VertVel, NewVertVel)
!!! Set the Updated State: Stage 2
FinalLogNS = (1.0/3.0)*(-1.0*OrigLogNS + 1.0*Stage1LogNS + 2.0*Stage2LogNS + 1.0*Stage3LogNS + (NewLogNS - LogNS) )
FinalLogINS = (1.0/3.0)*(-1.0*OrigLogINS + 1.0*Stage1LogINS + 2.0*Stage2LogINS + 1.0*Stage3LogINS + (NewLogINS - LogINS) )
FinalLogRho = (1.0/3.0)*(-1.0*OrigLogRho + 1.0*Stage1LogRho + 2.0*Stage2LogRho + 1.0*Stage3LogRho + (NewLogRho - LogRho))
FinalVel_GD = (1.0/3.0)*(-1.0*OrigVel_GD + 1.0*Stage1Vel_GD + 2.0*Stage2Vel_GD + 1.0*Stage3Vel_GD + (NewVel_GD - Vel_GD))
FinalTemp = (1.0/3.0)*(-1.0*OrigTemp + 1.0*Stage1Temp + 2.0*Stage2Temp + 1.0*Stage3Temp + (NewTemp - Temp))
FinalVS = (1.0/3.0)*(-1.0*OrigVS + 1.0*Stage1VS + 2.0*Stage2VS + 1.0*Stage3VS + (NewVertVel - VertVel))
!!! Fill Bottom Cells with the Original State
FinalLogNS(-1:0,1:nSpecies) = OrigLogNS(-1:0,1:nSpecies)
FinalLogINS(-1:0,1:nIonsAdvect) = OrigLogINS(-1:0,1:nIonsAdvect)
FinalLogRho(-1:0) = OrigLogRho(-1:0)
FinalVel_GD(-1:0,1:3) = OrigVel_GD(-1:0,1:3)
FinalTemp(-1:0) = OrigTemp(-1:0)
FinalVS(-1:0,1:nSpecies) = OrigVS(-1:0,1:nSpecies)
call set_vertical_bcs(FinalLogRho, FinalLogNS, FinalVel_GD, FinalTemp, FinalLogINS, IVel, FinalVS)
LogNS = FinalLogNS
LogINS = FinalLogINS
LogRho = FinalLogRho
Vel_GD = FinalVel_GD
Temp = FinalTemp
VertVel = FinalVS
end subroutine advance_vertical_1d
!=============================================================================
subroutine advance_vertical_1stage(DtIn, &
LogRho, LogNS, Vel_GD, Temp, NewLogRho, NewLogNS, NewVel_GD, NewTemp, &
LogINS, NewLogINS, IVel, VertVel, NewVertVel)
! With fluxes and sources based on LogRho..Temp, update NewLogRho..NewTemp
use ModGITM, only: &
Dt, iEast_, iNorth_, iUp_
use ModPlanet
use ModSizeGitm
use ModVertical, only : &
Heating, EddyCoef_1d, ViscCoef_1d,Centrifugal, Coriolis, &
MeanMajorMass_1d, Gamma_1d, InvRadialDistance_C, &
Gravity_G, Altitude_G,Cv_1D, dAlt_F
use ModTime
use ModInputs
use ModConstants
use ModSources, only : EddyCondAdia
implicit none
real, intent(in) :: DtIn
real, intent(in) :: LogRho(-1:nAlts+2)
real, intent(in) :: LogNS(-1:nAlts+2,nSpecies)
real, intent(in) :: LogINS(-1:nAlts+2,nIonsAdvect)
real, intent(in) :: Vel_GD(-1:nAlts+2,3)
real, intent(in) :: IVel(-1:nAlts+2,3)
real, intent(in) :: Temp(-1:nAlts+2)
real, intent(in) :: VertVel(-1:nAlts+2,nSpecies)
real, intent(inout) :: NewLogRho(-1:nAlts+2)
real, intent(inout) :: NewLogNS(-1:nAlts+2,nSpecies)
real, intent(inout) :: NewLogINS(-1:nAlts+2,nIonsAdvect)
real, intent(inout) :: NewVel_GD(-1:nAlts+2,3)
real :: NewVel2_G(-1:nAlts+2)
real, intent(inout) :: NewTemp(-1:nAlts+2)
real, intent(inout) :: NewVertVel(-1:nAlts+2,nSpecies)
real :: NS(-1:nAlts+2,nSpecies), Pressure1D(-1:nAlts+2)
real :: Rho(-1:nAlts+2)
real :: LogNum(-1:nAlts+2)
real, dimension(1:nAlts) :: GradLogRho, DivVel, GradTemp, GradTempKoM, &
DiffLogRho, DiffTemp, GradTmp, DiffTmp, DiffLogNum, GradLogNum
real, dimension(1:nAlts,3) :: GradVel_CD, DiffVel_CD
real, dimension(1:nAlts,nSpecies) :: GradLogNS, DiffLogNS, &
GradVertVel, DiffVertVel, DivVertVel
real, dimension(1:nAlts,nIonsAdvect) :: GradLogINS, DiffLogINS
real :: NewSumRho, NewLogSumRho, rat, ed
integer :: iAlt, iSpecies, jSpecies, iDim
real, dimension(-1:nAlts+2) :: NT
real, dimension(-1:nAlts+2) :: Press, LogPress
real, dimension(1:nAlts) :: DiffLogPress, GradLogPress
real, dimension(1:nAlts,nSpecies) :: EddyDiffusionVel
real :: nVel(-1:nAlts+2,1:nSpecies)
integer :: nFilter, iFilter
real :: LowFilter
!! WAVEDRAG Heating Hickey et al [2000]
real, dimension(1:nAlts) :: StressHeating
!\
! Parameters Used for the Sponge
! This Sponge is useful to dampen out spurious modes
! oscillating between the bottom and top of the model.
integer :: nAltsSponge = 12
real :: kSP, NuSP, AmpSP
!! Eddy Diffusion Variables
real, dimension(1:nAlts,nSpecies) :: GradLogConS
real, dimension(-1:nAlts+2,nSpecies) :: ConS, LogConS
real, dimension(1:nAlts,nSpecies) :: EddyCoefRatio_1d
!--------------------------------------------------------------------------
!!! Turbulent Lapse Rate Contribution
real, dimension(-1:nAlts+2) :: LocalEddyHeatFlux
real, dimension(-1:nAlts+2) :: LocalLogEddyHeatFlux
real, dimension(-1:nAlts+2) :: LocalGradLogEddyHeatFlux
!--------------------------------------------------------------------------
! 4th Order Gradients on a Non-Uniform Mesh (5-point Stencil)
!--------------------------------------------------------------------------
real :: h1, h2, h3, h4
real :: MeshH1, MeshH2, MeshH3, MeshH4
real :: MeshCoef0, MeshCoef1, &
MeshCoef2, MeshCoef3, &
MeshCoef4
NS = exp(LogNS)
Rho = exp(LogRho)
LogNum = alog(sum(NS,dim=2))
nFilter = 10
NT(-1:nAlts+2) = exp(LogNum(-1:nAlts+2))
do iAlt = -1, nAlts + 2
Press(iAlt) = NT(iAlt)*Boltzmanns_Constant*Temp(iAlt)
LogPress(iAlt) = alog(Press(iAlt))
enddo
call calc_rusanov_alts(LogPress ,GradLogPress, DiffLogPress)
call calc_rusanov_alts(LogRho ,GradLogRho, DiffLogRho)
call calc_rusanov_alts(LogNum ,GradLogNum, DiffLogNum)
call calc_rusanov_alts(Temp ,GradTemp, DiffTemp)
do iDim = 1, 3
call calc_rusanov_alts(Vel_GD(:,iDim), &
GradVel_CD(:,iDim),DiffVel_CD(:,iDim))
enddo
do iSpecies = 1, nSpecies
LogConS(-1:nAlts+2,iSpecies) = &
alog(Mass(iSpecies)*NS(-1:nAlts+2,iSpecies)/Rho(-1:nAlts+2))
enddo
! Add geometrical correction to gradient and obtain divergence
DivVel = GradVel_CD(:,iUp_) + &
2*Vel_GD(1:nAlts,iUp_)*InvRadialDistance_C(1:nAlts)
do iSpecies=1,nSpecies
call calc_rusanov_alts(LogNS(:,iSpecies),GradTmp, DiffTmp)
GradLogNS(:,iSpecies) = GradTmp
DiffLogNS(:,iSpecies) = DiffTmp
call calc_rusanov_alts(VertVel(:,iSpecies),GradTmp, DiffTmp)
GradVertVel(:,iSpecies) = GradTmp
DiffVertVel(:,iSpecies) = DiffTmp
DivVertVel(:,iSpecies) = GradVertVel(:,iSpecies) + &
2*VertVel(1:nAlts,iSpecies)*InvRadialDistance_C(1:nAlts)
enddo
do iSpecies=1,nIonsAdvect
call calc_rusanov_alts(LogINS(:,iSpecies), GradTmp, DiffTmp)
GradLogINS(:,iSpecies) = GradTmp
DiffLogINS(:,iSpecies) = DiffTmp
enddo
!!! Add the Grad Log Con Variable
if (UseBoquehoAndBlelly) then
do iAlt = 1, nAlts
do iSpecies = 1, nSpecies
GradLogConS(iAlt,iSpecies) = &
-1.0*Gravity_G(iAlt)*&
(1.0 - (MeanMajorMass_1d(iAlt)/Mass(iSpecies)) )
enddo
enddo
else
! do iSpecies=1,nSpecies
! call calc_rusanov_alts(LogConS(:,iSpecies), GradTmp, DiffTmp)
! GradLogConS(:,iSpecies) = GradTmp
! enddo
do iAlt = 1, nAlts
h1 = dAlt_F(iAlt-1)
h2 = dAlt_F(iAlt+0)
h3 = dAlt_F(iAlt+1)
h4 = dAlt_F(iAlt+2)
MeshH2 = h2 + h1
MeshH3 = h3 + h2 + h1
MeshH4 = h4 + h3 + h2 + h1
MeshCoef0 = (h2*h3*(h3+h4))/(h1*MeshH2*MeshH3*MeshH4)
MeshCoef1 = -1.0*(MeshH2*h3*(h3 + h4))/(h1*h2*(h2+h3)*(h2+h3+h4))
MeshCoef3 = MeshH2*h2*(h4 + h3)/(MeshH3*(h2+h3)*h3*h4)
MeshCoef4 = -1.0*MeshH2*h2*h3/(MeshH4*(h2+h3+h4)*(h3+h4)*h4)
MeshCoef2 = (h2*h3*(h3+h4) + &
MeshH2*h3*(h3+h4) - &
MeshH2*h2*(h3+h4) - &
MeshH2*h2*h3)/&
(MeshH2*h2*h3*(h3+h4))
do iSpecies = 1, nSpecies
GradLogConS(iAlt,iSpecies) = &
MeshCoef0*LogConS(iAlt-2,iSpecies)&
+ MeshCoef1*LogConS(iAlt-1,iSpecies)&
+ MeshCoef2*LogConS(iAlt ,iSpecies)&
+ MeshCoef3*LogConS(iAlt+1,iSpecies)&
+ MeshCoef4*LogConS(iAlt+2,iSpecies)
enddo
enddo
endif
AmpSP = (1.0/(10.0*DtIn))
kSP = nAltsSponge + 1
do iAlt = 1,nAlts
NewLogRho(iAlt) = LogRho(iAlt) - DtIn * &
(DivVel(iAlt) + Vel_GD(iAlt,iUp_) * GradLogRho(iAlt) ) &
+ DtIn * DiffLogRho(iAlt)
do iSpecies=1,nSpecies
NewLogNS(iAlt,iSpecies) = LogNS(iAlt,iSpecies) - DtIn * &
(DivVertVel(iAlt,iSpecies) + &
VertVel(iAlt,iSpecies) * GradLogNS(iAlt,iSpecies) ) + &
DtIn * DiffLogNS(iAlt,iSpecies)
enddo
do iSpecies=1,nIonsAdvect
NewLogINS(iAlt,iSpecies) = LogINS(iAlt,iSpecies) - DtIn * &
(IVel(iAlt,iUp_) * GradLogINS(iAlt,iSpecies) ) &
+ DtIn * DiffLogINS(iAlt,iSpecies)
enddo
! ! dVr/dt = -[ (V grad V)_r + grad T + T grad ln Rho - g ]
! ! and V grad V contains the centripetal acceleration
! ! (Vphi**2+Vtheta**2)/R
! NewVel_GD(iAlt,iUp_) = NewVel_GD(iAlt,iUp_) - DtIn * &
! (Vel_GD(iAlt,iUp_)*GradVel_CD(iAlt,iUp_) &
! - (Vel_GD(iAlt,iNorth_)**2 + Vel_GD(iAlt,iEast_)**2) &
! * InvRadialDistance_C(iAlt) &
! - Gravity_G(iAlt)) &
! + DtIn * DiffVel_CD(iAlt,iUp_)
NewVel_GD(iAlt,iUp_) = 0.0
if (iAlt >= (nAlts - nAltsSponge)) then
NuSP = AmpSP*(1.0 - cos( pi*(kSP - (nAlts - iAlt))/kSP) )
else
NuSP = 0.0
endif
if (UseDamping) then
VertTau(iAlt) = &
exp(altitude_G(ialt)/1000.0/20.0)
endif
do iSpecies=1,nSpecies
!The tau term was added as a vertical wind damping term
! Version of vertical velocity with grad(p) and g here :
NewVertVel(iAlt, iSpecies) = VertVel(iAlt, iSpecies) - DtIn * &
(VertVel(iAlt,iSpecies)*GradVertVel(iAlt,iSpecies) &
- (Vel_GD(iAlt,iNorth_)**2 + Vel_GD(iAlt,iEast_)**2) &
* InvRadialDistance_C(iAlt) + &
Temp(iAlt)*GradLogNS(iAlt,iSpecies) * Boltzmanns_Constant / &
Mass(iSpecies) + &
GradTemp(iAlt) * Boltzmanns_Constant / Mass(iSpecies) &
- Gravity_G(iAlt)) &
+ DtIn * DiffVertVel(iAlt,iSpecies) - VertVel(ialt,iSpecies)/VertTau(ialt)
if (UseCoriolis) then
NewVertVel(iAlt,ispecies) = NewVertVel(iAlt,ispecies) + DtIn * ( &
Centrifugal / InvRadialDistance_C(iAlt) + &
Coriolis * Vel_GD(iAlt,iEast_))
endif
if (iSpecies .eq. iHe_) then
NewVertVel(iAlt, iSpecies) = &
NewVertVel(iAlt, iSpecies) + &
Dt * (0.25)* GradTemp(iAlt)*&
Boltzmanns_Constant/Mass(iHe_)
endif
enddo
enddo
! Both Flags set in the Input File
if (UseNeutralFriction .and. UseNeutralFrictionInSolver) then
nVel(-1:nAlts+2,1:nSpecies) = NewVertVel(-1:nAlts+2,1:nSpecies)
call calc_neutral_friction_dt(DtIn,nVel(1:nAlts,1:nSpecies), &
EddyCoef_1d(1:nAlts), &
NT(1:nAlts), &
NS(1:nAlts,1:nSpecies), &
GradLogConS(1:nAlts,1:nSpecies), &
EddyCoefRatio_1d(1:nAlts,1:nSpecies), &
Temp(1:nAlts), Gravity_G(1:nAlts) )
NewVertVel(1:nAlts,1:nSpecies) = nVel(1:nAlts,1:nSpecies)
endif
NewVel_GD(-1:nAlts+2,iUp_) = 0.0
do iAlt = 1, nAlts
do iSpecies=1,nSpecies
NewVertVel(iAlt, iSpecies) = max(-MaximumVerticalVelocity, &
NewVertVel(iAlt, iSpecies))
NewVertVel(iAlt, iSpecies) = min( MaximumVerticalVelocity, &
NewVertVel(iAlt, iSpecies))
NewVel_GD(iAlt,iUp_) = NewVel_GD(iAlt,iUp_) + &
NewVertVel(iAlt, iSpecies) * &
(Mass(iSpecies) * NS(iAlt,iSpecies) / Rho(iAlt))
enddo
enddo
StressHeating = 0.0
if (UseStressHeating) then
do iAlt = 1, nAlts
StressHeating(iAlt) = ViscCoef_1d(iAlt)* &
( ( (Gamma_1d(iAlt) - 1.0)/ ( NT(iAlt)*Boltzmanns_Constant) ) * &
( &
(4.0/3.0)*GradVel_CD(iAlt,iUp_)**2 + &
GradVel_CD(iAlt,iNorth_)**2 + &
GradVel_CD(iAlt,iEast_)**2 &
) )
enddo
endif
do iAlt = 1, nAlts
! dVphi/dt = - (V grad V)_phi
NewVel_GD(iAlt,iEast_) = Vel_GD(iAlt,iEast_) - DtIn * &
Vel_GD(iAlt,iUp_)*GradVel_CD(iAlt,iEast_) &
+ DtIn * DiffVel_CD(iAlt,iEast_)
! dVtheta/dt = - (V grad V)_theta
NewVel_GD(iAlt,iNorth_) = Vel_GD(iAlt,iNorth_) - DtIn * &
Vel_GD(iAlt,iUp_)*GradVel_CD(iAlt,iNorth_) &
+ DtIn * DiffVel_CD(iAlt,iNorth_)
! dT/dt = -(V.grad T + (gamma - 1) T div V + &
! (gamma - 1) * g * grad (KeH^2 * rho) /rho
! if (UseTurbulentCond) then
! NewTemp(iAlt) = NewTemp(iAlt) - Dt * &
! (Vel_GD(iAlt,iUp_)*GradTemp(iAlt) + &
! (Gamma_1d(iAlt) - 1.0) * Temp(iAlt)*DivVel(iAlt))&
! + Dt * DiffTemp(iAlt)
! else
NewTemp(iAlt) = Temp(iAlt) - DtIn * &
(Vel_GD(iAlt,iUp_)*GradTemp(iAlt) + &
(Gamma_1d(iAlt) - 1.0) * ( &
Temp(iAlt)*DivVel(iAlt))) &
+ DtIn * DiffTemp(iAlt) &
+ DtIn * StressHeating(iAlt)
! NewTemp(iAlt) = NewTemp(iAlt) + &
! DtIn*Vel_GD(iAlt,iUp_)* &
! ( (Gamma_1d(iAlt) - 1.0)/Gamma_1d(iAlt) )*&
! Temp(iAlt)*GradLogPress(iAlt)
end do
do iAlt = 1, nAlts
NewSumRho = sum( Mass(1:nSpecies)*exp(NewLogNS(iAlt,1:nSpecies)) )
NewLogRho(iAlt) = alog(NewSumRho)
enddo
end subroutine advance_vertical_1stage
!\
! ------------------------------------------------------------
! calc_rusanov
! ------------------------------------------------------------
!/
subroutine calc_rusanov_alts(Var, GradVar, DiffVar)
use ModSizeGitm
use ModVertical, only : dAlt_C, cMax
implicit none
real, intent(in) :: Var(-1:nAlts+2)
real, intent(out):: GradVar(1:nAlts), DiffVar(1:nAlts)
real, dimension(1:nAlts+1) :: VarLeft, VarRight, DiffFlux
!------------------------------------------------------------
call calc_facevalues_alts(Var, VarLeft, VarRight)
! Gradient based on averaged Left/Right values
GradVar = 0.5 * &
(VarLeft(2:nAlts+1)+VarRight(2:nAlts+1) - &
VarLeft(1:nAlts)-VarRight(1:nAlts))/dAlt_C
! Rusanov/Lax-Friedrichs diffusive term
DiffFlux = 0.5 * max(cMax(0:nAlts),cMax(1:nAlts+1)) * (VarRight - VarLeft)
DiffVar = (DiffFlux(2:nAlts+1) - DiffFlux(1:nAlts))/dAlt_C
end subroutine calc_rusanov_alts
!\
! ------------------------------------------------------------
! calc_facevalues_alts
! ------------------------------------------------------------
!/
subroutine calc_facevalues_alts(Var, VarLeft, VarRight)
use ModVertical, only: dAlt_F, InvDAlt_F
use ModSizeGITM, only: nAlts
use ModLimiterGitm
implicit none
real, intent(in) :: Var(-1:nAlts+2)
real, intent(out):: VarLeft(1:nAlts+1), VarRight(1:nAlts+1)
real :: dVarUp, dVarDown, dVarLimited(0:nAlts+1)
real, parameter :: Factor1=0.6250000 ! 15/24
real, parameter :: Factor2=0.0416667 ! 1/24
real :: h
integer :: i
do i=1,nAlts
! 4th order scheme for calculating face values
h = InvDAlt_F(i+1)*2.0
dVarUp = h*(Factor1*(Var(i+1)-Var(i) ) - Factor2*(Var(i+2)-Var(i-1)))
h = InvDAlt_F(i)*2.0
dVarDown = h*(Factor1*(Var(i) -Var(i-1)) - Factor2*(Var(i+1)-Var(i-2)))
! ! This is Gabor's scheme
! dVarUp = (Var(i+1) - Var(i)) * InvDAlt_F(i+1)
! dVarDown = (Var(i) - Var(i-1)) * InvDAlt_F(i)
dVarLimited(i) = Limiter_mc(dVarUp, dVarDown)
! write(*,*) dVarUp, dVarDown, dVarLimited(i)
end do
i = 0
dVarUp = (Var(i+1) - Var(i)) * InvDAlt_F(i+1)
dVarDown = (Var(i) - Var(i-1)) * InvDAlt_F(i)
dVarLimited(i) = Limiter_mc(dVarUp, dVarDown)
i = nAlts+1
dVarUp = (Var(i+1) - Var(i)) * InvDAlt_F(i+1)
dVarDown = (Var(i) - Var(i-1)) * InvDAlt_F(i)
dVarLimited(i) = Limiter_mc(dVarUp, dVarDown)
do i=1,nAlts+1
VarLeft(i) = Var(i-1) + 0.5*dVarLimited(i-1) * dAlt_F(i)
VarRight(i) = Var(i) - 0.5*dVarLimited(i) * dAlt_F(i)
end do
end subroutine calc_facevalues_alts