GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: phylmd/cv3_enthalpmix.F90 Lines: 72 76 94.7 %
Date: 2023-06-30 12:56:34 Branches: 55 64 85.9 %

Line Branch Exec Source
1
6648570
SUBROUTINE cv3_enthalpmix(len, nd, iflag, plim1, plim2, p, ph, &
2
                       t, q, u, v, w, &
3
1008
                       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
2016
  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
2016
  REAL, DIMENSION(len)                      :: plim2p  ! = min(plim2(:),plim1(:)-dpmin)
55
2016
  REAL, DIMENSION(len)                      :: akm     ! mixture enthalpy
56
2016
  REAL, DIMENSION(len)                      :: dpw, coef
57
2016
  REAL, DIMENSION(len)                      :: rdcp, a2, b2, pnk
58
2016
  REAL, DIMENSION(len)                      :: rh, chi
59
2016
  REAL, DIMENSION(len)                      :: eqwght
60
2016
  REAL, DIMENSION(len,nd)                   :: p1, p2
61
62
63
!!  print *,' ->cv3_vertmix, plim1,plim2 ', plim1,plim2   !jyg
64
1002960
  plim2p(:) = min(plim2(:),plim1(:)-dpmin)
65
1002960
  j1(:)=nd
66
1002960
  j2(:) = 0
67
40320
  DO j = 1, nd
68
39116448
    DO i = 1, len
69
39076128
      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
39115440
      IF (plim2p(i)< ph(i,j)) j2(i) = j
72
    END DO
73
  END DO
74
75
40320
  DO j = 1, nd
76
39116448
    DO i = 1, len
77
39115440
      wi(i, j) = 0.
78
    END DO
79
  END DO
80
1002960
  DO i = 1, len
81
1001952
    akm(i) = 0.
82
1001952
    qmix(i) = 0.
83
1001952
    umix(i) = 0.
84
1001952
    vmix(i) = 0.
85
1001952
    dpw(i) = 0.
86
1001952
    a2(i) = 0.0
87
1001952
    b2(i) = 0.
88
1002960
    pnk(i) = p(i, nk(i))
89
  END DO
90
1002960
  eqwght(:) = 0.
91
92
  p0 = 1000.
93
  p0m1 = 1./p0
94
95
1002960
  DO i = 1, len
96
1002960
    IF (j2(i) < j1(i)) THEN
97
      coef(i) = 1.
98
      eqwght(i) = 1.
99
    ELSE
100
1001952
      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
40320
  DO j = 1, nd
107
39116448
    DO i = 1, len
108

39115440
      IF (j>=j1(i) .AND. j<=j2(i)) THEN
109
2321829
        p1(i, j) = min(ph(i,j), plim1(i))
110
2321829
        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
2321829
        wi(i, j) = w(j)*(p1(i,j)-p2(i,j))*coef(i)+eqwght(i)
115
2321829
        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
40320
  DO j = 1, nd
128
39116448
    DO i = 1, len
129

39115440
      IF (j>=j1(i) .AND. j<=j2(i)) THEN
130
2321829
        wi(i, j) = wi(i, j)/dpw(i)
131
2321829
        akm(i) = akm(i) + (cpd*(1.-q(i,j))+q(i,j)*cpv)*t(i, j)*wi(i, j)
132
2321829
        qmix(i) = qmix(i) + q(i, j)*wi(i, j)
133
2321829
        umix(i) = umix(i) + u(i, j)*wi(i, j)
134
2321829
        vmix(i) = vmix(i) + v(i, j)*wi(i, j)
135
      END IF
136
    END DO
137
  END DO
138
139
1002960
  DO i = 1, len
140
1002960
    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
40320
  DO j = 1, nd
149
39116448
    DO i = 1, len
150

39115440
      IF (j>=j1(i) .AND. j<=j2(i)) THEN
151
        ! c            x=(.5*(p1(i,j)+p2(i,j))*p0m1)**rdcp(i)
152
2321829
        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
2321829
        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
1002960
  DO i = 1, len
160
1001952
    tmix(i) = akm(i)/b2(i)
161
1001952
    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
1001952
    zdelta = max(0., sign(1.,rtt-tmix(i)))
169
1001952
    qsmix(i) = r2es*foeew(tmix(i), zdelta)/(pnk(i)*100.)
170
1001952
    qsmix(i) = min(0.5, qsmix(i))
171
1001952
    zcor = 1./(1.-retv*qsmix(i))
172
1002960
    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
1002960
  DO i = 1, len
186
187
1002960
    IF (iflag(i)/=7) THEN ! modif sb Jun7th 2002
188
189
1001952
      rh(i) = qmix(i)/qsmix(i)
190
1001952
      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
1001952
      chi(i) = max(chi(i), 0.)
194
1001952
      rh(i) = max(rh(i), 0.)
195
1001952
      plcl(i) = pnk(i)*(rh(i)**chi(i))
196

1001952
      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
1008
  RETURN
214
END SUBROUTINE cv3_enthalpmix
215