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

Last change on this file since 5441 was 5160, checked in by abarral, 5 months ago

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