-
Notifications
You must be signed in to change notification settings - Fork 237
/
ini_pressure.F
205 lines (186 loc) · 6.26 KB
/
ini_pressure.F
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
#include "PACKAGES_CONFIG.h"
#include "CPP_OPTIONS.h"
CBOP
C !ROUTINE: INI_PRESSURE
C !INTERFACE:
SUBROUTINE INI_PRESSURE( myThid )
C !DESCRIPTION: \bv
C *==========================================================*
C | SUBROUTINE INI_PRESSURE
C | o initialise the pressure field consistently with
C | temperature and salinity
C | - needs to be called after ini_theta, ini_salt, and
C | ini_psurf
C | - does not include surface pressure loading, because
C | that is only available until after
C | CALL packages_init_variables
C *==========================================================*
C \ev
C !USES:
IMPLICIT NONE
C == Global variables ==
#include "SIZE.h"
#include "EEPARAMS.h"
#include "PARAMS.h"
#include "EOS.h"
#include "GRID.h"
#include "DYNVARS.h"
C !INPUT/OUTPUT PARAMETERS:
C myThid :: my Thread Id number
INTEGER myThid
C !LOCAL VARIABLES:
C dPhiHydX,Y :: Gradient (X & Y directions) of Hyd. Potential
C bi,bj :: tile indices
C i,j,k :: Loop counters
INTEGER bi, bj
INTEGER i, j, k
#ifndef ALLOW_AUTODIFF
INTEGER iMin, iMax, jMin, jMax, npiter
_RL PhiHydF (1-OLx:sNx+OLx,1-OLy:sNy+OLy)
_RL PhiHydC (1-OLx:sNx+OLx,1-OLy:sNy+OLy)
_RL dPhiHydX(1-OLx:sNx+OLx,1-OLy:sNy+OLy)
_RL dPhiHydY(1-OLx:sNx+OLx,1-OLy:sNy+OLy)
_RL oldPhi (1-OLx:sNx+OLx,1-OLy:sNy+OLy)
_RL count, rmspp, rmsppold
_RL sumTile, rmsTile
#endif
CHARACTER*(MAX_LEN_MBUF) msgBuf
CEOP
_BEGIN_MASTER( myThid )
WRITE(msgBuf,'(a)')
& 'Start initial hydrostatic pressure computation'
CALL PRINT_MESSAGE( msgBuf, standardMessageUnit,
& SQUEEZE_RIGHT, myThid )
_END_MASTER( myThid )
DO bj = myByLo(myThid), myByHi(myThid)
DO bi = myBxLo(myThid), myBxHi(myThid)
DO k = 1,Nr
DO j=1-OLy,sNy+OLy
DO i=1-OLx,sNx+OLx
totPhiHyd(i,j,k,bi,bj) = 0. _d 0
ENDDO
ENDDO
ENDDO
ENDDO
ENDDO
IF ( storePhiHyd4Phys ) THEN
#ifndef ALLOW_AUTODIFF
cph-- deal with this iterative loop for AD once it will
cph-- really be needed;
cph-- would need storing of totPhiHyd for each npiter
iMin = 1-OLx
iMax = sNx+OLx
jMin = 1-OLy
jMax = sNy+OLy
rmspp = 1. _d 0
rmsppold = 0. _d 0
npiter = 0
C iterate pressure p = integral of (g*rho(p)*dz)
DO npiter= 1, 15
IF ( rmspp.GT.zeroRL ) THEN
rmsppold = rmspp
rmspp = 0. _d 0
count = 0. _d 0
DO bj = myByLo(myThid), myByHi(myThid)
DO bi = myBxLo(myThid), myBxHi(myThid)
rmsTile = 0. _d 0
sumTile = 0. _d 0
DO j=1-OLy,sNy+OLy
DO i=1-OLx,sNx+OLx
phiHydF(i,j) = 0. _d 0
ENDDO
ENDDO
DO k = 1, Nr
C for each level save old pressure and compute new pressure
DO j=jMin,jMax
DO i=iMin,iMax
oldPhi(i,j) = totPhiHyd(i,j,k,bi,bj)
ENDDO
ENDDO
CALL CALC_PHI_HYD(
I bi, bj, iMin, iMax, jMin, jMax, k,
U phiHydF,
O phiHydC, dPhiHydX, dPhiHydY,
I startTime, -1, myThid )
C compute convergence criterion
DO j=1,sNy
DO i=1,sNx
rmsTile = rmsTile
& + (totPhiHyd(i,j,k,bi,bj)-oldPhi(i,j))**2
& * maskC(i,j,k,bi,bj)
sumTile = sumTile + maskC(i,j,k,bi,bj)
ENDDO
ENDDO
C -- end k loop
ENDDO
rmspp = rmspp + rmsTile
count = count + sumTile
ENDDO
ENDDO
Cml WRITE(msgBuf,'(I10.10)') npiter
Cml CALL WRITE_FLD_XYZ_RL( 'POLD.',msgBuf,pold,npiter,myThid)
Cml CALL WRITE_FLD_XYZ_RL( 'PINI.',msgBuf,pressure,npiter,myThid)
_GLOBAL_SUM_RL( rmspp, myThid )
_GLOBAL_SUM_RL( count, myThid )
IF ( count .EQ. 0. ) THEN
rmspp = 0. _d 0
ELSE
rmspp = SQRT(rmspp/count)
ENDIF
_BEGIN_MASTER( myThid )
WRITE(msgBuf,'(A,I4,A,1PE20.12)')
& 'Iteration', npiter, ', RMS-difference =', rmspp
CALL PRINT_MESSAGE( msgBuf, standardMessageUnit,
& SQUEEZE_RIGHT, myThid )
_END_MASTER( myThid )
ENDIF
C -- end npiter loop
ENDDO
C print some diagnostics
_BEGIN_MASTER( myThid )
IF ( rmspp .NE. 0. ) THEN
IF ( rmspp .EQ. rmsppold ) THEN
WRITE(msgBuf,'(A)')
& 'Initial hydrostatic pressure did not converge perfectly,'
CALL PRINT_MESSAGE( msgBuf, standardMessageUnit,
& SQUEEZE_RIGHT, myThid )
WRITE(msgBuf,'(A)')
& 'but the RMS-difference is constant, indicating that the'
CALL PRINT_MESSAGE( msgBuf, standardMessageUnit,
& SQUEEZE_RIGHT, myThid )
WRITE(msgBuf,'(A)')
& 'algorithm converged within machine precision.'
CALL PRINT_MESSAGE( msgBuf, standardMessageUnit,
& SQUEEZE_RIGHT, myThid )
ELSE
WRITE(msgBuf,'(A,I2,A)')
& 'Initial hydrostatic pressure did not converge after ',
& npiter-1, ' steps'
CALL PRINT_ERROR( msgBuf, myThid )
STOP 'ABNORMAL END: S/R INI_PRESSURE'
ENDIF
ENDIF
WRITE(msgBuf,'(A)')
& 'Initial hydrostatic pressure converged.'
CALL PRINT_MESSAGE( msgBuf, standardMessageUnit,
& SQUEEZE_RIGHT, myThid )
_END_MASTER( myThid )
#endif /* ALLOW_AUTODIFF */
c-- else of if storePhiHyd4Phys
ELSE
C print a message and DO nothing
_BEGIN_MASTER( myThid )
WRITE(msgBuf,'(A,A)')
& 'Pressure is predetermined for buoyancyRelation ',
& buoyancyRelation(1:11)
CALL PRINT_MESSAGE( msgBuf, standardMessageUnit,
& SQUEEZE_RIGHT, myThid )
_END_MASTER( myThid )
ENDIF
_BEGIN_MASTER( myThid )
WRITE(msgBuf,'(A)') ' '
CALL PRINT_MESSAGE( msgBuf, standardMessageUnit,
& SQUEEZE_RIGHT, myThid )
_END_MASTER( myThid )
RETURN
END