/[MITgcm]/MITgcm/pkg/gmredi/gmredi_calc_tensor.F
ViewVC logotype

Diff of /MITgcm/pkg/gmredi/gmredi_calc_tensor.F

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

revision 1.32 by heimbach, Fri Mar 28 18:48:05 2008 UTC revision 1.36 by jmc, Wed Jan 20 01:20:29 2010 UTC
# Line 5  C $Name$ Line 5  C $Name$
5  #ifdef ALLOW_KPP  #ifdef ALLOW_KPP
6  # include "KPP_OPTIONS.h"  # include "KPP_OPTIONS.h"
7  #endif  #endif
 #undef OLD_VISBECK_CALC  
8    
9  CBOP  CBOP
10  C     !ROUTINE: GMREDI_CALC_TENSOR  C     !ROUTINE: GMREDI_CALC_TENSOR
# Line 64  CEOP Line 63  CEOP
63    
64  C     !LOCAL VARIABLES:  C     !LOCAL VARIABLES:
65  C     == Local variables ==  C     == Local variables ==
66        INTEGER i,j,k,kp1        INTEGER i,j,k
67        _RL SlopeX(1-Olx:sNx+Olx,1-Oly:sNy+Oly)        _RL SlopeX(1-Olx:sNx+Olx,1-Oly:sNy+Oly)
68        _RL SlopeY(1-Olx:sNx+Olx,1-Oly:sNy+Oly)        _RL SlopeY(1-Olx:sNx+Olx,1-Oly:sNy+Oly)
69        _RL dSigmaDx(1-Olx:sNx+Olx,1-Oly:sNy+Oly)        _RL dSigmaDx(1-Olx:sNx+Olx,1-Oly:sNy+Oly)
# Line 72  C     == Local variables == Line 71  C     == Local variables ==
71        _RL dSigmaDr(1-Olx:sNx+Olx,1-Oly:sNy+Oly)        _RL dSigmaDr(1-Olx:sNx+Olx,1-Oly:sNy+Oly)
72        _RL SlopeSqr(1-Olx:sNx+Olx,1-Oly:sNy+Oly)        _RL SlopeSqr(1-Olx:sNx+Olx,1-Oly:sNy+Oly)
73        _RL taperFct(1-Olx:sNx+Olx,1-Oly:sNy+Oly)        _RL taperFct(1-Olx:sNx+Olx,1-Oly:sNy+Oly)
74        _RL maskp1, Kgm_tmp        _RL Kgm_tmp
75        _RL ldd97_LrhoC(1-Olx:sNx+Olx,1-Oly:sNy+Oly)        _RL ldd97_LrhoC(1-Olx:sNx+Olx,1-Oly:sNy+Oly)
76        _RL ldd97_LrhoW(1-Olx:sNx+Olx,1-Oly:sNy+Oly)        _RL ldd97_LrhoW(1-Olx:sNx+Olx,1-Oly:sNy+Oly)
77        _RL ldd97_LrhoS(1-Olx:sNx+Olx,1-Oly:sNy+Oly)        _RL ldd97_LrhoS(1-Olx:sNx+Olx,1-Oly:sNy+Oly)
# Line 84  C     == Local variables == Line 83  C     == Local variables ==
83        _RL baseSlope  (1-Olx:sNx+Olx,1-Oly:sNy+Oly)        _RL baseSlope  (1-Olx:sNx+Olx,1-Oly:sNy+Oly)
84        _RL hTransLay  (1-Olx:sNx+Olx,1-Oly:sNy+Oly)        _RL hTransLay  (1-Olx:sNx+Olx,1-Oly:sNy+Oly)
85        _RL recipLambda(1-Olx:sNx+Olx,1-Oly:sNy+Oly)        _RL recipLambda(1-Olx:sNx+Olx,1-Oly:sNy+Oly)
86    #if ( defined (GM_NON_UNITY_DIAGONAL) || defined (GM_EXTRA_DIAGONAL) )
87          INTEGER kp1
88          _RL maskp1
89    #endif
90    
91  #ifdef GM_VISBECK_VARIABLE_K  #ifdef GM_VISBECK_VARIABLE_K
92  #ifdef OLD_VISBECK_CALC  #ifdef OLD_VISBECK_CALC
       _RL deltaH,zero_rs  
       PARAMETER(zero_rs=0.D0)  
       _RL N2,SN  
