PHYEX 0.9.5
PHYsique EXternalisée
Loading...
Searching...
No Matches
th_r_from_thl_rt.func.h
Go to the documentation of this file.
1!MNH_LIC Copyright 2006-2023 CNRS, Meteo-France and Universite Paul Sabatier
2!MNH_LIC This is part of the Meso-NH software governed by the CeCILL-C licence
3!MNH_LIC version 1. See LICENSE, CeCILL-C_V1-en.txt and CeCILL-C_V1-fr.txt
4!MNH_LIC for details. version 1.
5 SUBROUTINE th_r_from_thl_rt(D, CST, NEBN, HFRAC_ICE,PFRAC_ICE,PP, &
6 PTHL, PRT, PTH, PRV, PRL, PRI, &
7 PRSATW, PRSATI, PRR, PRS, PRG, PRH, OOCEAN,&
8 PBUF)
9! ******* TO BE INCLUDED IN THE *CONTAINS* OF A SUBROUTINE, IN ORDER TO EASE AUTOMATIC INLINING ******
10! => Don't use drHook !!!
11! "compute_frac_ice.func.h" must be included at the same time
12! #################################################################
13!
14!
15!!**** *TH_R_FROM_THL_RT* - computes the non-conservative variables
16!! from conservative variables
17!!
18!! PURPOSE
19!! -------
20!!
21!!** METHOD
22!! ------
23!!
24!!
25!! EXTERNAL
26!! --------
27!!
28!! IMPLICIT ARGUMENTS
29!! ------------------
30!!
31!!
32!! REFERENCE
33!! ---------
34!!
35!! AUTHOR
36!! ------
37!! Julien PERGAUD * Meteo-France *
38!!
39!! MODIFICATIONS
40!! -------------
41!! Original 13/03/06
42!! S. Riette April 2011 : ice added, allow ZRLTEMP to be negative
43!! we use dQsat/dT to help convergence
44!! use of optional PRR, PRS, PRG, PRH
45!! S. Riette Nov 2016: support for HFRAC_ICE='S'
46!! P. Wautelet Mar 2023: bugfix: protect operations on optional dummy arguments
47!!
48!! --------------------------------------------------------------------------
49!
50!* 0. DECLARATIONS
51! ------------
52!
54USE modd_cst, ONLY : cst_t
55USE modd_neb_n, ONLY : neb_t
56!
57IMPLICIT NONE
58!
59!
60!* 0.1 declarations of arguments
61!
62TYPE(dimphyex_t), INTENT(IN) :: D
63TYPE(cst_t), INTENT(IN) :: CST
64TYPE(neb_t), INTENT(IN) :: NEBN
65CHARACTER(LEN=1), INTENT(IN) :: HFRAC_ICE
66LOGICAL, INTENT(IN) :: OOCEAN ! switch for Ocean model version
67REAL, DIMENSION(D%NIJT), INTENT(INOUT) :: PFRAC_ICE
68REAL, DIMENSION(D%NIJT), INTENT(IN) :: PP ! Pressure
69REAL, DIMENSION(D%NIJT), INTENT(IN) :: PTHL ! thetal to transform into th
70REAL, DIMENSION(D%NIJT),INTENT(IN) :: PRT ! Total mixing ratios to transform into rv,rc and ri
71REAL, DIMENSION(D%NIJT),OPTIONAL,INTENT(IN) :: PRR, PRS, PRG, PRH
72REAL, DIMENSION(D%NIJT), INTENT(OUT):: PTH ! th
73REAL, DIMENSION(D%NIJT), INTENT(OUT):: PRV ! vapor mixing ratio
74REAL, DIMENSION(D%NIJT), INTENT(INOUT):: PRL ! vapor mixing ratio
75REAL, DIMENSION(D%NIJT), INTENT(INOUT):: PRI ! vapor mixing ratio
76REAL, DIMENSION(D%NIJT), INTENT(OUT) :: PRSATW ! estimated mixing ration at saturation over water
77REAL, DIMENSION(D%NIJT), INTENT(OUT) :: PRSATI ! estimated mixing ration at saturation over ice
78REAL, DIMENSION(D%NIJT, 16), INTENT(OUT) :: PBUF ! buffer to replace automatic arrays
79!
80!-------------------------------------------------------------------------------
81!
82! 0.2 declaration of local variables
83INTEGER :: II ! Loop control
84INTEGER :: JITER ! number of iterations
85INTEGER :: JIJ, IIJB, IIJE
86INTEGER, PARAMETER :: IEXN=1, irvsat=2, icph=3, irltemp=4, icph2=5, it=6, ilvocpexn=7, ilsocpexn=8, &
87 & idrsatodt=9, idrsatodtw=10, idrsatodti=11, ifoesw=12, ifoesi=13, &
88 & ilogt=14, i99pp=15, i1prt=16
89REAL :: ZVAR1, ZVAR2, ZTPOW2, ZDELT
90
91!----------------------------------------------------------------------------
92!
93!* 1 Initialisation
94! --------------
95!
96!
97!
98iije=d%NIJE
99iijb=d%NIJB
100
101!Number of iterations
102jiter=2
103!
104!Computation of PBUF(IIJB:IIJE, ICPH2) depending on dummy arguments received
105pbuf(iijb:iije, icph2)=0
106IF(PRESENT(prr)) pbuf(iijb:iije, icph2)=pbuf(iijb:iije, icph2) + cst%XCL*prr(iijb:iije)
107IF(PRESENT(prs)) pbuf(iijb:iije, icph2)=pbuf(iijb:iije, icph2) + cst%XCI*prs(iijb:iije)
108IF(PRESENT(prg)) pbuf(iijb:iije, icph2)=pbuf(iijb:iije, icph2) + cst%XCI*prg(iijb:iije)
109IF(PRESENT(prh)) pbuf(iijb:iije, icph2)=pbuf(iijb:iije, icph2) + cst%XCI*prh(iijb:iije)
110!
111!Computation of an approximate state thanks to PRL and PRI guess
112pbuf(iijb:iije, iexn)=(pp(iijb:iije)/cst%XP00) ** cst%RDSCPD
113
114DO jij=iijb,iije
115 pbuf(jij, i99pp)=0.99*pp(jij)
116 prv(jij)=prt(jij)-prl(jij)-pri(jij)
117 pbuf(jij, icph)=cst%XCPD+ cst%XCPV * prv(jij)+ cst%XCL * prl(jij) + cst%XCI * pri(jij) + pbuf(jij, icph2)
118 zvar2=pbuf(jij, icph)*pbuf(jij, iexn)
119 zdelt=(pthl(jij)*pbuf(jij, iexn))-cst%XTT
120 pbuf(jij, ilvocpexn) = (cst%XLVTT + (cst%XCPV-cst%XCL) * zdelt) /zvar2
121 pbuf(jij, ilsocpexn) = (cst%XLSTT + (cst%XCPV-cst%XCI) * zdelt) /zvar2
122 pth(jij)=pthl(jij)+pbuf(jij, ilvocpexn)*prl(jij)+pbuf(jij, ilsocpexn)*pri(jij)
123 pbuf(jij, i1prt)=1+prt(jij)
124ENDDO
125!
126!
127! 2 Iteration
128! ---------
129
130DO ii=1,jiter
131 IF (oocean) THEN
132 pbuf(iijb:iije, it)=pth(iijb:iije)
133 ELSE
134 pbuf(iijb:iije, it)=pth(iijb:iije)*pbuf(iijb:iije, iexn)
135 END IF
136 !Computation of liquid/ice fractions
137 pfrac_ice(iijb:iije) = 0.
138 DO jij=iijb, iije
139 IF(prl(jij)+pri(jij) > 1.e-20) THEN
140 pfrac_ice(jij) = pri(jij) / (prl(jij)+pri(jij))
141 ENDIF
142 ENDDO
143 CALL compute_frac_ice(cst, hfrac_ice,nebn,pfrac_ice(iijb:iije),pbuf(iijb:iije, it))
144
145 !Computation of Rvsat and dRsat/dT
146 !In this version QSAT, QSATI, DQSAT and DQASATI functions are not used
147 !due to performance issue
148
149 ! Log does not vectorize on all compilers:
150 pbuf(iijb:iije, ilogt)=log(pbuf(iijb:iije, it))
151
152 DO jij=iijb, iije
153 pbuf(jij, ifoesw) = min(exp( cst%XALPW - cst%XBETAW/pbuf(jij, it) - cst%XGAMW*pbuf(jij, ilogt) ), pbuf(jij, i99pp))
154 pbuf(jij, ifoesi) = min(exp( cst%XALPI - cst%XBETAI/pbuf(jij, it) - cst%XGAMI*pbuf(jij, ilogt) ), pbuf(jij, i99pp))
155 prsatw(jij) = cst%XRD/cst%XRV*pbuf(jij, ifoesw)/pp(jij) / (1.+(cst%XRD/cst%XRV-1.)*pbuf(jij, ifoesw)/pp(jij))
156 prsati(jij) = cst%XRD/cst%XRV*pbuf(jij, ifoesi)/pp(jij) / (1.+(cst%XRD/cst%XRV-1.)*pbuf(jij, ifoesi)/pp(jij))
157 ztpow2=pbuf(jij, it)**2
158 pbuf(jij, idrsatodtw) = prsatw(jij) / (1.+(cst%XRD/cst%XRV-1.)*pbuf(jij, ifoesw)/pp(jij) ) &
159 * (cst%XBETAW/ztpow2 - cst%XGAMW/pbuf(jij, it))*pbuf(jij, i1prt)
160 pbuf(jij, idrsatodti) = prsati(jij) / (1.+(cst%XRD/cst%XRV-1.)*pbuf(jij, ifoesi)/pp(jij) ) &
161 * (cst%XBETAI/ztpow2 - cst%XGAMI/pbuf(jij, it))*pbuf(jij, i1prt)
162 !PRSATW(JIJ) = QSAT(PBUF(JIJ, IT),PP(JIJ)) !qsatw
163 !PRSATI(JIJ) = QSATI(PBUF(JIJ, IT),PP(JIJ)) !qsati
164 !PBUF(JIJ, IDRSATODTW) = DQSAT(PBUF(JIJ, IT),PP(JIJ),PRSATW(JIJ))*PBUF(JIJ, I1PRT)
165 !PBUF(JIJ, IDRSATODTI) = DQSATI(PBUF(JIJ, IT),PP(JIJ),PRSATI(JIJ))*PBUF(JIJ, I1PRT)
166 prsatw(jij) = prsatw(jij)*pbuf(jij, i1prt)
167 prsati(jij) = prsati(jij)*pbuf(jij, i1prt)
168 pbuf(jij, irvsat) = prsatw(jij)*(1-pfrac_ice(jij)) + prsati(jij)*pfrac_ice(jij)
169 pbuf(jij, idrsatodt) = (pbuf(jij, idrsatodtw)*(1-pfrac_ice(jij))+ &
170 & pbuf(jij, idrsatodti)*pfrac_ice(jij))
171
172 !Computation of new PRL, PRI and PRV
173 !Correction term applied to (PRV(JIJ)-PBUF(JIJ, IRVSAT)) is computed assuming that
174 !PBUF(JIJ, ILVOCPEXN), PBUF(JIJ, ILSOCPEXN) and PBUF(JIJ, ICPH) don't vary too much with T. It takes into account
175 !the variation (estimated linear) of Qsat with T
176 pbuf(jij, irltemp)=(prv(jij)-pbuf(jij, irvsat))/ &
177 &(1 + pbuf(jij, idrsatodt)*pbuf(jij, iexn)* &
178 & (pbuf(jij, ilvocpexn)*(1-pfrac_ice(jij))+pbuf(jij, ilsocpexn)*pfrac_ice(jij)))
179 pbuf(jij, irltemp)=min(max(-prl(jij)-pri(jij), pbuf(jij, irltemp)),prv(jij))
180 prv(jij)=prv(jij)-pbuf(jij, irltemp)
181 prl(jij)=prl(jij)+pri(jij)+pbuf(jij, irltemp)
182 pri(jij)=pfrac_ice(jij) * (prl(jij))
183 prl(jij)=(1-pfrac_ice(jij)) * (prt(jij) - prv(jij))
184
185 !Computation of Cph (as defined in Meso-NH doc, equation 2.2, to be used with mixing ratios)
186 pbuf(jij, icph)=cst%XCPD+ cst%XCPV * prv(jij)+ cst%XCL * prl(jij) + cst%XCI * pri(jij) + pbuf(jij, icph2)
187
188 !Computation of L/Cph/EXN, then new PTH
189 zvar2=pbuf(jij, icph)*pbuf(jij, iexn)
190 pbuf(jij, ilvocpexn) = (cst%XLVTT + (cst%XCPV-cst%XCL) * (pbuf(jij, it)-cst%XTT)) /zvar2
191 pbuf(jij, ilsocpexn) = (cst%XLSTT + (cst%XCPV-cst%XCI) * (pbuf(jij, it)-cst%XTT)) /zvar2
192 pth(jij)=pthl(jij)+pbuf(jij, ilvocpexn)*prl(jij)+pbuf(jij, ilsocpexn)*pri(jij)
193
194 !Computation of estimated mixing ration at saturation
195 !To compute the adjustement a first order development was used
196 zvar1=pth(jij)*pbuf(jij, iexn)-pbuf(jij, it)
197 prsatw(jij)=prsatw(jij) + pbuf(jij, idrsatodtw)*zvar1
198 prsati(jij)=prsati(jij) + pbuf(jij, idrsatodti)*zvar1
199 ENDDO
200ENDDO
201
202END SUBROUTINE th_r_from_thl_rt
elemental subroutine compute_frac_ice(cst, hfrac_ice, nebn, pfrac_ice, pt)
subroutine th_r_from_thl_rt(d, cst, nebn, hfrac_ice, pfrac_ice, pp, pthl, prt, pth, prv, prl, pri, prsatw, prsati, prr, prs, prg, prh, oocean, pbuf)