Index: NEMO/branches/2020/r4.0-HEAD_r12713_clem_dan_fixcpl/src/ICE/icedyn_adv_pra.F90
===================================================================
--- NEMO/branches/2020/r4.0-HEAD_r12713_clem_dan_fixcpl/src/ICE/icedyn_adv_pra.F90	(revision 12815)
+++ NEMO/branches/2020/r4.0-HEAD_r12713_clem_dan_fixcpl/src/ICE/icedyn_adv_pra.F90	(revision 12816)
@@ -870,22 +870,31 @@
             !
             IF( ln_pnd_H12 ) THEN                                    ! melt pond fraction
-               CALL iom_get( numrir, jpdom_autoglo, 'sxap' , sxap  )
-               CALL iom_get( numrir, jpdom_autoglo, 'syap' , syap  )
-               CALL iom_get( numrir, jpdom_autoglo, 'sxxap', sxxap )
-               CALL iom_get( numrir, jpdom_autoglo, 'syyap', syyap )
-               CALL iom_get( numrir, jpdom_autoglo, 'sxyap', sxyap )
-               !                                                     ! melt pond volume
-               CALL iom_get( numrir, jpdom_autoglo, 'sxvp' , sxvp  )
-               CALL iom_get( numrir, jpdom_autoglo, 'syvp' , syvp  )
-               CALL iom_get( numrir, jpdom_autoglo, 'sxxvp', sxxvp )
-               CALL iom_get( numrir, jpdom_autoglo, 'syyvp', syyvp )
-               CALL iom_get( numrir, jpdom_autoglo, 'sxyvp', sxyvp )
-               !
+               IF( iom_varid( numror, 'sxap', ldstop = .FALSE. ) > 0 ) THEN
+                  CALL iom_get( numrir, jpdom_autoglo, 'sxap' , sxap  )
+                  CALL iom_get( numrir, jpdom_autoglo, 'syap' , syap  )
+                  CALL iom_get( numrir, jpdom_autoglo, 'sxxap', sxxap )
+                  CALL iom_get( numrir, jpdom_autoglo, 'syyap', syyap )
+                  CALL iom_get( numrir, jpdom_autoglo, 'sxyap', sxyap )
+                  !                                                     ! melt pond volume
+                  CALL iom_get( numrir, jpdom_autoglo, 'sxvp' , sxvp  )
+                  CALL iom_get( numrir, jpdom_autoglo, 'syvp' , syvp  )
+                  CALL iom_get( numrir, jpdom_autoglo, 'sxxvp', sxxvp )
+                  CALL iom_get( numrir, jpdom_autoglo, 'syyvp', syyvp )
+                  CALL iom_get( numrir, jpdom_autoglo, 'sxyvp', sxyvp )
+               ELSE
+                  sxap = 0._wp ;   syap = 0._wp    ;   sxxap = 0._wp    ;   syyap = 0._wp    ;   sxyap = 0._wp   ! melt pond fraction
+                  sxvp = 0._wp ;   syvp = 0._wp    ;   sxxvp = 0._wp    ;   syyvp = 0._wp    ;   sxyvp = 0._wp   ! melt pond volume
+               ENDIF
+                  !
                IF ( ln_pnd_lids ) THEN                               ! melt pond lid volume
-                  CALL iom_get( numrir, jpdom_autoglo, 'sxvl' , sxvl  )
-                  CALL iom_get( numrir, jpdom_autoglo, 'syvl' , syvl  )
-                  CALL iom_get( numrir, jpdom_autoglo, 'sxxvl', sxxvl )
-                  CALL iom_get( numrir, jpdom_autoglo, 'syyvl', syyvl )
-                  CALL iom_get( numrir, jpdom_autoglo, 'sxyvl', sxyvl )
+                  IF( iom_varid( numror, 'sxvl', ldstop = .FALSE. ) > 0 ) THEN
+                     CALL iom_get( numrir, jpdom_autoglo, 'sxvl' , sxvl  )
+                     CALL iom_get( numrir, jpdom_autoglo, 'syvl' , syvl  )
+                     CALL iom_get( numrir, jpdom_autoglo, 'sxxvl', sxxvl )
+                     CALL iom_get( numrir, jpdom_autoglo, 'syyvl', syyvl )
+                     CALL iom_get( numrir, jpdom_autoglo, 'sxyvl', sxyvl )
+                  ELSE
+                     sxvl = 0._wp; syvl = 0._wp    ;   sxxvl = 0._wp    ;   syyvl = 0._wp    ;   sxyvl = 0._wp   ! melt pond lid volume
+                  ENDIF
                ENDIF
             ENDIF
