1 |
C $Header: /u/gcmpack/MITgcm/pkg/generic_advdiff/gad_som_adv_x.F,v 1.6 2012/03/05 17:59:15 jmc Exp $ |
2 |
C $Name: $ |
3 |
|
4 |
#include "GAD_OPTIONS.h" |
5 |
|
6 |
CBOP |
7 |
C !ROUTINE: GAD_SOM_ADV_X |
8 |
|
9 |
C !INTERFACE: ========================================================== |
10 |
SUBROUTINE GAD_SOM_ADV_X( |
11 |
I bi,bj,k, limiter, |
12 |
I overlapOnly, interiorOnly, |
13 |
I N_edge, S_edge, E_edge, W_edge, |
14 |
I deltaTloc, uTrans, maskIn, |
15 |
U sm_v, sm_o, sm_x, sm_y, sm_z, |
16 |
U sm_xx, sm_yy, sm_zz, sm_xy, sm_xz, sm_yz, |
17 |
O uT, |
18 |
I myThid ) |
19 |
|
20 |
C !DESCRIPTION: |
21 |
C Calculates the area integrated zonal flux due to advection |
22 |
C of a tracer using |
23 |
C-- |
24 |
C Second-Order Moments Advection of tracer in X-direction |
25 |
C ref: M.J.Prather, 1986, JGR, 91, D6, pp 6671-6681. |
26 |
C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----| |
27 |
C The 3-D grid has dimension (Nx,Ny,Nz) with corresponding |
28 |
C velocity field (U,V,W). Parallel subroutine calculate |
29 |
C advection in the Y- and Z- directions. |
30 |
C The moment [Si] are as defined in the text, Sm refers to |
31 |
C the total mass in each grid box |
32 |
C the moments [Fi] are similarly defined and used as temporary |
33 |
C storage for portions of the grid boxes in transit. |
34 |
C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----| |
35 |
|
36 |
C !USES: =============================================================== |
37 |
IMPLICIT NONE |
38 |
#include "SIZE.h" |
39 |
#include "EEPARAMS.h" |
40 |
#include "GAD.h" |
41 |
|
42 |
C !INPUT PARAMETERS: =================================================== |
43 |
C bi,bj :: tile indices |
44 |
C k :: vertical level |
45 |
C limiter :: 0: no limiter ; 1: Prather, 1986 limiter |
46 |
C overlapOnly :: only update the edges of myTile, but not the interior |
47 |
C interiorOnly :: only update the interior of myTile, but not the edges |
48 |
C [N,S,E,W]_edge :: true if N,S,E,W edge of myTile is an Edge of the cube |
49 |
C uTrans :: zonal volume transport |
50 |
C maskIn :: 2-D array Interior mask |
51 |
C myThid :: my Thread Id. number |
52 |
INTEGER bi,bj,k |
53 |
INTEGER limiter |
54 |
LOGICAL overlapOnly, interiorOnly |
55 |
LOGICAL N_edge, S_edge, E_edge, W_edge |
56 |
_RL deltaTloc |
57 |
_RL uTrans(1-OLx:sNx+OLx,1-OLy:sNy+OLy) |
58 |
_RS maskIn(1-OLx:sNx+OLx,1-OLy:sNy+OLy) |
59 |
INTEGER myThid |
60 |
|
61 |
C !OUTPUT PARAMETERS: ================================================== |
62 |
C sm_v :: volume of grid cell |
63 |
C sm_o :: tracer content of grid cell (zero order moment) |
64 |
C sm_x,y,z :: 1rst order moment of tracer distribution, in x,y,z direction |
65 |
C sm_xx,yy,zz :: 2nd order moment of tracer distribution, in x,y,z direction |
66 |
C sm_xy,xz,yz :: 2nd order moment of tracer distr., in cross direction xy,xz,yz |
67 |
C uT :: zonal advective flux |
68 |
_RL sm_v (1-OLx:sNx+OLx,1-OLy:sNy+OLy) |
69 |
_RL sm_o (1-OLx:sNx+OLx,1-OLy:sNy+OLy) |
70 |
_RL sm_x (1-OLx:sNx+OLx,1-OLy:sNy+OLy) |
71 |
_RL sm_y (1-OLx:sNx+OLx,1-OLy:sNy+OLy) |
72 |
_RL sm_z (1-OLx:sNx+OLx,1-OLy:sNy+OLy) |
73 |
_RL sm_xx (1-OLx:sNx+OLx,1-OLy:sNy+OLy) |
74 |
_RL sm_yy (1-OLx:sNx+OLx,1-OLy:sNy+OLy) |
75 |
_RL sm_zz (1-OLx:sNx+OLx,1-OLy:sNy+OLy) |
76 |
_RL sm_xy (1-OLx:sNx+OLx,1-OLy:sNy+OLy) |
77 |
_RL sm_xz (1-OLx:sNx+OLx,1-OLy:sNy+OLy) |
78 |
_RL sm_yz (1-OLx:sNx+OLx,1-OLy:sNy+OLy) |
79 |
_RL uT (1-OLx:sNx+OLx,1-OLy:sNy+OLy) |
80 |
|
81 |
C !LOCAL VARIABLES: ==================================================== |
82 |
C i,j :: loop indices |
83 |
C uLoc :: volume transported (per time step) |
84 |
C [iMin,iMax]Upd :: loop range to update tracer field |
85 |
C [jMin,jMax]Upd :: loop range to update tracer field |
86 |
C nbStrips :: number of strips (if region to update is splitted) |
87 |
_RL three |
88 |
PARAMETER( three = 3. _d 0 ) |
89 |
INTEGER i,j |
90 |
INTEGER ns, nbStrips |
91 |
INTEGER iMinUpd(2), iMaxUpd(2), jMinUpd(2), jMaxUpd(2) |
92 |
_RL recip_dT |
93 |
_RL slpmax, s1max, s1new, s2new |
94 |
_RL uLoc, alf1, alf1q, alpmn |
95 |
_RL alfp, alpq, alp1, locTp |
96 |
_RL alfn, alnq, aln1, locTn |
97 |
_RL alp (1-OLx:sNx+OLx,1-OLy:sNy+OLy) |
98 |
_RL aln (1-OLx:sNx+OLx,1-OLy:sNy+OLy) |
99 |
_RL fp_v (1-OLx:sNx+OLx,1-OLy:sNy+OLy) |
100 |
_RL fn_v (1-OLx:sNx+OLx,1-OLy:sNy+OLy) |
101 |
_RL fp_o (1-OLx:sNx+OLx,1-OLy:sNy+OLy) |
102 |
_RL fn_o (1-OLx:sNx+OLx,1-OLy:sNy+OLy) |
103 |
_RL fp_x (1-OLx:sNx+OLx,1-OLy:sNy+OLy) |
104 |
_RL fn_x (1-OLx:sNx+OLx,1-OLy:sNy+OLy) |
105 |
_RL fp_y (1-OLx:sNx+OLx,1-OLy:sNy+OLy) |
106 |
_RL fn_y (1-OLx:sNx+OLx,1-OLy:sNy+OLy) |
107 |
_RL fp_z (1-OLx:sNx+OLx,1-OLy:sNy+OLy) |
108 |
_RL fn_z (1-OLx:sNx+OLx,1-OLy:sNy+OLy) |
109 |
_RL fp_xx(1-OLx:sNx+OLx,1-OLy:sNy+OLy) |
110 |
_RL fn_xx(1-OLx:sNx+OLx,1-OLy:sNy+OLy) |
111 |
_RL fp_yy(1-OLx:sNx+OLx,1-OLy:sNy+OLy) |
112 |
_RL fn_yy(1-OLx:sNx+OLx,1-OLy:sNy+OLy) |
113 |
_RL fp_zz(1-OLx:sNx+OLx,1-OLy:sNy+OLy) |
114 |
_RL fn_zz(1-OLx:sNx+OLx,1-OLy:sNy+OLy) |
115 |
_RL fp_xy(1-OLx:sNx+OLx,1-OLy:sNy+OLy) |
116 |
_RL fn_xy(1-OLx:sNx+OLx,1-OLy:sNy+OLy) |
117 |
_RL fp_xz(1-OLx:sNx+OLx,1-OLy:sNy+OLy) |
118 |
_RL fn_xz(1-OLx:sNx+OLx,1-OLy:sNy+OLy) |
119 |
_RL fp_yz(1-OLx:sNx+OLx,1-OLy:sNy+OLy) |
120 |
_RL fn_yz(1-OLx:sNx+OLx,1-OLy:sNy+OLy) |
121 |
CEOP |
122 |
|
123 |
recip_dT = 0. |
124 |
IF ( deltaTloc.GT.zeroRL ) recip_dT = 1.0 _d 0 / deltaTloc |
125 |
|
126 |
C- Set loop ranges for updating tracer field (splitted in 2 strips) |
127 |
nbStrips = 1 |
128 |
iMinUpd(1) = 1-OLx+1 |
129 |
iMaxUpd(1) = sNx+OLx-1 |
130 |
jMinUpd(1) = 1-OLy |
131 |
jMaxUpd(1) = sNy+OLy |
132 |
IF ( overlapOnly ) THEN |
133 |
C update in overlap-Only |
134 |
IF ( W_edge ) iMinUpd(1) = 1 |
135 |
IF ( E_edge ) iMaxUpd(1) = sNx |
136 |
IF ( S_edge ) THEN |
137 |
jMinUpd(1) = 1-OLy |
138 |
jMaxUpd(1) = 0 |
139 |
ENDIF |
140 |
IF ( N_edge ) THEN |
141 |
IF ( S_edge ) nbStrips = 2 |
142 |
jMinUpd(nbStrips) = sNy+1 |
143 |
jMaxUpd(nbStrips) = sNy+OLy |
144 |
ENDIF |
145 |
ELSE |
146 |
C do not only update the overlap |
147 |
IF ( interiorOnly .AND. S_edge ) jMinUpd(1) = 1 |
148 |
IF ( interiorOnly .AND. N_edge ) jMaxUpd(1) = sNy |
149 |
ENDIF |
150 |
|
151 |
C-- start 1rst loop on strip number "ns" |
152 |
DO ns=1,nbStrips |
153 |
|
154 |
IF ( limiter.EQ.1 ) THEN |
155 |
DO j=jMinUpd(ns),jMaxUpd(ns) |
156 |
DO i=iMinUpd(1)-1,iMaxUpd(1)+1 |
157 |
C If flux-limiting transport is to be applied, place limits on |
158 |
C appropriate moments before transport. |
159 |
slpmax = 0. |
160 |
IF ( sm_o(i,j).GT.zeroRL ) slpmax = sm_o(i,j) |
161 |
s1max = slpmax*1.5 _d 0 |
162 |
s1new = MIN( s1max, MAX(-s1max,sm_x(i,j)) ) |
163 |
s2new = MIN( (slpmax+slpmax-ABS(s1new)/three), |
164 |
& MAX(ABS(s1new)-slpmax,sm_xx(i,j)) ) |
165 |
sm_xy(i,j) = MIN( slpmax, MAX(-slpmax,sm_xy(i,j)) ) |
166 |
sm_xz(i,j) = MIN( slpmax, MAX(-slpmax,sm_xz(i,j)) ) |
167 |
sm_x (i,j) = s1new |
168 |
sm_xx(i,j) = s2new |
169 |
ENDDO |
170 |
ENDDO |
171 |
ENDIF |
172 |
|
173 |
C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----| |
174 |
C--- part.1 : calculate flux for all moments |
175 |
DO j=jMinUpd(ns),jMaxUpd(ns) |
176 |
DO i=iMinUpd(1),iMaxUpd(1)+1 |
177 |
uLoc = uTrans(i,j)*deltaTloc |
178 |
C-- Flux from (i-1) to (i) when U>0 (i.e., take right side of box i-1) |
179 |
fp_v (i,j) = MAX( zeroRL, uLoc ) |
180 |
alp (i,j) = fp_v(i,j)/sm_v(i-1,j) |
181 |
alpq = alp(i,j)*alp(i,j) |
182 |
alp1 = 1. _d 0 - alp(i,j) |
183 |
C- Create temporary moments/masses for partial boxes in transit |
184 |
C use same indexing as velocity, "p" for positive U |
185 |
fp_o (i,j) = alp(i,j)*( sm_o(i-1,j) + alp1*sm_x(i-1,j) |
186 |
& + alp1*(alp1-alp(i,j))*sm_xx(i-1,j) |
187 |
& ) |
188 |
fp_x (i,j) = alpq *( sm_x(i-1,j) + three*alp1*sm_xx(i-1,j) ) |
189 |
fp_xx(i,j) = alp(i,j)*alpq*sm_xx(i-1,j) |
190 |
fp_y (i,j) = alp(i,j)*( sm_y(i-1,j) + alp1*sm_xy(i-1,j) ) |
191 |
fp_z (i,j) = alp(i,j)*( sm_z(i-1,j) + alp1*sm_xz(i-1,j) ) |
192 |
fp_xy(i,j) = alpq *sm_xy(i-1,j) |
193 |
fp_xz(i,j) = alpq *sm_xz(i-1,j) |
194 |
fp_yy(i,j) = alp(i,j)*sm_yy(i-1,j) |
195 |
fp_zz(i,j) = alp(i,j)*sm_zz(i-1,j) |
196 |
fp_yz(i,j) = alp(i,j)*sm_yz(i-1,j) |
197 |
C-- Flux from (i) to (i-1) when U<0 (i.e., take left side of box i) |
198 |
fn_v (i,j) = MAX( zeroRL, -uLoc ) |
199 |
aln (i,j) = fn_v(i,j)/sm_v( i ,j) |
200 |
alnq = aln(i,j)*aln(i,j) |
201 |
aln1 = 1. _d 0 - aln(i,j) |
202 |
C- Create temporary moments/masses for partial boxes in transit |
203 |
C use same indexing as velocity, "n" for negative U |
204 |
fn_o (i,j) = aln(i,j)*( sm_o( i ,j) - aln1*sm_x( i ,j) |
205 |
& + aln1*(aln1-aln(i,j))*sm_xx( i ,j) |
206 |
& ) |
207 |
fn_x (i,j) = alnq *( sm_x( i ,j) - three*aln1*sm_xx( i ,j) ) |
208 |
fn_xx(i,j) = aln(i,j)*alnq*sm_xx( i ,j) |
209 |
fn_y (i,j) = aln(i,j)*( sm_y( i ,j) - aln1*sm_xy( i ,j) ) |
210 |
fn_z (i,j) = aln(i,j)*( sm_z( i ,j) - aln1*sm_xz( i ,j) ) |
211 |
fn_xy(i,j) = alnq *sm_xy( i ,j) |
212 |
fn_xz(i,j) = alnq *sm_xz( i ,j) |
213 |
fn_yy(i,j) = aln(i,j)*sm_yy( i ,j) |
214 |
fn_zz(i,j) = aln(i,j)*sm_zz( i ,j) |
215 |
fn_yz(i,j) = aln(i,j)*sm_yz( i ,j) |
216 |
C-- Save zero-order flux: |
217 |
uT(i,j) = ( fp_o(i,j) - fn_o(i,j) )*recip_dT |
218 |
ENDDO |
219 |
ENDDO |
220 |
|
221 |
C-- end 1rst loop on strip number "ns" |
222 |
c ENDDO |
223 |
|
224 |
C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----| |
225 |
C-- start 2nd loop on strip number "ns" |
226 |
c DO ns=1,nbStrips |
227 |
|
228 |
C--- part.2 : re-adjust moments remaining in the box |
229 |
C take off from grid box (i): negative U(i) and positive U(i+1) |
230 |
DO j=jMinUpd(ns),jMaxUpd(ns) |
231 |
DO i=iMinUpd(1),iMaxUpd(1) |
232 |
#ifdef ALLOW_OBCS |
233 |
IF ( maskIn(i,j).NE.zeroRS ) THEN |
234 |
#endif /* ALLOW_OBCS */ |
235 |
alf1 = 1. _d 0 - aln(i,j) - alp(i+1,j) |
236 |
alf1q = alf1*alf1 |
237 |
alpmn = alp(i+1,j) - aln(i,j) |
238 |
sm_v (i,j) = sm_v (i,j) - fn_v (i,j) - fp_v (i+1,j) |
239 |
sm_o (i,j) = sm_o (i,j) - fn_o (i,j) - fp_o (i+1,j) |
240 |
sm_x (i,j) = alf1q*( sm_x(i,j) - three*alpmn*sm_xx(i,j) ) |
241 |
sm_xx(i,j) = alf1*alf1q*sm_xx(i,j) |
242 |
sm_xy(i,j) = alf1q*sm_xy(i,j) |
243 |
sm_xz(i,j) = alf1q*sm_xz(i,j) |
244 |
sm_y (i,j) = sm_y (i,j) - fn_y (i,j) - fp_y (i+1,j) |
245 |
sm_yy(i,j) = sm_yy(i,j) - fn_yy(i,j) - fp_yy(i+1,j) |
246 |
sm_z (i,j) = sm_z (i,j) - fn_z (i,j) - fp_z (i+1,j) |
247 |
sm_zz(i,j) = sm_zz(i,j) - fn_zz(i,j) - fp_zz(i+1,j) |
248 |
sm_yz(i,j) = sm_yz(i,j) - fn_yz(i,j) - fp_yz(i+1,j) |
249 |
#ifdef ALLOW_OBCS |
250 |
ENDIF |
251 |
#endif /* ALLOW_OBCS */ |
252 |
ENDDO |
253 |
ENDDO |
254 |
|
255 |
C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----| |
256 |
C--- part.3 : Put the temporary moments into appropriate neighboring boxes |
257 |
C add into grid box (i): positive U(i) and negative U(i+1) |
258 |
DO j=jMinUpd(ns),jMaxUpd(ns) |
259 |
DO i=iMinUpd(1),iMaxUpd(1) |
260 |
#ifdef ALLOW_OBCS |
261 |
IF ( maskIn(i,j).NE.zeroRS ) THEN |
262 |
#endif /* ALLOW_OBCS */ |
263 |
sm_v (i,j) = sm_v (i,j) + fp_v (i,j) + fn_v (i+1,j) |
264 |
alfp = fp_v( i ,j)/sm_v(i,j) |
265 |
alfn = fn_v(i+1,j)/sm_v(i,j) |
266 |
alf1 = 1. _d 0 - alfp - alfn |
267 |
alp1 = 1. _d 0 - alfp |
268 |
aln1 = 1. _d 0 - alfn |
269 |
alpmn = alfp - alfn |
270 |
locTp = alfp*sm_o(i,j) - alp1*fp_o(i,j) |
271 |
locTn = alfn*sm_o(i,j) - aln1*fn_o(i+1,j) |
272 |
sm_xx(i,j) = alf1*alf1*sm_xx(i,j) + alfp*alfp*fp_xx(i,j) |
273 |
& + alfn*alfn*fn_xx(i+1,j) |
274 |
& - 5. _d 0*(-alpmn*alf1*sm_x(i,j) + alfp*alp1*fp_x(i,j) |
275 |
& - alfn*aln1*fn_x(i+1,j) |
276 |
& + twoRL*alfp*alfn*sm_o(i,j) + (alp1-alfp)*locTp |
277 |
& + (aln1-alfn)*locTn |
278 |
& ) |
279 |
sm_xy(i,j) = alf1*sm_xy(i,j) + alfp*fp_xy(i,j) |
280 |
& + alfn*fn_xy(i+1,j) |
281 |
& + three*( alpmn*sm_y(i,j) - alp1*fp_y(i,j) |
282 |
& + aln1*fn_y(i+1,j) |
283 |
& ) |
284 |
sm_xz(i,j) = alf1*sm_xz(i,j) + alfp*fp_xz(i,j) |
285 |
& + alfn*fn_xz(i+1,j) |
286 |
& + three*( alpmn*sm_z(i,j) - alp1*fp_z(i,j) |
287 |
& + aln1*fn_z(i+1,j) |
288 |
& ) |
289 |
sm_x (i,j) = alf1*sm_x(i,j) + alfp*fp_x(i,j) + alfn*fn_x(i+1,j) |
290 |
& + three*( locTp - locTn ) |
291 |
sm_o (i,j) = sm_o (i,j) + fp_o (i,j) + fn_o (i+1,j) |
292 |
sm_y (i,j) = sm_y (i,j) + fp_y (i,j) + fn_y (i+1,j) |
293 |
sm_yy(i,j) = sm_yy(i,j) + fp_yy(i,j) + fn_yy(i+1,j) |
294 |
sm_z (i,j) = sm_z (i,j) + fp_z (i,j) + fn_z (i+1,j) |
295 |
sm_zz(i,j) = sm_zz(i,j) + fp_zz(i,j) + fn_zz(i+1,j) |
296 |
sm_yz(i,j) = sm_yz(i,j) + fp_yz(i,j) + fn_yz(i+1,j) |
297 |
#ifdef ALLOW_OBCS |
298 |
ENDIF |
299 |
#endif /* ALLOW_OBCS */ |
300 |
ENDDO |
301 |
ENDDO |
302 |
|
303 |
C-- end 2nd loop on strip number "ns" |
304 |
ENDDO |
305 |
|
306 |
RETURN |
307 |
END |