source: trunk/LMDZ.MARS/libf/phymars/vdifc_mod.F @ 2825

Last change on this file since 2825 was 2823, checked in by emillour, 3 years ago

Mars GCM:
Remove the "tracer" (logical) flag as we now always run with at least
one tracer.
EM

File size: 38.3 KB
RevLine 
[1969]1      MODULE vdifc_mod
2     
3      IMPLICIT NONE
4     
5      CONTAINS
6     
[38]7      SUBROUTINE vdifc(ngrid,nlay,nq,co2ice,ppopsk,
8     $                ptimestep,pcapcal,lecrit,
9     $                pplay,pplev,pzlay,pzlev,pz0,
10     $                pu,pv,ph,pq,ptsrf,pemis,pqsurf,
11     $                pdufi,pdvfi,pdhfi,pdqfi,pfluxsrf,
12     $                pdudif,pdvdif,pdhdif,pdtsrf,pq2,
[660]13     $                pdqdif,pdqsdif,wstar,zcdv_true,zcdh_true,
[1996]14     $                hfmax,pcondicea_co2microp,sensibFlux,
[2260]15     $                dustliftday,local_time,watercap, dwatercap_dif)
[1236]16
[1036]17      use tracer_mod, only: noms, igcm_dust_mass, igcm_dust_number,
18     &                      igcm_dust_submicron, igcm_h2o_vap,
[1974]19     &                      igcm_h2o_ice, alpha_lift,
[2312]20     &                      igcm_hdo_vap, igcm_hdo_ice,
[1974]21     &                      igcm_stormdust_mass, igcm_stormdust_number
[1224]22      use surfdat_h, only: watercaptag, frost_albedo_threshold, dryness
[1969]23      USE comcstfi_h, ONLY: cpp, r, rcp, g
[1996]24      use watersat_mod, only: watersat
[1242]25      use turb_mod, only: turb_resolved, ustar, tstar
[2160]26      use compute_dtau_mod, only: ti_injection_sol,tf_injection_sol
[2312]27      use hdo_surfex_mod, only: hdo_surfex
[2515]28c      use geometry_mod, only: longitude_deg,latitude_deg !  Joseph
[2409]29      use dust_param_mod, only: doubleq, submicron, lifting
[2312]30
[38]31      IMPLICIT NONE
32
33c=======================================================================
34c
35c   subject:
36c   --------
37c   Turbulent diffusion (mixing) for potential T, U, V and tracer
38c
39c   Shema implicite
40c   On commence par rajouter au variables x la tendance physique
41c   et on resoult en fait:
42c      x(t+1) =  x(t) + dt * (dx/dt)phys(t)  +  dt * (dx/dt)difv(t+1)
43c
44c   author:
45c   ------
46c      Hourdin/Forget/Fournier
47c=======================================================================
48
49c-----------------------------------------------------------------------
50c   declarations:
51c   -------------
52
[1944]53      include "callkeys.h"
54      include "microphys.h"
[38]55
56c
57c   arguments:
58c   ----------
59
[1036]60      INTEGER,INTENT(IN) :: ngrid,nlay
61      REAL,INTENT(IN) :: ptimestep
62      REAL,INTENT(IN) :: pplay(ngrid,nlay),pplev(ngrid,nlay+1)
63      REAL,INTENT(IN) :: pzlay(ngrid,nlay),pzlev(ngrid,nlay+1)
64      REAL,INTENT(IN) :: pu(ngrid,nlay),pv(ngrid,nlay)
65      REAL,INTENT(IN) :: ph(ngrid,nlay)
66      REAL,INTENT(IN) :: ptsrf(ngrid),pemis(ngrid)
67      REAL,INTENT(IN) :: pdufi(ngrid,nlay),pdvfi(ngrid,nlay)
68      REAL,INTENT(IN) :: pdhfi(ngrid,nlay)
69      REAL,INTENT(IN) :: pfluxsrf(ngrid)
70      REAL,INTENT(OUT) :: pdudif(ngrid,nlay),pdvdif(ngrid,nlay)
71      REAL,INTENT(OUT) :: pdtsrf(ngrid),pdhdif(ngrid,nlay)
[1130]72      REAL,INTENT(IN) :: pcapcal(ngrid)
73      REAL,INTENT(INOUT) :: pq2(ngrid,nlay+1)
[38]74
75c    Argument added for condensation:
[1036]76      REAL,INTENT(IN) :: co2ice (ngrid), ppopsk(ngrid,nlay)
77      logical,INTENT(IN) :: lecrit
[1996]78      REAL,INTENT(IN) :: pcondicea_co2microp(ngrid,nlay)! tendency due to CO2 condensation (kg/kg.s-1)
79     
[1036]80      REAL,INTENT(IN) :: pz0(ngrid) ! surface roughness length (m)
[224]81
[256]82c    Argument added to account for subgrid gustiness :
83
[1944]84      REAL,INTENT(IN) :: wstar(ngrid), hfmax(ngrid)!, zi(ngrid)
[256]85
[38]86c    Traceurs :
[1036]87      integer,intent(in) :: nq
88      REAL,INTENT(IN) :: pqsurf(ngrid,nq)
[2515]89      REAL :: zqsurf(ngrid) ! temporary water tracer
[1036]90      real,intent(in) :: pq(ngrid,nlay,nq), pdqfi(ngrid,nlay,nq)
91      real,intent(out) :: pdqdif(ngrid,nlay,nq)
[1974]92      real,intent(out) :: pdqsdif(ngrid,nq)
93      REAL,INTENT(in) :: dustliftday(ngrid)
94      REAL,INTENT(in) :: local_time(ngrid)
[38]95     
96c   local:
97c   ------
98
[1130]99      REAL :: pt(ngrid,nlay)
[473]100 
[38]101      INTEGER ilev,ig,ilay,nlev
102
[1047]103      REAL z4st,zdplanck(ngrid)
104      REAL zkv(ngrid,nlay+1),zkh(ngrid,nlay+1)
105      REAL zkq(ngrid,nlay+1)
106      REAL zcdv(ngrid),zcdh(ngrid)
107      REAL zcdv_true(ngrid),zcdh_true(ngrid)    ! drag coeff are used by the LES to recompute u* and hfx
108      REAL zu(ngrid,nlay),zv(ngrid,nlay)
109      REAL zh(ngrid,nlay)
110      REAL ztsrf2(ngrid)
111      REAL z1(ngrid),z2(ngrid)
112      REAL za(ngrid,nlay),zb(ngrid,nlay)
113      REAL zb0(ngrid,nlay)
114      REAL zc(ngrid,nlay),zd(ngrid,nlay)
[38]115      REAL zcst1
[1047]116      REAL zu2(ngrid)
[38]117
118      EXTERNAL SSUM,SCOPY
119      REAL SSUM
[1036]120      LOGICAL,SAVE :: firstcall=.true.
[38]121
[2616]122!$OMP THREADPRIVATE(firstcall)
[626]123
[38]124c     variable added for CO2 condensation:
125c     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[1047]126      REAL hh , zhcond(ngrid,nlay)
127      REAL,PARAMETER :: latcond=5.9e5
128      REAL,PARAMETER :: tcond1mb=136.27
129      REAL,SAVE :: acond,bcond
[2616]130
131!$OMP THREADPRIVATE(acond,bcond)
[669]132     
[2515]133c     Subtimestep & implicit treatment of water vapor
134c     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
135      REAL zdqsdif(ngrid) ! subtimestep pdqsdif for water ice
136      REAL ztsrf(ngrid) ! temporary surface temperature in tsub
137      REAL zdtsrf(ngrid) ! surface temperature tendancy in tsub
138
[2179]139c     For latent heat release from ground water ice sublimation   
[2515]140c     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
141      REAL tsrf_lh(ngrid) ! temporary surface temperature with lh effect
[2179]142      REAL lh ! latent heat, formulation given in the Technical Document:
143              ! "Modeling water ice sublimation under Phoenix-like conditions", Montmessin et al. 2004 
[38]144
145c    Tracers :
146c    ~~~~~~~
147      INTEGER iq
[1047]148      REAL zq(ngrid,nlay,nq)
149      REAL zq1temp(ngrid)
150      REAL rho(ngrid) ! near surface air density
151      REAL qsat(ngrid)
[38]152
[2312]153      REAL hdoflux(ngrid)       ! value of vapour flux of HDO
154      REAL h2oflux(ngrid)       ! value of vapour flux of H2O
155      REAL old_h2o_vap(ngrid)   ! traceur d'eau avant traitement
156
[38]157      REAL kmixmin
158
[2260]159c    Argument added for surface water ice budget:
160      REAL,INTENT(IN) :: watercap(ngrid)
161      REAL,INTENT(OUT) :: dwatercap_dif(ngrid)
162
[2515]163c    Subtimestep to compute h2o latent heat flux:
164      REAL :: dtmax = 0.5 ! subtimestep temp criterion
165      INTEGER tsub ! adaptative subtimestep (seconds)
166      REAL subtimestep !ptimestep/nsubtimestep
167      INTEGER nsubtimestep(ngrid) ! number of subtimestep (int)
168
[473]169c    Mass-variation scheme :
170c    ~~~~~~~
171
172      INTEGER j,l
[1047]173      REAL zcondicea(ngrid,nlay)
174      REAL zt(ngrid,nlay),ztcond(ngrid,nlay+1)
175      REAL betam(ngrid,nlay),dmice(ngrid,nlay)
176      REAL pdtc(ngrid,nlay)
177      REAL zhs(ngrid,nlay)
178      REAL,SAVE :: ccond
[473]179
[2616]180!$OMP THREADPRIVATE(ccond)
181
[473]182c     Theta_m formulation for mass-variation scheme :
183c     ~~~~~~~
184
[1047]185      INTEGER,SAVE :: ico2
186      INTEGER llnt(ngrid)
187      REAL,SAVE :: m_co2, m_noco2, A , B
188      REAL vmr_co2(ngrid,nlay)
[473]189      REAL qco2,mmean
190
[2616]191!$OMP THREADPRIVATE(ico2,m_co2,m_noco2,A,B)
192
[1047]193      REAL,INTENT(OUT) :: sensibFlux(ngrid)
[660]194
[2312]195!!MARGAUX
196      REAL DoH_vap(ngrid,nlay)
197
[38]198c    ** un petit test de coherence
199c       --------------------------
200
[1779]201      ! AS: OK firstcall absolute
[38]202      IF (firstcall) THEN
203c        To compute: Tcond= 1./(bcond-acond*log(.0095*p)) (p in pascal)
204         bcond=1./tcond1mb
205         acond=r/latcond
[473]206         ccond=cpp/(g*latcond)
[38]207         PRINT*,'In vdifc: Tcond(P=1mb)=',tcond1mb,' Lcond=',latcond
[473]208         PRINT*,'          acond,bcond,ccond',acond,bcond,ccond
[38]209
[473]210
211         ico2=0
212
213c          Prepare Special treatment if one of the tracer is CO2 gas
[1036]214           do iq=1,nq
[473]215             if (noms(iq).eq."co2") then
216                ico2=iq
217                m_co2 = 44.01E-3  ! CO2 molecular mass (kg/mol)
218                m_noco2 = 33.37E-3  ! Non condensible mol mass (kg/mol)
219c               Compute A and B coefficient use to compute
220c               mean molecular mass Mair defined by
221c               1/Mair = q(ico2)/m_co2 + (1-q(ico2))/m_noco2
222c               1/Mair = A*q(ico2) + B
223                A =(1/m_co2 - 1/m_noco2)
224                B=1/m_noco2
225             endif
226           enddo
227
[38]228        firstcall=.false.
229      ENDIF
230
231
232c-----------------------------------------------------------------------
233c    1. initialisation
234c    -----------------
235
236      nlev=nlay+1
237
[1035]238      ! initialize output tendencies to zero:
239      pdudif(1:ngrid,1:nlay)=0
240      pdvdif(1:ngrid,1:nlay)=0
241      pdhdif(1:ngrid,1:nlay)=0
242      pdtsrf(1:ngrid)=0
[2515]243      zdtsrf(1:ngrid)=0
[1035]244      pdqdif(1:ngrid,1:nlay,1:nq)=0
245      pdqsdif(1:ngrid,1:nq)=0
[2515]246      zdqsdif(1:ngrid)=0
[2260]247      dwatercap_dif(1:ngrid)=0
[1035]248
[38]249c    ** calcul de rho*dz et dt*rho/dz=dt*rho**2 g/dp
250c       avec rho=p/RT=p/ (R Theta) (p/ps)**kappa
251c       ----------------------------------------
252
253      DO ilay=1,nlay
254         DO ig=1,ngrid
255            za(ig,ilay)=(pplev(ig,ilay)-pplev(ig,ilay+1))/g
[473]256! Mass variation scheme:
257            betam(ig,ilay)=-za(ig,ilay)*latcond/(cpp*ppopsk(ig,ilay))
[38]258         ENDDO
259      ENDDO
260
261      zcst1=4.*g*ptimestep/(r*r)
262      DO ilev=2,nlev-1
263         DO ig=1,ngrid
264            zb0(ig,ilev)=pplev(ig,ilev)*
265     s      (pplev(ig,1)/pplev(ig,ilev))**rcp /
266     s      (ph(ig,ilev-1)+ph(ig,ilev))
267            zb0(ig,ilev)=zcst1*zb0(ig,ilev)*zb0(ig,ilev)/
268     s      (pplay(ig,ilev-1)-pplay(ig,ilev))
269         ENDDO
270      ENDDO
271      DO ig=1,ngrid
[473]272         zb0(ig,1)=ptimestep*pplev(ig,1)/(r*ptsrf(ig))
[38]273      ENDDO
274
275c    ** diagnostique pour l'initialisation
276c       ----------------------------------
277
278      IF(lecrit) THEN
279         ig=ngrid/2+1
280         PRINT*,'Pression (mbar) ,altitude (km),u,v,theta, rho dz'
281         DO ilay=1,nlay
282            WRITE(*,'(6f11.5)')
283     s      .01*pplay(ig,ilay),.001*pzlay(ig,ilay),
284     s      pu(ig,ilay),pv(ig,ilay),ph(ig,ilay),za(ig,ilay)
285         ENDDO
286         PRINT*,'Pression (mbar) ,altitude (km),zb'
287         DO ilev=1,nlay
288            WRITE(*,'(3f15.7)')
289     s      .01*pplev(ig,ilev),.001*pzlev(ig,ilev),
290     s      zb0(ig,ilev)
291         ENDDO
292      ENDIF
293
[473]294c     -----------------------------------
[38]295c     Potential Condensation temperature:
296c     -----------------------------------
297
[473]298c     Compute CO2 Volume mixing ratio
299c     -------------------------------
300      if (callcond.and.(ico2.ne.0)) then
301         DO ilev=1,nlay
302            DO ig=1,ngrid
[529]303              qco2=MAX(1.E-30
304     &             ,pq(ig,ilev,ico2)+pdqfi(ig,ilev,ico2)*ptimestep)
[473]305c             Mean air molecular mass = 1/(q(ico2)/m_co2 + (1-q(ico2))/m_noco2)
306              mmean=1/(A*qco2 +B)
307              vmr_co2(ig,ilev) = qco2*mmean/m_co2
308            ENDDO
309         ENDDO
310      else
311         DO ilev=1,nlay
312            DO ig=1,ngrid
313              vmr_co2(ig,ilev)=0.95
314            ENDDO
315         ENDDO
316      end if
[38]317
[473]318c     forecast of atmospheric temperature zt and frost temperature ztcond
319c     --------------------------------------------------------------------
[38]320
[473]321      if (callcond) then
322        DO ilev=1,nlay
323          DO ig=1,ngrid
[884]324              ztcond(ig,ilev)=
325     &      1./(bcond-acond*log(.01*vmr_co2(ig,ilev)*pplay(ig,ilev)))
326            if (pplay(ig,ilev).lt.1e-4) ztcond(ig,ilev)=0.0 !mars Monica
[473]327!            zhcond(ig,ilev) =
328!     &  (1./(bcond-acond*log(.0095*pplay(ig,ilev))))/ppopsk(ig,ilev)
329              zhcond(ig,ilev) = ztcond(ig,ilev)/ppopsk(ig,ilev)
330          END DO
331        END DO
[884]332        ztcond(:,nlay+1)=ztcond(:,nlay)
[473]333      else
[884]334         zhcond(:,:) = 0
335         ztcond(:,:) = 0
[473]336      end if
337
338
[38]339c-----------------------------------------------------------------------
340c   2. ajout des tendances physiques
341c      -----------------------------
342
343      DO ilev=1,nlay
344         DO ig=1,ngrid
345            zu(ig,ilev)=pu(ig,ilev)+pdufi(ig,ilev)*ptimestep
346            zv(ig,ilev)=pv(ig,ilev)+pdvfi(ig,ilev)*ptimestep
347            zh(ig,ilev)=ph(ig,ilev)+pdhfi(ig,ilev)*ptimestep
[473]348!            zh(ig,ilev)=max(zh(ig,ilev),zhcond(ig,ilev))
[38]349         ENDDO
350      ENDDO
[2823]351      zq(1:ngrid,1:nlay,1:nq)=pq(1:ngrid,1:nlay,1:nq)+
352     &                        pdqfi(1:ngrid,1:nlay,1:nq)*ptimestep
[38]353
354c-----------------------------------------------------------------------
355c   3. schema de turbulence
356c      --------------------
357
358c    ** source d'energie cinetique turbulente a la surface
359c       (condition aux limites du schema de diffusion turbulente
360c       dans la couche limite
361c       ---------------------
362
[499]363      CALL vdif_cd(ngrid,nlay,pz0,g,pzlay,pu,pv,wstar,ptsrf,ph
[1236]364     &             ,zcdv_true,zcdh_true)
[256]365
[290]366        zu2(:)=pu(:,1)*pu(:,1)+pv(:,1)*pv(:,1)
[256]367
[291]368        IF (callrichsl) THEN
[545]369          zcdv(:)=zcdv_true(:)*sqrt(zu2(:)+
370     &     (log(1.+0.7*wstar(:) + 2.3*wstar(:)**2))**2)
371          zcdh(:)=zcdh_true(:)*sqrt(zu2(:)+
372     &     (log(1.+0.7*wstar(:) + 2.3*wstar(:)**2))**2)
[496]373
[1242]374           ustar(:)=sqrt(zcdv_true(:))*sqrt(zu2(:)+
[545]375     &     (log(1.+0.7*wstar(:) + 2.3*wstar(:)**2))**2)
376
[1242]377           tstar(:)=0.
[545]378           DO ig=1,ngrid
379              IF (zcdh_true(ig) .ne. 0.) THEN      ! When Cd=Ch=0, u*=t*=0
[1242]380                 tstar(ig)=(ph(ig,1)-ptsrf(ig))*zcdh(ig)/ustar(ig)
[545]381              ENDIF
382           ENDDO
383
[284]384        ELSE
[545]385           zcdv(:)=zcdv_true(:)*sqrt(zu2(:))     ! 1 / bulk aerodynamic momentum conductance
386           zcdh(:)=zcdh_true(:)*sqrt(zu2(:))     ! 1 / bulk aerodynamic heat conductance
[1242]387           ustar(:)=sqrt(zcdv_true(:))*sqrt(zu2(:))
388           tstar(:)=(ph(:,1)-ptsrf(:))*zcdh_true(:)/sqrt(zcdv_true(:))
[290]389        ENDIF
[38]390
[529]391! Some usefull diagnostics for the new surface layer parametrization :
[290]392
[1130]393!        call WRITEDIAGFI(ngrid,'vdifc_zcdv_true',
[256]394!     &              'momentum drag','no units',
395!     &                         2,zcdv_true)
[1130]396!        call WRITEDIAGFI(ngrid,'vdifc_zcdh_true',
[256]397!     &              'heat drag','no units',
398!     &                         2,zcdh_true)
[1130]399!        call WRITEDIAGFI(ngrid,'vdifc_ust',
[473]400!     &              'friction velocity','m/s',2,ust)
[1130]401!       call WRITEDIAGFI(ngrid,'vdifc_tst',
[473]402!     &              'friction temperature','K',2,tst)
[1130]403!        call WRITEDIAGFI(ngrid,'vdifc_zcdv',
[268]404!     &              'aerodyn momentum conductance','m/s',
[256]405!     &                         2,zcdv)
[1130]406!        call WRITEDIAGFI(ngrid,'vdifc_zcdh',
[268]407!     &              'aerodyn heat conductance','m/s',
[256]408!     &                         2,zcdh)
409
[38]410c    ** schema de diffusion turbulente dans la couche limite
411c       ----------------------------------------------------
[1240]412       IF (.not. callyamada4) THEN
[529]413
[1130]414       CALL vdif_kc(ngrid,nlay,nq,ptimestep,g,pzlev,pzlay
[38]415     &              ,pu,pv,ph,zcdv_true
[325]416     &              ,pq2,zkv,zkh,zq)
[529]417
[544]418      ELSE
[38]419
[555]420      pt(:,:)=ph(:,:)*ppopsk(:,:)
[1036]421      CALL yamada4(ngrid,nlay,nq,ptimestep,g,r,pplev,pt
[1242]422     s   ,pzlev,pzlay,pu,pv,ph,pq,zcdv_true,pq2,zkv,zkh,zkq,ustar
[652]423     s   ,9)
[544]424      ENDIF
425
[38]426      if ((doubleq).and.(ngrid.eq.1)) then
427        kmixmin = 80. !80.! minimum eddy mix coeff in 1D
428        do ilev=1,nlay
429          do ig=1,ngrid
430           zkh(ig,ilev) = max(kmixmin,zkh(ig,ilev))
431           zkv(ig,ilev) = max(kmixmin,zkv(ig,ilev))
432          end do
433        end do
434      end if
435
436c    ** diagnostique pour le schema de turbulence
437c       -----------------------------------------
438
439      IF(lecrit) THEN
440         PRINT*
441         PRINT*,'Diagnostic for the vertical turbulent mixing'
442         PRINT*,'Cd for momentum and potential temperature'
443
444         PRINT*,zcdv(ngrid/2+1),zcdh(ngrid/2+1)
445         PRINT*,'Mixing coefficient for momentum and pot.temp.'
446         DO ilev=1,nlay
447            PRINT*,zkv(ngrid/2+1,ilev),zkh(ngrid/2+1,ilev)
448         ENDDO
449      ENDIF
450
451
452
453
454c-----------------------------------------------------------------------
455c   4. inversion pour l'implicite sur u
456c      --------------------------------
457
458c    ** l'equation est
459c       u(t+1) =  u(t) + dt * {(du/dt)phys}(t)  +  dt * {(du/dt)difv}(t+1)
460c       avec
461c       /zu/ = u(t) + dt * {(du/dt)phys}(t)   (voir paragraphe 2.)
462c       et
463c       dt * {(du/dt)difv}(t+1) = dt * {(d/dz)[ Ku (du/dz) ]}(t+1)
464c       donc les entrees sont /zcdv/ pour la condition a la limite sol
465c       et /zkv/ = Ku
[2312]466
[2274]467      zb(1:ngrid,2:nlay)=zkv(1:ngrid,2:nlay)*zb0(1:ngrid,2:nlay)
468      zb(1:ngrid,1)=zcdv(1:ngrid)*zb0(1:ngrid,1)
[38]469
470      DO ig=1,ngrid
471         z1(ig)=1./(za(ig,nlay)+zb(ig,nlay))
472         zc(ig,nlay)=za(ig,nlay)*zu(ig,nlay)*z1(ig)
473         zd(ig,nlay)=zb(ig,nlay)*z1(ig)
474      ENDDO
475
476      DO ilay=nlay-1,1,-1
477         DO ig=1,ngrid
478            z1(ig)=1./(za(ig,ilay)+zb(ig,ilay)+
479     $         zb(ig,ilay+1)*(1.-zd(ig,ilay+1)))
480            zc(ig,ilay)=(za(ig,ilay)*zu(ig,ilay)+
481     $         zb(ig,ilay+1)*zc(ig,ilay+1))*z1(ig)
482            zd(ig,ilay)=zb(ig,ilay)*z1(ig)
483         ENDDO
484      ENDDO
485
486      DO ig=1,ngrid
487         zu(ig,1)=zc(ig,1)
488      ENDDO
489      DO ilay=2,nlay
490         DO ig=1,ngrid
491            zu(ig,ilay)=zc(ig,ilay)+zd(ig,ilay)*zu(ig,ilay-1)
492         ENDDO
493      ENDDO
494
495
496
497
498
499c-----------------------------------------------------------------------
500c   5. inversion pour l'implicite sur v
501c      --------------------------------
502
503c    ** l'equation est
504c       v(t+1) =  v(t) + dt * {(dv/dt)phys}(t)  +  dt * {(dv/dt)difv}(t+1)
505c       avec
506c       /zv/ = v(t) + dt * {(dv/dt)phys}(t)   (voir paragraphe 2.)
507c       et
508c       dt * {(dv/dt)difv}(t+1) = dt * {(d/dz)[ Kv (dv/dz) ]}(t+1)
509c       donc les entrees sont /zcdv/ pour la condition a la limite sol
510c       et /zkv/ = Kv
511
512      DO ig=1,ngrid
513         z1(ig)=1./(za(ig,nlay)+zb(ig,nlay))
514         zc(ig,nlay)=za(ig,nlay)*zv(ig,nlay)*z1(ig)
515         zd(ig,nlay)=zb(ig,nlay)*z1(ig)
516      ENDDO
517
518      DO ilay=nlay-1,1,-1
519         DO ig=1,ngrid
520            z1(ig)=1./(za(ig,ilay)+zb(ig,ilay)+
521     $         zb(ig,ilay+1)*(1.-zd(ig,ilay+1)))
522            zc(ig,ilay)=(za(ig,ilay)*zv(ig,ilay)+
523     $         zb(ig,ilay+1)*zc(ig,ilay+1))*z1(ig)
524            zd(ig,ilay)=zb(ig,ilay)*z1(ig)
525         ENDDO
526      ENDDO
527
528      DO ig=1,ngrid
529         zv(ig,1)=zc(ig,1)
530      ENDDO
531      DO ilay=2,nlay
532         DO ig=1,ngrid
533            zv(ig,ilay)=zc(ig,ilay)+zd(ig,ilay)*zv(ig,ilay-1)
534         ENDDO
535      ENDDO
536
537
538
539
540
541c-----------------------------------------------------------------------
542c   6. inversion pour l'implicite sur h sans oublier le couplage
543c      avec le sol (conduction)
544c      ------------------------
545
546c    ** l'equation est
547c       h(t+1) =  h(t) + dt * {(dh/dt)phys}(t)  +  dt * {(dh/dt)difv}(t+1)
548c       avec
549c       /zh/ = h(t) + dt * {(dh/dt)phys}(t)   (voir paragraphe 2.)
550c       et
551c       dt * {(dh/dt)difv}(t+1) = dt * {(d/dz)[ Kh (dh/dz) ]}(t+1)
552c       donc les entrees sont /zcdh/ pour la condition de raccord au sol
553c       et /zkh/ = Kh
554c       -------------
555
[473]556c Mass variation scheme:
[2274]557      zb(1:ngrid,2:nlay)=zkh(1:ngrid,2:nlay)*zb0(1:ngrid,2:nlay)
558      zb(1:ngrid,1)=zcdh(1:ngrid)*zb0(1:ngrid,1)
[38]559
[473]560c on initialise dm c
561     
562      pdtc(:,:)=0.
563      zt(:,:)=0.
564      dmice(:,:)=0.
[38]565
566c    ** calcul de (d Planck / dT) a la temperature d'interface
567c       ------------------------------------------------------
568
569      z4st=4.*5.67e-8*ptimestep
[544]570      IF (tke_heat_flux .eq. 0.) THEN
[38]571      DO ig=1,ngrid
572         zdplanck(ig)=z4st*pemis(ig)*ptsrf(ig)*ptsrf(ig)*ptsrf(ig)
573      ENDDO
[544]574      ELSE
575         zdplanck(:)=0.
576      ENDIF
[38]577
[473]578! calcul de zc et zd pour la couche top en prenant en compte le terme
[2080]579! de variation de masse (on fait une boucle pour que \E7a converge)
[473]580
581! Identification des points de grilles qui ont besoin de la correction
582
583      llnt(:)=1
[1236]584      IF (.not.turb_resolved) THEN
[884]585      IF (callcond) THEN
586       DO ig=1,ngrid
[473]587         DO l=1,nlay
588            if(zh(ig,l) .lt. zhcond(ig,l)) then
589               llnt(ig)=300 
590! 200 and 100 do not go beyond month 9 with normal dissipation
591               goto 5
592            endif
593         ENDDO
[884]5945      continue
595       ENDDO
596      ENDIF
[473]597
[529]598      ENDIF
599
[473]600      DO ig=1,ngrid
601
602! Initialization of z1 and zd, which do not depend on dmice
603
604      z1(ig)=1./(za(ig,nlay)+zb(ig,nlay))
605      zd(ig,nlay)=zb(ig,nlay)*z1(ig)
606
607      DO ilay=nlay-1,1,-1
608          z1(ig)=1./(za(ig,ilay)+zb(ig,ilay)+
609     $        zb(ig,ilay+1)*(1.-zd(ig,ilay+1)))
610          zd(ig,ilay)=zb(ig,ilay)*z1(ig)
611      ENDDO
612
613! Convergence loop
614
615      DO j=1,llnt(ig)
616
617            z1(ig)=1./(za(ig,nlay)+zb(ig,nlay))
618            zc(ig,nlay)=za(ig,nlay)*zh(ig,nlay)
619     &      -betam(ig,nlay)*dmice(ig,nlay)
620            zc(ig,nlay)=zc(ig,nlay)*z1(ig)
621!            zd(ig,nlay)=zb(ig,nlay)*z1(ig)
622
623! calcul de zc et zd pour les couches du haut vers le bas
624
625             DO ilay=nlay-1,1,-1
626               z1(ig)=1./(za(ig,ilay)+zb(ig,ilay)+
627     $            zb(ig,ilay+1)*(1.-zd(ig,ilay+1)))
628               zc(ig,ilay)=(za(ig,ilay)*zh(ig,ilay)+
629     $            zb(ig,ilay+1)*zc(ig,ilay+1)-
630     $            betam(ig,ilay)*dmice(ig,ilay))*z1(ig)
631!               zd(ig,ilay)=zb(ig,ilay)*z1(ig)
632            ENDDO
633
[38]634c    ** calcul de la temperature_d'interface et de sa tendance.
635c       on ecrit que la somme des flux est nulle a l'interface
636c       a t + \delta t,
637c       c'est a dire le flux radiatif a {t + \delta t}
638c       + le flux turbulent a {t + \delta t}
639c            qui s'ecrit K (T1-Tsurf) avec T1 = d1 Tsurf + c1
640c            (notation K dt = /cpp*b/)       
641c       + le flux dans le sol a t
642c       + l'evolution du flux dans le sol lorsque la temperature d'interface
643c       passe de sa valeur a t a sa valeur a {t + \delta t}.
644c       ----------------------------------------------------
645
646         z1(ig)=pcapcal(ig)*ptsrf(ig)+cpp*zb(ig,1)*zc(ig,1)
647     s     +zdplanck(ig)*ptsrf(ig)+ pfluxsrf(ig)*ptimestep
648         z2(ig)= pcapcal(ig)+cpp*zb(ig,1)*(1.-zd(ig,1))+zdplanck(ig)
649         ztsrf2(ig)=z1(ig)/z2(ig)
[473]650!         pdtsrf(ig)=(ztsrf2(ig)-ptsrf(ig))/ptimestep  !incremented outside loop
651            zhs(ig,1)=zc(ig,1)+zd(ig,1)*ztsrf2(ig)
[38]652
653c    ** et a partir de la temperature au sol on remonte
654c       -----------------------------------------------
655
[473]656            DO ilay=2,nlay
657               zhs(ig,ilay)=zc(ig,ilay)+zd(ig,ilay)*zhs(ig,ilay-1)
658            ENDDO
659            DO ilay=1,nlay
660               zt(ig,ilay)=zhs(ig,ilay)*ppopsk(ig,ilay)
661            ENDDO
662
663c      Condensation/sublimation in the atmosphere
664c      ------------------------------------------
665c      (computation of zcondicea and dmice)
666
[1996]667      IF (.NOT. co2clouds) then
668       DO l=nlay , 1, -1
[473]669           IF(zt(ig,l).LT.ztcond(ig,l)) THEN
670               pdtc(ig,l)=(ztcond(ig,l) - zt(ig,l))/ptimestep
671               zcondicea(ig,l)=(pplev(ig,l)-pplev(ig,l+1))
672     &                        *ccond*pdtc(ig,l)
673              dmice(ig,l)= dmice(ig,l) + zcondicea(ig,l)*ptimestep
674            END IF
[1996]675       ENDDO
676      ELSE
677       DO l=nlay , 1, -1
678         zcondicea(ig,l)= 0.!pcondicea_co2microp(ig,l)*
679c     &                        (pplev(ig,l) - pplev(ig,l+1))/g
680         dmice(ig,l)= 0.!dmice(ig,l) + zcondicea(ig,l)*ptimestep
681         pdtc(ig,l)=0.
682       ENDDO   
683      ENDIF
684     
685       ENDDO!of Do j=1,XXX
[38]686
[1996]687      ENDDO   !of Do ig=1,ngrid
[38]688
[473]689      pdtsrf(:)=(ztsrf2(:)-ptsrf(:))/ptimestep
[669]690     
[660]691      DO ig=1,ngrid  ! computing sensible heat flux (atm => surface)
692         sensibFlux(ig)=cpp*zb(ig,1)/ptimestep*(zhs(ig,1)-ztsrf2(ig))
693      ENDDO
[473]694
[38]695c-----------------------------------------------------------------------
696c   TRACERS
697c   -------
698
699c     Using the wind modified by friction for lifting and  sublimation
700c     ----------------------------------------------------------------
701
[529]702!     This is computed above and takes into account surface-atmosphere flux
703!     enhancement by subgrid gustiness and atmospheric-stability related
704!     variations of transfer coefficients.
705
706!        DO ig=1,ngrid
707!          zu2(ig)=zu(ig,1)*zu(ig,1)+zv(ig,1)*zv(ig,1)
708!          zcdv(ig)=zcdv_true(ig)*sqrt(zu2(ig))
709!          zcdh(ig)=zcdh_true(ig)*sqrt(zu2(ig))
710!        ENDDO
711
[38]712c       Calcul du flux vertical au bas de la premiere couche (dust) :
713c       -----------------------------------------------------------
[1047]714        do ig=1,ngrid 
[38]715          rho(ig) = zb0(ig,1) /ptimestep
716c          zb(ig,1) = 0.
717        end do
718c       Dust lifting:
719        if (lifting) then
[310]720#ifndef MESOSCALE
[38]721           if (doubleq.AND.submicron) then
722             do ig=1,ngrid
723c              if(co2ice(ig).lt.1) then
724                 pdqsdif(ig,igcm_dust_mass) =
725     &             -alpha_lift(igcm_dust_mass) 
726                 pdqsdif(ig,igcm_dust_number) =
727     &             -alpha_lift(igcm_dust_number) 
728                 pdqsdif(ig,igcm_dust_submicron) =
729     &             -alpha_lift(igcm_dust_submicron)
730c              end if
731             end do
732           else if (doubleq) then
[1974]733             if (dustinjection.eq.0) then !injection scheme 0 (old)
734                                          !or 2 (injection in CL)
735              do ig=1,ngrid
[1455]736               if(co2ice(ig).lt.1) then ! pas de soulevement si glace CO2
[38]737                 pdqsdif(ig,igcm_dust_mass) =
738     &             -alpha_lift(igcm_dust_mass) 
739                 pdqsdif(ig,igcm_dust_number) =
[520]740     &             -alpha_lift(igcm_dust_number)
741               end if
[1974]742              end do
743             elseif(dustinjection.eq.1)then ! dust injection scheme = 1 injection from surface
744              do ig=1,ngrid
745               if(co2ice(ig).lt.1) then ! pas de soulevement si glace CO2
[2160]746                IF((ti_injection_sol.LE.local_time(ig)).and.
747     &                  (local_time(ig).LE.tf_injection_sol)) THEN
[1974]748                  if (rdstorm) then !Rocket dust storm scheme
749                        pdqsdif(ig,igcm_stormdust_mass) =
750     &                          -alpha_lift(igcm_stormdust_mass)
751     &                          *dustliftday(ig)
752                        pdqsdif(ig,igcm_stormdust_number) =
753     &                          -alpha_lift(igcm_stormdust_number)
754     &                          *dustliftday(ig)
755                        pdqsdif(ig,igcm_dust_mass)= 0.
756                        pdqsdif(ig,igcm_dust_number)= 0.
757                  else
758                        pdqsdif(ig,igcm_dust_mass)=
759     &                          -dustliftday(ig)*
760     &                          alpha_lift(igcm_dust_mass)               
761                        pdqsdif(ig,igcm_dust_number)=
762     &                          -dustliftday(ig)*
763     &                          alpha_lift(igcm_dust_number)
764                  endif
765                  if (submicron) then
766                        pdqsdif(ig,igcm_dust_submicron) = 0.
767                  endif ! if (submicron)
768                ELSE ! outside dust injection time frame
[2080]769                  pdqsdif(ig,igcm_dust_mass)= 0.
770                  pdqsdif(ig,igcm_dust_number)= 0.
771                  if (rdstorm) then     
[1974]772                        pdqsdif(ig,igcm_stormdust_mass)= 0.
773                        pdqsdif(ig,igcm_stormdust_number)= 0.
[2080]774                  end if
[1974]775                ENDIF
776               
777                end if ! of if(co2ice(ig).lt.1)
778              end do
779             endif ! end if dustinjection
[38]780           else if (submicron) then
781             do ig=1,ngrid
782                 pdqsdif(ig,igcm_dust_submicron) =
783     &             -alpha_lift(igcm_dust_submicron)
784             end do
785           else
[1236]786#endif
[38]787            call dustlift(ngrid,nlay,nq,rho,zcdh_true,zcdh,co2ice,
788     &                    pdqsdif)
[1236]789#ifndef MESOSCALE
[38]790           endif !doubleq.AND.submicron
[310]791#endif
[38]792        else
793           pdqsdif(1:ngrid,1:nq) = 0.
794        end if
795
796c       OU calcul de la valeur de q a la surface (water)  :
797c       ----------------------------------------
798
799c      Inversion pour l'implicite sur q
[2515]800c      Cas des traceurs qui ne sont pas h2o_vap
801c      h2o_vap est traite plus loin avec un sous pas de temps
802c      hdo_vap est traite ensuite car dependant de h2o_vap
[38]803c       --------------------------------
[2515]804
805        do iq=1,nq  !for all tracers except water vapor
806          if ((.not. water).or.(.not. iq.eq.igcm_h2o_vap).or.
807     &       (.not. iq.eq.igcm_hdo_vap)) then
808
809
[2274]810          zb(1:ngrid,2:nlay)=zkh(1:ngrid,2:nlay)*zb0(1:ngrid,2:nlay)
[2515]811          zb(1:ngrid,1)=0
[38]812
[2515]813          DO ig=1,ngrid
814               z1(ig)=1./(za(ig,nlay)+zb(ig,nlay))
815               zc(ig,nlay)=za(ig,nlay)*zq(ig,nlay,iq)*z1(ig)
816               zd(ig,nlay)=zb(ig,nlay)*z1(ig)
817          ENDDO
818 
819          DO ilay=nlay-1,2,-1
820               DO ig=1,ngrid
821                z1(ig)=1./(za(ig,ilay)+zb(ig,ilay)+
822     $           zb(ig,ilay+1)*(1.-zd(ig,ilay+1)))
823                zc(ig,ilay)=(za(ig,ilay)*zq(ig,ilay,iq)+
824     $           zb(ig,ilay+1)*zc(ig,ilay+1))*z1(ig)
825                zd(ig,ilay)=zb(ig,ilay)*z1(ig)
826               ENDDO
827          ENDDO
828
829            if ((iq.eq.igcm_h2o_ice)
830     $      .or. (hdo.and.(iq.eq.igcm_hdo_ice) )) then
831
832               DO ig=1,ngrid
833                   z1(ig)=1./(za(ig,1)+zb(ig,1)+
834     $              zb(ig,2)*(1.-zd(ig,2)))
835                   zc(ig,1)=(za(ig,1)*zq(ig,1,iq)+
836     $              zb(ig,2)*zc(ig,2)) *z1(ig)  !special case h2o_ice
837               ENDDO
838            else ! every other tracer
839               DO ig=1,ngrid
840                   z1(ig)=1./(za(ig,1)+zb(ig,1)+
841     $              zb(ig,2)*(1.-zd(ig,2)))
842                   zc(ig,1)=(za(ig,1)*zq(ig,1,iq)+
843     $              zb(ig,2)*zc(ig,2) +
844     $             (-pdqsdif(ig,iq)) *ptimestep) *z1(ig)  !tracer flux from surface
845               ENDDO
846            endif !((iq.eq.igcm_h2o_ice)
847c         Starting upward calculations for simple mixing of tracer (dust)
848          DO ig=1,ngrid
849             zq(ig,1,iq)=zc(ig,1)
850             DO ilay=2,nlay
851               zq(ig,ilay,iq)=zc(ig,ilay)+zd(ig,ilay)*zq(ig,ilay-1,iq)
852             ENDDO
853          ENDDO
854          endif! ((.not. water).or.(.not. iq.eq.igcm_h2o_vap)) then
855        enddo ! of do iq=1,nq
856
857c --------- h2o_vap --------------------------------
858
859
860c      Traitement de la vapeur d'eau h2o_vap
861c      Utilisation d'un sous pas de temps afin
862c      de decrire le flux de chaleur latente
863
864
865        do iq=1,nq 
[2312]866          if ((water).and.(iq.eq.igcm_h2o_vap)) then
[2515]867
868
869           DO ig=1,ngrid
870             zqsurf(ig)=pqsurf(ig,igcm_h2o_ice)
871           ENDDO ! ig=1,ngrid
872
873c          make_tsub : sous pas de temps adaptatif
874c          la subroutine est a la fin du fichier
875
876           call make_tsub(ngrid,pdtsrf,zqsurf,
877     &                    ptimestep,dtmax,watercaptag,
878     &                    nsubtimestep)
879
880c           Calculation for turbulent exchange with the surface (for ice)
881c           initialization of ztsrf, which is surface temperature in
882c           the subtimestep.
883           DO ig=1,ngrid
884            subtimestep = ptimestep/nsubtimestep(ig)
885            ztsrf(ig)=ptsrf(ig)  !  +pdtsrf(ig)*subtimestep
886
887c           Debut du sous pas de temps
888
889            DO tsub=1,nsubtimestep(ig)
890
891c           C'est parti !
892
893             zb(1:ngrid,2:nlay)=zkh(1:ngrid,2:nlay)*zb0(1:ngrid,2:nlay)
894     &                     /float(nsubtimestep(ig))
[2274]895             zb(1:ngrid,1)=zcdv(1:ngrid)*zb0(1:ngrid,1)
[2515]896     &                     /float(nsubtimestep(ig))
[2274]897             zb(1:ngrid,1)=dryness(1:ngrid)*zb(1:ngrid,1)
[2515]898             
899             z1(ig)=1./(za(ig,nlay)+zb(ig,nlay))
900             zc(ig,nlay)=za(ig,nlay)*zq(ig,nlay,iq)*z1(ig)
901             zd(ig,nlay)=zb(ig,nlay)*z1(ig)
902             DO ilay=nlay-1,2,-1
903                 z1(ig)=1./(za(ig,ilay)+zb(ig,ilay)+
904     $            zb(ig,ilay+1)*(1.-zd(ig,ilay+1)))
905                 zc(ig,ilay)=(za(ig,ilay)*zq(ig,ilay,iq)+
906     $            zb(ig,ilay+1)*zc(ig,ilay+1))*z1(ig)
907                 zd(ig,ilay)=zb(ig,ilay)*z1(ig)
908             ENDDO 
909             z1(ig)=1./(za(ig,1)+zb(ig,1)+
910     $          zb(ig,2)*(1.-zd(ig,2)))
911             zc(ig,1)=(za(ig,1)*zq(ig,1,iq)+
912     $        zb(ig,2)*zc(ig,2)) * z1(ig)
[38]913
[2531]914             call watersat(1,ztsrf(ig),pplev(ig,1),qsat(ig))
[2515]915             old_h2o_vap(ig)=zq(ig,1,igcm_h2o_vap)
916             zd(ig,1)=zb(ig,1)*z1(ig)
917             zq1temp(ig)=zc(ig,1)+ zd(ig,1)*qsat(ig)
918
919             zdqsdif(ig)=rho(ig)*dryness(ig)*zcdv(ig)
920     &                      *(zq1temp(ig)-qsat(ig))
[2587]921c             write(*,*)'subliming more than available frost:  qsurf!'
922             if(.not.watercaptag(ig)) then
923               if ((-zdqsdif(ig)*subtimestep)
[2515]924     &            .gt.(zqsurf(ig))) then
[2587]925c             pdqsdif > 0 : ice condensing
926c             pdqsdif < 0 : ice subliming
927c             write(*,*) "subliming more than available frost:  qsurf!"
[2515]928                  zdqsdif(ig)=
929     &                        -zqsurf(ig)/subtimestep
930c                write(*,*)'flux vers le sol=',pdqsdif(ig,nq)
931                 z1(ig)=1./(za(ig,1)+ zb(ig,2)*(1.-zd(ig,2)))
932                 zc(ig,1)=(za(ig,1)*zq(ig,1,igcm_h2o_vap)+
[2587]933     $           zb(ig,2)*zc(ig,2) +
934     $           (-zdqsdif(ig)) *subtimestep) *z1(ig)
[2515]935                 zq1temp(ig)=zc(ig,1)
936               endif  !if .not.watercaptag(ig)
937             endif ! if sublim more than surface
938
939c             Starting upward calculations for water :
940c             Actualisation de h2o_vap dans le premier niveau
941             zq(ig,1,igcm_h2o_vap)=zq1temp(ig)
[2587]942
943c    Take into account the H2O latent heat impact on the surface temperature
[2515]944              if (latentheat_surfwater) then
945                lh=(2834.3-0.28*(ztsrf(ig)-To)-
946     &              0.004*(ztsrf(ig)-To)*(ztsrf(ig)-To))*1.e+3
[2587]947                zdtsrf(ig)=  zdqsdif(ig)*lh /pcapcal(ig)
[2515]948              endif ! (latentheat_surfwater) then
949
[2587]950              DO ilay=2,nlay
951                zq(ig,ilay,iq)=zc(ig,ilay)+zd(ig,ilay)*zq(ig,ilay-1,iq)
952              ENDDO
[2515]953
954c             Subtimestep water budget :
955
956              ztsrf(ig) = ztsrf(ig)+(pdtsrf(ig) + zdtsrf(ig))
957     &                          *subtimestep
958              zqsurf(ig)= zqsurf(ig)+(
959     &                       zdqsdif(ig))*subtimestep
960
961
962c             We ensure that surface temperature can't rise above the solid domain if there
963c             is still ice on the surface (oldschool)
964               if(zqsurf(ig)
965     &           +zdqsdif(ig)*subtimestep
966     &           .gt.frost_albedo_threshold) ! if there is still ice, T cannot exceed To
967     &           zdtsrf(ig) = min(zdtsrf(ig),(To-ztsrf(ig))/subtimestep) ! ice melt case
968
969
[2587]970
[2515]971c             Fin du sous pas de temps
972            ENDDO ! tsub=1,nsubtimestep
973
[2587]974c             Integration of subtimestep temp and water budget :
975c             (btw could also compute the post timestep temp and ice
976c             by simply adding the subtimestep trend instead of this)
[2515]977            pdtsrf(ig)= (ztsrf(ig) -
978     &                     ptsrf(ig))/ptimestep
979            pdqsdif(ig,igcm_h2o_ice)=
980     &                  (zqsurf(ig)- pqsurf(ig,igcm_h2o_ice))/ptimestep
981
[2587]982c if subliming more than qsurf(ice) and on watercaptag, water
983c sublimates from watercap reservoir (dwatercap_dif is <0)
984            if(watercaptag(ig)) then
985              if ((-pdqsdif(ig,igcm_h2o_ice)*ptimestep)
986     &           .gt.(pqsurf(ig,igcm_h2o_ice))) then
987                 dwatercap_dif(ig)=pdqsdif(ig,igcm_h2o_ice)+
988     &                     pqsurf(ig,igcm_h2o_ice)/ptimestep
989                 pdqsdif(ig,igcm_h2o_ice)=
990     &                   - pqsurf(ig,igcm_h2o_ice)/ptimestep
991              endif! ((-pdqsdif(ig)*ptimestep)
992            endif !(watercaptag(ig)) then
993
[2515]994           ENDDO ! of DO ig=1,ngrid
995          END IF ! of IF ((water).and.(iq.eq.igcm_h2o_vap))
996
997c --------- end of h2o_vap ----------------------------
998
999c --------- hdo_vap -----------------------------------
1000
1001c    hdo_ice has already been with along h2o_ice
1002c    amongst "normal" tracers (ie not h2o_vap)
1003
1004         if (hdo.and.(iq.eq.igcm_hdo_vap)) then
1005          zb(1:ngrid,2:nlay)=zkh(1:ngrid,2:nlay)*zb0(1:ngrid,2:nlay)
1006          zb(1:ngrid,1)=0
1007
[38]1008          DO ig=1,ngrid
1009               z1(ig)=1./(za(ig,nlay)+zb(ig,nlay))
1010               zc(ig,nlay)=za(ig,nlay)*zq(ig,nlay,iq)*z1(ig)
1011               zd(ig,nlay)=zb(ig,nlay)*z1(ig)
1012          ENDDO
[2515]1013
[38]1014          DO ilay=nlay-1,2,-1
1015               DO ig=1,ngrid
1016                z1(ig)=1./(za(ig,ilay)+zb(ig,ilay)+
1017     $           zb(ig,ilay+1)*(1.-zd(ig,ilay+1)))
1018                zc(ig,ilay)=(za(ig,ilay)*zq(ig,ilay,iq)+
1019     $           zb(ig,ilay+1)*zc(ig,ilay+1))*z1(ig)
1020                zd(ig,ilay)=zb(ig,ilay)*z1(ig)
1021               ENDDO
1022          ENDDO
1023
[2312]1024            CALL hdo_surfex(ngrid,nlay,nq,ptimestep,
[2593]1025     &                      zt,pplay,zq,pqsurf,
1026     &                      old_h2o_vap,qsat,pdqsdif,dwatercap_dif,
[2312]1027     &                      hdoflux)
1028            DO ig=1,ngrid
1029                z1(ig)=1./(za(ig,1)+zb(ig,1)+
1030     $           zb(ig,2)*(1.-zd(ig,2)))
1031                zc(ig,1)=(za(ig,1)*zq(ig,1,iq)+
1032     $         zb(ig,2)*zc(ig,2) +
1033     $        (-hdoflux(ig)) *ptimestep) *z1(ig)  !tracer flux from surface
1034            ENDDO
1035
[38]1036            DO ig=1,ngrid
[2515]1037              zq(ig,1,iq)=zc(ig,1)
1038              DO ilay=2,nlay
1039                zq(ig,ilay,iq)=zc(ig,ilay)+zd(ig,ilay)*zq(ig,ilay-1,iq)
1040              ENDDO
[38]1041            ENDDO
[2515]1042         endif ! (hdo.and.(iq.eq.igcm_hdo_vap))
[2312]1043
[2515]1044c --------- end of hdo ----------------------------
[38]1045
[2515]1046        enddo ! of do iq=1,nq
[38]1047
[2515]1048c --------- end of tracers  ----------------------------
[2312]1049
[2260]1050
[2312]1051C       Diagnostic output for HDO
1052        if (hdo) then
1053            CALL WRITEDIAGFI(ngrid,'hdoflux',
1054     &                       'hdoflux',
1055     &                       ' ',2,hdoflux) 
1056            CALL WRITEDIAGFI(ngrid,'h2oflux',
1057     &                       'h2oflux',
1058     &                       ' ',2,h2oflux)
1059        endif
1060
[38]1061c-----------------------------------------------------------------------
1062c   8. calcul final des tendances de la diffusion verticale
1063c      ----------------------------------------------------
1064
1065      DO ilev = 1, nlay
1066         DO ig=1,ngrid
1067            pdudif(ig,ilev)=(    zu(ig,ilev)-
1068     $      (pu(ig,ilev)+pdufi(ig,ilev)*ptimestep)    )/ptimestep
1069            pdvdif(ig,ilev)=(    zv(ig,ilev)-
1070     $      (pv(ig,ilev)+pdvfi(ig,ilev)*ptimestep)    )/ptimestep
[473]1071            hh = ph(ig,ilev)+pdhfi(ig,ilev)*ptimestep
1072     $  + (latcond*dmice(ig,ilev)/cpp)/ppopsk(ig,ilev)
1073            pdhdif(ig,ilev)=( zhs(ig,ilev)- hh )/ptimestep
[38]1074         ENDDO
1075      ENDDO
1076
[2823]1077      pdqdif(1:ngrid,1:nlay,1:nq)=(zq(1:ngrid,1:nlay,1:nq)-
1078     &                             (pq(1:ngrid,1:nlay,1:nq)
1079     &                              +pdqfi(1:ngrid,1:nlay,1:nq)
1080     &                                    *ptimestep))/ptimestep
[38]1081
1082c    ** diagnostique final
1083c       ------------------
1084
1085      IF(lecrit) THEN
1086         PRINT*,'In vdif'
1087         PRINT*,'Ts (t) and Ts (t+st)'
1088         WRITE(*,'(a10,3a15)')
1089     s   'theta(t)','theta(t+dt)','u(t)','u(t+dt)'
1090         PRINT*,ptsrf(ngrid/2+1),ztsrf2(ngrid/2+1)
1091         DO ilev=1,nlay
1092            WRITE(*,'(4f15.7)')
[473]1093     s      ph(ngrid/2+1,ilev),zhs(ngrid/2+1,ilev),
[38]1094     s      pu(ngrid/2+1,ilev),zu(ngrid/2+1,ilev)
1095
1096         ENDDO
1097      ENDIF
1098
[1036]1099      END SUBROUTINE vdifc
[1969]1100
[2312]1101c====================================
1102
[2515]1103      SUBROUTINE make_tsub(naersize,dtsurf,qsurf,ptimestep,
1104     $                     dtmax,watercaptag,ntsub)
[2312]1105
[2515]1106c Pas de temps adaptatif en estimant le taux de sublimation
1107c et en adaptant avec un critere "dtmax" du chauffage a accomoder
1108c dtmax est regle empiriquement (pour l'instant) a 0.5 K
1109
1110      integer,intent(in) :: naersize
1111      real,intent(in) :: dtsurf(naersize)
1112      real,intent(in) :: qsurf(naersize)
1113      logical,intent(in) :: watercaptag(naersize)
1114      real,intent(in) :: ptimestep
1115      real,intent(in)  :: dtmax
1116      real  :: ztsub(naersize)
1117      integer  :: i
1118      integer,intent(out) :: ntsub(naersize)
1119
1120      do i=1,naersize
1121        if ((qsurf(i).eq.0).and.
1122     &      (.not.watercaptag(i))) then
1123          ntsub(i) = 1
1124        else
1125          ztsub(i) = ptimestep * dtsurf(i) / dtmax
1126          ntsub(i) = ceiling(abs(ztsub(i)))
1127        endif ! (qsurf(i).eq.0) then
1128c     
1129c       write(78,*), dtsurf*ptimestep, dtsurf, ntsub
1130      enddo! 1=1,ngrid
1131
1132
1133
1134      END SUBROUTINE make_tsub
[1969]1135      END MODULE vdifc_mod
Note: See TracBrowser for help on using the repository browser.