Index: NEMO/branches/2020/r4.0-HEAD_r12713_clem_dan_fixcpl/src/ICE/iceistate.F90
===================================================================
--- NEMO/branches/2020/r4.0-HEAD_r12713_clem_dan_fixcpl/src/ICE/iceistate.F90	(revision 12815)
+++ NEMO/branches/2020/r4.0-HEAD_r12713_clem_dan_fixcpl/src/ICE/iceistate.F90	(revision 12816)
@@ -182,7 +182,7 @@
             !
             ! -- mandatory fields -- !
-            zht_i_ini(:,:) = si(jp_hti)%fnow(:,:,1)
-            zht_s_ini(:,:) = si(jp_hts)%fnow(:,:,1)
-            zat_i_ini(:,:) = si(jp_ati)%fnow(:,:,1)
+            zht_i_ini(:,:) = si(jp_hti)%fnow(:,:,1) * tmask(:,:,1)
+            zht_s_ini(:,:) = si(jp_hts)%fnow(:,:,1) * tmask(:,:,1)
+            zat_i_ini(:,:) = si(jp_ati)%fnow(:,:,1) * tmask(:,:,1)
 
             ! -- optional fields -- !
@@ -226,11 +226,11 @@
                &     si(jp_hld)%fnow(:,:,1) = ( rn_hld_ini_n * zswitch + rn_hld_ini_s * (1._wp - zswitch) ) * tmask(:,:,1)
             !
-            zsm_i_ini(:,:) = si(jp_smi)%fnow(:,:,1)
-            ztm_i_ini(:,:) = si(jp_tmi)%fnow(:,:,1)
-            zt_su_ini(:,:) = si(jp_tsu)%fnow(:,:,1)
-            ztm_s_ini(:,:) = si(jp_tms)%fnow(:,:,1)
-            zapnd_ini(:,:) = si(jp_apd)%fnow(:,:,1)
-            zhpnd_ini(:,:) = si(jp_hpd)%fnow(:,:,1)
-            zhlid_ini(:,:) = si(jp_hld)%fnow(:,:,1)
+            zsm_i_ini(:,:) = si(jp_smi)%fnow(:,:,1) * tmask(:,:,1)
+            ztm_i_ini(:,:) = si(jp_tmi)%fnow(:,:,1) * tmask(:,:,1)
+            zt_su_ini(:,:) = si(jp_tsu)%fnow(:,:,1) * tmask(:,:,1)
+            ztm_s_ini(:,:) = si(jp_tms)%fnow(:,:,1) * tmask(:,:,1)
+            zapnd_ini(:,:) = si(jp_apd)%fnow(:,:,1) * tmask(:,:,1)
+            zhpnd_ini(:,:) = si(jp_hpd)%fnow(:,:,1) * tmask(:,:,1)
+            zhlid_ini(:,:) = si(jp_hld)%fnow(:,:,1) * tmask(:,:,1)
             !
             ! change the switch for the following
Index: NEMO/branches/2020/r4.0-HEAD_r12713_clem_dan_fixcpl/src/NST/agrif_oce_interp.F90
===================================================================
--- NEMO/branches/2020/r4.0-HEAD_r12713_clem_dan_fixcpl/src/NST/agrif_oce_interp.F90	(revision 12815)
+++ NEMO/branches/2020/r4.0-HEAD_r12713_clem_dan_fixcpl/src/NST/agrif_oce_interp.F90	(revision 12816)
@@ -96,11 +96,11 @@
       i1 =  1   ;   i2 = nlci
       j1 =  1   ;   j2 = nlcj
-      IF( nbondj == -1 .OR. nbondj == 2 )   j1 = 2 + nbghostcells
-      IF( nbondj == +1 .OR. nbondj == 2 )   j2 = nlcj - nbghostcells - 1
-      IF( nbondi == -1 .OR. nbondi == 2 )   i1 = 2 + nbghostcells 
-      IF( nbondi == +1 .OR. nbondi == 2 )   i2 = nlci - nbghostcells - 1
+      IF( l_Northedge )   j1 = 2 + nbghostcells
+      IF( l_Southedge )   j2 = nlcj - nbghostcells - 1
+      IF( l_Westedge )    i1 = 2 + nbghostcells 
+      IF( l_Eastedge )    i2 = nlci - nbghostcells - 1
 
       ! --- West --- !
-      IF( nbondi == -1 .OR. nbondi == 2 ) THEN
+      IF( l_Westedge ) THEN
          ibdy1 = 2
          ibdy2 = 1+nbghostcells 
@@ -173,5 +173,5 @@
 
       ! --- East --- !
-      IF( nbondi ==  1 .OR. nbondi == 2 ) THEN
+      IF( l_Eastedge ) THEN
          ibdy1 = nlci-1-nbghostcells
          ibdy2 = nlci-2 
