/[MITgcm]/MITgcm/model/src/calc_phi_hyd.F
ViewVC logotype

Contents of /MITgcm/model/src/calc_phi_hyd.F

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.23 - (show annotations) (download)
Fri Nov 15 03:01:21 2002 UTC (21 years, 6 months ago) by heimbach
Branch: MAIN
CVS Tags: checkpoint47a_post, checkpoint47b_post, checkpoint47
Changes since 1.22: +10 -4 lines
differentiable version of checkpoint46n_post
o external_fields_load now part of differentiation list
o pressure needs multiple storing;
  would be nice to have store_pressure at beginning or
  end of forward_step, e.g. by having phiHyd global (5-dim.)
  (NB: pressure is needed for certain cases in find_rho,
  which is also invoked through convective_adjustment).
o recomputations in find_rho for cases
 'JMD95'/'UNESCO' or 'MDJWF' are OK.
o #define ATMOSPHERIC_LOADING should be differentiable
o ini_forcing shifted to begining of initialise_varia

1 C $Header: /u/gcmpack/MITgcm/model/src/calc_phi_hyd.F,v 1.22 2002/11/07 21:51:15 adcroft Exp $
2 C $Name: $
3
4 #include "CPP_OPTIONS.h"
5
6 CBOP
7 C !ROUTINE: CALC_PHI_HYD
8 C !INTERFACE:
9 SUBROUTINE CALC_PHI_HYD(
10 I bi, bj, iMin, iMax, jMin, jMax, K,
11 I tFld, sFld,
12 U phiHyd,
13 I myThid)
14 C !DESCRIPTION: \bv
15 C *==========================================================*
16 C | SUBROUTINE CALC_PHI_HYD |
17 C | o Integrate the hydrostatic relation to find the Hydros. |
18 C *==========================================================*
19 C | Potential (ocean: Pressure/rho ; atmos = geopotential)|
20 C | On entry: |
21 C | tFld,sFld are the current thermodynamics quantities|
22 C | (unchanged on exit) |
23 C | phiHyd(i,j,1:k-1) is the hydrostatic Potential |
24 C | at cell centers (tracer points) |
25 C | - 1:k-1 layers are valid |
26 C | - k:Nr layers are invalid |
27 C | phiHyd(i,j,k) is the hydrostatic Potential |
28 C | (ocean only_^) at cell the interface k (w point above) |
29 C | On exit: |
30 C | phiHyd(i,j,1:k) is the hydrostatic Potential |
31 C | at cell centers (tracer points) |
32 C | - 1:k layers are valid |
33 C | - k+1:Nr layers are invalid |
34 C | phiHyd(i,j,k+1) is the hydrostatic Potential (P/rho) |
35 C | (ocean only-^) at cell the interface k+1 (w point below)|
36 C | Atmosphere: |
37 C | Integr_GeoPot allows to select one integration method |
38 C | (see the list below) |
39 C *==========================================================*
40 C \ev
41 C !USES:
42 IMPLICIT NONE
43 C == Global variables ==
44 #include "SIZE.h"
45 #include "GRID.h"
46 #include "EEPARAMS.h"
47 #include "PARAMS.h"
48 #include "FFIELDS.h"
49 #ifdef ALLOW_AUTODIFF_TAMC
50 #include "tamc.h"
51 #include "tamc_keys.h"
52 #endif /* ALLOW_AUTODIFF_TAMC */
53 #include "SURFACE.h"
54 #include "DYNVARS.h"
55
56 C !INPUT/OUTPUT PARAMETERS:
57 C == Routine arguments ==
58 INTEGER bi,bj,iMin,iMax,jMin,jMax,K
59 _RL tFld(1-OLx:sNx+OLx,1-OLy:sNy+OLy,Nr,nSx,nSy)
60 _RL sFld(1-OLx:sNx+OLx,1-OLy:sNy+OLy,Nr,nSx,nSy)
61 _RL phiHyd(1-OLx:sNx+OLx,1-OLy:sNy+OLy,Nr)
62 INTEGER myThid
63
64 #ifdef INCLUDE_PHIHYD_CALCULATION_CODE
65
66 C !LOCAL VARIABLES:
67 C == Local variables ==
68 INTEGER i,j, Kp1
69 _RL zero, one, half
70 _RL alphaRho(1-OLx:sNx+OLx,1-OLy:sNy+OLy)
71 _RL dRloc,dRlocKp1,locAlpha
72 _RL ddPI, ddPIm, ddPIp, ratioRp, ratioRm
73 CEOP
74
75 zero = 0. _d 0
76 one = 1. _d 0
77 half = .5 _d 0
78
79 C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----|
80 C Atmosphere:
81 C Integr_GeoPot => select one option for the integration of the Geopotential:
82 C = 0 : Energy Conserving Form, No hFac ;
83 C = 1 : Finite Volume Form, with hFac, linear in P by Half level;
84 C =2,3: Finite Difference Form, with hFac, linear in P between 2 Tracer levels
85 C 2 : case Tracer level at the middle of InterFace_W;
86 C 3 : case InterFace_W at the middle of Tracer levels;
87 C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----|
88
89 #ifdef ALLOW_AUTODIFF_TAMC
90 act1 = bi - myBxLo(myThid)
91 max1 = myBxHi(myThid) - myBxLo(myThid) + 1
92
93 act2 = bj - myByLo(myThid)
94 max2 = myByHi(myThid) - myByLo(myThid) + 1
95
96 act3 = myThid - 1
97 max3 = nTx*nTy
98
99 act4 = ikey_dynamics - 1
100
101 ikey = (act1 + 1) + act2*max1
102 & + act3*max1*max2
103 & + act4*max1*max2*max3
104 #endif /* ALLOW_AUTODIFF_TAMC */
105
106 IF ( buoyancyRelation .eq. 'OCEANIC' ) THEN
107 C This is the hydrostatic pressure calculation for the Ocean
108 C which uses the FIND_RHO() routine to calculate density
109 C before integrating g*rho over the current layer/interface
110
111 dRloc=drC(k)
112 IF (k.EQ.1) dRloc=drF(1)
113 IF (k.EQ.Nr) THEN
114 dRlocKp1=0.
115 ELSE
116 dRlocKp1=drC(k+1)
117 ENDIF
118
119 C-- If this is the top layer we impose the boundary condition
120 C P(z=eta) = P(atmospheric_loading)
121 IF (k.EQ.1) THEN
122 DO j=jMin,jMax
123 DO i=iMin,iMax
124 #ifdef ATMOSPHERIC_LOADING
125 phiHyd(i,j,k)=pload(i,j,bi,bj)*recip_rhoConst
126 #else
127 phiHyd(i,j,k)=0. _d 0
128 #endif
129 ENDDO
130 ENDDO
131 ENDIF
132
133 C Calculate density
134 #ifdef ALLOW_AUTODIFF_TAMC
135 kkey = (ikey-1)*Nr + k
136 CADJ STORE tFld (:,:,k,bi,bj) = comlev1_bibj_k, key=kkey, byte=isbyte
137 CADJ STORE sFld (:,:,k,bi,bj) = comlev1_bibj_k, key=kkey, byte=isbyte
138 #endif /* ALLOW_AUTODIFF_TAMC */
139 CALL FIND_RHO( bi, bj, iMin, iMax, jMin, jMax, k, k,
140 & tFld, sFld,
141 & alphaRho, myThid)
142
143 C Quasi-hydrostatic terms are added in as if they modify the buoyancy
144 IF (quasiHydrostatic) THEN
145 CALL QUASIHYDROSTATICTERMS(bi,bj,k,alphaRho,myThid)
146 ENDIF
147
148 C Hydrostatic pressure at cell centers
149 DO j=jMin,jMax
150 DO i=iMin,iMax
151 #ifdef ALLOW_AUTODIFF_TAMC
152 c Patrick, is this directive correct or even necessary in
153 c this new code?
154 c Yes, because of phiHyd(i,j,k+1)=phiHyd(i,j,k)+...
155 c within the k-loop.
156 CADJ GENERAL
157 #endif /* ALLOW_AUTODIFF_TAMC */
158
159 CmlC---------- This discretization is the "finite volume" form
160 CmlC which has not been used to date since it does not
161 CmlC conserve KE+PE exactly even though it is more natural
162 CmlC
163 Cml IF ( K .EQ. kLowC(i,j,bi,bj) ) THEN
164 Cml phiHydLow(i,j,bi,bj) = phiHyd(i,j,k)
165 Cml & + hFacC(i,j,k,bi,bj)
166 Cml & *drF(K)*gravity*alphaRho(i,j)*recip_rhoConst
167 Cml & + gravity*etaN(i,j,bi,bj)
168 Cml ENDIF
169 Cml IF (k.LT.Nr) phiHyd(i,j,k+1)=phiHyd(i,j,k)+
170 Cml & drF(K)*gravity*alphaRho(i,j)*recip_rhoConst
171 Cml phiHyd(i,j,k)=phiHyd(i,j,k)+
172 Cml & 0.5*drF(K)*gravity*alphaRho(i,j)*recip_rhoConst
173 CmlC-----------------------------------------------------------------------
174
175 C---------- This discretization is the "energy conserving" form
176 C which has been used since at least Adcroft et al., MWR 1997
177 C
178
179 phiHyd(i,j,k)=phiHyd(i,j,k)+
180 & 0.5*dRloc*gravity*alphaRho(i,j)*recip_rhoConst
181 IF (k.LT.Nr) phiHyd(i,j,k+1)=phiHyd(i,j,k)+
182 & 0.5*dRlocKp1*gravity*alphaRho(i,j)*recip_rhoConst
183 C-----------------------------------------------------------------------
184
185 C---------- Compute bottom pressure deviation from gravity*rho0*H
186 C This has to be done starting from phiHyd at the current
187 C tracer point and .5 of the cell's thickness has to be
188 C substracted from hFacC
189 IF ( K .EQ. kLowC(i,j,bi,bj) ) THEN
190 phiHydLow(i,j,bi,bj) = phiHyd(i,j,k)
191 & + (hFacC(i,j,k,bi,bj)-.5)*drF(K)
192 & *gravity*alphaRho(i,j)*recip_rhoConst
193 & + gravity*etaN(i,j,bi,bj)
194 ENDIF
195 C-----------------------------------------------------------------------
196
197 ENDDO
198 ENDDO
199
200 ELSEIF ( buoyancyRelation .eq. 'OCEANICP' ) THEN
201 C This is the hydrostatic pressure calculation for the Ocean
202 C which uses the FIND_RHO() routine to calculate density
203 C before integrating g*rho over the current layer/interface
204 #ifdef ALLOW_AUTODIFF_TAMC
205 CADJ GENERAL
206 #endif /* ALLOW_AUTODIFF_TAMC */
207
208 dRloc=drC(k)
209 IF (k.EQ.1) dRloc=drF(1)
210 IF (k.EQ.Nr) THEN
211 dRlocKp1=0.
212 ELSE
213 dRlocKp1=drC(k+1)
214 ENDIF
215
216 IF (k.EQ.1) THEN
217 DO j=jMin,jMax
218 DO i=iMin,iMax
219 phiHyd(i,j,k)=0.
220 #ifdef ATMOSPHERIC_LOADING
221 phiHyd(i,j,k)=pload(i,j,bi,bj)
222 #endif
223 ENDDO
224 ENDDO
225 ENDIF
226
227 C Calculate density
228 #ifdef ALLOW_AUTODIFF_TAMC
229 kkey = (ikey-1)*Nr + k
230 CADJ STORE tFld (:,:,k,bi,bj) = comlev1_bibj_k, key=kkey, byte=isbyte
231 CADJ STORE sFld (:,:,k,bi,bj) = comlev1_bibj_k, key=kkey, byte=isbyte
232 #endif /* ALLOW_AUTODIFF_TAMC */
233 CALL FIND_RHO( bi, bj, iMin, iMax, jMin, jMax, k, k,
234 & tFld, sFld,
235 & alphaRho, myThid)
236 #ifdef ALLOW_AUTODIFF_TAMC
237 CADJ STORE alphaRho (:,:) = comlev1_bibj_k, key=kkey, byte=isbyte
238 #endif /* ALLOW_AUTODIFF_TAMC */
239
240
241 C Hydrostatic pressure at cell centers
242 DO j=jMin,jMax
243 DO i=iMin,iMax
244 locAlpha=alphaRho(i,j)+rhoConst
245 IF (locAlpha.NE.0.) locAlpha=maskC(i,j,k,bi,bj)/locAlpha
246
247 CmlC---------- This discretization is the "finite volume" form
248 CmlC which has not been used to date since it does not
249 CmlC conserve KE+PE exactly even though it is more natural
250 CmlC
251 Cml IF ( K .EQ. kLowC(i,j,bi,bj) ) THEN
252 Cml phiHydLow(i,j,bi,bj) = phiHyd(i,j,k)
253 Cml & + hFacC(i,j,k,bi,bj)*drF(K)*locAlpha
254 Cml & + Bo_surf(i,j,bi,bj)*etaN(i,j,bi,bj)
255 Cml ENDIF
256 Cml IF (k.LT.Nr) phiHyd(i,j,k+1)=phiHyd(i,j,k)+
257 Cml & drF(K)*locAlpha
258 Cml phiHyd(i,j,k)=phiHyd(i,j,k)+
259 Cml & 0.5*drF(K)*locAlpha
260 CmlC-----------------------------------------------------------------------
261
262 C---------- This discretization is the "energy conserving" form
263 C which has been used since at least Adcroft et al., MWR 1997
264 C
265
266 phiHyd(i,j,k)=phiHyd(i,j,k)+
267 & 0.5*dRloc*locAlpha
268 IF (k.LT.Nr) phiHyd(i,j,k+1)=phiHyd(i,j,k)+
269 & 0.5*dRlocKp1*locAlpha
270
271 C-----------------------------------------------------------------------
272
273 C---------- Compute gravity*(sea surface elevation) first
274 C This has to be done starting from phiHyd at the current
275 C tracer point and .5 of the cell's thickness has to be
276 C substracted from hFacC
277 IF ( K .EQ. kLowC(i,j,bi,bj) ) THEN
278 phiHydLow(i,j,bi,bj) = phiHyd(i,j,k)
279 & + (hFacC(i,j,k,bi,bj)-0.5)*drF(k)*locAlpha
280 & + Bo_surf(i,j,bi,bj)*etaN(i,j,bi,bj)
281 ENDIF
282 C-----------------------------------------------------------------------
283
284 ENDDO
285 ENDDO
286
287 ELSEIF ( buoyancyRelation .eq. 'ATMOSPHERIC' ) THEN
288 C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----|
289 C This is the hydrostatic geopotential calculation for the Atmosphere
290 C The ideal gas law is used implicitly here rather than calculating
291 C the specific volume, analogous to the oceanic case.
292
293 C Integrate d Phi / d pi
294
295 IF (Integr_GeoPot.EQ.0) THEN
296 C -- Energy Conserving Form, No hFac --
297 C------------ The integration for the first level phi(k=1) is the same
298 C for both the "finite volume" and energy conserving methods.
299 Ci *NOTE* o Working with geopotential Anomaly, the geopotential boundary
300 C condition is simply Phi-prime(Ro_surf)=0.
301 C o convention ddPI > 0 (same as drF & drC)
302 C-----------------------------------------------------------------------
303 IF (K.EQ.1) THEN
304 ddPIp=atm_cp*( ((rF(K)/atm_po)**atm_kappa)
305 & -((rC(K)/atm_po)**atm_kappa) )
306 DO j=jMin,jMax
307 DO i=iMin,iMax
308 phiHyd(i,j,K)=
309 & ddPIp*maskC(i,j,K,bi,bj)
310 & *(tFld(I,J,K,bi,bj)-tRef(K))
311 ENDDO
312 ENDDO
313 ELSE
314 C-------- This discretization is the energy conserving form
315 ddPI=atm_cp*( ((rC(K-1)/atm_po)**atm_kappa)
316 & -((rC( K )/atm_po)**atm_kappa) )*0.5
317 DO j=jMin,jMax
318 DO i=iMin,iMax
319 phiHyd(i,j,K)=phiHyd(i,j,K-1)
320 & +ddPI*maskC(i,j,K-1,bi,bj)
321 & *(tFld(I,J,K-1,bi,bj)-tRef(K-1))
322 & +ddPI*maskC(i,j, K ,bi,bj)
323 & *(tFld(I,J, K ,bi,bj)-tRef( K ))
324 C Old code (atmos-exact) looked like this
325 Cold phiHyd(i,j,K)=phiHyd(i,j,K-1) - ddPI*
326 Cold & (tFld(I,J,K-1,bi,bj)+tFld(I,J,K,bi,bj)-2.*tRef(K))
327 ENDDO
328 ENDDO
329 ENDIF
330 C end: Energy Conserving Form, No hFac --
331 C-----------------------------------------------------------------------
332
333 ELSEIF (Integr_GeoPot.EQ.1) THEN
334 C -- Finite Volume Form, with hFac, linear in P by Half level --
335 C---------
336 C Finite Volume formulation consistent with Partial Cell, linear in p by piece
337 C Note: a true Finite Volume form should be linear between 2 Interf_W :
338 C phi_C = (phi_W_k+ phi_W_k+1)/2 ; but not accurate in Stratosphere (low p)
339 C also: if Interface_W at the middle between tracer levels, this form
340 C is close to the Energy Cons. form in the Interior, except for the
341 C non-linearity in PI(p)
342 C---------
343 IF (K.EQ.1) THEN
344 ddPIp=atm_cp*( ((rF(K)/atm_po)**atm_kappa)
345 & -((rC(K)/atm_po)**atm_kappa) )
346 DO j=jMin,jMax
347 DO i=iMin,iMax
348 phiHyd(i,j,K) =
349 & ddPIp*_hFacC(I,J, K ,bi,bj)
350 & *(tFld(I,J, K ,bi,bj)-tRef( K ))
351 ENDDO
352 ENDDO
353 ELSE
354 ddPIm=atm_cp*( ((rC(K-1)/atm_po)**atm_kappa)
355 & -((rF( K )/atm_po)**atm_kappa) )
356 ddPIp=atm_cp*( ((rF( K )/atm_po)**atm_kappa)
357 & -((rC( K )/atm_po)**atm_kappa) )
358 DO j=jMin,jMax
359 DO i=iMin,iMax
360 phiHyd(i,j,K) = phiHyd(i,j,K-1)
361 & +ddPIm*_hFacC(I,J,K-1,bi,bj)
362 & *(tFld(I,J,K-1,bi,bj)-tRef(K-1))
363 & +ddPIp*_hFacC(I,J, K ,bi,bj)
364 & *(tFld(I,J, K ,bi,bj)-tRef( K ))
365 ENDDO
366 ENDDO
367 ENDIF
368 C end: Finite Volume Form, with hFac, linear in P by Half level --
369 C-----------------------------------------------------------------------
370
371 ELSEIF (Integr_GeoPot.EQ.2) THEN
372 C -- Finite Difference Form, with hFac, Tracer Lev. = middle --
373 C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----|
374 C Finite Difference formulation consistent with Partial Cell,
375 C case Tracer level at the middle of InterFace_W
376 C linear between 2 Tracer levels ; conserve energy in the Interior
377 C---------
378 Kp1 = min(Nr,K+1)
379 IF (K.EQ.1) THEN
380 ddPIm=atm_cp*( ((rF( K )/atm_po)**atm_kappa)
381 & -((rC( K )/atm_po)**atm_kappa) ) * 2. _d 0
382 ddPIp=atm_cp*( ((rC( K )/atm_po)**atm_kappa)
383 & -((rC(Kp1)/atm_po)**atm_kappa) )
384 DO j=jMin,jMax
385 DO i=iMin,iMax
386 phiHyd(i,j,K) =
387 & ( ddPIm*max(zero, _hFacC(i,j,K,bi,bj)-half)
388 & +ddPIp*min(zero, _hFacC(i,j,K,bi,bj)-half) )
389 & *(tFld(i,j, K ,bi,bj)-tRef( K ))
390 & * maskC(i,j, K ,bi,bj)
391 ENDDO
392 ENDDO
393 ELSE
394 ddPIm=atm_cp*( ((rC(K-1)/atm_po)**atm_kappa)
395 & -((rC( K )/atm_po)**atm_kappa) )
396 ddPIp=atm_cp*( ((rC( K )/atm_po)**atm_kappa)
397 & -((rC(Kp1)/atm_po)**atm_kappa) )
398 DO j=jMin,jMax
399 DO i=iMin,iMax
400 phiHyd(i,j,K) = phiHyd(i,j,K-1)
401 & + ddPIm*0.5
402 & *(tFld(i,j,K-1,bi,bj)-tRef(K-1))
403 & * maskC(i,j,K-1,bi,bj)
404 & +(ddPIm*max(zero, _hFacC(i,j,K,bi,bj)-half)
405 & +ddPIp*min(zero, _hFacC(i,j,K,bi,bj)-half) )
406 & *(tFld(i,j, K ,bi,bj)-tRef( K ))
407 & * maskC(i,j, K ,bi,bj)
408 ENDDO
409 ENDDO
410 ENDIF
411 C end: Finite Difference Form, with hFac, Tracer Lev. = middle --
412 C-----------------------------------------------------------------------
413
414 ELSEIF (Integr_GeoPot.EQ.3) THEN
415 C -- Finite Difference Form, with hFac, Interface_W = middle --
416 C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----|
417 C Finite Difference formulation consistent with Partial Cell,
418 C Valid & accurate if Interface_W at middle between tracer levels
419 C linear in p between 2 Tracer levels ; conserve energy in the Interior
420 C---------
421 Kp1 = min(Nr,K+1)
422 IF (K.EQ.1) THEN
423 ratioRm=0.5*drF(K)/(rF(k)-rC(K))
424 ratioRp=drF(K)*recip_drC(Kp1)
425 ddPIm=atm_cp*( ((rF( K )/atm_po)**atm_kappa)
426 & -((rC( K )/atm_po)**atm_kappa) ) * 2. _d 0
427 ddPIp=atm_cp*( ((rC( K )/atm_po)**atm_kappa)
428 & -((rC(Kp1)/atm_po)**atm_kappa) )
429 DO j=jMin,jMax
430 DO i=iMin,iMax
431 phiHyd(i,j,K) =
432 & ( ddPIm*max(zero,(_hFacC(i,j,K,bi,bj)-one)*ratioRm+half)
433 & +ddPIp*min(zero, _hFacC(i,j,K,bi,bj)*ratioRp -half) )
434 & *(tFld(i,j, K ,bi,bj)-tRef( K ))
435 & * maskC(i,j, K ,bi,bj)
436 ENDDO
437 ENDDO
438 ELSE
439 ratioRm=drF(K)*recip_drC(K)
440 ratioRp=drF(K)*recip_drC(Kp1)
441 ddPIm=atm_cp*( ((rC(K-1)/atm_po)**atm_kappa)
442 & -((rC( K )/atm_po)**atm_kappa) )
443 ddPIp=atm_cp*( ((rC( K )/atm_po)**atm_kappa)
444 & -((rC(Kp1)/atm_po)**atm_kappa) )
445 DO j=jMin,jMax
446 DO i=iMin,iMax
447 phiHyd(i,j,K) = phiHyd(i,j,K-1)
448 & + ddPIm*0.5
449 & *(tFld(i,j,K-1,bi,bj)-tRef(K-1))
450 & * maskC(i,j,K-1,bi,bj)
451 & +(ddPIm*max(zero,(_hFacC(i,j,K,bi,bj)-one)*ratioRm+half)
452 & +ddPIp*min(zero, _hFacC(i,j,K,bi,bj)*ratioRp -half) )
453 & *(tFld(i,j, K ,bi,bj)-tRef( K ))
454 & * maskC(i,j, K ,bi,bj)
455 ENDDO
456 ENDDO
457 ENDIF
458 C end: Finite Difference Form, with hFac, Interface_W = middle --
459 C-----------------------------------------------------------------------
460
461 ELSE
462 STOP 'CALC_PHI_HYD: Bad Integr_GeoPot option !'
463 ENDIF
464
465 C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----|
466 ELSE
467 STOP 'CALC_PHI_HYD: We should never reach this point!'
468 ENDIF
469
470 #endif /* INCLUDE_PHIHYD_CALCULATION_CODE */
471
472 RETURN
473 END

  ViewVC Help
Powered by ViewVC 1.1.22