Index: /NEMO/branches/2019/dev_r10973_AGRIF-01_jchanut_small_jpi_jpj/cfgs/SHARED/field_def_nemo-oce.xml
===================================================================
--- /NEMO/branches/2019/dev_r10973_AGRIF-01_jchanut_small_jpi_jpj/cfgs/SHARED/field_def_nemo-oce.xml	(revision 11548)
+++ /NEMO/branches/2019/dev_r10973_AGRIF-01_jchanut_small_jpi_jpj/cfgs/SHARED/field_def_nemo-oce.xml	(revision 11549)
@@ -27,4 +27,7 @@
         <field id="soce"         long_name="salinity"                            standard_name="sea_water_practical_salinity"      unit="1e-3"     grid_ref="grid_T_3D"/>
         <field id="soce_e3t"     long_name="salinity    (thickness weighted)"                                                      unit="1e-3"     grid_ref="grid_T_3D" > soce * e3t </field >
+
+        <!-- AGRIF sponge -->
+        <field id="fsahm_spt"    long_name=" AGRIF t-sponge viscosity coefficient"   unit="m2/s"                              />
 
         <!-- t-eddy viscosity coefficients (ldfdyn) -->
@@ -364,4 +367,8 @@
         <field id="uoces"        long_name="ocean transport along i-axis times salinity (CRS)"                                                  unit="1e-3*m/s"   grid_ref="grid_U_3D" />
 
+
+        <!-- AGRIF sponge -->
+        <field id="fsaht_spu"    long_name=" AGRIF u-sponge diffusivity coefficient"   unit="m2/s"         />
+
         <!-- u-eddy diffusivity coefficients (available if ln_traldf_OFF=F) -->
         <field id="ahtu_2d"      long_name=" surface u-eddy diffusivity coefficient"   unit="m2/s or m4/s" />
@@ -418,4 +425,7 @@
         <field id="voces"        long_name="ocean transport along j-axis times salinity (CRS)"                                                  unit="1e-3*m/s"   grid_ref="grid_V_3D" />
 
+        <!-- AGRIF sponge -->
+        <field id="fsaht_spv"    long_name=" AGRIF v-sponge diffusivity coefficient"   unit="m2/s"         />
+
         <!-- v-eddy diffusivity coefficients (available if ln_traldf_OFF=F) -->
         <field id="ahtv_2d"      long_name=" surface v-eddy diffusivity coefficient"     unit="m2/s or (m4/s)^1/2" />
@@ -496,4 +506,7 @@
       
       <!-- F grid -->
+      <!-- AGRIF sponge -->
+      <field id="fsahm_spf"    long_name=" AGRIF f-sponge viscosity coefficient"   unit="m2/s"                              />
+
       <!-- f-eddy viscosity coefficients (ldfdyn) -->
       <field id="ahmf_2d"      long_name=" surface f-eddy viscosity coefficient"   unit="m2/s or m4/s" />
Index: /NEMO/branches/2019/dev_r10973_AGRIF-01_jchanut_small_jpi_jpj/src/NST/agrif_oce_sponge.F90
===================================================================
--- /NEMO/branches/2019/dev_r10973_AGRIF-01_jchanut_small_jpi_jpj/src/NST/agrif_oce_sponge.F90	(revision 11548)
+++ /NEMO/branches/2019/dev_r10973_AGRIF-01_jchanut_small_jpi_jpj/src/NST/agrif_oce_sponge.F90	(revision 11549)
@@ -22,4 +22,5 @@
    USE agrif_oce
    USE lbclnk          ! ocean lateral boundary conditions (or mpp link)
+   USE iom
 
    IMPLICIT NONE
@@ -58,4 +59,7 @@
 #endif
       !
+      CALL iom_put("fsaht_spu", fsaht_spu(:,:))
+      CALL iom_put("fsaht_spv", fsaht_spv(:,:))
+      !
    END SUBROUTINE Agrif_Sponge_Tra
 
@@ -84,4 +88,7 @@
       Agrif_UseSpecialValue = .FALSE.
 #endif
+      !
+      CALL iom_put("fsahm_spt", fsahm_spt(:,:))
+      CALL iom_put("fsahm_spf", fsahm_spf(:,:))
       !
    END SUBROUTINE Agrif_Sponge_dyn
@@ -96,8 +103,60 @@
       REAL(wp) ::   z1_ispongearea, z1_jspongearea
       REAL(wp), DIMENSION(jpi,jpj) :: ztabramp
+      REAL(wp), DIMENSION(jpjmax)  :: zmskwest,  zmskeast
+      REAL(wp), DIMENSION(jpimax)  :: zmsknorth, zmsksouth
       !!----------------------------------------------------------------------
       !
 #if defined SPONGE || defined SPONGE_TOP
       IF (( .NOT. spongedoneT ).OR.( .NOT. spongedoneU )) THEN
