PHYEX 0.9.5
PHYsique EXternalisée
Loading...
Searching...
No Matches
ice4_pack.F90
Go to the documentation of this file.
1!MNH_LIC Copyright 1995-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.
5!-----------------------------------------------------------------
6SUBROUTINE ice4_pack(D, CST, PARAMI, ICEP, ICED, BUCONF, PTSTEP, &
7 &KRR, OSAVE_MICRO, LDMICRO, OELEC, &
8 &PEXN, PRHODREF, PPABST, PCIT, PCLDFR, &
9 &PHLC_HCF, PHLC_HRC, PHLI_HCF, PHLI_HRI, &
10 &PTHS, PRS, PRREVAV, PRAINFR, PSIGS, PTHT, PRT, &
11 &PICLDFR, PZZZ, PCONC3D, PSSIO, PSSIU, PIFR, &
12 &PBUDGETS, PLATHAM_IAGGS, PRCRIAUTI, PRCRIAUTC, PICENU)
13! ######################################################################
14!
15!!**** * - compute the explicit microphysical sources
16!!
17!! PURPOSE
18!! -------
19!! The purpose of this routine is to pack arrays to compute
20!! the microphysics tendencies
21!!
22!!
23!! METHOD
24!! ------
25!! Pack arrays by chuncks
26!!
27!!
28!! MODIFICATIONS
29!! -------------
30!! R. El Khatib 28-Apr-2023 Fix (and re-enable) the cache-blocking mechanism on top of phyex
31!! S. Riette Sept 23: all 3D arrays are suppressed from ice4_stepping
32! -----------------------------------------------------------------
33!
34!* 0. DECLARATIONS
35! ------------
36!
37USE yomhook , ONLY : lhook, dr_hook, jphook
38
41USE modd_cst, ONLY: cst_t
45USE modd_fields_address, ONLY : & ! common fields adress
46 & irv, & ! Water vapor
47 & irc, & ! Cloud water
48 & irr, & ! Rain water
49 & iri, & ! Pristine ice
50 & irs, & ! Snow/aggregate
51 & irg, & ! Graupel
52 & irh, & ! Hail
53 & ibunum, & ! Number of tendency terms
55! Number of extra tendency terms
56!
57USE modi_ice4_stepping, ONLY: ice4_stepping
58!
59IMPLICIT NONE
60
61!NOTES ON SIZES
62!If we pack:
63! - ISIZE is the number of relevant point (with mixing ratio different from 0)
64! - IPROMA is the size of bloc of points
65!If we do not pack:
66! - ISIZE is the total number of points
67! - IPROMA is null for memory saving
68!
69!When we do not pack, we can transmit directly the 3D arrays to the ice4_stepping subroutine, we do not need
70!to copy the values. It is why IPROMA is null because we do not need these arrays.
71
72
73!
74!* 0.1 Declarations of dummy arguments :
75!
76!
77!
78TYPE(dimphyex_t), INTENT(IN) :: D
79TYPE(cst_t), INTENT(IN) :: CST
80TYPE(param_ice_t), INTENT(IN) :: PARAMI
81TYPE(rain_ice_param_t), INTENT(IN) :: ICEP
82TYPE(rain_ice_descr_t), INTENT(IN) :: ICED
83TYPE(tbudgetconf_t), INTENT(IN) :: BUCONF
84REAL, INTENT(IN) :: PTSTEP ! Double Time step (single if cold start)
85INTEGER, INTENT(IN) :: KRR ! Number of moist variable
86LOGICAL, INTENT(IN) :: OSAVE_MICRO ! If true, microphysical tendencies are saved
87LOGICAL, INTENT(IN) :: OELEC ! if true, cloud electricity is activated
88LOGICAL, DIMENSION(D%NIJT,D%NKT), INTENT(IN) :: LDMICRO ! mask to limit computation
89!
90REAL, DIMENSION(D%NIJT,D%NKT), INTENT(IN) :: PEXN ! Exner function
91REAL, DIMENSION(D%NIJT,D%NKT), INTENT(IN) :: PRHODREF! Reference density
92REAL, DIMENSION(D%NIJT,D%NKT), INTENT(IN) :: PPABST ! absolute pressure at t
93!
94REAL, DIMENSION(D%NIJT,D%NKT), INTENT(INOUT) :: PCIT ! Pristine ice n.c. at t
95REAL, DIMENSION(D%NIJT,D%NKT), INTENT(IN) :: PCLDFR ! Cloud fraction
96REAL, DIMENSION(D%NIJT,D%NKT), INTENT(INOUT) :: PHLC_HCF
97REAL, DIMENSION(D%NIJT,D%NKT), INTENT(INOUT) :: PHLC_HRC
98REAL, DIMENSION(D%NIJT,D%NKT), INTENT(INOUT) :: PHLI_HCF
99REAL, DIMENSION(D%NIJT,D%NKT), INTENT(INOUT) :: PHLI_HRI
100!
101REAL, DIMENSION(D%NIJT,D%NKT), INTENT(INOUT) :: PTHS ! Theta source
102REAL, DIMENSION(D%NIJT,D%NKT,KRR), INTENT(INOUT) :: PRS ! m.r. source
103!
104REAL, DIMENSION(D%NIJT,D%NKT), INTENT(INOUT) :: PRREVAV! Rain evap profile
105REAL, DIMENSION(D%NIJT,D%NKT), INTENT(INOUT) :: PRAINFR !Precipitation fraction
106REAL, DIMENSION(D%NIJT,D%NKT), INTENT(IN) :: PSIGS ! Sigma_s at t
107REAL, DIMENSION(D%NIJT,D%NKT), INTENT(IN) :: PICLDFR
108REAL, DIMENSION(D%NIJT,D%NKT), INTENT(IN) :: PZZZ
109REAL, DIMENSION(D%NIJT,D%NKT), INTENT(IN) :: PCONC3D
110REAL, DIMENSION(D%NIJT,D%NKT), INTENT(IN) :: PSSIO ! Super-saturation with respect to ice in the supersaturated fraction
111REAL, DIMENSION(D%NIJT,D%NKT), INTENT(IN) :: PSSIU ! Sub-saturation with respect to ice in the subsaturated fraction
112REAL, DIMENSION(D%NIJT,D%NKT), INTENT(IN) :: PIFR ! Ratio cloud ice moist part to dry part
113REAL, DIMENSION(D%NIJT,D%NKT), INTENT(INOUT) :: PTHT
114REAL, DIMENSION(D%NIJT,D%NKT,7), INTENT(INOUT) :: PRT
115REAL, DIMENSION(MERGE(D%NIJT,0,OSAVE_MICRO .OR. BUCONF%LBU_ENABLE), & MERGE(D%NKT,0,OSAVE_MICRO .OR. BUCONF%LBU_ENABLE), & MERGE(IBUNUM-IBUNUM_EXTRA,0,OSAVE_MICRO .OR. BUCONF%LBU_ENABLE)), &
116 INTENT(OUT) :: PBUDGETS ! Microphysical tendencies
117REAL, DIMENSION(MERGE(D%NIJT,0,OELEC),MERGE(D%NKT,0,OELEC)), &
118 OPTIONAL, INTENT(IN) :: PLATHAM_IAGGS ! E Function to simulate
119 ! enhancement of IAGGS
120! SPP perturbation arrays
121REAL, DIMENSION(D%NIJT), OPTIONAL, INTENT(IN) :: PRCRIAUTI
122REAL, DIMENSION(D%NIJT), OPTIONAL, INTENT(IN) :: PRCRIAUTC
123REAL, DIMENSION(D%NIJT), OPTIONAL, INTENT(IN) :: PICENU
124!
125!
126!* 0.2 Declarations of local variables :
127!
128REAL(KIND=jphook) :: zhook_handle
129REAL, DIMENSION(D%NIJT) :: ZPRCRIAUTI, ZPRCRIAUTC, ZPICENU ! SPP perturbations
130!
131INTEGER :: IPROMA ! cache-blocking factor for microphysic loop
132INTEGER :: ISIZE
133INTEGER :: IGPBLKS
134INTEGER :: JIJ, JK
135INTEGER :: IKT, IKTB, IKTE, IIJT, IIJB, IIJE
136INTEGER :: ISTIJ, ISTK
137!
138!For packing
139INTEGER :: IMICRO ! Case r_x>0 locations
140INTEGER :: JL, JV
141!
142INTEGER :: IC, JMICRO, IDX
143LOGICAL :: LLSIGMA_RC, LL_AUCV_ADJU
144TYPE(dimphyex_t) :: DD
145!
146!-------------------------------------------------------------------------------
147IF (lhook) CALL dr_hook('ICE4_PACK', 0, zhook_handle)
148!
149!* 1. GENERALITIES
150! ------------
151!
152ikt=d%NKT
153iktb=d%NKTB
154ikte=d%NKTE
155iijt=d%NIJT
156iijb=d%NIJB
157iije=d%NIJE
158!
159!SPP perturbations (default values if absent)
160IF (PRESENT(prcriauti)) THEN
161!$acc kernels
162 !$mnh_expand_array(JIJ=IIJB:IIJE)
163 zprcriauti(iijb:iije) = prcriauti(iijb:iije)
164 !$mnh_end_expand_array(JIJ=IIJB:IIJE)
165!$acc end kernels
166ELSE
167!$acc kernels
168 zprcriauti(iijb:iije) = icep%XCRIAUTI
169!$acc end kernels
170ENDIF
171IF (PRESENT(prcriautc)) THEN
172!$acc kernels
173 !$mnh_expand_array(JIJ=IIJB:IIJE)
174 zprcriautc(iijb:iije) = prcriautc(iijb:iije)
175 !$mnh_end_expand_array(JIJ=IIJB:IIJE)
176!$acc end kernels
177ELSE
178!$acc kernels
179 zprcriautc(iijb:iije) = icep%XCRIAUTC
180!$acc end kernels
181ENDIF
182IF (PRESENT(picenu)) THEN
183!$acc kernels
184 !$mnh_expand_array(JIJ=IIJB:IIJE)
185 zpicenu(iijb:iije) = picenu(iijb:iije)
186 !$mnh_end_expand_array(JIJ=IIJB:IIJE)
187!$acc end kernels
188ELSE
189!$acc kernels
190 zpicenu(iijb:iije) = 1.
191!$acc end kernels
192ENDIF
193!
194llsigma_rc=(parami%CSUBG_AUCV_RC=='PDF ' .AND. parami%CSUBG_PR_PDF=='SIGM')
195ll_aucv_adju=(parami%CSUBG_AUCV_RC=='ADJU' .OR. parami%CSUBG_AUCV_RI=='ADJU')
196!
197isize=0
198
199DO jk=1,d%NKT
200 DO jij=1,d%NIJT
201 IF(ldmicro(jij,jk)) isize=isize+1 ! Number of points with active microphysics
202 END DO
203END DO
204!PARAMI%NPROMICRO is the requested size for cache_blocking loop
205!IPROMA is the effective size
206!This parameter must be computed here because it is used for array dimensioning in ice4_pack
207IF (parami%NPROMICRO > 0 .AND. isize > 0) THEN
208 ! Cache-blocking is active
209 ! number of chunks :
210 igpblks = (isize-1)/min(parami%NPROMICRO,isize)+1
211 ! Adjust IPROMA to limit the number of small chunks
212 iproma=(isize-1)/igpblks+1
213ELSE
214 iproma=isize ! no cache-blocking
215ENDIF
216
218!
219IF (lhook) CALL dr_hook('ICE4_PACK', 1, zhook_handle)
220
221CONTAINS
222
223SUBROUTINE ice4_pack_loop
224
225REAL, DIMENSION(IPROMA) :: &
226 & ZCIT, & ! Pristine ice conc. at t
227 & ZICLDFR, & ! Ice cloud fraction
228 & ZZZZ, & ! model level height
229 & ZCONC3D, & ! Cloud droplet number concentration at t
230 & ZSSIO, & ! Super-saturation with respect to ice in the supersaturated fraction
231 & ZSSIU, & ! Sub-saturation with respect to ice in the subsaturated fraction
232 & ZIFR, & ! Ratio cloud ice moist part to dry part
233 & ZRHODREF, & ! RHO Dry REFerence
234 & ZPABST, & ! Pressure
235 & ZEXN, & ! EXNer Pressure
236 & ZCLDFR, & ! Cloud fraction
237 & ZHLC_HCF, & ! HLCLOUDS : fraction of High Cloud Fraction in grid
238 & ZHLC_HRC, & ! HLCLOUDS : LWC that is High LWC in grid
239 & ZHLI_HCF, &
240 & ZHLI_HRI, &
241 & ZRAINFR, &
242 & ZRREVAV, &
243 & ZSIGS, & ! Standard deviation of rc at time t
244 & ZTHT, &
245 & ZTHS, &
246 & ZCRIT, & ! SPP ri->rs threshold (packed)
247 & ZCRTC, & ! SPP rc->rr threshold (packed)
248 & ZICENU ! SPP nucleation factor (packed)
249LOGICAL, DIMENSION(IPROMA) :: LLMICRO
250!
251!Output packed tendencies (for budgets only)
252REAL, DIMENSION(IPROMA, IBUNUM-IBUNUM_EXTRA) :: ZBUDGETS
253!
254REAL, DIMENSION(IPROMA,7) :: ZRT !Packed variables
255REAL, DIMENSION(IPROMA,7) :: ZRS !To take into acount external tendencies inside the splitting
256!
257!For retroaction of E on IAGGS
258REAL, DIMENSION(MERGE(IPROMA,0,OELEC)) :: ZLATHAM_IAGGS
259!
260INTEGER, DIMENSION(IPROMA) :: I1,I2 ! Used to replace the COUNT and PACK intrinsics on variables
261
262!
263!* 2. POINT SELECTION
264! ---------------
265!
266! optimization by looking for locations where
267! the microphysical fields are larger than a minimal value only !!!
268!
269pbudgets(:,:,:)=0.
270
271IF (isize == 0) RETURN
272
273!
274!* 3. CACHE-BLOCKING LOOP
275! -------------------
276!
277
278! starting indexes :
279ic=0
280istk=iktb
281istij=iijb
282DO jmicro=1,isize,iproma
283
284 imicro=min(iproma,isize-jmicro+1)
285 !
286 !* 4. PACKING
287 ! -------
288 !
289
290 ! Setup packing parameters
291!$acc kernels
292!$acc loop seq
293 outer_loop: DO jk = istk, ikte
294 IF (any(ldmicro(iijb:iije,jk))) THEN
295 !$acc loop gang vector independent
296 DO jij = istij, iije
297 IF (ldmicro(jij,jk)) THEN
298 !$acc atomic capture
299 ic=ic+1
300 idx=ic !change of variable to use acc atomic capture (IC is shared)
301 !$acc end atomic
302 llmicro(idx)=.true.
303 ! Initialization of variables in packed format :
304 ztht(idx)=ptht(jij, jk)
305 zrt(idx, irv)=prt(jij, jk, irv)
306 zrt(idx, irc)=prt(jij, jk, irc)
307 zrt(idx, irr)=prt(jij, jk, irr)
308 zrt(idx, iri)=prt(jij, jk, iri)
309 zrt(idx, irs)=prt(jij, jk, irs)
310 zrt(idx, irg)=prt(jij, jk, irg)
311 IF (krr==7) THEN
312 zrt(idx, irh)=prt(jij, jk, irh)
313 ENDIF
314 IF (parami%LEXT_TEND) THEN
315 !The th tendency is not related to a mixing ratio change, there is no exn/exnref issue here
316 zths(idx)=pths(jij, jk)
317 zrs(idx, irv)=prs(jij, jk, irv)
318 zrs(idx, irc)=prs(jij, jk, irc)
319 zrs(idx, irr)=prs(jij, jk, irr)
320 zrs(idx, iri)=prs(jij, jk, iri)
321 zrs(idx, irs)=prs(jij, jk, irs)
322 zrs(idx, irg)=prs(jij, jk, irg)
323 IF (krr==7) THEN
324 zrs(idx, irh)=prs(jij, jk, irh)
325 ENDIF
326 ENDIF
327 zcit(idx)=pcit(jij, jk)
328 zcldfr(idx)=pcldfr(jij, jk)
329 zrhodref(idx)=prhodref(jij, jk)
330 zpabst(idx)=ppabst(jij, jk)
331 zexn(idx)=pexn(jij, jk)
332 zcrit(idx)=zprcriauti(jij)
333 zcrtc(idx)=zprcriautc(jij)
334 zicenu(idx)=zpicenu(jij)
335 zicldfr(idx)=picldfr(jij, jk)
336 zzzz(idx)=pzzz(jij, jk)
337 zconc3d(idx)=pconc3d(jij, jk)
338 zssio(idx)=pssio(jij, jk)
339 zssiu(idx)=pssiu(jij, jk)
340 zifr(idx)=pifr(jij, jk)
341 IF(llsigma_rc) THEN
342 zsigs(idx) =psigs(jij, jk)
343 ENDIF
344 IF (ll_aucv_adju) THEN
345 zhlc_hcf(idx) = phlc_hcf(jij, jk)
346 zhlc_hrc(idx) = phlc_hrc(jij, jk)
347 zhli_hcf(idx) = phli_hcf(jij, jk)
348 zhli_hri(idx) = phli_hri(jij, jk)
349 ENDIF
350 zrainfr(ic)=prainfr(jij, jk)
351 IF (oelec) zlatham_iaggs(ic) = platham_iaggs(jij, jk)
352 ! Save indices for later usages:
353 i1(idx) = jij
354 i2(idx) = jk
355 IF (ic==imicro) THEN
356 ! the end of the chunk has been reached, then reset the starting index :
357 istij=jij+1
358 IF (istij <= iije) THEN
359 !$acc atomic write
360 istk=jk
361 !$acc end atomic
362 ELSE
363 ! end of line, restart from 1 and increment upper loop
364 istij=d%NIJB
365 !$acc atomic write
366 istk=jk+1
367 !$acc end atomic
368 IF (istk > ikte) THEN
369 ! end of line, restart from 1
370 !$acc atomic write
371 istk=iktb
372 !$acc end atomic
373 ENDIF
374 ENDIF
375#ifndef MNH_OPENACC
376 ic=0
377 EXIT outer_loop
378#endif
379 ENDIF
380 ENDIF
381 ENDDO
382 ENDIF
383 ! restart inner loop on JIJ :
384 istij=iijb
385 ENDDO outer_loop
386!$acc end kernels
387 !
388 !* 5. TENDENCIES COMPUTATION
389 ! ----------------------
390 !
391
392 dd = d
393 dd%NIJT = iproma
394 dd%NIJB = 1
395 dd%NIJE = imicro
396
397 CALL ice4_stepping(dd, cst, parami, icep, iced, buconf, ptstep, &
398 &krr, osave_micro, llmicro, oelec, &
399 &zexn, zrhodref, &
400 &zpabst, zcit, zcldfr, &
401 &zhlc_hcf, zhlc_hrc, &
402 &zhli_hcf, zhli_hri, &
403 &zths, zrs, zrrevav, &
404 &zrainfr, zsigs, &
405 &ztht, zrt, &
406 &zicldfr, zzzz, zconc3d, &
407 &zssio, zssiu, zifr, &
408 &zbudgets, &
409 &zlatham_iaggs, zcrit, zcrtc, zicenu)
410 !
411 !* 6. UNPACKING
412 ! ---------
413 !
414!$acc kernels
415!$acc loop independent
416 DO jl=1, imicro
417 pcit(i1(jl),i2(jl))=zcit(jl)
418 prrevav(i1(jl),i2(jl))=zrrevav(jl)
419 prt(i1(jl),i2(jl),irv)=zrt(jl, irv)
420 prt(i1(jl),i2(jl),irc)=zrt(jl, irc)
421 prt(i1(jl),i2(jl),irr)=zrt(jl, irr)
422 prt(i1(jl),i2(jl),iri)=zrt(jl, iri)
423 prt(i1(jl),i2(jl),irs)=zrt(jl, irs)
424 prt(i1(jl),i2(jl),irg)=zrt(jl, irg)
425 IF (krr==7) THEN
426 prt(i1(jl),i2(jl),irh)=zrt(jl, irh)
427 ENDIF
428 prainfr(i1(jl),i2(jl))=zrainfr(jl)
429 ENDDO
430!$acc end kernels
431 IF(buconf%LBU_ENABLE .OR. osave_micro) THEN
432!$acc kernels
433!$acc loop independent collapse(2)
434 DO jv=1, ibunum-ibunum_extra
435 DO jl=1, imicro
436 pbudgets(i1(jl),i2(jl),jv)=zbudgets(jl, jv)
437 ENDDO
438 ENDDO
439!$acc end kernels
440 ENDIF
441
442
443ENDDO ! JMICRO
444
445END SUBROUTINE ice4_pack_loop
446
447END SUBROUTINE ice4_pack
448
subroutine ice4_pack(d, cst, parami, icep, iced, buconf, ptstep, krr, osave_micro, ldmicro, oelec, pexn, prhodref, ppabst, pcit, pcldfr, phlc_hcf, phlc_hrc, phli_hcf, phli_hri, pths, prs, prrevav, prainfr, psigs, ptht, prt, picldfr, pzzz, pconc3d, pssio, pssiu, pifr, pbudgets, platham_iaggs, prcriauti, prcriautc, picenu)
Definition ice4_pack.F90:13
subroutine ice4_pack_loop
subroutine ice4_stepping(d, cst, parami, icep, iced, buconf, ptstep, krr, osave_micro, ldmicro, oelec, pexn, prhodref, ppabst, pcit, pcldfr, phlc_hcf, phlc_hrc, phli_hcf, phli_hri, pths, prs, prrevav, prainfr, psigs, ptht, prt, picldfr, pzzz, pconc3d, pssio, pssiu, pifr, pbudgets, platham_iaggs, prcriauti, prcriautc, picenu)
integer, parameter ibunum_extra
integer, parameter ibunum