From 83ea40f2a0ae4cc3f10b222f993ab061b2b545b8 Mon Sep 17 00:00:00 2001
From: Philippe WAUTELET <philippe.wautelet@aero.obs-mip.fr>
Date: Wed, 10 Feb 2021 14:02:05 +0100
Subject: [PATCH] Philippe 10/02/2021: budgets: add missing sources for
 NSV_C2R2BEG+3 budget

---
 src/MNH/ini_budget.f90          | 50 +++++++++++++++++----------------
 src/MNH/khko_notadjust.f90      |  3 ++
 src/MNH/sources_neg_correct.f90 | 13 +++++----
 3 files changed, 36 insertions(+), 30 deletions(-)

diff --git a/src/MNH/ini_budget.f90 b/src/MNH/ini_budget.f90
index 27afc1fd6..da40e7ec1 100644
--- a/src/MNH/ini_budget.f90
+++ b/src/MNH/ini_budget.f90
@@ -5,10 +5,6 @@
 !-----------------------------------------------------------------
 ! 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
-!  P. Wautelet 02/02/2021: budgets: add missing source terms for SV budgets in LIMA
-!  P. Wautelet 03/02/2021: budgets: add new source if LIMA splitting: CORR2
 !-----------------------------------------------------------------
 module mode_ini_budget
 
@@ -203,6 +199,11 @@ end subroutine Budget_preallocate
 !  P. Wautelet 30/06/2020: add NNETURSV, NNEADVSV and NNECONSV variables
 !  P. Wautelet 06/07/2020: bugfix: add condition on HTURB for NETUR sources for SV budgets
 !  P. Wautelet 08/12/2020: add nbusubwrite and nbutotwrite
+!  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
+!  P. Wautelet 02/02/2021: budgets: add missing source terms for SV budgets in LIMA
+!  P. Wautelet 03/02/2021: budgets: add new source if LIMA splitting: CORR2
+!  P. Wautelet 10/02/2021: budgets: add missing sources for NSV_C2R2BEG+3 budget
 !-------------------------------------------------------------------------------
 !
 !*       0.    DECLARATIONS
@@ -2816,28 +2817,25 @@ SV_BUDGETS: do jsv = 1, ksv
       ! C2R2 or KHKO Case
 
       ! Source terms in common for all C2R2/KHKO budgets
-      ! (except supersaturation not taken into account in the budgets (for the moment))
-      if ( jsv <= nsv_c2r2beg + 2 ) then
-        gcond = hturb == 'TKEL'
-        tzsource%cmnhname  = 'NETUR'
-        tzsource%clongname = 'negative correction induced by turbulence'
-        call Budget_source_add( tbudgets(ibudget), tzsource, gcond, nnetursv )
+      gcond = hturb == 'TKEL'
+      tzsource%cmnhname  = 'NETUR'
+      tzsource%clongname = 'negative correction induced by turbulence'
+      call Budget_source_add( tbudgets(ibudget), tzsource, gcond, nnetursv )
 
-        gcond = .true.
-        tzsource%cmnhname  = 'NEADV'
-        tzsource%clongname = 'negative correction induced by advection'
-        call Budget_source_add( tbudgets(ibudget), tzsource, gcond, nneadvsv )
+      gcond = .true.
+      tzsource%cmnhname  = 'NEADV'
+      tzsource%clongname = 'negative correction induced by advection'
+      call Budget_source_add( tbudgets(ibudget), tzsource, gcond, nneadvsv )
 
-        gcond = .true.
-        tzsource%cmnhname  = 'NEGA'
-        tzsource%clongname = 'negative correction'
-        call Budget_source_add( tbudgets(ibudget), tzsource, gcond, nnegasv )
+      gcond = .true.
+      tzsource%cmnhname  = 'NEGA'
+      tzsource%clongname = 'negative correction'
+      call Budget_source_add( tbudgets(ibudget), tzsource, gcond, nnegasv )
 
