Newer
Older
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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
MODULE bdydyn2d
!!======================================================================
!! *** MODULE bdydyn ***
!! Unstructured Open Boundary Cond. : Apply boundary conditions to barotropic solution
!!======================================================================
!! History : 3.4 ! 2011 (D. Storkey) new module as part of BDY rewrite
!! 3.5 ! 2012 (S. Mocavero, I. Epicoco) Optimization of BDY communications
!! 3.5 ! 2013-07 (J. Chanut) Compliant with time splitting changes
!!----------------------------------------------------------------------
!! bdy_dyn2d : Apply open boundary conditions to barotropic variables.
!! bdy_dyn2d_frs : Apply Flow Relaxation Scheme
!! bdy_dyn2d_fla : Apply Flather condition
!! bdy_dyn2d_orlanski : Orlanski Radiation
!! bdy_ssh : Duplicate sea level across open boundaries
!!----------------------------------------------------------------------
USE dom_oce ! ocean space and time domain
USE bdy_oce ! ocean open boundary conditions
USE bdylib ! BDY library routines
USE phycst ! physical constants
USE lib_mpp
USE lbclnk ! ocean lateral boundary conditions (or mpp link)
USE wet_dry ! Use wet dry to get reference ssh level
USE in_out_manager !
IMPLICIT NONE
PRIVATE
PUBLIC bdy_dyn2d ! routine called in dynspg_ts and bdy_dyn
PUBLIC bdy_ssh ! routine called in dynspg_ts or sshwzv
!!----------------------------------------------------------------------
!! NEMO/OCE 4.0 , NEMO Consortium (2018)
!! $Id: bdydyn2d.F90 15368 2021-10-14 08:25:34Z smasson $
!! Software governed by the CeCILL license (see ./LICENSE)
!!----------------------------------------------------------------------
CONTAINS
SUBROUTINE bdy_dyn2d( kt, pua2d, pva2d, pub2d, pvb2d, phur, phvr, pssh )
!!----------------------------------------------------------------------
!! *** SUBROUTINE bdy_dyn2d ***
!!
!! ** Purpose : - Apply open boundary conditions for barotropic variables
!!
!!----------------------------------------------------------------------
INTEGER, INTENT(in) :: kt ! Main time step counter
REAL(wp), DIMENSION(jpi,jpj), INTENT(inout) :: pua2d, pva2d
REAL(wp), DIMENSION(jpi,jpj), INTENT(in ) :: pub2d, pvb2d
REAL(wp), DIMENSION(jpi,jpj), INTENT(in ) :: phur, phvr
REAL(wp), DIMENSION(jpi,jpj), INTENT(in ) :: pssh
!!
INTEGER :: ib_bdy, ir ! BDY set index, rim index
INTEGER, DIMENSION(3) :: idir3
INTEGER, DIMENSION(6) :: idir6
LOGICAL :: llrim0 ! indicate if rim 0 is treated
LOGICAL, DIMENSION(8) :: llsend2, llrecv2, llsend3, llrecv3 ! indicate how communications are to be carried out
!!----------------------------------------------------------------------
llsend2(:) = .false. ; llrecv2(:) = .false.
llsend3(:) = .false. ; llrecv3(:) = .false.
DO ir = 1, 0, -1 ! treat rim 1 before rim 0
IF( ir == 0 ) THEN ; llrim0 = .TRUE.
ELSE ; llrim0 = .FALSE.
END IF
DO ib_bdy=1, nb_bdy
SELECT CASE( cn_dyn2d(ib_bdy) )
CASE('none')
CYCLE
CASE('frs') ! treat the whole boundary at once
IF( llrim0 ) CALL bdy_dyn2d_frs( idx_bdy(ib_bdy), dta_bdy(ib_bdy), ib_bdy, pua2d, pva2d )
CASE('flather')
CALL bdy_dyn2d_fla( idx_bdy(ib_bdy), dta_bdy(ib_bdy), ib_bdy, pua2d, pva2d, pssh, phur, phvr, llrim0 )
CASE('orlanski')
CALL bdy_dyn2d_orlanski( idx_bdy(ib_bdy), dta_bdy(ib_bdy), ib_bdy, &
& pua2d, pva2d, pub2d, pvb2d, llrim0, ll_npo=.false. )
CASE('orlanski_npo')
CALL bdy_dyn2d_orlanski( idx_bdy(ib_bdy), dta_bdy(ib_bdy), ib_bdy, &
& pua2d, pva2d, pub2d, pvb2d, llrim0, ll_npo=.true. )
CASE DEFAULT
CALL ctl_stop( 'bdy_dyn2d : unrecognised option for open boundaries for barotropic variables' )
END SELECT
ENDDO
!
IF( nn_hls > 1 .AND. ir == 1 ) CYCLE ! at least 2 halos will be corrected -> no need to correct rim 1 before rim 0
IF( nn_hls == 1 ) THEN
llsend2(:) = .false. ; llrecv2(:) = .false.
llsend3(:) = .false. ; llrecv3(:) = .false.
END IF
DO ib_bdy=1, nb_bdy
SELECT CASE( cn_dyn2d(ib_bdy) )
CASE('flather')
idir6 = (/ jpwe, jpea, jpsw, jpse, jpnw, jpne /)
llsend2(idir6) = llsend2(idir6) .OR. lsend_bdyint(ib_bdy,2,idir6,ir) ! west/east, U points
idir3 = (/ jpwe, jpsw, jpnw /)
llsend2(idir3) = llsend2(idir3) .OR. lsend_bdyext(ib_bdy,2,idir3,ir) ! nei might search point towards its east bdy
llrecv2(idir6) = llrecv2(idir6) .OR. lrecv_bdyint(ib_bdy,2,idir6,ir) ! west/east, U points
idir3 = (/ jpea, jpse, jpne /)
llrecv2(idir3) = llrecv2(idir3) .OR. lrecv_bdyext(ib_bdy,2,idir3,ir) ! might search point towards bdy on the east
idir6 = (/ jpso, jpno, jpsw, jpse, jpnw, jpne /)
llsend3(idir6) = llsend3(idir6) .OR. lsend_bdyint(ib_bdy,3,idir6,ir) ! north/south, V points
idir3 = (/ jpso, jpsw, jpse /)
llsend3(idir3) = llsend3(idir3) .OR. lsend_bdyext(ib_bdy,3,idir3,ir) ! nei might search point towards its north bdy
llrecv3(idir6) = llrecv3(idir6) .OR. lrecv_bdyint(ib_bdy,3,idir6,ir) ! north/south, V points
idir3 = (/ jpno, jpnw, jpne /)
llrecv3(idir3) = llrecv3(idir3) .OR. lrecv_bdyext(ib_bdy,3,idir3,ir) ! might search point towards bdy on the north
CASE('orlanski', 'orlanski_npo')
llsend2(:) = llsend2(:) .OR. lsend_bdyolr(ib_bdy,2,:,ir) ! possibly every direction, U points
llrecv2(:) = llrecv2(:) .OR. lrecv_bdyolr(ib_bdy,2,:,ir) ! possibly every direction, U points
llsend3(:) = llsend3(:) .OR. lsend_bdyolr(ib_bdy,3,:,ir) ! possibly every direction, V points
llrecv3(:) = llrecv3(:) .OR. lrecv_bdyolr(ib_bdy,3,:,ir) ! possibly every direction, V points
END SELECT
END DO
IF( ANY(llsend2) .OR. ANY(llrecv2) ) THEN ! if need to send/recv in at least one direction
CALL lbc_lnk( 'bdydyn2d', pua2d, 'U', -1.0_wp, kfillmode=jpfillnothing ,lsend=llsend2, lrecv=llrecv2 )
END IF
IF( ANY(llsend3) .OR. ANY(llrecv3) ) THEN ! if need to send/recv in at least one direction
CALL lbc_lnk( 'bdydyn2d', pva2d, 'V', -1.0_wp, kfillmode=jpfillnothing ,lsend=llsend3, lrecv=llrecv3 )
END IF
!
END DO ! ir
!
END SUBROUTINE bdy_dyn2d
SUBROUTINE bdy_dyn2d_frs( idx, dta, ib_bdy, pua2d, pva2d )
!!----------------------------------------------------------------------
!! *** SUBROUTINE bdy_dyn2d_frs ***
!!
!! ** Purpose : - Apply the Flow Relaxation Scheme for barotropic velocities
!! at open boundaries.
!!
!! References :- Engedahl H., 1995: Use of the flow relaxation scheme in
!! a three-dimensional baroclinic ocean model with realistic
!! topography. Tellus, 365-382.
!!----------------------------------------------------------------------
TYPE(OBC_INDEX), INTENT(in) :: idx ! OBC indices
TYPE(OBC_DATA), INTENT(in) :: dta ! OBC external data
INTEGER, INTENT(in) :: ib_bdy ! BDY set index
REAL(wp), DIMENSION(jpi,jpj), INTENT(inout) :: pua2d, pva2d
!!
INTEGER :: jb ! dummy loop indices
INTEGER :: ii, ij, igrd ! local integers
REAL(wp) :: zwgt ! boundary weight
!!----------------------------------------------------------------------
!
igrd = 2 ! Relaxation of zonal velocity
DO jb = 1, idx%nblen(igrd)
ii = idx%nbi(jb,igrd)
ij = idx%nbj(jb,igrd)
zwgt = idx%nbw(jb,igrd)
pua2d(ii,ij) = ( pua2d(ii,ij) + zwgt * ( dta%u2d(jb) - pua2d(ii,ij) ) ) * umask(ii,ij,1)
END DO
!
igrd = 3 ! Relaxation of meridional velocity
DO jb = 1, idx%nblen(igrd)
ii = idx%nbi(jb,igrd)
ij = idx%nbj(jb,igrd)
zwgt = idx%nbw(jb,igrd)
pva2d(ii,ij) = ( pva2d(ii,ij) + zwgt * ( dta%v2d(jb) - pva2d(ii,ij) ) ) * vmask(ii,ij,1)
END DO
!
END SUBROUTINE bdy_dyn2d_frs
SUBROUTINE bdy_dyn2d_fla( idx, dta, ib_bdy, pua2d, pva2d, pssh, phur, phvr, llrim0 )
!!----------------------------------------------------------------------
!! *** SUBROUTINE bdy_dyn2d_fla ***
!!
!! - Apply Flather boundary conditions on normal barotropic velocities
!!
!! ** WARNINGS about FLATHER implementation:
!!1. According to Palma and Matano, 1998 "after ssh" is used.
!! In ROMS and POM implementations, it is "now ssh". In the current
!! implementation (tested only in the EEL-R5 conf.), both cases were unstable.
!! So I use "before ssh" in the following.
!!
!!2. We assume that the normal ssh gradient at the bdy is zero. As a matter of
!! fact, the model ssh just inside the dynamical boundary is used (the outside
!! ssh in the code is not updated).
!!
!! References: Flather, R. A., 1976: A tidal model of the northwest European
!! continental shelf. Mem. Soc. R. Sci. Liege, Ser. 6,10, 141-164.
!!----------------------------------------------------------------------
TYPE(OBC_INDEX), INTENT(in) :: idx ! OBC indices
TYPE(OBC_DATA), INTENT(in) :: dta ! OBC external data
INTEGER, INTENT(in) :: ib_bdy ! BDY set index
REAL(wp), DIMENSION(jpi,jpj), INTENT(inout) :: pua2d, pva2d
REAL(wp), DIMENSION(jpi,jpj), INTENT(in) :: pssh, phur, phvr
LOGICAL , INTENT(in) :: llrim0 ! indicate if rim 0 is treated
INTEGER :: ibeg, iend ! length of rim to be treated (rim 0 or rim 1)
INTEGER :: jb, igrd ! dummy loop indices
INTEGER :: ii, ij ! 2D addresses
INTEGER :: iiTrim, ijTrim ! T pts i/j-indice on the rim
INTEGER :: iiToce, ijToce, iiUoce, ijVoce ! T, U and V pts i/j-indice of the ocean next to the rim
REAL(wp) :: flagu, flagv ! short cuts
REAL(wp) :: zfla ! Flather correction
REAL(wp) :: z1_2 !
REAL(wp), DIMENSION(jpi,jpj) :: sshdta ! 2D version of dta%ssh
!!----------------------------------------------------------------------
z1_2 = 0.5_wp
! ---------------------------------!
! Flather boundary conditions :!
! ---------------------------------!
! Fill temporary array with ssh data (here we use spgu with the alias sshdta):
igrd = 1
IF( llrim0 ) THEN ; ibeg = 1 ; iend = idx%nblenrim0(igrd)
ELSE ; ibeg = idx%nblenrim0(igrd)+1 ; iend = idx%nblenrim(igrd)
END IF
!
DO jb = ibeg, iend
ii = idx%nbi(jb,igrd)
ij = idx%nbj(jb,igrd)
IF( ll_wd ) THEN ; sshdta(ii, ij) = dta%ssh(jb) - ssh_ref
ELSE ; sshdta(ii, ij) = dta%ssh(jb)
ENDIF
END DO
!
igrd = 2 ! Flather bc on u-velocity
! ! remember that flagu=-1 if normal velocity direction is outward
! ! I think we should rather use after ssh ?
IF( llrim0 ) THEN ; ibeg = 1 ; iend = idx%nblenrim0(igrd)
ELSE ; ibeg = idx%nblenrim0(igrd)+1 ; iend = idx%nblenrim(igrd)
END IF
DO jb = ibeg, iend
ii = idx%nbi(jb,igrd)
ij = idx%nbj(jb,igrd)
flagu = idx%flagu(jb,igrd)
IF( flagu == 0. ) THEN
pua2d(ii,ij) = dta%u2d(jb)
ELSE ! T pts j-indice on the rim on the ocean next to the rim on T and U points
IF( flagu == 1. ) THEN ; iiTrim = ii ; iiToce = ii+1 ; iiUoce = ii+1 ; ENDIF
IF( flagu == -1. ) THEN ; iiTrim = ii+1 ; iiToce = ii ; iiUoce = ii-1 ; ENDIF
!
! Rare case : rim is parallel to the mpi subdomain border and on the halo : point will be received
IF( iiTrim > jpi .OR. iiToce > jpi .OR. iiUoce > jpi .OR. iiUoce < 1 ) CYCLE
!
zfla = dta%u2d(jb) - flagu * SQRT( grav * phur(ii, ij) ) * ( pssh(iiToce,ij) - sshdta(iiTrim,ij) )
!
! jchanut tschanges, use characteristics method (Blayo et Debreu, 2005) :
! mix Flather scheme with velocity of the ocean next to the rim
pua2d(ii,ij) = z1_2 * ( pua2d(iiUoce,ij) + zfla )
END IF
END DO
!
igrd = 3 ! Flather bc on v-velocity
! ! remember that flagv=-1 if normal velocity direction is outward
IF( llrim0 ) THEN ; ibeg = 1 ; iend = idx%nblenrim0(igrd)
ELSE ; ibeg = idx%nblenrim0(igrd)+1 ; iend = idx%nblenrim(igrd)
END IF
DO jb = ibeg, iend
ii = idx%nbi(jb,igrd)
ij = idx%nbj(jb,igrd)
flagv = idx%flagv(jb,igrd)
IF( flagv == 0. ) THEN
pva2d(ii,ij) = dta%v2d(jb)
ELSE ! T pts j-indice on the rim on the ocean next to the rim on T and V points
IF( flagv == 1. ) THEN ; ijTrim = ij ; ijToce = ij+1 ; ijVoce = ij+1 ; ENDIF
IF( flagv == -1. ) THEN ; ijTrim = ij+1 ; ijToce = ij ; ijVoce = ij-1 ; ENDIF
!
! Rare case : rim is parallel to the mpi subdomain border and on the halo : point will be received
IF( ijTrim > jpj .OR. ijToce > jpj .OR. ijVoce > jpj .OR. ijVoce < 1 ) CYCLE
!
zfla = dta%v2d(jb) - flagv * SQRT( grav * phvr(ii, ij) ) * ( pssh(ii,ijToce) - sshdta(ii,ijTrim) )
!
! jchanut tschanges, use characteristics method (Blayo et Debreu, 2005) :
! mix Flather scheme with velocity of the ocean next to the rim
pva2d(ii,ij) = z1_2 * ( pva2d(ii,ijVoce) + zfla )
END IF
END DO
!
END SUBROUTINE bdy_dyn2d_fla
SUBROUTINE bdy_dyn2d_orlanski( idx, dta, ib_bdy, pua2d, pva2d, pub2d, pvb2d, llrim0, ll_npo )
!!----------------------------------------------------------------------
!! *** SUBROUTINE bdy_dyn2d_orlanski ***
!!
!! - Apply Orlanski radiation condition adaptively:
!! - radiation plus weak nudging at outflow points
!! - no radiation and strong nudging at inflow points
!!
!!
!! References: Marchesiello, McWilliams and Shchepetkin, Ocean Modelling vol. 3 (2001)
!!----------------------------------------------------------------------
TYPE(OBC_INDEX), INTENT(in) :: idx ! OBC indices
TYPE(OBC_DATA), INTENT(in) :: dta ! OBC external data
INTEGER, INTENT(in) :: ib_bdy ! number of current open boundary set
REAL(wp), DIMENSION(jpi,jpj), INTENT(inout) :: pua2d, pva2d
REAL(wp), DIMENSION(jpi,jpj), INTENT(in) :: pub2d, pvb2d
LOGICAL, INTENT(in) :: ll_npo ! flag for NPO version
LOGICAL, INTENT(in) :: llrim0 ! indicate if rim 0 is treated
INTEGER :: ib, igrd ! dummy loop indices
INTEGER :: ii, ij, iibm1, ijbm1 ! indices
!!----------------------------------------------------------------------
!
igrd = 2 ! Orlanski bc on u-velocity;
!
CALL bdy_orlanski_2d( idx, igrd, pub2d, pua2d, dta%u2d, llrim0, ll_npo )
igrd = 3 ! Orlanski bc on v-velocity
!
CALL bdy_orlanski_2d( idx, igrd, pvb2d, pva2d, dta%v2d, llrim0, ll_npo )
!
END SUBROUTINE bdy_dyn2d_orlanski
SUBROUTINE bdy_ssh( zssh )
!!----------------------------------------------------------------------
!! *** SUBROUTINE bdy_ssh ***
!!
!! ** Purpose : Duplicate sea level across open boundaries
!!
!!----------------------------------------------------------------------
REAL(wp), DIMENSION(jpi,jpj,1), INTENT(inout) :: zssh ! Sea level, need 3 dimensions to be used by bdy_nmn
!!
INTEGER :: ib_bdy, ir ! bdy index, rim index
INTEGER :: ibeg, iend ! length of rim to be treated (rim 0 or rim 1)
LOGICAL :: llrim0 ! indicate if rim 0 is treated
LOGICAL, DIMENSION(8) :: llsend1, llrecv1 ! indicate how communications are to be carried out
!!----------------------------------------------------------------------
llsend1(:) = .false. ; llrecv1(:) = .false.
DO ir = 1, 0, -1 ! treat rim 1 before rim 0
IF( nn_hls == 1 ) THEN ; llsend1(:) = .false. ; llrecv1(:) = .false. ; END IF
IF( ir == 0 ) THEN ; llrim0 = .TRUE.
ELSE ; llrim0 = .FALSE.
END IF
DO ib_bdy = 1, nb_bdy
CALL bdy_nmn( idx_bdy(ib_bdy), 1, zssh, llrim0 ) ! zssh is masked
llsend1(:) = llsend1(:) .OR. lsend_bdyint(ib_bdy,1,:,ir) ! possibly every direction, T points
llrecv1(:) = llrecv1(:) .OR. lrecv_bdyint(ib_bdy,1,:,ir) ! possibly every direction, T points
END DO
IF( nn_hls > 1 .AND. ir == 1 ) CYCLE ! at least 2 halos will be corrected -> no need to correct rim 1 before rim 0
IF( ANY(llsend1) .OR. ANY(llrecv1) ) THEN ! if need to send/recv in at least one direction
CALL lbc_lnk( 'bdydyn2d', zssh(:,:,1), 'T', 1.0_wp, kfillmode=jpfillnothing ,lsend=llsend1, lrecv=llrecv1 )
END IF
END DO
!
END SUBROUTINE bdy_ssh
!!======================================================================
END MODULE bdydyn2d