From 9007e90d8796a8c91c2fa012e1f5fe321a119174 Mon Sep 17 00:00:00 2001
From: Christine Lac <christine.lac@meteo.fr>
Date: Fri, 12 May 2017 14:16:41 +0200
Subject: [PATCH] Maud:avoid negative values for SVS

---
 src/MNH/turb_ver_sv_flux.f90 | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/src/MNH/turb_ver_sv_flux.f90 b/src/MNH/turb_ver_sv_flux.f90
index c3ec5d032..35aef367a 100644
--- a/src/MNH/turb_ver_sv_flux.f90
+++ b/src/MNH/turb_ver_sv_flux.f90
@@ -267,6 +267,9 @@ END MODULE MODI_TURB_VER_SV_FLUX
 !!                                              change of YCOMMENT
 !!                     Feb 2012(Y. Seity) add possibility to run with reversed 
 !!                                              vertical levels
+!!                     Feb 2017(M. Leriche) add initialisation of ZSOURCE
+!!                                   to avoid unknwon values outside physical domain
+!!                                   and avoid negative values in sv tendencies
 !!--------------------------------------------------------------------------
 !       
 !*      0. DECLARATIONS
@@ -277,7 +280,7 @@ USE MODD_CTURB
 USE MODD_PARAMETERS
 USE MODD_LES
 USE MODD_CONF
-USE MODD_NSV, ONLY : NSV_LGBEG,NSV_LGEND
+USE MODD_NSV, ONLY : XSVMIN,NSV_LGBEG,NSV_LGEND
 !
 USE MODI_GRADIENT_U
 USE MODI_GRADIENT_V
@@ -397,6 +400,7 @@ DO JSV=1,ISV
   ZA(:,:,:)    = -PTSTEP*XCHF*PPSI_SV(:,:,:,JSV) *   &
                  ZKEFF * MZM(KKA,KKU,KKL,PRHODJ) /   &
                  PDZZ**2
+  ZSOURCE(:,:,:) = 0.
 !
 ! Compute the sources for the JSVth scalar variable
 
@@ -421,8 +425,8 @@ DO JSV=1,ISV
   CALL TRIDIAG(KKA,KKU,KKL,PSVM(:,:,:,JSV),ZA,PTSTEP,PEXPL,PIMPL,PRHODJ,ZSOURCE,ZRES)
 !
 !  Compute the equivalent tendency for the JSV scalar variable
-  PRSVS(:,:,:,JSV)= PRSVS(:,:,:,JSV)+    &
-                    PRHODJ(:,:,:)*(ZRES(:,:,:)-PSVM(:,:,:,JSV))/PTSTEP
+  PRSVS(:,:,:,JSV)= MAX((PRSVS(:,:,:,JSV)+    &
+                    PRHODJ(:,:,:)*(ZRES(:,:,:)-PSVM(:,:,:,JSV))/PTSTEP),XSVMIN(JSV))
 !
   IF ( (OTURB_FLX .AND. OCLOSE_OUT) .OR. LLES_CALL ) THEN
     ! Diagnostic of the cartesian vertical flux
-- 
GitLab