source: LMDZ6/branches/Amaury_dev/libf/phylmd/cv3_enthalpmix.F90 @ 5151

Last change on this file since 5151 was 5144, checked in by abarral, 3 months ago

Put YOMCST.h into modules

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