source: trunk/LMDZ.MARS/libf/phymars/topmons_mod.F90 @ 2224

Last change on this file since 2224 was 2199, checked in by mvals, 6 years ago

Mars GCM:
Implementation of a new parametrization of the dust entrainment by slope winds above the sub-grid scale topography. The parametrization is activated with the flag slpwind=.true. (set to "false" by
default) in callphys.def. The new parametrization involves the new tracers topdust_mass and topdust_number.
MV

File size: 46.9 KB
Line 
1      MODULE topmons_mod
2
3      IMPLICIT NONE
4
5!     sub-grid scale mountain mesh fraction
6      REAL, SAVE, ALLOCATABLE :: alpha_hmons(:)
7
8      CONTAINS
9
10!=======================================================================
11! ENTRAINMENT OF DUST ABOVE THE SUB-GRID SCALE TOPOGRAPHY
12!=======================================================================
13! calculation of the vertical wind velocity of topdust tracers
14! transport scheme of topdust tracers
15! detrainement of topdust into background dust
16! -----------------------------------------------------------------------
17! Authors: M. Vals; C. Wang; T. Bertrand; F. Forget
18! Institution: Laboratoire de Meteorologie Dynamique (LMD) Paris, France
19! -----------------------------------------------------------------------
20
21      SUBROUTINE topmons(ngrid,nlayer,nq,ptime,ptimestep,              &
22                                 pq,pdq,pt,pdt,pplev,pplay,pzlev,      &
23                                 pzlay,pdtsw,pdtlw,                    &
24!             input for radiative transfer
25                                 icount,zday,zls,tsurf,igout,aerosol,  &
26!             input sub-grid scale rocket dust storm
27                                 totstormfract,clearatm,dsords,        &
28!             input sub-grid scale cloud
29                                 clearsky,totcloudfrac,                &
30!             input sub-grid scale mountain
31                                 nohmons,hsummit,                      &
32!             output
33                                 pdqtop,wfin,dsodust,                   &
34                                 tauref)
35
36      USE tracer_mod, only: igcm_topdust_mass,igcm_topdust_number &
37                            ,igcm_dust_mass,igcm_dust_number      &
38                            ,rho_dust
39      USE comcstfi_h, only: r,g,cpp,rcp
40      USE dimradmars_mod, only: albedo,naerkind
41      USE comsaison_h, only: dist_sol,mu0,fract
42      USE surfdat_h, only: emis,co2ice,hmons,summit
43      USE callradite_mod
44
45      IMPLICIT NONE
46
47!--------------------------------------------------------
48! Input Variables
49!--------------------------------------------------------
50
51      INTEGER, INTENT(IN) :: ngrid ! number of horizontal grid points
52      INTEGER, INTENT(IN) :: nlayer ! number of vertical grid points
53      INTEGER, INTENT(IN) :: nq ! number of tracer species
54      REAL, INTENT(IN) :: ptime
55      REAL, INTENT(IN) :: ptimestep
56
57      REAL, INTENT(IN) :: pq(ngrid,nlayer,nq) ! advected field nq
58      REAL, INTENT(IN) :: pdq(ngrid,nlayer,nq)! tendancy field pq
59      REAL, INTENT(IN) :: pt(ngrid,nlayer)    ! temperature at mid-layer (K)
60      REAL, INTENT(IN) :: pdt(ngrid,nlayer)   ! tendancy temperature at mid-layer (K)
61
62      REAL, INTENT(IN) :: pplay(ngrid,nlayer)     ! pressure at middle of the layers
63      REAL, INTENT(IN) :: pplev(ngrid,nlayer+1)   ! pressure at intermediate levels
64      REAL, INTENT(IN) :: pzlay(ngrid,nlayer)     ! altitude at the middle of the layers
65      REAL, INTENT(IN) :: pzlev(ngrid,nlayer+1)   ! altitude at layer boundaries
66
67      REAL, INTENT(IN) :: pdtsw(ngrid,nlayer)     ! (K/s) env
68      REAL, INTENT(IN) :: pdtlw(ngrid,nlayer)     ! (K/s) env
69
70!     input for second radiative transfer
71      INTEGER, INTENT(INOUT) :: icount
72      REAL, INTENT(IN) :: zday
73      REAL, INTENT(IN) :: zls
74      REAL, INTENT(IN) :: tsurf(ngrid)
75      INTEGER, INTENT(IN) :: igout
76!     input sub-grid scale rocket dust storm
77      LOGICAL, INTENT(IN) :: clearatm
78      REAL, INTENT(IN) :: totstormfract(ngrid)
79!     input sub-grid scale water ice clouds
80      LOGICAL, INTENT(IN) :: clearsky
81      REAL, INTENT(IN) :: totcloudfrac(ngrid)
82!     input sub-grid scale mountain
83      LOGICAL, INTENT(IN) :: nohmons
84      REAL, INTENT(IN) :: hsummit(ngrid)
85
86!--------------------------------------------------------
87! Output Variables
88!--------------------------------------------------------
89
90      REAL, INTENT(OUT) :: pdqtop(ngrid,nlayer,nq)  ! tendancy field for dust
91      REAL, INTENT(OUT) :: wfin(ngrid,nlayer+1)     ! final vertical wind velocity: combination of both wup and wrad
92                                                    ! wfin < 0 means upward wind (in pressure levels/s)
93      REAL, INTENT(OUT) :: dsodust(ngrid,nlayer)
94
95!     output for second radiative transfer
96      REAL, INTENT(OUT) :: aerosol(ngrid,nlayer,naerkind)
97      REAL, INTENT(OUT) :: dsords(ngrid,nlayer)
98      REAL, INTENT(OUT) :: tauref(ngrid)
99
100!--------------------------------------------------------
101! Local variables
102!--------------------------------------------------------
103      LOGICAL,SAVE :: firstcall=.true.
104      INTEGER l,ig,tsub,iq,ll
105      REAL zq0(ngrid,nlayer,nq)     ! initial tracers
106      REAL zq(ngrid,nlayer,nq)      ! updated tracers
107      REAL,PARAMETER:: mu0lim=0.001 ! solar zenith angle limit to determine the daytime
108
109!     Variables for radiative transfer
110      REAL  fluxsurf_lw1(ngrid)
111      REAL  fluxsurf_sw1(ngrid,2)
112      REAL  fluxtop_lw1(ngrid)
113      REAL  fluxtop_sw1(ngrid,2)
114      REAL  tau(ngrid,naerkind)
115      REAL  tauscaling(ngrid)
116      REAL  taucloudtes(ngrid)
117      REAL  rdust(ngrid,nlayer)
118      REAL  rstormdust(ngrid,nlayer)
119      REAL  rtopdust(ngrid,nlayer)
120      REAL  rice(ngrid,nlayer)
121      REAL  nuice(ngrid,nlayer)
122
123!     Temperature profile
124      REAL zt(ngrid,nlayer)                                  ! actual temperature at mid-layer (K)
125      REAL ztlev(ngrid,nlayer)                               ! temperature at intermediate levels l+1/2 without last level
126      REAL zdtlw1(ngrid,nlayer)                              ! (K/s) topdust
127      REAL zdtsw1(ngrid,nlayer)                              ! (K/s) topdust
128      REAL zdtlw1_lev(ngrid,nlayer),zdtsw1_lev(ngrid,nlayer) ! rad. heating rate at intermediate levels l+1/2
129      REAL zdtlw_lev(ngrid,nlayer),zdtsw_lev(ngrid,nlayer)   ! rad. heating rate at intermediate levels l+1/2
130      REAL zdtvert(ngrid,nlayer)                             ! dT/dz , lapse rate
131      REAL deltahr(ngrid,nlayer+1)                           ! extra heating between the concentrated and non-concentrated dust
132
133      REAL newzt(ngrid,nlayer)    ! recalculated temperature with extra radiative heating
134      REAL t_top(ngrid,nlayer)    ! estimated temperature above the mountain
135      REAL t_top_lev(ngrid,nlayer)! estimated temperature above the mountain at the levels
136      REAL dt_top(ngrid)          ! temperature difference between the summit and the environment
137      INTEGER lmons(ngrid)        ! layer of the mountain's slope
138      INTEGER lsummit(ngrid)      ! layer of the mountain's summit
139      REAL t_env(ngrid,nlayer)    ! recalculated temperature of the environment air "next" to the mountain
140
141!     Vertical velocity profile
142      REAL wrad(ngrid,nlayer+1)  ! vertical wind velocity resulting from radiative heating
143      REAL wup(ngrid,nlayer+1)   ! vertical wind velocity calculated above the sub-grid scale mountain
144      REAL wup2(ngrid,nlayer+1)  ! square of the vertical velocity calculated above the sub-grid scale mountain
145      REAL w0(ngrid)             ! vertical wind velocity convergence at the top of the sub-grid scale mountain
146      INTEGER lwmax(ngrid)       ! level of the maximum vertical velocity
147
148      REAL,PARAMETER:: wmax=10.  ! maximum vertical velocity resulting from radiative heating (m/s)
149      REAL,PARAMETER:: secu=3.   ! coefficient on wfin to avoid dust crossing many layers during subtimestep
150      REAL,PARAMETER:: k0=0.25   !max 10m/s: k0=1.      !max 3m/s: k0=0.25
151      REAL,PARAMETER:: k1=5.e-4  !max 10m/s: k1=5.e-4   !max 3m/s: k1=5.e-4
152      REAL,PARAMETER:: k2=5.e-3  !max 10m/s: k2=30.e-3  !max 3m/s: k2=5.e-3
153
154!     Entrainment
155      REAL entr(ngrid)                                             ! entrainment flux
156      REAL rho(ngrid,nlayer),rhobarz(ngrid,nlayer)                 ! density, density at the levels
157      REAL masse(ngrid,nlayer)                                     ! air mass
158      REAL masse_pbl(ngrid)                                        ! total air mass within the PBL
159      REAL masse_pbl_dust_mass(ngrid),masse_pbl_dust_number(ngrid) ! total air mass + dust mass/number within the PBL (kg/m2)
160      REAL dqm_mass_pbl(ngrid),dqm_number_pbl(ngrid)               ! total mass of the entrained dust mass/number from the PBL (kg/m2)
161
162!     Van Leer
163      REAL zq_dust_mass(ngrid,nlayer),zq_dust_number(ngrid,nlayer)       ! mixing ratio background dust (kg/kg)
164      REAL zq_topdust_mass(ngrid,nlayer),zq_topdust_number(ngrid,nlayer) ! mixing ratio topdust (kg/kg)
165      REAL mr_dust_mass(ngrid,nlayer),mr_dust_number(ngrid,nlayer)       ! mixing ratio background dust (kg/kg)
166      REAL mr_topdust_mass(ngrid,nlayer),mr_topdust_number(ngrid,nlayer) ! mixing ratio background dust + concentrated topdust (kg/kg)
167
168      REAL w(ngrid,nlayer)          ! vertical flux above the sub-grid scale mountain
169      REAL wqmass(ngrid,nlayer+1)   ! flux mass
170      REAL wqnumber(ngrid,nlayer+1) ! flux number
171      REAL qbar_mass_pbl(ngrid)     ! total dust mass mixing ratio within the PBL for Van Leer
172      REAL qbar_number_pbl(ngrid)   ! total dust number mixing ratio within the PBL for Van Leer
173      REAL masse_col(nlayer)        ! masse of the atmosphere in one column
174
175      REAL dqvl_dust_mass(ngrid,nlayer)       ! tendancy pdq dust mass after vertical transport
176      REAL dqvl_dust_number(ngrid,nlayer)     ! tendancy pdq dust number after vertical transport
177      REAL dqvl_topdust_mass(ngrid,nlayer)    ! tendancy pdq topdust mass after vertical transport
178      REAL dqvl_topdust_number(ngrid,nlayer)  ! tendancy pdq topdust number after vertical transport
179
180      INTEGER nsubtimestep(ngrid)    ! number of subtimestep when calling Van Leer scheme
181      REAL subtimestep(ngrid)        ! ptimestep/nsubtimestep
182      REAL dtmax                     ! considered minimum time interval needed for the dust to cross one vertical layer
183
184!     Detrainment     
185      REAL coefdetrain(ngrid,nlayer)          ! coefficient for detrainment : % of stormdust detrained
186      REAL dqdet_topdust_mass(ngrid,nlayer)   ! tendancy pdq topdust mass after detrainment only
187      REAL dqdet_topdust_number(ngrid,nlayer) ! tendancy pdq topdust number after detrainment only
188
189!     Diagnostics
190      REAL    zlaywmax(ngrid)
191      REAL    detrain_rate(ngrid,nlayer)
192
193      ! **********************************************************************
194      ! **********************************************************************
195      ! Parametrization of the entrainment by slope wind above the sub-grid
196      ! scale topography
197      ! **********************************************************************
198      ! **********************************************************************     
199      !!    1. Radiative transfer in topdust
200      !!    2. Compute vertical velocity for topdust
201      !!    3. Vertical transport
202      !!    4. Detrainment
203      ! **********************************************************************
204      ! **********************************************************************
205     
206      ! **********************************************************************
207      ! 0. Initializations
208      ! **********************************************************************
209      aerosol(:,:,:)=0.
210      dsodust(:,:)=0.
211      dsords(:,:)=0.
212      pdqtop(:,:,:) = 0.
213      dqvl_topdust_mass(:,:)=0.
214      dqvl_topdust_number(:,:)=0.
215      dqvl_dust_mass(:,:)=0.
216      dqvl_dust_number(:,:)=0.
217      dqdet_topdust_mass(:,:)=0.
218      dqdet_topdust_number(:,:)=0.
219      wup(:,:)=0.
220      wup2(:,:)=0.
221      wrad(:,:)=0.
222      w0(:)=0.
223      wfin(:,:)=0.     
224      w(:,:)=0.
225      zq(:,:,:) = 0.
226      zq0(:,:,:) = 0.
227      entr(:) = 0.
228      mr_dust_mass(:,:) = 0.
229      mr_dust_number(:,:) = 0.
230      mr_topdust_mass(:,:) = 0.
231      mr_topdust_number(:,:) = 0.
232      t_top(:,:) = 0.
233      dt_top(:) = 0.
234      newzt(:,:) = 0.
235      lmons(:) = 1
236      lsummit(:) =1
237      lwmax(:) = 1
238      deltahr(:,:) = 0.
239      zdtvert(:,:) = 0.
240      wqmass(:,:) = 0.
241      wqnumber(:,:) = 0.       
242      coefdetrain(:,:) = 1.
243      dqm_mass_pbl(:)=0.
244      dqm_number_pbl(:)=0.
245      nsubtimestep(:)=1
246      masse_pbl(:)=0.
247      detrain_rate(:,:) = 0.
248
249      !! Update the initial temperature
250      zt(1:ngrid,1:nlayer)=pt(1:ngrid,1:nlayer)+pdt(1:ngrid,1:nlayer)*ptimestep
251      newzt(1:ngrid,1:nlayer)=zt(1:ngrid,1:nlayer)
252      t_env(1:ngrid,1:nlayer)=zt(1:ngrid,1:nlayer)
253      t_top(1:ngrid,1:nlayer)=zt(1:ngrid,1:nlayer)
254
255      !! Update the initial mixing ratios
256      zq0(1:ngrid,1:nlayer,1:nq)=pq(1:ngrid,1:nlayer,1:nq) !+pdq(1:ngrid,1:nlayer,1:nq)*ptimestep update after rocket dust storm scheme ?
257      zq(1:ngrid,1:nlayer,1:nq)=zq0(1:ngrid,1:nlayer,1:nq)
258      zq_dust_mass(1:ngrid,1:nlayer)=zq(1:ngrid,1:nlayer,igcm_dust_mass)
259      zq_dust_number(1:ngrid,1:nlayer)=zq(1:ngrid,1:nlayer,igcm_dust_number)
260      zq_topdust_mass(1:ngrid,1:nlayer)=zq(1:ngrid,1:nlayer,igcm_topdust_mass)
261      zq_topdust_number(1:ngrid,1:nlayer)=zq(1:ngrid,1:nlayer,igcm_topdust_number)
262         
263! ----------------------------------------------------------------------
264! 1. Radiative heating
265! ----------------------------------------------------------------------
266
267       ! *********************************************************************
268       ! 1.1. Call the second radiative transfer for topdust, obtain the extra heating
269       ! *********************************************************************
270        CALL callradite(icount,ngrid,nlayer,nq,zday,zls,zq,albedo,     &
271                 emis,mu0,pplev,pplay,pt,tsurf,fract,dist_sol,igout,   &
272                 zdtlw1,zdtsw1,fluxsurf_lw1,fluxsurf_sw1,fluxtop_lw1,  &
273                 fluxtop_sw1,tauref,tau,aerosol,dsodust,tauscaling,    &
274                 taucloudtes,rdust,rice,nuice,co2ice,rstormdust,rtopdust, &
275                 totstormfract,clearatm,dsords,alpha_hmons,nohmons,    &
276                 clearsky,totcloudfrac)
277       ! **********************************************************************
278       ! 1.2. Compute radiative vertical velocity for entrained topdust
279       ! **********************************************************************
280        DO ig=1,ngrid
281          IF ( (mu0(ig) .gt. mu0lim) .and. (alpha_hmons(ig) .gt. 0.) ) THEN
282            !! **********************************************************************
283            !! Temperature profile above the mountain and in the close environment
284            call t_topmons(nlayer,summit(ig),hsummit(ig),hmons(ig),zt(ig,:),pzlay(ig,:), &
285                               t_top(ig,:),dt_top(ig),t_env(ig,:),lsummit(ig),lmons(ig))
286            !! **********************************************************************
287            !! Calculation of the extra heating : computing heating rates
288            !! gradient at boundaries of each layer
289            zdtlw1_lev(ig,1)=0.
290            zdtsw1_lev(ig,1)=0.
291            zdtlw_lev(ig,1)=0.
292            zdtsw_lev(ig,1)=0.
293            ztlev(ig,1)=zt(ig,1)
294            DO l=1,nlayer-1
295              !! Calculation for the background dust AND the concentrated topdust
296              zdtlw1_lev(ig,l+1)=(zdtlw1(ig,l)*(pzlay(ig,l+1)-pzlev(ig,l+1))+ &
297                           zdtlw1(ig,l+1)*(pzlev(ig,l+1)-pzlay(ig,l)))  /  &
298                              (pzlay(ig,l+1)-pzlay(ig,l))
299           
300              zdtsw1_lev(ig,l+1)=(zdtsw1(ig,l)*(pzlay(ig,l+1)-pzlev(ig,l+1))+ &
301                           zdtsw1(ig,l+1)*(pzlev(ig,l+1)-pzlay(ig,l)))  /  &
302                              (pzlay(ig,l+1)-pzlay(ig,l))
303              !! Calculation for the background dust only
304              zdtlw_lev(ig,l+1)=(pdtlw(ig,l)*(pzlay(ig,l+1)-pzlev(ig,l+1))+   &
305                           pdtlw(ig,l+1)*(pzlev(ig,l+1)-pzlay(ig,l)))  /   &
306                              (pzlay(ig,l+1)-pzlay(ig,l))
307           
308              zdtsw_lev(ig,l+1)=(pdtsw(ig,l)*(pzlay(ig,l+1)-pzlev(ig,l+1))+   &
309                           pdtsw(ig,l+1)*(pzlev(ig,l+1)-pzlay(ig,l)))  /   &
310                              (pzlay(ig,l+1)-pzlay(ig,l))
311              !! Temperature at the levels
312              ztlev(ig,l+1)=(zt(ig,l)*(pzlay(ig,l+1)-pzlev(ig,l+1))+          &
313                           zt(ig,l+1)*(pzlev(ig,l+1)-pzlay(ig,l)))  /      &
314                              (pzlay(ig,l+1)-pzlay(ig,l))
315              !! Temperature above the mountain at the levels
316              t_top_lev(ig,l+1)=(t_top(ig,l)*(pzlay(ig,l+1)-pzlev(ig,l+1))+          &
317                           t_top(ig,l+1)*(pzlev(ig,l+1)-pzlay(ig,l)))  /      &
318                              (pzlay(ig,l+1)-pzlay(ig,l))
319
320            ENDDO ! DO l=1,nlayer-1
321            !! **********************************************************************
322            !! Vertical velocity profile for extra heating balanced by adiabatic cooling
323            !! Gradient at boundaries of each layer, start from surface
324            zdtvert(ig,1)=0.
325            DO l=1,nlayer-1
326              zdtvert(ig,l+1)=(t_top_lev(ig,l+1)-t_top_lev(ig,l))/(pzlay(ig,l+1)-pzlay(ig,l))
327            ENDDO
328            !! Extra heating balanced by adiabatic cooling
329            DO l=1,nlayer
330              deltahr(ig,l)=(zdtlw1_lev(ig,l)+zdtsw1_lev(ig,l))  &
331                                          -(zdtlw_lev(ig,l)+zdtsw_lev(ig,l))
332              wrad(ig,l)=-deltahr(ig,l)/(g/cpp+   &
333                                         max(zdtvert(ig,l),-0.99*g/cpp))
334              !! Limit of the vertical wind velocity in case of lapse rate close to adiabatic
335              wrad(ig,l)=max(wrad(ig,l),-wmax)
336              wrad(ig,l)=min(wrad(ig,l),wmax)
337              !! ATTENTION !! to simplify here, no downward velocity calculated
338              if (wrad(ig,l).gt.0.) then
339                wrad(ig,l)=0. 
340              endif
341            ENDDO
342          ENDIF ! IF ((mu0(ig) .gt. mu0lim) .and. alpha_hmons(ig) .gt. 0.)
343        ENDDO ! DO ig=1,ngrid
344
345! ----------------------------------------------------------------------
346! 2. Vertical velocity profile
347! ----------------------------------------------------------------------
348
349       ! **********************************************************************
350       ! 2.1 Compute total vertical velocity for entrained topdust: buoyancy + radiative
351       ! **********************************************************************
352       DO ig=1,ngrid
353         IF ( (mu0(ig) .gt. mu0lim) .and. (alpha_hmons(ig) .gt. 0.) ) THEN
354           !! Positive buoyancy: negative vertical velocity entrains UP
355           IF (dt_top(ig) .gt. 0.) THEN
356             !! Convergence of vertical winds at the top of the mountain
357             w0(ig)=-k0*g*sqrt((dt_top(ig)/t_env(ig,lsummit(ig))))
358             !! Case the vertical velocity at the top of the mountain > wrad
359             IF (w0(ig).lt.wrad(ig,lsummit(ig)+1)) then
360               wup(ig,lsummit(ig)+1)=w0(ig)
361               wfin(ig,lsummit(ig)+1)=w0(ig)
362               newzt(ig,lsummit(ig))= t_top(ig,lsummit(ig))
363               !! Temperature profile from the top of the summit to the top of the atmosphere
364               DO l=lsummit(ig)+1,nlayer-1
365                 !ATTENTION: test without wrad, T is only decreasing because of the adiabatic gradient
366                 !newzt(ig,l)=newzt(ig,l-1)-(g/cpp)*        &
367                 !               (pzlay(ig,l)-pzlay(ig,l-1))
368                 !! Case of superadiabatic layer
369                 IF (zdtvert(ig,l) .lt. -g/cpp) then
370                    newzt(ig,l)=t_top(ig,l)
371                 !! New temperature due to radiative heating balanced by adiabatic cooling
372                 ELSE
373                    newzt(ig,l)=newzt(ig,l-1)+ &
374                               ( (deltahr(ig,l)/-wfin(ig,l))-g/cpp )*  &
375                               ( pzlay(ig,l)-pzlay(ig,l-1) )
376                 ENDIF ! (zdtvert(ig,l) .lt. -g/cpp)
377                 !! Vertical velocity profile due to the presence of the mountain with the new temperature
378                 !! Square of the vertical velocity profile with the new temperature
379                 wup2(ig,l+1)=(1.-2*k1*(pzlev(ig,l+1)-pzlev(ig,l)))*&
380                              (wup(ig,l)**2)+2.*k2*g*(pzlev(ig,l+1) &
381                             -pzlev(ig,l))*((newzt(ig,l)       &
382                             -t_env(ig,l))/t_env(ig,l))
383                 !! Vertical velocity profile if W2 > 0
384                 IF (wup2(ig,l+1) .gt. 0.) THEN
385                   wup(ig,l+1)=-sqrt(wup2(ig,l+1))
386                   wfin(ig,l+1)=wup(ig,l+1)
387                   IF (wup(ig,l+1) .gt. wrad(ig,l+1)) then
388                     DO ll=l,nlayer-1
389                       newzt(ig,ll)=zt(ig,ll)
390                       wfin(ig,ll+1)=wrad(ig,ll+1)
391                     ENDDO
392                     EXIT
393                   ENDIF
394                 !! Vertical velocity profile if W2 < 0
395                 ELSE
396                   DO ll=l,nlayer-1
397                     newzt(ig,ll)=zt(ig,ll)
398                     wfin(ig,ll+1)=wrad(ig,ll+1)
399                   ENDDO
400                     EXIT
401                 ENDIF ! IF (wup2(ig,l+1) .gt. 0.)   
402               ENDDO ! DO l=lsummit(ig)+1,nlayer-1
403             !! Case the vertical velocity at the top of the mountain < wrad
404             ELSE
405               DO ll=lsummit(ig),nlayer-1
406                  newzt(ig,ll)=zt(ig,ll)
407                  wfin(ig,ll+1)=wrad(ig,ll+1)
408               ENDDO
409             ENDIF !(w0(ig).lt.wrad(ig,lsummit(ig)+1))
410           !! Positive buoyancy: positive vertical velocity entrains DOWN
411           ELSE
412             DO l=lsummit(ig)+1,nlayer
413                wfin(ig,l)=wrad(ig,l)
414             ENDDO
415           ENDIF ! IF (dt_top(ig) .gt. 0.)           
416       ! **********************************************************************
417       ! 2.2 Find the level lwmax of the maximum vertical velocity caused by the
418       ! mountain presence (wup), where to entrain the dust from the PBL
419       ! **********************************************************************
420           IF (minloc(wup(ig,:),dim=1).lt.nlayer) THEN
421             lwmax(ig)=minloc(wup(ig,:),dim=1)
422           ENDIF
423           zlaywmax(ig)=pzlay(ig,lwmax(ig)) ! wup(lwmax) acts on level lwmax, going to layer lwmax
424       ! **********************************************************************
425       ! 2.3 Compute the subtimestep to conserve the mass in the Van Leer transport
426       ! **********************************************************************
427           !! Calculation of the subtimesteps
428           dtmax=ptimestep
429           DO l=lwmax(ig),nlayer
430             IF (wfin(ig,l).lt.0.) THEN
431               dtmax=min(dtmax,(pzlev(ig,l)-pzlev(ig,l-1))/  &
432                                 (secu*abs(wfin(ig,l))))
433             ELSE IF (wfin(ig,l).gt.0.) then
434               dtmax=min(dtmax,(pzlev(ig,l+1)-pzlev(ig,l))/  &
435                                 (secu*abs(wfin(ig,l))))
436             ENDIF
437           ENDDO
438           nsubtimestep(ig)= int(ptimestep/dtmax)
439           subtimestep(ig)=ptimestep/float(nsubtimestep(ig))
440           !! Mass flux generated by wup in kg/m2
441           DO l=1,nlayer!+1
442             w(ig,l)=wfin(ig,l)*pplev(ig,l)/(r*ztlev(ig,l)) &
443                      *subtimestep(ig)
444           ENDDO ! l=1,nlayer
445                       
446          ENDIF ! ((mu0(ig) .gt. mu0lim)...
447        ENDDO ! DO ig=1,ngrid
448
449! ----------------------------------------------------------------------
450! 3. Dust entrainment by slope winds above the mountain
451! ----------------------------------------------------------------------
452        !! rho on the layer
453        rho(:,:)=pplay(:,:)/(r*pt(:,:))
454        !! rhobarz(l) = rho(l+1/2): rho on the levels
455        rhobarz(:,1)=rho(:,1)
456        DO l=2,nlayer
457          rhobarz(:,l)=pplev(:,l)/(r*0.5*(pt(:,l)+pt(:,l-1)))
458        ENDDO
459        !! Mass computation
460        DO l=1,nlayer
461          masse(:,l)=(pplev(:,l)-pplev(:,l+1))/g
462        ENDDO
463
464        DO ig=1,ngrid
465          IF ( (mu0(ig) .gt. mu0lim) .and. (alpha_hmons(ig) .gt. 0.) ) THEN
466            !! Total air mass within the PBL before entrainment (=> by PBL we mean between the surface and the layer where the vertical wind is maximum)
467            masse_pbl(ig)=0.
468            DO l=1,lwmax(ig)-1
469              masse_pbl(ig)=masse_pbl(ig)+(pplev(ig,l)-pplev(ig,l+1))/g
470            ENDDO
471          ENDIF ! ((mu0(ig) .gt. mu0lim)...
472        ENDDO ! ig=1,ngrid
473       ! **********************************************************************
474       ! 3.1. Entrainment
475       ! **********************************************************************
476        DO ig=1,ngrid
477          IF ( (mu0(ig) .gt. mu0lim) .and. (alpha_hmons(ig) .gt. 0.) .and. (masse_pbl(ig) .gt. 0.) ) THEN
478            !! Transport of background dust + concentrated topdust above lwmax
479            DO l=lwmax(ig),nlayer
480              mr_dust_mass(ig,l) = zq_dust_mass(ig,l)
481              mr_dust_number(ig,l) = zq_dust_number(ig,l)
482              mr_topdust_mass(ig,l) = zq_dust_mass(ig,l) &
483                                     +zq_topdust_mass(ig,l)/alpha_hmons(ig)
484              mr_topdust_number(ig,l) = zq_dust_number(ig,l) &
485                                     +zq_topdust_number(ig,l)/alpha_hmons(ig)
486            ENDDO ! l=lwmax(ig),nlayer
487            !! Entrainment flux from the PBL
488            entr(ig) = alpha_hmons(ig)*wup(ig,lwmax(ig))*rhobarz(ig,lwmax(ig))/masse_pbl(ig)
489            !! If entrains more than available masse_pbl (abs(entr) x mass_pbl x ptimestep > masse_pbl)
490            if (abs(entr(ig)) .gt. 1./ptimestep) then
491              entr(ig) = -(1./ptimestep)
492            end if
493       ! **********************************************************************
494       ! 3.2. Vertical transport: Van Leer
495       ! **********************************************************************
496            !! Loop over the subtimesteps
497            DO tsub=1,nsubtimestep(ig)
498              !! qbar_pbl: total mixing ratio within the PBL
499              masse_pbl_dust_mass(ig)=0.
500              masse_pbl_dust_number(ig)=0.
501              DO l=1,lwmax(ig)-1
502                masse_pbl_dust_mass(ig)=masse_pbl_dust_mass(ig)+zq_dust_mass(ig,l)*(pplev(ig,l)-pplev(ig,l+1))/g
503                masse_pbl_dust_number(ig)=masse_pbl_dust_number(ig)+zq_dust_number(ig,l)*(pplev(ig,l)-pplev(ig,l+1))/g
504              ENDDO
505              qbar_mass_pbl(ig)=masse_pbl_dust_mass(ig)/masse_pbl(ig)
506              qbar_number_pbl(ig)=masse_pbl_dust_mass(ig)/masse_pbl(ig)
507              !! integration of the equation dq/dt = -(entr)q, with entr constant --> w0 < 0 when up so the equation is dq/dt = (entr)q
508              dqm_mass_pbl(:)=0.
509              dqm_number_pbl(:)=0.
510              DO l=1,lwmax(ig)-1 ! this time we take the dust from the surface up to the level, where the velocity is maximum
511                !! Total dust entrained from the PBL:
512                dqm_mass_pbl(ig)=dqm_mass_pbl(ig)+(1.-exp(entr(ig)*subtimestep(ig)))*zq_dust_mass(ig,l)*(pplev(ig,l)-pplev(ig,l+1))/g
513                dqm_number_pbl(ig)=dqm_number_pbl(ig)+(1.-exp(entr(ig)*subtimestep(ig)))*zq_dust_number(ig,l)*(pplev(ig,l)-pplev(ig,l+1))/g
514                !! Background dust after entrainment (explicit: qdust(ig,l)=qdust(ig,l)-entr(ig)*qdust(ig,l)*ptimestep)
515                zq_dust_mass(ig,l)=zq_dust_mass(ig,l)-(1.-exp(entr(ig)*subtimestep(ig)))*zq_dust_mass(ig,l)
516                zq_dust_number(ig,l)=zq_dust_number(ig,l)-(1.-exp(entr(ig)*subtimestep(ig)))*zq_dust_number(ig,l)
517              ENDDO
518              !! Van Leer scheme (from lwmax to nlayer)
519              wqmass(ig,:)=0.
520              wqnumber(ig,:)=0.
521              CALL van_leer(nlayer,mr_topdust_mass(ig,:),2.,lwmax(ig),  &
522                  masse(ig,:),w(ig,:),wqmass(ig,:),masse_pbl(ig),dqm_mass_pbl(ig),alpha_hmons(ig),qbar_mass_pbl(ig))
523              CALL van_leer(nlayer,mr_topdust_number(ig,:),2.,lwmax(ig),  &
524                  masse(ig,:),w(ig,:),wqnumber(ig,:),masse_pbl(ig),dqm_number_pbl(ig),alpha_hmons(ig),qbar_number_pbl(ig))
525            ENDDO !tsub=...
526       ! **********************************************************************
527       ! 3.3. Re-calculation of the mixing ratios after vertical transport
528       ! **********************************************************************
529            !! Redistribution from lwmax to nlayer
530            DO l=lwmax(ig),nlayer
531              !! General and "healthy" case
532              IF (mr_topdust_mass(ig,l).ge.mr_dust_mass(ig,l)) THEN
533                zq_dust_mass(ig,l) = mr_dust_mass(ig,l)
534                zq_dust_number(ig,l) = mr_dust_number(ig,l)
535                zq_topdust_mass(ig,l) = alpha_hmons(ig)*(mr_topdust_mass(ig,l)-mr_dust_mass(ig,l))
536                zq_topdust_number(ig,l) = alpha_hmons(ig)*(mr_topdust_number(ig,l)-mr_dust_number(ig,l))
537              !! Particular case: there is less than initial dust mixing ratio after the vertical transport
538              ELSE
539                zq_dust_mass(ig,l) = (1.-alpha_hmons(ig))*mr_dust_mass(ig,l)+alpha_hmons(ig)*mr_topdust_mass(ig,l)
540                zq_dust_number(ig,l) = (1.-alpha_hmons(ig))*mr_dust_number(ig,l)+alpha_hmons(ig)*mr_topdust_number(ig,l)
541                zq_topdust_mass(ig,l) = 0.
542                zq_topdust_number(ig,l) = 0.
543              ENDIF
544            ENDDO ! DO l=lwmax(ig),nlayer
545       ! **********************************************************************
546       ! 3.4. Calculation of the tendencies of the vertical transport from the surface up to the top of the atmosphere
547       ! **********************************************************************
548            DO l=1,nlayer
549              dqvl_topdust_mass(ig,l) = (zq_topdust_mass(ig,l)- &
550                                    zq0(ig,l,igcm_topdust_mass)) /ptimestep
551              dqvl_topdust_number(ig,l) = (zq_topdust_number(ig,l)- &
552                                      zq0(ig,l,igcm_topdust_number)) /ptimestep
553              dqvl_dust_mass(ig,l) = (zq_dust_mass(ig,l)-zq0(ig,l,igcm_dust_mass)) /ptimestep
554              dqvl_dust_number(ig,l) = (zq_dust_number(ig,l)-zq0(ig,l,igcm_dust_number)) /ptimestep
555           ENDDO
556
557          ENDIF ! ((mu0(ig) .gt. mu0lim)...
558        ENDDO ! ig=1,ngrid
559
560! ----------------------------------------------------------------------
561! 4. Detrainment: topdust is converted to background dust
562! ----------------------------------------------------------------------
563
564        !! **********************************************************************
565        !! 4.1 Compute the coefficient of detrainment
566        !! **********************************************************************
567        DO ig=1,ngrid
568          !DO l=lwmax(ig),nlayer-1
569          DO l=1,nlayer!-1
570            !! Detrainment during the day
571            IF ( (mu0(ig) .gt. mu0lim) .and. (zq_topdust_mass(ig,l) .gt. zq_dust_mass(ig,l)*0.01)) THEN
572               coefdetrain(ig,l)=1.*( rhobarz(ig,l+1)*abs(wfin(ig,l+1)) - rhobarz(ig,l)*abs(wfin(ig,l)) ) / masse(ig,l)
573               !! Detrainment when abs(w(l)) > abs(w(l+1)), i.e. coefdetrain < 0
574               if ( coefdetrain(ig,l).lt.0.) then
575                dqdet_topdust_mass(ig,l)=-(1.-exp(coefdetrain(ig,l)*ptimestep))*zq_topdust_mass(ig,l)/ptimestep
576                dqdet_topdust_number(ig,l)=-(1.-exp(coefdetrain(ig,l)*ptimestep))*zq_topdust_number(ig,l)/ptimestep
577                ! for diagnostics
578                detrain_rate(ig,l)=(1.-exp(coefdetrain(ig,l)*ptimestep))
579                !! One cannot detrain more than available topdust
580                if ( (abs(dqdet_topdust_mass(ig,l)).gt.zq_topdust_mass(ig,l)/ptimestep) .or. (abs(dqdet_topdust_number(ig,l)).gt.zq_topdust_number(ig,l)/ptimestep) ) then
581                  dqdet_topdust_mass(ig,l)=-zq_topdust_mass(ig,l)/ptimestep
582                  dqdet_topdust_number(ig,l)=-zq_topdust_number(ig,l)/ptimestep
583                  detrain_rate(ig,l)=1.
584                endif
585               !else!entrainment
586               !  dqdet_topdust_mass(ig,l)=-(1.-exp(coefdetrain(ig,l)*ptimestep))*zq_dust_mass(ig,l)/ptimestep
587               !  dqdet_topdust_number(ig,l)=-(1.-exp(coefdetrain(ig,l)*ptimestep))*zq_dust_number(ig,l)/ptimestep
588               endif
589            !! Full detrainment during the night imposed
590            ELSE
591               dqdet_topdust_mass(ig,l)=-zq_topdust_mass(ig,l)/ptimestep
592               dqdet_topdust_number(ig,l)=-zq_topdust_number(ig,l)/ptimestep
593               detrain_rate(ig,l)=1.
594            ENDIF
595          ENDDO ! DO l=1,nlayer
596        ENDDO ! DO ig=1,ngrid
597
598! ----------------------------------------------------------------------
599! 5. Final tendencies: vertical transport + detrainment
600! ----------------------------------------------------------------------     
601
602        DO ig=1,ngrid
603          DO l=1,nlayer     
604          pdqtop(ig,l,igcm_topdust_mass)=dqdet_topdust_mass(ig,l) &
605                                                 +dqvl_topdust_mass(ig,l)
606          pdqtop(ig,l,igcm_topdust_number)=dqdet_topdust_number(ig,l) &
607                                                 +dqvl_topdust_number(ig,l)
608          pdqtop(ig,l,igcm_dust_mass)= -dqdet_topdust_mass(ig,l) &
609                                       +dqvl_dust_mass(ig,l)
610          pdqtop(ig,l,igcm_dust_number)= -dqdet_topdust_number(ig,l) &
611                                       +dqvl_dust_number(ig,l)
612          ENDDO ! DO l=1,nlayer
613        ENDDO ! DO ig=1,ngrid
614
615
616! **********************************************************************
617! WRITEDIAGFI
618! **********************************************************************
619        IF (ngrid.eq.1) THEN
620               CALL WRITEDIAGFI(ngrid,'wup_top', &
621                'wup_top','',1,wup(:,:))
622               CALL WRITEDIAGFI(ngrid,'wrad_top', &
623                'wrad_top','',1,wrad(:,:))
624               CALL WRITEDIAGFI(ngrid,'wfin_top', &
625                'wfin_top','',1,wfin(:,:))
626               CALL WRITEDIAGFI(ngrid,'wlwmax_top', &
627                'wlwmax_top','',0,wup(:,lwmax(1)))
628               CALL WRITEDIAGFI(ngrid,'w0_top', &
629                'w0_top','',0,wup(:,lsummit(1)+1))
630               CALL WRITEDIAGFI(ngrid,'alpha_hmons', &
631                'alpha_hmons','',0,alpha_hmons)
632               CALL WRITEDIAGFI(ngrid,'zt_top', &
633                'zt_top','',1,t_top(:,:))
634               CALL WRITEDIAGFI(ngrid,'dt_top', &
635                'dt_top','',0,dt_top(:))
636               CALL WRITEDIAGFI(ngrid,'envtemp', &
637                'envtemp','',1,zt(:,:))
638               CALL WRITEDIAGFI(ngrid,'t_env', &
639                't_env','',1,t_env(:,:))
640               CALL WRITEDIAGFI(ngrid,'newzt_top', &
641                'newzt_top','',1,newzt(:,:))
642               CALL WRITEDIAGFI(ngrid,'deltahr_top', &
643                'deltahr_top','',1,deltahr(:,:))
644               CALL WRITEDIAGFI(ngrid,'rholev', &
645                'rholev','',1,rho(:,:))
646               CALL WRITEDIAGFI(ngrid,'rhobarz', &
647                'rhobarz','',1,rhobarz(:,:))
648               CALL WRITEDIAGFI(ngrid,'zlsummit', &
649                'zlsummit','',0,pzlay(:,lsummit(1)))
650               CALL WRITEDIAGFI(ngrid,'zlwmax', &
651                'zlwmax','',0,pzlay(:,lwmax(1)))
652               CALL WRITEDIAGFI(ngrid,'pzlev_top', &
653                'pzlev_top','',1,pzlev(:,:))
654               CALL WRITEDIAGFI(ngrid,'coefdetrain', &
655                'coefdetrain','',1,coefdetrain(:,:))
656               CALL WRITEDIAGFI(ngrid,'zdtvert', &
657                'zdtvert','',1,zdtvert(:,:))
658               CALL WRITEDIAGFI(ngrid,'entr', &
659                'entr','',0,entr(:))
660        ELSE
661               CALL WRITEDIAGFI(ngrid,'wup_top', &
662                'wup_top','',3,wup(:,:))
663               CALL WRITEDIAGFI(ngrid,'wup2_top', &
664                'wup2_top','',3,wup2(:,:))
665               CALL WRITEDIAGFI(ngrid,'wrad_top', &
666                'wrad_top','',3,wrad(:,:))
667               CALL WRITEDIAGFI(ngrid,'wfin_top', &
668                'wfin_top','',3,wfin(:,:))
669               CALL WRITEDIAGFI(ngrid,'alpha_hmons', &
670                'alpha_hmons','',2,alpha_hmons)
671               CALL WRITEDIAGFI(ngrid,'zt_top', &
672                'zt_top','',3,t_top(:,:))
673               CALL WRITEDIAGFI(ngrid,'ztemp', &
674                'envtemp','',3,zt(:,:))
675               CALL WRITEDIAGFI(ngrid,'zt_env', &
676                't_env','',3,t_env(:,:))
677               CALL WRITEDIAGFI(ngrid,'zdtvert_top', &
678                'zdtvert_top','',3,zdtvert(:,:))
679               CALL WRITEDIAGFI(ngrid,'newzt_top', &
680                'newzt_top','',3,newzt(:,:))
681               CALL WRITEDIAGFI(ngrid,'deltahr_top', &
682                'deltahr_top','',3,deltahr(:,:))
683               CALL WRITEDIAGFI(ngrid,'rhobarz', &
684                'rhobarz','',3,rhobarz(:,:))
685               CALL WRITEDIAGFI(ngrid,'zlwmax', &
686                'zlwmax','',2,zlaywmax(:))
687               CALL WRITEDIAGFI(ngrid,'coefdetrain', &
688                'coefdetrain','',3,coefdetrain(:,:))
689               CALL WRITEDIAGFI(ngrid,'detrain_rate', &
690                              'detrain_rate', &
691                              '',3,detrain_rate(:,:))
692
693        ENDIF
694       
695        END SUBROUTINE topmons
696
697!=======================================================================     
698
699! **********************************************************************
700! Subroutine to determine both temperature profiles above and near
701! a sub-grid scale mountain
702!***********************************************************************
703       SUBROUTINE t_topmons(nlayer,summit,hsummit,hmons,zt,zlay,t_top,dt_top,t_env,lsummit,lmons)
704
705       USE comcstfi_h, only: g,cpp
706
707       IMPLICIT NONE
708
709!--------------------------------------------------------
710! Input Variables
711!--------------------------------------------------------
712       integer,intent(in) :: nlayer
713       real,intent(in) :: summit          ! Height of the mountain summit
714       real,intent(in) :: hmons           ! Height of the mountain slope
715       real,intent(in) :: hsummit         ! Height of the mountain summit from the GCM surface
716       real,intent(in) :: zt(nlayer)      ! large scale temperature profile
717       real,intent(in) :: zlay(nlayer)    ! height at the middle of each layer
718!--------------------------------------------------------
719! Output Variables
720!--------------------------------------------------------
721       real,intent(out) :: t_top(nlayer) ! temperature  above the mountain
722       real,intent(out) :: dt_top        ! temperature difference between the slope and
723                                         ! the environment
724       real,intent(out) :: t_env(nlayer)   ! temperature of the environment next to the mountain
725       integer,intent(out) :: lsummit      ! layer reached by the summit height in the GCM
726       integer,intent(out) :: lmons        ! layer of the real temperature to be considered near to the mountain top
727
728!--------------------------------------------------------
729! Local Variables
730!--------------------------------------------------------
731       integer l,ll
732       real zlmons
733
734! **********************************************************************
735       t_env(:)=zt(:)
736       t_top(:)=zt(:)
737       dt_top=0.
738       lsummit=1
739       lmons=1
740
741       !! Layer where the dust is injected
742       do while (hsummit .ge. zlay(lsummit))
743           !! highest layer reached by the mountain (we don't interpolate and define zlay(lsummit) as the top of the mountain)
744           lsummit=lsummit+1
745       enddo
746       !! temperature above the mountain is set to the surface temperature
747       t_top(lsummit)=zt(1)
748       do l=lsummit,nlayer-1
749          !! temperature above the mountain follows the adiabatic
750          t_top(l+1)=t_top(l)-(zlay(l+1)-zlay(l))*g/cpp
751       enddo
752
753       !! Layer where to take the temperature above the mountain
754       do while (hmons .ge. zlay(lmons))
755           lmons=lmons+1
756       enddo
757       !! Real temperature of the environment near to the mountain is t_env(lsummit)=zt(lmons)
758       !! (More simple and makes no real difference is to impose t_env(:)=zt(:))
759       if (lmons.gt.lsummit) then
760         t_env(lsummit)=zt(lmons)
761         zlmons=zlay(lmons)
762         do l=0,nlayer-lsummit-1!2
763           zlmons=zlmons+(zlay(lsummit+l+1)-zlay(lsummit+l))
764           ll=lmons
765           do while (zlmons .ge. zlay(ll) .and. ll.lt.nlayer )
766             ll=ll+1
767           enddo
768           ll=ll-1
769           !! Interpolation above lsummit
770           t_env(lsummit+l+1)= zt(ll) + ((zlmons-zlay(ll))*(zt(ll+1)-zt(ll))/(zlay(ll+1)-zlay(ll)))
771         enddo
772         t_env(nlayer)=zt(nlayer)
773       endif ! (lmons.gt.lsummit)
774       do l=1,nlayer
775          !! temperature above the mountain follows the adiabatic up to reach the environment temperature
776          if (t_top(l).le.t_env(l)) then
777            t_top(l)=t_env(l)
778          endif
779       enddo
780       !!  Temperature delta created at the top of the mountain
781       dt_top = t_top(lsummit)-t_env(lsummit)
782
783       END SUBROUTINE t_topmons
784
785!======================================================================= 
786! **********************************************************************
787! Subroutine to determine the vertical transport with
788! a Van Leer advection scheme (copied from the sedimentation scheme --> see vlz_fi.F)
789!***********************************************************************
790      SUBROUTINE van_leer(nlay,q,pente_max,lwmax,masse,w,wq,masse_pbl,dqm_pbl,alpha_hmons,qbar_pbl)
791
792      IMPLICIT NONE
793
794!--------------------------------------------------------
795! Input/Output Variables
796!--------------------------------------------------------
797      INTEGER,INTENT(IN) :: nlay       ! number of atmospheric layers
798      REAL,INTENT(IN) :: masse(nlay)   ! mass of the layer Dp/g
799      REAL,INTENT(IN) :: pente_max     != 2 conseillee
800      INTEGER,INTENT(IN) :: lwmax      ! layer of dust injection above the mountain, where the vertical velocity is maximum
801      REAL,INTENT(INOUT) :: w(nlay)    ! atmospheric mass "transferred" at each timestep (kg.m-2)
802      REAL,INTENT(INOUT) :: wq(nlay+1)
803      REAL,INTENT(INOUT) :: q(nlay)    ! mixing ratio (kg/kg)
804      REAL,INTENT(IN) :: masse_pbl
805      REAL,INTENT(IN) :: dqm_pbl
806      REAL,INTENT(IN) :: alpha_hmons
807      REAL,INTENT(IN) :: qbar_pbl
808
809!--------------------------------------------------------
810! Local Variables
811!--------------------------------------------------------
812
813      INTEGER i,l,j,ii
814      REAL dzq(nlay),dzqw(nlay),adzqw(nlay),dzqmax
815      REAL sigw, Mtot, MQtot
816      INTEGER m
817
818! **********************************************************************
819!  Mixing ratio vertical gradient at the levels
820! **********************************************************************
821      do l=lwmax+1,nlay !l=2,nlay
822            dzqw(l)=q(l-1)-q(l)
823            adzqw(l)=abs(dzqw(l))
824      enddo
825
826      do l=lwmax+1,nlay-1 !l=2,nlay-1
827            if(dzqw(l)*dzqw(l+1).gt.0.) then
828                dzq(l)=0.5*(dzqw(l)+dzqw(l+1))
829            else
830                dzq(l)=0.
831            endif
832            dzqmax=pente_max*min(adzqw(l),adzqw(l+1))
833            dzq(l)=sign(min(abs(dzq(l)),dzqmax),dzq(l))
834      enddo
835
836      dzq(lwmax)=0. !! dzq(1)=0. => Attention: in the case of van leer only above the mountain it is very important to initialize the transport from lwmax !!
837      dzq(nlay)=0.
838! **********************************************************************
839!  Vertical advection
840! **********************************************************************
841
842       !! No flux at the model top:
843       wq(nlay+1)=0.
844
845       !! Mass flux injected at lwmax
846       wq(lwmax) = -dqm_pbl/alpha_hmons ! dqm_pbl = alpha_hmons x wup(wmax) x rho(lwmax) x ptimestep x qbar_pbl
847                                        ! /alpha_hmons because the variable considered is mr_topdust
848       do l = lwmax,nlay-1
849
850!      1) Compute wq where w < 0 (up) (UPWARD TRANSPORT)     
851!      ===============================
852
853         if (w(l+1).le.0) then
854!         Regular scheme (transfered mass < 1 layer)
855!         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
856          if(-w(l+1).le.masse(l))then
857            sigw=w(l+1)/masse(l)
858            wq(l+1)=w(l+1)*(q(l)-0.5*(1.+sigw)*dzq(l))
859!!-------------------------------------------------------
860!          The following part should not be needed in the
861!          case of an integration over subtimesteps
862!!-------------------------------------------------------
863!!         Extended scheme (transfered mass > 1 layer)
864!!         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
865!!          else
866!!             m = l-1
867!!             Mtot = masse(m+1)
868!!             MQtot = masse(m+1)*q(m+1)
869!!             if (m.lt.lwmax)goto 77!if (m.le.0)goto 77
870!!             do while(-w(l+1).gt.(Mtot+masse(m)))
871!!                m=m-1
872!!                Mtot = Mtot + masse(m+1)
873!!                MQtot = MQtot + masse(m+1)*q(m+1)
874!!                if (m.lt.lwmax)goto 77!if (m.le.0)goto 77
875!!             end do
876!! 77          continue
877!!
878!!              if (m.gt.lwmax) then!if (m.gt.0) then
879!!                sigw=(w(l+1)+Mtot)/masse(m)
880!!                wq(l+1)= -(MQtot + (-w(l+1)-Mtot)*         &
881!!                (q(m)-0.5*(1.+sigw)*dzq(m)))
882!!              else if ((-w(l+1).gt.(Mtot))) then
883!!                Mtot=Mtot+masse_pbl!*alpha_hmons
884!!                MQtot=MQtot+masse_pbl*qbar_pbl!*alpha_hmons
885!!                sigw=(w(l+1)+Mtot)/masse(m)
886!!                wq(l+1)= -(MQtot + (-w(l+1)-Mtot)*qbar_pbl)
887!!              else
888!!                w(l+1) = -Mtot
889!!                wq(l+1) = -MQtot
890!!              end if
891!!
892          endif
893
894!      2) Compute wq where w > 0 (down) (DOWNWARD TRANSPORT)     
895!      ===============================
896
897         else if (w(l).gt.0.) then
898!         Regular scheme (transfered mass < 1 layer)
899!         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
900          if(w(l).le.masse(l))then
901            sigw=w(l)/masse(l)
902            wq(l)=w(l)*(q(l)+0.5*(1.-sigw)*dzq(l))
903!!-------------------------------------------------------
904!          The following part should not be needed in the
905!          case of an integration over subtimesteps
906!!-------------------------------------------------------
907!!         Extended scheme (transfered mass > 1 layer)
908!!         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
909!!          else
910!!            m=l
911!!            Mtot = masse(m)
912!!            MQtot = masse(m)*q(m)
913!!            if(m.ge.nlay)goto 88
914!!            do while(w(l).gt.(Mtot+masse(m+1)))
915!!               m=m+1
916!!                Mtot = Mtot + masse(m)
917!!                MQtot = MQtot + masse(m)*q(m)
918!!                if(m.ge.nlay)goto 88
919!!            end do
920!! 88         continue
921!!            if (m.lt.nlay) then
922!!                sigw=(w(l)-Mtot)/masse(m+1)
923!!                wq(l)=(MQtot + (w(l)-Mtot)* &
924!!                          (q(m+1)+0.5*(1.-sigw)*dzq(m+1)) )
925!!            else
926!!                w(l) = Mtot
927!!                wq(l) = MQtot
928!!            end if
929          end if ! (w(l).le.masse(l))
930
931         end if ! (w(l+1).le.0)
932
933       enddo ! l = lwmax+1,nlay-1
934
935! **********************************************************************
936!  Mixing ratio update after the vertical transport
937! **********************************************************************
938       do l = lwmax,nlay-1 !l = 1,nlay-1  ! loop different than when w>0
939
940         if ( (wq(l+1)-wq(l)) .lt. -(masse(l)*q(l)) .and. (abs(wq(l+1)).gt. 0.) .and.  (abs(wq(l)).gt. 0.) ) then
941           wq(l+1) = wq(l)-masse(l)*q(l)
942         end if
943
944         q(l)=q(l) +  (wq(l+1)-wq(l))/masse(l)
945
946       enddo
947
948
949      end subroutine van_leer
950
951!********************************************************************************
952       ! initialization module variables
953       subroutine ini_topmons_mod(ngrid,nlayer)
954       
955       implicit none
956       
957       integer, intent(in) :: ngrid
958       integer, intent(in) :: nlayer
959       
960       allocate(alpha_hmons(ngrid))
961
962       end subroutine ini_topmons_mod
963       
964       subroutine end_topmons_mod
965       
966       implicit none
967       
968       if (allocated(alpha_hmons)) deallocate(alpha_hmons)
969
970       end subroutine end_topmons_mod       
971     
972      END MODULE topmons_mod
Note: See TracBrowser for help on using the repository browser.