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/branches/UKMO/NEMO_4.0.2_ENHANCE-02_ISF_nemo/src/OCE/ISF – NEMO

source: NEMO/branches/UKMO/NEMO_4.0.2_ENHANCE-02_ISF_nemo/src/OCE/ISF/isfcpl.F90 @ 12709

Last change on this file since 12709 was 12709, checked in by mathiot, 4 years ago

NEMO_4.0.2_ENHANCE-02_ISF_nemo: remove svn keywords

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