forked from darwinproject/darwin3
-
Notifications
You must be signed in to change notification settings - Fork 1
/
gad_dst3fl_adv_x.F
102 lines (90 loc) · 3.27 KB
/
gad_dst3fl_adv_x.F
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
#include "GAD_OPTIONS.h"
SUBROUTINE GAD_DST3FL_ADV_X(
I bi,bj,k, calcCFL, deltaTloc,
I uTrans, uFld,
I maskLocW, tracer,
O uT,
I myThid )
C /==========================================================\
C | SUBROUTINE GAD_DST3FL_ADV_X |
C | o Compute Zonal advective Flux of Tracer using |
C | 3rd Order DST Sceheme with flux limiting |
C |==========================================================|
IMPLICIT NONE
C == GLobal variables ==
#include "SIZE.h"
#include "GRID.h"
#include "GAD.h"
C == Routine arguments ==
INTEGER bi,bj,k
LOGICAL calcCFL
_RL deltaTloc
_RL uTrans(1-OLx:sNx+OLx,1-OLy:sNy+OLy)
_RL uFld (1-OLx:sNx+OLx,1-OLy:sNy+OLy)
_RS maskLocW(1-OLx:sNx+OLx,1-OLy:sNy+OLy)
_RL tracer(1-OLx:sNx+OLx,1-OLy:sNy+OLy)
_RL uT (1-OLx:sNx+OLx,1-OLy:sNy+OLy)
INTEGER myThid
C == Local variables ==
INTEGER i,j
_RL Rjm,Rj,Rjp,uCFL,d0,d1,psiP,psiM,thetaP,thetaM
_RL thetaMax
PARAMETER( thetaMax = 1.D+20 )
C- jmc: an alternative would be to compute directly psiM*Rj & psiP*Rj
C (if Rj*Rjm < 0 => psiP*Rj = 0 , elsef Rj > 0 ... , else ... )
C with no need to compute thetaM (might be easier to differentiate)
DO j=1-OLy,sNy+OLy
uT(1-OLx,j)=0. _d 0
uT(2-OLx,j)=0. _d 0
uT(sNx+OLx,j)=0. _d 0
ENDDO
DO j=1-OLy,sNy+OLy
DO i=1-OLx+2,sNx+OLx-1
#if (defined ALLOW_AUTODIFF && defined TARGET_NEC_SX)
C These lines make TAF create vectorizable code
thetaP = 0. _d 0
thetaM = 0. _d 0
#endif
Rjp=(tracer(i+1,j)-tracer( i ,j))*maskLocW(i+1,j)
Rj =(tracer( i ,j)-tracer(i-1,j))*maskLocW( i ,j)
Rjm=(tracer(i-1,j)-tracer(i-2,j))*maskLocW(i-1,j)
uCFL = uFld(i,j)
IF ( calcCFL ) uCFL = ABS( uFld(i,j)*deltaTloc
& *recip_dxC(i,j,bi,bj)*recip_deepFacC(k) )
d0=(2. _d 0 -uCFL)*(1. _d 0 -uCFL)*oneSixth
d1=(1. _d 0 -uCFL*uCFL)*oneSixth
C- the old version: can produce overflow, division by zero,
c and is wrong for tracer with low concentration:
c thetaP=Rjm/(1.D-20+Rj)
c thetaM=Rjp/(1.D-20+Rj)
C- the right expression, but not bounded:
c thetaP=0.D0
c thetaM=0.D0
c IF (Rj.NE.0.D0) thetaP=Rjm/Rj
c IF (Rj.NE.0.D0) thetaM=Rjp/Rj
C- prevent |thetaP,M| to reach too big value:
IF ( ABS(Rj)*thetaMax .LE. ABS(Rjm) ) THEN
thetaP=SIGN(thetaMax,Rjm*Rj)
ELSE
thetaP=Rjm/Rj
ENDIF
IF ( ABS(Rj)*thetaMax .LE. ABS(Rjp) ) THEN
thetaM=SIGN(thetaMax,Rjp*Rj)
ELSE
thetaM=Rjp/Rj
ENDIF
psiP=d0+d1*thetaP
psiP=MAX(0. _d 0,MIN(MIN(1. _d 0,psiP),
& thetaP*(1. _d 0 -uCFL)/(uCFL+1. _d -20) ))
psiM=d0+d1*thetaM
psiM=MAX(0. _d 0,MIN(MIN(1. _d 0,psiM),
& thetaM*(1. _d 0 -uCFL)/(uCFL+1. _d -20) ))
uT(i,j)=
& 0.5*(uTrans(i,j)+ABS(uTrans(i,j)))
& *( Tracer(i-1,j) + psiP*Rj )
& +0.5*(uTrans(i,j)-ABS(uTrans(i,j)))
& *( Tracer( i ,j) - psiM*Rj )
ENDDO
ENDDO
RETURN
END