1 |
C $Header: /u/gcmpack/MITgcm/model/src/integr_continuity.F,v 1.27 2011/12/08 22:35:43 jmc Exp $ |
2 |
C $Name: $ |
3 |
|
4 |
#include "PACKAGES_CONFIG.h" |
5 |
#include "CPP_OPTIONS.h" |
6 |
|
7 |
CBOP |
8 |
C !ROUTINE: INTEGR_CONTINUITY |
9 |
C !INTERFACE: |
10 |
SUBROUTINE INTEGR_CONTINUITY( |
11 |
I uFld, vFld, |
12 |
I myTime, myIter, myThid ) |
13 |
C !DESCRIPTION: \bv |
14 |
C *==========================================================* |
15 |
C | SUBROUTINE INTEGR_CONTINUITY |
16 |
C | o Integrate the continuity Eq : compute vertical velocity |
17 |
C | and free surface "r-anomaly" (etaN,etaH) to satisfy |
18 |
C | exactly the conservation of the Total Volume |
19 |
C *==========================================================* |
20 |
C \ev |
21 |
|
22 |
C !USES: |
23 |
IMPLICIT NONE |
24 |
C == Global variables |
25 |
#include "SIZE.h" |
26 |
#include "EEPARAMS.h" |
27 |
#include "PARAMS.h" |
28 |
#include "DYNVARS.h" |
29 |
#include "GRID.h" |
30 |
#include "SURFACE.h" |
31 |
#include "FFIELDS.h" |
32 |
|
33 |
C !INPUT/OUTPUT PARAMETERS: |
34 |
C == Routine arguments == |
35 |
C uFld :: Zonal velocity ( m/s ) |
36 |
C vFld :: Meridional velocity ( m/s ) |
37 |
C myTime :: Current time in simulation |
38 |
C myIter :: Current iteration number in simulation |
39 |
C myThid :: my Thread Id. number |
40 |
_RL myTime |
41 |
INTEGER myIter |
42 |
INTEGER myThid |
43 |
_RL uFld(1-OLx:sNx+OLx,1-OLy:sNy+OLy,Nr,nSx,nSy) |
44 |
_RL vFld(1-OLx:sNx+OLx,1-OLy:sNy+OLy,Nr,nSx,nSy) |
45 |
|
46 |
C !LOCAL VARIABLES: |
47 |
C Local variables in common block |
48 |
|
49 |
C Local variables |
50 |
C bi,bj :: tile index |
51 |
C i,j,k :: Loop counters |
52 |
C uTrans :: Volume transports ( uVel.xA ) |
53 |
C vTrans :: Volume transports ( vVel.yA ) |
54 |
C hDivFlow :: Div. Barotropic Flow [transport unit m3/s] |
55 |
INTEGER k,bi,bj |
56 |
#ifdef EXACT_CONSERV |
57 |
INTEGER i, j |
58 |
INTEGER ks |
59 |
_RL uTrans(1-OLx:sNx+OLx,1-OLy:sNy+OLy) |
60 |
_RL vTrans(1-OLx:sNx+OLx,1-OLy:sNy+OLy) |
61 |
_RL hDivFlow(1-OLx:sNx+OLx,1-OLy:sNy+OLy) |
62 |
_RL facEmP, facMass |
63 |
#else /* EXACT_CONSERV */ |
64 |
# ifdef ALLOW_OBCS |
65 |
INTEGER i, j |
66 |
# endif |
67 |
#endif /* EXACT_CONSERV */ |
68 |
#ifndef ALLOW_ADDFLUID |
69 |
_RL addMass(1) |
70 |
#endif /* ndef ALLOW_ADDFLUID */ |
71 |
#if (defined NONLIN_FRSURF) && !(defined DISABLE_RSTAR_CODE) |
72 |
_RL rStarDhDt(1-OLx:sNx+OLx,1-OLy:sNy+OLy) |
73 |
#else |
74 |
_RL rStarDhDt(1) |
75 |
#endif |
76 |
CEOP |
77 |
|
78 |
C-- Start bi,bj loops |
79 |
DO bj=myByLo(myThid),myByHi(myThid) |
80 |
DO bi=myBxLo(myThid),myBxHi(myThid) |
81 |
|
82 |
C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----| |
83 |
|
84 |
#ifdef EXACT_CONSERV |
85 |
IF (exactConserv) THEN |
86 |
|
87 |
facEmP = 0. |
88 |
IF ( fluidIsWater.AND.useRealFreshWaterFlux ) facEmP=mass2rUnit |
89 |
facMass = 0. |
90 |
IF ( selectAddFluid.GE.1 ) facMass = mass2rUnit |
91 |
|
92 |
C-- Compute the Divergence of The Barotropic Flow : |
93 |
|
94 |
C- Initialise |
95 |
DO j=1-OLy,sNy+OLy |
96 |
DO i=1-OLx,sNx+OLx |
97 |
hDivFlow(i,j) = 0. _d 0 |
98 |
utrans(i,j) = 0. _d 0 |
99 |
vtrans(i,j) = 0. _d 0 |
100 |
ENDDO |
101 |
ENDDO |
102 |
|
103 |
DO k=1,Nr |
104 |
|
105 |
C- Calculate velocity field "volume transports" through tracer cell faces |
106 |
C anelastic: uTrans,vTrans are scaled by rhoFacC (~ mass transport). |
107 |
DO j=1,sNy+1 |
108 |
DO i=1,sNx+1 |
109 |
uTrans(i,j) = uFld(i,j,k,bi,bj)*_dyG(i,j,bi,bj) |
110 |
& *deepFacC(k)*rhoFacC(k) |
111 |
& *drF(k)*_hFacW(i,j,k,bi,bj) |
112 |
vTrans(i,j) = vFld(i,j,k,bi,bj)*_dxG(i,j,bi,bj) |
113 |
& *deepFacC(k)*rhoFacC(k) |
114 |
& *drF(k)*_hFacS(i,j,k,bi,bj) |
115 |
ENDDO |
116 |
ENDDO |
117 |
|
118 |
C- Integrate vertically the Horizontal Divergence |
119 |
DO j=1,sNy |
120 |
DO i=1,sNx |
121 |
hDivFlow(i,j) = hDivFlow(i,j) |
122 |
& +maskC(i,j,k,bi,bj)*( uTrans(i+1,j)-uTrans(i,j) |
123 |
& +vTrans(i,j+1)-vTrans(i,j) ) |
124 |
#ifdef ALLOW_ADDFLUID |
125 |
& -facMass*addMass(i,j,k,bi,bj) |
126 |
#endif /* ALLOW_ADDFLUID */ |
127 |
ENDDO |
128 |
ENDDO |
129 |
|
130 |
C- End DO k=1,Nr |
131 |
ENDDO |
132 |
|
133 |
C------------------------------------ |
134 |
C note: deep-model not implemented for P-coordinate + realFreshWaterFlux ; |
135 |
C anelastic: always assumes that rhoFacF(1) = 1 |
136 |
IF ( myIter.EQ.nIter0 .AND. myIter.NE.0 |
137 |
& .AND. fluidIsWater .AND. useRealFreshWaterFlux ) THEN |
138 |
|
139 |
C needs previous time-step value of E-P-R, that has not been loaded |
140 |
C and was not in old pickup-file ; try to use etaN & etaH instead. |
141 |
IF ( usePickupBeforeC54 ) THEN |
142 |
DO j=1,sNy |
143 |
DO i=1,sNx |
144 |
dEtaHdt(i,j,bi,bj) = (etaN(i,j,bi,bj)-etaH(i,j,bi,bj)) |
145 |
& / (implicDiv2Dflow*deltaTfreesurf) |
146 |
ENDDO |
147 |
ENDDO |
148 |
ENDIF |
149 |
|
150 |
DO j=1,sNy |
151 |
DO i=1,sNx |
152 |
PmEpR(i,j,bi,bj) = dEtaHdt(i,j,bi,bj) |
153 |
& + hDivFlow(i,j)*recip_rA(i,j,bi,bj) |
154 |
& *recip_deepFac2F(1) |
155 |
PmEpR(i,j,bi,bj) = PmEpR(i,j,bi,bj)*rUnit2mass |
156 |
ENDDO |
157 |
ENDDO |
158 |
ELSEIF ( myIter.EQ.nIter0 ) THEN |
159 |
DO j=1,sNy |
160 |
DO i=1,sNx |
161 |
ks = kSurfC(I,J,bi,bj) |
162 |
PmEpR(i,j,bi,bj) = 0. _d 0 |
163 |
dEtaHdt(i,j,bi,bj) = -hDivFlow(i,j)*recip_rA(i,j,bi,bj) |
164 |
& *recip_deepFac2F(ks) |
165 |
ENDDO |
166 |
ENDDO |
167 |
ELSE |
168 |
C-- Needs to get valid PmEpR (for T,S forcing) also in overlap regions |
169 |
C (e.g., if using KPP) => set over full index range |
170 |
DO j=1-OLy,sNy+OLy |
171 |
DO i=1-OLx,sNx+OLx |
172 |
PmEpR(i,j,bi,bj) = -EmPmR(i,j,bi,bj) |
173 |
ENDDO |
174 |
ENDDO |
175 |
DO j=1,sNy |
176 |
DO i=1,sNx |
177 |
ks = kSurfC(i,j,bi,bj) |
178 |
dEtaHdt(i,j,bi,bj) = -hDivFlow(i,j)*recip_rA(i,j,bi,bj) |
179 |
& *recip_deepFac2F(ks) |
180 |
& -facEmP*EmPmR(i,j,bi,bj) |
181 |
ENDDO |
182 |
ENDDO |
183 |
ENDIF |
184 |
C------------------------------------ |
185 |
|
186 |
#ifdef ALLOW_OBCS |
187 |
C-- reset dEtaHdt to zero outside the OB interior region |
188 |
IF ( useOBCS ) THEN |
189 |
DO j=1,sNy |
190 |
DO i=1,sNx |
191 |
dEtaHdt(i,j,bi,bj) = dEtaHdt(i,j,bi,bj)*maskInC(i,j,bi,bj) |
192 |
ENDDO |
193 |
ENDDO |
194 |
ENDIF |
195 |
#endif /* ALLOW_OBCS */ |
196 |
|
197 |
C-- end if exactConserv block |
198 |
ENDIF |
199 |
|
200 |
C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----| |
201 |
|
202 |
IF ( exactConserv .AND. myIter.NE.nIter0 ) THEN |
203 |
C-- Update etaN at the end of the time step : |
204 |
C Incorporate the Implicit part of -Divergence(Barotropic_Flow) |
205 |
|
206 |
IF (implicDiv2Dflow.EQ. 0. _d 0) THEN |
207 |
DO j=1-OLy,sNy+OLy |
208 |
DO i=1-OLx,sNx+OLx |
209 |
etaN(i,j,bi,bj) = etaH(i,j,bi,bj) |
210 |
ENDDO |
211 |
ENDDO |
212 |
ELSE |
213 |
DO j=1,sNy |
214 |
DO i=1,sNx |
215 |
etaN(i,j,bi,bj) = etaH(i,j,bi,bj) |
216 |
& + implicDiv2Dflow*dEtaHdt(i,j,bi,bj)*deltaTfreesurf |
217 |
ENDDO |
218 |
ENDDO |
219 |
ENDIF |
220 |
|
221 |
#ifdef ALLOW_OBCS |
222 |
C-- Was added on Dec 30, 2004 (to fix unrealistic etaN ?), but no longer |
223 |
C needed with proper masking in solver (matrix+cg2d_b,x) and masking |
224 |
C of dEtaHdt above. etaN next to OB does not enter present algorithm but |
225 |
C leave it commented out in case we would implement an aternative scheme. |
226 |
c IF ( useOBCS ) CALL OBCS_APPLY_ETA( bi, bj, etaN, myThid ) |
227 |
#endif /* ALLOW_OBCS */ |
228 |
|
229 |
C-- end if exactConserv and not myIter=nIter0 block |
230 |
ENDIF |
231 |
|
232 |
C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----| |
233 |
|
234 |
# ifdef NONLIN_FRSURF |
235 |
IF (select_rStar .NE. 0) THEN |
236 |
# ifndef DISABLE_RSTAR_CODE |
237 |
C-- note: rStarDhDt is similar to rStarDhCDt from S/R CALC_R_STAR |
238 |
C except for deep-factor and rho factor. |
239 |
DO j=1,sNy |
240 |
DO i=1,sNx |
241 |
ks = kSurfC(i,j,bi,bj) |
242 |
rStarDhDt(i,j) = dEtaHdt(i,j,bi,bj) |
243 |
& *deepFac2F(ks)*rhoFacF(ks) |
244 |
& *recip_Rcol(i,j,bi,bj) |
245 |
ENDDO |
246 |
ENDDO |
247 |
# endif /* DISABLE_RSTAR_CODE */ |
248 |
ENDIF |
249 |
# endif /* NONLIN_FRSURF */ |
250 |
|
251 |
#endif /* EXACT_CONSERV */ |
252 |
|
253 |
C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----| |
254 |
|
255 |
DO k=Nr,1,-1 |
256 |
C-- Integrate continuity vertically for vertical velocity |
257 |
|
258 |
CALL INTEGRATE_FOR_W( |
259 |
I bi, bj, k, uFld, vFld, |
260 |
I addMass, rStarDhDt, |
261 |
O wVel, |
262 |
I myThid ) |
263 |
|
264 |
#ifdef EXACT_CONSERV |
265 |
IF ( k.EQ.Nr .AND. myIter.NE.0 .AND. usingPCoords |
266 |
& .AND. fluidIsWater .AND. useRealFreshWaterFlux ) THEN |
267 |
|
268 |
DO j=1,sNy |
269 |
DO i=1,sNx |
270 |
wVel(i,j,k,bi,bj) = wVel(i,j,k,bi,bj) |
271 |
& +mass2rUnit*PmEpR(i,j,bi,bj)*maskC(i,j,k,bi,bj) |
272 |
ENDDO |
273 |
ENDDO |
274 |
|
275 |
ENDIF |
276 |
#endif /* EXACT_CONSERV */ |
277 |
|
278 |
#ifdef ALLOW_OBCS |
279 |
C-- reset W to zero outside the OB interior region |
280 |
IF ( useOBCS ) THEN |
281 |
DO j=1,sNy |
282 |
DO i=1,sNx |
283 |
wVel(i,j,k,bi,bj) = wVel(i,j,k,bi,bj)*maskInC(i,j,bi,bj) |
284 |
ENDDO |
285 |
ENDDO |
286 |
ENDIF |
287 |
C-- Apply OBC to W (non-hydrostatic): |
288 |
IF ( useOBCS.AND.nonHydrostatic ) |
289 |
& CALL OBCS_APPLY_W( bi, bj, k, wVel, myThid ) |
290 |
#endif /* ALLOW_OBCS */ |
291 |
|
292 |
C- End DO k=Nr,1,-1 |
293 |
ENDDO |
294 |
|
295 |
C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----| |
296 |
|
297 |
C-- End bi,bj loops |
298 |
ENDDO |
299 |
ENDDO |
300 |
|
301 |
IF ( exactConserv .AND. myIter.NE.nIter0 |
302 |
& .AND. implicDiv2Dflow .NE. 0. _d 0 ) |
303 |
& _EXCH_XY_RL( etaN , myThid ) |
304 |
IF ( implicitIntGravWave .OR. myIter.EQ.nIter0 ) |
305 |
& _EXCH_XYZ_RL( wVel , myThid ) |
306 |
|
307 |
#ifdef EXACT_CONSERV |
308 |
C-- Update etaH (from etaN and dEtaHdt): |
309 |
IF (exactConserv) THEN |
310 |
c IF ( useRealFreshWaterFlux .AND. myIter.EQ.nIter0 ) |
311 |
c & _EXCH_XY_RL( PmEpR, myThid ) |
312 |
#ifdef ALLOW_DEBUG |
313 |
IF (debugMode) CALL DEBUG_CALL('UPDATE_ETAH',myThid) |
314 |
#endif |
315 |
CALL UPDATE_ETAH( myTime, myIter, myThid ) |
316 |
ENDIF |
317 |
|
318 |
#ifdef NONLIN_FRSURF |
319 |
# ifndef DISABLE_SIGMA_CODE |
320 |
IF ( nonlinFreeSurf.GT.0 .AND. selectSigmaCoord.NE.0 ) THEN |
321 |
CALL EXCH_XY_RL( dEtaHdt, myThid ) |
322 |
CALL UPDATE_ETAWS( myTime, myIter, myThid ) |
323 |
ENDIF |
324 |
# endif /* DISABLE_SIGMA_CODE */ |
325 |
#endif /* NONLIN_FRSURF */ |
326 |
|
327 |
#endif /* EXACT_CONSERV */ |
328 |
|
329 |
RETURN |
330 |
END |