From 2270989ed3a4b6f8c3116b7cf27219810ddf6ce4 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Beno=C3=AEt=20Vi=C3=A9?= <benoit.vie@meteo.fr>
Date: Mon, 22 Aug 2022 09:38:10 +0200
Subject: [PATCH] bugfix budgets & snow self collection test

---
 src/MNH/ini_budget.f90                | 18 ++++++++++++++----
 src/MNH/lima_snow_self_collection.f90 | 22 ++++++++++++----------
 src/MNH/lima_tendencies.f90           |  2 +-
 src/MNH/modd_budget.f90               |  2 +-
 4 files changed, 28 insertions(+), 16 deletions(-)

diff --git a/src/MNH/ini_budget.f90 b/src/MNH/ini_budget.f90
index e608329df..e446214f0 100644
--- a/src/MNH/ini_budget.f90
+++ b/src/MNH/ini_budget.f90
@@ -1220,7 +1220,8 @@ if ( lbu_rth ) then
   tzsource%clongname  = 'wet growth of hail'
   tzsource%lavailable =      ( hcloud == 'LIMA' .and. .not.lptsplit .and. lhail_lima .and. lcold_lima &
                                                 .and. lwarm_lima    .and. lsnow_lima )                   &
-                        .or.   hcloud == 'ICE4'
+                        .or. ( hcloud == 'LIMA' .and. lptsplit ) &
+                        .or.   hcloud == 'ICE4' 
   call Budget_source_add( tbudgets(NBUDGET_TH), tzsource )
 
   tzsource%cmnhname   = 'DRYH'
@@ -1232,6 +1233,7 @@ if ( lbu_rth ) then
   tzsource%clongname  = 'melting of hail'
   tzsource%lavailable =      ( hcloud == 'LIMA' .and. .not.lptsplit .and. lhail_lima .and. lcold_lima &
                                                 .and. lwarm_lima    .and. lsnow_lima ) &
+                        .or. ( hcloud == 'LIMA' .and. lptsplit ) &
                         .or.   hcloud == 'ICE4'
   call Budget_source_add( tbudgets(NBUDGET_TH), tzsource )
 
@@ -1833,6 +1835,7 @@ if ( tbudgets(NBUDGET_RC)%lenabled ) then
   tzsource%clongname  = 'wet growth of hail'
   tzsource%lavailable =      ( hcloud == 'LIMA' .and. .not.lptsplit .and. lhail_lima .and. lcold_lima  &
                                                 .and. lwarm_lima    .and. lsnow_lima )                 &
+                        .or. ( hcloud == 'LIMA' .and. lptsplit ) &
                         .or.   hcloud == 'ICE4'
   call Budget_source_add( tbudgets(NBUDGET_RC), tzsource )
 
@@ -2062,6 +2065,7 @@ if ( tbudgets(NBUDGET_RR)%lenabled ) then
   tzsource%clongname  = 'wet growth of hail'
   tzsource%lavailable =      ( hcloud == 'LIMA' .and. .not.lptsplit .and. lhail_lima .and. lcold_lima &
                                                 .and. lwarm_lima    .and. lsnow_lima )                &
+                        .or. ( hcloud == 'LIMA' .and. lptsplit ) &
                         .or.   hcloud == 'ICE4'
   call Budget_source_add( tbudgets(NBUDGET_RR), tzsource )
 
@@ -2074,6 +2078,7 @@ if ( tbudgets(NBUDGET_RR)%lenabled ) then
   tzsource%clongname  = 'melting of hail'
   tzsource%lavailable =       ( hcloud == 'LIMA' .and. .not.lptsplit .and. lhail_lima .and. lcold_lima &
                                                 .and. lwarm_lima    .and. lsnow_lima )                &
+                        .or. ( hcloud == 'LIMA' .and. lptsplit ) &
                          .or.   hcloud == 'ICE4'
   call Budget_source_add( tbudgets(NBUDGET_RR), tzsource )
 
@@ -2323,6 +2328,7 @@ if ( tbudgets(NBUDGET_RI)%lenabled ) then
   tzsource%clongname  = 'wet growth of hail'
   tzsource%lavailable =      ( hcloud == 'LIMA' .and. .not.lptsplit .and. lhail_lima .and. lcold_lima &
                                                 .and. lwarm_lima    .and. lsnow_lima )                &
+                        .or. ( hcloud == 'LIMA' .and. lptsplit ) &
                         .or.   hcloud == 'ICE4'
   call Budget_source_add( tbudgets(NBUDGET_RI), tzsource )
 