93        _RL Ssq(1-Olx:sNx+Olx,1-Oly:sNy+Oly)        _RL Ssq(1-Olx:sNx+Olx,1-Oly:sNy+Oly)
94  #else  #else
95        _RL dSigmaH        _RL dSigmaH, dSigmaR
96        _RL deltaH, integrDepth        _RL Sloc, M2loc
       _RL Sloc, M2loc, SNloc  
 #endif  
97  #endif  #endif
98          _RL recipMaxSlope
99          _RL deltaH, integrDepth
100          _RL N2loc, SNloc
101    #endif /* GM_VISBECK_VARIABLE_K */
102    
103  #ifdef ALLOW_DIAGNOSTICS  #ifdef ALLOW_DIAGNOSTICS
104        LOGICAL  doDiagRediFlx        LOGICAL  doDiagRediFlx
105        LOGICAL  DIAGNOSTICS_IS_ON        LOGICAL  DIAGNOSTICS_IS_ON
106        EXTERNAL DIAGNOSTICS_IS_ON        EXTERNAL DIAGNOSTICS_IS_ON
107    #if ( defined (GM_NON_UNITY_DIAGONAL) || defined (GM_EXTRA_DIAGONAL) )
108        INTEGER  km1        INTEGER  km1
109        _RL dTdz        _RL dTdz
110        _RL tmp1k(1-OLx:sNx+OLx,1-OLy:sNy+OLy)        _RL tmp1k(1-OLx:sNx+OLx,1-OLy:sNy+OLy)
111  #endif  #endif
112    #endif /* ALLOW_DIAGNOSTICS */
113    
114  C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----|  C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----|
115    
# Line 132  C---+----1----+----2----+----3----+----4 Line 136  C---+----1----+----2----+----3----+----4
136  #endif  #endif
137    
138  #ifdef GM_VISBECK_VARIABLE_K  #ifdef GM_VISBECK_VARIABLE_K
139          recipMaxSlope = 0. _d 0
140          IF ( GM_Visbeck_maxSlope.GT.0. _d 0 ) THEN
141            recipMaxSlope = 1. _d 0 / GM_Visbeck_maxSlope
142          ENDIF
143        DO j=1-Oly,sNy+Oly        DO j=1-Oly,sNy+Oly
144         DO i=1-Olx,sNx+Olx         DO i=1-Olx,sNx+Olx
145          VisbeckK(i,j,bi,bj) = 0. _d 0          VisbeckK(i,j,bi,bj) = 0. _d 0
# Line 258  C-- 1rst loop on k : compute Tensor Coef Line 266  C-- 1rst loop on k : compute Tensor Coef
266  # endif  # endif
267          ENDDO          ENDDO
268         ENDDO         ENDDO
269  #endif  #endif /* ALLOW_AUTODIFF_TAMC */
270    
271         DO j=1-Oly+1,sNy+Oly-1         DO j=1-Oly+1,sNy+Oly-1
272          DO i=1-Olx+1,sNx+Olx-1          DO i=1-Olx+1,sNx+Olx-1
# Line 269  C      Gradient of Sigma at rVel points Line 277  C      Gradient of Sigma at rVel points
277           dSigmaDy(i,j)=op25*( sigmaY(i,j+1,k-1)+sigmaY(i,j,k-1)           dSigmaDy(i,j)=op25*( sigmaY(i,j+1,k-1)+sigmaY(i,j,k-1)
278       &                       +sigmaY(i,j+1, k )+sigmaY(i,j, k )       &                       +sigmaY(i,j+1, k )+sigmaY(i,j, k )
279       &                      )*maskC(i,j,k,bi,bj)       &                      )*maskC(i,j,k,bi,bj)
280           dSigmaDr(i,j)=sigmaR(i,j,k)  c        dSigmaDr(i,j)=sigmaR(i,j,k)
281          ENDDO          ENDDO
282         ENDDO         ENDDO
283    
 #ifdef ALLOW_AUTODIFF_TAMC  
 CADJ STORE dSigmaDx(:,:)       = comlev1_bibj_k, key=kkey, byte=isbyte  
 CADJ STORE dSigmaDy(:,:)       = comlev1_bibj_k, key=kkey, byte=isbyte  
 CADJ STORE dSigmaDr(:,:)       = comlev1_bibj_k, key=kkey, byte=isbyte  
 CADJ STORE baseSlope(:,:)      = comlev1_bibj_k, key=kkey, byte=isbyte  
 CADJ STORE hTransLay(:,:)      = comlev1_bibj_k, key=kkey, byte=isbyte  
 CADJ STORE recipLambda(:,:)    = comlev1_bibj_k, key=kkey, byte=isbyte  
 #endif /* ALLOW_AUTODIFF_TAMC */  
   
