1 |
C $Header: /u/gcmpack/MITgcm/model/src/pre_cg3d.F,v 1.2 2010/01/23 00:04:03 jmc Exp $ |
2 |
C $Name: $ |
3 |
|
4 |
#include "PACKAGES_CONFIG.h" |
5 |
#include "CPP_OPTIONS.h" |
6 |
|
7 |
CBOP |
8 |
C !ROUTINE: PRE_CG3D |
9 |
C !INTERFACE: |
10 |
SUBROUTINE PRE_CG3D( |
11 |
I oldFreeSurfTerm, |
12 |
I cg2d_x, |
13 |
U cg3d_b, |
14 |
I myTime, myIter, myThid ) |
15 |
|
16 |
C !DESCRIPTION: |
17 |
C Called from SOLVE_FOR_PRESSURE, before 3-D solver (cg3d): |
18 |
C Finish calculation of 3-D RHS after 2-D inversionis done. |
19 |
|
20 |
C !USES: |
21 |
IMPLICIT NONE |
22 |
C == Global variables |
23 |
#include "SIZE.h" |
24 |
#include "EEPARAMS.h" |
25 |
#include "PARAMS.h" |
26 |
#include "GRID.h" |
27 |
#include "SURFACE.h" |
28 |
#include "FFIELDS.h" |
29 |
#include "DYNVARS.h" |
30 |
#ifdef ALLOW_NONHYDROSTATIC |
31 |
#include "NH_VARS.h" |
32 |
#endif |
33 |
|
34 |
C === Functions ==== |
35 |
c LOGICAL DIFFERENT_MULTIPLE |
36 |
c EXTERNAL DIFFERENT_MULTIPLE |
37 |
|
38 |
C !INPUT/OUTPUT PARAMETERS: |
39 |
C == Routine arguments == |
40 |
C oldFreeSurfTerm :: Treat free-surface term in the old way (no exactConserv) |
41 |
C cg2d_x :: Solution vector of the 2-D solver equation a.x=b |
42 |
C cg3d_b :: Right Hand side vector of the 3-D solver equation A.X=B |
43 |
C myTime :: Current time in simulation |
44 |
C myIter :: Current iteration number in simulation |
45 |
C myThid :: My Thread Id number |
46 |
LOGICAL oldFreeSurfTerm |
47 |
_RL cg2d_x(1-OLx:sNx+OLx,1-OLy:sNy+OLy,nSx,nSy) |
48 |
_RL cg3d_b(1-OLx:sNx+OLx,1-OLy:sNy+OLy,Nr,nSx,nSy) |
49 |
_RL myTime |
50 |
INTEGER myIter |
51 |
INTEGER myThid |
52 |
|
53 |
#ifdef ALLOW_NONHYDROSTATIC |
54 |
C !LOCAL VARIABLES: |
55 |
C == Local variables == |
56 |
INTEGER i,j,k,bi,bj |
57 |
INTEGER ks, kp1 |
58 |
c CHARACTER*10 sufx |
59 |
c CHARACTER*(MAX_LEN_MBUF) msgBuf |
60 |
_RL tmpFac, tmpSurf |
61 |
_RL wFacKm, wFacKp |
62 |
_RL uf(1-Olx:sNx+Olx,1-Oly:sNy+Oly) |
63 |
_RL vf(1-Olx:sNx+Olx,1-Oly:sNy+Oly) |
64 |
#ifdef NONLIN_FRSURF |
65 |
_RL tmpVar(1-Olx:sNx+Olx,1-Oly:sNy+Oly) |
66 |
#endif |
67 |
CEOP |
68 |
|
69 |
c IF ( use3Dsolver ) THEN |
70 |
|
71 |
C-- Solve for a three-dimensional pressure term (NH or IGW or both ). |
72 |
C see CG3D.h for the interface to this routine. |
73 |
DO bj=myByLo(myThid),myByHi(myThid) |
74 |
DO bi=myBxLo(myThid),myBxHi(myThid) |
75 |
|
76 |
C-- Add EmPmR contribution to top level cg3d_b: |
77 |
C (has been done for cg2d_b ; and addMass was added by CALC_DIV_GHAT) |
78 |
IF ( useRealFreshWaterFlux.AND.fluidIsWater ) THEN |
79 |
tmpFac = freeSurfFac*mass2rUnit |
80 |
IF (exactConserv) |
81 |
& tmpFac = freeSurfFac*mass2rUnit*implicDiv2DFlow |
82 |
ks = 1 |
83 |
IF ( usingPCoords ) ks = Nr |
84 |
DO j=1,sNy |
85 |
DO i=1,sNx |
86 |
cg3d_b(i,j,ks,bi,bj) = cg3d_b(i,j,ks,bi,bj) |
87 |
& + tmpFac*_rA(i,j,bi,bj)*EmPmR(i,j,bi,bj)/deltaTMom |
88 |
ENDDO |
89 |
ENDDO |
90 |
ENDIF |
91 |
|
92 |
C-- Update or Add free-surface contribution to cg3d_b: |
93 |
c IF ( select_rStar.EQ.0 .AND. exactConserv ) THEN |
94 |
IF ( select_rStar.EQ.0 .AND. .NOT.oldFreeSurfTerm ) THEN |
95 |
tmpFac = 0. |
96 |
DO j=1,sNy |
97 |
DO i=1,sNx |
98 |
IF ( selectNHfreeSurf.GE.1 ) THEN |
99 |
tmpSurf = deltaTMom*deltaTfreesurf |
100 |
& *Bo_surf(i,j,bi,bj)*recip_drC(1) |
101 |
& *implicitNHPress*implicDiv2DFlow |
102 |
tmpSurf = ( tmpSurf*( etaN(i,j,bi,bj)-etaH(i,j,bi,bj) ) |
103 |
& +implicDiv2DFlow*deltaTfreesurf |
104 |
c & *(wVel(i,j,1,bi,bj)+PmE) |
105 |
& *wVel(i,j,1,bi,bj) |
106 |
& )/(1. _d 0 + tmpSurf ) |
107 |
ELSE |
108 |
tmpSurf = etaN(i,j,bi,bj)-etaH(i,j,bi,bj) |
109 |
ENDIF |
110 |
ks = ksurfC(i,j,bi,bj) |
111 |
IF ( ks.LE.Nr ) THEN |
112 |
cg3d_b(i,j,ks,bi,bj) = cg3d_b(i,j,ks,bi,bj) |
113 |
& +freeSurfFac*tmpSurf |
114 |
c & +freeSurfFac*(etaN(i,j,bi,bj)-etaH(i,j,bi,bj)) |
115 |
& *_rA(i,j,bi,bj)*deepFac2F(ks) |
116 |
& /deltaTMom/deltaTfreesurf |
117 |
ENDIF |
118 |
ENDDO |
119 |
ENDDO |
120 |
#ifdef NONLIN_FRSURF |
121 |
ELSEIF ( select_rStar.NE.0 ) THEN |
122 |
tmpFac = 0. |
123 |
DO j=1,sNy |
124 |
DO i=1,sNx |
125 |
ks = ksurfC(i,j,bi,bj) |
126 |
tmpVar(i,j) = freeSurfFac |
127 |
& *( etaN(i,j,bi,bj) - etaH(i,j,bi,bj) ) |
128 |
& *_rA(i,j,bi,bj)*deepFac2F(ks) |
129 |
& /deltaTMom/deltaTfreesurf |
130 |
& *recip_Rcol(i,j,bi,bj) |
131 |
ENDDO |
132 |
ENDDO |
133 |
DO k=1,Nr |
134 |
DO j=1,sNy |
135 |
DO i=1,sNx |
136 |
cg3d_b(i,j,k,bi,bj) = cg3d_b(i,j,k,bi,bj) |
137 |
& + tmpVar(i,j)*drF(k)*h0FacC(i,j,k,bi,bj) |
138 |
ENDDO |
139 |
ENDDO |
140 |
ENDDO |
141 |
#endif /* NONLIN_FRSURF */ |
142 |
ELSEIF ( usingZCoords ) THEN |
143 |
C- Z coordinate: assume surface @ level k=1 |
144 |
tmpFac = freeSurfFac*deepFac2F(1) |
145 |
ELSE |
146 |
C- Other than Z coordinate: no assumption on surface level index |
147 |
tmpFac = 0. |
148 |
DO j=1,sNy |
149 |
DO i=1,sNx |
150 |
ks = ksurfC(i,j,bi,bj) |
151 |
IF ( ks.LE.Nr ) THEN |
152 |
cg3d_b(i,j,ks,bi,bj) = cg3d_b(i,j,ks,bi,bj) |
153 |
& +freeSurfFac*etaN(i,j,bi,bj)/deltaTfreesurf |
154 |
& *_rA(i,j,bi,bj)*deepFac2F(ks)/deltaTmom |
155 |
ENDIF |
156 |
ENDDO |
157 |
ENDDO |
158 |
ENDIF |
159 |
|
160 |
C---+----1----+----2----+----3----+----4----+----5----+----6----+----7-|--+----| |
161 |
|
162 |
C-- Finish updating cg3d_b: 1) increment in horiz velocity due to new cg2d_x |
163 |
C 2) add vertical velocity contribution. |
164 |
DO j=1,sNy+1 |
165 |
DO i=1,sNx+1 |
166 |
uf(i,j) = -_recip_dxC(i,j,bi,bj) |
167 |
& * implicSurfPress*implicDiv2DFlow |
168 |
& *(cg2d_x(i,j,bi,bj)-cg2d_x(i-1,j,bi,bj)) |
169 |
#ifdef ALLOW_OBCS |
170 |
& *maskInC(i,j,bi,bj)*maskInC(i-1,j,bi,bj) |
171 |
#endif |
172 |
vf(i,j) = -_recip_dyC(i,j,bi,bj) |
173 |
& * implicSurfPress*implicDiv2DFlow |
174 |
& *(cg2d_x(i,j,bi,bj)-cg2d_x(i,j-1,bi,bj)) |
175 |
#ifdef ALLOW_OBCS |
176 |
& *maskInC(i,j,bi,bj)*maskInC(i,j-1,bi,bj) |
177 |
#endif |
178 |
ENDDO |
179 |
ENDDO |
180 |
|
181 |
C Note: with implicDiv2DFlow < 1, wVel contribution to cg3d_b is similar to |
182 |
C uVel,vVel contribution to cg2d_b when exactConserv=T, since wVel is |
183 |
C always recomputed from continuity eq (like eta when exactConserv=T) |
184 |
k=1 |
185 |
kp1 = MIN(k+1,Nr) |
186 |
wFacKp = implicDiv2DFlow*deepFac2F(kp1)*rhoFacF(kp1) |
187 |
IF (k.GE.Nr) wFacKp = 0. |
188 |
DO j=1,sNy |
189 |
DO i=1,sNx |
190 |
cg3d_b(i,j,k,bi,bj) = cg3d_b(i,j,k,bi,bj) |
191 |
& +drF(k)*dyG(i+1,j,bi,bj)*_hFacW(i+1,j,k,bi,bj)*uf(i+1,j) |
192 |
& -drF(k)*dyG( i ,j,bi,bj)*_hFacW( i ,j,k,bi,bj)*uf( i ,j) |
193 |
& +drF(k)*dxG(i,j+1,bi,bj)*_hFacS(i,j+1,k,bi,bj)*vf(i,j+1) |
194 |
& -drF(k)*dxG(i, j ,bi,bj)*_hFacS(i, j ,k,bi,bj)*vf(i, j ) |
195 |
& +( tmpFac*etaN(i,j,bi,bj)/deltaTfreesurf |
196 |
& -wVel(i,j,kp1,bi,bj)*wFacKp |
197 |
& )*_rA(i,j,bi,bj)/deltaTmom |
198 |
ENDDO |
199 |
ENDDO |
200 |
DO k=2,Nr |
201 |
kp1 = MIN(k+1,Nr) |
202 |
C- deepFac & rhoFac cancel with the ones in uf[=del_i(Phi)/dx],vf ; |
203 |
C both appear in wVel term, but at 2 different levels |
204 |
wFacKm = implicDiv2DFlow*deepFac2F( k )*rhoFacF( k ) |
205 |
wFacKp = implicDiv2DFlow*deepFac2F(kp1)*rhoFacF(kp1) |
206 |
IF (k.GE.Nr) wFacKp = 0. |
207 |
DO j=1,sNy |
208 |
DO i=1,sNx |
209 |
cg3d_b(i,j,k,bi,bj) = cg3d_b(i,j,k,bi,bj) |
210 |
& +drF(k)*dyG(i+1,j,bi,bj)*_hFacW(i+1,j,k,bi,bj)*uf(i+1,j) |
211 |
& -drF(k)*dyG( i ,j,bi,bj)*_hFacW( i ,j,k,bi,bj)*uf( i ,j) |
212 |
& +drF(k)*dxG(i,j+1,bi,bj)*_hFacS(i,j+1,k,bi,bj)*vf(i,j+1) |
213 |
& -drF(k)*dxG(i, j ,bi,bj)*_hFacS(i, j ,k,bi,bj)*vf(i, j ) |
214 |
& +( wVel(i,j, k ,bi,bj)*wFacKm*maskC(i,j,k-1,bi,bj) |
215 |
& -wVel(i,j,kp1,bi,bj)*wFacKp |
216 |
& )*_rA(i,j,bi,bj)/deltaTmom |
217 |
ENDDO |
218 |
ENDDO |
219 |
ENDDO |
220 |
|
221 |
#ifdef ALLOW_OBCS |
222 |
C- Note: solver matrix is trivial outside OB region (main diagonal only) |
223 |
C => no real need to reset RHS (=cg3d_b) & cg3d_x, except that: |
224 |
C a) normalisation is fct of Max(RHS), which can be large ouside OB region |
225 |
C (would be different if we were solving for increment of phi_nh |
226 |
C instead of directly for phi_nh). |
227 |
C => need to reset RHS to ensure that interior solution does not depend |
228 |
C on ouside OB region. |
229 |
C b) provide directly the trivial solution cg3d_x == 0 for outside OB region |
230 |
C (=> no residual => no effect on solver convergence and interior solution) |
231 |
IF (useOBCS) THEN |
232 |
DO k=1,Nr |
233 |
DO j=1,sNy |
234 |
DO i=1,sNx |
235 |
cg3d_b(i,j,k,bi,bj) = cg3d_b(i,j,k,bi,bj) |
236 |
& *maskInC(i,j,bi,bj) |
237 |
phi_nh(i,j,k,bi,bj) = phi_nh(i,j,k,bi,bj) |
238 |
& *maskInC(i,j,bi,bj) |
239 |
ENDDO |
240 |
ENDDO |
241 |
ENDDO |
242 |
ENDIF |
243 |
#endif /* ALLOW_OBCS */ |
244 |
|
245 |
C- end bi,bj loops |
246 |
ENDDO |
247 |
ENDDO |
248 |
|
249 |
c ENDIF |
250 |
#endif /* ALLOW_NONHYDROSTATIC */ |
251 |
|
252 |
RETURN |
253 |
END |