@@ -2529,6 +2535,7 @@ if ( tbudgets(NBUDGET_RS)%lenabled ) then
   tzsource%clongname  = 'wet growth of hail'
   tzsource%lavailable =      ( hcloud == 'LIMA' .and. .not.lptsplit .and. lhail_lima .and. lcold_lima &
                                                 .and. lwarm_lima    .and. lsnow_lima )                &
+                        .or. ( hcloud == 'LIMA' .and. lptsplit ) &
                         .or.   hcloud == 'ICE4'
   call Budget_source_add( tbudgets(NBUDGET_RS), tzsource )
 
@@ -2725,12 +2732,13 @@ if ( tbudgets(NBUDGET_RG)%lenabled ) then
   tzsource%clongname  = 'wet growth of hail'
   tzsource%lavailable =      ( hcloud == 'LIMA' .and. .not.lptsplit .and. lhail_lima .and. lcold_lima &
                                                 .and. lwarm_lima    .and. lsnow_lima )                &
+                        .or. ( hcloud == 'LIMA' .and. lptsplit ) &
                         .or.   hcloud == 'ICE4'
   call Budget_source_add( tbudgets(NBUDGET_RG), tzsource )
 
   tzsource%cmnhname   = 'COHG'
   tzsource%clongname  = 'conversion of hail to graupel'
-  tzsource%lavailable = hcloud == 'LIMA' .and. .not.lptsplit .and. lhail_lima .and. lcold_lima .and. lwarm_lima .and. lsnow_lima
+  tzsource%lavailable = hcloud == 'LIMA' .and. (lptsplit .or. (lhail_lima .and. lcold_lima .and. lwarm_lima .and. lsnow_lima) )
   call Budget_source_add( tbudgets(NBUDGET_RG), tzsource )
 
   tzsource%cmnhname   = 'HGCV'
@@ -2872,13 +2880,14 @@ if ( tbudgets(NBUDGET_RH)%lenabled ) then
   tzsource%clongname  = 'wet growth of hail'
   tzsource%lavailable =      ( hcloud == 'LIMA' .and. .not.lptsplit .and. lhail_lima .and. lcold_lima    &
                                                                     .and. lwarm_lima .and. lsnow_lima ) &
+                        .or. ( hcloud == 'LIMA' .and. lptsplit ) &
                         .or.   hcloud == 'ICE4'
   call Budget_source_add( tbudgets(NBUDGET_RH), tzsource )
 
   tzsource%cmnhname   = 'COHG'
   tzsource%clongname  = 'conversion from hail to graupel'
-  tzsource%lavailable = hcloud == 'LIMA' .and. .not.lptsplit .and. lhail_lima .and. lcold_lima &
-                                                             .and. lwarm_lima .and. lsnow_lima
+  tzsource%lavailable = hcloud == 'LIMA' .and. ( lptsplit .or. (lhail_lima .and. lcold_lima &
+                                                             .and. lwarm_lima .and. lsnow_lima) )
   call Budget_source_add( tbudgets(NBUDGET_RH), tzsource )
 
   tzsource%cmnhname   = 'HGCV'
@@ -2895,6 +2904,7 @@ if ( tbudgets(NBUDGET_RH)%lenabled ) then
   tzsource%clongname  = 'melting of hail'
   tzsource%lavailable =      ( hcloud == 'LIMA' .and. .not. lptsplit .and. lhail_lima .and. lcold_lima   &
                                                                      .and. lwarm_lima .and. lsnow_lima ) &
+                        .or. ( hcloud == 'LIMA' .and. lptsplit ) &
                         .or.   hcloud == 'ICE4'
   call Budget_source_add( tbudgets(NBUDGET_RH), tzsource )
 
diff --git a/src/MNH/lima_snow_self_collection.f90 b/src/MNH/lima_snow_self_collection.f90
index 9c499d666..ea38870b8 100644
--- a/src/MNH/lima_snow_self_collection.f90
+++ b/src/MNH/lima_snow_self_collection.f90
@@ -8,16 +8,17 @@
 !      #################################
 !
 INTERFACE
-   SUBROUTINE LIMA_SNOW_SELF_COLLECTION (LDCOMPUTE,    &
-                                         PRHODREF, PT, &
-                                         PCST, PLBDS,  &
-                                         P_CS_SSC      )
+   SUBROUTINE LIMA_SNOW_SELF_COLLECTION (LDCOMPUTE,          &
+                                         PRHODREF, PT,       &
+                                         PRST, PCST, PLBDS,  &
+                                         P_CS_SSC            )
 !
 LOGICAL, DIMENSION(:),INTENT(IN)    :: LDCOMPUTE
 !
 REAL, DIMENSION(:),   INTENT(IN)    :: PRHODREF ! Reference Exner function
 REAL, DIMENSION(:),   INTENT(IN)    :: PT       ! Temperature
 !