@@ -246,5 +246,5 @@
 
       ! --- South --- !
-      IF( nbondj == -1 .OR. nbondj == 2 ) THEN
+      IF ( l_Southedge ) THEN
          jbdy1 = 2
          jbdy2 = 1+nbghostcells 
@@ -318,5 +318,5 @@
 
       ! --- North --- !
-      IF( nbondj ==  1 .OR. nbondj == 2 ) THEN
+      IF( l_Northedge ) THEN
          jbdy1 = nlcj-1-nbghostcells
          jbdy2 = nlcj-2 
@@ -405,5 +405,5 @@
       IF( Agrif_Root() )   RETURN
       !
-      IF((nbondi == -1).OR.(nbondi == 2)) THEN
+      IF( l_Westedge ) THEN
          DO jj=1,jpj
             va_e(2:nbghostcells+1,jj) = vbdy_w(1:nbghostcells,jj) * hvr_e(2:nbghostcells+1,jj)
@@ -416,5 +416,5 @@
       ENDIF
       !
-      IF((nbondi == 1).OR.(nbondi == 2)) THEN
+      IF( l_Eastedge ) THEN
          DO jj=1,jpj
             va_e(nlci-nbghostcells:nlci-1,jj)   = vbdy_e(1:nbghostcells,jj) * hvr_e(nlci-nbghostcells:nlci-1,jj)
@@ -427,5 +427,5 @@
       ENDIF
       !
-      IF((nbondj == -1).OR.(nbondj == 2)) THEN
+      IF ( l_Southedge ) THEN
          DO ji=1,jpi
             ua_e(ji,2:nbghostcells+1) = ubdy_s(ji,1:nbghostcells) * hur_e(ji,2:nbghostcells+1)
@@ -438,5 +438,5 @@
       ENDIF
       !
-      IF((nbondj == 1).OR.(nbondj == 2)) THEN
+      IF ( l_Northedge ) THEN
          DO ji=1,jpi
             ua_e(ji,nlcj-nbghostcells:nlcj-1)   = ubdy_n(ji,1:nbghostcells) * hur_e(ji,nlcj-nbghostcells:nlcj-1)
@@ -516,5 +516,5 @@
       !
       ! --- West --- !
-      IF((nbondi == -1).OR.(nbondi == 2)) THEN
+      IF( l_Westedge ) THEN
          indx = 1+nbghostcells
          DO jj = 1, jpj
@@ -526,5 +526,5 @@
       !
       ! --- East --- !
-      IF((nbondi == 1).OR.(nbondi == 2)) THEN
+      IF( l_Eastedge ) THEN
          indx = nlci-nbghostcells
          DO jj = 1, jpj
@@ -536,5 +536,5 @@
       !
       ! --- South --- !
-      IF((nbondj == -1).OR.(nbondj == 2)) THEN
+      IF ( l_Southedge ) THEN
          indy = 1+nbghostcells
          DO jj = 2, indy
@@ -546,5 +546,5 @@
       !
       ! --- North --- !
-      IF((nbondj == 1).OR.(nbondj == 2)) THEN
+      IF ( l_Northedge ) THEN
          indy = nlcj-nbghostcells
          DO jj = indy, nlcj-1
@@ -571,5 +571,5 @@
       !
       ! --- West --- !
-      IF((nbondi == -1).OR.(nbondi == 2)) THEN
+      IF( l_Westedge ) THEN
          indx = 1+nbghostcells
          DO jj = 1, jpj
@@ -581,5 +581,5 @@
       !
       ! --- East --- !
-      IF((nbondi == 1).OR.(nbondi == 2)) THEN
+      IF( l_Eastedge ) THEN
          indx = nlci-nbghostcells
          DO jj = 1, jpj
@@ -591,5 +591,5 @@
       !
       ! --- South --- !
-      IF((nbondj == -1).OR.(nbondj == 2)) THEN
+      IF( l_Southedge ) THEN
          indy = 1+nbghostcells
          DO jj = 2, indy
@@ -601,5 +601,5 @@
       !
       ! --- North --- !
-      IF((nbondj == 1).OR.(nbondj == 2)) THEN
+      IF( l_Northedge ) THEN
          indy = nlcj-nbghostcells
          DO jj = indy, nlcj-1
@@ -722,8 +722,8 @@
             ! 
             ! Remove CORNERS
