From 3d2bf84c3a654957a4048e9fee12ac161e0374d9 Mon Sep 17 00:00:00 2001
From: Philippe WAUTELET <philippe.wautelet@aero.obs-mip.fr>
Date: Mon, 1 Feb 2021 13:46:11 +0100
Subject: [PATCH] Philippe 01/02/2021: bugfix: add missing CEDS source terms
 for SV budgets

---
 src/MNH/ini_budget.f90  | 26 ++++++++++++++++++++++----
 src/MNH/lima_adjust.f90 | 21 +++++++++++++++++++++
 2 files changed, 43 insertions(+), 4 deletions(-)

diff --git a/src/MNH/ini_budget.f90 b/src/MNH/ini_budget.f90
index eba251b14..7d49b1451 100644
--- a/src/MNH/ini_budget.f90
+++ b/src/MNH/ini_budget.f90
@@ -6,6 +6,7 @@
 ! Modifications:
 !  P. Wautelet 17/08/2020: add Budget_preallocate subroutine
 !  P. Wautelet 11/01/2021: ignore xbuwri for cartesian boxes (write at every xbulen interval)
+!  P. Wautelet 01/02/2021: bugfix: add missing CEDS source terms for SV budgets
 !-----------------------------------------------------------------
 module mode_ini_budget
 
@@ -224,10 +225,11 @@ use modd_parameters,   only: jphext
 use modd_param_c2r2,   only: ldepoc_c2r2 => ldepoc, lrain_c2r2 => lrain, lsedc_c2r2 => lsedc, lsupsat_c2r2 => lsupsat
 use modd_param_ice,    only: ladj_after, ladj_before, ldeposc_ice => ldeposc, lred, lsedic_ice => lsedic, lwarm_ice => lwarm
 use modd_param_n,      only: cactccn, celec
-use modd_param_lima,   only: lacti_lima => lacti, lcold_lima => lcold, ldepoc_lima => ldepoc, lhail_lima => lhail, &
-                             lhhoni_lima => lhhoni, lmeyers_lima => lmeyers, lnucl_lima => lnucl, lptsplit,        &
-                             lrain_lima => lrain, lscav_lima => lscav, lsedc_lima => lsedc, lsedi_lima => lsedi,   &
-                             lsnow_lima => lsnow, lwarm_lima => lwarm,                                             &
+use modd_param_lima,   only: laero_mass_lima => laero_mass, lacti_lima => lacti, lcold_lima => lcold, ldepoc_lima => ldepoc, &
+                             lhail_lima => lhail, lhhoni_lima => lhhoni, lmeyers_lima => lmeyers, lnucl_lima => lnucl,  &
+                             lptsplit,                                                                                  &
+                             lrain_lima => lrain, lscav_lima => lscav, lsedc_lima => lsedc, lsedi_lima => lsedi,        &
+                             lsnow_lima => lsnow, lwarm_lima => lwarm,                                                  &
                              nmod_ccn, nmod_ifn, nmod_imm
 use modd_salt,         only: lsalt
 use modd_viscosity,    only: lvisc, lvisc_r, lvisc_sv, lvisc_th, lvisc_uvw
@@ -3132,10 +3134,18 @@ SV_BUDGETS: do jsv = 1, ksv
 
       else if ( jsv >= nsv_lima_ccn_acti .and. jsv <= nsv_lima_ccn_acti + nmod_ccn - 1 ) then SV_LIMA
         ! Activated CCN concentration
+        gcond = lwarm_lima
+        tzsource%cmnhname  = 'CEDS'
+        tzsource%clongname = 'adjustment to saturation'
+        call Budget_source_add( tbudgets(ibudget), tzsource, gcond, igroup )
 
 
       else if ( jsv == nsv_lima_scavmass ) then SV_LIMA
         ! Scavenged mass variable
+        gcond = lscav_lima .and. laero_mass_lima
+        tzsource%cmnhname  = 'CEDS'
+        tzsource%clongname = 'adjustment to saturation'
+        call Budget_source_add( tbudgets(ibudget), tzsource, gcond, igroup )
 
 
       else if ( jsv == nsv_lima_ni ) then SV_LIMA
@@ -3252,10 +3262,18 @@ SV_BUDGETS: do jsv = 1, ksv
 
       else if ( jsv >= nsv_lima_ifn_nucl .and. jsv <= nsv_lima_ifn_nucl + nmod_ifn - 1 ) then SV_LIMA
         ! Nucleated IFN concentration
+        gcond = lcold_lima
+        tzsource%cmnhname  = 'CEDS'
+        tzsource%clongname = 'adjustment to saturation'
+        call Budget_source_add( tbudgets(ibudget), tzsource, gcond, igroup )
 
 
       else if ( jsv >= nsv_lima_imm_nucl .and. jsv <= nsv_lima_imm_nucl + nmod_imm - 1 ) then SV_LIMA
         ! Nucleated IMM concentration
+        gcond = lcold_lima
+        tzsource%cmnhname  = 'CEDS'
+        tzsource%clongname = 'adjustment to saturation'
+        call Budget_source_add( tbudgets(ibudget), tzsource, gcond, igroup )
 
 
       else if ( jsv == nsv_lima_hom_haze ) then SV_LIMA
