source: LMDZ6/branches/Amaury_dev/libf/phylmd/cv3_estatmix.F90

Last change on this file was 5160, checked in by abarral, 3 months ago

Put .h into modules

File size: 6.1 KB
Line 
1SUBROUTINE cv3_estatmix(len, nd, iflag, plim1, plim2, p, ph, &
2                       t, q, u, v, h, gz, w, &
3                       wi, nk, tmix, thmix, qmix, qsmix, umix, vmix, plcl)
4  ! **************************************************************
5  ! *
6  ! CV3_ESTATMIX  Determine the properties of an adiabatic updraft  *
7  !                made of air coming from several layers by        *
8  !                mixing static energy                             *
9  !                                                                 *
10  ! written by   : Grandpeix Jean-Yves, 28/12/2001, 13.14.24        *
11  ! modified by :  Filiberti M-A 06/2005 vectorisation              *
12  ! ****************************************************************
13USE lmdz_cvthermo
14USE lmdz_yoethf
15
16USE lmdz_yomcst
17
18  IMPLICIT NONE
19 INCLUDE "FCTTRE.h"
20  ! ==============================================================
21
22  ! estatmix : determines theta, t, q, qs, u and v of the lifted mixture
23  ! made of air between plim1 and plim2 with weighting w.
24  ! If plim1 and plim2 fall within the same model layer, then theta, ... v
25  ! are those of that layer.
26  ! A minimum value (dpmin) is imposed upon plim1-plim2
27
28  ! ===============================================================
29
30!inputs:
31  INTEGER, INTENT (IN)                      :: nd, len
32  INTEGER, DIMENSION (len), INTENT (IN)     :: nk
33  REAL, DIMENSION (len), INTENT (IN)        :: plim1, plim2
34  REAL, DIMENSION (len,nd), INTENT (IN)     :: t, q
35  REAL, DIMENSION (len,nd), INTENT (IN)     :: u, v
36  REAL, DIMENSION (len,nd), INTENT (IN)     :: h ! static energy of the layers
37  REAL, DIMENSION (len,nd), INTENT (IN)     :: gz
38  REAL, DIMENSION (nd), INTENT (IN)         :: w
39  REAL, DIMENSION (len,nd), INTENT (IN)     :: p
40  REAL, DIMENSION (len,nd+1), INTENT (IN)   :: ph
41!input/output:
42  INTEGER, DIMENSION (len), INTENT (INOUT)  ::  iflag
43!outputs:
44  REAL, DIMENSION (len), INTENT (OUT)       :: tmix, thmix, qmix
45  REAL, DIMENSION (len), INTENT (OUT)       :: umix, vmix
46  REAL, DIMENSION (len), INTENT (OUT)       :: qsmix
47  REAL, DIMENSION (len), INTENT (OUT)       :: plcl
48  REAL, DIMENSION (len,nd), INTENT (OUT)    :: wi
49!internal variables :
50  INTEGER i, j
51  INTEGER niflag7
52  INTEGER, DIMENSION(len)                   :: j1, j2
53  REAL                                      :: a, b
54  REAL                                      :: cpn
55  REAL                                      :: x, y, p0, zdelta, zcor
56  REAL, SAVE                                :: dpmin=1.
57!$OMP THREADPRIVATE(dpmin)
58  REAL, DIMENSION(len)                      :: plim2p  ! = min(plim2(:),plim1(:)-dpmin)
59  REAL, DIMENSION(len)                      :: dpw, coef
60  REAL, DIMENSION(len)                      :: hmix ! static energy of the updraft
61  REAL, DIMENSION(len)                      :: rdcp, pnk
62  REAL, DIMENSION(len)                      :: rh, chi
63  REAL, DIMENSION(len)                      :: eqwght
64  REAL, DIMENSION(len,nd)                   :: p1, p2
65
66
67!!  PRINT *,' ->cv3_vertmix, plim1,plim2 ', plim1,plim2   !jyg
68  plim2p(:) = min(plim2(:),plim1(:)-dpmin)
69  j1(:)=nd
70  j2(:) = 0
71  DO j = 1, nd
72    DO i = 1, len
73      IF (plim1(i)<=ph(i,j)) j1(i) = j
74!!!      IF (plim2p(i)>=ph(i,j+1) .AND. plim2p(i)<ph(i,j)) j2(i) = j
75      IF (plim2p(i)< ph(i,j)) j2(i) = j
76    END DO
77  END DO
78
79  DO j = 1, nd
80    DO i = 1, len
81      wi(i, j) = 0.
82    END DO
83  END DO
84  DO i = 1, len
85    hmix(i) = 0.
86    qmix(i) = 0.
87    umix(i) = 0.
88    vmix(i) = 0.
89    dpw(i) = 0.
90    pnk(i) = p(i, nk(i))
91  END DO
92  eqwght(:) = 0.
93
94  p0 = 1000.
95
96  DO i = 1, len
97    IF (j2(i) < j1(i)) THEN
98      coef(i) = 1.
99      eqwght(i) = 1.
100    ELSE
101      coef(i) = 1./(plim1(i)-plim2p(i))
102    ENDIF
103  END DO
104
105!!  PRINT *,'cv3_vertmix, j1,j2,coef ', j1,j2,coef  !jyg
106
107  DO j = 1, nd
108    DO i = 1, len
109      IF (j>=j1(i) .AND. j<=j2(i)) THEN
110        p1(i, j) = min(ph(i,j), plim1(i))
111        p2(i, j) = max(ph(i,j+1), plim2p(i))
112        ! CRtest:couplage thermiques: deja normalise
113        ! wi(i,j) = w(j)
114        ! PRINT*,'wi',wi(i,j)
115        wi(i, j) = w(j)*(p1(i,j)-p2(i,j))*coef(i)+eqwght(i)
116        dpw(i) = dpw(i) + wi(i, j)
117
118!!  PRINT *,'cv3_vertmix, j, wi(1,j),dpw ', j, wi(1,j),dpw  !jyg
119
120      END IF
121    END DO
122  END DO
123
124  ! CR:print
125  ! do i=1,len
126  ! PRINT*,'plim',plim1(i),plim2p(i)
127  ! enddo
128  DO j = 1, nd
129    DO i = 1, len
130      IF (j>=j1(i) .AND. j<=j2(i)) THEN
131        wi(i, j) = wi(i, j)/dpw(i)
132        hmix(i) = hmix(i) + h(i, j)*wi(i, j)
133        qmix(i) = qmix(i) +  q(i, j)*wi(i, j)
134        umix(i) = umix(i) +  u(i, j)*wi(i, j)
135        vmix(i) = vmix(i) +  v(i, j)*wi(i, j)
136      END IF
137    END DO
138  END DO
139
140  DO i = 1, len
141    rdcp(i) = (rrd*(1.-qmix(i))+qmix(i)*rrv)/(cpd*(1.-qmix(i))+qmix(i)*cpv)
142  END DO
143
144
145!!  PRINT *,'cv3_vertmix, rdcp ', rdcp  !jyg
146
147  DO i = 1, len
148    tmix(i) = (hmix(i) - gz(i,1))/(cpd*(1.-qmix(i)) + qmix(i)*cpv)
149    !      (Use of Cpv since we are dealing with dry static energy)
150    thmix(i) = tmix(i)*(p0/pnk(i))**rdcp(i)
151    ! PRINT*,'tmix thmix hmix ',tmix(i),thmix(i),hmix(i)
152    zdelta = max(0., sign(1.,rtt-tmix(i)))
153    qsmix(i) = r2es*foeew(tmix(i), zdelta)/(pnk(i)*100.)
154    qsmix(i) = min(0.5, qsmix(i))
155    zcor = 1./(1.-retv*qsmix(i))
156    qsmix(i) = qsmix(i)*zcor
157  END DO
158
159  ! -------------------------------------------------------------------
160  ! --- Calculate lifted condensation level of air at parcel origin level
161  ! --- (Within 0.2% of formula of Bolton, MON. WEA. REV.,1980)
162  ! -------------------------------------------------------------------
163
164  a = 1669.0 ! convect3
165  b = 122.0 ! convect3
166
167
168  niflag7 = 0
169  DO i = 1, len
170
171    IF (iflag(i)/=7) THEN ! modif sb Jun7th 2002
172
173      rh(i) = qmix(i)/qsmix(i)
174      chi(i) = tmix(i)/(a-b*rh(i)-tmix(i)) ! convect3
175      ! ATTENTION, la LIGNE DESSOUS A ETE RAJOUTEE ARBITRAIREMENT ET
176      ! MASQUE UN PB POTENTIEL
177      chi(i) = max(chi(i), 0.)
178      rh(i) = max(rh(i), 0.)
179      plcl(i) = pnk(i)*(rh(i)**chi(i))
180      IF (((plcl(i)<200.0) .OR. (plcl(i)>=2000.0)) .AND. (iflag(i)==0)) &
181          iflag(i) = 8
182
183    ELSE
184
185      niflag7 = niflag7 + 1
186      plcl(i) = plim2p(i)
187
188    END IF ! iflag=7
189
190    ! PRINT*,'NIFLAG7  =',niflag7
191
192  END DO
193
194!!  PRINT *,' cv3_vertmix->'  !jyg
195
196
197
198END SUBROUTINE cv3_estatmix
199
Note: See TracBrowser for help on using the repository browser.