-            IF((nbondj == -1).OR.(nbondj == 2)) jmin = 2 + nbghostcells
-            IF((nbondj == +1).OR.(nbondj == 2)) jmax = nlcj - nbghostcells - 1
-            IF((nbondi == -1).OR.(nbondi == 2)) imin = 2 + nbghostcells
-            IF((nbondi == +1).OR.(nbondi == 2)) imax = nlci - nbghostcells - 1      
+            IF( l_Southedge ) jmin = 2 + nbghostcells
+            IF( l_Northedge ) jmax = nlcj - nbghostcells - 1
+            IF( l_Westedge )  imin = 2 + nbghostcells
+            IF( l_Eastedge )  imax = nlci - nbghostcells - 1      
             !
             IF( eastern_side ) THEN
Index: NEMO/branches/2020/r4.0-HEAD_r12713_clem_dan_fixcpl/src/NST/agrif_oce_sponge.F90
===================================================================
--- NEMO/branches/2020/r4.0-HEAD_r12713_clem_dan_fixcpl/src/NST/agrif_oce_sponge.F90	(revision 12815)
+++ NEMO/branches/2020/r4.0-HEAD_r12713_clem_dan_fixcpl/src/NST/agrif_oce_sponge.F90	(revision 12816)
@@ -109,5 +109,5 @@
 
          ! --- West --- !
-         IF( (nbondi == -1) .OR. (nbondi == 2) ) THEN
+         IF( l_Westedge ) THEN
             ind1 = 1+nbghostcells
             ind2 = 1+nbghostcells + ispongearea 
@@ -120,5 +120,5 @@
 
          ! --- East --- !
-         IF( (nbondi == 1) .OR. (nbondi == 2) ) THEN
+         IF( l_Eastedge ) THEN
             ind1 = nlci - nbghostcells - ispongearea
             ind2 = nlci - nbghostcells
@@ -131,5 +131,5 @@
 
          ! --- South --- !
-         IF( (nbondj == -1) .OR. (nbondj == 2) ) THEN
+         IF( l_Southedge ) THEN
             ind1 = 1+nbghostcells
             ind2 = 1+nbghostcells + ispongearea
@@ -142,5 +142,5 @@
 
          ! --- North --- !
-         IF( (nbondj == 1) .OR. (nbondj == 2) ) THEN
+         IF( l_Northedge ) THEN
             ind1 = nlcj - nbghostcells - ispongearea
             ind2 = nlcj - nbghostcells
@@ -454,5 +454,5 @@
 
          jmax = j2-1
-         IF ((nbondj == 1).OR.(nbondj == 2)) jmax = MIN(jmax,nlcj-nbghostcells-2)   ! North
+         IF ( l_Northedge ) jmax = MIN(jmax,nlcj-nbghostcells-2)   ! North
 
          DO jj = j1+1, jmax
@@ -580,5 +580,5 @@
 
          imax = i2 - 1
-         IF ((nbondi == 1).OR.(nbondi == 2))   imax = MIN(imax,nlci-nbghostcells-2)   ! East
+         IF ( l_Eastedge )   imax = MIN(imax,nlci-nbghostcells-2)   ! East
 
          DO jj = j1+1, j2
Index: NEMO/branches/2020/r4.0-HEAD_r12713_clem_dan_fixcpl/src/NST/agrif_top_interp.F90
===================================================================
--- NEMO/branches/2020/r4.0-HEAD_r12713_clem_dan_fixcpl/src/NST/agrif_top_interp.F90	(revision 12815)
+++ NEMO/branches/2020/r4.0-HEAD_r12713_clem_dan_fixcpl/src/NST/agrif_top_interp.F90	(revision 12816)
@@ -136,8 +136,8 @@
             ! 
             ! Remove CORNERS
-            IF((nbondj == -1).OR.(nbondj == 2)) jmin = 2 + nbghostcells
-            IF((nbondj == +1).OR.(nbondj == 2)) jmax = nlcj - nbghostcells - 1
-            IF((nbondi == -1).OR.(nbondi == 2)) imin = 2 + nbghostcells
-            IF((nbondi == +1).OR.(nbondi == 2)) imax = nlci - nbghostcells - 1      
+            IF( l_Southedge ) jmin = 2 + nbghostcells
+            IF( l_Northedge ) jmax = nlcj - nbghostcells - 1
+            IF( l_Westedge )  imin = 2 + nbghostcells
+            IF( l_Eastedge )  imax = nlci - nbghostcells - 1      
             !
             IF( eastern_side ) THEN
Index: NEMO/branches/2020/r4.0-HEAD_r12713_clem_dan_fixcpl/src/OCE/DOM/dom_oce.F90
===================================================================
--- NEMO/branches/2020/r4.0-HEAD_r12713_clem_dan_fixcpl/src/OCE/DOM/dom_oce.F90	(revision 12815)
+++ NEMO/branches/2020/r4.0-HEAD_r12713_clem_dan_fixcpl/src/OCE/DOM/dom_oce.F90	(revision 12816)
@@ -74,4 +74,6 @@
    !                                !  = 7 bi-cyclic East-West AND North-South
    LOGICAL, PUBLIC ::   l_Iperio, l_Jperio   !   should we explicitely take care I/J periodicity 
