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

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

Put .h into modules

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