New URL for NEMO forge!   http://forge.nemo-ocean.eu

Since March 2022 along with NEMO 4.2 release, the code development moved to a self-hosted GitLab.
This present forge is now archived and remained online for history.
isfcpl.F90 in NEMO/trunk/src/OCE/ISF – NEMO

source: NEMO/trunk/src/OCE/ISF/isfcpl.F90 @ 14072

Last change on this file since 14072 was 14072, checked in by laurent, 3 years ago

Merging branch "2020/dev_r13648_ASINTER-04_laurent_bulk_ice", ticket #2369

File size: 35.7 KB
Line 
1MODULE isfcpl
2   !!======================================================================
3   !!                       ***  MODULE  isfcpl  ***
4   !!
5   !! iceshelf coupling module : module managing the coupling between NEMO and an ice sheet model
6   !!
7   !!======================================================================
8   !! History :  4.1  !  2019-07  (P. Mathiot) Original code
9   !!----------------------------------------------------------------------
10
11   !!----------------------------------------------------------------------
12   !!   isfrst        : read/write iceshelf variables in/from restart
13   !!----------------------------------------------------------------------
14   USE oce            ! ocean dynamics and tracers
15#if defined key_qco
16   USE domqco  , ONLY : dom_qco_zgr      ! vertical scale factor interpolation
17#else
18   USE domvvl  , ONLY : dom_vvl_zgr      ! vertical scale factor interpolation
19#endif
20   USE domutl  , ONLY : dom_ngb          ! find the closest grid point from a given lon/lat position
21   USE isf_oce        ! ice shelf variable
22   USE isfutils, ONLY : debug
23   !
24   USE in_out_manager ! I/O manager
25   USE iom            ! I/O library
26   USE lib_mpp , ONLY : mpp_sum, mpp_max ! mpp routine
27   !
28   IMPLICIT NONE
29
30   PRIVATE
31
32   PUBLIC isfcpl_rst_write, isfcpl_init                    ! iceshelf restart read and write
33   PUBLIC isfcpl_ssh, isfcpl_tra, isfcpl_vol, isfcpl_cons  ! iceshelf correction for ssh, tra, dyn and conservation
34
35   TYPE isfcons
36      INTEGER ::   ii     ! i global
37      INTEGER ::   jj     ! j global
38      INTEGER ::   kk     ! k level
39      REAL(wp)::   dvol   ! volume increment
40      REAL(wp)::   dsal   ! salt increment
41      REAL(wp)::   dtem   ! heat increment
42      REAL(wp)::   lon    ! lon
43      REAL(wp)::   lat    ! lat
44      INTEGER ::   ngb    ! 0/1 (valid location or not (ie on halo or no neigbourg))
45   END TYPE
46   !
47   !! * Substitutions
48#  include "do_loop_substitute.h90"
49#  include "domzgr_substitute.h90"
50   !!----------------------------------------------------------------------
51   !! NEMO/OCE 4.0 , NEMO Consortium (2018)
52   !! $Id: sbcisf.F90 10536 2019-01-16 19:21:09Z mathiot $
53   !! Software governed by the CeCILL license (see ./LICENSE)
54   !!----------------------------------------------------------------------
55CONTAINS
56   SUBROUTINE isfcpl_init(Kbb, Kmm, Kaa)
57      !!---------------------------------------------------------------------
58      !!                   ***  ROUTINE iscpl_init  ***
59      !!
60      !! ** Purpose : correct ocean state for new wet cell and horizontal divergence
61      !!              correction for the dynamical adjustement
62      !!
63      !! ** Action : - compute ssh on new wet cell
64      !!             - compute T/S on new wet cell
65      !!             - compute horizontal divergence correction as a volume flux
66      !!             - compute the T/S/vol correction increment to keep trend to 0
67      !!
68      !!---------------------------------------------------------------------
69      INTEGER, INTENT(in) :: Kbb, Kmm, Kaa      ! ocean time level indices
70      !!---------------------------------------------------------------------
71      INTEGER :: id
72      !!----------------------------------------------------------------------
73      !
74      ! start on an euler time step
75      l_1st_euler = .TRUE.
76      !
77      ! allocation and initialisation to 0
78      CALL isf_alloc_cpl()
79      !
80      ! check presence of variable needed for coupling
81      ! iom_varid return 0 if not found
82      id = 1
83      id = id * iom_varid(numror, 'ssmask', ldstop = .false.)
84      id = id * iom_varid(numror, 'tmask' , ldstop = .false.)
85      id = id * iom_varid(numror, 'e3t_n' , ldstop = .false.)
86      id = id * iom_varid(numror, 'e3u_n' , ldstop = .false.)
87      id = id * iom_varid(numror, 'e3v_n' , ldstop = .false.)
88      IF(lwp) WRITE(numout,*) ' isfcpl_init:', id
89      IF (id == 0) THEN
90         IF(lwp) WRITE(numout,*) ' isfcpl_init: restart variables for ice sheet coupling are missing, skip coupling for this leg '
91         IF(lwp) WRITE(numout,*) ' ~~~~~~~~~~~'
92         IF(lwp) WRITE(numout,*) ''
93      ELSE
94         ! extrapolation ssh
95         CALL isfcpl_ssh(Kbb, Kmm, Kaa)
96         !
97         ! extrapolation tracer properties
98         CALL isfcpl_tra(Kmm)
99         !
100         ! correction of the horizontal divergence and associated temp. and salt content flux
101         ! Need to : - include in the cpl cons the risfcpl_vol/tsc contribution
102         !           - decide how to manage thickness level change in conservation
103         CALL isfcpl_vol(Kmm)
104         !
105         ! apply the 'conservation' method
106         IF ( ln_isfcpl_cons ) CALL isfcpl_cons(Kmm)
107         !
108      END IF
109      !
110      ! mask velocity properly (mask used in restart not compatible with new mask)
111      uu(:,:,:,Kmm) = uu(:,:,:,Kmm) * umask(:,:,:)
112      vv(:,:,:,Kmm) = vv(:,:,:,Kmm) * vmask(:,:,:)
113      !
114      ! all before fields set to now values
115      ts  (:,:,:,:,Kbb) = ts  (:,:,:,:,Kmm)
116      uu   (:,:,:,Kbb)   = uu   (:,:,:,Kmm)
117      vv   (:,:,:,Kbb)   = vv   (:,:,:,Kmm)
118      ssh (:,:,Kbb)     = ssh (:,:,Kmm)
119#if ! defined key_qco
120      e3t(:,:,:,Kbb)   = e3t(:,:,:,Kmm)
121#endif
122   END SUBROUTINE isfcpl_init
123
124
125   SUBROUTINE isfcpl_rst_write( kt, Kmm )
126      !!---------------------------------------------------------------------
127      !!                   ***  ROUTINE iscpl_rst_write  ***
128      !!
129      !! ** Purpose : write icesheet coupling variables in restart
130      !!
131      !!-------------------------- IN  --------------------------------------
132      INTEGER, INTENT(in) :: kt
133      INTEGER, INTENT(in) :: Kmm    ! ocean time level index
134      !!----------------------------------------------------------------------
135      INTEGER :: jk                               ! loop index
136      REAL(wp), DIMENSION(jpi,jpj,jpk) :: ze3t, ze3u, ze3v, zgdepw  ! for qco substitution
137      !!----------------------------------------------------------------------
138      !
139      DO jk = 1, jpk
140         ze3t(:,:,jk) = e3t(:,:,jk,Kmm)
141         ze3u(:,:,jk) = e3u(:,:,jk,Kmm)
142         ze3v(:,:,jk) = e3v(:,:,jk,Kmm)
143         !
144         zgdepw(:,:,jk) = gdepw(:,:,jk,Kmm)
145      END DO
146      !
147      CALL iom_rstput( kt, nitrst, numrow, 'tmask'  , tmask  )
148      CALL iom_rstput( kt, nitrst, numrow, 'ssmask' , ssmask )
149      CALL iom_rstput( kt, nitrst, numrow, 'e3t_n'  , ze3t   )
150      CALL iom_rstput( kt, nitrst, numrow, 'e3u_n'  , ze3u   )
151      CALL iom_rstput( kt, nitrst, numrow, 'e3v_n'  , ze3v   )
152      CALL iom_rstput( kt, nitrst, numrow, 'gdepw_n', zgdepw )
153      !
154   END SUBROUTINE isfcpl_rst_write
155
156
157   SUBROUTINE isfcpl_ssh(Kbb, Kmm, Kaa)
158      !!----------------------------------------------------------------------
159      !!                   ***  ROUTINE iscpl_ssh  ***
160      !!
161      !! ** Purpose :   basic guess of ssh in new wet cell
162      !!
163      !! ** Method  :   basic extrapolation from neigbourg cells
164      !!
165      !!----------------------------------------------------------------------
166      !!
167      INTEGER, INTENT(in) :: Kbb, Kmm, Kaa    ! ocean time level indices
168      !!----------------------------------------------------------------------
169      INTEGER :: ji, jj, jd, jk      !! loop index
170      INTEGER :: jip1, jim1, jjp1, jjm1
171      !!
172      REAL(wp):: zsummsk
173      REAL(wp), DIMENSION(jpi,jpj) :: zdssmask, zssmask0, zssmask_b, zssh
174      !!----------------------------------------------------------------------
175      !
176      CALL iom_get( numror, jpdom_auto, 'ssmask'  , zssmask_b   ) ! need to extrapolate T/S
177
178      ! compute new ssh if we open a full water column
179      ! rude average of the closest neigbourgs (e1e2t not taking into account)
180      !
181      zssh(:,:)     = ssh(:,:,Kmm)
182      zssmask0(:,:) = zssmask_b(:,:)
183      !
184      DO jd = 1, nn_drown
185         !
186         zdssmask(:,:) = ssmask(:,:) - zssmask0(:,:)
187         DO_2D( 0, 0, 0, 0 )
188            jip1=ji+1   ;   jim1=ji-1
189            jjp1=jj+1   ;   jjm1=jj-1
190            !
191            zsummsk = zssmask0(jip1,jj) + zssmask0(jim1,jj) + zssmask0(ji,jjp1) + zssmask0(ji,jjm1)
192            !
193            IF (zdssmask(ji,jj) == 1._wp .AND. zsummsk /= 0._wp) THEN
194               ssh(ji,jj,Kmm)=( zssh(jip1,jj)*zssmask0(jip1,jj)     &
195                  &           + zssh(jim1,jj)*zssmask0(jim1,jj)     &
196                  &           + zssh(ji,jjp1)*zssmask0(ji,jjp1)     &
197                  &           + zssh(ji,jjm1)*zssmask0(ji,jjm1)) / zsummsk
198               zssmask_b(ji,jj) = 1._wp
199            ENDIF
200         END_2D
201         !
202         zssh(:,:) = ssh(:,:,Kmm)
203         zssmask0(:,:) = zssmask_b(:,:)
204         !
205         CALL lbc_lnk_multi( 'iscplrst', zssh, 'T', 1.0_wp, zssmask0, 'T', 1.0_wp )
206         !
207      END DO
208      !
209      ! update ssh(:,:,Kmm)
210      ssh(:,:,Kmm) = zssh(:,:) * ssmask(:,:)
211      !
212      ssh(:,:,Kbb) = ssh(:,:,Kmm)
213      !
214      IF ( ln_isfdebug ) CALL debug('isfcpl_ssh: sshn',ssh(:,:,Kmm))
215      !
216      ! recompute the vertical scale factor, depth and water thickness
217      IF(lwp) write(numout,*) 'isfcpl_ssh : recompute scale factor from ssh (new wet cell,Kmm)'
218      IF(lwp) write(numout,*) '~~~~~~~~~~~'
219#if ! defined key_qco
220      DO jk = 1, jpk
221         e3t(:,:,jk,Kmm) = e3t_0(:,:,jk) * ( 1._wp + (ht_0(:,:) + ssh(:,:,Kmm)) * r1_ht_0(:,:) )
222      END DO
223      e3t(:,:,:,Kbb) = e3t(:,:,:,Kmm)
224      CALL dom_vvl_zgr(Kbb, Kmm, Kaa)
225#else
226      CALL dom_qco_zgr(Kbb, Kmm)
227#endif
228      !
229   END SUBROUTINE isfcpl_ssh
230
231
232   SUBROUTINE isfcpl_tra(Kmm)
233      !!----------------------------------------------------------------------
234      !!                   ***  ROUTINE iscpl_tra  ***
235      !!
236      !! ** Purpose :   compute new tn, sn in case of evolving geometry of ice shelves
237      !!
238      !! ** Method  :   tn, sn : basic extrapolation from neigbourg cells
239      !!
240      !!----------------------------------------------------------------------
241      INTEGER, INTENT(in) :: Kmm    ! ocean time level index
242      !!----------------------------------------------------------------------
243      REAL(wp), DIMENSION(jpi,jpj,jpk) :: ztmask_b
244      !REAL(wp), DIMENSION(:,:,:  ), INTENT(in ) :: pdepw_b                         !! depth w before
245      !!
246      INTEGER :: ji, jj, jk, jd          !! loop index
247      INTEGER :: jip1, jim1, jjp1, jjm1, jkp1, jkm1
248      !!
249      REAL(wp):: zsummsk
250      REAL(wp):: zdz, zdzm1, zdzp1
251      !!
252      REAL(wp), DIMENSION(jpi,jpj)          :: zdmask
253      REAL(wp), DIMENSION(jpi,jpj,jpk)      :: ztmask0, zwmaskn
254      REAL(wp), DIMENSION(jpi,jpj,jpk)      :: ztmask1, zwmaskb, ztmp3d
255      REAL(wp), DIMENSION(jpi,jpj,jpk,jpts) :: zts0
256      !!----------------------------------------------------------------------
257      !
258      CALL iom_get( numror, jpdom_auto, 'tmask'  , ztmask_b   ) ! need to extrapolate T/S
259      !CALL iom_get( numror, jpdom_auto, 'wmask'  , zwmask_b  ) ! need to extrapolate T/S
260      !CALL iom_get( numror, jpdom_auto, 'gdepw_n', zdepw_b(:,:,:) ) ! need to interpol vertical profile (vvl)
261      !
262      !
263      ! compute new T/S (interpolation) if vvl only for common wet cell in before and after wmask
264      !PM: Is this IF needed since change to VVL by default
265      !bugged : to be corrected (PM)
266      ! back up original t/s/mask
267      !tsb (:,:,:,:) = ts(:,:,:,:,Kmm)
268      !
269     ! compute new T/S (interpolation) if vvl only for common wet cell in before and after wmask
270
271!      IF (.NOT.ln_linssh) THEN
272!         DO jk = 2,jpk-1
273!            DO jj = 1,jpj
274!               DO ji = 1,jpi
275!                  IF (wmask(ji,jj,jk) * zwmaskb(ji,jj,jk) == 1._wp .AND. (tmask(ji,jj,1)==0._wp .OR. ztmask_b(ji,jj,1)==0._wp) ) THEN
276!
277!                     !compute weight
278!                     zdzp1 = MAX(0._wp,pdepw_b(ji,jj,jk+1) - gdepw(ji,jj,jk+1,Kmm))
279!                     zdzm1 = MAX(0._wp,gdepw(ji,jj,jk  ,Kmm) - pdepw_b(ji,jj,jk  ))
280!                     zdz   = e3t(ji,jj,jk,Kmm) - zdzp1 - zdzm1 ! if isf : e3t = gdepw(ji,jj,jk+1,Kmm)- gdepw(ji,jj,jk,Kmm)
281!
282!                     IF (zdz .LT. 0._wp) THEN
283!                        CALL ctl_stop( 'STOP', 'rst_iscpl : unable to compute the interpolation' )
284!                     END IF
285!
286!                     ts(ji,jj,jk,jp_tem,Kmm) = ( zdzp1*ts(ji,jj,jk+1,jp_tem,Kbb) &
287!                        &                   + zdz  *ts(ji,jj,jk  ,jp_tem,Kbb) &
288!                        &                   + zdzm1*ts(ji,jj,jk-1,jp_tem,Kbb) )/e3t(ji,jj,jk,Kmm)
289!
290!                     ts(ji,jj,jk,jp_sal,Kmm) = ( zdzp1*ts(ji,jj,jk+1,jp_sal,Kbb) &
291!                        &                   + zdz  *ts(ji,jj,jk  ,jp_sal,Kbb) &
292!                        &                   + zdzm1*ts(ji,jj,jk-1,jp_sal,Kbb) )/e3t(ji,jj,jk,Kmm)
293!
294!                  END IF
295!               END DO
296!            END DO
297!         END DO
298!      END IF
299
300      zts0(:,:,:,:)  = ts(:,:,:,:,Kmm)
301      ztmask0(:,:,:) = ztmask_b(:,:,:)
302      ztmask1(:,:,:) = ztmask_b(:,:,:)
303      !
304      ! iterate the extrapolation processes nn_drown times
305      DO jd = 1,nn_drown ! resolution dependent (OK for ISOMIP+ case)
306         DO jk = 1,jpk-1
307            !
308            ! define new wet cell
309            zdmask(:,:) = tmask(:,:,jk) - ztmask0(:,:,jk);
310            !
311            DO_2D( 0, 0, 0, 0 )
312               jip1=ji+1; jim1=ji-1;
313               jjp1=jj+1; jjm1=jj-1;
314               !
315               ! check if a wet neigbourg cell is present
316               zsummsk = ztmask0(jip1,jj  ,jk) + ztmask0(jim1,jj  ,jk) &
317                       + ztmask0(ji  ,jjp1,jk) + ztmask0(ji  ,jjm1,jk)
318               !
319               ! if neigbourg wet cell available at the same level
320               IF ( zdmask(ji,jj) == 1._wp  .AND. zsummsk /= 0._wp ) THEN
321                  !
322                  ! horizontal basic extrapolation
323                  ts(ji,jj,jk,1,Kmm)=( zts0(jip1,jj  ,jk,1) * ztmask0(jip1,jj  ,jk) &
324                  &               + zts0(jim1,jj  ,jk,1) * ztmask0(jim1,jj  ,jk) &
325                  &               + zts0(ji  ,jjp1,jk,1) * ztmask0(ji  ,jjp1,jk) &
326                  &               + zts0(ji  ,jjm1,jk,1) * ztmask0(ji  ,jjm1,jk) ) / zsummsk
327                  ts(ji,jj,jk,2,Kmm)=( zts0(jip1,jj  ,jk,2) * ztmask0(jip1,jj  ,jk) &
328                  &               + zts0(jim1,jj  ,jk,2) * ztmask0(jim1,jj  ,jk) &
329                  &               + zts0(ji  ,jjp1,jk,2) * ztmask0(ji  ,jjp1,jk) &
330                  &               + zts0(ji  ,jjm1,jk,2) * ztmask0(ji  ,jjm1,jk) ) / zsummsk
331                  !
332                  ! update mask for next pass
333                  ztmask1(ji,jj,jk)=1
334                  !
335               ! in case no neigbourg wet cell available at the same level
336               ! check if a wet cell is available below
337               ELSEIF (zdmask(ji,jj) == 1._wp .AND. zsummsk == 0._wp) THEN
338                  !
339                  ! vertical extrapolation if horizontal extrapolation failed
340                  jkm1=max(1,jk-1) ; jkp1=min(jpk,jk+1)
341                  !
342                  ! check if a wet neigbourg cell is present
343                  zsummsk = ztmask0(ji,jj,jkm1) + ztmask0(ji,jj,jkp1)
344                  IF (zdmask(ji,jj) == 1._wp .AND. zsummsk /= 0._wp ) THEN
345                     ts(ji,jj,jk,1,Kmm)=( zts0(ji,jj,jkp1,1)*ztmask0(ji,jj,jkp1)     &
346                     &               + zts0(ji,jj,jkm1,1)*ztmask0(ji,jj,jkm1)) / zsummsk
347                     ts(ji,jj,jk,2,Kmm)=( zts0(ji,jj,jkp1,2)*ztmask0(ji,jj,jkp1)     &
348                     &               + zts0(ji,jj,jkm1,2)*ztmask0(ji,jj,jkm1)) / zsummsk
349                     !
350                     ! update mask for next pass
351                     ztmask1(ji,jj,jk)=1._wp
352                  END IF
353               END IF
354            END_2D
355         END DO
356         !
357         ! update temperature and salinity and mask
358         zts0(:,:,:,:)  = ts(:,:,:,:,Kmm)
359         ztmask0(:,:,:) = ztmask1(:,:,:)
360         !
361         CALL lbc_lnk_multi( 'iscplrst', zts0(:,:,:,jp_tem), 'T', 1.0_wp, zts0(:,:,:,jp_sal), 'T', 1.0_wp, ztmask0, 'T', 1.0_wp)
362         !
363      END DO  ! nn_drown
364      !
365      ! mask new ts(:,:,:,:,Kmm) field
366      ts(:,:,:,jp_tem,Kmm) = zts0(:,:,:,jp_tem) * tmask(:,:,:)
367      ts(:,:,:,jp_sal,Kmm) = zts0(:,:,:,jp_sal) * tmask(:,:,:)
368      !
369      ! sanity check
370      ! -----------------------------------------------------------------------------------------
371      ! case we open a cell but no neigbour cells available to get an estimate of T and S
372      DO_3D( 1, 1, 1, 1, 1,jpk-1 )
373         IF (tmask(ji,jj,jk) == 1._wp .AND. ts(ji,jj,jk,2,Kmm) == 0._wp)              &
374            &   CALL ctl_stop('STOP', 'failing to fill all new weet cell,     &
375            &                          try increase nn_drown or activate XXXX &
376            &                         in your domain cfg computation'         )
377      END_3D
378      !
379   END SUBROUTINE isfcpl_tra
380
381
382   SUBROUTINE isfcpl_vol(Kmm)
383      !!----------------------------------------------------------------------
384      !!                   ***  ROUTINE iscpl_vol  ***
385      !!
386      !! ** Purpose : compute the correction of the local divergence to apply
387      !!              during the first time step after the coupling.
388      !!
389      !! ** Method  : - compute horizontal vol div. before/after coupling
390      !!              - compute vertical input
391      !!              - compute correction
392      !!
393      !!----------------------------------------------------------------------
394      !!
395      INTEGER, INTENT(in) :: Kmm    ! ocean time level index
396      !!----------------------------------------------------------------------
397      INTEGER :: ji, jj, jk
398      INTEGER :: ikb, ikt
399      !!
400      REAL(wp), DIMENSION(jpi,jpj,jpk) :: zqvolb, zqvoln  ! vol flux div.         before/after coupling
401      REAL(wp), DIMENSION(jpi,jpj,jpk) :: ze3u_b, ze3v_b  ! vertical scale factor before/after coupling
402      REAL(wp), DIMENSION(jpi,jpj,jpk) :: ztmask_b        ! mask                  before       coupling
403      !!----------------------------------------------------------------------
404      !
405      CALL iom_get( numror, jpdom_auto, 'tmask'  , ztmask_b )
406      CALL iom_get( numror, jpdom_auto, 'e3u_n'  , ze3u_b   )
407      CALL iom_get( numror, jpdom_auto, 'e3v_n'  , ze3v_b   )
408      !
409      ! 1.0: compute horizontal volume flux divergence difference before-after coupling
410      !
411      DO jk = 1, jpk                                 ! Horizontal slab
412         ! 1.1: get volume flux before coupling (>0 out)
413         DO_2D( 0, 0, 0, 0 )
414            zqvolb(ji,jj,jk) =    &
415               &  (   e2u(ji  ,jj  ) * ze3u_b(ji  ,jj  ,jk) * uu(ji  ,jj  ,jk,Kmm)      &
416               &    - e2u(ji-1,jj  ) * ze3u_b(ji-1,jj  ,jk) * uu(ji-1,jj  ,jk,Kmm)      &
417               &    + e1v(ji  ,jj  ) * ze3v_b(ji  ,jj  ,jk) * vv(ji  ,jj  ,jk,Kmm)      &
418               &    - e1v(ji  ,jj-1) * ze3v_b(ji  ,jj-1,jk) * vv(ji  ,jj-1,jk,Kmm)  )   &
419               &                * ztmask_b(ji,jj,jk)
420         END_2D
421         !
422         ! 1.2: get volume flux after coupling (>0 out)
423         ! properly mask velocity
424         ! (velocity are still mask with old mask at this stage)
425         uu(:,:,jk,Kmm) = uu(:,:,jk,Kmm) * umask(:,:,jk)
426         vv(:,:,jk,Kmm) = vv(:,:,jk,Kmm) * vmask(:,:,jk)
427         ! compute volume flux divergence after coupling
428         DO_2D( 0, 0, 0, 0 )
429            zqvoln(ji,jj,jk) =   &
430               &  (   e2u(ji  ,jj  ) * e3u(ji  ,jj  ,jk,Kmm) * uu(ji  ,jj  ,jk,Kmm)    &
431               &    - e2u(ji-1,jj  ) * e3u(ji-1,jj  ,jk,Kmm) * uu(ji-1,jj  ,jk,Kmm)    &
432               &    + e1v(ji  ,jj  ) * e3v(ji  ,jj  ,jk,Kmm) * vv(ji  ,jj  ,jk,Kmm)    &
433               &    - e1v(ji  ,jj-1) * e3v(ji  ,jj-1,jk,Kmm) * vv(ji  ,jj-1,jk,Kmm)  ) &
434               &               * tmask(ji,jj,jk)
435         END_2D
436         !
437         ! 1.3: get 3d volume flux difference (before - after cpl) (>0 out)
438         !      correction to add is _b - _n
439         risfcpl_vol(:,:,jk) = zqvolb(:,:,jk) - zqvoln(:,:,jk)
440      END DO
441      !
442      ! 2.0: include the contribution of the vertical velocity in the volume flux correction
443      !
444      DO_2D( 0, 0, 0, 0 )
445         !
446         ikt = mikt(ji,jj)
447         IF ( ikt > 1 .AND. ssmask(ji,jj) == 1 ) THEN
448            risfcpl_vol(ji,jj,ikt) = risfcpl_vol(ji,jj,ikt) + SUM(zqvolb(ji,jj,1:ikt-1))  ! test sign
449         ENDIF
450         !
451      END_2D
452      !
453      CALL lbc_lnk( 'iscpl', risfcpl_vol, 'T', 1.0_wp )
454      !
455      ! 3.0: set total correction (div, tr(:,:,:,:,Krhs), ssh)
456      !
457      ! 3.1: mask volume flux divergence correction
458      risfcpl_vol(:,:,:) = risfcpl_vol(:,:,:) * tmask(:,:,:)
459      !
460      ! 3.2: get 3d tr(:,:,:,:,Krhs) increment to apply at the first time step
461      ! temperature and salt content flux computed using local ts(:,:,:,:,Kmm)
462      ! (very simple advection scheme)
463      ! (>0 out)
464      risfcpl_tsc(:,:,:,jp_tem) = -risfcpl_vol(:,:,:) * ts(:,:,:,jp_tem,Kmm)
465      risfcpl_tsc(:,:,:,jp_sal) = -risfcpl_vol(:,:,:) * ts(:,:,:,jp_sal,Kmm)
466      !
467      ! 3.3: ssh correction (for dynspg_ts)
468      risfcpl_ssh(:,:) = 0.0
469      DO jk = 1,jpk
470         risfcpl_ssh(:,:) = risfcpl_ssh(:,:) + risfcpl_vol(:,:,jk) * r1_e1e2t(:,:)
471      END DO
472      !
473   END SUBROUTINE isfcpl_vol
474
475
476   SUBROUTINE isfcpl_cons(Kmm)
477      !!----------------------------------------------------------------------
478      !!                   ***  ROUTINE iscpl_cons  ***
479      !!
480      !! ** Purpose :   compute the corrective increment in volume/salt/heat to put back the vol/heat/salt
481      !!                removed or added during the coupling processes (wet or dry new cell)
482      !!
483      !! ** Method  :   - compare volume/heat/salt before and after
484      !!                - look for the closest wet cells (share amoung neigbourgs if there are)
485      !!                - build the correction increment to applied at each time step
486      !!
487      !!----------------------------------------------------------------------
488      !
489      TYPE(isfcons), DIMENSION(:),ALLOCATABLE :: zisfpts ! list of point receiving a correction
490      !
491      !!----------------------------------------------------------------------
492      INTEGER, INTENT(in) :: Kmm    ! ocean time level index
493      !!----------------------------------------------------------------------
494      INTEGER  ::   ji   , jj  , jk  , jproc          ! loop index
495      INTEGER  ::   jip1 , jim1, jjp1, jjm1           ! dummy indices
496      INTEGER  ::   iig  , ijg, ik                    ! dummy indices
497      INTEGER  ::   jisf                              ! start, end and current position in the increment array
498      INTEGER  ::   ingb, ifind                       ! 0/1 target found or need to be found
499      INTEGER  ::   nisfl_area                        ! global number of cell concerned by the wet->dry case
500      INTEGER, DIMENSION(jpnij) :: nisfl              ! local  number of cell concerned by the wet->dry case
501      !
502      REAL(wp) ::   z1_sum, z1_rdtiscpl
503      REAL(wp) ::   zdtem, zdsal, zdvol, zratio       ! tem, sal, vol increment
504      REAL(wp) ::   zlon , zlat                       ! target location
505      REAL(wp), DIMENSION(jpi,jpj,jpk) :: ztmask_b    ! mask before
506      REAL(wp), DIMENSION(jpi,jpj,jpk) :: ze3t_b      ! scale factor before
507      REAL(wp), DIMENSION(jpi,jpj,jpk) :: zt_b      ! scale factor before
508      REAL(wp), DIMENSION(jpi,jpj,jpk) :: zs_b      ! scale factor before
509      !!----------------------------------------------------------------------
510
511      !==============================================================================
512      ! 1.0: initialisation
513      !==============================================================================
514
515      ! get restart variable
516      CALL iom_get( numror, jpdom_auto, 'tmask'  , ztmask_b(:,:,:) ) ! need to extrapolate T/S
517      CALL iom_get( numror, jpdom_auto, 'e3t_n'  , ze3t_b(:,:,:)   )
518      CALL iom_get( numror, jpdom_auto, 'tn'     , zt_b(:,:,:)     )
519      CALL iom_get( numror, jpdom_auto, 'sn'     , zs_b(:,:,:)     )
520
521      ! compute run length
522      nstp_iscpl  = nitend - nit000 + 1
523      rdt_iscpl   = nstp_iscpl * rn_Dt
524      z1_rdtiscpl = 1._wp / rdt_iscpl
525
526      IF (lwp) WRITE(numout,*) '            nb of stp for cons  = ', nstp_iscpl
527      IF (lwp) WRITE(numout,*) '            coupling time step  = ', rdt_iscpl
528
529      ! initialisation correction
530      risfcpl_cons_vol = 0.0
531      risfcpl_cons_ssh = 0.0
532      risfcpl_cons_tsc = 0.0
533
534      !==============================================================================
535      ! 2.0: diagnose the heat, salt and volume input and compute the correction variable
536      !      for case where we wet a cell or cell still wet (no change in cell status)
537      !==============================================================================
538
539      DO jk = 1,jpk-1
540         DO jj = Njs0,Nje0
541            DO ji = Nis0,Nie0
542
543               ! volume diff
544               zdvol =   e3t  (ji,jj,jk,Kmm) *  tmask  (ji,jj,jk)   &
545                  &   - ze3t_b(ji,jj,jk    ) * ztmask_b(ji,jj,jk)
546
547               ! heat diff
548               zdtem = ts (ji,jj,jk,jp_tem,Kmm) *  e3t(ji,jj,jk,Kmm) *  tmask  (ji,jj,jk)   &
549                     - zt_b(ji,jj,jk)        * ze3t_b(ji,jj,jk) * ztmask_b(ji,jj,jk)
550
551               ! salt diff
552               zdsal = ts(ji,jj,jk,jp_sal,Kmm) *  e3t(ji,jj,jk,Kmm) *  tmask  (ji,jj,jk)   &
553                     - zs_b(ji,jj,jk)       * ze3t_b(ji,jj,jk) * ztmask_b(ji,jj,jk)
554
555               ! volume, heat and salt differences in each cell (>0 means correction is an outward flux)
556               ! in addition to the geometry change unconservation, need to add the divergence correction as it is flux across the boundary
557               risfcpl_cons_vol(ji,jj,jk)        = (   zdvol * e1e2t(ji,jj) + risfcpl_vol(ji,jj,jk)        ) * z1_rdtiscpl
558               risfcpl_cons_tsc(ji,jj,jk,jp_sal) = ( - zdsal * e1e2t(ji,jj) + risfcpl_tsc(ji,jj,jk,jp_sal) ) * z1_rdtiscpl
559               risfcpl_cons_tsc(ji,jj,jk,jp_tem) = ( - zdtem * e1e2t(ji,jj) + risfcpl_tsc(ji,jj,jk,jp_tem) ) * z1_rdtiscpl
560
561            END DO
562         END DO
563      END DO
564      !
565      !==============================================================================
566      ! 3.0: diagnose the heat, salt and volume input and compute the correction variable
567      !      for case where we close a cell
568      !==============================================================================
569      !
570      ! compute the total number of point receiving a correction increment for each processor
571      ! local
572      nisfl(:)=0
573      DO jk = 1,jpk-1
574         DO jj = Njs0,Nje0
575            DO ji = Nis0,Nie0
576               jip1=MIN(ji+1,jpi) ; jim1=MAX(ji-1,1) ; jjp1=MIN(jj+1,jpj) ; jjm1=MAX(jj-1,1) ;
577               IF ( tmask(ji,jj,jk) == 0._wp .AND. ztmask_b(ji,jj,jk) == 1._wp ) THEN
578                  nisfl(narea) = nisfl(narea) + MAX(SUM(tmask(jim1:jip1,jjm1:jjp1,jk)),1._wp)
579               ENDIF
580            ENDDO
581         ENDDO
582      ENDDO
583      !
584      ! global
585      CALL mpp_sum('isfcpl',nisfl  )
586      !
587      ! allocate list of point receiving correction
588      ALLOCATE(zisfpts(nisfl(narea)))
589      !
590      zisfpts(:) = isfcons(0,0,0,-HUGE(1.0), -HUGE(1.0), -HUGE(1.0), -HUGE(1.0), -HUGE(1.0), 0)
591      !
592      ! start computing the correction and fill zisfpts
593      ! local
594      jisf = 0
595      DO jk = 1,jpk-1
596         DO jj = Njs0,Nje0
597            DO ji = Nis0,Nie0
598               IF ( tmask(ji,jj,jk) == 0._wp .AND. ztmask_b(ji,jj,jk) == 1._wp ) THEN
599
600                  jip1=MIN(ji+1,jpi) ; jim1=MAX(ji-1,1) ; jjp1=MIN(jj+1,jpj) ; jjm1=MAX(jj-1,1) ;
601
602                  zdvol = risfcpl_cons_vol(ji,jj,jk       )
603                  zdsal = risfcpl_cons_tsc(ji,jj,jk,jp_sal)
604                  zdtem = risfcpl_cons_tsc(ji,jj,jk,jp_tem)
605
606                  IF ( SUM( tmask(jim1:jip1,jjm1:jjp1,jk) ) > 0._wp ) THEN
607                     ! spread correction amoung neigbourg wet cells (horizontal direction first)
608                     ! as it is a rude correction corner and lateral cell have the same weight
609                     !
610                     z1_sum =  1._wp / SUM( tmask(jim1:jip1,jjm1:jjp1,jk) )
611                     !
612                     ! lateral cells
613                     IF (tmask(jip1,jj  ,jk) == 1) CALL update_isfpts(zisfpts, jisf, jip1, jj  , jk, zdvol, zdsal, zdtem, z1_sum)
614                     IF (tmask(jim1,jj  ,jk) == 1) CALL update_isfpts(zisfpts, jisf, jim1, jj  , jk, zdvol, zdsal, zdtem, z1_sum)
615                     IF (tmask(ji  ,jjp1,jk) == 1) CALL update_isfpts(zisfpts, jisf, ji  , jjp1, jk, zdvol, zdsal, zdtem, z1_sum)
616                     IF (tmask(ji  ,jjm1,jk) == 1) CALL update_isfpts(zisfpts, jisf, ji  , jjm1, jk, zdvol, zdsal, zdtem, z1_sum)
617                     !
618                     ! corner  cells
619                     IF (tmask(jip1,jjm1,jk) == 1) CALL update_isfpts(zisfpts, jisf, jip1, jjm1, jk, zdvol, zdsal, zdtem, z1_sum)
620                     IF (tmask(jim1,jjm1,jk) == 1) CALL update_isfpts(zisfpts, jisf, jim1, jjm1, jk, zdvol, zdsal, zdtem, z1_sum)
621                     IF (tmask(jim1,jjp1,jk) == 1) CALL update_isfpts(zisfpts, jisf, jim1, jjp1, jk, zdvol, zdsal, zdtem, z1_sum)
622                     IF (tmask(jip1,jjp1,jk) == 1) CALL update_isfpts(zisfpts, jisf, jip1, jjp1, jk, zdvol, zdsal, zdtem, z1_sum)
623                     !
624                  ELSE IF ( tmask(ji,jj,jk+1) == 1._wp ) THEN
625                     ! spread correction amoung neigbourg wet cells (vertical direction)
626                     CALL update_isfpts(zisfpts, jisf, ji  , jj  , jk+1, zdvol, zdsal, zdtem, 1.0_wp, 0)
627                  ELSE
628                     ! need to find where to put correction in later on
629                     CALL update_isfpts(zisfpts, jisf, ji  , jj  , jk  , zdvol, zdsal, zdtem, 1.0_wp, 1)
630                  END IF
631               END IF
632            END DO
633         END DO
634      END DO
635      !
636      ! share data among all processes because for some point we need to find the closest wet point (could be on other process)
637      DO jproc=1,jpnij
638         !
639         ! share total number of isf point treated for proc jproc
640         IF (jproc==narea) THEN
641            nisfl_area=nisfl(jproc)
642         ELSE
643            nisfl_area=0
644         END IF
645         CALL mpp_max('isfcpl',nisfl_area)
646         !
647         DO jisf = 1,nisfl_area
648            !
649            IF (jproc==narea) THEN
650               ! indices (conversion to global indices and sharing)
651               iig = zisfpts(jisf)%ii       ; ijg = zisfpts(jisf)%jj       ; ik = zisfpts(jisf)%kk
652               !
653               ! data
654               zdvol = zisfpts(jisf)%dvol   ; zdsal = zisfpts(jisf)%dsal   ; zdtem = zisfpts(jisf)%dtem
655               !
656               ! location
657               zlat = zisfpts(jisf)%lat     ; zlon = zisfpts(jisf)%lon
658               !
659               ! find flag
660               ingb = zisfpts(jisf)%ngb
661            ELSE
662               iig  =0   ; ijg  =0   ; ik   =0
663               zdvol=-HUGE(1.0) ; zdsal=-HUGE(1.0) ; zdtem=-HUGE(1.0)
664               zlat =-HUGE(1.0) ; zlon =-HUGE(1.0)
665               ingb = 0
666            END IF
667            !
668            ! share data (need synchronisation of data as get_correction call a global com)
669            CALL mpp_max('isfcpl',iig)   ; CALL mpp_max('isfcpl',ijg)   ; CALL mpp_max('isfcpl',ik)
670            CALL mpp_max('isfcpl',zdvol) ; CALL mpp_max('isfcpl',zdsal) ; CALL mpp_max('isfcpl',zdtem)
671            CALL mpp_max('isfcpl',zlat)  ; CALL mpp_max('isfcpl',zlon)
672            CALL mpp_max('isfcpl',ingb)
673            !
674            ! fill the 3d correction array
675            CALL get_correction(iig, ijg, ik, zlon, zlat, zdvol, zdsal, zdtem, ingb)
676         END DO
677      END DO
678      !
679      !==============================================================================
680      ! 4.0: finalisation and compute ssh equivalent of the volume correction
681      !==============================================================================
682      !
683      ! mask (>0 out)
684      risfcpl_cons_vol(:,:,:       ) = risfcpl_cons_vol(:,:,:       ) * tmask(:,:,:)
685      risfcpl_cons_tsc(:,:,:,jp_sal) = risfcpl_cons_tsc(:,:,:,jp_sal) * tmask(:,:,:)
686      risfcpl_cons_tsc(:,:,:,jp_tem) = risfcpl_cons_tsc(:,:,:,jp_tem) * tmask(:,:,:)
687      !
688      ! add lbclnk
689      CALL lbc_lnk_multi( 'iscplrst', risfcpl_cons_tsc(:,:,:,jp_tem), 'T', 1.0_wp, risfcpl_cons_tsc(:,:,:,jp_sal), 'T', 1.0_wp, &
690         &                            risfcpl_cons_vol(:,:,:)       , 'T', 1.0_wp)
691      !
692      ! ssh correction (for dynspg_ts)
693      DO jk = 1,jpk
694         risfcpl_cons_ssh(:,:) = risfcpl_cons_ssh(:,:) + risfcpl_cons_vol(:,:,jk)
695      END DO
696      risfcpl_cons_ssh(:,:) = risfcpl_cons_ssh(:,:) * r1_e1e2t(:,:)
697      !
698   END SUBROUTINE isfcpl_cons
699   !
700   SUBROUTINE update_isfpts(sisfpts, kpts, ki, kj, kk, pdvol, pdsal, pdtem, pratio, kfind)
701      !!---------------------------------------------------------------------
702      !!                  ***  ROUTINE update_isfpts  ***
703      !!
704      !! ** Purpose : if a cell become dry, we need to put the corrective increment elsewhere
705      !!
706      !! ** Action  : update the list of point
707      !!
708      !!----------------------------------------------------------------------
709      !!----------------------------------------------------------------------
710      TYPE(isfcons), DIMENSION(:), INTENT(inout) :: sisfpts
711      INTEGER,                     INTENT(inout) :: kpts
712      !!----------------------------------------------------------------------
713      INTEGER,      INTENT(in   )           :: ki, kj, kk                  !    target location (kfind=0)
714      !                                                                    ! or source location (kfind=1)
715      INTEGER,      INTENT(in   ), OPTIONAL :: kfind                       ! 0  target cell already found
716      !                                                                    ! 1  target to be determined
717      REAL(wp),     INTENT(in   )           :: pdvol, pdsal, pdtem, pratio ! vol/sal/tem increment
718      !                                                                    ! and ratio in case increment span over multiple cells.
719      !!----------------------------------------------------------------------
720      INTEGER :: ifind
721      !!----------------------------------------------------------------------
722      !
723      ! increment position
724      kpts = kpts + 1
725      !
726      ! define if we need to look for closest valid wet cell (no neighbours or neigbourg on halo)
727      IF ( PRESENT(kfind) ) THEN
728         ifind = kfind
729      ELSE
730         ifind = ( 1 - tmask_h(ki,kj) ) * tmask(ki,kj,kk)
731      END IF
732      !
733      ! update isfpts structure
734      sisfpts(kpts) = isfcons(mig(ki), mjg(kj), kk, pratio * pdvol, pratio * pdsal, pratio * pdtem, glamt(ki,kj), gphit(ki,kj), ifind )
735      !
736   END SUBROUTINE update_isfpts
737   !
738   SUBROUTINE get_correction( ki, kj, kk, plon, plat, pvolinc, psalinc, pteminc, kfind)
739      !!---------------------------------------------------------------------
740      !!                  ***  ROUTINE get_correction  ***
741      !!
742      !! ** Action : - Find the closest valid cell if needed (wet and not on the halo)
743      !!             - Scale the correction depending of pratio (case where multiple wet neigbourgs)
744      !!             - Fill the correction array
745      !!
746      !!----------------------------------------------------------------------
747      INTEGER , INTENT(in) :: ki, kj, kk, kfind        ! target point indices
748      REAL(wp), INTENT(in) :: plon, plat               ! target point lon/lat
749      REAL(wp), INTENT(in) :: pvolinc, pteminc,psalinc ! correction increment for vol/temp/salt
750      !!----------------------------------------------------------------------
751      INTEGER :: jj, ji, iig, ijg
752      !!----------------------------------------------------------------------
753      !
754      ! define global indice of correction location
755      iig = ki ; ijg = kj
756      IF ( kfind == 1 ) CALL dom_ngb( plon, plat, iig, ijg,'T', kk)
757      !
758      ! fill the correction array
759      DO jj = mj0(ijg),mj1(ijg)
760         DO ji = mi0(iig),mi1(iig)
761            ! correct the vol_flx and corresponding heat/salt flx in the closest cell
762            risfcpl_cons_vol(ji,jj,kk)        =  risfcpl_cons_vol(ji,jj,kk       ) + pvolinc
763            risfcpl_cons_tsc(ji,jj,kk,jp_sal) =  risfcpl_cons_tsc(ji,jj,kk,jp_sal) + psalinc
764            risfcpl_cons_tsc(ji,jj,kk,jp_tem) =  risfcpl_cons_tsc(ji,jj,kk,jp_tem) + pteminc
765         END DO
766      END DO
767
768   END SUBROUTINE get_correction
769
770END MODULE isfcpl
Note: See TracBrowser for help on using the repository browser.