diff --git a/src/common/micro/modd_nebn.F90 b/src/common/micro/modd_nebn.F90 index 51cebc5604b4c88ad05d87bbd0da1e80afae48e6..dce8f1d9aab9b16e9728812d8fbd01d52c26e5a3 100644 --- a/src/common/micro/modd_nebn.F90 +++ b/src/common/micro/modd_nebn.F90 @@ -188,6 +188,8 @@ IF(LLDEFAULTVAL) THEN CFRAC_ICE_SHALLOW_MF='T' VSIGQSAT=0. LSIGMAS=.FALSE. + ELSEIF(HPROGRAM=='LMDZ') THEN + LSUBG_COND=.TRUE. ENDIF ENDIF ! diff --git a/src/common/micro/modd_param_icen.F90 b/src/common/micro/modd_param_icen.F90 index af4d288bf3fb22e92feae57a47466e81eaeba642..3534bf3f8678df846c54ab7aa57b7c14c6b2e9d6 100644 --- a/src/common/micro/modd_param_icen.F90 +++ b/src/common/micro/modd_param_icen.F90 @@ -373,6 +373,18 @@ IF(LLDEFAULTVAL) THEN LSEDIC=.FALSE. XMRSTEP=0. CSUBG_AUCV_RC='PDF' + ELSEIF(HPROGRAM=='LMDZ') THEN + CSUBG_AUCV_RC='PDF' + CSEDIM='STAT' + NMAXITER_MICRO=1 + LCRIAUTI=.TRUE. + XCRIAUTC_NAM=0.001 + XCRIAUTI_NAM=0.0002 + XT0CRIAUTI_NAM=-5. + LRED=.TRUE. + LCONVHG=.TRUE. + LADJ_BEFORE=.TRUE. + LADJ_AFTER=.FALSE. ENDIF ENDIF ! @@ -409,9 +421,9 @@ IF(LLCHECK) THEN CALL ABOR1 ("XRDESRED_NAM and XRDEGRED_NAM must not be activated together with LOCND2") ENDIF - IF(HPROGRAM=='AROME') THEN + IF(HPROGRAM=='AROME' .OR. HPROGRAM=='LMDZ') THEN IF(.NOT. (LADJ_BEFORE .AND. .NOT. LADJ_AFTER)) THEN - CALL PRINT_MSG(NVERB_FATAL, 'GEN', 'MODD_PARAM_ICE_n', 'With AROME, LADJ_BEFORE must be .T. and LADJ_AFTER must be .F.') + CALL PRINT_MSG(NVERB_FATAL, 'GEN', 'MODD_PARAM_ICE_n', 'With AROME/LMDZ, LADJ_BEFORE must be .T. and LADJ_AFTER must be .F.') ENDIF ELSEIF(HPROGRAM=='MESONH') THEN IF(.NOT. LPACK_MICRO) THEN diff --git a/src/common/turb/modd_turbn.F90 b/src/common/turb/modd_turbn.F90 index 6ad26f635c5cfac33d23f762a2214b9e2821391c..867228d2721c5bcb82b64ce6a5440eb332c22cb2 100644 --- a/src/common/turb/modd_turbn.F90 +++ b/src/common/turb/modd_turbn.F90 @@ -343,6 +343,9 @@ IF(LLDEFAULTVAL) THEN ELSEIF(HPROGRAM=='MESONH') THEN LROTATE_WIND=.TRUE. LTKEMINTURB=.FALSE. + ELSEIF(HPROGRAM=='LMDZ') THEN + XTKEMIN=1.E-6 + XLINI=0. ENDIF ENDIF ! diff --git a/src/lmdz/ext/mode_init_phyex.F90 b/src/lmdz/ext/mode_init_phyex.F90 index b96dc25b9b019340562710a56387f3add51f5364..8fb3e00d8d65f52908c3fd38f3d935bf022c5d4f 100644 --- a/src/lmdz/ext/mode_init_phyex.F90 +++ b/src/lmdz/ext/mode_init_phyex.F90 @@ -41,6 +41,7 @@ SUBROUTINE INIT_PHYEX(PTSTEP, PDZMIN, PHYEX) ! USE MODD_PHYEX, ONLY: PHYEX_t USE MODI_INI_PHYEX, ONLY: INI_PHYEX +USE print_control_mod, ONLY : lunout ! IMPLICIT NONE ! @@ -53,19 +54,34 @@ CHARACTER(LEN=4) :: CMICRO CHARACTER(LEN=4) :: CSCONV CHARACTER(LEN=4) :: CTURB INTEGER :: K +LOGICAL :: LREADNAM, LOPENED +INTEGER :: IUNITNML, ILUN ! !General configuration, cannot be modified by namelist -CPROGRAM='AROME ' +CPROGRAM='LMDZ' CMICRO='ICE3' CSCONV='EDKF' CTURB='TKEL' ! ! Initialize PHYEX -CALL INI_PHYEX(HPROGRAM=CPROGRAM, KUNITNML=0, LDNEEDNAM=.TRUE., & - &KLUOUT=20, KFROM=0, KTO=1, & +!If the namelist file exists, we use it +INQUIRE(FILE='phyex.nam', EXIST=LREADNAM) +IF(LREADNAM) THEN + IUNITNML=-1 + DO ILUN=1,100 + INQUIRE(UNIT=ILUN, OPENED=LOPENED) + IF (.NOT. LOPENED) THEN + IUNITNML=ILUN + EXIT + END IF + END DO + OPEN(ACTION='read', FILE='phyex.nam', UNIT=IUNITNML) +ENDIF +CALL INI_PHYEX(HPROGRAM=CPROGRAM, KUNITNML=IUNITNML, LDNEEDNAM=.FALSE., & + &KLUOUT=lunout, KFROM=0, KTO=1, & &PTSTEP=PTSTEP, PDZMIN=PDZMIN, & &CMICRO=CMICRO, CSCONV=CSCONV, CTURB=CTURB, & - &LDDEFAULTVAL=.TRUE., LDREADNAM=.FALSE., LDCHECK=.TRUE., & + &LDDEFAULTVAL=.TRUE., LDREADNAM=LREADNAM, LDCHECK=.TRUE., & &KPRINT=2, LDINIT=.TRUE., & &PHYEX_OUT=PHYEX) ! diff --git a/src/lmdz/ext/physiqex_mod.F90 b/src/lmdz/ext/physiqex_mod.F90 index e4d018f38bf7b94b7d1d70f43b8e5f1b92225a17..59ab075c1295389c21d4b425a26731a35875fc45 100644 --- a/src/lmdz/ext/physiqex_mod.F90 +++ b/src/lmdz/ext/physiqex_mod.F90 @@ -228,9 +228,6 @@ if (debut) then ! Things to do only for the first call to physics CALL INIT_PHYEX(pdtphys, ZDZMIN, PHYEX) CALL FILL_DIMPHYEX(KLON, KLEV, D) - !Update default values - PHYEX%NEBN%LSUBG_COND = .TRUE. - PHYEX%PARAM_ICEN%CSUBG_AUCV_RC='PDF' ! ! Variables saved ALLOCATE(PTKEM(klon,klev+2)) @@ -360,9 +357,9 @@ CALL VERTICAL_EXTEND(ZVT,klev) ZRXS(:,:,:) = ZRX(:,:,:)/pdtphys ZTHETAS(:,:)=ZTHETA(:,:)/pdtphys ZTKES(:,:)=PTKEM(:,:)/pdtphys -!To compute the actual tendecy, we save the initial values of these variables +!To compute the actual tendency, we save the initial values of these variables ZRXS0(:,:,:) = ZRXS(:,:,:) -ZTHETAS0=ZTHETAS +ZTHETAS0(:,:)=ZTHETAS(:,:) ZTKES0(:,:)=ZTKES(:,:) !------------------------------------------------------------ ! Adjustment @@ -383,7 +380,7 @@ CALL ICE_ADJUST (D, PHYEX%CST, PHYEX%RAIN_ICE_PARAMN, PHYEX%NEBN, PHYEX%TURBN, P &ZRX(:,:,3), ZRX(:,:,4), ZRXS(:,:,4), ZRX(:,:,5), ZRX(:,:,6), & &PHYEX%MISC%YLBUDGET, PHYEX%MISC%NBUDGET, & &ZICE_CLD_WGT, & - &ZHLC_HRC, ZHLC_HCF, ZHLI_HRI, ZHLI_HCF ) + &PHLC_HRC=ZHLC_HRC, PHLC_HCF=ZHLC_HCF, PHLI_HRI=ZHLI_HRI, PHLI_HCF=ZHLI_HCF ) ! !Variables are updated with their adjusted values (to be used by the other parametrisations) ZTHETA(:,:)=ZTHETAS(:,:)*pdtphys @@ -419,22 +416,21 @@ d_u(1:klon,1)=d_u(1:klon,1)-u(1:klon,1)/86400. d_v(1:klon,1)=d_v(1:klon,1)-v(1:klon,1)/86400. ! ! Flux RICO -PSFTH(:) = 5E-3 ! RICO -PSFRV(:) = 6E-5 ! RICO +!PSFTH(:) = 5E-3 ! RICO +!PSFRV(:) = 6E-5 ! RICO ! Flux ARMCU -!PSFTH(:) = -fsens/1000. -!PSFRV(:) = -flat/(2.5e6) +PSFTH(:) = -fsens/1000. +PSFRV(:) = -flat/(2.5e6) ! PSFSV(:,:) = 0. PSFU(:) = 0. PSFV(:) = 0. ! -!TODO PSIGMF option STAT !------------------------------------------------------------ ! Shallow convection !------------------------------------------------------------ ! - CALL SHALLOW_MF(D, PHYEX%CST, PHYEX%NEBN, PHYEX%PARAM_MFSHALLN, PHYEX%TURBN, PHYEX%CSTURB, & +CALL SHALLOW_MF(D, PHYEX%CST, PHYEX%NEBN, PHYEX%PARAM_MFSHALLN, PHYEX%TURBN, PHYEX%CSTURB, & &KRR=KRR, KRRL=KRRL, KRRI=KRRI, KSV=KSV, & &ONOMIXLG=PHYEX%MISC%ONOMIXLG,KSV_LGBEG=PHYEX%MISC%KSV_LGBEG,KSV_LGEND=PHYEX%MISC%KSV_LGEND, & &PTSTEP=pdtphys, & @@ -480,7 +476,7 @@ CALL TURB(PHYEX%CST, PHYEX%CSTURB, PHYEX%MISC%TBUCONF, PHYEX%TURBN, PHYEX%NEBN, & PHYEX%MISC%KSPLIT,PHYEX%MISC%KMI, KSV, PHYEX%MISC%KSV_LGBEG, PHYEX%MISC%KSV_LGEND, & & PHYEX%MISC%KSV_LIMA_NR, PHYEX%MISC%KSV_LIMA_NS, PHYEX%MISC%KSV_LIMA_NG, PHYEX%MISC%KSV_LIMA_NH, & & PHYEX%MISC%O2D, PHYEX%MISC%ONOMIXLG, PHYEX%MISC%OFLAT, PHYEX%MISC%OCOUPLES, & - & PHYEX%MISC%OBLOWSNOW,PHYEX%MISC%OIBM, & + & PHYEX%MISC%OBLOWSNOW,PHYEX%MISC%OIBM, & & PHYEX%MISC%OFLYER, PHYEX%MISC%COMPUTE_SRC, PHYEX%MISC%PRSNOW, & & PHYEX%MISC%OOCEAN, PHYEX%MISC%ODEEPOC, PHYEX%MISC%ODIAG_IN_RUN, & & PHYEX%MISC%HTURBLEN_CL,PHYEX%MISC%CMICRO, & diff --git a/src/lmdz/lmdz_version.json b/src/lmdz/lmdz_version.json new file mode 100644 index 0000000000000000000000000000000000000000..2aef852a86f9d562bffec1efb065891b887de7a9 --- /dev/null +++ b/src/lmdz/lmdz_version.json @@ -0,0 +1,5 @@ +{ +"version":"20230522.trunk", +"install_arg":"-unstable", +"rad":"oldrad" +} diff --git a/tools/check_commit_lmdz.sh b/tools/check_commit_lmdz.sh new file mode 100755 index 0000000000000000000000000000000000000000..b46bb4eb61455daaa30c4562d55272d5e28d76ed --- /dev/null +++ b/tools/check_commit_lmdz.sh @@ -0,0 +1,269 @@ +#!/bin/bash + +set -x +set -e +set -o pipefail #abort if left command on a pipe fails + +#This script: +# - compiles the LMDZ model using a specific commit for the externalised physics +# - runs RICO and ARM-CU 1D cases + +PHYEXTOOLSDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +specialPack="ref" +availTests="rico arm_cu" +defaultTest="rico" +defaultRef='ref' +LMDZPACK=${LMDZPACK:=$HOME/LMDZ/PHYEX} +separator='_' #- be carrefull, gmkpack (at least on belenos) has multiple allergies (':', '.', '@') + #- seprator must be in sync with prep_code.sh separator + +function usage { + echo "Usage: $0 [-h] [-p] [-c] [-C] [-r] [-s] [--expand] [-t test] [--version VERSION] [--repo-user] [--repo-protocol] commit [reference]" + echo "commit commit hash (or a directory, or among $specialPack) to test" + echo "reference commit hash (or a directory, or among $specialPack) REF to use as a reference" + echo "-s suppress compilation pack" + echo "-p creates pack" + echo "-c performs compilation" + echo "-r runs the tests" + echo "-C checks the result against the reference" + echo "-t comma separated list of tests to execute" + echo " or ALL to execute all tests" + echo "--nofcm don't use fcm (be carreful, with fcm compilation exits with a (false) error" + echo "--expand use mnh_expand (code will be in do loops)" + echo "--version VERSION to force using lmdz VERSION" + echo "--repo-user user hosting the PHYEX repository on github," + echo " defaults to the env variable PHYEXREOuser (=$PHYEXREOuser)" + echo "--repo-protocol protocol (https or ssh) to reach the PHYEX repository on github," + echo " defaults to the env variable PHYEXREOprotocol (=$PHYEXREOprotocol)" + echo "" + echo "If nothing is asked (pack creation, compilation, running, check) everything is done" + echo "If no test is aked for, the default one ($defaultTest) is executed" + echo + echo "With the special reference REF commit, a suitable reference is guessed" + echo "The directory (for commit only, not ref) can take the form server:directory" + echo "If using a directory (for commit or reference) it must contain at least one '/'" + echo "The commit can be a tag, written with syntagx tags/<TAG>" +} + +fcm=1 +packcreation=0 +compilation=0 +run=0 +check=0 +commit="" +reference="" +tests="" +suppress=0 +useexpand=0 +version="" + +while [ -n "$1" ]; do + case "$1" in + '-h') usage;; + '-s') suppress=1;; + '-p') packcreation=1;; + '-c') compilation=1;; + '-r') run=$(($run+1));; + '-C') check=1;; + '-t') tests="$2"; shift;; + '--nofcm') fcm=0;; + '--expand') useexpand=1;; + '--version') version="$2"; shift;; + '--repo-user') export PHYEXREPOuser=$2; shift;; + '--repo-protocol') export PHYEXREPOprotocol=$2; shift;; + #--) shift; break ;; + *) if [ -z "${commit-}" ]; then + commit=$1 + else + if [ -z "${reference-}" ]; then + reference=$1 + else + echo "Only two commit hash allowed on command line" + exit 1 + fi + fi;; + esac + shift +done + +if [ -z "${tests-}" ]; then + tests=$defaultTest +elif [ $tests == 'ALL' ]; then + tests=$availTests +fi + +if [ $packcreation -eq 0 -a \ + $compilation -eq 0 -a \ + $run -eq 0 -a \ + $check -eq 0 ]; then + packcreation=1 + compilation=1 + run=1 + check=1 +fi + +if [ -z "${commit-}" ]; then + echo "At least one commit hash must be provided on command line" + exit 2 +fi + +if [ $check -eq 1 -a -z "${reference-}" ]; then + echo "To perform a comparison two commit hashes are mandatory on the command line" + exit 3 +fi + +function jsonarg { + #$1 is the file containing the json dictionnary + #$2 is the dictionnary key to return + python3 -c "import json; print(json.load(open('$1', 'r'))['$2'])" +} + +fromdir='' +if echo $commit | grep '/' | grep -v '^tags/' > /dev/null; then + fromdir=$commit + if [ "$version" == "" ]; then + content_lmdz_version=$(scp $commit/src/lmdz/lmdz_version.json /dev/stdout 2>/dev/null) + version=$(jsonarg <(echo $content_lmdz_version) version) + rad=$(jsonarg <(echo $content_lmdz_version) rad) + install_arg=$(jsonarg <(echo $content_lmdz_version) install_arg) + fi + name=$(echo $commit | sed 's/\//'${separator}'/g' | sed 's/:/'${separator}'/g' | sed 's/\./'${separator}'/g') + [ $suppress -eq 1 -a -d $LMDZPACK/$name ] && rm -rf $LMDZPACK/$name +elif echo $specialPack | grep -w $commit > /dev/null; then + name="PHYEX/$commit" +else + if [ "$version" == "" ]; then + if [[ $commit == lmdz${separator}* ]]; then + lmdz_version_file="lmdz_version.json" + else + lmdz_version_file="src/lmdz/lmdz_version.json" + fi + if echo $commit | grep '^tags/' > /dev/null; then + urlcommit=$(echo $commit | cut -d / -f 2-) + else + urlcommit=$commit + fi + content_lmdz_version=$(wget --no-check-certificate https://raw.githubusercontent.com/$PHYEXREPOuser/PHYEX/${urlcommit}/$lmdz_version_file -O - 2>/dev/null || echo "") + version=$(jsonarg <(echo $content_lmdz_version) version) + rad=$(jsonarg <(echo $content_lmdz_version) rad) + install_arg=$(jsonarg <(echo $content_lmdz_version) install_arg) + fi + name="COMMIT$(echo $commit | sed 's/\//'${separator}'/g' | sed 's/:/'${separator}'/g' | sed 's/\./'${separator}'/g')" + [ $suppress -eq 1 -a -d $LMDZPACK/$name ] && rm -rf $LMDZPACK/$name +fi +if [ ! -z "${reference-}" ]; then + [ $reference == 'REF' ] && reference=$defaultRef + reffromdir='' + if echo $reference | grep '/' > /dev/null; then + reffromdir=$reference + refname="PHYEX/$(echo $reference | sed 's/\//'${separator}'/g' | sed 's/:/'${separator}'/g' | sed 's/\./'${separator}'/g')" + elif echo $specialPack | grep -w $reference > /dev/null; then + refname="PHYEX/$reference" + else + refname="PHYEX/COMMIT${reference}" + fi +fi + +if [ $packcreation -eq 1 ]; then + echo "### Compilation of commit $commit" + + if echo $specialPack | grep -w $commit > /dev/null; then + echo "Special commit '$commit' cannot be compiled with this script" + exit 4 + fi + + if [ -d $LMDZPACK/$name ]; then + echo "Pack already exists ($LMDZPACK/$name), suppress it to be able to compile it again (or use the -s option to automatically suppress it)" + exit 5 + fi + + #Create directory + cd $LMDZPACK + mkdir $name + cd $name + base=$PWD + wget https://lmdz.lmd.jussieu.fr/pub/install_lmdz.sh + bash install_lmdz.sh -v $version $install_arg -bench 0 -rad $rad -name LMDZ > Install.log + lmdzdir=$PWD/LMDZ + + #Populate with test cases + cd $lmdzdir + wget https://lmdz.lmd.jussieu.fr/pub/1D/1D.tar.gz + tar xf 1D.tar.gz + cd 1D + rad=$(echo $rad) #to suppress spaces + sed -i'' -e 's:^listecas=.*$:listecas="arm_cu rico":' -e "s/^rad=.*$/rad='$rad'/" run.sh + + cd INPUT/PHYS + cp physiq.def_6A physiq.def_PHYLMD + echo "iflag_physiq=1" >> physiq.def_PHYLMD + sed -e "s/iflag_physiq=1/iflag_physiq=2/" physiq.def_PHYLMD > physiq.def_PHYEX + + #Update compilation cript + phylmd=${lmdzdir}/modipsl/modeles/LMDZ/libf/phylmd/ + if [ $fcm -eq 1 ]; then + sed -i "s/fcm=0/fcm=1/g" $lmdzdir/1D/bin/compile + fi + + #Checkout PHYEX + cd $base + phyex=$base/PHYEX/ + MNH_EXPAND_DIR=$PHYEXTOOLSDIR/mnh_expand + export PATH=$MNH_EXPAND_DIR/filepp:$MNH_EXPAND_DIR/MNH_Expand_Array:$PATH + + if [ $useexpand == 1 ]; then + expand_options="-D MNH_EXPAND -D MNH_EXPAND_LOOP" + else + expand_options="" + fi + subs="-s turb -s micro -s aux -s ext" + prep_code=$PHYEXTOOLSDIR/prep_code.sh + if [ "$fromdir" == '' ]; then + echo "Clone repository, and checkout commit $commit (using prep_code.sh)" + if [[ $commit == lmdz${separator}* ]]; then + $prep_code -c $commit PHYEX #This commit is ready for inclusion + else + $prep_code -c $commit $expand_options $subs -m arome PHYEX + fi + else + echo "Copy $fromdir" + mkdir PHYEX + scp -q -r $fromdir/src PHYEX/ + $prep_code $expand_options $subs -m lmdz PHYEX + fi + + #Update code + cd $phylmd + cp -r . ../phylmdorig + ln -sf $phyex/*/* . + if [ $fcm -eq 0 ]; then + mv modd_dimphyexn.F90 modd_dimphyex.F90 + for name in `grep -i 'END MODULE' modd*n.F90 | cut -d: -f1 | sed -e 's/n.F90//'` ; do mv ${name}n.F90 ${name}_n.F90 ; done + mv hypgeo.F90 modi_hypgeo.F90 + mv hypser.f90 modi_hypser.F90 + mv tools.F90 mode_tools.F90 + mv shuman_mf.F90 modi_shuman_mf.F90 + mv shuman_phy.F90 mode_shuman_phy.F90 + fi + + #Missing files in case ecrad is not used + if [ "$rad" != "ecrad" ] ; then + ln -s ecrad/yom* ecrad/abor1.F90 ecrad/abor1.intfb.h ecrad/parkind1.F90 . + fi +fi + +if [ $compilation -eq 1 ]; then + echo "### Compilation of commit $commit" + cd $LMDZPACK/$name/LMDZ/1D + sed -i'' -e 's/^listedef=.*$/listedef="PHYLMD PHYEX"/' run.sh + ./run.sh > log.$$ 2>&1 +fi + +if [ $run -eq 1 ]; then + echo "### Execution of commit $commit" + cd $LMDZPACK/$name/LMDZ/1D + ./run.sh -r > log.$$ 2>&1 + wget https://www.lmd.jussieu.fr/~hourdin/phyex/compare.sh + bash compare.sh +fi +