Index: NEMO/branches/2020/dev_r13787_OSMOSIS_IMMERSE/cfgs/SHARED/field_def_nemo-oce.xml
===================================================================
--- NEMO/branches/2020/dev_r13787_OSMOSIS_IMMERSE/cfgs/SHARED/field_def_nemo-oce.xml	(revision 13871)
+++ NEMO/branches/2020/dev_r13787_OSMOSIS_IMMERSE/cfgs/SHARED/field_def_nemo-oce.xml	(revision 13872)
@@ -265,41 +265,96 @@
 
       <field_group id="OSMOSIS_T" grid_ref="grid_T_2D">
+        <field id="hml"                 long_name="mixed layr depth"                         unit="m"       />
+        <field id="hbl"                 long_name="boundary layer depth"                     unit="m"       />
+        <field id="dh"                  long_name="Pycnocline thickness"                     unit=" m"      />
+        <field id="ibld"                long_name="index of boundary layer depth"            unit="#"       />
+        <field id="imld"                long_name="index of mixed layer depth"            unit="#"       />
+        <field id="zhbl"                long_name="boundary layer depth -grid"                     unit="m"       />
+        <field id="zhml"                long_name="mixed layer depth - grid"                        unit="m"       />
+        <field id="zdh"                 long_name="Pycnocline  depth - grid"                 unit=" m"      />
+        <field id="zustke"              long_name="magnitude of stokes drift  at T-points"   unit="m/s"     />
+        <field id="us_x"        long_name="i component of active Stokes drift"                      unit="m/s"     />
+        <field id="us_y"        long_name="j component of active Stokes drift"                      unit="m/s"     />
+        <field id="dstokes"             long_name="stokes drift  depth scale"                unit="m"       />
         <field id="zwth0"               long_name="surface non-local temperature flux"       unit="deg m/s" />
         <field id="zws0"                long_name="surface non-local salinity flux"          unit="psu m/s" />
-        <field id="hbl"                 long_name="boundary layer depth"                     unit="m"       />
-        <field id="hbli"                long_name="initial boundary layer depth"             unit="m"       />
-        <field id="dstokes"             long_name="stokes drift  depth scale"                unit="m"       />
-        <field id="zustke"              long_name="magnitude of stokes drift  at T-points"   unit="m/s"     />
         <field id="zwstrc"              long_name="convective velocity scale"                unit="m/s"     />
+        <field id="zustar"              long_name="friction velocity"                        unit="m/s"     />
         <field id="zwstrl"              long_name="langmuir velocity scale"                  unit="m/s"     />
-        <field id="zustar"              long_name="friction velocity"                        unit="m/s"     />
-        <field id="zhbl"                long_name="boundary layer depth"                     unit="m"       />
-        <field id="zhml"                long_name="mixed layer depth"                        unit="m"       />
+        <field id="zvstr"               long_name="mixed velocity scale"                     unit="m/s"     />
+        <field id="zla"                 long_name="langmuir number"                          unit="m/s"     />
         <field id="wind_wave_abs_power" long_name="\rho |U_s| x u*^2"                        unit="mW"      />
         <field id="wind_wave_power"     long_name="U_s \dot  tau"                            unit="mW"      />
         <field id="wind_power"          long_name="\rho  u*^3"                               unit="mW"      />
 
-        <!-- extra OSMOSIS diagnostics -->
+       <!-- interior BL OSMOSIS diagnostics -->
         <field id="zwthav"              long_name="av turb flux of T in ml"                  unit="deg m/s" />
         <field id="zt_ml"               long_name="av T in ml"                               unit="deg"     />
+        <field id="zhol"                long_name="Hoenekker number"                         unit="#"       />
+        <field id="zws_ent"            long_name="entrainment turb flux of S"                unit="10^-3 m/s" />
         <field id="zwth_ent"            long_name="entrainment turb flux of T"               unit="deg m/s" />