+REAL, DIMENSION(:),   INTENT(IN)    :: PRST    ! Snow mr at t
 REAL, DIMENSION(:),   INTENT(IN)    :: PCST    ! Snow C. at t
 REAL, DIMENSION(:),   INTENT(IN)    :: PLBDS   ! 
 !
@@ -28,10 +29,10 @@ END INTERFACE
 END MODULE MODI_LIMA_SNOW_SELF_COLLECTION
 !
 !     #############################################################
-      SUBROUTINE LIMA_SNOW_SELF_COLLECTION (LDCOMPUTE,    &
-                                            PRHODREF, PT, &
-                                            PCST, PLBDS,  &
-                                            P_CS_SSC      )
+      SUBROUTINE LIMA_SNOW_SELF_COLLECTION (LDCOMPUTE,          &
+                                            PRHODREF, PT,       &
+                                            PRST, PCST, PLBDS,  &
+                                            P_CS_SSC            )
 !     #############################################################
 !
 !!    PURPOSE
@@ -56,7 +57,7 @@ END MODULE MODI_LIMA_SNOW_SELF_COLLECTION
 !              ------------
 !
 USE MODD_CST,             ONLY : XTT
-USE MODD_PARAM_LIMA,      ONLY : XCTMIN, XCEXVT
+USE MODD_PARAM_LIMA,      ONLY : XRTMIN, XCTMIN, XCEXVT
 USE MODD_PARAM_LIMA_COLD, ONLY : NSCLBDAS, XSCINTP1S, XSCINTP2S, XKER_N_SSCS, XFNSSCS, XCOLEXSS, &
                                  XLBNSSCS1, XLBNSSCS2
 !
@@ -69,6 +70,7 @@ LOGICAL, DIMENSION(:),INTENT(IN)    :: LDCOMPUTE
 REAL, DIMENSION(:),   INTENT(IN)    :: PRHODREF ! Reference Exner function
 REAL, DIMENSION(:),   INTENT(IN)    :: PT       ! Temperature
 !
+REAL, DIMENSION(:),   INTENT(IN)    :: PRST    ! Snow mr at t
 REAL, DIMENSION(:),   INTENT(IN)    :: PCST    ! Snow C. at t
 REAL, DIMENSION(:),   INTENT(IN)    :: PLBDS   ! 
 !
@@ -96,7 +98,7 @@ P_CS_SSC(:)=0.
 ZW1(:) =0.
 ZW2(:) =0.
 !
-GSSC(:) = PCST(:)>XCTMIN(5)
+GSSC(:) = PCST(:)>XCTMIN(5) .AND. PRST(:)>XRTMIN(5)
 IGSSC = COUNT(GSSC(:))
 !
 IF( IGSSC>0 ) THEN
diff --git a/src/MNH/lima_tendencies.f90 b/src/MNH/lima_tendencies.f90
index ea5acd4c9..d8c8d18d9 100644
--- a/src/MNH/lima_tendencies.f90
+++ b/src/MNH/lima_tendencies.f90
@@ -853,7 +853,7 @@ END IF
 IF (LSNOW .AND. NMOM_S.GE.2) THEN 
    CALL LIMA_SNOW_SELF_COLLECTION (LDCOMPUTE,           & ! depends on PF
                                    PRHODREF,            &
-                                   PCST/ZPF1D(:), ZLBDS, ZLBDS3, &
+                                   ZRST(:)/ZPF1D(:), PCST/ZPF1D(:), ZLBDS, ZLBDS3, &
                                    P_CS_SSC             )
    !
    P_CS_SSC(:) = P_CS_SSC(:) * ZPF1D(:)
diff --git a/src/MNH/modd_budget.f90 b/src/MNH/modd_budget.f90
index 7442dfd3e..cf07928ba 100644
--- a/src/MNH/modd_budget.f90
+++ b/src/MNH/modd_budget.f90
@@ -60,7 +60,7 @@ implicit none
 
 public
 
-integer, parameter :: NBULISTMAXLEN   = 256
+integer, parameter :: NBULISTMAXLEN   = 128
 integer, parameter :: NBULISTMAXLINES = 50
 
 integer, parameter :: NBUDGET_RHO = 0  ! Reference number for budget of RhoJ
-- 
GitLab