source: LMDZ6/trunk/libf/phylmdiso/cv3_estatmix.F90 @ 5282

Last change on this file since 5282 was 5276, checked in by abarral, 6 weeks ago

Turn cvthermo.h into a module

  • Property svn:keywords set to Id
File size: 7.5 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#ifdef ISO
5     &                 ,xt,xtmix &
6#endif
7                       )
8#ifdef ISO
9    use infotrac_phy, ONLY: ntiso
10#endif
11  ! **************************************************************
12  ! *
13  ! CV3_ESTATMIX  Determine the properties of an adiabatic updraft  *
14  !                made of air coming from several layers by        *
15  !                mixing static energy                             *
16  !                                                                 *
17  ! written by   : Grandpeix Jean-Yves, 28/12/2001, 13.14.24        *
18  ! modified by :  Filiberti M-A 06/2005 vectorisation              *
19  ! ****************************************************************
20
21  USE cvthermo_mod_h, ONLY: cpd, cpv, cl, ci, rrv, rrd, lv0, lf0, g, rowl, t0, clmcpv, clmcpd, cpdmcp, cpvmcpd, cpvmcl  &
22          , clmci, eps, epsi, epsim1, ginv, hrd, grav
23  USE yomcst_mod_h, ONLY: RPI, RCLUM, RHPLA, RKBOL, RNAVO                   &
24          , RDAY, REA, REPSM, RSIYEA, RSIDAY, ROMEGA                  &
25          , R_ecc, R_peri, R_incl                                      &
26          , RA, RG, R1SA                                         &
27          , RSIGMA                                                     &
28          , R, RMD, RMV, RD, RV, RCPD                    &
29          , RMO3, RMCO2, RMC, RMCH4, RMN2O, RMCFC11, RMCFC12        &
30          , RCPV, RCVD, RCVV, RKAPPA, RETV, eps_w                    &
31          , RCW, RCS                                                 &
32          , RLVTT, RLSTT, RLMLT, RTT, RATM                           &
33          , RESTT, RALPW, RBETW, RGAMW, RALPS, RBETS, RGAMS            &
34          , RALPD, RBETD, RGAMD
35IMPLICIT NONE
36  ! ==============================================================
37
38  ! estatmix : determines theta, t, q, qs, u and v of the lifted mixture
39  ! made of air between plim1 and plim2 with weighting w.
40  ! If plim1 and plim2 fall within the same model layer, then theta, ... v
41  ! are those of that layer.
42  ! A minimum value (dpmin) is imposed upon plim1-plim2
43
44  ! ===============================================================
45
46  include "YOETHF.h"
47
48  include "FCTTRE.h"
49!inputs:
50  INTEGER, INTENT (IN)                      :: nd, len
51  INTEGER, DIMENSION (len), INTENT (IN)     :: nk
52  REAL, DIMENSION (len), INTENT (IN)        :: plim1, plim2
53  REAL, DIMENSION (len,nd), INTENT (IN)     :: t, q
54  REAL, DIMENSION (len,nd), INTENT (IN)     :: u, v
55  REAL, DIMENSION (len,nd), INTENT (IN)     :: h ! static energy of the layers
56  REAL, DIMENSION (len,nd), INTENT (IN)     :: gz
57  REAL, DIMENSION (nd), INTENT (IN)         :: w
58  REAL, DIMENSION (len,nd), INTENT (IN)     :: p
59  REAL, DIMENSION (len,nd+1), INTENT (IN)   :: ph
60#ifdef ISO
61  REAL, DIMENSION (ntiso,len,nd), INTENT (IN)     :: xt
62#endif
63!input/output:
64  INTEGER, DIMENSION (len), INTENT (INOUT)  ::  iflag
65!outputs:
66  REAL, DIMENSION (len), INTENT (OUT)       :: tmix, thmix, qmix
67  REAL, DIMENSION (len), INTENT (OUT)       :: umix, vmix
68  REAL, DIMENSION (len), INTENT (OUT)       :: qsmix
69  REAL, DIMENSION (len), INTENT (OUT)       :: plcl
70  REAL, DIMENSION (len,nd), INTENT (OUT)    :: wi
71#ifdef ISO
72  REAL, DIMENSION (ntiso,len), INTENT (OUT)     :: xtmix
73#endif
74!internal variables :
75  INTEGER i, j
76  INTEGER niflag7
77  INTEGER, DIMENSION(len)                   :: j1, j2
78  REAL                                      :: a, b
79  REAL                                      :: cpn
80  REAL                                      :: x, y, p0, zdelta, zcor
81  REAL, SAVE                                :: dpmin=1.
82!$OMP THREADPRIVATE(dpmin)
83  REAL, DIMENSION(len)                      :: plim2p  ! = min(plim2(:),plim1(:)-dpmin)
84  REAL, DIMENSION(len)                      :: dpw, coef
85  REAL, DIMENSION(len)                      :: hmix ! static energy of the updraft
86  REAL, DIMENSION(len)                      :: rdcp, pnk
87  REAL, DIMENSION(len)                      :: rh, chi
88  REAL, DIMENSION(len)                      :: eqwght
89  REAL, DIMENSION(len,nd)                   :: p1, p2
90#ifdef ISO
91  INTEGER ixt
92#endif
93
94
95!!  print *,' ->cv3_vertmix, plim1,plim2 ', plim1,plim2   !jyg
96  plim2p(:) = min(plim2(:),plim1(:)-dpmin)
97  j1(:)=nd
98  j2(:) = 0
99  DO j = 1, nd
100    DO i = 1, len
101      IF (plim1(i)<=ph(i,j)) j1(i) = j
102!!!      IF (plim2p(i)>=ph(i,j+1) .AND. plim2p(i)<ph(i,j)) j2(i) = j
103      IF (plim2p(i)< ph(i,j)) j2(i) = j
104    END DO
105  END DO
106
107  DO j = 1, nd
108    DO i = 1, len
109      wi(i, j) = 0.
110    END DO
111  END DO
112  DO i = 1, len
113    hmix(i) = 0.
114    qmix(i) = 0.
115    umix(i) = 0.
116    vmix(i) = 0.
117    dpw(i) = 0.
118    pnk(i) = p(i, nk(i))
119#ifdef ISO
120    xtmix(:,i) = 0.
121#endif
122  END DO
123  eqwght(:) = 0.
124
125  p0 = 1000.
126
127  DO i = 1, len
128    IF (j2(i) < j1(i)) THEN
129      coef(i) = 1.
130      eqwght(i) = 1.
131    ELSE
132      coef(i) = 1./(plim1(i)-plim2p(i))
133    ENDIF
134  END DO
135
136!!  print *,'cv3_vertmix, j1,j2,coef ', j1,j2,coef  !jyg
137
138  DO j = 1, nd
139    DO i = 1, len
140      IF (j>=j1(i) .AND. j<=j2(i)) THEN
141        p1(i, j) = min(ph(i,j), plim1(i))
142        p2(i, j) = max(ph(i,j+1), plim2p(i))
143        ! CRtest:couplage thermiques: deja normalise
144        ! wi(i,j) = w(j)
145        ! print*,'wi',wi(i,j)
146        wi(i, j) = w(j)*(p1(i,j)-p2(i,j))*coef(i)+eqwght(i)
147        dpw(i) = dpw(i) + wi(i, j)
148
149!!  print *,'cv3_vertmix, j, wi(1,j),dpw ', j, wi(1,j),dpw  !jyg
150
151      END IF
152    END DO
153  END DO
154
155  ! CR:print
156  ! do i=1,len
157  ! print*,'plim',plim1(i),plim2p(i)
158  ! enddo
159  DO j = 1, nd
160    DO i = 1, len
161      IF (j>=j1(i) .AND. j<=j2(i)) THEN
162        wi(i, j) = wi(i, j)/dpw(i)
163        hmix(i) = hmix(i) + h(i, j)*wi(i, j)
164        qmix(i) = qmix(i) +  q(i, j)*wi(i, j)
165        umix(i) = umix(i) +  u(i, j)*wi(i, j)
166        vmix(i) = vmix(i) +  v(i, j)*wi(i, j)
167#ifdef ISO
168        do ixt=1,ntiso
169          xtmix(ixt,i) = xtmix(ixt,i) +  xt(ixt,i, j)*wi(i, j)
170        enddo
171#endif
172      END IF
173    END DO
174  END DO
175
176  DO i = 1, len
177    rdcp(i) = (rrd*(1.-qmix(i))+qmix(i)*rrv)/(cpd*(1.-qmix(i))+qmix(i)*cpv)
178  END DO
179
180
181!!  print *,'cv3_vertmix, rdcp ', rdcp  !jyg
182
183  DO i = 1, len
184    tmix(i) = (hmix(i) - gz(i,1))/(cpd*(1.-qmix(i)) + qmix(i)*cpv)
185    !      (Use of Cpv since we are dealing with dry static energy)
186    thmix(i) = tmix(i)*(p0/pnk(i))**rdcp(i)
187    ! print*,'tmix thmix hmix ',tmix(i),thmix(i),hmix(i)
188    zdelta = max(0., sign(1.,rtt-tmix(i)))
189    qsmix(i) = r2es*foeew(tmix(i), zdelta)/(pnk(i)*100.)
190    qsmix(i) = min(0.5, qsmix(i))
191    zcor = 1./(1.-retv*qsmix(i))
192    qsmix(i) = qsmix(i)*zcor
193  END DO
194
195  ! -------------------------------------------------------------------
196  ! --- Calculate lifted condensation level of air at parcel origin level
197  ! --- (Within 0.2% of formula of Bolton, MON. WEA. REV.,1980)
198  ! -------------------------------------------------------------------
199
200  a = 1669.0 ! convect3
201  b = 122.0 ! convect3
202
203
204  niflag7 = 0
205  DO i = 1, len
206
207    IF (iflag(i)/=7) THEN ! modif sb Jun7th 2002
208
209      rh(i) = qmix(i)/qsmix(i)
210      chi(i) = tmix(i)/(a-b*rh(i)-tmix(i)) ! convect3
211      ! ATTENTION, la LIGNE DESSOUS A ETE RAJOUTEE ARBITRAIREMENT ET
212      ! MASQUE UN PB POTENTIEL
213      chi(i) = max(chi(i), 0.)
214      rh(i) = max(rh(i), 0.)
215      plcl(i) = pnk(i)*(rh(i)**chi(i))
216      IF (((plcl(i)<200.0) .OR. (plcl(i)>=2000.0)) .AND. (iflag(i)==0)) &
217          iflag(i) = 8
218
219    ELSE
220
221      niflag7 = niflag7 + 1
222      plcl(i) = plim2p(i)
223
224    END IF ! iflag=7
225
226    ! print*,'NIFLAG7  =',niflag7
227
228  END DO
229
230!!  print *,' cv3_vertmix->'  !jyg
231
232
233  RETURN
234END SUBROUTINE cv3_estatmix
235
Note: See TracBrowser for help on using the repository browser.