source: flexpart.git/src/timemanager.f90

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

add SPDX-License-Identifier to all .f90 files

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