+         !
+         ! Retrieve masks at open boundaries:
+
+         ! --- West --- !
+         ztabramp(:,:) = 0._wp
+         ind1 = 1+nbghostcells
+         DO ji = mi0(ind1), mi1(ind1)                
+            ztabramp(ji,:) = umask(ji,:,1)
+         END DO
+         !
+         zmskwest(:) = 0._wp
+         zmskwest(1:jpj) = MAXVAL(ztabramp(:,:), dim=1)
+
+         ! --- East --- !
+         ztabramp(:,:) = 0._wp
+         ind1 = jpiglo - nbghostcells - 1
+         DO ji = mi0(ind1), mi1(ind1)                 
+            ztabramp(ji,:) = umask(ji,:,1)
+         END DO
+         !
+         zmskeast(:) = 0._wp
+         zmskeast(1:jpj) = MAXVAL(ztabramp(:,:), dim=1)
+
+         ! --- South --- !
+         ztabramp(:,:) = 0._wp
+         ind1 = 1+nbghostcells
+         DO jj = mj0(ind1), mj1(ind1)                 
+            ztabramp(:,jj) = vmask(:,jj,1)
+         END DO
+         !
+         zmsksouth(:) = 0._wp
+         zmsksouth(1:jpi) = MAXVAL(ztabramp(:,:), dim=2)
+
+         ! --- North --- !
+         ztabramp(:,:) = 0._wp
+         ind1 = jpjglo - nbghostcells - 1
+         DO jj = mj0(ind1), mj1(ind1)                 
+            ztabramp(:,jj) = vmask(:,jj,1)
+         END DO
+         !
+         zmsknorth(:) = 0._wp
+         zmsknorth(1:jpi) = MAXVAL(ztabramp(:,:), dim=2)
+
+#if defined key_mpp_mpi
+         CALL mpp_max( 'AGRIF_sponge', zmskwest(:) , jpjmax )
+         CALL mpp_max( 'AGRIF_Sponge', zmskeast(:) , jpjmax )
+         CALL mpp_max( 'AGRIF_Sponge', zmsksouth(:), jpimax )
+         CALL mpp_max( 'AGRIF_Sponge', zmsknorth(:), jpimax )
+#endif
+
          ! Define ramp from boundaries towards domain interior at T-points
          ! Store it in ztabramp
@@ -117,5 +176,14 @@
          DO ji = mi0(ind1), mi1(ind2)   
             DO jj = 1, jpj               
-               ztabramp(ji,jj) = REAL( ind2 - mig(ji) ) * z1_ispongearea
+               ztabramp(ji,jj) = REAL( ind2 - mig(ji) ) * z1_ispongearea * zmskwest(jj)
+            END DO
+         END DO
+
+         ! ghost cells (cosmetic):
+         ind1 = 1
+         ind2 = nbghostcells
+         DO ji = mi0(ind1), mi1(ind2)   
+            DO jj = 1, jpj               
+               ztabramp(ji,jj) = zmskwest(jj)
             END DO
          END DO
@@ -126,5 +194,14 @@
          DO ji = mi0(ind1), mi1(ind2)
             DO jj = 1, jpj
-               ztabramp(ji,jj) = MAX( ztabramp(ji,jj), REAL( mig(ji) - ind1 ) * z1_ispongearea)
+               ztabramp(ji,jj) = MAX( ztabramp(ji,jj), REAL( mig(ji) - ind1 ) * z1_ispongearea) * zmskeast(jj)
+            ENDDO
+         END DO
+
+         ! ghost cells (cosmetic):
+         ind1 = jpiglo - nbghostcells + 1
+         ind2 = jpiglo
+         DO ji = mi0(ind1), mi1(ind2)
+            DO jj = 1, jpj
+               ztabramp(ji,jj) = zmskeast(jj)
             ENDDO
          END DO
@@ -135,5 +212,14 @@
          DO jj = mj0(ind1), mj1(ind2) 
             DO ji = 1, jpi
-               ztabramp(ji,jj) = MAX( ztabramp(ji,jj), REAL( ind2 - mjg(jj) ) * z1_jspongearea)
+               ztabramp(ji,jj) = MAX( ztabramp(ji,jj), REAL( ind2 - mjg(jj) ) * z1_jspongearea) * zmsksouth(ji)
+            END DO
+         END DO
+
+         ! ghost cells (cosmetic):
+         ind1 = 1
+         ind2 = nbghostcells
+         DO jj = mj0(ind1), mj1(ind2) 
+            DO ji = 1, jpi
+               ztabramp(ji,jj) = zmsksouth(ji)
             END DO
          END DO
@@ -144,5 +230,14 @@
          DO jj = mj0(ind1), mj1(ind2)
             DO ji = 1, jpi
-               ztabramp(ji,jj) = MAX( ztabramp(ji,jj), REAL( mjg(jj) - ind1 ) * z1_jspongearea)
+               ztabramp(ji,jj) = MAX( ztabramp(ji,jj), REAL( mjg(jj) - ind1 ) * z1_jspongearea) * zmsknorth(ji)
+            END DO
+         END DO
+
+         ! ghost cells (cosmetic):
+         ind1 = jpjglo - nbghostcells + 1
+         ind2 = jpjglo
+         DO jj = mj0(ind1), mj1(ind2)
+            DO ji = 1, jpi
+               ztabramp(ji,jj) = zmsknorth(ji)
             END DO
          END DO
@@ -160,6 +255,6 @@
             END DO
          END DO
-         CALL lbc_lnk( 'agrif_oce_sponge', fsaht_spu, 'U', 1. )   ! Lateral boundary conditions
-         CALL lbc_lnk( 'agrif_oce_sponge', fsaht_spv, 'V', 1. )
+         CALL lbc_lnk( 'agrif_Sponge', fsaht_spu, 'U', 1. )   ! Lateral boundary conditions
+         CALL lbc_lnk( 'agrif_Sponge', fsaht_spv, 'V', 1. )
          
          spongedoneT = .TRUE.
@@ -177,6 +272,6 @@
             END DO
          END DO
-         CALL lbc_lnk( 'agrif_oce_sponge', fsahm_spt, 'T', 1. )   ! Lateral boundary conditions
-         CALL lbc_lnk( 'agrif_oce_sponge', fsahm_spf, 'F', 1. )
+         CALL lbc_lnk( 'agrif_Sponge', fsahm_spt, 'T', 1. )   ! Lateral boundary conditions
+         CALL lbc_lnk( 'agrif_Sponge', fsahm_spf, 'F', 1. )
          
          spongedoneU = .TRUE.