+   LOGICAL, PUBLIC ::   l_Westedge, l_Eastedge, l_Northedge, l_Southedge ! flag to detect global domain edges
+                                                                         ! on local domain (needed for AGRIF)
 
    !                                 !  domain MPP decomposition parameters
Index: NEMO/branches/2020/r4.0-HEAD_r12713_clem_dan_fixcpl/src/OCE/DOM/dommsk.F90
===================================================================
--- NEMO/branches/2020/r4.0-HEAD_r12713_clem_dan_fixcpl/src/OCE/DOM/dommsk.F90	(revision 12815)
+++ NEMO/branches/2020/r4.0-HEAD_r12713_clem_dan_fixcpl/src/OCE/DOM/dommsk.F90	(revision 12816)
@@ -273,8 +273,8 @@
 #if defined key_agrif 
             IF( .NOT. AGRIF_Root() ) THEN 
-               IF ((nbondi ==  1).OR.(nbondi == 2)) fmask(nlci-1 , :     ,jk) = 0.e0      ! east 
-               IF ((nbondi == -1).OR.(nbondi == 2)) fmask(1      , :     ,jk) = 0.e0      ! west 
-               IF ((nbondj ==  1).OR.(nbondj == 2)) fmask(:      ,nlcj-1 ,jk) = 0.e0      ! north 
-               IF ((nbondj == -1).OR.(nbondj == 2)) fmask(:      ,1      ,jk) = 0.e0      ! south 
+               IF ( l_Eastedge )  fmask(nlci-1 , :     ,jk) = 0.e0      ! east 
+               IF ( l_Westedge )  fmask(1      , :     ,jk) = 0.e0      ! west 
+               IF ( l_Northedge ) fmask(:      ,nlcj-1 ,jk) = 0.e0      ! north 
+               IF ( l_Southedge ) fmask(:      ,1      ,jk) = 0.e0      ! south 
             ENDIF 
 #endif 
Index: NEMO/branches/2020/r4.0-HEAD_r12713_clem_dan_fixcpl/src/OCE/DYN/divhor.F90
===================================================================
--- NEMO/branches/2020/r4.0-HEAD_r12713_clem_dan_fixcpl/src/OCE/DYN/divhor.F90	(revision 12815)
+++ NEMO/branches/2020/r4.0-HEAD_r12713_clem_dan_fixcpl/src/OCE/DYN/divhor.F90	(revision 12816)
@@ -88,8 +88,8 @@
 #if defined key_agrif
       IF( .NOT. Agrif_Root() ) THEN
-         IF( nbondi == -1 .OR. nbondi == 2 )   hdivn(   2   ,  :   ,:) = 0._wp      ! west
-         IF( nbondi ==  1 .OR. nbondi == 2 )   hdivn( nlci-1,  :   ,:) = 0._wp      ! east
-         IF( nbondj == -1 .OR. nbondj == 2 )   hdivn(   :   ,  2   ,:) = 0._wp      ! south
-         IF( nbondj ==  1 .OR. nbondj == 2 )   hdivn(   :   ,nlcj-1,:) = 0._wp      ! north
+         IF( l_Westedge )   hdivn(   2   ,  :   ,:) = 0._wp      ! west
+         IF( l_Eastedge )   hdivn( nlci-1,  :   ,:) = 0._wp      ! east
+         IF( l_Southedge )  hdivn(   :   ,  2   ,:) = 0._wp      ! south
+         IF( l_Northedge )  hdivn(   :   ,nlcj-1,:) = 0._wp      ! north
       ENDIF
 #endif
Index: NEMO/branches/2020/r4.0-HEAD_r12713_clem_dan_fixcpl/src/OCE/DYN/dynldf_lap_blp.F90
===================================================================
--- NEMO/branches/2020/r4.0-HEAD_r12713_clem_dan_fixcpl/src/OCE/DYN/dynldf_lap_blp.F90	(revision 12815)
+++ NEMO/branches/2020/r4.0-HEAD_r12713_clem_dan_fixcpl/src/OCE/DYN/dynldf_lap_blp.F90	(revision 12816)
@@ -74,12 +74,9 @@
             DO ji = fs_2, jpi   ! vector opt.
                !                                      ! ahm * e3 * curl  (computed from 1 to jpim1/jpjm1)