diff --git a/src/MNH/lima_adjust.f90 b/src/MNH/lima_adjust.f90
index 0c0e8af9a..a629f3920 100644
--- a/src/MNH/lima_adjust.f90
+++ b/src/MNH/lima_adjust.f90
@@ -137,6 +137,7 @@ END MODULE MODI_LIMA_ADJUST
 !  P. Wautelet 10/04/2019: replace ABORT and STOP calls by Print_msg
 !  P. Wautelet 28/05/2019: move COUNTJV function to tools.f90
 !  P. Wautelet 28/05/2020: bugfix: correct array start for PSVT and PSVS
+!  P. Wautelet 01/02/2021: bugfix: add missing CEDS source terms for SV budgets
 !-------------------------------------------------------------------------------
 !
 !*       0.    DECLARATIONS
@@ -382,16 +383,26 @@ if ( nbumod == kmi .and. lbu_enable ) then
   if ( lbudget_sv ) then
     call Budget_store_init( tbudgets(NBUDGET_SV1 - 1 + nsv_lima_nc), 'CEDS', pccs(:, :, :) * prhodj(:, :, :) )
     call Budget_store_init( tbudgets(NBUDGET_SV1 - 1 + nsv_lima_ni), 'CEDS', pcis(:, :, :) * prhodj(:, :, :) )
+    if ( lscav .and. laero_mass ) &
+      call Budget_store_init( tbudgets(NBUDGET_SV1 - 1 + nsv_lima_scavmass), 'CEDS', pmas(:, :, :) * prhodj(:, :, :) )
     if ( lwarm ) then
       do jl = 1, nmod_ccn
         idx = NBUDGET_SV1 - 1 + nsv_lima_ccn_free - 1 + jl
         call Budget_store_init( tbudgets(idx), 'CEDS', pnfs(:, :, :, jl) * prhodj(:, :, :) )
+        idx = NBUDGET_SV1 - 1 + nsv_lima_ccn_acti - 1 + jl
+        call Budget_store_init( tbudgets(idx), 'CEDS', pnas(:, :, :, jl) * prhodj(:, :, :) )
       end do
     end if
     if ( lcold ) then
       do jl = 1, nmod_ifn
         idx = NBUDGET_SV1 - 1 + nsv_lima_ifn_free - 1 + jl
         call Budget_store_init( tbudgets(idx), 'CEDS', pifs(:, :, :, jl) * prhodj(:, :, :) )
+        idx = NBUDGET_SV1 - 1 + nsv_lima_ifn_nucl - 1 + jl
+        call Budget_store_init( tbudgets(idx), 'CEDS', pins(:, :, :, jl) * prhodj(:, :, :) )
+      end do
+      do jl = 1, nmod_imm
+        idx = NBUDGET_SV1 - 1 + nsv_lima_imm_nucl - 1 + jl
+        call Budget_store_init( tbudgets(idx), 'CEDS', pnis(:, :, :, jl) * prhodj(:, :, :) )
       end do
     end if
   end if
@@ -1226,16 +1237,26 @@ if ( nbumod == kmi .and. lbu_enable ) then
   if ( lbudget_sv ) then
     call Budget_store_end( tbudgets(NBUDGET_SV1 - 1 + nsv_lima_nc), 'CEDS', pccs(:, :, :) * prhodj(:, :, :) )
     call Budget_store_end( tbudgets(NBUDGET_SV1 - 1 + nsv_lima_ni), 'CEDS', pcis(:, :, :) * prhodj(:, :, :) )
+    if ( lscav .and. laero_mass ) &
+      call Budget_store_end( tbudgets(NBUDGET_SV1 - 1 + nsv_lima_scavmass), 'CEDS', pmas(:, :, :) * prhodj(:, :, :) )
     if ( lwarm ) then
       do jl = 1, nmod_ccn
         idx = NBUDGET_SV1 - 1 + nsv_lima_ccn_free - 1 + jl
         call Budget_store_end( tbudgets(idx), 'CEDS', pnfs(:, :, :, jl) * prhodj(:, :, :) )
+        idx = NBUDGET_SV1 - 1 + nsv_lima_ccn_acti - 1 + jl
+        call Budget_store_end( tbudgets(idx), 'CEDS', pnas(:, :, :, jl) * prhodj(:, :, :) )
       end do
     end if
     if ( lcold ) then
       do jl = 1, nmod_ifn
         idx = NBUDGET_SV1 - 1 + nsv_lima_ifn_free - 1 + jl
         call Budget_store_end( tbudgets(idx), 'CEDS', pifs(:, :, :, jl) * prhodj(:, :, :) )
+        idx = NBUDGET_SV1 - 1 + nsv_lima_ifn_nucl - 1 + jl
+        call Budget_store_end( tbudgets(idx), 'CEDS', pins(:, :, :, jl) * prhodj(:, :, :) )
+      end do
+      do jl = 1, nmod_imm
+        idx = NBUDGET_SV1 - 1 + nsv_lima_imm_nucl - 1 + jl
+        call Budget_store_init( tbudgets(idx), 'CEDS', pnis(:, :, :, jl) * prhodj(:, :, :) )
       end do
     end if
   end if
-- 
GitLab