source: LMDZ6/branches/LMDZ-COSP/libf/phylmd/cv3_enthalpmix.F90 @ 4212

Last change on this file since 4212 was 3043, checked in by Ehouarn Millour, 7 years ago

Some fixes to enable compiling with the pgf compiler and updated arch files for pgf on Ciclad.
EM

File size: 6.3 KB
Line 
1SUBROUTINE cv3_enthalpmix(len, nd, iflag, plim1, plim2, p, ph, &
2                       t, q, u, v, w, &
3                       wi, nk, tmix, thmix, qmix, qsmix, umix, vmix, plcl)
4  ! **************************************************************
5  ! *
6  ! CV3_ENTHALPMIX   Brassage adiabatique d'une couche d'epaisseur *
7  ! arbitraire.                                   *
8  ! *
9  ! written by   : Grandpeix Jean-Yves, 28/12/2001, 13.14.24    *
10  ! modified by :  Filiberti M-A 06/2005 vectorisation          *
11  ! **************************************************************
12
13  IMPLICIT NONE
14  ! ==============================================================
15
16  ! vertmix : determines theta, t, q, qs, u and v of the mixture generated by
17  ! adiabatic mixing of air between plim1 and plim2 with weighting w.
18  ! If plim1 and plim2 fall within the same model layer, then theta, ... v
19  ! are those of that layer.
20  ! A minimum value (dpmin) is imposed upon plim1-plim2
21
22  ! ===============================================================
23
24  include "cvthermo.h"
25  include "YOETHF.h"
26  include "YOMCST.h"
27  include "FCTTRE.h"
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
147
148  DO j = 1, nd
149    DO i = 1, len
150      IF (j>=j1(i) .AND. j<=j2(i)) THEN
151        ! c            x=(.5*(p1(i,j)+p2(i,j))*p0m1)**rdcp(i)
152        y = (.5*(p1(i,j)+p2(i,j))/pnk(i))**rdcp(i)
153        ! c            a2(i)=a2(i)+(cpd*(1.-qmix(i))+qmix(i)*cpv)*x*wi(i,j)
154        b2(i) = b2(i) + (cpd*(1.-qmix(i))+qmix(i)*cpv)*y*wi(i, j)
155      END IF
156    END DO
157  END DO
158
159  DO i = 1, len
160    tmix(i) = akm(i)/b2(i)
161    thmix(i) = tmix(i)*(p0/pnk(i))**rdcp(i)
162    ! print*,'thmix akm',akm(i),b2(i)
163    ! print*,'thmix t',tmix(i),p0
164    ! print*,'thmix p',pnk(i),rdcp(i)
165    ! print*,'thmix',thmix(i)
166    ! c         thmix(i) = akm(i)/a2(i)
167    ! c         tmix(i)= thmix(i)*(pnk(i)*p0m1)**rdcp(i)
168    zdelta = max(0., sign(1.,rtt-tmix(i)))
169    qsmix(i) = r2es*foeew(tmix(i), zdelta)/(pnk(i)*100.)
170    qsmix(i) = min(0.5, qsmix(i))
171    zcor = 1./(1.-retv*qsmix(i))
172    qsmix(i) = qsmix(i)*zcor
173  END DO
174
175  ! -------------------------------------------------------------------
176  ! --- Calculate lifted condensation level of air at parcel origin level
177  ! --- (Within 0.2% of formula of Bolton, MON. WEA. REV.,1980)
178  ! -------------------------------------------------------------------
179
180  a = 1669.0 ! convect3
181  b = 122.0 ! convect3
182
183
184  niflag7 = 0
185  DO i = 1, len
186
187    IF (iflag(i)/=7) THEN ! modif sb Jun7th 2002
188
189      rh(i) = qmix(i)/qsmix(i)
190      chi(i) = tmix(i)/(a-b*rh(i)-tmix(i)) ! convect3
191      ! ATTENTION, la LIGNE DESSOUS A ETE RAJOUTEE ARBITRAIREMENT ET
192      ! MASQUE UN PB POTENTIEL
193      chi(i) = max(chi(i), 0.)
194      rh(i) = max(rh(i), 0.)
195      plcl(i) = pnk(i)*(rh(i)**chi(i))
196      IF (((plcl(i)<200.0) .OR. (plcl(i)>=2000.0)) .AND. (iflag(i)==0)) &
197          iflag(i) = 8
198
199    ELSE
200
201      niflag7 = niflag7 + 1
202      plcl(i) = plim2p(i)
203
204    END IF ! iflag=7
205
206    ! print*,'NIFLAG7  =',niflag7
207
208  END DO
209
210!!  print *,' cv3_vertmix->'  !jyg
211
212
213  RETURN
214END SUBROUTINE cv3_enthalpmix
215
Note: See TracBrowser for help on using the repository browser.