-
Notifications
You must be signed in to change notification settings - Fork 0
/
velo.f90
3370 lines (2855 loc) · 120 KB
/
velo.f90
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
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
MODULE VELO
! Module computes the velocity flux terms, baroclinic torque correction terms, and performs the CFL Check
USE PRECISION_PARAMETERS
USE GLOBAL_CONSTANTS
USE MESH_POINTERS
USE COMP_FUNCTIONS, ONLY: SECOND
IMPLICIT NONE
PRIVATE
CHARACTER(255), PARAMETER :: veloid='$Id: velo.f90 9960 2012-02-01 21:02:15Z randy.mcdermott $'
CHARACTER(255), PARAMETER :: velorev='$Revision: 9960 $'
CHARACTER(255), PARAMETER :: velodate='$Date: 2012-02-01 13:02:15 -0800 (Wed, 01 Feb 2012) $'
PUBLIC COMPUTE_VELOCITY_FLUX,VELOCITY_PREDICTOR,VELOCITY_CORRECTOR,NO_FLUX,GET_REV_velo, &
MATCH_VELOCITY,VELOCITY_BC,CHECK_STABILITY
PRIVATE VELOCITY_FLUX,VELOCITY_FLUX_CYLINDRICAL
CONTAINS
SUBROUTINE COMPUTE_VELOCITY_FLUX(T,NM,FUNCTION_CODE)
REAL(EB), INTENT(IN) :: T
REAL(EB) :: TNOW
INTEGER, INTENT(IN) :: NM,FUNCTION_CODE
IF (SOLID_PHASE_ONLY .OR. FREEZE_VELOCITY) RETURN
TNOW = SECOND()
SELECT CASE(FUNCTION_CODE)
CASE(1)
CALL COMPUTE_VISCOSITY(NM)
CASE(2)
CALL VISCOSITY_BC(NM)
IF (.NOT.CYLINDRICAL) CALL VELOCITY_FLUX(T,NM)
IF ( CYLINDRICAL) CALL VELOCITY_FLUX_CYLINDRICAL(T,NM)
END SELECT
TUSED(4,NM) = TUSED(4,NM) + SECOND() - TNOW
END SUBROUTINE COMPUTE_VELOCITY_FLUX
SUBROUTINE COMPUTE_VISCOSITY(NM)
USE PHYSICAL_FUNCTIONS, ONLY: GET_VISCOSITY
USE TURBULENCE, ONLY: VARDEN_DYNSMAG,TEST_FILTER,EX2G3D
INTEGER, INTENT(IN) :: NM
REAL(EB) :: ZZ_GET(0:N_TRACKED_SPECIES),NU_EDDY,DELTA,KSGS,NU_G,GRAD_RHO(3),U2,V2,W2,AA,A_IJ(3,3),BB,B_IJ(3,3),&
DUDX,DUDY,DUDZ,DVDX,DVDY,DVDZ,DWDX,DWDY,DWDZ,MU_DNS
INTEGER :: I,J,K,IIG,JJG,KKG,II,JJ,KK,IW,TURB_MODEL_TMP,IOR
REAL(EB), POINTER, DIMENSION(:,:,:) :: RHOP=>NULL(),UP=>NULL(),VP=>NULL(),WP=>NULL(), &
UP_HAT=>NULL(),VP_HAT=>NULL(),WP_HAT=>NULL(), &
UU=>NULL(),VV=>NULL(),WW=>NULL()
REAL(EB), POINTER, DIMENSION(:,:,:,:) :: ZZP=>NULL()
TYPE(WALL_TYPE), POINTER :: WC=>NULL()
CALL POINT_TO_MESH(NM)
IF (PREDICTOR) THEN
RHOP => RHO
UU => U
VV => V
WW => W
IF (N_TRACKED_SPECIES > 0) ZZP => ZZ
ELSE
RHOP => RHOS
UU => US
VV => VS
WW => WS
IF (N_TRACKED_SPECIES > 0 .AND. .NOT.EVACUATION_ONLY(NM)) ZZP => ZZS
ENDIF
! Compute viscosity for DNS using primitive species/mixture fraction
!$OMP PARALLEL DEFAULT(NONE) &
!$OMP SHARED(N_TRACKED_SPECIES,EVACUATION_ONLY,KBAR,JBAR,IBAR,SOLID,CELL_INDEX,ZZP,MU,TMP, &
!$OMP LES,NM,C_SMAGORINSKY,TWO_D,DX,DY,DZ,RDX,RDY,RDZ,UU,VV,WW,RHOP,CSD2, &
!$OMP N_EXTERNAL_WALL_CELLS,N_INTERNAL_WALL_CELLS,KRES, &
!$OMP IBP1,JBP1,KBP1,TURB_MODEL_TMP,TURB_MODEL,PREDICTOR,STRAIN_RATE,UP,VP,WP,WORK1,WORK2,WORK3,WC,WALL,U_GHOST,V_GHOST, &
!$OMP W_GHOST,UP_HAT,VP_HAT,WP_HAT,WORK4,WORK5,WORK6,DELTA,KSGS,NU_EDDY,C_DEARDORFF,DUDX,DVDY,DWDZ,DUDY,DUDZ,DVDX,DVDZ, &
!$OMP DWDX,DWDY,II,JJ,KK,A_IJ,AA,B_IJ,BB,C_VREMAN,GRAV_VISC,GRAD_RHO,NU_G,C_G,GVEC,IOR,MU_DNS) &
!$OMP PRIVATE(ZZ_GET)
IF (N_TRACKED_SPECIES>0 .AND. EVACUATION_ONLY(NM)) ZZ_GET(1:N_TRACKED_SPECIES) = 0._EB
!$OMP DO COLLAPSE(3) SCHEDULE(STATIC) &
!$OMP PRIVATE(K,J,I)
DO K=1,KBAR
DO J=1,JBAR
DO I=1,IBAR
IF (SOLID(CELL_INDEX(I,J,K))) CYCLE
IF (N_TRACKED_SPECIES>0 .AND. .NOT.EVACUATION_ONLY(NM)) ZZ_GET(1:N_TRACKED_SPECIES) = ZZP(I,J,K,1:N_TRACKED_SPECIES)
CALL GET_VISCOSITY(ZZ_GET,MU(I,J,K),TMP(I,J,K))
ENDDO
ENDDO
ENDDO
!$OMP END DO
TURB_MODEL_TMP = TURB_MODEL
IF (EVACUATION_ONLY(NM)) TURB_MODEL_TMP = CONSMAG
SELECT_TURB: SELECT CASE (TURB_MODEL_TMP)
CASE (CONSMAG,DYNSMAG) SELECT_TURB ! Smagorinsky (1963) eddy viscosity
CALL COMPUTE_STRAIN_RATE(NM)
IF (PREDICTOR .AND. TURB_MODEL_TMP==DYNSMAG) CALL VARDEN_DYNSMAG(NM) ! dynamic procedure, Moin et al. (1991)
!$OMP DO COLLAPSE(3) SCHEDULE(STATIC) &
!$OMP PRIVATE(K,J,I)
DO K=1,KBAR
DO J=1,JBAR
DO I=1,IBAR
IF (SOLID(CELL_INDEX(I,J,K))) CYCLE
MU(I,J,K) = MU(I,J,K) + RHOP(I,J,K)*CSD2(I,J,K)*STRAIN_RATE(I,J,K)
ENDDO
ENDDO
ENDDO
!$OMP END DO
CASE (DEARDORFF) SELECT_TURB ! Deardorff (1980) eddy viscosity model (current default)
! Velocities relative to the p-cell center
UP => WORK1
VP => WORK2
WP => WORK3
UP=0._EB
VP=0._EB
WP=0._EB
DO K=1,KBAR
DO J=1,JBAR
DO I=1,IBAR
UP(I,J,K) = 0.5_EB*(UU(I,J,K) + UU(I-1,J,K))
VP(I,J,K) = 0.5_EB*(VV(I,J,K) + VV(I,J-1,K))
WP(I,J,K) = 0.5_EB*(WW(I,J,K) + WW(I,J,K-1))
ENDDO
ENDDO
ENDDO
! extrapolate to ghost cells
CALL EX2G3D(UP,-1.E10_EB,1.E10_EB)
CALL EX2G3D(VP,-1.E10_EB,1.E10_EB)
CALL EX2G3D(WP,-1.E10_EB,1.E10_EB)
DO IW=1,N_EXTERNAL_WALL_CELLS
WC=>WALL(IW)
IF (WC%BOUNDARY_TYPE/=INTERPOLATED_BOUNDARY) CYCLE
II = WC%II
JJ = WC%JJ
KK = WC%KK
UP(II,JJ,KK) = U_GHOST(IW)
VP(II,JJ,KK) = V_GHOST(IW)
WP(II,JJ,KK) = W_GHOST(IW)
ENDDO
UP_HAT => WORK4
VP_HAT => WORK5
WP_HAT => WORK6
UP_HAT=0._EB
VP_HAT=0._EB
WP_HAT=0._EB
CALL TEST_FILTER(UP_HAT,UP,-1.E10_EB,1.E10_EB)
CALL TEST_FILTER(VP_HAT,VP,-1.E10_EB,1.E10_EB)
CALL TEST_FILTER(WP_HAT,WP,-1.E10_EB,1.E10_EB)
DO K=1,KBAR
DO J=1,JBAR
DO I=1,IBAR
IF (SOLID(CELL_INDEX(I,J,K))) CYCLE
IF (TWO_D) THEN
DELTA = MAX(DX(I),DZ(K))
ELSE
DELTA = MAX(DX(I),DY(J),DZ(K))
ENDIF
KSGS = 0.5_EB*( (UP(I,J,K)-UP_HAT(I,J,K))**2 + (VP(I,J,K)-VP_HAT(I,J,K))**2 + (WP(I,J,K)-WP_HAT(I,J,K))**2 )
NU_EDDY = C_DEARDORFF*DELTA*SQRT(KSGS)
MU(I,J,K) = MU(I,J,K) + RHOP(I,J,K)*NU_EDDY
ENDDO
ENDDO
ENDDO
CASE (VREMAN) SELECT_TURB ! Vreman (2004) eddy viscosity model (experimental)
! A. W. Vreman. An eddy-viscosity subgrid-scale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(2,2))**2 + (DZ(K)*A_IJ(3,2))**2
B_IJ(3,3)=(DX(I)*A_IJ(1,3))**2 + (DY(J)*A_IJ(2,3))**2 + (DZ(K)*A_IJ(3,3))**2
B_IJ(1,2)=DX(I)**2*A_IJ(1,1)*A_IJ(1,2) + DY(J)**2*A_IJ(2,1)*A_IJ(2,2) + DZ(K)**2*A_IJ(3,1)*A_IJ(3,2)
B_IJ(1,3)=DX(I)**2*A_IJ(1,1)*A_IJ(1,3) + DY(J)**2*A_IJ(2,1)*A_IJ(2,3) + DZ(K)**2*A_IJ(3,1)*A_IJ(3,3)
B_IJ(2,3)=DX(I)**2*A_IJ(1,2)*A_IJ(1,3) + DY(J)**2*A_IJ(2,2)*A_IJ(2,3) + DZ(K)**2*A_IJ(3,2)*A_IJ(3,3)
BB = B_IJ(1,1)*B_IJ(2,2) - B_IJ(1,2)**2 &
+ B_IJ(1,1)*B_IJ(3,3) - B_IJ(1,3)**2 &
+ B_IJ(2,2)*B_IJ(3,3) - B_IJ(2,3)**2 ! Vreman, Eq. (8)
IF (ABS(AA)>ZERO_P) THEN
NU_EDDY = C_VREMAN*SQRT(BB/AA) ! Vreman, Eq. (5)
ELSE
NU_EDDY=0._EB
ENDIF
MU(I,J,K) = MU(I,J,K) + RHOP(I,J,K)*NU_EDDY
ENDDO
ENDDO
ENDDO
END SELECT SELECT_TURB
! Add viscosity for stably stratified flows (experimental)
GRAVITY_IF: IF (LES .AND. GRAV_VISC) THEN
DO K=1,KBAR
DO J=1,JBAR
DO I=1,IBAR
IF (SOLID(CELL_INDEX(I,J,K))) CYCLE
IF (TWO_D) THEN
DELTA = MAX(DX(I),DZ(K))
ELSE
DELTA = MAX(DX(I),DY(J),DZ(K))
ENDIF
GRAD_RHO(1) = 0.5_EB*RDX(I)*(RHOP(I+1,J,K)-RHOP(I-1,J,K))
GRAD_RHO(2) = 0.5_EB*RDY(J)*(RHOP(I,J+1,K)-RHOP(I,J-1,K))
GRAD_RHO(3) = 0.5_EB*RDZ(K)*(RHOP(I,J,K+1)-RHOP(I,J,K-1))
NU_G = C_G*DELTA**2*SQRT(MAX(ZERO_P,DOT_PRODUCT(GRAD_RHO,GVEC))/RHOP(I,J,K))
MU(I,J,K) = MAX(MU(I,J,K),RHOP(I,J,K)*NU_G)
ENDDO
ENDDO
ENDDO
ENDIF GRAVITY_IF
! Compute resolved kinetic energy per unit mass
!$OMP DO COLLAPSE(3) SCHEDULE(STATIC) PRIVATE(K,J,I,U2,V2,W2)
DO K=1,KBAR
DO J=1,JBAR
DO I=1,IBAR
U2 = 0.25_EB*(UU(I-1,J,K)+UU(I,J,K))**2
V2 = 0.25_EB*(VV(I,J-1,K)+VV(I,J,K))**2
W2 = 0.25_EB*(WW(I,J,K-1)+WW(I,J,K))**2
KRES(I,J,K) = 0.5_EB*(U2+V2+W2)
ENDDO
ENDDO
ENDDO
!$OMP END DO NOWAIT
! Mirror viscosity into solids and exterior boundary cells
!$OMP DO SCHEDULE(STATIC) &
!$OMP PRIVATE(IW,II,JJ,KK,IIG,JJG,KKG)
WALL_LOOP: DO IW=1,N_EXTERNAL_WALL_CELLS+N_INTERNAL_WALL_CELLS
WC=>WALL(IW)
IF (WC%BOUNDARY_TYPE==NULL_BOUNDARY) CYCLE WALL_LOOP
II = WC%II
JJ = WC%JJ
KK = WC%KK
IOR = WC%IOR
IIG = WC%IIG
JJG = WC%JJG
KKG = WC%KKG
SELECT CASE(WC%BOUNDARY_TYPE)
CASE(SOLID_BOUNDARY)
IF (LES) THEN
IF (N_TRACKED_SPECIES>0 .AND. .NOT.EVACUATION_ONLY(NM)) &
ZZ_GET(1:N_TRACKED_SPECIES) = ZZP(IIG,JJG,KKG,1:N_TRACKED_SPECIES)
CALL GET_VISCOSITY(ZZ_GET,MU_DNS,TMP(IIG,JJG,KKG))
SELECT CASE (IOR)
CASE ( 1); MU(IIG,JJG,KKG) = MAX(MU_DNS,ONTH*MU(IIG+1,JJG,KKG))
CASE (-1); MU(IIG,JJG,KKG) = MAX(MU_DNS,ONTH*MU(IIG-1,JJG,KKG))
CASE ( 2); MU(IIG,JJG,KKG) = MAX(MU_DNS,ONTH*MU(IIG,JJG+1,KKG))
CASE (-2); MU(IIG,JJG,KKG) = MAX(MU_DNS,ONTH*MU(IIG,JJG-1,KKG))
CASE ( 3); MU(IIG,JJG,KKG) = MAX(MU_DNS,ONTH*MU(IIG,JJG,KKG+1))
CASE (-3); MU(IIG,JJG,KKG) = MAX(MU_DNS,ONTH*MU(IIG,JJG,KKG-1))
END SELECT
ENDIF
IF (SOLID(CELL_INDEX(II,JJ,KK))) MU(II,JJ,KK) = MU(IIG,JJG,KKG)
CASE(OPEN_BOUNDARY,MIRROR_BOUNDARY)
MU(II,JJ,KK) = MU(IIG,JJG,KKG)
KRES(II,JJ,KK) = KRES(IIG,JJG,KKG)
END SELECT
ENDDO WALL_LOOP
!$OMP END DO
!$OMP WORKSHARE
MU( 0,0:JBP1, 0) = MU( 1,0:JBP1,1)
MU(IBP1,0:JBP1, 0) = MU(IBAR,0:JBP1,1)
MU(IBP1,0:JBP1,KBP1) = MU(IBAR,0:JBP1,KBAR)
MU( 0,0:JBP1,KBP1) = MU( 1,0:JBP1,KBAR)
MU(0:IBP1, 0, 0) = MU(0:IBP1, 1,1)
MU(0:IBP1,JBP1,0) = MU(0:IBP1,JBAR,1)
MU(0:IBP1,JBP1,KBP1) = MU(0:IBP1,JBAR,KBAR)
MU(0:IBP1,0,KBP1) = MU(0:IBP1, 1,KBAR)
MU(0, 0,0:KBP1) = MU( 1, 1,0:KBP1)
MU(IBP1,0,0:KBP1) = MU(IBAR, 1,0:KBP1)
MU(IBP1,JBP1,0:KBP1) = MU(IBAR,JBAR,0:KBP1)
MU(0,JBP1,0:KBP1) = MU( 1,JBAR,0:KBP1)
!$OMP END WORKSHARE
!$OMP END PARALLEL
END SUBROUTINE COMPUTE_VISCOSITY
SUBROUTINE COMPUTE_STRAIN_RATE(NM)
INTEGER, INTENT(IN) :: NM
REAL(EB) :: DUDX,DUDY,DUDZ,DVDX,DVDY,DVDZ,DWDX,DWDY,DWDZ,S11,S22,S33,S12,S13,S23,ONTHDIV
INTEGER :: I,J,K,IOR,IIG,JJG,KKG,IW,SURF_INDEX
REAL(EB), POINTER, DIMENSION(:,:,:) :: UU=>NULL(),VV=>NULL(),WW=>NULL()
TYPE(WALL_TYPE), POINTER :: WC=>NULL()
CALL POINT_TO_MESH(NM)
IF (PREDICTOR) THEN
UU => U
VV => V
WW => W
ELSE
UU => US
VV => VS
WW => WS
ENDIF
DO K=1,KBAR
DO J=1,JBAR
DO I=1,IBAR
IF (SOLID(CELL_INDEX(I,J,K))) CYCLE
DUDX = RDX(I)*(UU(I,J,K)-UU(I-1,J,K))
DVDY = RDY(J)*(VV(I,J,K)-VV(I,J-1,K))
DWDZ = RDZ(K)*(WW(I,J,K)-WW(I,J,K-1))
DUDY = 0.25_EB*RDY(J)*(UU(I,J+1,K)-UU(I,J-1,K)+UU(I-1,J+1,K)-UU(I-1,J-1,K))
DUDZ = 0.25_EB*RDZ(K)*(UU(I,J,K+1)-UU(I,J,K-1)+UU(I-1,J,K+1)-UU(I-1,J,K-1))
DVDX = 0.25_EB*RDX(I)*(VV(I+1,J,K)-VV(I-1,J,K)+VV(I+1,J-1,K)-VV(I-1,J-1,K))
DVDZ = 0.25_EB*RDZ(K)*(VV(I,J,K+1)-VV(I,J,K-1)+VV(I,J-1,K+1)-VV(I,J-1,K-1))
DWDX = 0.25_EB*RDX(I)*(WW(I+1,J,K)-WW(I-1,J,K)+WW(I+1,J,K-1)-WW(I-1,J,K-1))
DWDY = 0.25_EB*RDY(J)*(WW(I,J+1,K)-WW(I,J-1,K)+WW(I,J+1,K-1)-WW(I,J-1,K-1))
ONTHDIV = ONTH*(DUDX+DVDY+DWDZ)
S11 = DUDX - ONTHDIV
S22 = DVDY - ONTHDIV
S33 = DWDZ - ONTHDIV
S12 = 0.5_EB*(DUDY+DVDX)
S13 = 0.5_EB*(DUDZ+DWDX)
S23 = 0.5_EB*(DVDZ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,JJG-1,KKG)+WW(IIG,JJG,KKG-1)+WW(IIG,JJG-1,KKG-1))
CASE(3)
DUDZ = 0.25_EB*RDZ(KKG)*(UU(IIG,JJG,KKG)+UU(IIG,JJG,KKG+1)+UU(IIG-1,JJG,KKG)+UU(IIG-1,JJG,KKG+1))
DVDZ = 0.25_EB*RDZ(KKG)*(VV(IIG,JJG,KKG)+VV(IIG,JJG,KKG+1)+VV(IIG,JJG-1,KKG)+VV(IIG,JJG-1,KKG+1))
CASE(-3)
DUDZ = -0.25_EB*RDZ(KKG)*(UU(IIG,JJG,KKG)+UU(IIG,JJG,KKG-1)+UU(IIG-1,JJG,KKG)+UU(IIG-1,JJG,KKG-1))
DVDZ = -0.25_EB*RDZ(KKG)*(VV(IIG,JJG,KKG)+VV(IIG,JJG,KKG-1)+VV(IIG,JJG-1,KKG)+VV(IIG,JJG-1,KKG-1))
END SELECT
ENDIF FREE_SLIP_IF
S12 = 0.5_EB*(DUDY+DVDX)
S13 = 0.5_EB*(DUDZ+DWDX)
S23 = 0.5_EB*(DVDZ+DWDY)
STRAIN_RATE(IIG,JJG,KKG) = SQRT(2._EB*(S11**2 + S22**2 + S33**2 + 2._EB*(S12**2 + S13**2 + S23**2)))
ENDDO WALL_LOOP
END SUBROUTINE COMPUTE_STRAIN_RATE
SUBROUTINE VISCOSITY_BC(NM)
! Specify ghost cell values of the viscosity array MU
INTEGER, INTENT(IN) :: NM
REAL(EB) :: MU_OTHER,DP_OTHER,KRES_OTHER
INTEGER :: II,JJ,KK,IW,IIO,JJO,KKO,NOM,N_INT_CELLS
TYPE(WALL_TYPE),POINTER :: WC=>NULL()
CALL POINT_TO_MESH(NM)
! Mirror viscosity into solids and exterior boundary cells
!$OMP PARALLEL DO DEFAULT(NONE) SCHEDULE(STATIC) &
!$OMP SHARED(N_EXTERNAL_WALL_CELLS,N_INTERNAL_WALL_CELLS,OMESH,PREDICTOR,MU,KRES,D,DS,WC,WALL) &
!$OMP PRIVATE(IW,II,JJ,KK,NOM,MU_OTHER,DP_OTHER,KRES_OTHER,KKO,JJO,IIO,N_INT_CELLS)
WALL_LOOP: DO IW=1,N_EXTERNAL_WALL_CELLS+N_INTERNAL_WALL_CELLS
WC=>WALL(IW)
IF (WC%NOM==0) CYCLE WALL_LOOP
II = WC%II
JJ = WC%JJ
KK = WC%KK
NOM = WC%NOM
MU_OTHER = 0._EB
DP_OTHER = 0._EB
KRES_OTHER = 0._EB
DO KKO=WC%NOM_IB(3),WC%NOM_IB(6)
DO JJO=WC%NOM_IB(2),WC%NOM_IB(5)
DO IIO=WC%NOM_IB(1),WC%NOM_IB(4)
MU_OTHER = MU_OTHER + OMESH(NOM)%MU(IIO,JJO,KKO)
KRES_OTHER = KRES_OTHER + OMESH(NOM)%KRES(IIO,JJO,KKO)
IF (PREDICTOR) THEN
DP_OTHER = DP_OTHER + OMESH(NOM)%D(IIO,JJO,KKO)
ELSE
DP_OTHER = DP_OTHER + OMESH(NOM)%DS(IIO,JJO,KKO)
ENDIF
ENDDO
ENDDO
ENDDO
N_INT_CELLS = (WC%NOM_IB(4)-WC%NOM_IB(1)+1) * (WC%NOM_IB(5)-WC%NOM_IB(2)+1) * (WC%NOM_IB(6)-WC%NOM_IB(3)+1)
MU_OTHER = MU_OTHER/REAL(N_INT_CELLS,EB)
KRES_OTHER = KRES_OTHER/REAL(N_INT_CELLS,EB)
DP_OTHER = DP_OTHER/REAL(N_INT_CELLS,EB)
MU(II,JJ,KK) = MU_OTHER
KRES(II,JJ,KK) = KRES_OTHER
IF (PREDICTOR) THEN
D(II,JJ,KK) = DP_OTHER
ELSE
DS(II,JJ,KK) = DP_OTHER
ENDIF
ENDDO WALL_LOOP
!$OMP END PARALLEL DO
END SUBROUTINE VISCOSITY_BC
SUBROUTINE VELOCITY_FLUX(T,NM)
! Compute convective and diffusive terms of the momentum equations
USE MATH_FUNCTIONS, ONLY: EVALUATE_RAMP
INTEGER, INTENT(IN) :: NM
REAL(EB) :: T,MUX,MUY,MUZ,UP,UM,VP,VM,WP,WM,VTRM,OMXP,OMXM,OMYP,OMYM,OMZP,OMZM,TXYP,TXYM,TXZP,TXZM,TYZP,TYZM, &
DTXYDY,DTXZDZ,DTYZDZ,DTXYDX,DTXZDX,DTYZDY, &
DUDX,DVDY,DWDZ,DUDY,DUDZ,DVDX,DVDZ,DWDX,DWDY, &
VOMZ,WOMY,UOMY,VOMX,UOMZ,WOMX, &
AH,RRHO,GX(0:IBAR_MAX),GY(0:IBAR_MAX),GZ(0:IBAR_MAX),TXXP,TXXM,TYYP,TYYM,TZZP,TZZM,DTXXDX,DTYYDY,DTZZDZ, &
DUMMY=0._EB, &
INTEGRAL,SUM_VOLUME,DVOLUME,UMEAN,VMEAN,WMEAN,DU_FORCING=0._EB,DV_FORCING=0._EB,DW_FORCING=0._EB
REAL(EB) :: VEG_UMAG
INTEGER :: I,J,K,IEXP,IEXM,IEYP,IEYM,IEZP,IEZM,IC,IC1,IC2
REAL(EB), POINTER, DIMENSION(:,:,:) :: TXY=>NULL(),TXZ=>NULL(),TYZ=>NULL(),OMX=>NULL(),OMY=>NULL(),OMZ=>NULL(), &
UU=>NULL(),VV=>NULL(),WW=>NULL(),RHOP=>NULL(),DP=>NULL()
CALL POINT_TO_MESH(NM)
IF (PREDICTOR) THEN
UU => U
VV => V
WW => W
DP => D
RHOP => RHO
ELSE
UU => US
VV => VS
WW => WS
DP => DS
RHOP => RHOS
ENDIF
TXY => WORK1
TXZ => WORK2
TYZ => WORK3
OMX => WORK4
OMY => WORK5
OMZ => WORK6
!$OMP PARALLEL DEFAULT(NONE) &
!$OMP SHARED(KBAR,JBAR,IBAR,RDXN,RDYN,RDZN,UU,VV,WW,OMX,OMY,OMZ,MU,TXY,TXZ,TYZ, &
!$OMP IMMERSED_BOUNDARY_METHOD,IBM_SAVE1,IBM_SAVE2,IBM_SAVE3,IBM_SAVE4,IBM_SAVE5,IBM_SAVE6, &
!$OMP SPATIAL_GRAVITY_VARIATION,GX,GY,GZ,T,DUMMY,I_RAMP_GX,I_RAMP_GY,I_RAMP_GZ,GVEC,X, &
!$OMP CELL_INDEX,EDGE_INDEX,OME_E,TAU_E,RHOP,RHO_0,RDX,RDY,RDZ,DP,FVEC,FVX,FVY,FVZ, &
!$OMP MEAN_FORCING,SOLID,U_MASK,V_MASK,W_MASK,DX,DY,DZ,DXN,DYN,DZN,INTEGRAL,SUM_VOLUME, &
!$OMP DU_FORCING,DV_FORCING,DW_FORCING,RFAC_FORCING, &
!$OMP U0,V0,W0,UMEAN,VMEAN,WMEAN,DT)
! Compute vorticity and stress tensor components
!$OMP DO COLLAPSE(3) SCHEDULE(STATIC) &
!$OMP PRIVATE(K,J,I,DUDY,DVDX,DUDZ,DWDX,DVDZ,DWDY,MUX,MUY,MUZ)
DO K=0,KBAR
DO J=0,JBAR
DO I=0,IBAR
DUDY = RDYN(J)*(UU(I,J+1,K)-UU(I,J,K))
DVDX = RDXN(I)*(VV(I+1,J,K)-VV(I,J,K))
DUDZ = RDZN(K)*(UU(I,J,K+1)-UU(I,J,K))
DWDX = RDXN(I)*(WW(I+1,J,K)-WW(I,J,K))
DVDZ = RDZN(K)*(VV(I,J,K+1)-VV(I,J,K))
DWDY = RDYN(J)*(WW(I,J+1,K)-WW(I,J,K))
OMX(I,J,K) = DWDY - DVDZ
OMY(I,J,K) = DUDZ - DWDX
OMZ(I,J,K) = DVDX - DUDY
MUX = 0.25_EB*(MU(I,J+1,K)+MU(I,J,K)+MU(I,J,K+1)+MU(I,J+1,K+1))
MUY = 0.25_EB*(MU(I+1,J,K)+MU(I,J,K)+MU(I,J,K+1)+MU(I+1,J,K+1))
MUZ = 0.25_EB*(MU(I+1,J,K)+MU(I,J,K)+MU(I,J+1,K)+MU(I+1,J+1,K))
TXY(I,J,K) = MUZ*(DVDX + DUDY)
TXZ(I,J,K) = MUY*(DUDZ + DWDX)
TYZ(I,J,K) = MUX*(DVDZ + DWDY)
IF (IMMERSED_BOUNDARY_METHOD==2) THEN
IBM_SAVE1(I,J,K) = DUDY
IBM_SAVE2(I,J,K) = DUDZ
IBM_SAVE3(I,J,K) = DVDX
IBM_SAVE4(I,J,K) = DVDZ
IBM_SAVE5(I,J,K) = DWDX
IBM_SAVE6(I,J,K) = DWDY
ENDIF
ENDDO
ENDDO
ENDDO
!$OMP END DO NOWAIT
! Compute gravity components
!$OMP SINGLE PRIVATE(I)
IF (.NOT.SPATIAL_GRAVITY_VARIATION) THEN
GX(0:IBAR) = EVALUATE_RAMP(T,DUMMY,I_RAMP_GX)*GVEC(1)
GY(0:IBAR) = EVALUATE_RAMP(T,DUMMY,I_RAMP_GY)*GVEC(2)
GZ(0:IBAR) = EVALUATE_RAMP(T,DUMMY,I_RAMP_GZ)*GVEC(3)
ELSE
DO I=0,IBAR
GX(I) = EVALUATE_RAMP(X(I),DUMMY,I_RAMP_GX)*GVEC(1)
GY(I) = EVALUATE_RAMP(X(I),DUMMY,I_RAMP_GY)*GVEC(2)
GZ(I) = EVALUATE_RAMP(X(I),DUMMY,I_RAMP_GZ)*GVEC(3)
ENDDO
ENDIF
!$OMP END SINGLE
! Compute x-direction flux term FVX
!$OMP DO COLLAPSE(3) &
!$OMP PRIVATE(K,J,I,WP,WM,VP,VM,OMYP,OMYM,OMZP,OMZM,TXZP,TXZM,TXYP,TXYM,IC,IEYP,IEYM,IEZP,IEZM) &
!$OMP PRIVATE(WOMY,VOMZ,RRHO,AH,DVDY,DWDZ,TXXP,TXXM,DTXXDX,DTXYDY,DTXZDZ,VTRM)
DO K=1,KBAR
DO J=1,JBAR
DO I=0,IBAR
WP = WW(I,J,K) + WW(I+1,J,K)
WM = WW(I,J,K-1) + WW(I+1,J,K-1)
VP = VV(I,J,K) + VV(I+1,J,K)
VM = VV(I,J-1,K) + VV(I+1,J-1,K)
OMYP = OMY(I,J,K)
OMYM = OMY(I,J,K-1)
OMZP = OMZ(I,J,K)
OMZM = OMZ(I,J-1,K)
TXZP = TXZ(I,J,K)
TXZM = TXZ(I,J,K-1)
TXYP = TXY(I,J,K)
TXYM = TXY(I,J-1,K)
IC = CELL_INDEX(I,J,K)
IEYP = EDGE_INDEX(IC,8)
IEYM = EDGE_INDEX(IC,6)
IEZP = EDGE_INDEX(IC,12)
IEZM = EDGE_INDEX(IC,10)
IF (OME_E(IEYP,-1)>-1.E5_EB) OMYP = OME_E(IEYP,-1)
IF (OME_E(IEYM, 1)>-1.E5_EB) OMYM = OME_E(IEYM, 1)
IF (OME_E(IEZP,-2)>-1.E5_EB) OMZP = OME_E(IEZP,-2)
IF (OME_E(IEZM, 2)>-1.E5_EB) OMZM = OME_E(IEZM, 2)
IF (TAU_E(IEYP,-1)>-1.E5_EB) TXZP = TAU_E(IEYP,-1)
IF (TAU_E(IEYM, 1)>-1.E5_EB) TXZM = TAU_E(IEYM, 1)
IF (TAU_E(IEZP,-2)>-1.E5_EB) TXYP = TAU_E(IEZP,-2)
IF (TAU_E(IEZM, 2)>-1.E5_EB) TXYM = TAU_E(IEZM, 2)
WOMY = WP*OMYP + WM*OMYM
VOMZ = VP*OMZP + VM*OMZM
RRHO = 2._EB/(RHOP(I,J,K)+RHOP(I+1,J,K))
AH = RHO_0(K)*RRHO - 1._EB
DVDY = (VV(I+1,J,K)-VV(I+1,J-1,K))*RDY(J)
DWDZ = (WW(I+1,J,K)-WW(I+1,J,K-1))*RDZ(K)
TXXP = MU(I+1,J,K)*( FOTH*DP(I+1,J,K) - 2._EB*(DVDY+DWDZ) )
DVDY = (VV(I,J,K)-VV(I,J-1,K))*RDY(J)
DWDZ = (WW(I,J,K)-WW(I,J,K-1))*RDZ(K)
TXXM = MU(I,J,K) *( FOTH*DP(I,J,K) - 2._EB*(DVDY+DWDZ) )
DTXXDX= RDXN(I)*(TXXP-TXXM)
DTXYDY= RDY(J) *(TXYP-TXYM)
DTXZDZ= RDZ(K) *(TXZP-TXZM)
VTRM = RRHO*(DTXXDX + DTXYDY + DTXZDZ)
FVX(I,J,K) = 0.25_EB*(WOMY - VOMZ) + GX(I)*AH - VTRM - RRHO*FVEC(1)
ENDDO
ENDDO
ENDDO
!$OMP END DO NOWAIT
! Compute y-direction flux term FVY
!$OMP DO COLLAPSE(3) &
!$OMP PRIVATE(K,J,I,UP,UM,WP,WM,OMXP,OMXM,OMZP,OMZM,TYZP,TYZM,TXYP,TXYM,IC,IEXP,IEXM,IEZP,IEZM) &
!$OMP PRIVATE(WOMX,UOMZ,RRHO,AH,DUDX,DWDZ,TYYP,TYYM,DTXYDX,DTYYDY,DTYZDZ,VTRM)
DO K=1,KBAR
DO J=0,JBAR
DO I=1,IBAR
UP = UU(I,J,K) + UU(I,J+1,K)
UM = UU(I-1,J,K) + UU(I-1,J+1,K)
WP = WW(I,J,K) + WW(I,J+1,K)
WM = WW(I,J,K-1) + WW(I,J+1,K-1)
OMXP = OMX(I,J,K)
OMXM = OMX(I,J,K-1)
OMZP = OMZ(I,J,K)
OMZM = OMZ(I-1,J,K)
TYZP = TYZ(I,J,K)
TYZM = TYZ(I,J,K-1)
TXYP = TXY(I,J,K)
TXYM = TXY(I-1,J,K)
IC = CELL_INDEX(I,J,K)
IEXP = EDGE_INDEX(IC,4)
IEXM = EDGE_INDEX(IC,2)
IEZP = EDGE_INDEX(IC,12)
IEZM = EDGE_INDEX(IC,11)
IF (OME_E(IEXP,-2)>-1.E5_EB) OMXP = OME_E(IEXP,-2)
IF (OME_E(IEXM, 2)>-1.E5_EB) OMXM = OME_E(IEXM, 2)
IF (OME_E(IEZP,-1)>-1.E5_EB) OMZP = OME_E(IEZP,-1)
IF (OME_E(IEZM, 1)>-1.E5_EB) OMZM = OME_E(IEZM, 1)
IF (TAU_E(IEXP,-2)>-1.E5_EB) TYZP = TAU_E(IEXP,-2)
IF (TAU_E(IEXM, 2)>-1.E5_EB) TYZM = TAU_E(IEXM, 2)
IF (TAU_E(IEZP,-1)>-1.E5_EB) TXYP = TAU_E(IEZP,-1)
IF (TAU_E(IEZM, 1)>-1.E5_EB) TXYM = TAU_E(IEZM, 1)
WOMX = WP*OMXP + WM*OMXM
UOMZ = UP*OMZP + UM*OMZM
RRHO = 2._EB/(RHOP(I,J,K)+RHOP(I,J+1,K))
AH = RHO_0(K)*RRHO - 1._EB
DUDX = (UU(I,J+1,K)-UU(I-1,J+1,K))*RDX(I)
DWDZ = (WW(I,J+1,K)-WW(I,J+1,K-1))*RDZ(K)
TYYP = MU(I,J+1,K)*( FOTH*DP(I,J+1,K) - 2._EB*(DUDX+DWDZ) )
DUDX = (UU(I,J,K)-UU(I-1,J,K))*RDX(I)
DWDZ = (WW(I,J,K)-WW(I,J,K-1))*RDZ(K)
TYYM = MU(I,J,K) *( FOTH*DP(I,J,K) - 2._EB*(DUDX+DWDZ) )
DTXYDX= RDX(I) *(TXYP-TXYM)
DTYYDY= RDYN(J)*(TYYP-TYYM)
DTYZDZ= RDZ(K) *(TYZP-TYZM)
VTRM = RRHO*(DTXYDX + DTYYDY + DTYZDZ)
FVY(I,J,K) = 0.25_EB*(UOMZ - WOMX) + GY(I)*AH - VTRM - RRHO*FVEC(2)
ENDDO
ENDDO
ENDDO
!$OMP END DO NOWAIT
! Compute z-direction flux term FVZ
!$OMP DO COLLAPSE(3) &
!$OMP PRIVATE(K,J,I,UP,UM,VP,VM,OMYP,OMYM,OMXP,OMXM,TXZP,TXZM,TYZP,TYZM,IC,IEXP,IEXM,IEYP,IEYM) &
!$OMP PRIVATE(UOMY,VOMX,RRHO,AH,DUDX,DVDY,TZZP,TZZM,DTXZDX,DTYZDY,DTZZDZ,VTRM)
DO K=0,KBAR
DO J=1,JBAR
DO I=1,IBAR
UP = UU(I,J,K) + UU(I,J,K+1)
UM = UU(I-1,J,K) + UU(I-1,J,K+1)
VP = VV(I,J,K) + VV(I,J,K+1)
VM = VV(I,J-1,K) + VV(I,J-1,K+1)
OMYP = OMY(I,J,K)
OMYM = OMY(I-1,J,K)
OMXP = OMX(I,J,K)
OMXM = OMX(I,J-1,K)
TXZP = TXZ(I,J,K)
TXZM = TXZ(I-1,J,K)
TYZP = TYZ(I,J,K)
TYZM = TYZ(I,J-1,K)
IC = CELL_INDEX(I,J,K)
IEXP = EDGE_INDEX(IC,4)
IEXM = EDGE_INDEX(IC,3)
IEYP = EDGE_INDEX(IC,8)
IEYM = EDGE_INDEX(IC,7)
IF (OME_E(IEXP,-1)>-1.E5_EB) OMXP = OME_E(IEXP,-1)
IF (OME_E(IEXM, 1)>-1.E5_EB) OMXM = OME_E(IEXM, 1)
IF (OME_E(IEYP,-2)>-1.E5_EB) OMYP = OME_E(IEYP,-2)
IF (OME_E(IEYM, 2)>-1.E5_EB) OMYM = OME_E(IEYM, 2)
IF (TAU_E(IEXP,-1)>-1.E5_EB) TYZP = TAU_E(IEXP,-1)
IF (TAU_E(IEXM, 1)>-1.E5_EB) TYZM = TAU_E(IEXM, 1)
IF (TAU_E(IEYP,-2)>-1.E5_EB) TXZP = TAU_E(IEYP,-2)
IF (TAU_E(IEYM, 2)>-1.E5_EB) TXZM = TAU_E(IEYM, 2)
UOMY = UP*OMYP + UM*OMYM
VOMX = VP*OMXP + VM*OMXM
RRHO = 2._EB/(RHOP(I,J,K)+RHOP(I,J,K+1))
AH = 0.5_EB*(RHO_0(K)+RHO_0(K+1))*RRHO - 1._EB
DUDX = (UU(I,J,K+1)-UU(I-1,J,K+1))*RDX(I)
DVDY = (VV(I,J,K+1)-VV(I,J-1,K+1))*RDY(J)
TZZP = MU(I,J,K+1)*( FOTH*DP(I,J,K+1) - 2._EB*(DUDX+DVDY) )
DUDX = (UU(I,J,K)-UU(I-1,J,K))*RDX(I)
DVDY = (VV(I,J,K)-VV(I,J-1,K))*RDY(J)
TZZM = MU(I,J,K) *( FOTH*DP(I,J,K) - 2._EB*(DUDX+DVDY) )
DTXZDX= RDX(I) *(TXZP-TXZM)
DTYZDY= RDY(J) *(TYZP-TYZM)
DTZZDZ= RDZN(K)*(TZZP-TZZM)
VTRM = RRHO*(DTXZDX + DTYZDY + DTZZDZ)
FVZ(I,J,K) = 0.25_EB*(VOMX - UOMY) + GZ(I)*AH - VTRM - RRHO*FVEC(3)
ENDDO
ENDDO
ENDDO
!$OMP END DO NOWAIT
! Mean forcing
MEAN_FORCING_X: IF (MEAN_FORCING(1)) THEN
!$OMP SINGLE
INTEGRAL = 0._EB
SUM_VOLUME = 0._EB
!$OMP END SINGLE
!$OMP DO COLLAPSE(3) SCHEDULE(STATIC) &
!$OMP PRIVATE(K,J,I,IC1,IC2,DVOLUME) REDUCTION(+:INTEGRAL,SUM_VOLUME)
DO K=1,KBAR
DO J=1,JBAR
DO I=0,IBAR
IC1 = CELL_INDEX(I,J,K)
IC2 = CELL_INDEX(I+1,J,K)
IF (SOLID(IC1) .OR. SOLID(IC2)) CYCLE
IF (IMMERSED_BOUNDARY_METHOD>0 .AND. U_MASK(I,J,K)==-1) CYCLE
DVOLUME = DXN(I)*DY(J)*DZ(K)
INTEGRAL = INTEGRAL + UU(I,J,K)*DVOLUME
SUM_VOLUME = SUM_VOLUME + DVOLUME
ENDDO
ENDDO
ENDDO
!$OMP END DO
!$OMP SINGLE
UMEAN = INTEGRAL/SUM_VOLUME
DU_FORCING = RFAC_FORCING(1)*(U0-UMEAN)/DT
!$OMP END SINGLE
!$OMP WORKSHARE
FVX = FVX-DU_FORCING
!$OMP END WORKSHARE NOWAIT
ENDIF MEAN_FORCING_X
MEAN_FORCING_Y: IF (MEAN_FORCING(2)) THEN
!$OMP SINGLE
INTEGRAL = 0._EB
SUM_VOLUME = 0._EB
!$OMP END SINGLE
!$OMP DO COLLAPSE(3) SCHEDULE(STATIC) &
!$OMP PRIVATE(K,J,I,IC1,IC2,DVOLUME) REDUCTION(+:INTEGRAL,SUM_VOLUME)
DO K=1,KBAR
DO J=0,JBAR
DO I=1,IBAR
IC1 = CELL_INDEX(I,J,K)
IC2 = CELL_INDEX(I,J+1,K)
IF (SOLID(IC1) .OR. SOLID(IC2)) CYCLE
IF (IMMERSED_BOUNDARY_METHOD>0 .AND. V_MASK(I,J,K)==-1) CYCLE
DVOLUME = DX(I)*DYN(J)*DZ(K)
INTEGRAL = INTEGRAL + VV(I,J,K)*DVOLUME
SUM_VOLUME = SUM_VOLUME + DVOLUME
ENDDO
ENDDO
ENDDO
!$OMP END DO
!$OMP SINGLE
VMEAN = INTEGRAL/SUM_VOLUME
DV_FORCING = RFAC_FORCING(2)*(V0-VMEAN)/DT
!$OMP END SINGLE
!$OMP WORKSHARE
FVY=FVY-DV_FORCING
!$OMP END WORKSHARE NOWAIT
ENDIF MEAN_FORCING_Y
MEAN_FORCING_Z: IF (MEAN_FORCING(3)) THEN
!$OMP SINGLE
INTEGRAL = 0._EB
SUM_VOLUME = 0._EB
!$OMP END SINGLE
!$OMP DO COLLAPSE(3) SCHEDULE(STATIC) &
!$OMP PRIVATE(K,J,I,IC1,IC2,DVOLUME) REDUCTION(+:INTEGRAL,SUM_VOLUME)
DO K=0,KBAR
DO J=1,JBAR
DO I=1,IBAR
IC1 = CELL_INDEX(I,J,K)
IC2 = CELL_INDEX(I,J,K+1)
IF (SOLID(IC1) .OR. SOLID(IC2)) CYCLE
IF (IMMERSED_BOUNDARY_METHOD>0 .AND. W_MASK(I,J,K)==-1) CYCLE
DVOLUME = DX(I)*DY(J)*DZN(K)
INTEGRAL = INTEGRAL + WW(I,J,K)*DVOLUME
SUM_VOLUME = SUM_VOLUME + DVOLUME
ENDDO
ENDDO
ENDDO
!$OMP END DO
!$OMP SINGLE
WMEAN = INTEGRAL/SUM_VOLUME
DW_FORCING = RFAC_FORCING(3)*(W0-WMEAN)/DT
!$OMP END SINGLE
!$OMP WORKSHARE
FVZ=FVZ-DW_FORCING
!$OMP END WORKSHARE NOWAIT
ENDIF MEAN_FORCING_Z
!$OMP END PARALLEL
! Surface vegetation drag
WFDS_BNDRYFUEL_IF: IF (WFDS_BNDRYFUEL .OR. VEG_LEVEL_SET_COUPLED) THEN
DO K=1,MIN(8,KBAR)
VEG_DRAG(0,:,K) = VEG_DRAG(1,:,K)
DO J=1,JBAR
DO I=0,IBAR
VEG_UMAG = SQRT(UU(I,J,K)**2 + VV(I,J,K)**2 + WW(I,J,K)**2) ! VEG_UMAG=KRES(I,J,K)
FVX(I,J,K) = FVX(I,J,K) + VEG_DRAG(I,J,K)*VEG_UMAG*UU(I,J,K)
ENDDO
ENDDO
VEG_DRAG(:,0,K) = VEG_DRAG(:,1,K)
DO J=0,JBAR
DO I=1,IBAR
VEG_UMAG = SQRT(UU(I,J,K)**2 + VV(I,J,K)**2 + WW(I,J,K)**2)
FVY(I,J,K) = FVY(I,J,K) + VEG_DRAG(I,J,K)*VEG_UMAG*VV(I,J,K)
ENDDO
ENDDO
DO J=1,JBAR
DO I=1,IBAR
VEG_UMAG = SQRT(UU(I,J,K)**2 + VV(I,J,K)**2 + WW(I,J,K)**2)
FVZ(I,J,K) = FVZ(I,J,K) + VEG_DRAG(I,J,K)*VEG_UMAG*WW(I,J,K)
ENDDO
ENDDO
ENDDO
ENDIF WFDS_BNDRYFUEL_IF
! Baroclinic torque correction
IF (BAROCLINIC .AND. .NOT.EVACUATION_ONLY(NM)) CALL BAROCLINIC_CORRECTION(T)
! Specified patch velocity
IF (PATCH_VELOCITY) CALL PATCH_VELOCITY_FLUX
! Adjust FVX, FVY and FVZ at solid, internal obstructions for no flux
CALL NO_FLUX(NM)
IF (IMMERSED_BOUNDARY_METHOD>=0) CALL IBM_VELOCITY_FLUX(NM)
IF (EVACUATION_ONLY(NM)) FVZ = 0._EB
END SUBROUTINE VELOCITY_FLUX
SUBROUTINE VELOCITY_FLUX_CYLINDRICAL(T,NM)
! Compute convective and diffusive terms for 2D axisymmetric
USE MATH_FUNCTIONS, ONLY: EVALUATE_RAMP
REAL(EB) :: T,DMUDX
INTEGER :: I0
INTEGER, INTENT(IN) :: NM
REAL(EB) :: MUY,UP,UM,WP,WM,VTRM,DTXZDZ,DTXZDX,DUDX,DWDZ,DUDZ,DWDX,WOMY,UOMY,OMYP,OMYM,TXZP,TXZM, &
AH,RRHO,GX,GZ,TXXP,TXXM,TZZP,TZZM,DTXXDX,DTZZDZ,DUMMY=0._EB
INTEGER :: I,J,K,IEYP,IEYM,IC
REAL(EB), POINTER, DIMENSION(:,:,:) :: TXZ=>NULL(),OMY=>NULL(),UU=>NULL(),WW=>NULL(),RHOP=>NULL(),DP=>NULL()
CALL POINT_TO_MESH(NM)
IF (PREDICTOR) THEN
UU => U
WW => W
DP => D
RHOP => RHO
ELSE
UU => US
WW => WS
DP => DS
RHOP => RHOS
ENDIF
TXZ => WORK2
OMY => WORK5
! Compute vorticity and stress tensor components
!$OMP PARALLEL DEFAULT(NONE) &
!$OMP SHARED(KBAR,JBAR,IBAR,RDZN,RDXN,UU,WW,OMY,MU,TXZ, &
!$OMP GX,GZ,XS,T,DUMMY,I_RAMP_GZ,GVEC,I0,J, &
!$OMP CELL_INDEX,EDGE_INDEX,OME_E,TAU_E,RHOP,RHO_0,RDX,RDZ,DP,R,FVX,FVZ,RRN)
!$OMP DO COLLAPSE(3) SCHEDULE(STATIC) &
!$OMP PRIVATE(K,J,I,DUDZ,DWDX,MUY)
DO K=0,KBAR
DO J=0,JBAR
DO I=0,IBAR
DUDZ = RDZN(K)*(UU(I,J,K+1)-UU(I,J,K))
DWDX = RDXN(I)*(WW(I+1,J,K)-WW(I,J,K))
OMY(I,J,K) = DUDZ - DWDX
MUY = 0.25_EB*(MU(I+1,J,K)+MU(I,J,K)+MU(I,J,K+1)+MU(I+1,J,K+1))
TXZ(I,J,K) = MUY*(DUDZ + DWDX)
ENDDO
ENDDO
ENDDO
!$OMP END DO NOWAIT
! Compute gravity components
!$OMP SINGLE
GX = 0._EB
GZ = EVALUATE_RAMP(T,DUMMY,I_RAMP_GZ)*GVEC(3)
! Compute r-direction flux term FVX
IF (ABS(XS)<=ZERO_P) THEN
I0 = 1
ELSE
I0 = 0
ENDIF
J = 1
!$OMP END SINGLE
!$OMP DO COLLAPSE(2) SCHEDULE(STATIC) &
!$OMP PRIVATE(K,I,WP,WM,OMYP,OMYM,TXZP,TXZM,IC,IEYP,IEYM,WOMY,RRHO,AH,DWDZ,TXXP,TXXM,DTXXDX,DTXZDZ,DMUDX,VTRM)
DO K= 1,KBAR
DO I=I0,IBAR