284  #ifdef GM_VISBECK_VARIABLE_K  #ifdef GM_VISBECK_VARIABLE_K
285  #ifndef OLD_VISBECK_CALC  #ifndef OLD_VISBECK_CALC
286         IF ( GM_Visbeck_alpha.GT.0. .AND.         IF ( GM_Visbeck_alpha.GT.0. .AND.
287       &      -rC(k-1).LT.GM_Visbeck_depth ) THEN       &      -rC(k-1).LT.GM_Visbeck_depth ) THEN
288    
289            DO j=1-Oly,sNy+Oly
290             DO i=1-Olx,sNx+Olx
291              dSigmaDr(i,j) = MIN( sigmaR(i,j,k), 0. _d 0 )
292             ENDDO
293            ENDDO
294    
295  C--     Depth average of f/sqrt(Ri) = M^2/N^2 * N  C--     Depth average of f/sqrt(Ri) = M^2/N^2 * N
296  C       M^2 and N^2 are horizontal & vertical gradient of buoyancy.  C       M^2 and N^2 are horizontal & vertical gradient of buoyancy.
297    
# Line 301  C       GM_Visbeck_depth, whatever is th Line 306  C       GM_Visbeck_depth, whatever is th
306             integrDepth = -rC( kLowC(i,j,bi,bj) )             integrDepth = -rC( kLowC(i,j,bi,bj) )
307  C-      in 2 steps to avoid mix of RS & RL type in min fct. arguments  C-      in 2 steps to avoid mix of RS & RL type in min fct. arguments
308             integrDepth = MIN( integrDepth, GM_Visbeck_depth )             integrDepth = MIN( integrDepth, GM_Visbeck_depth )
309    C-      to recover "old-visbeck" form with Visbeck_minDepth = Visbeck_depth
310               integrDepth = MAX( integrDepth, GM_Visbeck_minDepth )
311  C       Distance between level center above and the integration depth  C       Distance between level center above and the integration depth
312             deltaH = integrDepth + rC(k-1)             deltaH = integrDepth + rC(k-1)
313  C       If negative then we are below the integration level  C       If negative then we are below the integration level
# Line 310  C       If positive we limit this to the Line 317  C       If positive we limit this to the
317  C       Now we convert deltaH to a non-dimensional fraction  C       Now we convert deltaH to a non-dimensional fraction
318             deltaH = deltaH/( integrDepth+rC(1) )             deltaH = deltaH/( integrDepth+rC(1) )
319    
320  C--      compute: ( M^2 * S )^1/2   (= M^2 / N since S=M^2/N^2 )  C--      compute: ( M^2 * S )^1/2   (= S*N since S=M^2/N^2 )
321    C        a 5 points average gives a more "homogeneous" formulation
322    C        (same stencil and same weights as for dSigmaH calculation)
323               dSigmaR = ( dSigmaDr(i,j)*4. _d 0
324         &               + dSigmaDr(i-1,j)
325         &               + dSigmaDr(i+1,j)
326         &               + dSigmaDr(i,j-1)
327         &               + dSigmaDr(i,j+1)
328         &               )/( 4. _d 0
329         &                 + maskC(i-1,j,k,bi,bj)
330         &                 + maskC(i+1,j,k,bi,bj)
331         &                 + maskC(i,j-1,k,bi,bj)
332         &                 + maskC(i,j+1,k,bi,bj)
333         &                 )
334             dSigmaH = dSigmaDx(i,j)*dSigmaDx(i,j)             dSigmaH = dSigmaDx(i,j)*dSigmaDx(i,j)
335       &             + dSigmaDy(i,j)*dSigmaDy(i,j)       &             + dSigmaDy(i,j)*dSigmaDy(i,j)
336             IF ( dSigmaH .GT. 0. _d 0 ) THEN             IF ( dSigmaH .GT. 0. _d 0 ) THEN
337               dSigmaH = SQRT( dSigmaH )               dSigmaH = SQRT( dSigmaH )
338  C-       compute slope, limited by GM_maxSlope:  C-       compute slope, limited by GM_Visbeck_maxSlope:
339               IF ( -dSigmaDr(i,j).GT.dSigmaH*GM_rMaxSlope ) THEN               IF ( -dSigmaR.GT.dSigmaH*recipMaxSlope ) THEN
340                Sloc = dSigmaH / ( -dSigmaDr(i,j) )                Sloc = dSigmaH / ( -dSigmaR )
341                 ELSE
342                  Sloc = GM_Visbeck_maxSlope
343                 ENDIF
344                 M2loc = gravity*recip_rhoConst*dSigmaH
345    c            SNloc = SQRT( Sloc*M2loc )
346                 N2loc = -gravity*recip_rhoConst*dSigmaR
347    c            N2loc = -gravity*recip_rhoConst*dSigmaDr(i,j)
348                 IF ( N2loc.GT.0. _d 0 ) THEN
349                   SNloc = Sloc*SQRT(N2loc)
350               ELSE               ELSE
351                Sloc = GM_maxSlope                 SNloc = 0. _d 0
352               ENDIF               ENDIF
              M2loc = Gravity*recip_RhoConst*dSigmaH  
              SNloc = SQRT( Sloc*M2loc )  
