PHYEX 0.9.5
PHYsique EXternalisée
Loading...
Searching...
No Matches
mode_bl89.F90
Go to the documentation of this file.
1!MNH_LIC Copyright 1994-2025 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.
6
7!$ACDC singlecolumn
8
9IMPLICIT NONE
10CONTAINS
11! ######spl
12 SUBROUTINE bl89(D,CST,CSTURB,TURBN,PZZ,PDZZ,PTHVREF,PTHLM,KRR,PRM,PTKEM,PSHEAR,PLM,OOCEAN,PTURB_SPP)
13 USE yomhook , ONLY : lhook, dr_hook, jphook
14! #########################################################
15!
16!!**** *BL89* -
17!!
18!! PURPOSE
19!! -------
20!! This routine computes the mixing length from Bougeault-Lacarrere 89
21!! formula.
22!!
23!!** METHOD
24!! ------
25!!
26!! EXTERNAL
27!! --------
28!!
29!! IMPLICIT ARGUMENTS
30!! ------------------
31!!
32!!
33!! REFERENCE
34!! ---------
35!!
36!! Book 2
37!!
38!! AUTHOR
39!! ------
40!!
41!! J. Cuxart INM and Meteo-France
42!!
43!! MODIFICATIONS
44!! -------------
45!! Original 27/04/97 (V. Masson) separation from turb.f90
46!! and optimization
47!! 06/01/98 (V. Masson and P. Jabouille) optimization
48!! 15/03/99 (V. Masson) new lup ldown averaging
49!! 21/02/01 (P. Jabouille) improve vectorization
50!! 2012-02 (Y. Seity) add possibility to run with
51!! reversed vertical levels
52!! Philippe 13/02/2018: use ifdef MNH_REAL to prevent problems with intrinsics on Blue Gene/Q
53!! 01/2019 (Q. Rodier) support for RM17 mixing length
54!! 03/2021 (JL Redelsperger) Ocean model case
55!! 06/2021 (P. Marquet) correction of exponent on final length according to Lemarié et al. 2021
56!-------------------------------------------------------------------------------
57!
58!* 0. DECLARATIONS
59! ------------
60!
61USE modd_cst, ONLY: cst_t
62USE modd_cturb, ONLY: csturb_t
65USE modd_precision, ONLY: mnhreal
66!
67!
68IMPLICIT NONE
69!
70!* 0.1 Declaration of arguments
71! ------------------------
72!
73TYPE(dimphyex_t), INTENT(IN) :: D
74TYPE(cst_t), INTENT(IN) :: CST
75TYPE(csturb_t), INTENT(IN) :: CSTURB
76TYPE(turb_t), INTENT(IN) :: TURBN
77REAL, DIMENSION(D%NIJT,D%NKT), INTENT(IN) :: PZZ
78REAL, DIMENSION(D%NIJT,D%NKT), INTENT(IN) :: PDZZ
79REAL, DIMENSION(D%NIJT,D%NKT), INTENT(IN) :: PTHVREF
80REAL, DIMENSION(D%NIJT,D%NKT), INTENT(IN) :: PTHLM ! conservative pot. temp.
81INTEGER, INTENT(IN) :: KRR
82REAL, DIMENSION(D%NIJT,D%NKT,KRR), INTENT(IN) :: PRM ! water var.
83REAL, DIMENSION(D%NIJT,D%NKT), INTENT(IN) :: PTKEM ! TKE
84REAL, DIMENSION(D%NIJT,D%NKT), INTENT(IN) :: PSHEAR
85REAL, DIMENSION(D%NIJT,D%NKT), INTENT(OUT) :: PLM ! Mixing length
86LOGICAL, INTENT(IN) :: OOCEAN ! switch for Ocean model version
87REAL, DIMENSION(D%NIJT,D%NKT,NTURB_S), INTENT(IN) :: PTURB_SPP ! switch for Ocean model version
88! thermodynamical variables PTHLM=Theta at the begining
89!
90!* 0.2 Declaration of local variables
91! ------------------------------
92!
93INTEGER :: IKT,IKB,IKA,IKU
94
95REAL, DIMENSION(D%NIJT,D%NKT) :: ZVPT ! Virtual Potential Temp at half levels
96REAL, DIMENSION(D%NIJT,D%NKT) :: ZDELTVPT
97 ! Increment of Virtual Potential Temp between two following levels
98REAL, DIMENSION(D%NIJT,D%NKT) :: ZHLVPT
99 ! Virtual Potential Temp at half levels
100REAL, DIMENSION(D%NIJT,D%NKT) :: ZLWORK, ZLWORKUP
101REAL, DIMENSION(D%NIJT) :: ZINTE, ZTMP
102! ! downwards then upwards vertical displacement,
103! ! residual internal energy,
104! ! residual potential energy
105! ! input and output arrays packed according one horizontal coord.
106! ! input array packed according one horizontal coord.
107REAL, DIMENSION(D%NIJT,D%NKT) :: ZSUM ! to replace SUM function
108REAL, DIMENSION(D%NIJT,D%NKT) :: ZG_O_THVREF
109REAL, DIMENSION(D%NIJT,D%NKT) :: ZSQRT_TKE
110REAL, DIMENSION(D%NIJT,D%NKT) :: PLMDN
111!
112INTEGER :: IIJB, IIJE
113INTEGER :: IKTB, IKTE, IKE,IKL
114INTEGER :: JIJ ! horizontal loop counter
115INTEGER :: JK,JKK ! loop counters
116INTEGER :: JRR ! moist loop counter
117REAL :: ZRVORD ! Rv/Rd
118REAL :: ZPOTE,ZLWORK1,ZLWORK2
119REAL :: ZTEST,ZTEST0,ZTESTM ! test for vectorization
120!-------------------------------------------------------------------------------
121!
122REAL(KIND=jphook) :: zhook_handle
123IF (lhook) CALL dr_hook('BL89',0,zhook_handle)
124!
125zrvord = cst%XRV / cst%XRD
126!
127iijb=d%NIJB
128iije=d%NIJE
129iktb=d%NKTB
130ikte=d%NKTE
131ikt=d%NKT
132ikb=d%NKB
133ike=d%NKE
134ika=d%NKA
135iku=d%NKU
136ikl=d%NKL
137!-------------------------------------------------------------------------------
138!
139!* 1. pack the horizontal dimensions into one
140! ---------------------------------------
141!
142! Pointer remapping instead of RESHAPE (contiguous memory)
143! 2D array => 3D array
144!
145!$acc kernels
146IF (oocean) THEN
147!$acc loop independent collapse(2)
148 DO jk=1,ikt
149 DO jij=iijb,iije
150 zg_o_thvref(jij,jk) = cst%XG * cst%XALPHAOC
151 END DO
152 END DO
153ELSE !Atmosphere case
154!$acc loop independent collapse(2)
155 DO jk=1,ikt
156 DO jij=iijb,iije
157 zg_o_thvref(jij,jk) = cst%XG / pthvref(jij,jk)
158 END DO
159 END DO
160END IF
161!$acc end kernels
162!
163!$acc kernels
164!$mnh_expand_array(JIJ=IIJB:IIJE,JK=1:IKT)
165zsqrt_tke(iijb:iije,1:ikt) = sqrt(ptkem(iijb:iije,1:ikt))
166!$mnh_end_expand_array(JIJ=IIJB:IIJE,JK=1:IKT)
167!$acc end kernels
168!-------------------------------------------------------------------------------
169!
170!* 2. Virtual potential temperature on the model grid
171! -----------------------------------------------
172!
173 !$acc kernels
174IF(krr /= 0) THEN
175 !$mnh_expand_array(JIJ=IIJB:IIJE,JK=1:IKT)
176 zsum(iijb:iije,1:ikt) = 0.
177 !$mnh_end_expand_array(JIJ=IIJB:IIJE,JK=1:IKT)
178 DO jrr=1,krr
179 !$mnh_expand_array(JIJ=IIJB:IIJE,JK=1:IKT)
180 zsum(iijb:iije,1:ikt) = zsum(iijb:iije,1:ikt)+prm(iijb:iije,1:ikt,jrr)
181 !$mnh_end_expand_array(JIJ=IIJB:IIJE,JK=1:IKT)
182 ENDDO
183 !$mnh_expand_array(JIJ=IIJB:IIJE,JK=1:IKT)
184 zvpt(iijb:iije,1:ikt)=pthlm(iijb:iije,1:ikt) * ( 1. + zrvord*prm(iijb:iije,1:ikt,1) ) &
185 / ( 1. + zsum(iijb:iije,1:ikt) )
186 !$mnh_end_expand_array(JIJ=IIJB:IIJE,JK=1:IKT)
187ELSE
188 !$mnh_expand_array(JIJ=IIJB:IIJE,JK=1:IKT)
189 zvpt(iijb:iije,1:ikt)=pthlm(iijb:iije,1:ikt)
190 !$mnh_end_expand_array(JIJ=IIJB:IIJE,JK=1:IKT)
191END IF
192!$acc end kernels
193!
194!!!!!!!!!!!!
195!!!!!!!!!!!!
196!!!!!!!!!!!!!!!!!! WARNING !!
197!!!!!!!!!!!!
198!!!!!!!!!!!!
199!Any modification done to the following lines and to the sections 4 and
200!6 must be copied in compute_bl89_ml routine.
201!We do not call directly this routine for numerical performance reasons
202!but algorithm must remain the same.
203!!!!!!!!!!!!
204!
205!$acc kernels present_cr(ZLWORK,ZINTE)
206!$acc loop independent collapse(2)
207DO jk=iktb,ikte
208 DO jij=iijb,iije
209 zdeltvpt(jij,jk) = zvpt(jij,jk) - zvpt(jij,jk-ikl)
210 zhlvpt(jij,jk) = 0.5 * ( zvpt(jij,jk) + zvpt(jij,jk-ikl) )
211 END DO
212END DO
213!
214!$acc loop independent
215DO jij=iijb,iije
216 zdeltvpt(jij,iku) = zvpt(jij,iku) - zvpt(jij,iku-ikl)
217 zdeltvpt(jij,ika) = 0.
218 zhlvpt(jij,iku) = 0.5 * ( zvpt(jij,iku) + zvpt(jij,iku-ikl) )
219 zhlvpt(jij,ika) = zvpt(jij,ika)
220END DO
221!$acc end kernels
222!
223!$acc kernels
224!$acc loop independent collapse(2)
225DO jk=1,ikt
226 DO jij=iijb,iije
227 IF(abs(zdeltvpt(jij,jk))<csturb%XLINF) THEN
228 zdeltvpt(jij,jk)=csturb%XLINF
229 END IF
230 END DO
231END DO
232zlworkup(:,:) = 0.
233ztmp(:)=0.
234!$acc end kernels
235!
236!-------------------------------------------------------------------------------
237!
238!* 3. loop on model levels
239! --------------------
240!
241!$acc kernels create(ZTESTM)
242DO jk=iktb,ikte
243!Remark create(ZTESTM) to force the NVIDIA compiler 23.5 to manage correctly ZTESTM (implicit reduction)
244!
245!-------------------------------------------------------------------------------
246!
247!* 4. mixing length for a downwards displacement
248! ------------------------------------------
249 zinte(iijb:iije)=ptkem(iijb:iije,jk)
250 zlwork=0.
251 ztestm=1.
252!$acc loop seq
253 DO jkk=jk,ikb,-ikl
254 IF(ztestm > 0.) THEN
255 ztestm=0.
256 !!!$acc loop independent
257 !DO CONCURRENT(JIJ = IIBJ:IIJE)
258 DO jij=iijb,iije
259 ztest0=0.5+sign(0.5,zinte(jij))
260 !--------- SHEAR + STABILITY -----------
261 zpote = ztest0* &
262 (-zg_o_thvref(jij,jk)*(zhlvpt(jij,jkk)-zvpt(jij,jk)) &
263 + csturb%XRM17*pshear(jij,jkk)*zsqrt_tke(jij,jk) &
264 )*pdzz(jij,jkk)
265
266 ztest =0.5+sign(0.5,zinte(jij)-zpote)
267 ztestm=ztestm+ztest0
268 zlwork1=pdzz(jij,jkk)
269
270 !--------- SHEAR + STABILITY -----------
271 zlwork2 = (zg_o_thvref(jij,jk) *(zvpt(jij,jkk) - zvpt(jij,jk)) &
272 -csturb%XRM17*pshear(jij,jkk)*zsqrt_tke(jij,jk) &
273 + sqrt(abs( (csturb%XRM17*pshear(jij,jkk)*zsqrt_tke(jij,jk) &
274 + ( -zg_o_thvref(jij,jk) * (zvpt(jij,jkk) - zvpt(jij,jk)) ))**2.0 + &
275 2. * zinte(jij) * &
276 (zg_o_thvref(jij,jk) * zdeltvpt(jij,jkk)/ pdzz(jij,jkk))))) / &
277 (zg_o_thvref(jij,jk) * zdeltvpt(jij,jkk) / pdzz(jij,jkk))
278 zlwork(jij,jk)=zlwork(jij,jk)+ztest0*(ztest*zlwork1+(1-ztest)*zlwork2)
279 zinte(jij) = zinte(jij) - zpote
280 END DO
281 ENDIF
282 END DO
283!-------------------------------------------------------------------------------
284!
285!* 5. intermediate storage of the final mixing length
286! -----------------------------------------------
287!
288 !$acc loop independent
289 DO jij=iijb,iije
290 plmdn(jij,jk)=min(zlwork(jij,jk),0.5*(pzz(jij,jk)+pzz(jij,jk+ikl))-pzz(jij,ikb))
291 END DO
292!
293!-------------------------------------------------------------------------------
294!
295!* 6. mixing length for an upwards displacement
296! -----------------------------------------
297!
298 zinte(iijb:iije)=ptkem(iijb:iije,jk)
299 zlworkup(iijb:iije,jk)=0.
300 ztestm=1.
301!
302!$acc loop seq
303 DO jkk=jk+ikl,ike,ikl
304 IF(ztestm > 0.) THEN
305 ztestm=0.
306 !!!$acc loop independent
307 !DO CONCURRENT(JIJ = IIBJ:IIJE)
308 DO jij=iijb,iije
309 ztest0=0.5+sign(0.5,zinte(jij))
310 !--------- SHEAR + STABILITY -----------
311 zpote = ztest0* &
312 (zg_o_thvref(jij,jk)*(zhlvpt(jij,jkk)-zvpt(jij,jk)) &
313 +csturb%XRM17*pshear(jij,jkk)*zsqrt_tke(jij,jk) &
314 )*pdzz(jij,jkk)
315 ztest =0.5+sign(0.5,zinte(jij)-zpote)
316 ztestm=ztestm+ztest0
317 zlwork1=pdzz(jij,jkk)
318 !--------- SHEAR + STABILITY -----------
319 zlwork2= ( - zg_o_thvref(jij,jk) *(zvpt(jij,jkk-ikl) - zvpt(jij,jk) ) &
320 - csturb%XRM17*pshear(jij,jkk)*zsqrt_tke(jij,jk) &
321 + sqrt(abs( &
322 (csturb%XRM17*pshear(jij,jkk)*zsqrt_tke(jij,jk) &
323 + ( zg_o_thvref(jij,jk) * (zvpt(jij,jkk-ikl) - zvpt(jij,jk))) )**2 &
324 + 2. * zinte(jij) * &
325 (zg_o_thvref(jij,jk)* zdeltvpt(jij,jkk)/pdzz(jij,jkk))))) / &
326 (zg_o_thvref(jij,jk) * zdeltvpt(jij,jkk) / pdzz(jij,jkk))
327 zlworkup(jij,jk)=zlworkup(jij,jk)+ztest0*(ztest*zlwork1+(1-ztest)*zlwork2)
328 zinte(jij) = zinte(jij) - zpote
329 END DO
330 ENDIF
331 END DO
332END DO
333!
334!* Maximal length between JK and the levels below (as in ARPEGE)
335!
336IF (turbn%LBL89TOP) THEN
337 DO jk=ikte,iktb,ikl
338 DO jij=iijb,iije
339 ztmp(jij) = zlworkup(jij,jk-ikl)-pdzz(jij,jk)
340 ENDDO
341 DO jij=iijb,iije
342 zlworkup(jij,jk) = max(zlworkup(jij,jk),ztmp(jij))
343 ENDDO
344 ENDDO
345END IF
346!
347!
348!-------------------------------------------------------------------------------
349!
350!* 7. final mixing length
351!
352!$acc loop independent collapse(2)
353DO jk=iktb,ikte
354 DO jij=iijb,iije
355 zlwork1=max(plmdn(jij,jk),1.e-10_mnhreal)
356 zlwork2=max(zlworkup(jij,jk),1.e-10_mnhreal)
357 zpote = zlwork1 / zlwork2
358 zlwork2=1.d0 + zpote**pturb_spp(jij,jk,nbl89exp)
359 plm(jij,jk) = zlwork1*(2./zlwork2)**pturb_spp(jij,jk,nusrbl89)
360 plm(jij,jk)=max(plm(jij,jk),turbn%XLINI)
361 END DO
362END DO
363!$acc end kernels
364
365!-------------------------------------------------------------------------------
366!* 8. end of the loop on the vertical levels
367! --------------------------------------
368!
369!-------------------------------------------------------------------------------
370!
371!* 9. boundaries
372! ----------
373!
374!$acc kernels
375plm(iijb:iije,ika)=plm(iijb:iije,ikb)
376plm(iijb:iije,ike)=plm(iijb:iije,ike-ikl)
377plm(iijb:iije,iku)=plm(iijb:iije,ike-ikl)
378!
379!$acc end kernels
380!-------------------------------------------------------------------------------
381!
382!* 10. retrieve output array in model coordinates
383! ------------------------------------------
384! Not needed anymore because of the use of Pointer remapping (see 1.)
385! PLM (3D array) is the target of PLM (2D array) in a contiguous way
386!
387IF (lhook) CALL dr_hook('BL89',1,zhook_handle)
388END SUBROUTINE bl89
389END MODULE mode_bl89
integer, parameter mnhreal
integer, parameter nusrbl89
integer, parameter nbl89exp
integer, parameter nturb_s
subroutine bl89(d, cst, csturb, turbn, pzz, pdzz, pthvref, pthlm, krr, prm, ptkem, pshear, plm, oocean, pturb_spp)
Definition mode_bl89.F90:13