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