source: LMDZ6/trunk/libf/phylmd/flott_gwd_rando_m.F90 @ 3412

Last change on this file since 3412 was 3198, checked in by fhourdin, 7 years ago

Retour vers l'insensibilite au decoupage en sous domaine.
Les routines gwd_rando incluait le calcul de niveaux de reference
sur la base d'un profile pris au milieu du domaine (en klon/2).
Rempace par un test en presnivs.

Une autre intercation entre routines concernant la tke a fait apparaitre
que la tke n'était pas passee correctement au niveau klev+1 au moment
du regroupement des mailles sous les sous surface.

Ces changements garantissent la convergence numerique si
addtkeoro=0
iflag_pbl<12
et
ok_gwd_rando=n
La convergence n'est pas garantie pour les dernieres versions des physiq.def
mais les differences devraient etre mineures.

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