1 | MODULE agrif_connect |
---|
2 | |
---|
3 | USE dom_oce |
---|
4 | USE domzgr |
---|
5 | USE agrif_parameters |
---|
6 | USE agrif_profiles |
---|
7 | |
---|
8 | IMPLICIT NONE |
---|
9 | PRIVATE |
---|
10 | |
---|
11 | PUBLIC agrif_boundary_connections |
---|
12 | |
---|
13 | CONTAINS |
---|
14 | |
---|
15 | #if defined key_agrif |
---|
16 | |
---|
17 | SUBROUTINE agrif_boundary_connections |
---|
18 | !!---------------------------------------------------------------------- |
---|
19 | !! *** ROUTINE agrif_boundary_connections *** |
---|
20 | !!---------------------------------------------------------------------- |
---|
21 | IF( Agrif_Root() ) return |
---|
22 | |
---|
23 | CALL agrif_connection() |
---|
24 | ! |
---|
25 | CALL Agrif_Bc_variable(bottom_level_id, procname = connect_bottom_level) |
---|
26 | ! |
---|
27 | CALL Agrif_Bc_variable(e3t_copy_id, procname = connect_e3t_copy) |
---|
28 | |
---|
29 | ALLOCATE(e3t_interp(jpi,jpj,jpk)) |
---|
30 | e3t_interp = -10. |
---|
31 | Agrif_UseSpecialValue = .FALSE. |
---|
32 | Agrif_SpecialValue = 0. |
---|
33 | CALL Agrif_Bc_variable(e3t_connect_id, procname = connect_e3t_connect) |
---|
34 | Agrif_UseSpecialValue = .FALSE. |
---|
35 | ! |
---|
36 | END SUBROUTINE agrif_boundary_connections |
---|
37 | |
---|
38 | SUBROUTINE connect_e3t_copy( ptab, i1, i2, j1, j2, k1, k2, before, nb,ndir) |
---|
39 | !!---------------------------------------------------------------------- |
---|
40 | !! *** ROUTINE connect_e3t_copy *** |
---|
41 | !!---------------------------------------------------------------------- |
---|
42 | INTEGER , INTENT(in ) :: i1, i2, j1, j2, k1, k2 |
---|
43 | REAL(wp), DIMENSION(i1:i2,j1:j2,k1:k2), INTENT(inout) :: ptab |
---|
44 | LOGICAL , INTENT(in ) :: before |
---|
45 | INTEGER , INTENT(in ) :: nb , ndir |
---|
46 | ! |
---|
47 | !!---------------------------------------------------------------------- |
---|
48 | ! |
---|
49 | IF( before) THEN |
---|
50 | ptab(i1:i2,j1:j2,k1:k2) = e3t_0(i1:i2,j1:j2,k1:k2) |
---|
51 | ELSE |
---|
52 | e3t_0(i1:i2,j1:j2,k1:k2) = ptab(i1:i2,j1:j2,k1:k2) |
---|
53 | ENDIF |
---|
54 | ! |
---|
55 | END SUBROUTINE connect_e3t_copy |
---|
56 | |
---|
57 | SUBROUTINE connect_bottom_level( ptab, i1, i2, j1, j2, before, nb,ndir) |
---|
58 | !!---------------------------------------------------------------------- |
---|
59 | !! *** ROUTINE connect_bottom_level *** |
---|
60 | !!---------------------------------------------------------------------- |
---|
61 | INTEGER , INTENT(in ) :: i1, i2, j1, j2 |
---|
62 | REAL(wp), DIMENSION(i1:i2,j1:j2), INTENT(inout) :: ptab |
---|
63 | LOGICAL , INTENT(in ) :: before |
---|
64 | INTEGER , INTENT(in ) :: nb , ndir |
---|
65 | ! |
---|
66 | !!---------------------------------------------------------------------- |
---|
67 | ! |
---|
68 | IF( before) THEN |
---|
69 | ptab(i1:i2,j1:j2) = mbkt(i1:i2,j1:j2)*ssmask(i1:i2,j1:j2) |
---|
70 | ELSE |
---|
71 | mbkt(i1:i2,j1:j2) = nint(ptab(i1:i2,j1:j2)) |
---|
72 | WHERE (mbkt(i1:i2,j1:j2)==0) |
---|
73 | ssmask(i1:i2,j1:j2) = 0. |
---|
74 | ELSEWHERE |
---|
75 | ssmask(i1:i2,j1:j2) = 1. |
---|
76 | END WHERE |
---|
77 | ENDIF |
---|
78 | ! |
---|
79 | END SUBROUTINE connect_bottom_level |
---|
80 | |
---|
81 | SUBROUTINE connect_e3t_connect( ptab, i1, i2, j1, j2, k1, k2, before, nb,ndir) |
---|
82 | !!---------------------------------------------------------------------- |
---|
83 | !! *** ROUTINE connect_e3t_connect *** |
---|
84 | !!---------------------------------------------------------------------- |
---|
85 | INTEGER , INTENT(in ) :: i1, i2, j1, j2, k1, k2 |
---|
86 | REAL(wp), DIMENSION(i1:i2,j1:j2,k1:k2), INTENT(inout) :: ptab |
---|
87 | LOGICAL , INTENT(in ) :: before |
---|
88 | INTEGER , INTENT(in ) :: nb , ndir |
---|
89 | ! |
---|
90 | !!---------------------------------------------------------------------- |
---|
91 | INTEGER :: ji, jj, jk |
---|
92 | REAL(wp), DIMENSION(i1:i2,j1:j2) :: bathy_local, bathy_interp |
---|
93 | REAL(wp) :: zdepth, zmax |
---|
94 | ! |
---|
95 | IF( before) THEN |
---|
96 | DO jk=1,jpk |
---|
97 | DO jj=j1,j2 |
---|
98 | DO ji=i1,i2 |
---|
99 | IF( mbkt(ji,jj) .GE. jk ) THEN |
---|
100 | ptab(ji,jj,jk) = e3t_0(ji,jj,jk) |
---|
101 | ELSE |
---|
102 | ptab(ji,jj,jk) = 0. |
---|
103 | ENDIF |
---|
104 | END DO |
---|
105 | END DO |
---|
106 | END DO |
---|
107 | ! |
---|
108 | DO jj=j1,j2 |
---|
109 | DO ji=i1,i2 |
---|
110 | ptab(ji,jj,jpk+1) = SUM ( e3t_0(ji,jj, 1:mbkt(ji,jj) ) ) * ssmask(ji,jj) |
---|
111 | END DO |
---|
112 | END DO |
---|
113 | ELSE |
---|
114 | DO jj=j1,j2 |
---|
115 | DO ji=i1,i2 |
---|
116 | bathy_local (ji,jj) = SUM ( e3t_0(ji,jj, 1:mbkt(ji,jj) ) ) * ssmask(ji,jj) |
---|
117 | bathy_interp (ji,jj) = ptab(ji,jj,jpk+1) |
---|
118 | |
---|
119 | ! Connected bathymetry |
---|
120 | bathy_local(ji,jj)=(1.-ztabramp(ji,jj))*bathy_local(ji,jj)+ztabramp(ji,jj)*bathy_interp(ji,jj) |
---|
121 | END DO |
---|
122 | END DO |
---|
123 | |
---|
124 | ! Update mbkt and ssmask |
---|
125 | zmax = gdepw_1d(jpk) + e3t_1d(jpk) |
---|
126 | bathy_local(:,:) = MAX(MIN(zmax,bathy_local(:,:)),0._wp) |
---|
127 | WHERE( bathy_local(i1:i2,j1:j2) == 0._wp); mbathy(i1:i2,j1:j2) = 0 |
---|
128 | ELSE WHERE ; mbathy(i1:i2,j1:j2) = jpkm1 |
---|
129 | END WHERE |
---|
130 | |
---|
131 | DO jk=jpkm1,1,-1 |
---|
132 | zdepth = gdepw_1d(jk)+MIN(e3zps_min,e3t_1d(jk)*e3zps_rat) |
---|
133 | WHERE( 0._wp < bathy_local(:,:) .AND. bathy_local(:,:) <= zdepth ) mbathy(i1:i2,j1:j2) = jk-1 |
---|
134 | ENDDO |
---|
135 | |
---|
136 | WHERE (mbathy(i1:i2,j1:j2) == 0); ssmask(i1:i2,j1:j2) = 0 |
---|
137 | ELSE WHERE ; ssmask(i1:i2,j1:j2) = 1. |
---|
138 | END WHERE |
---|
139 | |
---|
140 | mbkt(i1:i2,j1:j2) = MAX( mbathy(i1:i2,j1:j2), 1 ) |
---|
141 | |
---|
142 | ! |
---|
143 | DO jk=1,jpk |
---|
144 | DO jj=j1,j2 |
---|
145 | DO ji=i1,i2 |
---|
146 | IF( e3t_interp(ji,jj,jk) == -10 ) THEN ! the connection has not yet been done |
---|
147 | e3t_interp(ji,jj,jk) = MAX( ptab(ji,jj,jk),MIN(e3zps_min, e3t_1d(jk)*e3zps_rat) ) |
---|
148 | ! e3t_interp(ji,jj,jk) = MIN( e3t_interp(ji,jj,jk),e3t_1d(jk) ) |
---|
149 | e3t_0(ji,jj,jk) = ( 1. - ztabramp(ji,jj) )*e3t_0(ji,jj,jk) + ztabramp(ji,jj)*e3t_interp(ji,jj,jk) |
---|
150 | ENDIF |
---|
151 | IF( jk > mbkt(ji,jj)) THEN |
---|
152 | e3t_0(ji,jj,jk) = e3t_1d(jk) |
---|
153 | ENDIF |
---|
154 | END DO |
---|
155 | END DO |
---|
156 | END DO |
---|
157 | ENDIF |
---|
158 | ! |
---|
159 | END SUBROUTINE connect_e3t_connect |
---|
160 | |
---|
161 | SUBROUTINE agrif_connection |
---|
162 | !!---------------------------------------------------------------------- |
---|
163 | !! *** ROUTINE Agrif_connection *** |
---|
164 | !!---------------------------------------------------------------------- |
---|
165 | INTEGER :: ji, jj, ind1, ind2 |
---|
166 | INTEGER :: ispongearea, istart |
---|
167 | REAL(wp) :: z1_spongearea |
---|
168 | !!---------------------------------------------------------------------- |
---|
169 | ! |
---|
170 | ! Define ramp from boundaries towards domain interior at T-points |
---|
171 | ! Store it in ztabramp |
---|
172 | |
---|
173 | ALLOCATE(ztabramp(jpi,jpj)) |
---|
174 | ispongearea = 1 + npt_connect * Agrif_irhox() |
---|
175 | istart = npt_copy * Agrif_irhox() |
---|
176 | z1_spongearea = 1._wp / REAL( ispongearea, wp ) |
---|
177 | |
---|
178 | ztabramp(:,:) = 0._wp |
---|
179 | |
---|
180 | ! --- West --- ! |
---|
181 | IF( ((nbondi == -1) .OR. (nbondi == 2) ).AND. .NOT. (jperio == 1 .OR. jperio == 4 .OR. jperio == 6)) THEN |
---|
182 | ind1 = nn_hls + nbghostcells + istart |
---|
183 | ind2 = ind1 + ispongearea |
---|
184 | DO ji = mi0(ind1), mi1(ind2) |
---|
185 | DO jj = 1, jpj |
---|
186 | ztabramp(ji,jj) = REAL(ind2 - mig(ji), wp) * z1_spongearea |
---|
187 | END DO |
---|
188 | ENDDO |
---|
189 | ! ghost cells: |
---|
190 | ind1 = 1 |
---|
191 | ind2 = nn_hls + nbghostcells + istart ! halo + land + nbghostcells |
---|
192 | DO ji = mi0(ind1), mi1(ind2) |
---|
193 | DO jj = 1, jpj |
---|
194 | ztabramp(ji,jj) = 1._wp |
---|
195 | END DO |
---|
196 | END DO |
---|
197 | ENDIF |
---|
198 | |
---|
199 | ! --- East --- ! |
---|
200 | IF( ((nbondi == 1) .OR. (nbondi == 2) ).AND. .NOT. (jperio == 1 .OR. jperio == 4 .OR. jperio == 6)) THEN |
---|
201 | ind2 = jpiglo - (nn_hls + nbghostcells -1 ) - istart |
---|
202 | ind1 = ind2 -ispongearea |
---|
203 | DO ji = mi0(ind1), mi1(ind2) |
---|
204 | DO jj = 1, jpj |
---|
205 | ztabramp(ji,jj) = MAX( ztabramp(ji,jj), REAL( mig(ji) - ind1 ) * z1_spongearea ) |
---|
206 | ENDDO |
---|
207 | ENDDO |
---|
208 | ! ghost cells: |
---|
209 | ind1 = jpiglo - (nn_hls + nbghostcells - 1 ) - istart ! halo + land + nbghostcells - 1 |
---|
210 | ind2 = jpiglo - 1 |
---|
211 | DO ji = mi0(ind1), mi1(ind2) |
---|
212 | DO jj = 1, jpj |
---|
213 | ztabramp(ji,jj) = 1._wp |
---|
214 | END DO |
---|
215 | END DO |
---|
216 | ENDIF |
---|
217 | |
---|
218 | ! --- South --- ! |
---|
219 | IF(( (nbondj == -1) .OR. (nbondj == 2) ).AND.(lk_south)) THEN |
---|
220 | ind1 = nn_hls + nbghostcells + istart |
---|
221 | ind2 = ind1 + ispongearea |
---|
222 | DO jj = mj0(ind1), mj1(ind2) |
---|
223 | DO ji = 1, jpi |
---|
224 | ztabramp(ji,jj) = MAX( ztabramp(ji,jj), REAL( ind2 - mjg(jj) ) * z1_spongearea ) |
---|
225 | END DO |
---|
226 | ENDDO |
---|
227 | ! ghost cells: |
---|
228 | ind1 = 1 |
---|
229 | ind2 = nn_hls + nbghostcells + istart ! halo + land + nbghostcells |
---|
230 | DO jj = mj0(ind1), mj1(ind2) |
---|
231 | DO ji = 1, jpi |
---|
232 | ztabramp(ji,jj) = 1._wp |
---|
233 | END DO |
---|
234 | END DO |
---|
235 | ENDIF |
---|
236 | |
---|
237 | ! --- North --- ! |
---|
238 | IF( (nbondj == 1) .OR. (nbondj == 2) ) THEN |
---|
239 | ind2 = jpjglo - (nn_hls + nbghostcells - 1) - istart |
---|
240 | ind1 = ind2 -ispongearea |
---|
241 | DO jj = mj0(ind1), mj1(ind2) |
---|
242 | DO ji = 1, jpi |
---|
243 | ztabramp(ji,jj) = MAX( ztabramp(ji,jj), REAL( mjg(jj) - ind1 ) * z1_spongearea ) |
---|
244 | END DO |
---|
245 | ENDDO |
---|
246 | ! ghost cells: |
---|
247 | ind1 = jpjglo - (nn_hls + nbghostcells - 1) - istart ! halo + land + nbghostcells - 1 |
---|
248 | ind2 = jpjglo |
---|
249 | DO jj = mj0(ind1), mj1(ind2) |
---|
250 | DO ji = 1, jpi |
---|
251 | ztabramp(ji,jj) = 1._wp |
---|
252 | END DO |
---|
253 | END DO |
---|
254 | ENDIF |
---|
255 | ! |
---|
256 | END SUBROUTINE agrif_connection |
---|
257 | |
---|
258 | #else |
---|
259 | SUBROUTINE agrif_boundary_connections |
---|
260 | END SUBROUTINE agrif_boundary_connections |
---|
261 | #endif |
---|
262 | |
---|
263 | END MODULE agrif_connect |
---|