source: LMDZ6/trunk/libf/phylmd/flott_gwd_rando_m.f90 @ 5300

Last change on this file since 5300 was 5285, checked in by abarral, 5 weeks ago

As discussed internally, remove generic ONLY: ... for new _mod_h modules

  • Property copyright set to
    Name of program: LMDZ
    Creation date: 1984
    Version: LMDZ5
    License: CeCILL version 2
    Holder: Laboratoire de m\'et\'eorologie dynamique, CNRS, UMR 8539
    See the license file in the root directory.
  • Property svn:keywords set to Id
File size: 15.2 KB
Line 
1!
2! $Id: flott_gwd_rando_m.f90 5285 2024-10-28 13:33:29Z abarral $
3!
4module FLOTT_GWD_rando_m
5
6  USE clesphys_mod_h
7      implicit none
8
9contains
10
11  SUBROUTINE FLOTT_GWD_rando(DTIME, pp, tt, uu, vv, prec, zustr, zvstr, d_u, &
12       d_v,east_gwstress,west_gwstress)
13
14    ! Parametrization of the momentum flux deposition due to a discrete
15    ! number of gravity waves.
16    ! Author: F. Lott
17    ! July, 12th, 2012
18    ! Gaussian distribution of the source, source is precipitation
19    ! Reference: Lott (JGR, vol 118, page 8897, 2013)
20
21    !ONLINE:
22      USE yomcst_mod_h
23use dimphy, only: klon, klev
24      use assert_m, only: assert
25      USE ioipsl_getin_p_mod, ONLY : getin_p
26      USE vertical_layers_mod, ONLY : presnivs
27      CHARACTER (LEN=20) :: modname='flott_gwd_rando'
28      CHARACTER (LEN=80) :: abort_message
29
30
31    ! OFFLINE:
32    ! include "dimensions_mod.f90"
33    ! include "dimphy.h"
34    ! END OF DIFFERENCE ONLINE-OFFLINE
35    include "YOEGWD.h"
36
37    ! 0. DECLARATIONS:
38
39    ! 0.1 INPUTS
40    REAL, intent(in)::DTIME ! Time step of the Physics
41    REAL, intent(in):: pp(:, :) ! (KLON, KLEV) Pressure at full levels
42    REAL, intent(in):: prec(:) ! (klon) Precipitation (kg/m^2/s)
43    REAL, intent(in):: TT(:, :) ! (KLON, KLEV) Temp at full levels
44    REAL, intent(in):: UU(:, :) ! (KLON, KLEV) Zonal wind at full levels
45    REAL, intent(in):: VV(:, :) ! (KLON, KLEV) Merid wind at full levels
46
47    ! 0.2 OUTPUTS
48    REAL, intent(out):: zustr(:), zvstr(:) ! (KLON) Surface Stresses
49
50    REAL, intent(inout):: d_u(:, :), d_v(:, :)
51    REAL, intent(inout):: east_gwstress(:, :) !  Profile of eastward stress
52    REAL, intent(inout):: west_gwstress(:, :) !  Profile of westward stress
53
54    ! (KLON, KLEV) tendencies on winds
55
56    ! O.3 INTERNAL ARRAYS
57    REAL BVLOW(klon)
58    REAL DZ   !  Characteristic depth of the Source
59
60    INTEGER II, JJ, LL
61
62    ! 0.3.0 TIME SCALE OF THE LIFE CYCLE OF THE WAVES PARAMETERIZED
63
64    REAL DELTAT
65
66    ! 0.3.1 GRAVITY-WAVES SPECIFICATIONS
67
68    INTEGER, PARAMETER:: NK = 2, NP = 2, NO = 2, NW = NK * NP * NO
69    INTEGER JK, JP, JO, JW
70    INTEGER, PARAMETER:: NA = 5  !number of realizations to get the phase speed
71    REAL KMIN, KMAX ! Min and Max horizontal wavenumbers
72    REAL CMAX ! standard deviation of the phase speed distribution
73    REAL RUWMAX,SAT  ! ONLINE SPECIFIED IN run.def
74    REAL CPHA ! absolute PHASE VELOCITY frequency
75    REAL ZK(NW, KLON) ! Horizontal wavenumber amplitude
76    REAL ZP(NW, KLON) ! Horizontal wavenumber angle
77    REAL ZO(NW, KLON) ! Absolute frequency !
78
79    ! Waves Intr. freq. at the 1/2 lev surrounding the full level
80    REAL ZOM(NW, KLON), ZOP(NW, KLON)
81
82    ! Wave EP-fluxes at the 2 semi levels surrounding the full level
83    REAL WWM(NW, KLON), WWP(NW, KLON)
84
85    REAL RUW0(NW, KLON) ! Fluxes at launching level
86
87    REAL RUWP(NW, KLON), RVWP(NW, KLON)
88    ! Fluxes X and Y for each waves at 1/2 Levels
89
90    INTEGER LAUNCH, LTROP ! Launching altitude and tropo altitude
91
92    REAL XLAUNCH ! Controle the launching altitude
93    REAL XTROP ! SORT of Tropopause altitude
94    REAL RUW(KLON, KLEV + 1) ! Flux x at semi levels
95    REAL RVW(KLON, KLEV + 1) ! Flux y at semi levels
96
97    REAL PRMAX ! Maximum value of PREC, and for which our linear formula
98    ! for GWs parameterisation apply
99
100    ! 0.3.2 PARAMETERS OF WAVES DISSIPATIONS
101
102    REAL RDISS, ZOISEC ! COEFF DE DISSIPATION, SECURITY FOR INTRINSIC FREQ
103
104    ! 0.3.3 BACKGROUND FLOW AT 1/2 LEVELS AND VERTICAL COORDINATE
105
106    REAL H0 ! Characteristic Height of the atmosphere
107    REAL PR, TR ! Reference Pressure and Temperature
108
109    REAL ZH(KLON, KLEV + 1) ! Log-pressure altitude
110
111    REAL UH(KLON, KLEV + 1), VH(KLON, KLEV + 1) ! Winds at 1/2 levels
112    REAL PH(KLON, KLEV + 1) ! Pressure at 1/2 levels
113    REAL PSEC ! Security to avoid division by 0 pressure
114    REAL BV(KLON, KLEV + 1) ! Brunt Vaisala freq. (BVF) at 1/2 levels
115    REAL BVSEC ! Security to avoid negative BVF
116    REAL RAN_NUM_1,RAN_NUM_2,RAN_NUM_3
117
118    REAL, DIMENSION(klev+1) ::HREF
119
120    LOGICAL, SAVE :: gwd_reproductibilite_mpiomp=.true.
121    LOGICAL, SAVE :: firstcall = .TRUE.
122  !$OMP THREADPRIVATE(firstcall,gwd_reproductibilite_mpiomp)
123
124
125  IF (firstcall) THEN
126    ! Cle introduite pour resoudre un probleme de non reproductibilite
127    ! Le but est de pouvoir tester de revenir a la version precedenete
128    ! A eliminer rapidement
129    CALL getin_p('gwd_reproductibilite_mpiomp',gwd_reproductibilite_mpiomp)
130    IF (NW+3*NA>=KLEV) THEN
131       abort_message = 'NW+3*NA>=KLEV Probleme pour generation des ondes'
132       CALL abort_physic (modname,abort_message,1)
133    ENDIF
134    firstcall=.false.
135  ENDIF
136
137
138    !-----------------------------------------------------------------
139
140    ! 1. INITIALISATIONS
141
142    ! 1.1 Basic parameter
143
144    ! Are provided from elsewhere (latent heat of vaporization, dry
145    ! gaz constant for air, gravity constant, heat capacity of dry air
146    ! at constant pressure, earth rotation rate, pi).
147
148    ! 1.2 Tuning parameters of V14
149
150   
151    RDISS = 0.5 ! Diffusion parameter
152    ! ONLINE
153      RUWMAX=GWD_RANDO_RUWMAX
154      SAT=gwd_rando_sat
155    !END ONLINE
156    ! OFFLINE
157    ! RUWMAX= 1.75    ! Launched flux
158    ! SAT=0.25     ! Saturation parameter
159    ! END OFFLINE
160
161    PRMAX = 20. / 24. /3600.
162    ! maximum of rain for which our theory applies (in kg/m^2/s)
163
164 ! Characteristic depth of the source
165    DZ = 1000.
166    XLAUNCH=0.5 ! Parameter that control launching altitude
167    XTROP=0.2 ! Parameter that control tropopause altitude
168    DELTAT=24.*3600. ! Time scale of the waves (first introduced in 9b)
169    !  OFFLINE
170    !  DELTAT=DTIME
171    !  END OFFLINE
172
173    KMIN = 2.E-5
174    ! minimum horizontal wavenumber (inverse of the subgrid scale resolution)
175
176    KMAX = 1.E-3 ! Max horizontal wavenumber
177    CMAX = 30. ! Max phase speed velocity
178
179    TR = 240. ! Reference Temperature
180    PR = 101300. ! Reference pressure
181    H0 = RD * TR / RG ! Characteristic vertical scale height
182
183    BVSEC = 5.E-3 ! Security to avoid negative BVF
184    PSEC = 1.E-6 ! Security to avoid division by 0 pressure
185    ZOISEC = 1.E-6 ! Security FOR 0 INTRINSIC FREQ
186
187IF (1==0) THEN
188    !ONLINE
189        call assert(klon == (/size(pp, 1), size(tt, 1), size(uu, 1), &
190         size(vv, 1), size(zustr), size(zvstr), size(d_u, 1), &
191         size(d_v, 1), &
192         size(east_gwstress, 1), size(west_gwstress, 1) /), &
193         "FLOTT_GWD_RANDO klon")
194     call assert(klev == (/size(pp, 2), size(tt, 2), size(uu, 2), &
195          size(vv, 2), size(d_u, 2), size(d_v, 2), &
196          size(east_gwstress,2), size(west_gwstress,2) /), &
197          "FLOTT_GWD_RANDO klev")
198    !END ONLINE
199ENDIF
200
201    IF(DELTAT < DTIME)THEN
202       abort_message='flott_gwd_rando: deltat < dtime!'
203       CALL abort_physic(modname,abort_message,1)
204    ENDIF
205
206    IF (KLEV < NW) THEN
207       abort_message='flott_gwd_rando: you will have problem with random numbers'
208       CALL abort_physic(modname,abort_message,1)
209    ENDIF
210
211    ! 2. EVALUATION OF THE BACKGROUND FLOW AT SEMI-LEVELS
212
213    ! Pressure and Inv of pressure
214    DO LL = 2, KLEV
215       PH(:, LL) = EXP((LOG(PP(:, LL)) + LOG(PP(:, LL - 1))) / 2.)
216    end DO
217    PH(:, KLEV + 1) = 0.
218    PH(:, 1) = 2. * PP(:, 1) - PH(:, 2)
219
220    ! Launching altitude
221
222    !Pour revenir a la version non reproductible en changeant le nombre de process
223    IF (gwd_reproductibilite_mpiomp) THEN
224       ! Reprend la formule qui calcule PH en fonction de PP=play
225       DO LL = 2, KLEV
226          HREF(LL) = EXP((LOG(presnivs(LL)) + LOG(presnivs(LL - 1))) / 2.)
227       end DO
228       HREF(KLEV + 1) = 0.
229       HREF(1) = 2. * presnivs(1) - HREF(2)
230    ELSE
231       HREF(1:KLEV)=PH(KLON/2,1:KLEV)
232    ENDIF
233
234    LAUNCH=0
235    LTROP =0
236    DO LL = 1, KLEV
237       IF (HREF(LL) / HREF(1) > XLAUNCH) LAUNCH = LL
238    ENDDO
239    DO LL = 1, KLEV
240       IF (HREF(LL) / HREF(1) > XTROP) LTROP = LL
241    ENDDO
242    !LAUNCH=22 ; LTROP=33
243!   print*,'LAUNCH=',LAUNCH,'LTROP=',LTROP
244
245    ! Log pressure vert. coordinate
246    DO LL = 1, KLEV + 1
247       ZH(:, LL) = H0 * LOG(PR / (PH(:, LL) + PSEC))
248    end DO
249
250    ! BV frequency
251    DO LL = 2, KLEV
252       ! BVSEC: BV Frequency (UH USED IS AS A TEMPORARY ARRAY DOWN TO WINDS)
253       UH(:, LL) = 0.5 * (TT(:, LL) + TT(:, LL - 1)) &
254            * RD**2 / RCPD / H0**2 + (TT(:, LL) &
255            - TT(:, LL - 1)) / (ZH(:, LL) - ZH(:, LL - 1)) * RD / H0
256    end DO
257    BVLOW(:) = 0.5 * (TT(:, LTROP )+ TT(:, LAUNCH)) &
258         * RD**2 / RCPD / H0**2 + (TT(:, LTROP ) &
259         - TT(:, LAUNCH))/(ZH(:, LTROP )- ZH(:, LAUNCH)) * RD / H0
260
261    UH(:, 1) = UH(:, 2)
262    UH(:, KLEV + 1) = UH(:, KLEV)
263    BV(:, 1) = UH(:, 2)
264    BV(:, KLEV + 1) = UH(:, KLEV)
265    ! SMOOTHING THE BV HELPS
266    DO LL = 2, KLEV
267       BV(:, LL)=(UH(:, LL+1)+2.*UH(:, LL)+UH(:, LL-1))/4.
268    end DO
269
270    BV=MAX(SQRT(MAX(BV, 0.)), BVSEC)
271    BVLOW=MAX(SQRT(MAX(BVLOW, 0.)), BVSEC)
272
273
274    ! WINDS
275    DO LL = 2, KLEV
276       UH(:, LL) = 0.5 * (UU(:, LL) + UU(:, LL - 1)) ! Zonal wind
277       VH(:, LL) = 0.5 * (VV(:, LL) + VV(:, LL - 1)) ! Meridional wind
278    end DO
279    UH(:, 1) = 0.
280    VH(:, 1) = 0.
281    UH(:, KLEV + 1) = UU(:, KLEV)
282    VH(:, KLEV + 1) = VV(:, KLEV)
283
284    ! 3 WAVES CHARACTERISTICS CHOSEN RANDOMLY AT THE LAUNCH ALTITUDE
285
286    ! The mod functions of weird arguments are used to produce the
287    ! waves characteristics in an almost stochastic way
288
289    DO JW = 1, NW
290             ! Angle
291             DO II = 1, KLON
292                ! Angle (0 or PI so far)
293                RAN_NUM_1=MOD(TT(II, JW) * 10., 1.)
294                RAN_NUM_2= MOD(TT(II, JW) * 100., 1.)
295                ZP(JW, II) = (SIGN(1., 0.5 - RAN_NUM_1) + 1.) &
296                     * RPI / 2.
297                ! Horizontal wavenumber amplitude
298                ZK(JW, II) = KMIN + (KMAX - KMIN) *RAN_NUM_2
299                ! Horizontal phase speed
300                CPHA = 0.
301                DO JJ = 1, NA
302                    RAN_NUM_3=MOD(TT(II, JW+3*JJ)**2, 1.)
303                    CPHA = CPHA + &
304                    CMAX*2.*(RAN_NUM_3 -0.5)*SQRT(3.)/SQRT(NA*1.)
305                END DO
306                IF (CPHA.LT.0.)  THEN
307                   CPHA = -1.*CPHA
308                   ZP(JW,II) = ZP(JW,II) + RPI
309                ENDIF
310                ! Absolute frequency is imposed
311                ZO(JW, II) = CPHA * ZK(JW, II)
312                ! Intrinsic frequency is imposed
313                ZO(JW, II) = ZO(JW, II) &
314                     + ZK(JW, II) * COS(ZP(JW, II)) * UH(II, LAUNCH) &
315                     + ZK(JW, II) * SIN(ZP(JW, II)) * VH(II, LAUNCH)
316                ! Momentum flux at launch lev
317                RUW0(JW, II) = RUWMAX
318             ENDDO
319    ENDDO
320
321    ! 4. COMPUTE THE FLUXES
322
323    ! 4.1 Vertical velocity at launching altitude to ensure
324    ! the correct value to the imposed fluxes.
325
326    DO JW = 1, NW
327
328       ! Evaluate intrinsic frequency at launching altitude:
329       ZOP(JW, :) = ZO(JW, :) &
330            - ZK(JW, :) * COS(ZP(JW, :)) * UH(:, LAUNCH) &
331            - ZK(JW, :) * SIN(ZP(JW, :)) * VH(:, LAUNCH)
332
333       ! VERSION WITH CONVECTIVE SOURCE
334
335       ! Vertical velocity at launch level, value to ensure the
336       ! imposed factor related to the convective forcing:
337       ! precipitations.
338
339       ! tanh limitation to values above prmax:
340       WWP(JW, :) = RUW0(JW, :) &
341            * (RD / RCPD / H0 * RLVTT * PRMAX * TANH(PREC(:) / PRMAX))**2
342
343       ! Factor related to the characteristics of the waves:
344       WWP(JW, :) = WWP(JW, :) * ZK(JW, :)**3 / KMIN / BVLOW(:)  &
345            / MAX(ABS(ZOP(JW, :)), ZOISEC)**3
346
347       ! Moderation by the depth of the source (dz here):
348       WWP(JW, :) = WWP(JW, :) &
349            * EXP(- BVLOW(:)**2 / MAX(ABS(ZOP(JW, :)), ZOISEC)**2 * ZK(JW, :)**2 &
350            * DZ**2)
351
352       ! Put the stress in the right direction:
353       RUWP(JW, :) = ZOP(JW, :) / MAX(ABS(ZOP(JW, :)), ZOISEC)**2 &
354            * BV(:, LAUNCH) * COS(ZP(JW, :)) * WWP(JW, :)**2
355       RVWP(JW, :) = ZOP(JW, :) / MAX(ABS(ZOP(JW, :)), ZOISEC)**2 &
356            * BV(:, LAUNCH) * SIN(ZP(JW, :)) * WWP(JW, :)**2
357    end DO
358
359
360    ! 4.2 Uniform values below the launching altitude
361
362    DO LL = 1, LAUNCH
363       RUW(:, LL) = 0
364       RVW(:, LL) = 0
365       DO JW = 1, NW
366          RUW(:, LL) = RUW(:, LL) + RUWP(JW, :)
367          RVW(:, LL) = RVW(:, LL) + RVWP(JW, :)
368       end DO
369    end DO
370
371    ! 4.3 Loop over altitudes, with passage from one level to the next
372    ! done by i) conserving the EP flux, ii) dissipating a little,
373    ! iii) testing critical levels, and vi) testing the breaking.
374
375    DO LL = LAUNCH, KLEV - 1
376       ! Warning: all the physics is here (passage from one level
377       ! to the next)
378       DO JW = 1, NW
379          ZOM(JW, :) = ZOP(JW, :)
380          WWM(JW, :) = WWP(JW, :)
381          ! Intrinsic Frequency
382          ZOP(JW, :) = ZO(JW, :) - ZK(JW, :) * COS(ZP(JW, :)) * UH(:, LL + 1) &
383               - ZK(JW, :) * SIN(ZP(JW, :)) * VH(:, LL + 1)
384
385          ! No breaking (Eq.6)
386          ! Dissipation (Eq. 8)
387          WWP(JW, :) = WWM(JW, :) * EXP(- 4. * RDISS * PR / (PH(:, LL + 1) &
388               + PH(:, LL)) * ((BV(:, LL + 1) + BV(:, LL)) / 2.)**3 &
389               / MAX(ABS(ZOP(JW, :) + ZOM(JW, :)) / 2., ZOISEC)**4 &
390               * ZK(JW, :)**3 * (ZH(:, LL + 1) - ZH(:, LL)))
391
392          ! Critical levels (forced to zero if intrinsic frequency changes sign)
393          ! Saturation (Eq. 12)
394          WWP(JW, :) = min(WWP(JW, :), MAX(0., &
395               SIGN(1., ZOP(JW, :) * ZOM(JW, :))) * ABS(ZOP(JW, :))**3 &
396               / BV(:, LL + 1) * EXP(- ZH(:, LL + 1) / H0) * KMIN**2  &
397               * SAT**2 / ZK(JW, :)**4)
398       end DO
399
400       ! Evaluate EP-flux from Eq. 7 and give the right orientation to
401       ! the stress
402
403       DO JW = 1, NW
404          RUWP(JW, :) = SIGN(1., ZOP(JW, :))*COS(ZP(JW, :)) * WWP(JW, :)
405          RVWP(JW, :) = SIGN(1., ZOP(JW, :))*SIN(ZP(JW, :)) * WWP(JW, :)
406       end DO
407
408       RUW(:, LL + 1) = 0.
409       RVW(:, LL + 1) = 0.
410
411       DO JW = 1, NW
412          RUW(:, LL + 1) = RUW(:, LL + 1) + RUWP(JW, :)
413          RVW(:, LL + 1) = RVW(:, LL + 1) + RVWP(JW, :)
414          EAST_GWSTRESS(:, LL)=EAST_GWSTRESS(:, LL)+MAX(0.,RUWP(JW,:))/FLOAT(NW)
415          WEST_GWSTRESS(:, LL)=WEST_GWSTRESS(:, LL)+MIN(0.,RUWP(JW,:))/FLOAT(NW)
416       end DO
417    end DO
418! OFFLINE ONLY
419!   PRINT *,'SAT PROFILE:'
420!   DO LL=1,KLEV
421!   PRINT *,ZH(KLON/2,LL)/1000.,SAT*(2.+TANH(ZH(KLON/2,LL)/H0-8.))
422!   ENDDO
423
424    ! 5 CALCUL DES TENDANCES:
425
426    ! 5.1 Rectification des flux au sommet et dans les basses couches
427
428    RUW(:, KLEV + 1) = 0.
429    RVW(:, KLEV + 1) = 0.
430    RUW(:, 1) = RUW(:, LAUNCH)
431    RVW(:, 1) = RVW(:, LAUNCH)
432    DO LL = 1, LAUNCH
433       RUW(:, LL) = RUW(:, LAUNCH+1)
434       RVW(:, LL) = RVW(:, LAUNCH+1)
435       EAST_GWSTRESS(:, LL)  = EAST_GWSTRESS(:, LAUNCH)
436       WEST_GWSTRESS(:, LL)  = WEST_GWSTRESS(:, LAUNCH)
437    end DO
438
439    ! AR-1 RECURSIVE FORMULA (13) IN VERSION 4
440    DO LL = 1, KLEV
441       D_U(:, LL) = (1.-DTIME/DELTAT) * D_U(:, LL) + DTIME/DELTAT/REAL(NW) * &
442            RG * (RUW(:, LL + 1) - RUW(:, LL)) &
443            / (PH(:, LL + 1) - PH(:, LL)) * DTIME
444       ! NO AR-1 FOR MERIDIONAL TENDENCIES
445       D_V(:, LL) =                                            1./REAL(NW) * &
446            RG * (RVW(:, LL + 1) - RVW(:, LL)) &
447            / (PH(:, LL + 1) - PH(:, LL)) * DTIME
448    ENDDO
449
450    ! Cosmetic: evaluation of the cumulated stress
451    ZUSTR = 0.
452    ZVSTR = 0.
453    DO LL = 1, KLEV
454       ZUSTR = ZUSTR + D_U(:, LL) / RG * (PH(:, LL + 1) - PH(:, LL))/DTIME
455       ZVSTR = ZVSTR + D_V(:, LL) / RG * (PH(:, LL + 1) - PH(:, LL))/DTIME
456    ENDDO
457
458
459  END SUBROUTINE FLOTT_GWD_RANDO
460
461end module FLOTT_GWD_rando_m
Note: See TracBrowser for help on using the repository browser.