1 |
C $Header: /u/gcmpack/MITgcm/pkg/generic_advdiff/gad_implicit_r.F,v 1.5 2004/11/12 17:31:16 jmc Exp $ |
2 |
C $Name: $ |
3 |
|
4 |
#include "GAD_OPTIONS.h" |
5 |
|
6 |
CBOP |
7 |
C !ROUTINE: GAD_IMPLICIT_R |
8 |
C !INTERFACE: |
9 |
SUBROUTINE GAD_IMPLICIT_R( |
10 |
I implicitAdvection, advectionScheme, tracerIdentity, |
11 |
I kappaRX, wVel, tracer, |
12 |
U gTracer, |
13 |
I bi, bj, myTime, myIter, myThid ) |
14 |
C !DESCRIPTION: |
15 |
C Solve implicitly vertical advection and diffusion for one tracer. |
16 |
|
17 |
C !USES: |
18 |
IMPLICIT NONE |
19 |
C == Global data == |
20 |
#include "SIZE.h" |
21 |
#include "EEPARAMS.h" |
22 |
#include "PARAMS.h" |
23 |
#include "GRID.h" |
24 |
#include "GAD.h" |
25 |
|
26 |
C !INPUT/OUTPUT PARAMETERS: |
27 |
C == Routine Arguments == |
28 |
C implicitAdvection :: if True, treat vertical advection implicitly |
29 |
C advectionScheme :: advection scheme to use |
30 |
C tracerIdentity :: Identifier for the tracer |
31 |
C kappaRX :: 3-D array for vertical diffusion coefficient |
32 |
C wVel :: vertical component of the velcity field |
33 |
C tracer :: tracer field at current time step |
34 |
C gTracer :: future tracer field |
35 |
C bi,bj :: tile indices |
36 |
C myTime :: current time |
37 |
C myIter :: current iteration number |
38 |
C myThid :: thread number |
39 |
LOGICAL implicitAdvection |
40 |
INTEGER advectionScheme |
41 |
INTEGER tracerIdentity |
42 |
_RL kappaRX(1-Olx:sNx+Olx,1-Oly:sNy+Oly,Nr) |
43 |
_RL wVel (1-Olx:sNx+Olx,1-Oly:sNy+Oly,Nr,nSx,nSy) |
44 |
_RL tracer (1-Olx:sNx+Olx,1-Oly:sNy+Oly,Nr,nSx,nSy) |
45 |
_RL gTracer(1-Olx:sNx+Olx,1-Oly:sNy+Oly,Nr,nSx,nSy) |
46 |
INTEGER bi, bj |
47 |
_RL myTime |
48 |
INTEGER myIter, myThid |
49 |
|
50 |
C !LOCAL VARIABLES: |
51 |
C == Local variables == |
52 |
C iMin,iMax,jMin,jMax :: computational domain |
53 |
C i,j,k :: loop indices |
54 |
C a5d :: 2nd lower diagonal of the pentadiagonal matrix |
55 |
C b5d :: 1rst lower diagonal of the pentadiagonal matrix |
56 |
C c5d :: main diagonal of the pentadiagonal matrix |
57 |
C d5d :: 1rst upper diagonal of the pentadiagonal matrix |
58 |
C e5d :: 2nd upper diagonal of the pentadiagonal matrix |
59 |
C rTrans :: vertical volume transport at inteface k |
60 |
C rTransKp1 :: vertical volume transport at inteface k+1 |
61 |
C localTijk :: local copy of tracer (for Non-Lin Adv.Scheme) |
62 |
C diagonalNumber :: number of non-zero diagonals in the matrix |
63 |
C errCode :: > 0 if singular matrix |
64 |
INTEGER iMin,iMax,jMin,jMax |
65 |
INTEGER i,j,k |
66 |
INTEGER diagonalNumber, errCode |
67 |
_RL a5d(1-Olx:sNx+Olx,1-Oly:sNy+Oly,Nr) |
68 |
_RL b5d(1-Olx:sNx+Olx,1-Oly:sNy+Oly,Nr) |
69 |
_RL c5d(1-Olx:sNx+Olx,1-Oly:sNy+Oly,Nr) |
70 |
_RL d5d(1-Olx:sNx+Olx,1-Oly:sNy+Oly,Nr) |
71 |
_RL e5d(1-Olx:sNx+Olx,1-Oly:sNy+Oly,Nr) |
72 |
_RL rTrans(1-Olx:sNx+Olx,1-Oly:sNy+Oly) |
73 |
_RL rTransKp1(1-Olx:sNx+Olx,1-Oly:sNy+Oly) |
74 |
_RL localTijk(1-Olx:sNx+Olx,1-Oly:sNy+Oly,Nr) |
75 |
CEOP |
76 |
|
77 |
IF (Nr.LE.1) RETURN |
78 |
|
79 |
C-- Initialise |
80 |
iMin = 1 |
81 |
jMin = 1 |
82 |
iMax = sNx |
83 |
jMax = sNy |
84 |
DO k=1,Nr |
85 |
DO j=1-Oly,sNy+Oly |
86 |
DO i=1-Olx,sNx+Olx |
87 |
a5d(i,j,k) = 0. _d 0 |
88 |
b5d(i,j,k) = 0. _d 0 |
89 |
c5d(i,j,k) = 1. _d 0 |
90 |
d5d(i,j,k) = 0. _d 0 |
91 |
e5d(i,j,k) = 0. _d 0 |
92 |
ENDDO |
93 |
ENDDO |
94 |
ENDDO |
95 |
diagonalNumber = 1 |
96 |
|
97 |
C-- Non-Linear Advection scheme: keep a local copy of tracer field |
98 |
IF ( advectionScheme.EQ.ENUM_FLUX_LIMIT .OR. |
99 |
& advectionScheme.EQ.ENUM_DST3_FLUX_LIMIT ) THEN |
100 |
IF ( multiDimAdvection ) THEN |
101 |
DO k=1,Nr |
102 |
DO j=1-Oly,sNy+Oly |
103 |
DO i=1-Olx,sNx+Olx |
104 |
localTijk(i,j,k) = gTracer(i,j,k,bi,bj) |
105 |
ENDDO |
106 |
ENDDO |
107 |
ENDDO |
108 |
ELSE |
109 |
DO k=1,Nr |
110 |
DO j=1-Oly,sNy+Oly |
111 |
DO i=1-Olx,sNx+Olx |
112 |
localTijk(i,j,k) = tracer(i,j,k,bi,bj) |
113 |
ENDDO |
114 |
ENDDO |
115 |
ENDDO |
116 |
ENDIF |
117 |
ENDIF |
118 |
|
119 |
IF (implicitDiffusion) THEN |
120 |
C-- set the tri-diagonal matrix to solve the implicit diffusion problem |
121 |
diagonalNumber = 3 |
122 |
C- 1rst lower diagonal : |
123 |
DO k=2,Nr |
124 |
DO j=jMin,jMax |
125 |
DO i=iMin,iMax |
126 |
IF (maskC(i,j,k-1,bi,bj).EQ.1.) |
127 |
& b5d(i,j,k) = -dTtracerLev(1) |
128 |
& *recip_hFacC(i,j,k,bi,bj)*recip_drF(k) |
129 |
& *kappaRX(i,j, k )*recip_drC( k ) |
130 |
ENDDO |
131 |
ENDDO |
132 |
ENDDO |
133 |
C- 1rst upper diagonal : |
134 |
DO k=1,Nr-1 |
135 |
DO j=jMin,jMax |
136 |
DO i=iMin,iMax |
137 |
IF (maskC(i,j,k+1,bi,bj).EQ.1.) |
138 |
& d5d(i,j,k) = -dTtracerLev(1) |
139 |
& *recip_hFacC(i,j,k,bi,bj)*recip_drF(k) |
140 |
& *KappaRX(i,j,k+1)*recip_drC(k+1) |
141 |
ENDDO |
142 |
ENDDO |
143 |
ENDDO |
144 |
C- Main diagonal : |
145 |
DO k=1,Nr |
146 |
DO j=jMin,jMax |
147 |
DO i=iMin,iMax |
148 |
c5d(i,j,k) = 1. _d 0 - b5d(i,j,k) - d5d(i,j,k) |
149 |
ENDDO |
150 |
ENDDO |
151 |
ENDDO |
152 |
|
153 |
C-- end if implicitDiffusion |
154 |
ENDIF |
155 |
|
156 |
IF (implicitAdvection) THEN |
157 |
|
158 |
DO k=Nr,1,-1 |
159 |
|
160 |
C-- Compute transport |
161 |
IF (k.EQ.Nr) THEN |
162 |
DO j=1-Oly,sNy+Oly |
163 |
DO i=1-Olx,sNx+Olx |
164 |
rTransKp1(i,j) = 0. |
165 |
ENDDO |
166 |
ENDDO |
167 |
ELSE |
168 |
DO j=1-Oly,sNy+Oly |
169 |
DO i=1-Olx,sNx+Olx |
170 |
rTransKp1(i,j) = rTrans(i,j) |
171 |
ENDDO |
172 |
ENDDO |
173 |
ENDIF |
174 |
|
175 |
IF (k.EQ.1) THEN |
176 |
DO j=1-Oly,sNy+Oly |
177 |
DO i=1-Olx,sNx+Olx |
178 |
rTrans(i,j) = 0. |
179 |
ENDDO |
180 |
ENDDO |
181 |
ELSE |
182 |
DO j=1-Oly,sNy+Oly |
183 |
DO i=1-Olx,sNx+Olx |
184 |
rTrans(i,j) = wVel(i,j,k,bi,bj)*rA(i,j,bi,bj) |
185 |
& *maskC(i,j,k-1,bi,bj) |
186 |
ENDDO |
187 |
ENDDO |
188 |
#ifdef ALLOW_GMREDI |
189 |
C-- Residual transp = Bolus transp + Eulerian transp |
190 |
IF (useGMRedi) |
191 |
& CALL GMREDI_CALC_WFLOW( |
192 |
& rTrans, bi, bj, k, myThid) |
193 |
#endif /* ALLOW_GMREDI */ |
194 |
ENDIF |
195 |
DO j=jMin,jMax |
196 |
DO i=iMin,iMax |
197 |
c localTijk(i,j,k) = gTracer(i,j,k,bi,bj) |
198 |
gTracer(i,j,k,bi,bj) = gTracer(i,j,k,bi,bj) |
199 |
& + dTtracerLev(1)*recip_rA(i,j,bi,bj) |
200 |
& *_recip_hFacC(i,j,k,bi,bj)*recip_drF(k) |
201 |
& *tracer(i,j,k,bi,bj)*(rTrans(i,j)-rTransKp1(i,j))*rkFac |
202 |
ENDDO |
203 |
ENDDO |
204 |
|
205 |
#ifdef ALLOW_AIM |
206 |
C- a hack to prevent Water-Vapor vert.transport into the stratospheric level Nr |
207 |
IF ( K.GE.2 .AND. |
208 |
& (.NOT.useAIM .OR.tracerIdentity.NE.GAD_SALINITY .OR.K.LT.Nr) |
209 |
& ) THEN |
210 |
#else |
211 |
IF ( K.GE.2 ) THEN |
212 |
#endif |
213 |
|
214 |
IF ( advectionScheme.EQ.ENUM_CENTERED_2ND ) THEN |
215 |
diagonalNumber = 3 |
216 |
CALL GAD_C2_IMPL_R( bi,bj,k, iMin,iMax,jMin,jMax, |
217 |
I dTtracerLev(1), rTrans, |
218 |
U b5d, c5d, d5d, |
219 |
I myThid) |
220 |
ELSEIF (advectionScheme.EQ.ENUM_FLUX_LIMIT) THEN |
221 |
diagonalNumber = 3 |
222 |
CALL GAD_FLUXLIMIT_IMPL_R( bi,bj,k, iMin,iMax,jMin,jMax, |
223 |
I dTtracerLev(1), rTrans, localTijk, |
224 |
U b5d, c5d, d5d, |
225 |
I myThid) |
226 |
ELSEIF (advectionScheme.EQ.ENUM_UPWIND_3RD .OR. |
227 |
& advectionScheme.EQ.ENUM_CENTERED_4TH) THEN |
228 |
diagonalNumber = 5 |
229 |
CALL GAD_U3C4_IMPL_R( bi,bj,k, iMin,iMax,jMin,jMax, |
230 |
I advectionScheme, dTtracerLev(1), rTrans, |
231 |
U a5d, b5d, c5d, d5d, e5d, |
232 |
I myThid) |
233 |
ELSE |
234 |
STOP 'GAD_IMPLICIT_R: Adv.Scheme in Impl form not yet coded' |
235 |
ENDIF |
236 |
|
237 |
ENDIF |
238 |
|
239 |
C-- end k loop |
240 |
ENDDO |
241 |
|
242 |
C-- end if implicitAdvection |
243 |
ENDIF |
244 |
|
245 |
IF ( diagonalNumber .EQ. 3 ) THEN |
246 |
C-- Solve tri-diagonal system : |
247 |
CALL SOLVE_TRIDIAGONAL( iMin,iMax, jMin,jMax, |
248 |
I b5d, c5d, d5d, |
249 |
U gTracer, |
250 |
O errCode, |
251 |
I bi, bj, myThid ) |
252 |
IF (errCode.GE.1) THEN |
253 |
STOP 'GAD_IMPLICIT_R: error when solving 3-Diag problem' |
254 |
ENDIF |
255 |
ELSEIF ( diagonalNumber .EQ. 5 ) THEN |
256 |
C-- Solve penta-diagonal system : |
257 |
CALL SOLVE_PENTADIAGONAL( iMin,iMax, jMin,jMax, |
258 |
I a5d, b5d, c5d, d5d, e5d, |
259 |
U gTracer, |
260 |
O errCode, |
261 |
I bi, bj, myThid ) |
262 |
IF (errCode.GE.1) THEN |
263 |
STOP 'GAD_IMPLICIT_R: error when solving 5-Diag problem' |
264 |
ENDIF |
265 |
ELSEIF ( diagonalNumber .NE. 1 ) THEN |
266 |
STOP 'GAD_IMPLICIT_R: no solver available' |
267 |
ENDIF |
268 |
|
269 |
RETURN |
270 |
END |