-!!gm open question here : e3f  at before or now ?    probably now...
-!!gm note that ahmf has already been multiplied by fmask
-               zcur(ji-1,jj-1) = ahmf(ji-1,jj-1,jk) * e3f_n(ji-1,jj-1,jk) * r1_e1e2f(ji-1,jj-1)       &
+               zcur(ji-1,jj-1) = ahmf(ji-1,jj-1,jk) * e3f_n(ji-1,jj-1,jk) * r1_e1e2f(ji-1,jj-1)       &   ! ahmf already * by fmask
                   &     * (  e2v(ji  ,jj-1) * pvb(ji  ,jj-1,jk) - e2v(ji-1,jj-1) * pvb(ji-1,jj-1,jk)  &
                   &        - e1u(ji-1,jj  ) * pub(ji-1,jj  ,jk) + e1u(ji-1,jj-1) * pub(ji-1,jj-1,jk)  )
                !                                      ! ahm * div        (computed from 2 to jpi/jpj)
-!!gm note that ahmt has already been multiplied by tmask
-               zdiv(ji,jj)     = ahmt(ji,jj,jk) * r1_e1e2t(ji,jj) / e3t_b(ji,jj,jk)                                         &
+               zdiv(ji,jj)     = ahmt(ji,jj,jk) * r1_e1e2t(ji,jj) / e3t_b(ji,jj,jk)                   &   ! ahmt already * by tmask
                   &     * (  e2u(ji,jj)*e3u_b(ji,jj,jk) * pub(ji,jj,jk) - e2u(ji-1,jj)*e3u_b(ji-1,jj,jk) * pub(ji-1,jj,jk)  &
                   &        + e1v(ji,jj)*e3v_b(ji,jj,jk) * pvb(ji,jj,jk) - e1v(ji,jj-1)*e3v_b(ji,jj-1,jk) * pvb(ji,jj-1,jk)  )
@@ -89,9 +86,9 @@
          DO jj = 2, jpjm1                             ! - curl( curl) + grad( div )
             DO ji = fs_2, fs_jpim1   ! vector opt.
