source: LMDZ5/trunk/libf/phylmd/thermcell_main.F90 @ 1957

Last change on this file since 1957 was 1943, checked in by idelkadi, 11 years ago

Changes concerinng the Hourdin et al. 2002 version of the thermals and
Ayotte cases

calltherm.F90


call to thermcell_2002 modified :
1) iflag_thermals changed from 1 to >= 1000 ; iflag_thermals-1000
controls sub options.
2) thermals w and fraction in output files.

hbtm.F


Singularity in the 1/heat dependency of the Monin Obukov length L when
heat=0. Since 1/L is used rather than L, it is preferable to compute
directly L. There is a dependency in 1/u* then which is treated with a
threshold value.
(+ some cleaning in the syntax).

lmdz1d.F


If nday<0, -nday is used as the total number of time steps of the
simulation.
The option with imposed wtsurf and wqsurf read in lmdz1d.def was not
active anymore.
< IF(.NOT.ok_flux_surf) THEN
changed to

IF(.NOT.ok_flux_surf.or.max(abs(wtsurf),abs(wqsurf))>0.) THEN

before

fsens=-wtsurf*rcpd*rho(1)
flat=-wqsurf*rlvtt*rho(1)

phys_output_write.F90 et phys_local_var_mod.F90


Removing the d_u_ajsb contribution to duthe (same for dv).
Those tendencies are not computed by the model ...
< zx_tmp_fi3d(1:klon,1:klev)=d_u_ajs(1:klon,1:klev)/pdtphys - &
< d_u_ajsb(1:klon,1:klev)/pdtphys
---

zx_tmp_fi3d(1:klon,1:klev)=d_u_ajs(1:klon,1:klev)/pdtphys

! d_u_ajsb(1:klon,1:klev)/pdtphys

thermcell_dq.F90, thermcell_main.F90


Some cleaning

thermcell_old.F


Control by iflag_thermals >= 1000
wa_moy and fraca in outputs
+ cleaning

  • Property copyright set to
    Name of program: LMDZ
    Creation date: 1984
    Version: LMDZ5
    License: CeCILL version 2
    Holder: Laboratoire de m\'et\'eorologie dynamique, CNRS, UMR 8539
    See the license file in the root directory
  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 40.4 KB
