source: flexpart.git/src/timemanager.f90 @ fddc6ec

10.4.1_peseiGFS_025bugfixes+enhancementsdevrelease-10release-10.4.1scaling-bugunivie
Last change on this file since fddc6ec was fdc0f03, checked in by Espen Sollum ATMOS <eso@…>, 8 years ago

Code for cloud water should be correct if the total cw is stored in field clwc (old scheme) or in field qc (new scheme). Minor edits in some files.

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