-               pua(ji,jj,jk) = pua(ji,jj,jk) + zsign * (                                                 &
+               pua(ji,jj,jk) = pua(ji,jj,jk) + zsign * umask(ji,jj,jk) * (       &    ! * by umask is mandatory for dyn_ldf_blp use
                   &              - ( zcur(ji  ,jj) - zcur(ji,jj-1) ) * r1_e2u(ji,jj) / e3u_n(ji,jj,jk)   &
                   &              + ( zdiv(ji+1,jj) - zdiv(ji,jj  ) ) * r1_e1u(ji,jj)                     )
                   !
-               pva(ji,jj,jk) = pva(ji,jj,jk) + zsign * (                                                 &
+               pva(ji,jj,jk) = pva(ji,jj,jk) + zsign * vmask(ji,jj,jk) * (       &    ! * by vmask is mandatory for dyn_ldf_blp use
                   &                ( zcur(ji,jj  ) - zcur(ji-1,jj) ) * r1_e1v(ji,jj) / e3v_n(ji,jj,jk)   &
                   &              + ( zdiv(ji,jj+1) - zdiv(ji  ,jj) ) * r1_e2v(ji,jj)                     )
Index: NEMO/branches/2020/r4.0-HEAD_r12713_clem_dan_fixcpl/src/OCE/DYN/dynspg_ts.F90
===================================================================
--- NEMO/branches/2020/r4.0-HEAD_r12713_clem_dan_fixcpl/src/OCE/DYN/dynspg_ts.F90	(revision 12815)
+++ NEMO/branches/2020/r4.0-HEAD_r12713_clem_dan_fixcpl/src/OCE/DYN/dynspg_ts.F90	(revision 12816)
@@ -487,5 +487,5 @@
          ! Set fluxes during predictor step to ensure volume conservation
          IF( .NOT.Agrif_Root() .AND. ln_bt_fw ) THEN
-            IF((nbondi == -1).OR.(nbondi == 2)) THEN
+            IF( l_Westedge ) THEN
                DO jj = 1, jpj
                   zhU(2:nbghostcells+1,jj) = ubdy_w(1:nbghostcells,jj) * e2u(2:nbghostcells+1,jj)
@@ -493,5 +493,5 @@
                END DO
             ENDIF
-            IF((nbondi ==  1).OR.(nbondi == 2)) THEN
+            IF( l_Eastedge ) THEN
                DO jj=1,jpj
                   zhU(nlci-nbghostcells-1:nlci-2,jj) = ubdy_e(1:nbghostcells,jj) * e2u(nlci-nbghostcells-1:nlci-2,jj)
@@ -499,5 +499,5 @@
                END DO
             ENDIF
-            IF((nbondj == -1).OR.(nbondj == 2)) THEN
+            IF( l_Southedge ) THEN
                DO ji=1,jpi
                   zhV(ji,2:nbghostcells+1) = vbdy_s(ji,1:nbghostcells) * e1v(ji,2:nbghostcells+1)
@@ -505,5 +505,5 @@
                END DO
             ENDIF
-            IF((nbondj ==  1).OR.(nbondj == 2)) THEN
+            IF( l_Northedge ) THEN
                DO ji=1,jpi
                   zhV(ji,nlcj-nbghostcells-1:nlcj-2) = vbdy_n(ji,1:nbghostcells) * e1v(ji,nlcj-nbghostcells-1:nlcj-2)
Index: NEMO/branches/2020/r4.0-HEAD_r12713_clem_dan_fixcpl/src/OCE/DYN/dynvor.F90
===================================================================
--- NEMO/branches/2020/r4.0-HEAD_r12713_clem_dan_fixcpl/src/OCE/DYN/dynvor.F90	(revision 12815)
+++ NEMO/branches/2020/r4.0-HEAD_r12713_clem_dan_fixcpl/src/OCE/DYN/dynvor.F90	(revision 12816)
@@ -881,5 +881,5 @@
                DO ji = 1, jpim1
                   IF(    tmask(ji,jj+1,jk) + tmask(ji+1,jj+1,jk)              &
-                     & + tmask(ji,jj  ,jk) + tmask(ji+1,jj+1,jk) == 3._wp )   fmask(ji,jj,jk) = 1._wp
+                     & + tmask(ji,jj  ,jk) + tmask(ji+1,jj  ,jk) == 3._wp )   fmask(ji,jj,jk) = 1._wp
                END DO
             END DO
Index: NEMO/branches/2020/r4.0-HEAD_r12713_clem_dan_fixcpl/src/OCE/DYN/sshwzv.F90
===================================================================
--- NEMO/branches/2020/r4.0-HEAD_r12713_clem_dan_fixcpl/src/OCE/DYN/sshwzv.F90	(revision 12815)
+++ NEMO/branches/2020/r4.0-HEAD_r12713_clem_dan_fixcpl/src/OCE/DYN/sshwzv.F90	(revision 12816)
@@ -203,8 +203,8 @@
 #if defined key_agrif 
       IF( .NOT. AGRIF_Root() ) THEN 
-         IF ((nbondi ==  1).OR.(nbondi == 2)) wn(nlci-1 , :     ,:) = 0.e0      ! east 
-         IF ((nbondi == -1).OR.(nbondi == 2)) wn(2      , :     ,:) = 0.e0      ! west 
-         IF ((nbondj ==  1).OR.(nbondj == 2)) wn(:      ,nlcj-1 ,:) = 0.e0      ! north 
-         IF ((nbondj == -1).OR.(nbondj == 2)) wn(:      ,2      ,:) = 0.e0      ! south 
+         IF ( l_Eastedge )  wn(nlci-1 , :     ,:) = 0.e0      ! east 
+         IF ( l_Westedge )  wn(2      , :     ,:) = 0.e0      ! west 
+         IF ( l_Northedge ) wn(:      ,nlcj-1 ,:) = 0.e0      ! north 
+         IF ( l_Southedge ) wn(:      ,2      ,:) = 0.e0      ! south 
       ENDIF 
 #endif 
Index: NEMO/branches/2020/r4.0-HEAD_r12713_clem_dan_fixcpl/src/OCE/LBC/mppini.F90
===================================================================
--- NEMO/branches/2020/r4.0-HEAD_r12713_clem_dan_fixcpl/src/OCE/LBC/mppini.F90	(revision 12815)
+++ NEMO/branches/2020/r4.0-HEAD_r12713_clem_dan_fixcpl/src/OCE/LBC/mppini.F90	(revision 12816)
@@ -90,4 +90,7 @@
       l_Jperio = jpnj == 1 .AND. (jperio == 2 .OR. jperio == 7)
       !
+      ! Set flags to detect global domain edges for AGRIF
+      l_Westedge = .true. ; l_Eastedge = .true. ; l_Northedge = .true.; l_Southedge = .true.
+      !
       IF(lwp) THEN
          WRITE(numout,*)
@@ -162,4 +165,5 @@
       INTEGER, ALLOCATABLE, DIMENSION(:,:) ::   ilej, ildj, ioso, iowe         !  -     -
       LOGICAL, ALLOCATABLE, DIMENSION(:,:) ::   llisoce                        !  -     -
+      LOGICAL, ALLOCATABLE, DIMENSION(:,:) ::   lliswest, lliseast, llisnorth, llissouth  !  -     -
       NAMELIST/nambdy/ ln_bdy, nb_bdy, ln_coords_file, cn_coords_file,           &
            &             ln_mask_file, cn_mask_file, cn_dyn2d, nn_dyn2d_dta,     &
@@ -331,4 +335,8 @@
          &       ilei(jpni,jpnj), ildi(jpni,jpnj), iono(jpni,jpnj), ioea(jpni,jpnj),   &
          &       ilej(jpni,jpnj), ildj(jpni,jpnj), ioso(jpni,jpnj), iowe(jpni,jpnj),   &
+#if defined key_agrif
+                 lliswest(jpni,jpnj), lliseast(jpni,jpnj),  & 
+         &       llisnorth(jpni,jpnj),llissouth(jpni,jpnj), &
+#endif
          &       STAT=ierr )
       CALL mpp_sum( 'mppini', ierr )