-        gcond = .true.
-        tzsource%cmnhname  = 'NECON'
-        tzsource%clongname = 'negative correction induced by condensation'
-        call Budget_source_add( tbudgets(ibudget), tzsource, gcond, nneconsv )
-      end if
+      gcond = .true.
+      tzsource%cmnhname  = 'NECON'
+      tzsource%clongname = 'negative correction induced by condensation'
+      call Budget_source_add( tbudgets(ibudget), tzsource, gcond, nneconsv )
 
       ! Source terms specific to each budget
       SV_C2R2: select case( jsv - nsv_c2r2beg + 1 )
@@ -2925,7 +2923,11 @@ SV_BUDGETS: do jsv = 1, ksv
 
         case ( 4 ) SV_C2R2
           ! Supersaturation
-          ! Nothing to do
+          gcond = .true.
+          tzsource%cmnhname  = 'CEVA'
+          tzsource%clongname = 'evaporation'
+          call Budget_source_add( tbudgets(ibudget), tzsource, gcond, igroup )
+
       end select SV_C2R2
 
 
diff --git a/src/MNH/khko_notadjust.f90 b/src/MNH/khko_notadjust.f90
index a6fc11057..344c2e976 100644
--- a/src/MNH/khko_notadjust.f90
+++ b/src/MNH/khko_notadjust.f90
@@ -91,6 +91,7 @@ END MODULE MODI_KHKO_NOTADJUST
 !!  Philippe Wautelet: 05/2016-04/2018: new data structures and calls for I/O
 !  P. Wautelet 28/05/2019: move COUNTJV function to tools.f90
 !  P. Wautelet    02/2020: use the new data structures and subroutines for budgets
+!  P. Wautelet 10/02/2021: add CEVA source for NSV_C2R2BEG+3 budget
 !-------------------------------------------------------------------------------
 !
 !*       0.    DECLARATIONS
