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

Last change on this file since 2429 was 2417, checked in by emillour, 5 years ago

Mars GCM:
Add a new scheme to handle the dust and its radiative impact. Triggered using
a new flag dustscaling_mode=2 (dustscaling_mod=0: no rescaling at all, and
dustscaling_mode=1: full rescaling using tauscaling, GCMv5.3 style). Rescaling
is then only done on the radiative impact (see dust_scaling_mod.F90) of dust.
Moreover the scaling factor "dust_rad_adjust" is evaluated using the target dust
scenario opacity for the next sol and left to evolve linearly until then to not
impose the diurnal evolution of dust.
In practice, main changes or additions in the code are:

  • renamed flag "tauscaling_mode" as "dustscaling_mode"
  • moved parameter "t_scenario_sol" to "dust_param_mod"
  • adapted "compute_dustscaling" routine in "dust_scaling_mod"
  • added module "dust_rad_adjust_mod"
  • 2D fields "dust_rad_adjust_prev" and "dust_rad_adjust_next" required to compute coefficient "dust_rad_adjust" need to be stored in (re)startfi files

EM

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