forked from altMITgcm/MITgcm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gmredi_calc_tensor.F
362 lines (310 loc) · 10.7 KB
/
gmredi_calc_tensor.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
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
C $Header: /u/gcmpack/MITgcm/pkg/gmredi/gmredi_calc_tensor.F,v 1.9 2001/12/16 18:54:49 jmc Exp $
C $Name: $
#include "GMREDI_OPTIONS.h"
CStartOfInterface
SUBROUTINE GMREDI_CALC_TENSOR(
I bi, bj, iMin, iMax, jMin, jMax,
I sigmaX, sigmaY, sigmaR,
I myThid )
C /==========================================================\
C | SUBROUTINE GMREDI_CALC_TENSOR |
C | o Calculate tensor elements for GM/Redi tensor. |
C |==========================================================|
C \==========================================================/
IMPLICIT NONE
C == Global variables ==
#include "SIZE.h"
#include "GRID.h"
#include "DYNVARS.h"
#include "EEPARAMS.h"
#include "PARAMS.h"
#include "GMREDI.h"
#include "GMREDI_DIAGS.h"
C == Routine arguments ==
C
_RL sigmaX(1-Olx:sNx+Olx,1-Oly:sNy+Oly,Nr)
_RL sigmaY(1-Olx:sNx+Olx,1-Oly:sNy+Oly,Nr)
_RL sigmaR(1-Olx:sNx+Olx,1-Oly:sNy+Oly,Nr)
INTEGER bi,bj,iMin,iMax,jMin,jMax
INTEGER myThid
CEndOfInterface
#ifdef ALLOW_GMREDI
C == Local variables ==
INTEGER i,j,k,km1,kp1
_RL SlopeX(1-Olx:sNx+Olx,1-Oly:sNy+Oly)
_RL SlopeY(1-Olx:sNx+Olx,1-Oly:sNy+Oly)
_RL dSigmaDrReal(1-Olx:sNx+Olx,1-Oly:sNy+Oly)
_RL SlopeSqr(1-Olx:sNx+Olx,1-Oly:sNy+Oly)
_RL taperFct(1-Olx:sNx+Olx,1-Oly:sNy+Oly)
_RL maskp1, Kgm_tmp
#ifdef GM_VISBECK_VARIABLE_K
_RS deltaH,zero_rs
PARAMETER(zero_rs=0.)
_RL N2,SN
_RL Ssq
#endif
DO k=2,Nr
C-- 1rst loop on k : compute Tensor Coeff. at W points.
c km1 = MAX(1,k-1)
#ifdef ALLOW_AUTODIFF_TAMC
!HPF$ INDEPENDENT
#endif
DO j=1-Oly+1,sNy+Oly-1
#ifdef ALLOW_AUTODIFF_TAMC
!HPF$ INDEPENDENT
#endif
DO i=1-Olx+1,sNx+Olx-1
C Gradient of Sigma at rVel points
SlopeX(i,j)=0.25*( sigmaX(i+1, j ,k-1) +sigmaX(i,j,k-1)
& +sigmaX(i+1, j , k ) +sigmaX(i,j, k ) )
& *maskC(i,j,k,bi,bj)
SlopeY(i,j)=0.25*( sigmaY( i ,j+1,k-1) +sigmaY(i,j,k-1)
& +sigmaY( i ,j+1, k ) +sigmaY(i,j, k ) )
& *maskC(i,j,k,bi,bj)
dSigmaDrReal(i,j)=sigmaR(i,j,k)
ENDDO
ENDDO
C Calculate slopes for use in tensor, taper and/or clip
CALL GMREDI_SLOPE_LIMIT(
U dSigmadRReal,
I rF(K),
U SlopeX, SlopeY,
O SlopeSqr, taperFct,
I bi, bj, myThid )
DO j=1-Oly+1,sNy+Oly-1
DO i=1-Olx+1,sNx+Olx-1
C Mask Iso-neutral slopes
SlopeX(i,j)=SlopeX(i,j)*maskC(i,j,k,bi,bj)
SlopeY(i,j)=SlopeY(i,j)*maskC(i,j,k,bi,bj)
SlopeSqr(i,j)=SlopeSqr(i,j)*maskC(i,j,k,bi,bj)
c Ssq=SlopeX(i,j)*SlopeX(i,j)+SlopeY(i,j)*SlopeY(i,j)
C Components of Redi/GM tensor
Kwx(i,j,k,bi,bj)= SlopeX(i,j)*taperFct(i,j)
Kwy(i,j,k,bi,bj)= SlopeY(i,j)*taperFct(i,j)
Kwz(i,j,k,bi,bj)= SlopeSqr(i,j)*taperFct(i,j)
#ifdef GM_VISBECK_VARIABLE_K
C- note (jmc) : moved here since only used in VISBECK_VARIABLE_K
C but don't know if *taperFct (or **2 ?) is necessary
Ssq=SlopeSqr(i,j)*taperFct(i,j)
C-- Depth average of M^2/N^2 * N
C Calculate terms for mean Richardson number
C which is used in the "variable K" parameterisaton.
C Distance between interface above layer and the integration depth
deltaH=abs(GM_Visbeck_depth)-abs(rF(k))
C If positive we limit this to the layer thickness
deltaH=min(deltaH,drF(k))
C If negative then we are below the integration level
deltaH=max(deltaH,zero_rs)
C Now we convert deltaH to a non-dimensional fraction
deltaH=deltaH/GM_Visbeck_depth
IF (K.eq.2) VisbeckK(i,j,bi,bj)=0.
IF (Ssq.NE.0.) THEN
N2= -Gravity*recip_Rhonil*dSigmaDrReal(i,j)
SN=sqrt(Ssq*N2)
VisbeckK(i,j,bi,bj)=VisbeckK(i,j,bi,bj)+deltaH
& *GM_Visbeck_alpha*GM_Visbeck_length*GM_Visbeck_length*SN
ENDIF
#endif /* GM_VISBECK_VARIABLE_K */
ENDDO
ENDDO
C-- end 1rst loop on vertical level index k
ENDDO
#ifdef GM_VISBECK_VARIABLE_K
IF ( GM_Visbeck_alpha.NE.0. ) THEN
C- Limit range that KapGM can take
DO j=1-Oly+1,sNy+Oly-1
DO i=1-Olx+1,sNx+Olx-1
VisbeckK(i,j,bi,bj)=
& MIN(VisbeckK(i,j,bi,bj),GM_Visbeck_maxval_K)
#ifdef ALLOW_TIMEAVE
Visbeck_K_T(i,j,bi,bj)=Visbeck_K_T(i,j,bi,bj)
& +VisbeckK(i,j,bi,bj)*deltaTclock
#endif
ENDDO
ENDDO
ENDIF
#endif /* GM_VISBECK_VARIABLE_K */
C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----|
C-- 2nd loop on k : compute Tensor Coeff. at U,V levels.
DO k=1,Nr
kp1 = MIN(Nr,k+1)
maskp1 = 1. _d 0
IF (k.GE.Nr) maskp1 = 0. _d 0
C- express the Tensor in term of Diffusivity (= m**2 / s )
DO j=1-Oly+1,sNy+Oly-1
DO i=1-Olx+1,sNx+Olx-1
Kgm_tmp = GM_isopycK + GM_skewflx*GM_background_K
#ifdef GM_VISBECK_VARIABLE_K
& + VisbeckK(i,j,bi,bj)*(1.+GM_skewflx)
#endif
Kwx(i,j,k,bi,bj)= Kgm_tmp*Kwx(i,j,k,bi,bj)
Kwy(i,j,k,bi,bj)= Kgm_tmp*Kwy(i,j,k,bi,bj)
Kwz(i,j,k,bi,bj)= ( GM_isopycK
#ifdef GM_VISBECK_VARIABLE_K
& + VisbeckK(i,j,bi,bj)
#endif
& )*Kwz(i,j,k,bi,bj)
ENDDO
ENDDO
#if ( defined (GM_NON_UNITY_DIAGONAL) || defined (GM_EXTRA_DIAGONAL) )
C Gradient of Sigma at U points
DO j=1-Oly+1,sNy+Oly-1
DO i=1-Olx+1,sNx+Olx-1
SlopeX(i,j)=sigmaX(i,j,k)
& *_maskW(i,j,k,bi,bj)
SlopeY(i,j)=0.25*( sigmaY(i-1,j+1,k) +sigmaY(i,j+1,k)
& +sigmaY(i-1, j ,k) +sigmaY(i, j ,k) )
& *_maskW(i,j,k,bi,bj)
dSigmaDrReal(i,j)=0.25*( sigmaR(i-1,j, k ) +sigmaR(i,j, k )
& +maskp1*(sigmaR(i-1,j,kp1) +sigmaR(i,j,kp1)) )
& *_maskW(i,j,k,bi,bj)
ENDDO
ENDDO
C Calculate slopes for use in tensor, taper and/or clip
CALL GMREDI_SLOPE_LIMIT(
U dSigmadRReal,
I rF(K),
U SlopeX, SlopeY,
O SlopeSqr, taperFct,
I bi, bj, myThid )
#ifdef GM_NON_UNITY_DIAGONAL
DO j=1-Oly+1,sNy+Oly-1
DO i=1-Olx+1,sNx+Olx-1
Kux(i,j,k,bi,bj) =
& ( GM_isopycK
#ifdef GM_VISBECK_VARIABLE_K
& +0.5*(VisbeckK(i,j,bi,bj)+VisbeckK(i-1,j,bi,bj))
#endif
& )*taperFct(i,j)
Kux(i,j,k,bi,bj) = MAX( Kux(i,j,k,bi,bj), GM_Kmin_horiz )
ENDDO
ENDDO
#endif /* GM_NON_UNITY_DIAGONAL */
#ifdef GM_EXTRA_DIAGONAL
IF (GM_ExtraDiag) THEN
DO j=1-Oly+1,sNy+Oly-1
DO i=1-Olx+1,sNx+Olx-1
Kuz(i,j,k,bi,bj) =
& ( GM_isopycK - GM_skewflx*GM_background_K
#ifdef GM_VISBECK_VARIABLE_K
& +0.5*(VisbeckK(i,j,bi,bj)+VisbeckK(i-1,j,bi,bj))*GM_advect
#endif
& )*SlopeX(i,j)*taperFct(i,j)
ENDDO
ENDDO
ENDIF
#endif /* GM_EXTRA_DIAGONAL */
C Gradient of Sigma at V points
DO j=1-Oly+1,sNy+Oly-1
DO i=1-Olx+1,sNx+Olx-1
SlopeX(i,j)=0.25*( sigmaX(i, j ,k) +sigmaX(i+1, j ,k)
& +sigmaX(i,j-1,k) +sigmaX(i+1,j-1,k) )
& *_maskS(i,j,k,bi,bj)
SlopeY(i,j)=sigmaY(i,j,k)
& *_maskS(i,j,k,bi,bj)
dSigmaDrReal(i,j)=0.25*( sigmaR(i,j-1, k ) +sigmaR(i,j, k )
& +maskp1*(sigmaR(i,j-1,kp1) +sigmaR(i,j,kp1)) )
& *_maskS(i,j,k,bi,bj)
ENDDO
ENDDO
C Calculate slopes for use in tensor, taper and/or clip
CALL GMREDI_SLOPE_LIMIT(
U dSigmadRReal,
I rF(K),
U SlopeX, SlopeY,
O SlopeSqr, taperFct,
I bi, bj, myThid )
#ifdef GM_NON_UNITY_DIAGONAL
DO j=1-Oly+1,sNy+Oly-1
DO i=1-Olx+1,sNx+Olx-1
Kvy(i,j,k,bi,bj) =
& ( GM_isopycK
#ifdef GM_VISBECK_VARIABLE_K
& +0.5*(VisbeckK(i,j,bi,bj)+VisbeckK(i,j-1,bi,bj))
#endif
& )*taperFct(i,j)
Kvy(i,j,k,bi,bj) = MAX( Kvy(i,j,k,bi,bj), GM_Kmin_horiz )
ENDDO
ENDDO
#endif /* GM_NON_UNITY_DIAGONAL */
#ifdef GM_EXTRA_DIAGONAL
IF (GM_ExtraDiag) THEN
DO j=1-Oly+1,sNy+Oly-1
DO i=1-Olx+1,sNx+Olx-1
Kvz(i,j,k,bi,bj) =
& ( GM_isopycK - GM_skewflx*GM_background_K
#ifdef GM_VISBECK_VARIABLE_K
& +0.5*(VisbeckK(i,j,bi,bj)+VisbeckK(i,j-1,bi,bj))*GM_advect
#endif
& )*SlopeY(i,j)*taperFct(i,j)
ENDDO
ENDDO
ENDIF
#endif /* GM_EXTRA_DIAGONAL */
#endif /* GM_NON_UNITY_DIAGONAL || GM_EXTRA_DIAGONAL */
#ifdef ALLOW_TIMEAVE
C-- Time-average
DO j=1-Oly+1,sNy+Oly-1
DO i=1-Olx+1,sNx+Olx-1
GM_Kwx_T(i,j,k,bi,bj)=GM_Kwx_T(i,j,k,bi,bj)
& +Kwx(i,j,k,bi,bj)*deltaTclock
GM_Kwy_T(i,j,k,bi,bj)=GM_Kwy_T(i,j,k,bi,bj)
& +Kwy(i,j,k,bi,bj)*deltaTclock
GM_Kwz_T(i,j,k,bi,bj)=GM_Kwz_T(i,j,k,bi,bj)
& +Kwz(i,j,k,bi,bj)*deltaTclock
ENDDO
ENDDO
GM_TimeAve(k,bi,bj)=GM_TimeAve(k,bi,bj)+deltaTclock
#endif /* ALLOW_TIMEAVE */
C-- end 2nd loop on vertical level index k
ENDDO
#ifdef GM_BOLUS_ADVEC
IF (GM_AdvForm) THEN
CALL GMREDI_CALC_PSI_B(
I bi, bj, iMin, iMax, jMin, jMax,
I sigmaX, sigmaY, sigmaR,
I myThid )
ENDIF
#endif
#endif /* ALLOW_GMREDI */
RETURN
END
SUBROUTINE GMREDI_CALC_TENSOR_DUMMY(
I bi, bj, iMin, iMax, jMin, jMax,
I sigmaX, sigmaY, sigmaR,
I myThid )
C /==========================================================\
C | SUBROUTINE GMREDI_CALC_TENSOR |
C | o Calculate tensor elements for GM/Redi tensor. |
C |==========================================================|
C \==========================================================/
IMPLICIT NONE
C == Global variables ==
#include "SIZE.h"
#include "GRID.h"
#include "DYNVARS.h"
#include "EEPARAMS.h"
#include "PARAMS.h"
#include "GMREDI.h"
C == Routine arguments ==
C
_RL sigmaX(1-Olx:sNx+Olx,1-Oly:sNy+Oly,Nr)
_RL sigmaY(1-Olx:sNx+Olx,1-Oly:sNy+Oly,Nr)
_RL sigmaR(1-Olx:sNx+Olx,1-Oly:sNy+Oly,Nr)
INTEGER bi,bj,iMin,iMax,jMin,jMax
INTEGER myThid
CEndOfInterface
INTEGER i, j, k
#ifdef ALLOW_GMREDI
DO k=1,Nr
DO j=1-Oly+1,sNy+Oly-1
DO i=1-Olx+1,sNx+Olx-1
Kwx(i,j,k,bi,bj) = 0.0
Kwy(i,j,k,bi,bj) = 0.0
Kwz(i,j,k,bi,bj) = 0.0
ENDDO
ENDDO
ENDDO
#endif /* ALLOW_GMREDI */
RETURN
END