source: flexpart.git/src/timemanager.f90 @ 3481cc1

10.4.1_peseiGFS_025bugfixes+enhancementsdevrelease-10release-10.4.1scaling-bug
Last change on this file since 3481cc1 was 3481cc1, checked in by Ignacio Pisso <ip@…>, 4 years ago

move license from headers to a different file

  • Property mode set to 100644
File size: 29.1 KB
Line 
1subroutine timemanager(metdata_format)
2
3  !*****************************************************************************
4  !                                                                            *
5  ! Handles the computation of trajectories, i.e. determines which             *
6  ! trajectories have to be computed at what time.                             *
7  ! Manages dry+wet deposition routines, radioactive decay and the computation *
8  ! of concentrations.                                                         *
9  !                                                                            *
10  !     Author: A. Stohl                                                       *
11  !                                                                            *
12  !     20 May 1996                                                            *
13  !                                                                            *
14  !*****************************************************************************
15  !  Changes, Bernd C. Krueger, Feb. 2001:                                     *
16  !        Call of convmix when new windfield is read                          *
17  !------------------------------------                                        *
18  !  Changes Petra Seibert, Sept 2002                                          *
19  !     fix wet scavenging problem                                             *
20  !     Code may not be correct for decay of deposition!                       *
21  !  Changes Petra Seibert, Nov 2002                                           *
22  !     call convection BEFORE new fields are read in BWD mode                 *
23  !  Changes Caroline Forster, Feb 2005                                        *
24  !   new interface between flexpart and convection scheme                     *
25  !   Emanuel's latest subroutine convect43c.f is used                         *
26  !  Changes Stefan Henne, Harald Sodemann, 2013-2014                          *
27  !   added netcdf output code                                                 *
28  !  Changes Espen Sollum 2014                                                 *
29  !   For compatibility with MPI version,                                      *
30  !   variables uap,ucp,uzp,us,vs,ws,cbt now in module com_mod                 *
31  !  Unified ECMWF and GFS builds                                              *
32  !   Marian Harustak, 12.5.2017                                               *
33  !   - Added passing of metdata_format as it was needed by called routines    *
34  !*****************************************************************************
35  !                                                                            *
36  ! Variables:                                                                 *
37  ! DEP                .true. if either wet or dry deposition is switched on   *
38  ! decay(maxspec) [1/s] decay constant for radioactive decay                  *
39  ! DRYDEP             .true. if dry deposition is switched on                 *
40  ! ideltas [s]        modelling period                                        *
41  ! itime [s]          actual temporal position of calculation                 *
42  ! ldeltat [s]        time since computation of radioact. decay of depositions*
43  ! loutaver [s]       averaging period for concentration calculations         *
44  ! loutend [s]        end of averaging for concentration calculations         *
45  ! loutnext [s]       next time at which output fields shall be centered      *
46  ! loutsample [s]     sampling interval for averaging of concentrations       *
47  ! loutstart [s]      start of averaging for concentration calculations       *
48  ! loutstep [s]       time interval for which concentrations shall be         *
49  !                    calculated                                              *
50  ! npoint(maxpart)    index, which starting point the trajectory has          *
51  !                    starting positions of trajectories                      *
52  ! nstop              serves as indicator for fate of particles               *
53  !                    in the particle loop                                    *
54  ! nstop1             serves as indicator for wind fields (see getfields)     *
55  ! outnum             number of samples for each concentration calculation    *
56  ! outnum             number of samples for each concentration calculation    *
57  ! prob               probability of absorption at ground due to dry          *
58  !                    deposition                                              *
59  ! WETDEP             .true. if wet deposition is switched on                 *
60  ! weight             weight for each concentration sample (1/2 or 1)         *
61  ! uap(maxpart),ucp(maxpart),uzp(maxpart) = random velocities due to          *
62  !                    turbulence                                              *
63  ! us(maxpart),vs(maxpart),ws(maxpart) = random velocities due to inter-      *
64  !                    polation                                                *
65  ! xtra1(maxpart), ytra1(maxpart), ztra1(maxpart) =                           *
66  !                    spatial positions of trajectories                       *
67  ! metdata_format     format of metdata (ecmwf/gfs)                           *
68  !                                                                            *
69  ! Constants:                                                                 *
70  ! maxpart            maximum number of trajectories                          *
71  !                                                                            *
72  !*****************************************************************************
73
74  use unc_mod
75  use point_mod
76  use xmass_mod
77  use flux_mod
78  use outg_mod
79  use oh_mod
80  use par_mod
81  use com_mod
82#ifdef USE_NCF
83  use netcdf_output_mod, only: concoutput_netcdf,concoutput_nest_netcdf,&
84       &concoutput_surf_netcdf,concoutput_surf_nest_netcdf
85#endif
86
87  implicit none
88
89  integer :: metdata_format
90  integer :: j,ks,kp,l,n,itime=0,nstop,nstop1
91! integer :: ksp
92  integer :: loutnext,loutstart,loutend
93  integer :: ix,jy,ldeltat,itage,nage,idummy
94  integer :: i_nan=0,ii_nan,total_nan_intl=0  !added by mc to check instability in CBL scheme
95  real :: outnum,weight,prob_rec(maxspec),prob(maxspec),decfact,wetscav
96  ! real :: uap(maxpart),ucp(maxpart),uzp(maxpart)
97  ! real :: us(maxpart),vs(maxpart),ws(maxpart)
98  ! integer(kind=2) :: cbt(maxpart)
99  real(sp) :: gridtotalunc
100  real(dep_prec) :: drydeposit(maxspec),wetgridtotalunc,drygridtotalunc
101  real :: xold,yold,zold,xmassfract
102  real :: grfraction(3)
103  real, parameter :: e_inv = 1.0/exp(1.0)
104
105  !double precision xm(maxspec,maxpointspec_act),
106  !    +                 xm_depw(maxspec,maxpointspec_act),
107  !    +                 xm_depd(maxspec,maxpointspec_act)
108
109
110  !open(88,file='TEST.dat')
111
112  ! First output for time 0
113  !************************
114
115  loutnext=loutstep/2
116  outnum=0.
117  loutstart=loutnext-loutaver/2
118  loutend=loutnext+loutaver/2
119
120  !  open(127,file=path(2)(1:length(2))//'depostat.dat'
121  !    +  ,form='unformatted')
122  !write (*,*) 'writing deposition statistics depostat.dat!'
123
124  !**********************************************************************
125  ! Loop over the whole modelling period in time steps of mintime seconds
126  !**********************************************************************
127
128!ZHG 2015
129!CGZ-lifetime: set lifetime to 0
130  ! checklifetime(:,:)=0
131  ! species_lifetime(:,:)=0
132  ! print*, 'Initialized lifetime'
133!CGZ-lifetime: set lifetime to 0
134 
135  if (.not.lusekerneloutput) write(*,*) 'Not using the kernel'
136  if (turboff) write(*,*) 'Turbulence switched off'
137
138  write(*,46) float(itime)/3600,itime,numpart
139
140  if (verbosity.gt.0) then
141    write (*,*) 'timemanager> starting simulation'
142    if (verbosity.gt.1) then
143      CALL SYSTEM_CLOCK(count_clock)
144      WRITE(*,*) 'timemanager> SYSTEM CLOCK',(count_clock - count_clock0)/real(count_rate)
145    endif     
146  endif
147
148  do itime=0,ideltas,lsynctime
149
150  ! Computation of wet deposition, OH reaction and mass transfer
151  ! between two species every lsynctime seconds
152  ! maybe wet depo frequency can be relaxed later but better be on safe side
153  ! wetdepo must be called BEFORE new fields are read in but should not
154  ! be called in the very beginning before any fields are loaded, or
155  ! before particles are in the system
156  ! Code may not be correct for decay of deposition
157  ! changed by Petra Seibert 9/02
158  !********************************************************************
159
160    if (WETDEP .and. itime .ne. 0 .and. numpart .gt. 0) then
161        if (verbosity.gt.0) then
162           write (*,*) 'timemanager> call wetdepo'
163        endif     
164         call wetdepo(itime,lsynctime,loutnext)
165    endif
166
167    if (OHREA .and. itime .ne. 0 .and. numpart .gt. 0) &
168         call ohreaction(itime,lsynctime,loutnext)
169
170    if (ASSSPEC .and. itime .ne. 0 .and. numpart .gt. 0) then
171       stop 'associated species not yet implemented!'
172  !     call transferspec(itime,lsynctime,loutnext)
173    endif
174
175  ! compute convection for backward runs
176  !*************************************
177
178   if ((ldirect.eq.-1).and.(lconvection.eq.1).and.(itime.lt.0)) then
179        if (verbosity.gt.0) then
180           write (*,*) 'timemanager> call convmix -- backward'
181        endif         
182      call convmix(itime,metdata_format)
183        if (verbosity.gt.1) then
184          !CALL SYSTEM_CLOCK(count_clock, count_rate, count_max)
185          CALL SYSTEM_CLOCK(count_clock)
186          WRITE(*,*) 'timemanager> SYSTEM CLOCK',(count_clock - count_clock0)/real(count_rate)
187        endif
188   endif
189
190  ! Get necessary wind fields if not available
191  !*******************************************
192    if (verbosity.gt.0) then
193           write (*,*) 'timemanager> call getfields'
194    endif
195    call getfields(itime,nstop1,metdata_format)
196        if (verbosity.gt.1) then
197          CALL SYSTEM_CLOCK(count_clock)
198          WRITE(*,*) 'timemanager> SYSTEM CLOCK',(count_clock - count_clock0)/real(count_rate)
199        endif
200    if (nstop1.gt.1) stop 'NO METEO FIELDS AVAILABLE'
201
202  ! Get hourly OH fields if not available
203  !****************************************************
204    if (OHREA) then
205      if (verbosity.gt.0) then
206             write (*,*) 'timemanager> call gethourlyOH'
207      endif
208      call gethourlyOH(itime)
209          if (verbosity.gt.1) then
210            CALL SYSTEM_CLOCK(count_clock)
211            WRITE(*,*) 'timemanager> SYSTEM CLOCK',(count_clock - count_clock0)/real(count_rate)
212          endif
213    endif
214       
215  ! Release particles
216  !******************
217
218    if (verbosity.gt.0) then
219           write (*,*) 'timemanager>  Release particles'
220    endif
221
222    if (mdomainfill.ge.1) then
223      if (itime.eq.0) then
224        if (verbosity.gt.0) then
225          write (*,*) 'timemanager>  call init_domainfill'
226        endif       
227        call init_domainfill
228      else
229        if (verbosity.gt.0) then
230          write (*,*) 'timemanager>  call boundcond_domainfill'
231        endif   
232        call boundcond_domainfill(itime,loutend)
233      endif
234    else
235      if (verbosity.gt.0) then
236        print*,'call releaseparticles' 
237      endif
238      call releaseparticles(itime)
239      if (verbosity.gt.1) then
240        CALL SYSTEM_CLOCK(count_clock)
241        WRITE(*,*) 'timemanager> SYSTEM CLOCK',(count_clock - count_clock0)/real(count_rate)
242      endif
243    endif
244
245
246  ! Compute convective mixing for forward runs
247  ! for backward runs it is done before next windfield is read in
248  !**************************************************************
249
250   if ((ldirect.eq.1).and.(lconvection.eq.1)) then
251     if (verbosity.gt.0) then
252       write (*,*) 'timemanager> call convmix -- forward'
253     endif   
254     call convmix(itime,metdata_format)
255   endif
256
257  ! If middle of averaging period of output fields is reached, accumulated
258  ! deposited mass radioactively decays
259  !***********************************************************************
260
261    if (DEP.and.(itime.eq.loutnext).and.(ldirect.gt.0)) then
262      do ks=1,nspec
263      do kp=1,maxpointspec_act
264        if (decay(ks).gt.0.) then
265          do nage=1,nageclass
266            do l=1,nclassunc
267  ! Mother output grid
268              do jy=0,numygrid-1
269                do ix=0,numxgrid-1
270                  wetgridunc(ix,jy,ks,kp,l,nage)= &
271                       wetgridunc(ix,jy,ks,kp,l,nage)* &
272                       exp(-1.*outstep*decay(ks))
273                  drygridunc(ix,jy,ks,kp,l,nage)= &
274                       drygridunc(ix,jy,ks,kp,l,nage)* &
275                       exp(-1.*outstep*decay(ks))
276                end do
277              end do
278  ! Nested output grid
279              if (nested_output.eq.1) then
280                do jy=0,numygridn-1
281                  do ix=0,numxgridn-1
282                    wetgriduncn(ix,jy,ks,kp,l,nage)= &
283                         wetgriduncn(ix,jy,ks,kp,l,nage)* &
284                         exp(-1.*outstep*decay(ks))
285                    drygriduncn(ix,jy,ks,kp,l,nage)= &
286                         drygriduncn(ix,jy,ks,kp,l,nage)* &
287                         exp(-1.*outstep*decay(ks))
288                  end do
289                end do
290              endif
291            end do
292          end do
293        endif
294      end do
295      end do
296    endif
297
298  !!! CHANGE: These lines may be switched on to check the conservation
299  !!! of mass within FLEXPART
300  !   if (itime.eq.loutnext) then
301  !   do 247 ksp=1, nspec
302  !   do 247 kp=1, maxpointspec_act
303  !47         xm(ksp,kp)=0.
304
305  !   do 249 ksp=1, nspec
306  !     do 249 j=1,numpart
307  !          if (ioutputforeachrelease.eq.1) then
308  !            kp=npoint(j)
309  !          else
310  !            kp=1
311  !          endif
312  !       if (itra1(j).eq.itime) then
313  !          xm(ksp,kp)=xm(ksp,kp)+xmass1(j,ksp)
314  !         write(*,*) 'xmass: ',xmass1(j,ksp),j,ksp,nspec
315  !       endif
316  !49     continue
317  !  do 248 ksp=1,nspec
318  !  do 248 kp=1,maxpointspec_act
319  !  xm_depw(ksp,kp)=0.
320  !  xm_depd(ksp,kp)=0.
321  !     do 248 nage=1,nageclass
322  !       do 248 ix=0,numxgrid-1
323  !         do 248 jy=0,numygrid-1
324  !           do 248 l=1,nclassunc
325  !              xm_depw(ksp,kp)=xm_depw(ksp,kp)
326  !    +                  +wetgridunc(ix,jy,ksp,kp,l,nage)
327  !48                 xm_depd(ksp,kp)=xm_depd(ksp,kp)
328  !    +                  +drygridunc(ix,jy,ksp,kp,l,nage)
329  !             do 246 ksp=1,nspec
330  !46                    write(88,'(2i10,3e12.3)')
331  !    +              itime,ksp,(xm(ksp,kp),kp=1,maxpointspec_act),
332  !    +                (xm_depw(ksp,kp),kp=1,maxpointspec_act),
333  !    +                (xm_depd(ksp,kp),kp=1,maxpointspec_act)
334  !  endif
335  !!! CHANGE
336
337
338
339  ! Check whether concentrations are to be calculated
340  !**************************************************
341
342    if ((ldirect*itime.ge.ldirect*loutstart).and. &
343         (ldirect*itime.le.ldirect*loutend)) then ! add to grid
344      if (mod(itime-loutstart,loutsample).eq.0) then
345
346  ! If we are exactly at the start or end of the concentration averaging interval,
347  ! give only half the weight to this sample
348  !*****************************************************************************
349
350        if ((itime.eq.loutstart).or.(itime.eq.loutend)) then
351          weight=0.5
352        else
353          weight=1.0
354        endif
355        outnum=outnum+weight
356        call conccalc(itime,weight)
357      endif
358
359
360      if ((mquasilag.eq.1).and.(itime.eq.(loutstart+loutend)/2)) &
361           call partoutput_short(itime)    ! dump particle positions in extremely compressed format
362
363
364  ! Output and reinitialization of grid
365  ! If necessary, first sample of new grid is also taken
366  !*****************************************************
367
368      if ((itime.eq.loutend).and.(outnum.gt.0.)) then
369        if ((iout.le.3.).or.(iout.eq.5)) then
370          if (surf_only.ne.1) then
371            if (lnetcdfout.eq.1) then
372#ifdef USE_NCF
373              call concoutput_netcdf(itime,outnum,gridtotalunc,wetgridtotalunc,drygridtotalunc)
374#endif
375            else
376              call concoutput(itime,outnum,gridtotalunc,wetgridtotalunc,drygridtotalunc)
377            endif
378          else 
379            if (verbosity.eq.1) then
380             print*,'call concoutput_surf '
381             call system_clock(count_clock)
382             write(*,*) 'system clock',count_clock - count_clock0   
383            endif
384            if (lnetcdfout.eq.1) then
385#ifdef USE_NCF
386              call concoutput_surf_netcdf(itime,outnum,gridtotalunc,wetgridtotalunc,drygridtotalunc)
387#endif
388            else
389              if (linversionout.eq.1) then
390                call concoutput_inversion(itime,outnum,gridtotalunc,wetgridtotalunc,drygridtotalunc)
391                if (verbosity.eq.1) then
392                  print*,'called concoutput_inversion'
393                  call system_clock(count_clock)
394                  write(*,*) 'system clock',count_clock - count_clock0
395                endif
396              else
397              call concoutput_surf(itime,outnum,gridtotalunc,wetgridtotalunc,drygridtotalunc)
398              endif
399              if (verbosity.eq.1) then
400                print*,'called concoutput_surf '
401                call system_clock(count_clock)
402                write(*,*) 'system clock',count_clock - count_clock0   
403              endif
404            endif
405          endif
406
407          if (nested_output .eq. 1) then
408            if (lnetcdfout.eq.0) then
409              if (surf_only.ne.1) then
410                call concoutput_nest(itime,outnum)
411              else
412                if(linversionout.eq.1) then
413                  call concoutput_inversion_nest(itime,outnum)
414                else
415                call concoutput_surf_nest(itime,outnum)
416              endif
417              endif
418            else
419#ifdef USE_NCF
420              if (surf_only.ne.1) then
421                call concoutput_nest_netcdf(itime,outnum)
422              else
423                call concoutput_surf_nest_netcdf(itime,outnum)
424              endif
425#endif
426            endif
427          endif
428          outnum=0.
429        endif
430        if ((iout.eq.4).or.(iout.eq.5)) call plumetraj(itime)
431        if (iflux.eq.1) call fluxoutput(itime)
432        write(*,45) itime,numpart,gridtotalunc,wetgridtotalunc,drygridtotalunc
433 
434        !CGZ-lifetime: output species lifetime
435!ZHG
436        ! write(*,*) 'Overview species lifetime in days', &
437        !      real((species_lifetime(:,1)/species_lifetime(:,2))/real(3600.0*24.0))
438        ! write(*,*) 'all info:',species_lifetime
439!ZHG
440        !CGZ-lifetime: output species lifetime
441
442        !write(*,46) float(itime)/3600,itime,numpart
44345      format(i13,' Seconds simulated: ',i13, ' Particles:    Uncertainty: ',3f7.3)
44446      format(' Simulated ',f7.1,' hours (',i13,' s), ',i13, ' particles')
445        if (ipout.ge.1) then
446          if (mod(itime,ipoutfac*loutstep).eq.0) call partoutput(itime) ! dump particle positions
447          if (ipout.eq.3) call partoutput_average(itime) ! dump particle positions
448        endif
449        loutnext=loutnext+loutstep
450        loutstart=loutnext-loutaver/2
451        loutend=loutnext+loutaver/2
452        if (itime.eq.loutstart) then
453          weight=0.5
454          outnum=outnum+weight
455          call conccalc(itime,weight)
456        endif
457
458
459  ! Check, whether particles are to be split:
460  ! If so, create new particles and attribute all information from the old
461  ! particles also to the new ones; old and new particles both get half the
462  ! mass of the old ones
463  !************************************************************************
464
465        if (ldirect*itime.ge.ldirect*itsplit) then
466          n=numpart
467          do j=1,numpart
468            if (ldirect*itime.ge.ldirect*itrasplit(j)) then
469              if (n.lt.maxpart) then
470                n=n+1
471                itrasplit(j)=2*(itrasplit(j)-itramem(j))+itramem(j)
472                itrasplit(n)=itrasplit(j)
473                itramem(n)=itramem(j)
474                itra1(n)=itra1(j)
475                idt(n)=idt(j)
476                npoint(n)=npoint(j)
477                nclass(n)=nclass(j)
478                xtra1(n)=xtra1(j)
479                ytra1(n)=ytra1(j)
480                ztra1(n)=ztra1(j)
481                uap(n)=uap(j)
482                ucp(n)=ucp(j)
483                uzp(n)=uzp(j)
484                us(n)=us(j)
485                vs(n)=vs(j)
486                ws(n)=ws(j)
487                cbt(n)=cbt(j)
488                do ks=1,nspec
489                  xmass1(j,ks)=xmass1(j,ks)/2.
490                  xmass1(n,ks)=xmass1(j,ks)
491                end do
492              endif
493            endif
494          end do
495          numpart=n
496        endif
497      endif
498    endif
499
500
501    if (itime.eq.ideltas) exit         ! almost finished
502
503  ! Compute interval since radioactive decay of deposited mass was computed
504  !************************************************************************
505
506    if (itime.lt.loutnext) then
507      ldeltat=itime-(loutnext-loutstep)
508    else                                  ! first half of next interval
509      ldeltat=itime-loutnext
510    endif
511
512
513  ! Loop over all particles
514  !************************
515  ! Various variables for testing reason of CBL scheme, by mc
516    well_mixed_vector=0. !erase vector to test well mixed condition: modified by mc
517    well_mixed_norm=0.   !erase normalization to test well mixed condition: modified by mc
518    avg_ol=0.
519    avg_wst=0.
520    avg_h=0.
521    avg_air_dens=0.  !erase vector to obtain air density at particle positions: modified by mc
522  !-----------------------------------------------------------------------------
523    do j=1,numpart
524
525
526  ! If integration step is due, do it
527  !**********************************
528
529      if (itra1(j).eq.itime) then
530
531        if (ioutputforeachrelease.eq.1) then
532            kp=npoint(j)
533        else
534            kp=1
535        endif
536  ! Determine age class of the particle
537        itage=abs(itra1(j)-itramem(j))
538        do nage=1,nageclass
539          if (itage.lt.lage(nage)) exit
540        end do
541
542  ! Initialize newly released particle
543  !***********************************
544
545        if ((itramem(j).eq.itime).or.(itime.eq.0)) &
546             call initialize(itime,idt(j),uap(j),ucp(j),uzp(j), &
547             us(j),vs(j),ws(j),xtra1(j),ytra1(j),ztra1(j),cbt(j))
548
549  ! Memorize particle positions
550  !****************************
551
552        xold=xtra1(j)
553        yold=ytra1(j)
554        zold=ztra1(j)
555
556   
557  ! RECEPTOR: dry/wet depovel
558  !****************************
559  ! Before the particle is moved
560  ! the calculation of the scavenged mass shall only be done once after release
561  ! xscav_frac1 was initialised with a negative value
562
563      if  (DRYBKDEP) then
564       do ks=1,nspec
565         if  ((xscav_frac1(j,ks).lt.0)) then
566            call get_vdep_prob(itime,xtra1(j),ytra1(j),ztra1(j),prob_rec)
567            if (DRYDEPSPEC(ks)) then        ! dry deposition
568               xscav_frac1(j,ks)=prob_rec(ks)
569             else
570                xmass1(j,ks)=0.
571                xscav_frac1(j,ks)=0.
572             endif
573         endif
574        enddo
575       endif
576
577       if (WETBKDEP) then
578       do ks=1,nspec
579         if  ((xscav_frac1(j,ks).lt.0)) then
580            call get_wetscav(itime,lsynctime,loutnext,j,ks,grfraction,idummy,idummy,wetscav)
581            if (wetscav.gt.0) then
582                xscav_frac1(j,ks)=wetscav* &
583                       (zpoint2(npoint(j))-zpoint1(npoint(j)))*grfraction(1)
584            else
585                xmass1(j,ks)=0.
586                xscav_frac1(j,ks)=0.
587            endif
588         endif
589        enddo
590       endif
591
592  ! Integrate Lagevin equation for lsynctime seconds
593  !*************************************************
594
595        if (verbosity.gt.0) then
596           if (j.eq.1) then
597             write (*,*) 'timemanager> call advance'
598           endif     
599        endif
600     
601        call advance(itime,npoint(j),idt(j),uap(j),ucp(j),uzp(j), &
602             us(j),vs(j),ws(j),nstop,xtra1(j),ytra1(j),ztra1(j),prob, &
603             cbt(j))
604!        write (*,*) 'advance: ',prob(1),xmass1(j,1),ztra1(j)
605
606  ! Calculate average position for particle dump output
607  !****************************************************
608
609        if (ipout.eq.3) call partpos_average(itime,j)
610
611
612  ! Calculate the gross fluxes across layer interfaces
613  !***************************************************
614
615        if (iflux.eq.1) call calcfluxes(nage,j,xold,yold,zold)
616
617
618  ! Determine, when next time step is due
619  ! If trajectory is terminated, mark it
620  !**************************************
621
622        if (nstop.gt.1) then
623          if (linit_cond.ge.1) call initial_cond_calc(itime,j)
624          itra1(j)=-999999999
625        else
626          itra1(j)=itime+lsynctime
627
628
629  ! Dry deposition and radioactive decay for each species
630  ! Also check maximum (of all species) of initial mass remaining on the particle;
631  ! if it is below a threshold value, terminate particle
632  !*****************************************************************************
633
634          xmassfract=0.
635          do ks=1,nspec
636            if (decay(ks).gt.0.) then             ! radioactive decay
637              decfact=exp(-real(abs(lsynctime))*decay(ks))
638            else
639              decfact=1.
640            endif
641
642            if (DRYDEPSPEC(ks)) then        ! dry deposition
643              drydeposit(ks)=xmass1(j,ks)*prob(ks)*decfact
644              xmass1(j,ks)=xmass1(j,ks)*(1.-prob(ks))*decfact
645              if (decay(ks).gt.0.) then   ! correct for decay (see wetdepo)
646                drydeposit(ks)=drydeposit(ks)* &
647                     exp(real(abs(ldeltat))*decay(ks))
648              endif
649            else                           ! no dry deposition
650              xmass1(j,ks)=xmass1(j,ks)*decfact
651            endif
652
653! Skip check on mass fraction when npoint represents particle number
654            if (mdomainfill.eq.0.and.mquasilag.eq.0) then
655              if (xmass(npoint(j),ks).gt.0.) &
656                   xmassfract=max(xmassfract,real(npart(npoint(j)))* &
657                   xmass1(j,ks)/xmass(npoint(j),ks))
658!ZHG 2015
659                  !CGZ-lifetime: Check mass fraction left/save lifetime
660                   ! if(real(npart(npoint(j)))*xmass1(j,ks)/xmass(npoint(j),ks).lt.e_inv.and.checklifetime(j,ks).eq.0.)then
661                       !Mass below 1% of initial >register lifetime
662                       ! checklifetime(j,ks)=abs(itra1(j)-itramem(j))
663                       ! species_lifetime(ks,1)=species_lifetime(ks,1)+abs(itra1(j)-itramem(j))
664                       ! species_lifetime(ks,2)= species_lifetime(ks,2)+1
665                   ! endif
666                   !CGZ-lifetime: Check mass fraction left/save lifetime
667!ZHG 2015
668            else
669              xmassfract=1.0
670            end if
671          end do
672
673          if (xmassfract.lt.minmass) then   ! terminate all particles carrying less mass
674            itra1(j)=-999999999
675            if (verbosity.gt.0) then
676              print*,'terminated particle ',j,' for small mass'
677            endif
678          endif
679
680  !        Sabine Eckhardt, June 2008
681  !        don't create depofield for backward runs
682          if (DRYDEP.AND.(ldirect.eq.1)) then
683            call drydepokernel(nclass(j),drydeposit,real(xtra1(j)), &
684                 real(ytra1(j)),nage,kp)
685            if (nested_output.eq.1) call drydepokernel_nest( &
686                 nclass(j),drydeposit,real(xtra1(j)),real(ytra1(j)), &
687                 nage,kp)
688          endif
689
690  ! Terminate trajectories that are older than maximum allowed age
691  !***************************************************************
692
693          if (abs(itra1(j)-itramem(j)).ge.lage(nageclass)) then
694            if (linit_cond.ge.1) call initial_cond_calc(itime+lsynctime,j)
695            itra1(j)=-999999999
696            if (verbosity.gt.0) then
697              print*,'terminated particle ',j,' for age'
698            endif
699          endif
700        endif
701
702      endif
703
704    end do !loop over particles
705   
706  ! Counter of "unstable" particle velocity during a time scale of
707  ! maximumtl=20 minutes (defined in com_mod)
708  !***************************************************************
709   
710    total_nan_intl=0
711    i_nan=i_nan+1 ! added by mc to count nan during a time of maxtl (i.e. maximum tl fixed here to 20 minutes, see com_mod)
712    sum_nan_count(i_nan)=nan_count
713    if (i_nan > maxtl/lsynctime) i_nan=1 !lsynctime must be <= maxtl
714    do ii_nan=1, (maxtl/lsynctime)
715      total_nan_intl=total_nan_intl+sum_nan_count(ii_nan)
716    end do
717  ! Output to keep track of the numerical instabilities in CBL simulation and if
718  ! they are compromising the final result (or not)
719    if (cblflag.eq.1) print *,j,itime,'nan_synctime',nan_count,'nan_tl',total_nan_intl 
720         
721  end do
722
723
724  ! Complete the calculation of initial conditions for particles not yet terminated
725  !*****************************************************************************
726
727  do j=1,numpart
728    if (linit_cond.ge.1) call initial_cond_calc(itime,j)
729  end do
730
731  if (ipout.eq.2) call partoutput(itime)     ! dump particle positions
732
733  if (linit_cond.ge.1) then
734    if(linversionout.eq.1) then
735      call initial_cond_output_inversion(itime)   ! dump initial cond. field
736    else
737      call initial_cond_output(itime)   ! dump initial cond. fielf
738    endif
739  endif
740
741  !close(104)
742
743  ! De-allocate memory and end
744  !***************************
745
746  if (iflux.eq.1) then
747      deallocate(flux)
748  endif
749  if (OHREA) then
750      deallocate(OH_field,OH_hourly,lonOH,latOH,altOH)
751  endif
752  if (ldirect.gt.0) then
753  deallocate(drygridunc,wetgridunc)
754  endif
755  deallocate(gridunc)
756  deallocate(xpoint1,xpoint2,ypoint1,ypoint2,zpoint1,zpoint2,xmass)
757  deallocate(ireleasestart,ireleaseend,npart,kindz)
758  deallocate(xmasssave)
759  if (nested_output.eq.1) then
760     deallocate(orooutn, arean, volumen)
761     if (ldirect.gt.0) then
762     deallocate(griduncn,drygriduncn,wetgriduncn)
763     endif
764  endif
765  deallocate(outheight,outheighthalf)
766  deallocate(oroout, area, volume)
767
768end subroutine timemanager
769
Note: See TracBrowser for help on using the repository browser.
hosted by ZAMG