Index: /trunk/LMDZ.MARS/changelog.txt
===================================================================
--- /trunk/LMDZ.MARS/changelog.txt	(revision 3218)
+++ /trunk/LMDZ.MARS/changelog.txt	(revision 3219)
@@ -4496,2 +4496,6 @@
 == 13/02/2024 == EM
 Move "Martian nogcm" from common dynamics to Mars dynamics-physics interface.
+
+== 16/02/2024 == LL
+Small correction for the surface layer scheme: the value of the critical Richardson varys if one used the classic yamada scheme (0.2 in this case) or can be a tunning parameter if one uses the atke scheme
+Also add the possibily to write the tke in the diagfi.nc when calling pbl_parameter
Index: /trunk/LMDZ.MARS/libf/phymars/pbl_parameters_mod.F90
===================================================================
--- /trunk/LMDZ.MARS/libf/phymars/pbl_parameters_mod.F90	(revision 3218)
+++ /trunk/LMDZ.MARS/libf/phymars/pbl_parameters_mod.F90	(revision 3219)
@@ -19,5 +19,5 @@
 CONTAINS
 
-      SUBROUTINE pbl_parameters(ngrid,nlay,ps,pplay,pz0,pg,zzlay,zzlev,pu,pv,wstar_in,hfmax,zmax,pts,ph,z_out,n_out, & 
+      SUBROUTINE pbl_parameters(ngrid,nlay,ps,pplay,pz0,pg,zzlay,zzlev,pu,pv,wstar_in,hfmax,zmax,tke,pts,ph,z_out,n_out, & 
                                 T_out,u_out,ustar,tstar,vhf,vvv)
                                 
@@ -25,5 +25,5 @@
       use write_output_mod, only: write_output
       use turb_mod, only: turb_resolved
-      use lmdz_atke_turbulence_ini, only : smmin, cinf, cepsilon, pr_slope, pr_asym, pr_neut, ri0, ri1, cn, rpi
+      use lmdz_atke_turbulence_ini, only : smmin, ric, cinf, cepsilon, pr_slope, pr_asym, pr_neut, ri0, ri1, cn, rpi
 
       IMPLICIT NONE
@@ -57,4 +57,5 @@
 !     hfmax(ngrid)        maximum vertical turbulent heat flux in thermals (W/m^2)
 !     zmax(ngrid)         height reached by the thermals (pbl height) (m)
+!     tke(ngrid,nlay+1)   turbulent kinetic energy (J/kg)
 !     pts(ngrid)          surface temperature (K)
 !     ph(ngrid,nlay)      potential temperature T*(p/ps)^kappa (k)
@@ -88,4 +89,5 @@
       REAL, INTENT(IN) :: pu(ngrid,nlay),pv(ngrid,nlay)             ! winds
       REAL, INTENT(IN) :: wstar_in(ngrid),hfmax(ngrid),zmax(ngrid)  ! free convection velocity , vertical turbulent heat, pbl height
+      REAL, INTENT(IN) :: tke(ngrid,nlay+1)                         ! Turbulent kinetic energy 
       REAL, INTENT(IN) :: pts(ngrid),ph(ngrid,nlay)                 ! surface temperature, potentiel temperature
       REAL, INTENT(IN) :: z_out(n_out)                              ! altitudes of the interpolation in the surface layer
@@ -123,5 +125,5 @@
       REAL cdn(ngrid),chn(ngrid)                                    ! neutral momentum and heat drag coefficient (1)
       REAL pz0t                                                     ! initial thermal roughness length z0t for the iterative scheme (m)
-      REAL ric                                                      ! critical richardson number (1)
+      REAL ric_colaitis                                             ! critical richardson number (1)
       REAL reynolds(ngrid)                                          ! Reynolds number (1)
       REAL prandtl(ngrid)                                           ! Prandtl number  (1)
@@ -139,5 +141,5 @@
       REAL sm                                                       ! Stability function computed with the ATKE scheme
       REAL f_ri_cd_min                                              ! minimum of the stability function with the ATKE scheme
-
+      REAL ric_4interp                                              ! critical richardson number which is either the one from Colaitis et al. (2013) or ATKE (1)
 !    Code:
 !    --------
@@ -173,6 +175,12 @@
       betah = 5.         
       lambda = (sqrt(bh/bm))/alphah
-      
-      ric = betah/(betam**2)
+      ric_colaitis = betah/(betam**2)
+      
+      if(callatke) then
+         ric_4interp = ric
+      else
+         ric_4interp = ric_colaitis
+      endif
+      
       
       DO ig=1,ngrid
@@ -195,5 +203,5 @@
                print*,'warning, infinite Richardson at surface'
                print*,pu(ig,1),pv(ig,1)
-               rib(ig) = ric
+               rib(ig) = ric_colaitis
             ENDIF
 
@@ -221,8 +229,8 @@
                    ! STABLE BOUNDARY LAYER :
                    prandtl(ig) = 1.
-                   IF(rib(ig) .lt. ric) THEN
+                   IF(rib(ig) .lt. ric_colaitis) THEN
                       ! Assuming alphah=1. and bh=bm for stable conditions :
-                      fm(ig) = ((ric-rib(ig))/ric)**2
-                      fh(ig) = ((ric-rib(ig))/ric)**2
+                      fm(ig) = ((ric_colaitis-rib(ig))/ric_colaitis)**2
+                      fh(ig) = ((ric_colaitis-rib(ig))/ric_colaitis)**2
                    ELSE
                       ! For Ri>Ric, we consider Ri->Infinity => no turbulent mixing at surface
@@ -259,5 +267,5 @@
          zout = z_out(n)
          DO ig=1,ngrid
-            IF (rib(ig) .ge. ric) THEN !stable case, no turbulence
+            IF (rib(ig) .ge. ric_4interp) THEN !stable case, no turbulence
                ustar(ig) = 0.
                tstar(ig) = 0.
@@ -275,5 +283,5 @@
                 u_out(ig,n) = 0.
             ELSE
-               IF (rib(ig) .ge. ric) THEN ! ustar=tstar=0  (and fm=fh=0) because no turbulence
+               IF (rib(ig) .ge. ric_4interp) THEN ! ustar=tstar=0  (and fm=fh=0) because no turbulence
                   u_out(ig,n) = 0
                   Teta_out(ig,n) = pts(ig)
@@ -346,4 +354,5 @@
 
 #ifndef MESOSCALE
+            call write_output('tke_pbl','Tke in the pbl after physic','J/kg',tke(:,:))
             call write_output('rib_pbl','Richardson in pbl parameter','m/s',rib(:))
             call write_output('cdn_pbl','neutral momentum coef','m/s',cdn(:))
Index: /trunk/LMDZ.MARS/libf/phymars/physiq_mod.F
===================================================================
--- /trunk/LMDZ.MARS/libf/phymars/physiq_mod.F	(revision 3218)
+++ /trunk/LMDZ.MARS/libf/phymars/physiq_mod.F	(revision 3219)
@@ -2581,5 +2581,5 @@
 
            call pbl_parameters(ngrid,nlayer,ps,zplay,z0,
-     & g,zzlay,zzlev,zu,zv,wstar,hfmax_th,zmax_th,tsurf(:,iflat),
+     & g,zzlay,zzlev,zu,zv,wstar,hfmax_th,zmax_th,q2,tsurf(:,iflat),
      & zh,z_out,n_out,T_out,u_out,ustar,tstar,vhf,vvv)
                    ! pourquoi ustar recalcule ici? fait dans vdifc.
Index: /trunk/LMDZ.MARS/libf/phymars/vdif_cd_mod.F90
===================================================================
--- /trunk/LMDZ.MARS/libf/phymars/vdif_cd_mod.F90	(revision 3218)
+++ /trunk/LMDZ.MARS/libf/phymars/vdif_cd_mod.F90	(revision 3219)
@@ -1,3 +1,3 @@
- MODULE vdif_cd_mod
+MODULE vdif_cd_mod
  
 !======================================================================================================================!
@@ -21,5 +21,5 @@
    use turb_mod, only: turb_resolved
    use watersat_mod, only: watersat
-   use lmdz_atke_turbulence_ini, only : smmin, cinf, cepsilon, pr_slope, pr_asym, pr_neut, ri0, ri1, cn, rpi
+   use lmdz_atke_turbulence_ini, only : smmin, ric, cinf, cepsilon, pr_slope, pr_asym, pr_neut, ri0, ri1, cn, rpi
    
    IMPLICIT NONE
@@ -112,5 +112,5 @@
 
       REAL pz0t                  ! initial thermal roughness length z0t for the iterative scheme (m)
-      REAL ric                   ! critical richardson number (1)
+      REAL ric_colaitis          ! critical richardson number (1)
       REAL reynolds(ngrid)       ! Reynolds number (1)
       REAL prandtl(ngrid)        ! Prandtl number  (1)
@@ -160,5 +160,5 @@
       lambda = (sqrt(bh/bm))/alphah
       
-      ric = betah/(betam**2)
+      ric_colaitis = betah/(betam**2)
       
       IF(virtual) then
@@ -214,5 +214,5 @@
                       print*,'warning, infinite Richardson at surface'
                       print*,pu(ig,1),pv(ig,1)
-                      rib(ig) = ric         
+                      rib(ig) = ric_colaitis         
                    ENDIF
         
@@ -240,8 +240,8 @@
                         ! STABLE BOUNDARY LAYER :
                         prandtl(ig) = 1.
-                        IF(rib(ig) .lt. ric) THEN
+                        IF(rib(ig) .lt. ric_colaitis) THEN
                ! Assuming alphah=1. and bh=bm for stable conditions :
-                           fm(ig) = ((ric-rib(ig))/ric)**2
-                           fh(ig) = ((ric-rib(ig))/ric)**2
+                           fm(ig) = ((ric_colaitis-rib(ig))/ric_colaitis)**2
+                           fh(ig) = ((ric_colaitis-rib(ig))/ric_colaitis)**2
                         ELSE
                ! For Ri>Ric, we consider Ri->Infinity => no turbulent mixing at surface
@@ -284,4 +284,6 @@
       
       
+      
+      
        
 
