From dbb4435318456fa0bed49212f79f6f6ec25c8da5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Riette?= <sebastien.riette@meteo.fr>
Date: Thu, 17 Nov 2022 11:19:41 +0100
Subject: [PATCH] S. Riette 17 Nov 2022: bugfixes rhcj and check tolerance

Bug correction in compute_updraft_rhcj: bit-repro of small_3D_alt8 now OK
Tolerance threshold modified in comp_DDH due to reference and/or OS version change
Explanations in check_commit_ial about references to use for special test cases
---
 .../turb/mode_compute_updraft_rhcj10.F90      |  6 +++---
 tools/check_commit_ial.sh                     | 20 ++++++++++++++++---
 tools/comp_DDH.py                             |  2 +-
 3 files changed, 21 insertions(+), 7 deletions(-)

diff --git a/src/common/turb/mode_compute_updraft_rhcj10.F90 b/src/common/turb/mode_compute_updraft_rhcj10.F90
index 4a293bd8d..c1394196f 100644
--- a/src/common/turb/mode_compute_updraft_rhcj10.F90
+++ b/src/common/turb/mode_compute_updraft_rhcj10.F90
@@ -297,7 +297,7 @@ CALL MZM_MF(D, PRVM(:,:), ZRVM_F(:,:))
 
 ! thetav at mass and flux levels 
 DO JK=1,D%NKT
-  DO JI=d%NIB,D%NIJE
+  DO JI=D%NIB,D%NIJE
     ZTHVM_F(JI,JK)=ZTHM_F(JI,JK)*((1.+ZRVORD*ZRVM_F(JI,JK))/(1.+ZRTM_F(JI,JK)))
   ENDDO
 ENDDO
@@ -570,7 +570,7 @@ DO JK=D%NKB,D%NKE-D%NKL,D%NKL
     ENDIF
   ENDDO
 
-  DO JI=D%NIJB,D%NIJB
+  DO JI=D%NIJB,D%NIJE
     IF(GTEST(JI)) THEN
       PEMF(JI,JK+D%NKL)=PEMF(JI,JK)*EXP(ZMIX1(JI))
     ENDIF
@@ -594,7 +594,7 @@ DO JK=D%NKB,D%NKE-D%NKL,D%NKL
 
 
 ! Test is we have reached the top of the updraft
-  DO JI=D%NIJB,D%NIJB
+  DO JI=D%NIJB,D%NIJE
     IF (GTEST(JI) .AND. ((ZW_UP2(JI,JK+D%NKL)<=ZEPS).OR.(PEMF(JI,JK+D%NKL)<=ZEPS))) THEN
       ZW_UP2   (JI,JK+D%NKL)=ZEPS
       PEMF     (JI,JK+D%NKL)=0.
diff --git a/tools/check_commit_ial.sh b/tools/check_commit_ial.sh
index 0acd970da..fe3136e17 100755
--- a/tools/check_commit_ial.sh
+++ b/tools/check_commit_ial.sh
@@ -18,10 +18,24 @@ set -e
 #small_3D_alt8: CMF_UPDRAFT='RHCJ'
 #small_3D_alt9: CCLOUD='OLD3', OCND2=.T.
 
-#The small_3D_alt8 is not included in the list of available tests because it needs to be compared against a special commit.
-#Indeed, on 3 February 2022 (commit 907e906) the mesonh version of compute_updraft_rhcj.F90 has been put in the common directory.
+#The small_3D_alt7 needed a correction in apl_arome which has been introduced in d37dd1f. But the reference pack has been modified
+#                  afterwards to enable this test case to be run (documented in INSTALL_pack_ial.md). In consequence, the reference
+#                  to use is the same as for the other test cases and this case cannot be run for commit before d37dd1f (20 April 2022).
 
-#The small_3D_alt9 is not included in the list of available tests because it cannot be run before 21 September (commit edc3f88).
+#The small_3D_alt8 is not included in the list of available tests because it needs to be compared against a special commit.
+#                  Indeed, on 3 February 2022 (commit 907e906) the mesonh version of compute_updraft_rhcj.F90 has been put in the common directory.
+#                  The reference is
+#                       the commit 907e906 when running in 48t1
+#                       the commit d10ed48 when running in 48t3
+#                  Indeed, it was checked that edc3f88 (last commit in 48t1) is identical to 907e906.
+#                  Between edc3f88 and d10ed48 only the reference change, physics source code is identical.
+
+#The small_3D_alt9 is not included in the list of available tests because it needs to be compared against a special commit.
+#                  Indeed, some pieces are missing in the reference pack. Theses pieces have been added in commit edc3f88 during phasing with 48t3.
+#                  The reference is
+#                       the commit edc3f88 (21 September 2022) when running in 48t1
+#                       the commit d10ed48 in 48t3 (29 september 2022) when running in 48t3
+#                  Between edc3f88 and d10ed48 only the reference change, physics source code is identical.
 
 #Special pack names:
 # - recompil: original source code (everything under mpa)
diff --git a/tools/comp_DDH.py b/tools/comp_DDH.py
index 63d886c86..fd36158a6 100755
--- a/tools/comp_DDH.py
+++ b/tools/comp_DDH.py
@@ -9,7 +9,7 @@ import numpy
 import matplotlib.pyplot as plt
 epygram.init_env()
 
-def comp_DDH(filename1, filename2, output_fig, tol_ad=1.2E-7, tol_rd=1.E-6, verbose=False):
+def comp_DDH(filename1, filename2, output_fig, tol_ad=3E-7, tol_rd=1.E-6, verbose=False):
     r1 = epygram.formats.resource(filename1, 'r')
     r2 = epygram.formats.resource(filename2, 'r')
 
-- 
GitLab