RevLine 
[878]1!
[1403]2! $Id: thermcell_main.F90 1943 2014-01-22 09:51:36Z fairhead $
[878]3!
[972]4      SUBROUTINE thermcell_main(itap,ngrid,nlay,ptimestep  &
[878]5     &                  ,pplay,pplev,pphi,debut  &
6     &                  ,pu,pv,pt,po  &
7     &                  ,pduadj,pdvadj,pdtadj,pdoadj  &
[1026]8     &                  ,fm0,entr0,detr0,zqta,zqla,lmax  &
[878]9     &                  ,ratqscth,ratqsdiff,zqsatth  &
[927]10     &                  ,Ale_bl,Alp_bl,lalim_conv,wght_th &
[1403]11     &                  ,zmax0, f0,zw2,fraca,ztv &
[1638]12     &                  ,zpspsk,ztla,zthl &
13!!! nrlmd le 10/04/2012
14     &                  ,pbl_tke,pctsrf,omega,airephy &
15     &                  ,zlcl,fraca0,w0,w_conv,therm_tke_max0,env_tke_max0 &
16     &                  ,n2,s2,ale_bl_stat &
17     &                  ,therm_tke_max,env_tke_max &
18     &                  ,alp_bl_det,alp_bl_fluct_m,alp_bl_fluct_tke &
19     &                  ,alp_bl_conv,alp_bl_stat &
20!!! fin nrlmd le 10/04/2012
[1790]21     &                  ,ztva  )
[878]22
[972]23      USE dimphy
[1738]24      USE ioipsl
[1026]25      USE comgeomphy , ONLY:rlond,rlatd
[1785]26      USE indice_sol_mod
[878]27      IMPLICIT NONE
28
29!=======================================================================
30!   Auteurs: Frederic Hourdin, Catherine Rio, Anne Mathieu
31!   Version du 09.02.07
32!   Calcul du transport vertical dans la couche limite en presence
33!   de "thermiques" explicitement representes avec processus nuageux
34!
[1403]35!   Reecriture a partir d'un listing papier a Habas, le 14/02/00
[878]36!
[1403]37!   le thermique est suppose homogene et dissipe par melange avec
38!   son environnement. la longueur l_mix controle l'efficacite du
39!   melange
[878]40!
[1403]41!   Le calcul du transport des differentes especes se fait en prenant
[878]42!   en compte:
43!     1. un flux de masse montant
44!     2. un flux de masse descendant
45!     3. un entrainement
46!     4. un detrainement
47!
[1738]48! Modif 2013/01/04 (FH hourdin@lmd.jussieu.fr)
49!    Introduction of an implicit computation of vertical advection in
50!    the environment of thermal plumes in thermcell_dq
51!    impl =     0 : explicit, 1 : implicit, -1 : old version
52!    controled by iflag_thermals =
53!       15, 16 run with impl=-1 : numerical convergence with NPv3
54!       17, 18 run with impl=1  : more stable
55!    15 and 17 correspond to the activation of the stratocumulus "bidouille"
56!
[878]57!=======================================================================
58
[1738]59
[878]60!-----------------------------------------------------------------------
61!   declarations:
62!   -------------
63
64#include "dimensions.h"
65#include "YOMCST.h"
66#include "YOETHF.h"
67#include "FCTTRE.h"
[938]68#include "iniprint.h"
[1496]69#include "thermcell.h"
[878]70
71!   arguments:
72!   ----------
73
[972]74!IM 140508
75      INTEGER itap
76
[1496]77      INTEGER ngrid,nlay
78      real ptimestep
[878]79      REAL pt(ngrid,nlay),pdtadj(ngrid,nlay)
80      REAL pu(ngrid,nlay),pduadj(ngrid,nlay)
81      REAL pv(ngrid,nlay),pdvadj(ngrid,nlay)
82      REAL po(ngrid,nlay),pdoadj(ngrid,nlay)
83      REAL pplay(ngrid,nlay),pplev(ngrid,nlay+1)
84      real pphi(ngrid,nlay)
[1943]85      LOGICAL debut
[878]86
87!   local:
88!   ------
89
[972]90      integer icount
[1738]91
92      integer, save :: dvdq=1,dqimpl=-1
93!$OMP THREADPRIVATE(dvdq,dqimpl)
[972]94      data icount/0/
95      save icount
[987]96!$OMP THREADPRIVATE(icount)
[972]97
[883]98      integer,save :: igout=1
[987]99!$OMP THREADPRIVATE(igout)
[938]100      integer,save :: lunout1=6
[987]101!$OMP THREADPRIVATE(lunout1)
[883]102      integer,save :: lev_out=10
[987]103!$OMP THREADPRIVATE(lev_out)
[878]104
[1638]105      REAL susqr2pi, Reuler
106
[1494]107      INTEGER ig,k,l,ll,ierr
[878]108      real zsortie1d(klon)
109      INTEGER lmax(klon),lmin(klon),lalim(klon)
110      INTEGER lmix(klon)
[1026]111      INTEGER lmix_bis(klon)
[878]112      real linter(klon)
113      real zmix(klon)
[1403]114      real zmax(klon),zw2(klon,klev+1),ztva(klon,klev),zw_est(klon,klev+1),ztva_est(klon,klev)
[1026]115!      real fraca(klon,klev)
116
[878]117      real zmax_sec(klon)
118!on garde le zmax du pas de temps precedent
119      real zmax0(klon)
[927]120!FH/IM     save zmax0
[878]121
[972]122      real lambda
123
[878]124      real zlev(klon,klev+1),zlay(klon,klev)
125      real deltaz(klon,klev)
[972]126      REAL zh(klon,klev)
[878]127      real zthl(klon,klev),zdthladj(klon,klev)
128      REAL ztv(klon,klev)
129      real zu(klon,klev),zv(klon,klev),zo(klon,klev)
130      real zl(klon,klev)
131      real zsortie(klon,klev)
132      real zva(klon,klev)
133      real zua(klon,klev)
134      real zoa(klon,klev)
135
136      real zta(klon,klev)
137      real zha(klon,klev)
138      real fraca(klon,klev+1)
139      real zf,zf2
140      real thetath2(klon,klev),wth2(klon,klev),wth3(klon,klev)
141      real q2(klon,klev)
[972]142! FH probleme de dimensionnement avec l'allocation dynamique
143!     common/comtherm/thetath2,wth2
[1403]144      real wq(klon,klev)
145      real wthl(klon,klev)
146      real wthv(klon,klev)
[878]147   
148      real ratqscth(klon,klev)
149      real var
150      real vardiff
151      real ratqsdiff(klon,klev)
152
153      logical sorties
[972]154      real rho(klon,klev),rhobarz(klon,klev),masse(klon,klev)
[878]155      real zpspsk(klon,klev)
156
157      real wmax(klon)
[1403]158      real wmax_tmp(klon)
[878]159      real wmax_sec(klon)
[972]160      real fm0(klon,klev+1),entr0(klon,klev),detr0(klon,klev)
161      real fm(klon,klev+1),entr(klon,klev),detr(klon,klev)
[878]162
163      real ztla(klon,klev),zqla(klon,klev),zqta(klon,klev)
164!niveau de condensation
[879]165      integer nivcon(klon)
[878]166      real zcon(klon)
167      REAL CHI
168      real zcon2(klon)
169      real pcon(klon)
170      real zqsat(klon,klev)
171      real zqsatth(klon,klev)
172
173      real f_star(klon,klev+1),entr_star(klon,klev)
174      real detr_star(klon,klev)
[1403]175      real alim_star_tot(klon)
[878]176      real alim_star(klon,klev)
[1403]177      real alim_star_clos(klon,klev)
[878]178      real f(klon), f0(klon)
[927]179!FH/IM     save f0
[878]180      real zlevinter(klon)
181       real seuil
[1403]182      real csc(klon,klev)
[878]183
[1638]184!!! nrlmd le 10/04/2012
185
186!------Entrées
187      real pbl_tke(klon,klev+1,nbsrf)
188      real pctsrf(klon,nbsrf)
189      real omega(klon,klev)
190      real airephy(klon)
191!------Sorties
192      real zlcl(klon),fraca0(klon),w0(klon),w_conv(klon)
193      real therm_tke_max0(klon),env_tke_max0(klon)
194      real n2(klon),s2(klon)
195      real ale_bl_stat(klon)
196      real therm_tke_max(klon,klev),env_tke_max(klon,klev)
197      real alp_bl_det(klon),alp_bl_fluct_m(klon),alp_bl_fluct_tke(klon),alp_bl_conv(klon),alp_bl_stat(klon)
198!------Local
199      integer nsrf
200      real rhobarz0(klon)                    ! Densité au LCL
201      logical ok_lcl(klon)                   ! Existence du LCL des thermiques
202      integer klcl(klon)                     ! Niveau du LCL
203      real interp(klon)                      ! Coef d'interpolation pour le LCL
204!--Triggering
205      real Su                                ! Surface unité: celle d'un updraft élémentaire
206      parameter(Su=4e4)
207      real hcoef                             ! Coefficient directeur pour le calcul de s2
208      parameter(hcoef=1)
209      real hmincoef                          ! Coefficient directeur pour l'ordonnée à l'origine pour le calcul de s2
210      parameter(hmincoef=0.3)
211      real eps1                              ! Fraction de surface occupée par la population 1 : eps1=n1*s1/(fraca0*Sd)
212      parameter(eps1=0.3)
213      real hmin(ngrid)                       ! Ordonnée à l'origine pour le calcul de s2
214      real zmax_moy(ngrid)                   ! Hauteur moyenne des thermiques : zmax_moy = zlcl + 0.33 (zmax-zlcl)
215      real zmax_moy_coef
216      parameter(zmax_moy_coef=0.33)
217      real depth(klon)                       ! Epaisseur moyenne du cumulus
218      real w_max(klon)                       ! Vitesse max statistique
219      real s_max(klon)
220!--Closure
221      real pbl_tke_max(klon,klev)            ! Profil de TKE moyenne
222      real pbl_tke_max0(klon)                ! TKE moyenne au LCL
223      real w_ls(klon,klev)                   ! Vitesse verticale grande échelle (m/s)
224      real coef_m                            ! On considère un rendement pour alp_bl_fluct_m
225      parameter(coef_m=1.)
226      real coef_tke                          ! On considère un rendement pour alp_bl_fluct_tke
227      parameter(coef_tke=1.)
228
229!!! fin nrlmd le 10/04/2012
230
[878]231!
[879]232      !nouvelles variables pour la convection
233      real Ale_bl(klon)
234      real Alp_bl(klon)
[1496]235      real alp_int(klon),dp_int(klon),zdp
[879]236      real ale_int(klon)
237      integer n_int(klon)
238      real fm_tot(klon)
239      real wght_th(klon,klev)
240      integer lalim_conv(klon)
[926]241!v1d     logical therm
242!v1d     save therm
[878]243
244      character*2 str2
245      character*10 str10
246
[1403]247      character (len=20) :: modname='thermcell_main'
248      character (len=80) :: abort_message
249
[878]250      EXTERNAL SCOPY
251!
252
253!-----------------------------------------------------------------------
254!   initialisation:
255!   ---------------
256!
257
[1943]258   seuil=0.25
[878]259
[1943]260   if (debut) then
261      if (iflag_thermals==15.or.iflag_thermals==16) then
262         dvdq=0
263         dqimpl=-1
264      else
265         dvdq=1
266         dqimpl=1
[972]267      endif
268
[1943]269      fm0=0.
270      entr0=0.
271      detr0=0.
272   endif
273   fm=0. ; entr=0. ; detr=0.
274   icount=icount+1
[972]275
276!IM 090508 beg
277!print*,'====================================================================='
278!print*,'====================================================================='
279!print*,' PAS ',icount,' PAS ',icount,' PAS ',icount,' PAS ',icount
280!print*,'====================================================================='
281!print*,'====================================================================='
282!IM 090508 end
283
[938]284      if (prt_level.ge.1) print*,'thermcell_main V4'
[878]285
286       sorties=.true.
287      IF(ngrid.NE.klon) THEN
288         PRINT*
289         PRINT*,'STOP dans convadj'
290         PRINT*,'ngrid    =',ngrid
291         PRINT*,'klon  =',klon
292      ENDIF
293!
[1403]294!     write(lunout,*)'WARNING thermcell_main f0=max(f0,1.e-2)'
[972]295     do ig=1,klon
296         f0(ig)=max(f0(ig),1.e-2)
[1403]297         zmax0(ig)=max(zmax0(ig),40.)
[972]298!IMmarche pas ?!       if (f0(ig)<1.e-2) f0(ig)=1.e-2
299     enddo
[878]300
[1494]301      if (prt_level.ge.20) then
302       do ig=1,ngrid
303          print*,'th_main ig f0',ig,f0(ig)
304       enddo
305      endif
[878]306!-----------------------------------------------------------------------
307! Calcul de T,q,ql a partir de Tl et qT dans l environnement
308!   --------------------------------------------------------------------
309!
310      CALL thermcell_env(ngrid,nlay,po,pt,pu,pv,pplay,  &
311     &           pplev,zo,zh,zl,ztv,zthl,zu,zv,zpspsk,zqsat,lev_out)
312       
[938]313      if (prt_level.ge.1) print*,'thermcell_main apres thermcell_env'
[878]314
315!------------------------------------------------------------------------
316!                       --------------------
317!
318!
319!                       + + + + + + + + + + +
320!
321!
322!  wa, fraca, wd, fracd --------------------   zlev(2), rhobarz
323!  wh,wt,wo ...
324!
325!                       + + + + + + + + + + +  zh,zu,zv,zo,rho
326!
327!
328!                       --------------------   zlev(1)
329!                       \\\\\\\\\\\\\\\\\\\\
330!
331!
332
333!-----------------------------------------------------------------------
334!   Calcul des altitudes des couches
335!-----------------------------------------------------------------------
336
337      do l=2,nlay
338         zlev(:,l)=0.5*(pphi(:,l)+pphi(:,l-1))/RG
339      enddo
340         zlev(:,1)=0.
341         zlev(:,nlay+1)=(2.*pphi(:,klev)-pphi(:,klev-1))/RG
342      do l=1,nlay
343         zlay(:,l)=pphi(:,l)/RG
344      enddo
345!calcul de l epaisseur des couches
346      do l=1,nlay
347         deltaz(:,l)=zlev(:,l+1)-zlev(:,l)
348      enddo
349
350!     print*,'2 OK convect8'
351!-----------------------------------------------------------------------
352!   Calcul des densites
353!-----------------------------------------------------------------------
354
[1494]355     rho(:,:)=pplay(:,:)/(zpspsk(:,:)*RD*ztv(:,:))
[878]356
[1146]357     if (prt_level.ge.10)write(lunout,*)                                &
358    &    'WARNING thermcell_main rhobarz(:,1)=rho(:,1)'
[972]359      rhobarz(:,1)=rho(:,1)
360
[878]361      do l=2,nlay
362         rhobarz(:,l)=0.5*(rho(:,l)+rho(:,l-1))
363      enddo
364
365!calcul de la masse
366      do l=1,nlay
367         masse(:,l)=(pplev(:,l)-pplev(:,l+1))/RG
368      enddo
369
[938]370      if (prt_level.ge.1) print*,'thermcell_main apres initialisation'
[878]371
372!------------------------------------------------------------------
373!
374!             /|\
375!    --------  |  F_k+1 -------   
376!                              ----> D_k
377!             /|\              <---- E_k , A_k
378!    --------  |  F_k ---------
379!                              ----> D_k-1
380!                              <---- E_k-1 , A_k-1
381!
382!
383!
384!
385!
386!    ---------------------------
387!
388!    ----- F_lmax+1=0 ----------         \
389!            lmax     (zmax)              |
390!    ---------------------------          |
391!                                         |
392!    ---------------------------          |
393!                                         |
394!    ---------------------------          |
395!                                         |
396!    ---------------------------          |
397!                                         |
398!    ---------------------------          |
399!                                         |  E
400!    ---------------------------          |  D
401!                                         |
402!    ---------------------------          |
403!                                         |
404!    ---------------------------  \       |
405!            lalim                 |      |
406!    ---------------------------   |      |
407!                                  |      |
408!    ---------------------------   |      |
409!                                  | A    |
410!    ---------------------------   |      |
411!                                  |      |
412!    ---------------------------   |      |
413!    lmin  (=1 pour le moment)     |      |
414!    ----- F_lmin=0 ------------  /      /
415!
416!    ---------------------------
417!    //////////////////////////
418!
419!
420!=============================================================================
421!  Calculs initiaux ne faisant pas intervenir les changements de phase
422!=============================================================================
423
424!------------------------------------------------------------------
[1403]425!  1. alim_star est le profil vertical de l'alimentation a la base du
426!     panache thermique, calcule a partir de la flotabilite de l'air sec
[878]427!  2. lmin et lalim sont les indices inferieurs et superieurs de alim_star
428!------------------------------------------------------------------
429!
430      entr_star=0. ; detr_star=0. ; alim_star=0. ; alim_star_tot=0.
[1403]431      lmin=1
[878]432
433!-----------------------------------------------------------------------------
434!  3. wmax_sec et zmax_sec sont les vitesses et altitudes maximum d'un
435!     panache sec conservatif (e=d=0) alimente selon alim_star
436!     Il s'agit d'un calcul de type CAPE
[1403]437!     zmax_sec est utilise pour determiner la geometrie du thermique.
[878]438!------------------------------------------------------------------------------
[1403]439!---------------------------------------------------------------------------------
440!calcul du melange et des variables dans le thermique
441!--------------------------------------------------------------------------------
[878]442!
[1403]443      if (prt_level.ge.1) print*,'avant thermcell_plume ',lev_out
444!IM 140508   CALL thermcell_plume(ngrid,nlay,ptimestep,ztv,zthl,po,zl,rhobarz,  &
[878]445
[1403]446! Gestion temporaire de plusieurs appels à thermcell_plume au travers
447! de la variable iflag_thermals
[878]448
[1403]449!      print*,'THERM thermcell_main iflag_thermals_ed=',iflag_thermals_ed
450      if (iflag_thermals_ed<=9) then
451!         print*,'THERM NOUVELLE/NOUVELLE Arnaud'
452         CALL thermcell_plume(itap,ngrid,nlay,ptimestep,ztv,zthl,po,zl,rhobarz,&
453     &    zlev,pplev,pphi,zpspsk,alim_star,alim_star_tot,  &
454     &    lalim,f0,detr_star,entr_star,f_star,csc,ztva,  &
455     &    ztla,zqla,zqta,zha,zw2,zw_est,ztva_est,zqsatth,lmix,lmix_bis,linter &
456     &    ,lev_out,lunout1,igout)
[878]457
[1403]458      elseif (iflag_thermals_ed>9) then
459!        print*,'THERM RIO et al 2010, version d Arnaud'
460         CALL thermcellV1_plume(itap,ngrid,nlay,ptimestep,ztv,zthl,po,zl,rhobarz,&
461     &    zlev,pplev,pphi,zpspsk,alim_star,alim_star_tot,  &
462     &    lalim,f0,detr_star,entr_star,f_star,csc,ztva,  &
463     &    ztla,zqla,zqta,zha,zw2,zw_est,ztva_est,zqsatth,lmix,lmix_bis,linter &
464     &    ,lev_out,lunout1,igout)
[878]465
[1403]466      endif
[878]467
[972]468      if (prt_level.ge.1) print*,'apres thermcell_plume ',lev_out
469
[878]470      call test_ltherm(ngrid,nlay,pplev,pplay,lalim,seuil,ztv,po,ztva,zqla,f_star,zw2,'thermcell_plum lalim ')
471      call test_ltherm(ngrid,nlay,pplev,pplay,lmix ,seuil,ztv,po,ztva,zqla,f_star,zw2,'thermcell_plum lmix  ')
472
[938]473      if (prt_level.ge.1) print*,'thermcell_main apres thermcell_plume'
474      if (prt_level.ge.10) then
[972]475         write(lunout1,*) 'Dans thermcell_main 2'
476         write(lunout1,*) 'lmin ',lmin(igout)
477         write(lunout1,*) 'lalim ',lalim(igout)
478         write(lunout1,*) ' ig l alim_star entr_star detr_star f_star '
479         write(lunout1,'(i6,i4,4e15.5)') (igout,l,alim_star(igout,l),entr_star(igout,l),detr_star(igout,l) &
[878]480     &    ,f_star(igout,l+1),l=1,nint(linter(igout))+5)
481      endif
482
483!-------------------------------------------------------------------------------
484! Calcul des caracteristiques du thermique:zmax,zmix,wmax
485!-------------------------------------------------------------------------------
486!
487      CALL thermcell_height(ngrid,nlay,lalim,lmin,linter,lmix,zw2,  &
488     &           zlev,lmax,zmax,zmax0,zmix,wmax,lev_out)
[1403]489! Attention, w2 est transforme en sa racine carree dans cette routine
490! Le probleme vient du fait que linter et lmix sont souvent égaux à 1.
491      wmax_tmp=0.
492      do  l=1,nlay
493         wmax_tmp(:)=max(wmax_tmp(:),zw2(:,l))
494      enddo
495!     print*,"ZMAX ",lalim,lmin,linter,lmix,lmax,zmax,zmax0,zmix,wmax
[878]496
497
[1403]498
[878]499      call test_ltherm(ngrid,nlay,pplev,pplay,lalim,seuil,ztv,po,ztva,zqla,f_star,zw2,'thermcell_heig lalim ')
500      call test_ltherm(ngrid,nlay,pplev,pplay,lmin ,seuil,ztv,po,ztva,zqla,f_star,zw2,'thermcell_heig lmin  ')
501      call test_ltherm(ngrid,nlay,pplev,pplay,lmix ,seuil,ztv,po,ztva,zqla,f_star,zw2,'thermcell_heig lmix  ')
502      call test_ltherm(ngrid,nlay,pplev,pplay,lmax ,seuil,ztv,po,ztva,zqla,f_star,zw2,'thermcell_heig lmax  ')
503
[938]504      if (prt_level.ge.1) print*,'thermcell_main apres thermcell_height'
[878]505
506!-------------------------------------------------------------------------------
507! Fermeture,determination de f
508!-------------------------------------------------------------------------------
[1026]509!
[1403]510!
511!!      write(lunout,*)'THERM NOUVEAU XXXXX'
512      CALL thermcell_dry(ngrid,nlay,zlev,pphi,ztv,alim_star,  &
513    &                      lalim,lmin,zmax_sec,wmax_sec,lev_out)
[878]514
[1403]515call test_ltherm(ngrid,nlay,pplev,pplay,lmin,seuil,ztv,po,ztva,zqla,f_star,zw2,'thermcell_dry  lmin  ')
516call test_ltherm(ngrid,nlay,pplev,pplay,lalim,seuil,ztv,po,ztva,zqla,f_star,zw2,'thermcell_dry  lalim ')
517
518      if (prt_level.ge.1) print*,'thermcell_main apres thermcell_dry'
519      if (prt_level.ge.10) then
520         write(lunout1,*) 'Dans thermcell_main 1b'
521         write(lunout1,*) 'lmin ',lmin(igout)
522         write(lunout1,*) 'lalim ',lalim(igout)
523         write(lunout1,*) ' ig l alim_star entr_star detr_star f_star '
524         write(lunout1,'(i6,i4,e15.5)') (igout,l,alim_star(igout,l) &
525     &    ,l=1,lalim(igout)+4)
526      endif
527
528
529
530
531! Choix de la fonction d'alimentation utilisee pour la fermeture.
532! Apparemment sans importance
533      alim_star_clos(:,:)=alim_star(:,:)
534      alim_star_clos(:,:)=entr_star(:,:)+alim_star(:,:)
535
536! Appel avec la version seche
[1496]537      CALL thermcell_closure(ngrid,nlay,r_aspect_thermals,ptimestep,rho,  &
[1403]538     &   zlev,lalim,alim_star_clos,f_star,zmax_sec,wmax_sec,f,lev_out)
[878]539
[1403]540!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
541! Appel avec les zmax et wmax tenant compte de la condensation
542! Semble moins bien marcher
[1496]543!     CALL thermcell_closure(ngrid,nlay,r_aspect_thermals,ptimestep,rho,  &
[1403]544!    &   zlev,lalim,alim_star,f_star,zmax,wmax,f,lev_out)
545!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
546
[938]547      if(prt_level.ge.1)print*,'thermcell_closure apres thermcell_closure'
[878]548
[972]549      if (tau_thermals>1.) then
550         lambda=exp(-ptimestep/tau_thermals)
551         f0=(1.-lambda)*f+lambda*f0
552      else
553         f0=f
554      endif
555
556! Test valable seulement en 1D mais pas genant
557      if (.not. (f0(1).ge.0.) ) then
[1403]558              abort_message = '.not. (f0(1).ge.0.)'
559              CALL abort_gcm (modname,abort_message,1)
[972]560      endif
561
[878]562!-------------------------------------------------------------------------------
563!deduction des flux
564!-------------------------------------------------------------------------------
565
[972]566      CALL thermcell_flux2(ngrid,nlay,ptimestep,masse, &
[878]567     &       lalim,lmax,alim_star,  &
568     &       entr_star,detr_star,f,rhobarz,zlev,zw2,fm,entr,  &
[972]569     &       detr,zqla,lev_out,lunout1,igout)
570!IM 060508    &       detr,zqla,zmax,lev_out,lunout,igout)
[878]571
[938]572      if (prt_level.ge.1) print*,'thermcell_main apres thermcell_flux'
[878]573      call test_ltherm(ngrid,nlay,pplev,pplay,lalim,seuil,ztv,po,ztva,zqla,f_star,zw2,'thermcell_flux lalim ')
574      call test_ltherm(ngrid,nlay,pplev,pplay,lmax ,seuil,ztv,po,ztva,zqla,f_star,zw2,'thermcell_flux lmax  ')
575
576!------------------------------------------------------------------
[972]577!   On ne prend pas directement les profils issus des calculs precedents
578!   mais on s'autorise genereusement une relaxation vers ceci avec
579!   une constante de temps tau_thermals (typiquement 1800s).
580!------------------------------------------------------------------
[878]581
[972]582      if (tau_thermals>1.) then
583         lambda=exp(-ptimestep/tau_thermals)
584         fm0=(1.-lambda)*fm+lambda*fm0
585         entr0=(1.-lambda)*entr+lambda*entr0
[1403]586         detr0=(1.-lambda)*detr+lambda*detr0
[878]587      else
588         fm0=fm
589         entr0=entr
590         detr0=detr
591      endif
592
[972]593!c------------------------------------------------------------------
594!   calcul du transport vertical
595!------------------------------------------------------------------
596
[1738]597      call thermcell_dq(ngrid,nlay,dqimpl,ptimestep,fm0,entr0,masse,  &
[878]598     &                    zthl,zdthladj,zta,lev_out)
[1738]599      call thermcell_dq(ngrid,nlay,dqimpl,ptimestep,fm0,entr0,masse,  &
[878]600     &                   po,pdoadj,zoa,lev_out)
601
[883]602!------------------------------------------------------------------
603! Calcul de la fraction de l'ascendance
604!------------------------------------------------------------------
605      do ig=1,klon
606         fraca(ig,1)=0.
607         fraca(ig,nlay+1)=0.
608      enddo
609      do l=2,nlay
610         do ig=1,klon
611            if (zw2(ig,l).gt.1.e-10) then
612            fraca(ig,l)=fm(ig,l)/(rhobarz(ig,l)*zw2(ig,l))
613            else
614            fraca(ig,l)=0.
615            endif
616         enddo
617      enddo
618     
619!------------------------------------------------------------------
620!  calcul du transport vertical du moment horizontal
621!------------------------------------------------------------------
[878]622
[972]623!IM 090508 
[1738]624      if (dvdq == 0 ) then
[883]625
[878]626! Calcul du transport de V tenant compte d'echange par gradient
627! de pression horizontal avec l'environnement
628
629         call thermcell_dv2(ngrid,nlay,ptimestep,fm0,entr0,masse  &
[1738]630!    &    ,fraca*dvdq,zmax &
631     &    ,fraca,zmax &
[972]632     &    ,zu,zv,pduadj,pdvadj,zua,zva,lev_out)
[1403]633
[878]634      else
635
636! calcul purement conservatif pour le transport de V
[1738]637         call thermcell_dq(ngrid,nlay,dqimpl,ptimestep,fm0,entr0,masse  &
[878]638     &    ,zu,pduadj,zua,lev_out)
[1738]639         call thermcell_dq(ngrid,nlay,dqimpl,ptimestep,fm0,entr0,masse  &
[878]640     &    ,zv,pdvadj,zva,lev_out)
[1738]641
[878]642      endif
643
644!     print*,'13 OK convect8'
645      do l=1,nlay
646         do ig=1,ngrid
647           pdtadj(ig,l)=zdthladj(ig,l)*zpspsk(ig,l) 
648         enddo
649      enddo
650
[972]651      if (prt_level.ge.1) print*,'14 OK convect8'
[878]652!------------------------------------------------------------------
653!   Calculs de diagnostiques pour les sorties
654!------------------------------------------------------------------
655!calcul de fraca pour les sorties
656     
657      if (sorties) then
[972]658      if (prt_level.ge.1) print*,'14a OK convect8'
[878]659! calcul du niveau de condensation
660! initialisation
661      do ig=1,ngrid
[879]662         nivcon(ig)=0
[878]663         zcon(ig)=0.
664      enddo
665!nouveau calcul
666      do ig=1,ngrid
667      CHI=zh(ig,1)/(1669.0-122.0*zo(ig,1)/zqsat(ig,1)-zh(ig,1))
668      pcon(ig)=pplay(ig,1)*(zo(ig,1)/zqsat(ig,1))**CHI
669      enddo
[1403]670!IM   do k=1,nlay
671      do k=1,nlay-1
[878]672         do ig=1,ngrid
673         if ((pcon(ig).le.pplay(ig,k))  &
674     &      .and.(pcon(ig).gt.pplay(ig,k+1))) then
675            zcon2(ig)=zlay(ig,k)-(pcon(ig)-pplay(ig,k))/(RG*rho(ig,k))/100.
676         endif
677         enddo
678      enddo
[1403]679!IM
[1494]680      ierr=0
[1403]681      do ig=1,ngrid
682        if (pcon(ig).le.pplay(ig,nlay)) then
683           zcon2(ig)=zlay(ig,nlay)-(pcon(ig)-pplay(ig,nlay))/(RG*rho(ig,nlay))/100.
[1494]684           ierr=1
685        endif
686      enddo
687      if (ierr==1) then
[1403]688           abort_message = 'thermcellV0_main: les thermiques vont trop haut '
689           CALL abort_gcm (modname,abort_message,1)
[1494]690      endif
691
[972]692      if (prt_level.ge.1) print*,'14b OK convect8'
[878]693      do k=nlay,1,-1
694         do ig=1,ngrid
695            if (zqla(ig,k).gt.1e-10) then
696               nivcon(ig)=k
697               zcon(ig)=zlev(ig,k)
698            endif
699         enddo
700      enddo
[972]701      if (prt_level.ge.1) print*,'14c OK convect8'
[878]702!calcul des moments
703!initialisation
704      do l=1,nlay
705         do ig=1,ngrid
706            q2(ig,l)=0.
707            wth2(ig,l)=0.
708            wth3(ig,l)=0.
709            ratqscth(ig,l)=0.
710            ratqsdiff(ig,l)=0.
711         enddo
712      enddo     
[972]713      if (prt_level.ge.1) print*,'14d OK convect8'
[1146]714      if (prt_level.ge.10)write(lunout,*)                                &
715    &     'WARNING thermcell_main wth2=0. si zw2 > 1.e-10'
[878]716      do l=1,nlay
717         do ig=1,ngrid
718            zf=fraca(ig,l)
719            zf2=zf/(1.-zf)
[972]720!
[1403]721            thetath2(ig,l)=zf2*(ztla(ig,l)-zthl(ig,l))**2
[972]722            if(zw2(ig,l).gt.1.e-10) then
723             wth2(ig,l)=zf2*(zw2(ig,l))**2
724            else
725             wth2(ig,l)=0.
726            endif
[878]727            wth3(ig,l)=zf2*(1-2.*fraca(ig,l))/(1-fraca(ig,l))  &
728     &                *zw2(ig,l)*zw2(ig,l)*zw2(ig,l)
729            q2(ig,l)=zf2*(zqta(ig,l)*1000.-po(ig,l)*1000.)**2
730!test: on calcul q2/po=ratqsc
731            ratqscth(ig,l)=sqrt(max(q2(ig,l),1.e-6)/(po(ig,l)*1000.))
732         enddo
733      enddo
[1403]734!calcul des flux: q, thetal et thetav
735      do l=1,nlay
736         do ig=1,ngrid
737      wq(ig,l)=fraca(ig,l)*zw2(ig,l)*(zqta(ig,l)*1000.-po(ig,l)*1000.)
738      wthl(ig,l)=fraca(ig,l)*zw2(ig,l)*(ztla(ig,l)-zthl(ig,l))
739      wthv(ig,l)=fraca(ig,l)*zw2(ig,l)*(ztva(ig,l)-ztv(ig,l))
740         enddo
[879]741      enddo
[972]742!
[1638]743
744!!! nrlmd le 10/04/2012
745
746!------------Test sur le LCL des thermiques
747    do ig=1,ngrid
748      ok_lcl(ig)=.false.
749      if ( (pcon(ig) .gt. pplay(ig,klev-1)) .and. (pcon(ig) .lt. pplay(ig,1)) ) ok_lcl(ig)=.true.
750    enddo
751
752!------------Localisation des niveaux entourant le LCL et du coef d'interpolation
753    do l=1,nlay-1
754      do ig=1,ngrid
755        if (ok_lcl(ig)) then
756          if ((pplay(ig,l) .ge. pcon(ig)) .and. (pplay(ig,l+1) .le. pcon(ig))) then
757          klcl(ig)=l
758          interp(ig)=(pcon(ig)-pplay(ig,klcl(ig)))/(pplay(ig,klcl(ig)+1)-pplay(ig,klcl(ig)))
759          endif
760        endif
761      enddo
762    enddo
763
764!------------Hauteur des thermiques
765!!jyg le 27/04/2012
766!!    do ig =1,ngrid
767!!    rhobarz0(ig)=rhobarz(ig,klcl(ig))+(rhobarz(ig,klcl(ig)+1) &
768!! &               -rhobarz(ig,klcl(ig)))*interp(ig)
769!!    zlcl(ig)=(pplev(ig,1)-pcon(ig))/(rhobarz0(ig)*RG)
770!!    zmax(ig)=pphi(ig,lmax(ig))/rg
771!!      if ( (.not.ok_lcl(ig)) .or. (zlcl(ig).gt.zmax(ig)) ) zlcl(ig)=zmax(ig) ! Si zclc > zmax alors on pose zlcl = zmax
772!!    enddo
773    do ig =1,ngrid
774     zmax(ig)=pphi(ig,lmax(ig))/rg
775     if (ok_lcl(ig)) then
776      rhobarz0(ig)=rhobarz(ig,klcl(ig))+(rhobarz(ig,klcl(ig)+1) &
777 &               -rhobarz(ig,klcl(ig)))*interp(ig)
778      zlcl(ig)=(pplev(ig,1)-pcon(ig))/(rhobarz0(ig)*RG)
779      zlcl(ig)=min(zlcl(ig),zmax(ig))   ! Si zlcl > zmax alors on pose zlcl = zmax
780     else
781      rhobarz0(ig)=0.
782      zlcl(ig)=zmax(ig)
783     endif
784    enddo
785!!jyg fin
786
787!------------Calcul des propriétés du thermique au LCL
788  IF ( (iflag_trig_bl.ge.1) .or. (iflag_clos_bl.ge.1) ) THEN
789
790  !-----Initialisation de la TKE moyenne
791   do l=1,nlay
792    do ig=1,ngrid
793     pbl_tke_max(ig,l)=0.
794    enddo
795   enddo
796
797!-----Calcul de la TKE moyenne
798   do nsrf=1,nbsrf
799    do l=1,nlay
800     do ig=1,ngrid
801     pbl_tke_max(ig,l)=pctsrf(ig,nsrf)*pbl_tke(ig,l,nsrf)+pbl_tke_max(ig,l)
802     enddo
803    enddo
804   enddo
805
806!-----Initialisations des TKE dans et hors des thermiques
807   do l=1,nlay
808    do ig=1,ngrid
809    therm_tke_max(ig,l)=pbl_tke_max(ig,l)
810    env_tke_max(ig,l)=pbl_tke_max(ig,l)
811    enddo
812   enddo
813
814!-----Calcul de la TKE transportée par les thermiques : therm_tke_max
815   call thermcell_tke_transport(ngrid,nlay,ptimestep,fm0,entr0,  &
816  &           rg,pplev,therm_tke_max)
817!   print *,' thermcell_tke_transport -> '   !!jyg
818
819!-----Calcul des profils verticaux de TKE hors thermiques : env_tke_max, et de la vitesse verticale grande échelle : W_ls
820   do l=1,nlay
821    do ig=1,ngrid
822     pbl_tke_max(ig,l)=fraca(ig,l)*therm_tke_max(ig,l)+(1.-fraca(ig,l))*env_tke_max(ig,l)         !  Recalcul de TKE moyenne aprés transport de TKE_TH
823     env_tke_max(ig,l)=(pbl_tke_max(ig,l)-fraca(ig,l)*therm_tke_max(ig,l))/(1.-fraca(ig,l))       !  Recalcul de TKE dans  l'environnement aprés transport de TKE_TH
824     w_ls(ig,l)=-1.*omega(ig,l)/(RG*rhobarz(ig,l))                                                !  Vitesse verticale de grande échelle
825    enddo
826   enddo
827!    print *,' apres w_ls = '   !!jyg
828
829  do ig=1,ngrid
830   if (ok_lcl(ig)) then
831     fraca0(ig)=fraca(ig,klcl(ig))+(fraca(ig,klcl(ig)+1) &
832 &             -fraca(ig,klcl(ig)))*interp(ig)
833     w0(ig)=zw2(ig,klcl(ig))+(zw2(ig,klcl(ig)+1) &
834 &         -zw2(ig,klcl(ig)))*interp(ig)
835     w_conv(ig)=w_ls(ig,klcl(ig))+(w_ls(ig,klcl(ig)+1) &
836 &             -w_ls(ig,klcl(ig)))*interp(ig)
837     therm_tke_max0(ig)=therm_tke_max(ig,klcl(ig)) &
838 &                     +(therm_tke_max(ig,klcl(ig)+1)-therm_tke_max(ig,klcl(ig)))*interp(ig)
839     env_tke_max0(ig)=env_tke_max(ig,klcl(ig))+(env_tke_max(ig,klcl(ig)+1) &
840 &                   -env_tke_max(ig,klcl(ig)))*interp(ig)
841     pbl_tke_max0(ig)=pbl_tke_max(ig,klcl(ig))+(pbl_tke_max(ig,klcl(ig)+1) &
842 &                   -pbl_tke_max(ig,klcl(ig)))*interp(ig)
843     if (therm_tke_max0(ig).ge.20.) therm_tke_max0(ig)=20.
844     if (env_tke_max0(ig).ge.20.) env_tke_max0(ig)=20.
845     if (pbl_tke_max0(ig).ge.20.) pbl_tke_max0(ig)=20.
846   else
847     fraca0(ig)=0.
848     w0(ig)=0.
849!!jyg le 27/04/2012
850!!     zlcl(ig)=0.
851!!
852   endif
853  enddo
854
855  ENDIF ! IF ( (iflag_trig_bl.ge.1) .or. (iflag_clos_bl.ge.1) )
856!  print *,'ENDIF  ( (iflag_trig_bl.ge.1) .or. (iflag_clos_bl.ge.1) ) '    !!jyg
857
858!------------Triggering------------------
859  IF (iflag_trig_bl.ge.1) THEN
860
861!-----Initialisations
862   depth(:)=0.
863   n2(:)=0.
864   s2(:)=0.
865   s_max(:)=0.
866
867!-----Epaisseur du nuage (depth) et détermination de la queue du spectre de panaches (n2,s2) et du panache le plus gros (s_max)
868   do ig=1,ngrid
869     zmax_moy(ig)=zlcl(ig)+zmax_moy_coef*(zmax(ig)-zlcl(ig))
870     depth(ig)=zmax_moy(ig)-zlcl(ig)
871     hmin(ig)=hmincoef*zlcl(ig)
872     if (depth(ig).ge.10.) then
873       s2(ig)=(hcoef*depth(ig)+hmin(ig))**2
874       n2(ig)=(1.-eps1)*fraca0(ig)*airephy(ig)/s2(ig)
875!!
876!!jyg le 27/04/2012
877!!       s_max(ig)=s2(ig)*log(n2(ig))
878!!       if (n2(ig) .lt. 1) s_max(ig)=0.
879       s_max(ig)=s2(ig)*log(max(n2(ig),1.))
880!!fin jyg
881     else
882       s2(ig)=0.
883       n2(ig)=0.
884       s_max(ig)=0.
885     endif
886   enddo
887!   print *,'avant Calcul de Wmax '    !!jyg
888
889!-----Calcul de Wmax et ALE_BL_STAT associée
890!!jyg le 30/04/2012
891!!   do ig=1,ngrid
892!!     if ( (depth(ig).ge.10.) .and. (s_max(ig).gt.1.) ) then
893!!     w_max(ig)=w0(ig)*(1.+sqrt(2.*log(s_max(ig)/su)-log(2.*3.14)-log(2.*log(s_max(ig)/su)-log(2.*3.14))))
894!!     ale_bl_stat(ig)=0.5*w_max(ig)**2
895!!     else
896!!     w_max(ig)=0.
897!!     ale_bl_stat(ig)=0.
898!!     endif
899!!   enddo
900   susqr2pi=su*sqrt(2.*Rpi)
901   Reuler=exp(1.)
902   do ig=1,ngrid
903     if ( (depth(ig).ge.10.) .and. (s_max(ig).gt.susqr2pi*Reuler) ) then
904      w_max(ig)=w0(ig)*(1.+sqrt(2.*log(s_max(ig)/susqr2pi)-log(2.*log(s_max(ig)/susqr2pi))))
905      ale_bl_stat(ig)=0.5*w_max(ig)**2
906     else
907      w_max(ig)=0.
908      ale_bl_stat(ig)=0.
909     endif
910   enddo
911
912  ENDIF ! iflag_trig_bl
913!  print *,'ENDIF  iflag_trig_bl'    !!jyg
914
915!------------Closure------------------
916
917  IF (iflag_clos_bl.ge.1) THEN
918
919!-----Calcul de ALP_BL_STAT
920  do ig=1,ngrid
921  alp_bl_det(ig)=0.5*coef_m*rhobarz0(ig)*(w0(ig)**3)*fraca0(ig)*(1.-2.*fraca0(ig))/((1.-fraca0(ig))**2)
922  alp_bl_fluct_m(ig)=1.5*rhobarz0(ig)*fraca0(ig)*(w_conv(ig)+coef_m*w0(ig))* &
923 &                   (w0(ig)**2)
924  alp_bl_fluct_tke(ig)=3.*coef_m*rhobarz0(ig)*w0(ig)*fraca0(ig)*(therm_tke_max0(ig)-env_tke_max0(ig)) &
925 &                    +3.*rhobarz0(ig)*w_conv(ig)*pbl_tke_max0(ig)
926    if (iflag_clos_bl.ge.2) then
927    alp_bl_conv(ig)=1.5*coef_m*rhobarz0(ig)*fraca0(ig)*(fraca0(ig)/(1.-fraca0(ig)))*w_conv(ig)* &
928 &                   (w0(ig)**2)
929    else
930    alp_bl_conv(ig)=0.
931    endif
932  alp_bl_stat(ig)=alp_bl_det(ig)+alp_bl_fluct_m(ig)+alp_bl_fluct_tke(ig)+alp_bl_conv(ig)
933  enddo
934
935!-----Sécurité ALP infinie
936  do ig=1,ngrid
937   if (fraca0(ig).gt.0.98) alp_bl_stat(ig)=2.
938  enddo
939
940  ENDIF ! (iflag_clos_bl.ge.1)
941
942!!! fin nrlmd le 10/04/2012
943
[1494]944      if (prt_level.ge.10) then
945         ig=igout
946         do l=1,nlay
947            print*,'14f OK convect8 ig,l,zha zh zpspsk ',ig,l,zha(ig,l),zh(ig,l),zpspsk(ig,l)
948            print*,'14g OK convect8 ig,l,po',ig,l,po(ig,l)
949         enddo
950      endif
951
[1403]952!      print*,'avant calcul ale et alp'
953!calcul de ALE et ALP pour la convection
954      Alp_bl(:)=0.
955      Ale_bl(:)=0.
956!          print*,'ALE,ALP ,l,zw2(ig,l),Ale_bl(ig),Alp_bl(ig)'
[972]957      do l=1,nlay
[879]958      do ig=1,ngrid
[1403]959           Alp_bl(ig)=max(Alp_bl(ig),0.5*rhobarz(ig,l)*wth3(ig,l) )
960           Ale_bl(ig)=max(Ale_bl(ig),0.5*zw2(ig,l)**2)
961!          print*,'ALE,ALP',l,zw2(ig,l),Ale_bl(ig),Alp_bl(ig)
[879]962      enddo
963      enddo
[1403]964
[879]965!test:calcul de la ponderation des couches pour KE
966!initialisations
[1494]967
968      fm_tot(:)=0.
969      wght_th(:,:)=1.
970      lalim_conv(:)=lalim(:)
971
972      do k=1,klev
973         do ig=1,ngrid
974            if (k<=lalim_conv(ig)) fm_tot(ig)=fm_tot(ig)+fm(ig,k)
975         enddo
[879]976      enddo
[1494]977
978! assez bizarre car, si on est dans la couche d'alim et que alim_star et
979! plus petit que 1.e-10, on prend wght_th=1.
980      do k=1,klev
981         do ig=1,ngrid
982            if (k<=lalim_conv(ig).and.alim_star(ig,k)>1.e-10) then
983               wght_th(ig,k)=alim_star(ig,k)
984            endif
985         enddo
[879]986      enddo
[1494]987
[879]988!      print*,'apres wght_th'
989!test pour prolonger la convection
990      do ig=1,ngrid
[926]991!v1d  if ((alim_star(ig,1).lt.1.e-10).and.(therm)) then
992      if ((alim_star(ig,1).lt.1.e-10)) then
[879]993      lalim_conv(ig)=1
994      wght_th(ig,1)=1.
995!      print*,'lalim_conv ok',lalim_conv(ig),wght_th(ig,1)
996      endif
997      enddo
998
[1496]999!------------------------------------------------------------------------
1000! Modif CR/FH 20110310 : Alp integree sur la verticale.
1001! Integrale verticale de ALP.
1002! wth3 etant aux niveaux inter-couches, on utilise d play comme masse des
1003! couches
1004!------------------------------------------------------------------------
[1494]1005
[1496]1006      alp_int(:)=0.
1007      dp_int(:)=0.
1008      do l=2,nlay
1009        do ig=1,ngrid
1010           if(l.LE.lmax(ig)) THEN
1011           zdp=pplay(ig,l-1)-pplay(ig,l)
1012           alp_int(ig)=alp_int(ig)+0.5*rhobarz(ig,l)*wth3(ig,l)*zdp
1013           dp_int(ig)=dp_int(ig)+zdp
1014           endif
1015        enddo
1016      enddo
1017
[1525]1018      if (iflag_coupl>=3 .and. iflag_coupl<=5) then
[1496]1019      do ig=1,ngrid
1020!valeur integree de alp_bl * 0.5:
1021        if (dp_int(ig)>0.) then
1022        Alp_bl(ig)=alp_int(ig)/dp_int(ig)
1023        endif
1024      enddo!
1025      endif
1026
1027
1028! Facteur multiplicatif sur Alp_bl
1029      Alp_bl(:)=alp_bl_k*Alp_bl(:)
1030
1031!------------------------------------------------------------------------
1032
1033
[878]1034!calcul du ratqscdiff
[972]1035      if (prt_level.ge.1) print*,'14e OK convect8'
[878]1036      var=0.
1037      vardiff=0.
1038      ratqsdiff(:,:)=0.
[1494]1039
1040      do l=1,klev
1041         do ig=1,ngrid
1042            if (l<=lalim(ig)) then
[878]1043            var=var+alim_star(ig,l)*zqta(ig,l)*1000.
[1494]1044            endif
[878]1045         enddo
1046      enddo
[1494]1047
[972]1048      if (prt_level.ge.1) print*,'14f OK convect8'
[1494]1049
1050      do l=1,klev
1051         do ig=1,ngrid
1052            if (l<=lalim(ig)) then
1053               zf=fraca(ig,l)
1054               zf2=zf/(1.-zf)
1055               vardiff=vardiff+alim_star(ig,l)*(zqta(ig,l)*1000.-var)**2
1056            endif
1057         enddo
[878]1058      enddo
[1494]1059
[972]1060      if (prt_level.ge.1) print*,'14g OK convect8'
[878]1061      do l=1,nlay
1062         do ig=1,ngrid
1063            ratqsdiff(ig,l)=sqrt(vardiff)/(po(ig,l)*1000.)   
1064!           write(11,*)'ratqsdiff=',ratqsdiff(ig,l)
1065         enddo
1066      enddo
1067!--------------------------------------------------------------------   
1068!
1069!ecriture des fichiers sortie
[1494]1070!     print*,'15 OK convect8 CCCCCCCCCCCCCCCCCCc'
[878]1071
[1403]1072#ifdef wrgrads_thermcell
[938]1073      if (prt_level.ge.1) print*,'thermcell_main sorties 3D'
[878]1074#include "thermcell_out3d.h"
1075#endif
1076
1077      endif
1078
[938]1079      if (prt_level.ge.1) print*,'thermcell_main FIN  OK'
[878]1080
1081      return
1082      end
1083
1084!-----------------------------------------------------------------------------
1085
1086      subroutine test_ltherm(klon,klev,pplev,pplay,long,seuil,ztv,po,ztva,zqla,f_star,zw2,comment)
[938]1087      IMPLICIT NONE
1088#include "iniprint.h"
[878]1089
[938]1090      integer i, k, klon,klev
[878]1091      real pplev(klon,klev+1),pplay(klon,klev)
1092      real ztv(klon,klev)
1093      real po(klon,klev)
1094      real ztva(klon,klev)
1095      real zqla(klon,klev)
1096      real f_star(klon,klev)
1097      real zw2(klon,klev)
1098      integer long(klon)
1099      real seuil
1100      character*21 comment
1101
[938]1102      if (prt_level.ge.1) THEN
1103       print*,'WARNING !!! TEST ',comment
1104      endif
[879]1105      return
1106
[878]1107!  test sur la hauteur des thermiques ...
1108         do i=1,klon
[972]1109!IMtemp           if (pplay(i,long(i)).lt.seuil*pplev(i,1)) then
1110           if (prt_level.ge.10) then
[878]1111               print*,'WARNING ',comment,' au point ',i,' K= ',long(i)
1112               print*,'  K  P(MB)  THV(K)     Qenv(g/kg)THVA        QLA(g/kg)   F*        W2'
1113               do k=1,klev
1114                  write(6,'(i3,7f10.3)') k,pplay(i,k),ztv(i,k),1000*po(i,k),ztva(i,k),1000*zqla(i,k),f_star(i,k),zw2(i,k)
1115               enddo
[972]1116           endif
[878]1117         enddo
1118
1119
1120      return
1121      end
1122
[1638]1123!!! nrlmd le 10/04/2012                          Transport de la TKE par le thermique moyen pour la fermeture en ALP
1124!                                                         On transporte pbl_tke pour donner therm_tke
1125!                                          Copie conforme de la subroutine DTKE dans physiq.F écrite par Frederic Hourdin
1126      subroutine thermcell_tke_transport(ngrid,nlay,ptimestep,fm0,entr0,  &
1127     &           rg,pplev,therm_tke_max)
1128      implicit none
1129
1130#include "iniprint.h"
1131!=======================================================================
1132!
1133!   Calcul du transport verticale dans la couche limite en presence
1134!   de "thermiques" explicitement representes
1135!   calcul du dq/dt une fois qu'on connait les ascendances
1136!
1137!=======================================================================
1138
1139      integer ngrid,nlay,nsrf
1140
1141      real ptimestep
1142      real masse0(ngrid,nlay),fm0(ngrid,nlay+1),pplev(ngrid,nlay+1)
1143      real entr0(ngrid,nlay),rg
1144      real therm_tke_max(ngrid,nlay)
1145      real detr0(ngrid,nlay)
1146
1147
1148      real masse(ngrid,nlay),fm(ngrid,nlay+1)
1149      real entr(ngrid,nlay)
1150      real q(ngrid,nlay)
1151      integer lev_out                           ! niveau pour les print
1152
1153      real qa(ngrid,nlay),detr(ngrid,nlay),wqd(ngrid,nlay+1)
1154
1155      real zzm
1156
1157      integer ig,k
1158      integer isrf
1159
1160
1161      lev_out=0
1162
1163
1164      if (prt_level.ge.1) print*,'Q2 THERMCEL_DQ 0'
1165
1166!   calcul du detrainement
1167      do k=1,nlay
1168         detr0(:,k)=fm0(:,k)-fm0(:,k+1)+entr0(:,k)
1169         masse0(:,k)=(pplev(:,k)-pplev(:,k+1))/RG
1170      enddo
1171
1172
1173! Decalage vertical des entrainements et detrainements.
1174      masse(:,1)=0.5*masse0(:,1)
1175      entr(:,1)=0.5*entr0(:,1)
1176      detr(:,1)=0.5*detr0(:,1)
1177      fm(:,1)=0.
1178      do k=1,nlay-1
1179         masse(:,k+1)=0.5*(masse0(:,k)+masse0(:,k+1))
1180         entr(:,k+1)=0.5*(entr0(:,k)+entr0(:,k+1))
1181         detr(:,k+1)=0.5*(detr0(:,k)+detr0(:,k+1))
1182         fm(:,k+1)=fm(:,k)+entr(:,k)-detr(:,k)
1183      enddo
1184      fm(:,nlay+1)=0.
1185
1186!!! nrlmd le 16/09/2010
1187!   calcul de la valeur dans les ascendances
1188!       do ig=1,ngrid
1189!          qa(ig,1)=q(ig,1)
1190!       enddo
1191!!!
1192
1193!do isrf=1,nsrf
1194
1195!   q(:,:)=therm_tke(:,:,isrf)
1196   q(:,:)=therm_tke_max(:,:)
1197!!! nrlmd le 16/09/2010
1198      do ig=1,ngrid
1199         qa(ig,1)=q(ig,1)
1200      enddo
1201!!!
1202
1203    if (1==1) then
1204      do k=2,nlay
1205         do ig=1,ngrid
1206            if ((fm(ig,k+1)+detr(ig,k))*ptimestep.gt.  &
1207     &         1.e-5*masse(ig,k)) then
1208         qa(ig,k)=(fm(ig,k)*qa(ig,k-1)+entr(ig,k)*q(ig,k))  &
1209     &         /(fm(ig,k+1)+detr(ig,k))
1210            else
1211               qa(ig,k)=q(ig,k)
1212            endif
1213            if (qa(ig,k).lt.0.) then
1214!               print*,'qa<0!!!'
1215            endif
1216            if (q(ig,k).lt.0.) then
1217!               print*,'q<0!!!'
1218            endif
1219         enddo
1220      enddo
1221
1222! Calcul du flux subsident
1223
1224      do k=2,nlay
1225         do ig=1,ngrid
1226            wqd(ig,k)=fm(ig,k)*q(ig,k)
1227            if (wqd(ig,k).lt.0.) then
1228!               print*,'wqd<0!!!'
1229            endif
1230         enddo
1231      enddo
1232      do ig=1,ngrid
1233         wqd(ig,1)=0.
1234         wqd(ig,nlay+1)=0.
1235      enddo
1236
1237! Calcul des tendances
1238      do k=1,nlay
1239         do ig=1,ngrid
1240            q(ig,k)=q(ig,k)+(detr(ig,k)*qa(ig,k)-entr(ig,k)*q(ig,k)  &
1241     &               -wqd(ig,k)+wqd(ig,k+1))  &
1242     &               *ptimestep/masse(ig,k)
1243         enddo
1244      enddo
1245
1246 endif
1247
1248   therm_tke_max(:,:)=q(:,:)
1249
1250      return
1251!!! fin nrlmd le 10/04/2012
1252     end
1253
Note: See TracBrowser for help on using the repository browser.