@@ -196,6 +197,7 @@ if ( lbudget_th ) call Budget_store_init( tbudgets(NBUDGET_TH), 'COND', pths(:,
 if ( lbudget_sv ) then
   call Budget_store_init( tbudgets(NBUDGET_SV1 - 1 + nsv_c2r2beg    ), 'CEVA', pcnucs(:, :, :) * prhodj(:, :, :) )
   call Budget_store_init( tbudgets(NBUDGET_SV1 - 1 + nsv_c2r2beg + 1), 'CEVA', pccs  (:, :, :) * prhodj(:, :, :) )
+  call Budget_store_init( tbudgets(NBUDGET_SV1 - 1 + nsv_c2r2beg + 3), 'CEVA', psat  (:, :, :) * prhodj(:, :, :) )
 end if
 
 ILUOUT = TLUOUT%NLU
@@ -421,6 +423,7 @@ if ( lbudget_th ) call Budget_store_end( tbudgets(NBUDGET_TH), 'COND', pths(:, :
 if ( lbudget_sv ) then
   call Budget_store_end( tbudgets(NBUDGET_SV1 - 1 + nsv_c2r2beg    ), 'CEVA', pcnucs(:, :, :) * prhodj(:, :, :) )
   call Budget_store_end( tbudgets(NBUDGET_SV1 - 1 + nsv_c2r2beg + 1), 'CEVA', pccs  (:, :, :) * prhodj(:, :, :) )
+  call Budget_store_end( tbudgets(NBUDGET_SV1 - 1 + nsv_c2r2beg + 3), 'CEVA', psat  (:, :, :) * prhodj(:, :, :) )
 end if
 
 END SUBROUTINE KHKO_NOTADJUST
diff --git a/src/MNH/sources_neg_correct.f90 b/src/MNH/sources_neg_correct.f90
index 72c00c721..2c40ecb99 100644
--- a/src/MNH/sources_neg_correct.f90
+++ b/src/MNH/sources_neg_correct.f90
@@ -1,4 +1,4 @@
-!MNH_LIC Copyright 2020-2020 CNRS, Meteo-France and Universite Paul Sabatier
+!MNH_LIC Copyright 2020-2021 CNRS, Meteo-France and Universite Paul Sabatier
 !MNH_LIC This is part of the Meso-NH software governed by the CeCILL-C licence
 !MNH_LIC version 1. See LICENSE, CeCILL-C_V1-en.txt and CeCILL-C_V1-fr.txt
 !MNH_LIC for details. version 1.
@@ -7,6 +7,7 @@
 ! Modifications:
 !  P. Wautelet 30/06/2020: remove non-local corrections in resolved_cloud for NEGA => new local corrections here
 !  J. Escobar  21/07/2020: bug <-> array of size(:,:,:,0) => return if krr=0
+!  P. Wautelet 10/02/2021: budgets: add missing sources for NSV_C2R2BEG+3 budget
 !-----------------------------------------------------------------
 module mode_sources_neg_correct
 
@@ -26,7 +27,7 @@ use modd_budget,     only: lbudget_th, lbudget_rv, lbudget_rc, lbudget_rr, lbudg
                            NBUDGET_RS, NBUDGET_RG, NBUDGET_RH, NBUDGET_SV1,            &
                            tbudgets
 use modd_cst,        only: xci, xcl, xcpd, xcpv, xlstt, xlvtt, xp00, xrd, xtt
-use modd_nsv,        only: nsv_c2r2beg, nsv_lima_beg, nsv_lima_end, nsv_lima_nc, nsv_lima_nr, nsv_lima_ni
+use modd_nsv,        only: nsv_c2r2beg, nsv_c2r2end, nsv_lima_beg, nsv_lima_end, nsv_lima_nc, nsv_lima_nr, nsv_lima_ni
 use modd_param_lima, only: lcold_lima => lcold, lrain_lima => lrain, lwarm_lima => lwarm, &
                            xctmin_lima => xctmin, xrtmin_lima => xrtmin
 
@@ -78,7 +79,7 @@ if ( hbudname /= 'NECON' .and. hbudname /= 'NEGA' ) then
   end if
 
   if ( lbudget_sv .and. ( hcloud == 'C2R2' .or. hcloud == 'KHKO' ) ) then
-    do ji = nsv_c2r2beg, nsv_c2r2beg + 2
+    do ji = nsv_c2r2beg, nsv_c2r2end
       call Budget_store_init( tbudgets(NBUDGET_SV1 - 1 + ji), Trim( hbudname ), prsvs(:, :, :, ji) )
     end do
   end if
@@ -104,7 +105,7 @@ else !NECON + NEGA
   end if
 
   if ( lbudget_sv .and. ( hcloud == 'C2R2' .or. hcloud == 'KHKO' ) ) then
-    do ji = nsv_c2r2beg, nsv_c2r2beg + 2
+    do ji = nsv_c2r2beg, nsv_c2r2end
       call Budget_store_init( tbudgets(NBUDGET_SV1 - 1 + ji), Trim( hbudname ), prsvs(:, :, :, ji) * prhodj(:, :, :) )
     end do
   end if
@@ -309,7 +310,7 @@ if ( hbudname /= 'NECON' .and. hbudname /= 'NEGA' ) then
   end if
 
   if ( lbudget_sv .and. ( hcloud == 'C2R2' .or. hcloud == 'KHKO' ) ) then
-    do ji = nsv_c2r2beg, nsv_c2r2beg + 2
+    do ji = nsv_c2r2beg, nsv_c2r2end
       call Budget_store_end( tbudgets(NBUDGET_SV1 - 1 + ji), Trim( hbudname ), prsvs(:, :, :, ji) )
     end do
   end if
@@ -332,7 +333,7 @@ else !NECON + NEGA
   end if
 
   if ( lbudget_sv .and. ( hcloud == 'C2R2' .or. hcloud == 'KHKO' ) ) then
-    do ji = nsv_c2r2beg, nsv_c2r2beg + 2
+    do ji = nsv_c2r2beg, nsv_c2r2end
       call Budget_store_end( tbudgets(NBUDGET_SV1 - 1 + ji), Trim( hbudname ), prsvs(:, :, :, ji) * prhodj(:, :, :) )
     end do
   end if
-- 
GitLab