-        <field id="zhol"                long_name="Hoenekker number"                         unit="#"       />
-        <field id="zdh"                 long_name="Pycnocline  depth - grid"                 unit=" m"      />
-      </field_group>
-
-      <field_group id="OSMOSIS_W" grid_ref="grid_W_3D" operation="instant" >
+        <field id="zwb_ent"            long_name="entrainment turb flux of buoyancy"         unit="m^2/s^-3" />
+ 
+        <field id="zdt_bl"             long_name="temperature jump at base of BL"                 unit="deg"      />
+        <field id="zds_bl"             long_name="salinity jump at base of BL"                 unit="10^-3"      />
+        <field id="zdb_bl"             long_name="buoyancy jump at base of BL"                 unit="m/s^2"      />
+        <field id="zdu_bl"             long_name="u jump at base of BL"                       unit="m/s"      />
+        <field id="zdv_bl"             long_name="v jump at base of BL"                       unit="m/s"      />
+
+        <!-- extra OSMOSIS diagnostics for debugging -->
+       <field id="zsc_uw_1_0"       long_name="zsc u-momentum flux on T after Stokes"                       unit="m^2/s^2" />
+        <field id="zsc_uw_1_f"       long_name="zsc u-momentum flux on T after Coriolis"                       unit="m^2/s^2" />
+        <field id="zsc_vw_1_f"       long_name="zsc v-momentum flux on T after Coriolis"                       unit="m^2/s^2" />
+        <field id="zsc_uw_2_f"       long_name="2nd zsc u-momentum flux on T after Coriolis"                       unit="m^2/s^2" />
+        <field id="zsc_vw_2_f"       long_name="2nd zsc v-momentum flux on T after Coriolis"                       unit="m^2/s^2" />
+        <field id="zuw_bse"       long_name="base u-flux T-points"                          unit="m^2/s^2" />
+        <field id="zvw_bse"       long_name="base v-flux T-points"                          unit="m^2/s^2" />
+
+       <!-- FK_OSM OSMOSIS diagnostics (require also ln_osm_mle=.true.-->
+         <field id="hmle"          long_name="OBL FK-layer thickness"                                     unit="m"        />
+        <field id="mld_prof"              long_name="FK-layer depth index"                  unit="#" />
+        <field id="zmld"          long_name="target FK-layer thickness"                                     unit="m"        />
+        <field id="zwb_fk"          long_name="FK b-flux"                                     unit="m^2 s^-3"        />
+        <field id="zwb_fk_b"          long_name="layer averaged FK b-flux"                 unit="m^2 s^-3"       />
+        <field id="zdiff_mle"          long_name="max FK diffusivity in MLE"       unit=" 10^-4 m^2 s^-1"       />
+        <field id="zvel_mle"          long_name="FK velocity scale in MLE"       unit=" m s^-1"       />
+    </field_group>
+
+      <field_group id="OSMOSIS_W" grid_ref="grid_W_3D" >
+        <field id="zviscos"       long_name="BL viscosity"   unit="m^2/s" />
         <field id="ghamt"       long_name="non-local temperature flux"                       unit="deg m/s" />
         <field id="ghams"       long_name="non-local salinity flux"                          unit="psu m/s" />
         <field id="zdtdz_pyc"   long_name="Pycnocline temperature gradient"                  unit=" deg/m"  />
-      </field_group>
+        <field id="zdsdz_pyc"   long_name="Pycnocline salinity gradient"                  unit=" 10^-3/m"  />
+        <field id="zdbdz_pyc"   long_name="Pycnocline buoyancy gradient"                  unit=" s^-2"  />
+        <field id="zdudz_pyc"   long_name="Pycnocline u gradient"                  unit=" s^-2"  />
+        <field id="zdvdz_pyc"   long_name="Pycnocline v gradient"                  unit=" s^-2"  />
+
+        <!-- extra OSMOSIS diagnostics for debugging -->
+         <field id="ghamu_00"       long_name="initial non-local u-momentum flux"   unit="m^2/s^2" />
+        <field id="ghamv_00"       long_name="initial non-local v-momentum flux"   unit="m^2/s^2" />
+        <field id="ghamu_0"       long_name="after dstokes non-local u-momentum flux"   unit="m^2/s^2" />
+        <field id="ghamu_f"       long_name="after Coriolis non-local u-momentum flux"   unit="m^2/s^2" />
+        <field id="ghamv_f"       long_name="after Coriolis  non-local v-momentum flux"   unit="m^2/s^2" />
+        <field id="ghamu_b"       long_name="after buoyancy added non-local u-momentum flux"   unit="m^2/s^2" />
+        <field id="ghamv_b"       long_name="after buoyancy added  non-local v-momentum flux"  unit="m^2/s^2" />
+        <field id="ghamu_1"       long_name="after entrainment non-local u-momentum flux"   unit="m^2/s^2" />
+        <field id="ghamv_1"       long_name="after entrainment  non-local v-momentum flux"  unit="m^2/s^2" />
+     </field_group>
 
       <field_group id="OSMOSIS_U" grid_ref="grid_U_2D" >
         <field id="ghamu"       long_name="non-local u-momentum flux"   grid_ref="grid_U_3D" unit="m^2/s^2" />
-        <field id="us_x"        long_name="i component of Stokes drift"                      unit="m/s"     />
-      </field_group>
+       <!-- FK_OSM OSMOSIS diagnostics (require also ln_osm_mle=.true.-->
+       <field id="zdtdx"          long_name="FK  T x-gradient"                                     unit=" deg C m^-1"        />
+        <field id="zdsdx"          long_name="FK  S x-gradient"                                     unit=" 10^-3 m^-1"        />
+        <field id="dbdx_mle"          long_name="FK  B x-gradient"                                     unit=" s^-2"        />
+     </field_group>
 
       <field_group id="OSMOSIS_V" grid_ref="grid_V_2D" >
         <field id="ghamv"       long_name="non-local v-momentum flux"   grid_ref="grid_V_3D" unit="m^2/s^2" />
-        <field id="us_y"        long_name="j component of Stokes drift"                      unit="m/s"     />
+        <!-- FK_OSM OSMOSIS diagnostics (require also ln_osm_mle=.true.-->
+        <field id="zdtdy"          long_name="FK T y-gradient"                                     unit=" deg C m^-1"        />
+        <field id="zdsdy"          long_name="FK S y-gradient"                                     unit=" 10^-3 m^-1"        />
+        <field id="dbdy_mle"          long_name="FK B y-gradient"                                     unit=" s^-2"        />
       </field_group>
 
@@ -831,5 +886,10 @@
      <field id="strd_zdfp"     long_name="salinity   -trend: pure vert. diffusion"   unit="1e-3/s" />
 
-     <!-- -->
+     <!-- ln_zdfosm=T only (OSMOSIS-OBL) -->
+     <field id="ttrd_osm"      long_name="temperature-trend: OSM-OSBL non-local forcing"                             unit="degC/s" />
+     <field id="strd_osm"      long_name="salinity   -trend: OSM-OSBL non-local forcing"                             unit="1e-3/s" />
+
+
+    <!-- -->
      <field id="ttrd_dmp"      long_name="temperature-trend: interior restoring"        unit="degC/s" />
      <field id="strd_dmp"      long_name="salinity   -trend: interior restoring"        unit="1e-3/s" />
@@ -867,4 +927,8 @@
      <field id="strd_zdfp_e3t"     unit="1e-3/s * m"  >  strd_zdfp * e3t </field>
 
+          <!-- ln_zdfosm=T only (OSMOSIS-OBL) -->
+     <field id="ttrd_osm_e3t"      long_name="temperature-trend: OSM-OSBL non-local forcing"                             unit="degC/s * m" >  ttrd_osm * e3t </field>
+     <field id="strd_osm_e3t"      long_name="salinity   -trend: OSM-OSBL non-local forcing"                             unit="1e-3/s * m" >  strd_osm * e3t </field>
+     
      <!-- -->
      <field id="ttrd_dmp_e3t"      unit="degC/s * m"  >  ttrd_dmp * e3t </field>
@@ -882,4 +946,6 @@
      <field id="ttrd_totad_li"    long_name="layer integrated heat-trend: total advection"         unit="W/m^2"     > ttrd_totad_e3t * 1026.0 * 3991.86795711963 </field>
      <field id="strd_totad_li"    long_name="layer integrated salt-trend: total advection"         unit="kg/(m^2 s)"    > strd_totad_e3t * 1026.0 * 0.001  </field>
+     <field id="ttrd_osm_li"    long_name="layer integrated heat-trend: non-local OSM"         unit="W/m^2"     > ttrd_osm_e3t * 1026.0 * 3991.86795711963 </field>
+     <field id="strd_osm_li"    long_name="layer integrated salt-trend: non-local OSM"         unit="kg/(m^2 s)"    > strd_osm_e3t * 1026.0 * 0.001  </field>
      <field id="ttrd_evd_li"      long_name="layer integrated heat-trend: EVD convection"          unit="W/m^2"    > ttrd_evd_e3t * 1026.0 * 3991.86795711963 </field>
      <field id="strd_evd_li"      long_name="layer integrated salt-trend: EVD convection"          unit="kg/(m^2 s)"  > strd_evd_e3t * 1026.0 * 0.001  </field>
@@ -1089,4 +1155,15 @@
     </field_group>
 
+    <!-- TMB diagnostic output -->
+    <field_group  id="1h_grid_T_tmb" grid_ref="grid_T_2D" operation="instant">
+      <field id="top_temp"           name="votemper_top"  unit="degC"  />
+      <field id="mid_temp"           name="votemper_mid"  unit="degC"  />
+      <field id="bot_temp"           name="votemper_bot"  unit="degC"  />
+      <field id="top_sal"            name="vosaline_top"  unit="psu"   />
+      <field id="mid_sal"            name="vosaline_mid"  unit="psu"   />
+      <field id="bot_sal"            name="vosaline_bot"  unit="psu"   />
+      <field id="sshnmasked"         name="sossheig"      unit="m"     /> 
+    </field_group>
+
     <field_group  id="1h_grid_U_tmb" grid_ref="grid_U_2D" operation="instant">
       <field id="top_u"           name="vozocrtx_top"  unit="m/s"  />
Index: NEMO/branches/2020/dev_r13787_OSMOSIS_IMMERSE/cfgs/SHARED/namelist_ref
===================================================================
--- NEMO/branches/2020/dev_r13787_OSMOSIS_IMMERSE/cfgs/SHARED/namelist_ref	(revision 13871)
+++ NEMO/branches/2020/dev_r13787_OSMOSIS_IMMERSE/cfgs/SHARED/namelist_ref	(revision 13872)
@@ -1198,7 +1198,9 @@
 &namzdf_osm    !   OSM vertical diffusion                               (ln_zdfosm =T)
 !-----------------------------------------------------------------------
-   ln_use_osm_la = .false.      !  Use namelist  rn_osm_la
+   ln_use_osm_la = .false.     !  Use   rn_osm_la
    rn_osm_la     = 0.3         !  Turbulent Langmuir number
-   rn_osm_dstokes     = 5.     !  Depth scale of Stokes drift (m)
+   rn_zdfosm_adjust_sd = 1.0   ! Stokes drift reduction factor
+   rn_osm_hblfrac = 0.1        ! specify top part of hbl for nn_osm_wave = 3 or 4
+   rn_osm_bl_thresh   = 5.e-5      !Threshold buoyancy for deepening of OSBL base
    nn_ave = 0                  ! choice of horizontal averaging on avt, avmu, avmv
    ln_dia_osm = .true.         ! output OSMOSIS-OBL variables
@@ -1208,10 +1210,31 @@
    rn_difri  =  0.005          ! max Ri# diffusivity at Ri_g = 0 (m^2/s)
    ln_convmix  = .true.        ! Use convective instability mixing below BL
-   rn_difconv = 1.             ! diffusivity when unstable below BL  (m2/s)
+   rn_difconv = 1. !0.01 !1.             ! diffusivity when unstable below BL  (m2/s)
+   rn_osm_dstokes     = 5.     !  Depth scale of Stokes drift (m)
    nn_osm_wave = 0             ! Method used to calculate Stokes drift
       !                        !  = 2: Use ECMWF wave fields
       !                        !  = 1: Pierson Moskowitz wave spectrum
       !                        !  = 0: Constant La# = 0.3
-/
+   nn_osm_SD_reduce = 0        ! Method used to get active Stokes drift from surface value
+      !                        !  = 0: No reduction
+                               !  = 1: use SD avged over top 10% hbl
+                               !  = 2:use surface value of SD fit to slope at rn_osm_hblfrac*hbl below surface
+   ln_zdfosm_ice_shelter = .true.  ! reduce surface SD and depth scale under ice
+   ln_osm_mle = .false.        !  Use integrated FK-OSM model
+/
+!-----------------------------------------------------------------------
+&namosm_mle    !   mixed layer eddy parametrisation (Fox-Kemper)       (default: OFF)
+!-----------------------------------------------------------------------
+   rn_osm_mle_ce       = 0.06      ! magnitude of the MLE (typical value: 0.06 to 0.08)
+   nn_osm_mle          = 0         ! MLE type: =0 standard Fox-Kemper ; =1 new formulation
+   rn_osm_mle_lf       = 5.e+3     ! typical scale of mixed layer front (meters)                      (case rn_osm_mle=0)
+   rn_osm_mle_time     = 172800.   ! time scale for mixing momentum across the mixed layer (seconds)  (case rn_osm_mle=0)
+   rn_osm_mle_lat      = 20.       ! reference latitude (degrees) of MLE coef.                        (case rn_mle=1)
+   rn_osm_mle_rho_c =    0.01      ! delta rho criterion used to calculate MLD for FK
+   rn_osm_mle_thresh  = 0.0005     ! delta b criterion used for FK MLE criterion
+   rn_osm_mle_tau     = 172800.    ! time scale for FK-OSM (seconds)  (case rn_osm_mle=0)
+   ln_osm_hmle_limit   = .false.   ! limit hmle to rn_osm_hmle_limit*hbl
+   rn_osm_hmle_limit   = 1.2
+   /
 !-----------------------------------------------------------------------
 &namzdf_iwm    !    internal wave-driven mixing parameterization        (ln_zdfiwm =T)
Index: NEMO/branches/2020/dev_r13787_OSMOSIS_IMMERSE/src/OCE/ZDF/zdfphy.F90
===================================================================
--- NEMO/branches/2020/dev_r13787_OSMOSIS_IMMERSE/src/OCE/ZDF/zdfphy.F90	(revision 13871)
+++ NEMO/branches/2020/dev_r13787_OSMOSIS_IMMERSE/src/OCE/ZDF/zdfphy.F90	(revision 13872)
@@ -173,5 +173,5 @@
       IF( ln_zdfosm .AND. ln_zdfevd )   CALL ctl_stop( 'zdf_phy_init: chose between ln_zdfosm and ln_zdfevd' )
       IF( lk_top    .AND. ln_zdfnpc )   CALL ctl_stop( 'zdf_phy_init: npc scheme is not working with key_top' )
-      IF( lk_top    .AND. ln_zdfosm )   CALL ctl_stop( 'zdf_phy_init: osmosis scheme is not working with key_top' )
+      IF( lk_top    .AND. ln_zdfosm )   CALL ctl_warn( 'zdf_phy_init: osmosis gives no non-local fluxes for TOP tracers yet' )
       IF(lwp) THEN
          WRITE(numout,*)
