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

Last change on this file since 2814 was 2616, checked in by romain.vande, 3 years ago

LMDZ_MARS RV : Open_MP;
Put all the "save" variables as "!$OMP THREADPRIVATE" in phymars.
The code can now be tested, see README for more info

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