1 |
C $Header$ |
C $Header$ |
2 |
|
C $Name$ |
3 |
|
|
4 |
#include "CPP_EEOPTIONS.h" |
#include "PACKAGES_CONFIG.h" |
5 |
|
#include "CPP_OPTIONS.h" |
6 |
|
|
7 |
CStartOfInterFace |
CBOP |
8 |
SUBROUTINE CALC_GS( |
C !ROUTINE: CALC_GS |
9 |
|
C !INTERFACE: |
10 |
|
SUBROUTINE CALC_GS( |
11 |
I bi,bj,iMin,iMax,jMin,jMax,k,kM1,kUp,kDown, |
I bi,bj,iMin,iMax,jMin,jMax,k,kM1,kUp,kDown, |
12 |
I xA,yA,uTrans,vTrans,wTrans,maskup, |
I xA, yA, maskUp, uFld, vFld, wFld, |
13 |
U af,df,fZon,fMer, fVerS, |
I uTrans, vTrans, rTrans, rTransKp1, |
14 |
I myThid ) |
I KappaRS, |
15 |
C /==========================================================\ |
U fVerS, |
16 |
C | SUBROUTINE CALC_GS | |
I myTime,myIter,myThid ) |
17 |
C | o Calculate the salinity tendency terms. | |
C !DESCRIPTION: \bv |
18 |
C |==========================================================| |
C *==========================================================* |
19 |
C | A procedure called EXTERNAL_FORCING_S is called from | |
C | SUBROUTINE CALC_GS |
20 |
C | here. These procedures can be used to add per problem | |
C | o Calculate the salt tendency terms. |
21 |
C | fresh water flux source terms. | |
C *==========================================================* |
22 |
C | Note: Although it is slightly counter-intuitive the | |
C | A procedure called EXTERNAL_FORCING_S is called from |
23 |
C | EXTERNAL_FORCING routine is not the place to put | |
C | here. These procedures can be used to add per problem |
24 |
C | file I/O. Instead files that are required to | |
C | E-P flux source terms. |
25 |
C | calculate the external source terms are generally | |
C | Note: Although it is slightly counter-intuitive the |
26 |
C | read during the model main loop. This makes the | |
C | EXTERNAL_FORCING routine is not the place to put |
27 |
C | logisitics of multi-processing simpler and also | |
C | file I/O. Instead files that are required to |
28 |
C | makes the adjoint generation simpler. It also | |
C | calculate the external source terms are generally |
29 |
C | allows for I/O to overlap computation where that | |
C | read during the model main loop. This makes the |
30 |
C | is supported by hardware. | |
C | logisitics of multi-processing simpler and also |
31 |
C | Aside from the problem specific term the code here | |
C | makes the adjoint generation simpler. It also |
32 |
C | forms the tendency terms due to advection and mixing | |
C | allows for I/O to overlap computation where that |
33 |
C | The baseline implementation here uses a centered | |
C | is supported by hardware. |
34 |
C | difference form for the advection term and a tensorial | |
C | Aside from the problem specific term the code here |
35 |
C | divergence of a flux form for the diffusive term. The | |
C | forms the tendency terms due to advection and mixing |
36 |
C | diffusive term is formulated so that isopycnal mixing and| |
C | The baseline implementation here uses a centered |
37 |
C | GM-style subgrid-scale terms can be incorporated b simply| |
C | difference form for the advection term and a tensorial |
38 |
C | setting the diffusion tensor terms appropriately. | |
C | divergence of a flux form for the diffusive term. The |
39 |
C \==========================================================/ |
C | diffusive term is formulated so that isopycnal mixing and |
40 |
IMPLICIT NONE |
C | GM-style subgrid-scale terms can be incorporated b simply |
41 |
|
C | setting the diffusion tensor terms appropriately. |
42 |
|
C *==========================================================* |
43 |
|
C \ev |
44 |
|
|
45 |
|
C !USES: |
46 |
|
IMPLICIT NONE |
47 |
C == GLobal variables == |
C == GLobal variables == |
48 |
#include "SIZE.h" |
#include "SIZE.h" |
49 |
#include "DYNVARS.h" |
#include "DYNVARS.h" |
50 |
#include "EEPARAMS.h" |
#include "EEPARAMS.h" |
51 |
#include "PARAMS.h" |
#include "PARAMS.h" |
52 |
#include "GRID.h" |
#include "RESTART.h" |
53 |
|
#ifdef ALLOW_GENERIC_ADVDIFF |
54 |
|
#include "GAD.h" |
55 |
|
#endif |
56 |
|
#ifdef ALLOW_AUTODIFF_TAMC |
57 |
|
# include "tamc.h" |
58 |
|
# include "tamc_keys.h" |
59 |
|
#endif |
60 |
|
|
61 |
|
C !INPUT/OUTPUT PARAMETERS: |
62 |
C == Routine arguments == |
C == Routine arguments == |
63 |
C fZon - Work array for flux of temperature in the east-west |
C bi, bj, :: tile indices |
64 |
C direction at the west face of a cell. |
C iMin,iMax, jMin,jMax :: Range of points for which calculation |
65 |
C fMer - Work array for flux of temperature in the north-south |
C results will be set. |
66 |
C direction at the south face of a cell. |
C k :: vertical index |
67 |
C fVerS - Flux of salinity (S) in the vertical |
C kM1 :: =k-1 for k>1, =1 for k=1 |
68 |
C direction at the upper(U) and lower(D) faces of a cell. |
C kUp :: index into 2 1/2D array, toggles between 1|2 |
69 |
C maskUp - Land mask used to denote base of the domain. |
C kDown :: index into 2 1/2D array, toggles between 2|1 |
70 |
C xA - Tracer cell face area normal to X |
C xA :: Tracer cell face area normal to X |
71 |
C yA - Tracer cell face area normal to X |
C yA :: Tracer cell face area normal to X |
72 |
C uTrans - Zonal volume transport through cell face |
C maskUp :: Land mask used to denote base of the domain. |
73 |
C vTrans - Meridional volume transport through cell face |
C uFld,vFld :: Local copy of horizontal velocity field |
74 |
C wTrans - Vertical volume transport through cell face |
C wFld :: Local copy of vertical velocity field |
75 |
C af - Advective flux component work array |
C uTrans :: Zonal volume transport through cell face |
76 |
C df - Diffusive flux component work array |
C vTrans :: Meridional volume transport through cell face |
77 |
C bi, bj, iMin, iMax, jMin, jMax - Range of points for which calculation |
C rTrans :: Vertical volume transport at interface k |
78 |
C results will be set. |
C rTransKp1 :: Vertical volume transport at inteface k+1 |
79 |
C myThid - Instance number for this innvocation of CALC_GS |
C KappaRS :: Vertical diffusion for Salinity |
80 |
_RL fZon (1-OLx:sNx+OLx,1-OLy:sNy+OLy) |
C fVerS :: Flux of salt (S) in the vertical direction |
81 |
_RL fMer (1-OLx:sNx+OLx,1-OLy:sNy+OLy) |
C at the upper(U) and lower(D) faces of a cell. |
82 |
_RL fVerS (1-OLx:sNx+OLx,1-OLy:sNy+OLy,2) |
C myTime :: current time |
83 |
_RS xA (1-OLx:sNx+OLx,1-OLy:sNy+OLy) |
C myIter :: current iteration number |
84 |
_RS yA (1-OLx:sNx+OLx,1-OLy:sNy+OLy) |
C myThid :: my Thread Id. number |
85 |
_RL uTrans(1-OLx:sNx+OLx,1-OLy:sNy+OLy) |
|
|
_RL vTrans(1-OLx:sNx+OLx,1-OLy:sNy+OLy) |
|
|
_RL wTrans(1-OLx:sNx+OLx,1-OLy:sNy+OLy) |
|
|
_RS maskUp(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) |
|
|
INTEGER kUp,kDown,kM1 |
|
86 |
INTEGER bi,bj,iMin,iMax,jMin,jMax |
INTEGER bi,bj,iMin,iMax,jMin,jMax |
87 |
|
INTEGER k,kUp,kDown,kM1 |
88 |
|
_RS xA (1-OLx:sNx+OLx,1-OLy:sNy+OLy) |
89 |
|
_RS yA (1-OLx:sNx+OLx,1-OLy:sNy+OLy) |
90 |
|
_RS maskUp (1-OLx:sNx+OLx,1-OLy:sNy+OLy) |
91 |
|
_RL uFld (1-OLx:sNx+OLx,1-OLy:sNy+OLy) |
92 |
|
_RL vFld (1-OLx:sNx+OLx,1-OLy:sNy+OLy) |
93 |
|
_RL wFld (1-OLx:sNx+OLx,1-OLy:sNy+OLy) |
94 |
|
_RL uTrans (1-OLx:sNx+OLx,1-OLy:sNy+OLy) |
95 |
|
_RL vTrans (1-OLx:sNx+OLx,1-OLy:sNy+OLy) |
96 |
|
_RL rTrans (1-OLx:sNx+OLx,1-OLy:sNy+OLy) |
97 |
|
_RL rTransKp1(1-OLx:sNx+OLx,1-OLy:sNy+OLy) |
98 |
|
_RL KappaRS(1-OLx:sNx+OLx,1-OLy:sNy+OLy) |
99 |
|
_RL fVerS (1-OLx:sNx+OLx,1-OLy:sNy+OLy,2) |
100 |
|
_RL myTime |
101 |
|
INTEGER myIter |
102 |
INTEGER myThid |
INTEGER myThid |
103 |
CEndOfInterface |
CEOP |
104 |
|
|
105 |
C == Local variables == |
#ifdef ALLOW_GENERIC_ADVDIFF |
106 |
C I, J, K - Loop counters |
C === Local variables === |
107 |
INTEGER i,j,k |
LOGICAL calcAdvection |
108 |
INTEGER afFacS, dfFacS |
INTEGER iterNb |
109 |
|
#ifdef ALLOW_ADAMSBASHFORTH_3 |
110 |
afFacS = 1. _d 0 |
INTEGER m1, m2 |
111 |
dfFacS = 1. _d 0 |
#endif |
112 |
|
|
113 |
C--- |
#ifdef ALLOW_AUTODIFF_TAMC |
114 |
C--- Calculate advective and diffusive fluxes between cells. |
act1 = bi - myBxLo(myThid) |
115 |
C--- |
max1 = myBxHi(myThid) - myBxLo(myThid) + 1 |
116 |
|
act2 = bj - myByLo(myThid) |
117 |
C-- Zonal flux (fZon is at west face of "salt" cell) |
max2 = myByHi(myThid) - myByLo(myThid) + 1 |
118 |
C Advective component of zonal flux |
act3 = myThid - 1 |
119 |
DO j=jMin,jMax |
max3 = nTx*nTy |
120 |
DO i=iMin,iMax |
act4 = ikey_dynamics - 1 |
121 |
af(i,j) = |
itdkey = (act1 + 1) + act2*max1 |
122 |
& uTrans(i,j)*(salt(i,j,k,bi,bj)+salt(i-1,j,k,bi,bj))*0.5 _d 0 |
& + act3*max1*max2 |
123 |
ENDDO |
& + act4*max1*max2*max3 |
124 |
ENDDO |
kkey = (itdkey-1)*Nr + k |
125 |
C Diffusive component of zonal flux |
#endif /* ALLOW_AUTODIFF_TAMC */ |
126 |
DO j=jMin,jMax |
|
127 |
DO i=iMin,iMax |
#ifdef ALLOW_AUTODIFF_TAMC |
128 |
df(i,j) = |
C-- only the kUp part of fverS is set in this subroutine |
129 |
& -diffKhS*xA(i,j)*_rdxC(i,j,bi,bj) |
C-- the kDown is still required |
130 |
& *(salt(i,j,k,bi,bj)-salt(i-1,j,k,bi,bj)) |
fVerS(1,1,kDown) = fVerS(1,1,kDown) |
131 |
ENDDO |
# ifdef NONLIN_FRSURF |
132 |
ENDDO |
CADJ STORE fVerS(:,:,:) = |
133 |
C Net zonal flux |
CADJ & comlev1_bibj_k, key=kkey, byte=isbyte, |
134 |
DO j=jMin,jMax |
CADJ & kind = isbyte |
135 |
DO i=iMin,iMax |
CADJ STORE gsNm1(:,:,k,bi,bj) = |
136 |
fZon(i,j) = afFacS*af(i,j) + dfFacS*df(i,j) |
CADJ & comlev1_bibj_k, key=kkey, byte=isbyte, |
137 |
ENDDO |
CADJ & kind = isbyte |
138 |
ENDDO |
# endif |
139 |
|
#endif |
140 |
C-- Meridional flux (fMer is at south face of "salt" cell) |
|
141 |
C Advective component of meridional flux |
C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----| |
142 |
DO j=jMin,jMax |
|
143 |
DO i=iMin,iMax |
calcAdvection = saltAdvection .AND. .NOT.saltMultiDimAdvec |
144 |
C Advective component of meridional flux |
iterNb = myIter |
145 |
af(i,j) = |
IF (staggerTimeStep) iterNb = myIter - 1 |
146 |
& vTrans(i,j)*(salt(i,j,k,bi,bj)+salt(i,j-1,k,bi,bj))*0.5 _d 0 |
|
147 |
ENDDO |
#ifdef ALLOW_ADAMSBASHFORTH_3 |
148 |
ENDDO |
m1 = 1 + MOD(iterNb+1,2) |
149 |
C Diffusive component of meridional flux |
m2 = 1 + MOD( iterNb ,2) |
150 |
DO j=jMin,jMax |
CALL GAD_CALC_RHS( |
151 |
DO i=iMin,iMax |
I bi,bj,iMin,iMax,jMin,jMax,k,kM1,kUp,kDown, |
152 |
df(i,j) = |
I xA, yA, maskUp, uFld, vFld, wFld, |
153 |
& -diffKhS*yA(i,j)*rdyC(i,j,bi,bj) |
I uTrans, vTrans, rTrans, rTransKp1, |
154 |
& *(salt(i,j,k,bi,bj)-salt(i,j-1,k,bi,bj)) |
I diffKhS, diffK4S, KappaRS, |
155 |
ENDDO |
I gsNm(1-Olx,1-Oly,1,1,1,m2), salt, |
156 |
ENDDO |
I GAD_SALINITY, saltAdvScheme, saltVertAdvScheme, |
157 |
C Net meridional flux |
I calcAdvection, saltImplVertAdv, AdamsBashforth_S, |
158 |
DO j=jMin,jMax |
I useGMRedi, useKPP, |
159 |
DO i=iMin,iMax |
U fVerS, gS, |
160 |
fMer(i,j) = afFacS*af(i,j) + dfFacS*df(i,j) |
I myTime, myIter, myThid ) |
161 |
ENDDO |
#else /* ALLOW_ADAMSBASHFORTH_3 */ |
162 |
ENDDO |
CALL GAD_CALC_RHS( |
163 |
|
I bi,bj,iMin,iMax,jMin,jMax,k,kM1,kUp,kDown, |
164 |
C-- Vertical flux (fVerS) above |
I xA, yA, maskUp, uFld, vFld, wFld, |
165 |
C Note: For K=1 then KM1=1 this gives a dS/dz = 0 upper |
I uTrans, vTrans, rTrans, rTransKp1, |
166 |
C boundary condition. |
I diffKhS, diffK4S, KappaRS, gsNm1, salt, |
167 |
C Advective component of vertical flux |
I GAD_SALINITY, saltAdvScheme, saltVertAdvScheme, |
168 |
DO j=jMin,jMax |
I calcAdvection, saltImplVertAdv, AdamsBashforth_S, |
169 |
DO i=iMin,iMax |
I useGMRedi, useKPP, |
170 |
af(i,j) = |
U fVerS, gS, |
171 |
& wTrans(i,j)*(salt(i,j,k,bi,bj)+salt(i,j,kM1,bi,bj))*0.5 _d 0 |
I myTime, myIter, myThid ) |
172 |
ENDDO |
#endif /* ALLOW_ADAMSBASHFORTH_3 */ |
173 |
ENDDO |
|
174 |
C Diffusive component of vertical flux |
C-- External salinity forcing term(s) inside Adams-Bashforth: |
175 |
DO j=jMin,jMax |
IF ( saltForcing .AND. tracForcingOutAB.NE.1 ) |
176 |
DO i=iMin,iMax |
& CALL EXTERNAL_FORCING_S( |
177 |
df(i,j) = |
I iMin,iMax,jMin,jMax,bi,bj,k, |
178 |
& -diffKzS*zA(i,j,bi,bj)*rdzC(k) |
I myTime,myThid) |
179 |
& *(salt(i,j,kM1,bi,bj)-salt(i,j,k,bi,bj)) |
|
180 |
ENDDO |
IF ( AdamsBashforthGs ) THEN |
181 |
ENDDO |
#ifdef ALLOW_ADAMSBASHFORTH_3 |
182 |
C Net vertical flux |
CALL ADAMS_BASHFORTH3( |
183 |
DO j=jMin,jMax |
I bi, bj, k, |
184 |
DO i=iMin,iMax |
U gS, gsNm, |
185 |
fVerS(i,j,kUp) = (afFacS*af(i,j) + dfFacS*df(i,j))*maskUp(i,j) |
I saltStartAB, iterNb, myThid ) |
186 |
ENDDO |
#else |
187 |
ENDDO |
CALL ADAMS_BASHFORTH2( |
188 |
|
I bi, bj, k, |
189 |
C-- Tendency is minus divergence of the fluxes. |
U gS, gsNm1, |
190 |
C Note. Tendency terms will only be correct for range |
I saltStartAB, iterNb, myThid ) |
191 |
C i=iMin+1:iMax-1, j=jMin+1:jMax-1. Edge points |
#endif |
192 |
C will contain valid floating point numbers but |
ENDIF |
193 |
C they are not algorithmically correct. These points |
|
194 |
C are not used. |
C-- External salinity forcing term(s) outside Adams-Bashforth: |
195 |
DO j=jMin,jMax |
IF ( saltForcing .AND. tracForcingOutAB.EQ.1 ) |
196 |
DO i=iMin,iMax |
& CALL EXTERNAL_FORCING_S( |
197 |
gS(i,j,k,bi,bj)= |
I iMin,iMax,jMin,jMax,bi,bj,k, |
198 |
& -rHFacC(i,j,k,bi,bj)*rdzF(k)*rDxF(i,j,bi,bj)*rDyF(i,j,bi,bj) |
I myTime,myThid) |
199 |
& *( |
|
200 |
& +( fZon(i+1,j)-fZon(i,j) ) |
#ifdef NONLIN_FRSURF |
201 |
& +( fMer(i,j+1)-fMer(i,j) ) |
IF (nonlinFreeSurf.GT.0) THEN |
202 |
& +( fVerS(i,j,kUp)-fVerS(i,j,kDown) ) |
CALL FREESURF_RESCALE_G( |
203 |
& ) |
I bi, bj, k, |
204 |
ENDDO |
U gS, |
205 |
ENDDO |
I myThid ) |
206 |
|
IF ( AdamsBashforthGs ) THEN |
207 |
|
#ifdef ALLOW_ADAMSBASHFORTH_3 |
208 |
|
CALL FREESURF_RESCALE_G( |
209 |
|
I bi, bj, k, |
210 |
|
U gsNm(1-OLx,1-OLy,1,1,1,1), |
211 |
|
I myThid ) |
212 |
|
CALL FREESURF_RESCALE_G( |
213 |
|
I bi, bj, k, |
214 |
|
U gsNm(1-OLx,1-OLy,1,1,1,2), |
215 |
|
I myThid ) |
216 |
|
#else |
217 |
|
CALL FREESURF_RESCALE_G( |
218 |
|
I bi, bj, k, |
219 |
|
U gsNm1, |
220 |
|
I myThid ) |
221 |
|
#endif |
222 |
|
ENDIF |
223 |
|
ENDIF |
224 |
|
#endif /* NONLIN_FRSURF */ |
225 |
|
|
226 |
C-- External haline forcing term(s) |
#endif /* ALLOW_GENERIC_ADVDIFF */ |
227 |
|
|
228 |
RETURN |
RETURN |
229 |
END |
END |