353             ELSE             ELSE
354               SNloc = 0. _d 0               SNloc = 0. _d 0
355             ENDIF             ENDIF
# Line 335  C-       compute slope, limited by GM_ma Line 362  C-       compute slope, limited by GM_ma
362         ENDIF         ENDIF
363  #endif /* ndef OLD_VISBECK_CALC */  #endif /* ndef OLD_VISBECK_CALC */
364  #endif /* GM_VISBECK_VARIABLE_K */  #endif /* GM_VISBECK_VARIABLE_K */
365           DO j=1-Oly,sNy+Oly
366            DO i=1-Olx,sNx+Olx
367             dSigmaDr(i,j)=sigmaR(i,j,k)
368            ENDDO
369           ENDDO
370    
371    #ifdef ALLOW_AUTODIFF_TAMC
372    CADJ STORE dSigmaDx(:,:)       = comlev1_bibj_k, key=kkey, byte=isbyte
373    CADJ STORE dSigmaDy(:,:)       = comlev1_bibj_k, key=kkey, byte=isbyte
374    CADJ STORE dSigmaDr(:,:)       = comlev1_bibj_k, key=kkey, byte=isbyte
375    CADJ STORE baseSlope(:,:)      = comlev1_bibj_k, key=kkey, byte=isbyte
376    CADJ STORE hTransLay(:,:)      = comlev1_bibj_k, key=kkey, byte=isbyte
377    CADJ STORE recipLambda(:,:)    = comlev1_bibj_k, key=kkey, byte=isbyte
378    #endif /* ALLOW_AUTODIFF_TAMC */
379    
380  C     Calculate slopes for use in tensor, taper and/or clip  C     Calculate slopes for use in tensor, taper and/or clip
381         CALL GMREDI_SLOPE_LIMIT(         CALL GMREDI_SLOPE_LIMIT(
# Line 389  C       which is used in the "variable K Line 430  C       which is used in the "variable K
430  C       Distance between interface above layer and the integration depth  C       Distance between interface above layer and the integration depth
431          deltaH=abs(GM_Visbeck_depth)-abs(rF(k))          deltaH=abs(GM_Visbeck_depth)-abs(rF(k))
432  C       If positive we limit this to the layer thickness  C       If positive we limit this to the layer thickness
433          deltaH=min(deltaH,drF(k))          integrDepth = drF(k)
434            deltaH=min(deltaH,integrDepth)
435  C       If negative then we are below the integration level  C       If negative then we are below the integration level
436          deltaH=max(deltaH,zero_rs)          deltaH=max(deltaH, 0. _d 0)
437  C       Now we convert deltaH to a non-dimensional fraction  C       Now we convert deltaH to a non-dimensional fraction
438          deltaH=deltaH/GM_Visbeck_depth          deltaH=deltaH/GM_Visbeck_depth
439    
         IF (K.eq.2) VisbeckK(i,j,bi,bj)=0.  
440          IF ( Ssq(i,j).NE.0. .AND. dSigmaDr(i,j).NE.0. ) THEN          IF ( Ssq(i,j).NE.0. .AND. dSigmaDr(i,j).NE.0. ) THEN
441           N2= -Gravity*recip_RhoConst*dSigmaDr(i,j)           N2loc = -gravity*recip_rhoConst*dSigmaDr(i,j)
442           SN=sqrt(Ssq(i,j)*N2)           SNloc = SQRT(Ssq(i,j)*N2loc )
443           VisbeckK(i,j,bi,bj)=VisbeckK(i,j,bi,bj)+deltaH           VisbeckK(i,j,bi,bj) = VisbeckK(i,j,bi,bj)
444       &      *GM_Visbeck_alpha*GM_Visbeck_length*GM_Visbeck_length*SN       &       +deltaH*GM_Visbeck_alpha
445         &              *GM_Visbeck_length*GM_Visbeck_length*SNloc
446          ENDIF          ENDIF
447    
448          ENDDO          ENDDO
# Line 421  C-     Limit range that KapGM can take Line 463  C-     Limit range that KapGM can take
463         DO j=1-Oly+1,sNy+Oly-1         DO j=1-Oly+1,sNy+Oly-1
464          DO i=1-Olx+1,sNx+Olx-1          DO i=1-Olx+1,sNx+Olx-1
465           VisbeckK(i,j,bi,bj)=           VisbeckK(i,j,bi,bj)=
466       &       MIN(VisbeckK(i,j,bi,bj),GM_Visbeck_maxval_K)       &       MIN( MAX( VisbeckK(i,j,bi,bj), GM_Visbeck_minVal_K ),
467         &            GM_Visbeck_maxVal_K )
468          ENDDO          ENDDO
469         ENDDO         ENDDO
470        ENDIF        ENDIF
# Line 450  CADJ STORE Kwz(:,:,k,bi,bj) = comlev1_bi Line 493  CADJ STORE Kwz(:,:,k,bi,bj) = comlev1_bi
493  #else  #else
494           Kgm_tmp = GM_isopycK           Kgm_tmp = GM_isopycK
495  #endif  #endif
496  #if (defined (ALLOW_AUTODIFF) && defined (ALLOW_KAPGM_CONTROL))  #ifdef ALLOW_KAPGM_CONTROL
497       &           + GM_skewflx*kapgm(i,j,k,bi,bj)       &           + GM_skewflx*kapgm(i,j,k,bi,bj)
498  #else  #else
499       &           + GM_skewflx*GM_background_K       &           + GM_skewflx*GM_background_K
# Line 461  CADJ STORE Kwz(:,:,k,bi,bj) = comlev1_bi Line 504  CADJ STORE Kwz(:,:,k,bi,bj) = comlev1_bi
504           Kwx(i,j,k,bi,bj)= Kgm_tmp*Kwx(i,j,k,bi,bj)           Kwx(i,j,k,bi,bj)= Kgm_tmp*Kwx(i,j,k,bi,bj)
505           Kwy(i,j,k,bi,bj)= Kgm_tmp*Kwy(i,j,k,bi,bj)           Kwy(i,j,k,bi,bj)= Kgm_tmp*Kwy(i,j,k,bi,bj)
506  #ifdef ALLOW_KAPREDI_CONTROL  #ifdef ALLOW_KAPREDI_CONTROL
507           Kwz(i,j,k,bi,bj)= ( kapredi(i,j,k,bi,bj)           Kwz(i,j,k,bi,bj)= ( kapredi(i,j,k,bi,bj)
508  #else  #else
509           Kwz(i,j,k,bi,bj)= ( GM_isopycK           Kwz(i,j,k,bi,bj)= ( GM_isopycK
510  #endif  #endif
# Line 609  CADJ STORE taperFct(:,:)     = comlev1_b Line 652  CADJ STORE taperFct(:,:)     = comlev1_b
652  #else  #else
653       &     ( GM_isopycK       &     ( GM_isopycK
654  #endif  #endif
655  #if (defined (ALLOW_AUTODIFF) && defined (ALLOW_KAPGM_CONTROL))  #ifdef ALLOW_KAPGM_CONTROL
656       &     - GM_skewflx*kapgm(i,j,k,bi,bj)       &     - GM_skewflx*kapgm(i,j,k,bi,bj)
657  #else  #else
658       &     - GM_skewflx*GM_background_K       &     - GM_skewflx*GM_background_K
# Line 795  CADJ STORE taperFct(:,:)     = comlev1_b Line 838  CADJ STORE taperFct(:,:)     = comlev1_b
838  #ifdef ALLOW_KAPREDI_CONTROL  #ifdef ALLOW_KAPREDI_CONTROL
839       &     ( kapredi(i,j,k,bi,bj)       &     ( kapredi(i,j,k,bi,bj)
840  #else  #else
841       &     ( GM_isopycK       &     ( GM_isopycK
842  #endif  #endif
843  #if (defined (ALLOW_AUTODIFF) && defined (ALLOW_KAPGM_CONTROL))  #ifdef ALLOW_KAPGM_CONTROL
844       &     - GM_skewflx*kapgm(i,j,k,bi,bj)       &     - GM_skewflx*kapgm(i,j,k,bi,bj)
845  #else  #else
846       &     - GM_skewflx*GM_background_K       &     - GM_skewflx*GM_background_K
# Line 893  C--   Time-average Line 936  C--   Time-average
936       &                          deltaTclock, bi, bj, myThid )       &                          deltaTclock, bi, bj, myThid )
937         ENDIF         ENDIF
938  #endif  #endif
939         DO k=1,Nr         GM_timeAve(bi,bj) = GM_timeAve(bi,bj)+deltaTclock
          GM_TimeAve(k,bi,bj)=GM_TimeAve(k,bi,bj)+deltaTclock  
        ENDDO  
940    
941        ENDIF        ENDIF
942  #endif /* ALLOW_TIMEAVE */  #endif /* ALLOW_TIMEAVE */
# Line 911  C--   Time-average Line 952  C--   Time-average
952        RETURN        RETURN
953        END        END
954    
955    C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----|
956    
957        SUBROUTINE GMREDI_CALC_TENSOR_DUMMY(        SUBROUTINE GMREDI_CALC_TENSOR_DUMMY(
958       I             iMin, iMax, jMin, jMax,       I             iMin, iMax, jMin, jMax,

Legend:
Removed from v.1.32  
changed lines
  Added in v.1.36

  ViewVC Help
Powered by ViewVC 1.1.22