1 |
C $Header$ |
C $Header$ |
2 |
|
C $Name$ |
3 |
|
|
4 |
#include "CPP_OPTIONS.h" |
#include "CPP_OPTIONS.h" |
5 |
|
|
6 |
CStartOfInterFace |
CBOP |
7 |
|
C !ROUTINE: CALC_GS |
8 |
|
C !INTERFACE: |
9 |
SUBROUTINE CALC_GS( |
SUBROUTINE CALC_GS( |
10 |
I bi,bj,iMin,iMax,jMin,jMax,k,kM1,kUp,kDown, |
I bi,bj,iMin,iMax,jMin,jMax,k,kM1,kUp,kDown, |
11 |
I xA,yA,uTrans,vTrans,rTrans,maskup,maskC, |
I xA,yA,uTrans,vTrans,rTrans,rTransKp1,maskUp, |
12 |
I K13,K23,KappaRS,KapGM, |
I KappaRS, |
13 |
U af,df,fZon,fMer,fVerS, |
U fVerS, |
14 |
I myCurrentTime, myThid ) |
I myTime,myIter,myThid ) |
15 |
C /==========================================================\ |
C !DESCRIPTION: \bv |
16 |
C | SUBROUTINE CALC_GS | |
C *==========================================================* |
17 |
C | o Calculate the salt tendency terms. | |
C | SUBROUTINE CALC_GS |
18 |
C |==========================================================| |
C | o Calculate the salt tendency terms. |
19 |
C | A procedure called EXTERNAL_FORCING_S is called from | |
C *==========================================================* |
20 |
C | here. These procedures can be used to add per problem | |
C | A procedure called EXTERNAL_FORCING_S is called from |
21 |
C | E-P flux source terms. | |
C | here. These procedures can be used to add per problem |
22 |
C | Note: Although it is slightly counter-intuitive the | |
C | E-P flux source terms. |
23 |
C | EXTERNAL_FORCING routine is not the place to put | |
C | Note: Although it is slightly counter-intuitive the |
24 |
C | file I/O. Instead files that are required to | |
C | EXTERNAL_FORCING routine is not the place to put |
25 |
C | calculate the external source terms are generally | |
C | file I/O. Instead files that are required to |
26 |
C | read during the model main loop. This makes the | |
C | calculate the external source terms are generally |
27 |
C | logisitics of multi-processing simpler and also | |
C | read during the model main loop. This makes the |
28 |
C | makes the adjoint generation simpler. It also | |
C | logisitics of multi-processing simpler and also |
29 |
C | allows for I/O to overlap computation where that | |
C | makes the adjoint generation simpler. It also |
30 |
C | is supported by hardware. | |
C | allows for I/O to overlap computation where that |
31 |
C | Aside from the problem specific term the code here | |
C | is supported by hardware. |
32 |
C | forms the tendency terms due to advection and mixing | |
C | Aside from the problem specific term the code here |
33 |
C | The baseline implementation here uses a centered | |
C | forms the tendency terms due to advection and mixing |
34 |
C | difference form for the advection term and a tensorial | |
C | The baseline implementation here uses a centered |
35 |
C | divergence of a flux form for the diffusive term. The | |
C | difference form for the advection term and a tensorial |
36 |
C | diffusive term is formulated so that isopycnal mixing and| |
C | divergence of a flux form for the diffusive term. The |
37 |
C | GM-style subgrid-scale terms can be incorporated b simply| |
C | diffusive term is formulated so that isopycnal mixing and |
38 |
C | setting the diffusion tensor terms appropriately. | |
C | GM-style subgrid-scale terms can be incorporated b simply |
39 |
C \==========================================================/ |
C | setting the diffusion tensor terms appropriately. |
40 |
IMPLICIT NONE |
C *==========================================================* |
41 |
|
C \ev |
42 |
|
|
43 |
|
C !USES: |
44 |
|
IMPLICIT NONE |
45 |
C == GLobal variables == |
C == GLobal variables == |
46 |
#include "SIZE.h" |
#include "SIZE.h" |
47 |
#include "DYNVARS.h" |
#include "DYNVARS.h" |
48 |
#include "EEPARAMS.h" |
#include "EEPARAMS.h" |
49 |
#include "PARAMS.h" |
#include "PARAMS.h" |
50 |
#include "GRID.h" |
#include "GAD.h" |
|
#include "FFIELDS.h" |
|
|
#ifdef ALLOW_KPP |
|
|
#include "KPPMIX.h" |
|
|
#endif |
|
51 |
|
|
52 |
|
C !INPUT/OUTPUT PARAMETERS: |
53 |
C == Routine arguments == |
C == Routine arguments == |
54 |
C fZon - Work array for flux of temperature in the east-west |
C fVerS :: Flux of salt (S) in the vertical |
|
C direction at the west face of a cell. |
|
|
C fMer - Work array for flux of temperature in the north-south |
|
|
C direction at the south face of a cell. |
|
|
C fVerS - Flux of salt (S) in the vertical |
|
55 |
C direction at the upper(U) and lower(D) faces of a cell. |
C direction at the upper(U) and lower(D) faces of a cell. |
56 |
C maskUp - Land mask used to denote base of the domain. |
C maskUp :: Land mask used to denote base of the domain. |
57 |
C maskC - Land mask for salt cells (used in TOP_LAYER only) |
C xA :: Tracer cell face area normal to X |
58 |
C xA - Tracer cell face area normal to X |
C yA :: Tracer cell face area normal to X |
59 |
C yA - Tracer cell face area normal to X |
C uTrans :: Zonal volume transport through cell face |
60 |
C uTrans - Zonal volume transport through cell face |
C vTrans :: Meridional volume transport through cell face |
61 |
C vTrans - Meridional volume transport through cell face |
C rTrans :: Vertical volume transport at interface k |
62 |
C rTrans - Vertical volume transport through cell face |
C rTransKp1 :: Vertical volume transport at inteface k+1 |
63 |
C af - Advective flux component work array |
C bi, bj, iMin, iMax, jMin, jMax :: Range of points for which calculation |
|
C df - Diffusive flux component work array |
|
|
C bi, bj, iMin, iMax, jMin, jMax - Range of points for which calculation |
|
64 |
C results will be set. |
C results will be set. |
65 |
C myThid - Instance number for this innvocation of CALC_GT |
C myThid :: Instance number for this innvocation of CALC_GT |
|
_RL fZon (1-OLx:sNx+OLx,1-OLy:sNy+OLy) |
|
|
_RL fMer (1-OLx:sNx+OLx,1-OLy:sNy+OLy) |
|
66 |
_RL fVerS (1-OLx:sNx+OLx,1-OLy:sNy+OLy,2) |
_RL fVerS (1-OLx:sNx+OLx,1-OLy:sNy+OLy,2) |
67 |
_RS xA (1-OLx:sNx+OLx,1-OLy:sNy+OLy) |
_RS xA (1-OLx:sNx+OLx,1-OLy:sNy+OLy) |
68 |
_RS yA (1-OLx:sNx+OLx,1-OLy:sNy+OLy) |
_RS yA (1-OLx:sNx+OLx,1-OLy:sNy+OLy) |
69 |
_RL uTrans(1-OLx:sNx+OLx,1-OLy:sNy+OLy) |
_RL uTrans(1-OLx:sNx+OLx,1-OLy:sNy+OLy) |
70 |
_RL vTrans(1-OLx:sNx+OLx,1-OLy:sNy+OLy) |
_RL vTrans(1-OLx:sNx+OLx,1-OLy:sNy+OLy) |
71 |
_RL rTrans(1-OLx:sNx+OLx,1-OLy:sNy+OLy) |
_RL rTrans(1-OLx:sNx+OLx,1-OLy:sNy+OLy) |
72 |
|
_RL rTransKp1(1-OLx:sNx+OLx,1-OLy:sNy+OLy) |
73 |
_RS maskUp(1-OLx:sNx+OLx,1-OLy:sNy+OLy) |
_RS maskUp(1-OLx:sNx+OLx,1-OLy:sNy+OLy) |
|
_RS maskC (1-OLx:sNx+OLx,1-OLy:sNy+OLy) |
|
|
_RL K13 (1-OLx:sNx+OLx,1-OLy:sNy+OLy,Nr) |
|
|
_RL K23 (1-OLx:sNx+OLx,1-OLy:sNy+OLy,Nr) |
|
74 |
_RL KappaRS(1-OLx:sNx+OLx,1-OLy:sNy+OLy,Nr) |
_RL KappaRS(1-OLx:sNx+OLx,1-OLy:sNy+OLy,Nr) |
|
_RL KapGM (1-OLx:sNx+OLx,1-OLy:sNy+OLy) |
|
|
_RL af (1-OLx:sNx+OLx,1-OLy:sNy+OLy) |
|
|
_RL df (1-OLx:sNx+OLx,1-OLy:sNy+OLy) |
|
75 |
INTEGER k,kUp,kDown,kM1 |
INTEGER k,kUp,kDown,kM1 |
76 |
INTEGER bi,bj,iMin,iMax,jMin,jMax |
INTEGER bi,bj,iMin,iMax,jMin,jMax |
77 |
_RL myCurrentTime |
_RL myTime |
78 |
|
INTEGER myIter |
79 |
INTEGER myThid |
INTEGER myThid |
|
CEndOfInterface |
|
80 |
|
|
81 |
C == Local variables == |
CEOP |
|
C I, J, K - Loop counters |
|
|
INTEGER i,j |
|
|
LOGICAL TOP_LAYER |
|
|
_RL afFacS, dfFacS |
|
|
_RL dSdx(1-OLx:sNx+OLx,1-OLy:sNy+OLy) |
|
|
_RL dSdy(1-OLx:sNx+OLx,1-OLy:sNy+OLy) |
|
|
|
|
|
afFacS = 1. _d 0 |
|
|
dfFacS = 1. _d 0 |
|
|
TOP_LAYER = K .EQ. 1 |
|
|
|
|
|
C--- Calculate advective and diffusive fluxes between cells. |
|
|
|
|
|
C-- Zonal flux (fZon is at west face of "salt" cell) |
|
|
C Advective component of zonal flux |
|
|
DO j=jMin,jMax |
|
|
DO i=iMin,iMax |
|
|
af(i,j) = |
|
|
& uTrans(i,j)*(salt(i,j,k,bi,bj)+salt(i-1,j,k,bi,bj))*0.5 _d 0 |
|
|
ENDDO |
|
|
ENDDO |
|
|
C Zonal tracer gradient |
|
|
DO j=jMin,jMax |
|
|
DO i=iMin,iMax |
|
|
dSdx(i,j) = _recip_dxC(i,j,bi,bj)* |
|
|
& (salt(i,j,k,bi,bj)-salt(i-1,j,k,bi,bj)) |
|
|
ENDDO |
|
|
ENDDO |
|
|
C Diffusive component of zonal flux |
|
|
DO j=jMin,jMax |
|
|
DO i=iMin,iMax |
|
|
df(i,j) = -(diffKhS+0.5*(KapGM(i,j)+KapGM(i-1,j)))* |
|
|
& xA(i,j)*dSdx(i,j) |
|
|
ENDDO |
|
|
ENDDO |
|
|
C Net zonal flux |
|
|
DO j=jMin,jMax |
|
|
DO i=iMin,iMax |
|
|
fZon(i,j) = afFacS*af(i,j) + dfFacS*df(i,j) |
|
|
ENDDO |
|
|
ENDDO |
|
|
|
|
|
C-- Meridional flux (fMer is at south face of "salt" cell) |
|
|
C Advective component of meridional flux |
|
|
DO j=jMin,jMax |
|
|
DO i=iMin,iMax |
|
|
C Advective component of meridional flux |
|
|
af(i,j) = |
|
|
& vTrans(i,j)*(salt(i,j,k,bi,bj)+salt(i,j-1,k,bi,bj))*0.5 _d 0 |
|
|
ENDDO |
|
|
ENDDO |
|
|
C Zonal tracer gradient |
|
|
DO j=jMin,jMax |
|
|
DO i=iMin,iMax |
|
|
dSdy(i,j) = _recip_dyC(i,j,bi,bj)* |
|
|
& (salt(i,j,k,bi,bj)-salt(i,j-1,k,bi,bj)) |
|
|
ENDDO |
|
|
ENDDO |
|
|
C Diffusive component of meridional flux |
|
|
DO j=jMin,jMax |
|
|
DO i=iMin,iMax |
|
|
df(i,j) = -(diffKhS+0.5*(KapGM(i,j)+KapGM(i,j-1)))* |
|
|
& yA(i,j)*dSdy(i,j) |
|
|
ENDDO |
|
|
ENDDO |
|
|
C Net meridional flux |
|
|
DO j=jMin,jMax |
|
|
DO i=iMin,iMax |
|
|
fMer(i,j) = afFacS*af(i,j) + dfFacS*df(i,j) |
|
|
ENDDO |
|
|
ENDDO |
|
|
|
|
|
C-- Interpolate terms for Redi/GM scheme |
|
|
DO j=jMin,jMax |
|
|
DO i=iMin,iMax |
|
|
dSdx(i,j) = 0.5*( |
|
|
& +0.5*(_maskW(i+1,j,k,bi,bj) |
|
|
& *_recip_dxC(i+1,j,bi,bj)* |
|
|
& (salt(i+1,j,k,bi,bj)-salt(i,j,k,bi,bj)) |
|
|
& +_maskW(i,j,k,bi,bj) |
|
|
& *_recip_dxC(i,j,bi,bj)* |
|
|
& (salt(i,j,k,bi,bj)-salt(i-1,j,k,bi,bj))) |
|
|
& +0.5*(_maskW(i+1,j,km1,bi,bj) |
|
|
& *_recip_dxC(i+1,j,bi,bj)* |
|
|
& (salt(i+1,j,km1,bi,bj)-salt(i,j,km1,bi,bj)) |
|
|
& +_maskW(i,j,km1,bi,bj) |
|
|
& *_recip_dxC(i,j,bi,bj)* |
|
|
& (salt(i,j,km1,bi,bj)-salt(i-1,j,km1,bi,bj))) |
|
|
& ) |
|
|
ENDDO |
|
|
ENDDO |
|
|
DO j=jMin,jMax |
|
|
DO i=iMin,iMax |
|
|
dSdy(i,j) = 0.5*( |
|
|
& +0.5*(_maskS(i,j,k,bi,bj) |
|
|
& *_recip_dyC(i,j,bi,bj)* |
|
|
& (salt(i,j,k,bi,bj)-salt(i,j-1,k,bi,bj)) |
|
|
& +_maskS(i,j+1,k,bi,bj) |
|
|
& *_recip_dyC(i,j+1,bi,bj)* |
|
|
& (salt(i,j+1,k,bi,bj)-salt(i,j,k,bi,bj))) |
|
|
& +0.5*(_maskS(i,j,km1,bi,bj) |
|
|
& *_recip_dyC(i,j,bi,bj)* |
|
|
& (salt(i,j,km1,bi,bj)-salt(i,j-1,km1,bi,bj)) |
|
|
& +_maskS(i,j+1,km1,bi,bj) |
|
|
& *_recip_dyC(i,j+1,bi,bj)* |
|
|
& (salt(i,j+1,km1,bi,bj)-salt(i,j,km1,bi,bj))) |
|
|
& ) |
|
|
ENDDO |
|
|
ENDDO |
|
|
|
|
|
C-- Vertical flux (fVerS) above |
|
|
C Advective component of vertical flux |
|
|
C Note: For K=1 then KM1=1 this gives a barZ(T) = T |
|
|
C (this plays the role of the free-surface correction) |
|
|
DO j=jMin,jMax |
|
|
DO i=iMin,iMax |
|
|
af(i,j) = |
|
|
& rTrans(i,j)*(salt(i,j,k,bi,bj)+salt(i,j,kM1,bi,bj))*0.5 _d 0 |
|
|
ENDDO |
|
|
ENDDO |
|
|
C Diffusive component of vertical flux |
|
|
C Note: For K=1 then KM1=1 this gives a dS/dz = 0 upper |
|
|
C boundary condition. |
|
|
DO j=jMin,jMax |
|
|
DO i=iMin,iMax |
|
|
df(i,j) = _rA(i,j,bi,bj)*( |
|
|
& -KapGM(i,j)*K13(i,j,k)*dSdx(i,j) |
|
|
& -KapGM(i,j)*K23(i,j,k)*dSdy(i,j) |
|
|
& ) |
|
|
ENDDO |
|
|
ENDDO |
|
|
IF (.NOT.implicitDiffusion) THEN |
|
|
DO j=jMin,jMax |
|
|
DO i=iMin,iMax |
|
|
df(i,j) = df(i,j) + _rA(i,j,bi,bj)*( |
|
|
& -KappaRS(i,j,k)*recip_drC(k) |
|
|
& *(salt(i,j,kM1,bi,bj)-salt(i,j,k,bi,bj))*rkFac |
|
|
& ) |
|
|
ENDDO |
|
|
ENDDO |
|
|
ENDIF |
|
|
#ifdef ALLOW_KPP |
|
|
IF (usingKPPmixing) THEN |
|
|
C-- Add non local transport coefficient (ghat term) to right-hand-side |
|
|
C The nonlocal transport term is noNrero only for scalars in unstable |
|
|
C (convective) forcing conditions. |
|
|
IF ( TOP_LAYER ) THEN |
|
|
DO j=jMin,jMax |
|
|
DO i=iMin,iMax |
|
|
df(i,j) = df(i,j) - _rA(i,j,bi,bj) * |
|
|
& EmPmR(i,j,bi,bj) * delZ(1) * |
|
|
& ( KappaRS(i,j,k) * KPPghat(i,j,k,bi,bj) ) |
|
|
ENDDO |
|
|
ENDDO |
|
|
ELSE |
|
|
DO j=jMin,jMax |
|
|
DO i=iMin,iMax |
|
|
df(i,j) = df(i,j) - _rA(i,j,bi,bj) * |
|
|
& EmPmR(i,j,bi,bj) * delZ(1) * |
|
|
& ( KappaRS(i,j,k) * KPPghat(i,j,k,bi,bj) |
|
|
& - KappaRS(i,j,k-1) * KPPghat(i,j,k-1,bi,bj) ) |
|
|
ENDDO |
|
|
ENDDO |
|
|
ENDIF |
|
|
ENDIF |
|
|
#endif /* ALLOW_KPP */ |
|
82 |
|
|
83 |
C Net vertical flux |
C === Local variables === |
84 |
DO j=jMin,jMax |
LOGICAL calcAdvection |
85 |
DO i=iMin,iMax |
|
86 |
fVerS(i,j,kUp) = ( afFacS*af(i,j)+ dfFacS*df(i,j) )*maskUp(i,j) |
#ifdef ALLOW_AUTODIFF_TAMC |
87 |
ENDDO |
C-- only the kUp part of fverS is set in this subroutine |
88 |
ENDDO |
C-- the kDown is still required |
89 |
IF ( TOP_LAYER ) THEN |
fVerS(1,1,kDown) = fVerS(1,1,kDown) |
90 |
DO j=jMin,jMax |
#endif |
|
DO i=iMin,iMax |
|
|
fVerS(i,j,kUp) = afFacS*af(i,j)*freeSurfFac |
|
|
ENDDO |
|
|
ENDDO |
|
|
ENDIF |
|
91 |
|
|
92 |
C-- Tendency is minus divergence of the fluxes. |
calcAdvection = saltAdvection .AND. .NOT.saltMultiDimAdvec |
93 |
C Note. Tendency terms will only be correct for range |
CALL GAD_CALC_RHS( |
94 |
C i=iMin+1:iMax-1, j=jMin+1:jMax-1. Edge points |
I bi,bj,iMin,iMax,jMin,jMax,k,kM1,kUp,kDown, |
95 |
C will contain valid floating point numbers but |
I xA,yA,uTrans,vTrans,rTrans,rTransKp1,maskUp, |
96 |
C they are not algorithmically correct. These points |
I uVel, vVel, wVel, |
97 |
C are not used. |
I diffKhS, diffK4S, KappaRS, Salt, |
98 |
DO j=jMin,jMax |
I GAD_SALINITY, saltAdvScheme, |
99 |
DO i=iMin,iMax |
I calcAdvection, saltImplVertAdv, |
100 |
#define _recip_VolS1(i,j,k,bi,bj) _recip_hFacC(i,j,k,bi,bj)*recip_drF(k) |
U fVerS, gS, |
101 |
#define _recip_VolS2(i,j,k,bi,bj) /_rA(i,j,bi,bj) |
I myThid ) |
102 |
gS(i,j,k,bi,bj)= |
|
103 |
& -_recip_VolS1(i,j,k,bi,bj) |
C-- External salinity forcing term(s) inside Adams-Bashforth: |
104 |
& _recip_VolS2(i,j,k,bi,bj) |
IF ( saltForcing .AND. forcing_In_AB ) |
105 |
& *( |
& CALL EXTERNAL_FORCING_S( |
106 |
& +( fZon(i+1,j)-fZon(i,j) ) |
I iMin,iMax,jMin,jMax,bi,bj,k, |
107 |
& +( fMer(i,j+1)-fMer(i,j) ) |
I myTime,myThid) |
|
& +( fVerS(i,j,kUp)-fVerS(i,j,kDown) )*rkFac |
|
|
& ) |
|
|
ENDDO |
|
|
ENDDO |
|
108 |
|
|
109 |
C-- External forcing term(s) |
IF ( saltAdamsBashforth ) THEN |
110 |
CALL EXTERNAL_FORCING_S( |
CALL ADAMS_BASHFORTH2( |
111 |
|
I bi, bj, K, |
112 |
|
U gS, gSnm1, |
113 |
|
I myIter, myThid ) |
114 |
|
ENDIF |
115 |
|
|
116 |
|
C-- External salinity forcing term(s) outside Adams-Bashforth: |
117 |
|
IF ( saltForcing .AND. .NOT.forcing_In_AB ) |
118 |
|
& CALL EXTERNAL_FORCING_S( |
119 |
I iMin,iMax,jMin,jMax,bi,bj,k, |
I iMin,iMax,jMin,jMax,bi,bj,k, |
120 |
I maskC, |
I myTime,myThid) |
|
I myCurrentTime,myThid) |
|
121 |
|
|
122 |
#ifdef INCLUDE_LAT_CIRC_FFT_FILTER_CODE |
#ifdef NONLIN_FRSURF |
123 |
C-- |
IF (nonlinFreeSurf.GT.0) THEN |
124 |
CALL FILTER_LATCIRCS_FFT_APPLY( gS, 1, sNy, k, k, bi, bj, 1, myThid) |
CALL FREESURF_RESCALE_G( |
125 |
#endif |
I bi, bj, K, |
126 |
|
U gS, |
127 |
|
I myThid ) |
128 |
|
IF ( saltAdamsBashforth ) |
129 |
|
& CALL FREESURF_RESCALE_G( |
130 |
|
I bi, bj, K, |
131 |
|
U gSnm1, |
132 |
|
I myThid ) |
133 |
|
ENDIF |
134 |
|
#endif /* NONLIN_FRSURF */ |
135 |
|
|
136 |
RETURN |
RETURN |
137 |
END |
END |