@@ -343,4 +351,5 @@
          IF( ln_use_jattr )   CALL ctl_stop( 'STOP', 'mpp_init:Agrif children requires ln_use_jattr = .false. ' )
       ENDIF
+      lliswest(:,:) = .false. ; lliseast(:,:) = .false. ; llisnorth(:,:) = .false. ; llissouth(:,:) = .false.
 #endif
       !
@@ -430,6 +439,11 @@
          ENDIF
          !
+#if defined key_agrif
+         IF ((ibondi(ii,ij) ==  1).OR.(ibondi(ii,ij) == 2)) lliseast(ii,ij)  = .true.      ! east 
+         IF ((ibondi(ii,ij) == -1).OR.(ibondi(ii,ij) == 2)) lliswest(ii,ij)  = .true.      ! west 
+         IF ((ibondj(ii,ij) ==  1).OR.(ibondj(ii,ij) == 2)) llisnorth(ii,ij) = .true.      ! north 
+         IF ((ibondj(ii,ij) == -1).OR.(ibondj(ii,ij) == 2)) llissouth(ii,ij) = .true.      ! south 
+#endif
       END DO
-
       ! 4. deal with land subdomains
       ! ----------------------------
@@ -601,4 +615,8 @@
       ! Suppress once vertical online interpolation is ok
 !!$      IF(.NOT.Agrif_Root())   jpkglo = Agrif_Parent( jpkglo )
+      l_Westedge  = lliswest(ii,ij)
+      l_Eastedge  = lliseast(ii,ij)
+      l_Northedge = llisnorth(ii,ij)
+      l_Southedge = llissouth(ii,ij) 
 #endif
       jpim1 = jpi-1                                            ! inner domain indices
@@ -716,4 +734,7 @@
          &       ilci, ilcj, ilei, ilej, ildi, ildj,              &
          &       iono, ioea, ioso, iowe, llisoce)
+#if defined key_agrif
+      DEALLOCATE(lliswest, lliseast, llisnorth, llissouth)
+#endif
       !
     END SUBROUTINE mpp_init
Index: NEMO/branches/2020/r4.0-HEAD_r12713_clem_dan_fixcpl/src/OCE/SBC/sbcwave.F90
===================================================================
--- NEMO/branches/2020/r4.0-HEAD_r12713_clem_dan_fixcpl/src/OCE/SBC/sbcwave.F90	(revision 12815)
+++ NEMO/branches/2020/r4.0-HEAD_r12713_clem_dan_fixcpl/src/OCE/SBC/sbcwave.F90	(revision 12816)
@@ -233,8 +233,8 @@
 #if defined key_agrif
       IF( .NOT. Agrif_Root() ) THEN
-         IF( nbondi == -1 .OR. nbondi == 2 )   ze3divh( 2:nbghostcells+1,:        ,:) = 0._wp      ! west
-         IF( nbondi ==  1 .OR. nbondi == 2 )   ze3divh( nlci-nbghostcells:nlci-1,:,:) = 0._wp      ! east
-         IF( nbondj == -1 .OR. nbondj == 2 )   ze3divh( :,2:nbghostcells+1        ,:) = 0._wp      ! south
-         IF( nbondj ==  1 .OR. nbondj == 2 )   ze3divh( :,nlcj-nbghostcells:nlcj-1,:) = 0._wp      ! north
+         IF( l_Westedge )    ze3divh( 2:nbghostcells+1,:        ,:) = 0._wp      ! west
+         IF( l_Eastedge )    ze3divh( nlci-nbghostcells:nlci-1,:,:) = 0._wp      ! east
+         IF( l_Southedge )   ze3divh( :,2:nbghostcells+1        ,:) = 0._wp      ! south
+         IF( l_Northedge )   ze3divh( :,nlcj-nbghostcells:nlcj-1,:) = 0._wp      ! north
       ENDIF
 #endif
