source: palm/trunk/SOURCE/lpm_init.f90 @ 3259

Last change on this file since 3259 was 3241, checked in by raasch, 6 years ago

various changes to avoid compiler warnings (mainly removal of unused variables)

  • Property svn:keywords set to Id
File size: 47.5 KB
Line 
1!> @file lpm_init.f90
2!------------------------------------------------------------------------------!
3! This file is part of the PALM model system.
4!
5! PALM is free software: you can redistribute it and/or modify it under the
6! terms of the GNU General Public License as published by the Free Software
7! Foundation, either version 3 of the License, or (at your option) any later
8! version.
9!
10! PALM is distributed in the hope that it will be useful, but WITHOUT ANY
11! WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12! A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
13!
14! You should have received a copy of the GNU General Public License along with
15! PALM. If not, see <http://www.gnu.org/licenses/>.
16!
17! Copyright 1997-2018 Leibniz Universitaet Hannover
18!------------------------------------------------------------------------------!
19!
20! Current revisions:
21! -----------------
22!
23!
24! Former revisions:
25! -----------------
26! $Id: lpm_init.f90 3241 2018-09-12 15:02:00Z sward $
27! unused variables removed
28!
29! 3065 2018-06-12 07:03:02Z Giersch
30! dz was replaced by dzw or dz(1) to allow for right vertical stretching
31!
32! 3049 2018-05-29 13:52:36Z Giersch
33! Error messages revised
34!
35! 3045 2018-05-28 07:55:41Z Giersch
36! Error message revised
37!
38! 3039 2018-05-24 13:13:11Z schwenkel
39! bugfix for lcm with grid stretching
40!
41! 2967 2018-04-13 11:22:08Z raasch
42! nesting routine is only called if nesting is switched on
43!
44! 2954 2018-04-09 14:35:46Z schwenkel
45! Bugfix for particle initialization in case of ocean
46!
47! 2801 2018-02-14 16:01:55Z thiele
48! Introduce particle transfer in nested models.
49!
50! 2718 2018-01-02 08:49:38Z maronga
51! Corrected "Former revisions" section
52!
53! 2701 2017-12-15 15:40:50Z suehring
54! Changes from last commit documented
55!
56! 2698 2017-12-14 18:46:24Z suehring
57! Grid indices passed to lpm_boundary_conds. (responsible Philipp Thiele)
58!
59! 2696 2017-12-14 17:12:51Z kanani
60! Change in file header (GPL part)
61!
62! 2628 2017-11-20 12:40:38Z schwenkel
63! Enabled particle advection with grid stretching.
64!
65! 2608 2017-11-13 14:04:26Z schwenkel
66! Calculation of magnus equation in external module (diagnostic_quantities_mod).
67!
68! 2606 2017-11-10 10:36:31Z schwenkel
69! Changed particle box locations: center of particle box now coincides
70! with scalar grid point of same index.
71! Renamed module and subroutines: lpm_pack_arrays_mod -> lpm_pack_and_sort_mod
72! lpm_pack_all_arrays -> lpm_sort_in_subboxes, lpm_pack_arrays -> lpm_pack
73! lpm_sort -> lpm_sort_timeloop_done
74!
75! 2375 2017-08-29 14:10:28Z schwenkel
76! Initialization of chemical aerosol composition
77!
78! 2346 2017-08-09 16:39:17Z suehring
79! Bugfix, correct determination of topography top index
80!
81! 2318 2017-07-20 17:27:44Z suehring
82! Get topography top index via Function call
83!
84! 2317 2017-07-20 17:27:19Z suehring
85! Extended particle data type. Aerosol initialization improved.
86!
87! 2305 2017-07-06 11:18:47Z hoffmann
88! Improved calculation of particle IDs.
89!
90! 2274 2017-06-09 13:27:48Z Giersch
91!  Changed error messages
92!
93! 2265 2017-06-08 16:58:28Z schwenkel
94! Unused variables removed.
95!
96! 2263 2017-06-08 14:59:01Z schwenkel
97! Implemented splitting and merging algorithm
98!
99! 2233 2017-05-30 18:08:54Z suehring
100!
101! 2232 2017-05-30 17:47:52Z suehring
102! Adjustments according to new topography realization
103!
104!
105! 2223 2017-05-15 16:38:09Z suehring
106! Add check for particle release at model top
107!
108! 2182 2017-03-17 14:27:40Z schwenkel
109! Added parameters for simplified particle initialization.
110!
111! 2122 2017-01-18 12:22:54Z hoffmann
112! Improved initialization of equilibrium aerosol radii
113! Calculation of particle ID
114!
115! 2000 2016-08-20 18:09:15Z knoop
116! Forced header and separation lines into 80 columns
117!
118! 2016-06-09 16:25:25Z suehring
119! Bugfix in determining initial particle height and grid index in case of
120! seed_follows_topography.
121! Bugfix concerning random positions, ensure that particles do not move more
122! than one grid length.
123! Bugfix logarithmic interpolation.
124! Initial setting of sgs_wf_part.
125!
126! 1890 2016-04-22 08:52:11Z hoffmann
127! Initialization of aerosol equilibrium radius not possible in supersaturated
128! environments. Therefore, a maximum supersaturation of -1 % is assumed during
129! initialization.
130!
131! 1873 2016-04-18 14:50:06Z maronga
132! Module renamed (removed _mod
133!
134! 1871 2016-04-15 11:46:09Z hoffmann
135! Initialization of aerosols added.
136!
137! 1850 2016-04-08 13:29:27Z maronga
138! Module renamed
139!
140! 1831 2016-04-07 13:15:51Z hoffmann
141! curvature_solution_effects moved to particle_attributes
142!
143! 1822 2016-04-07 07:49:42Z hoffmann
144! Unused variables removed.
145!
146! 1783 2016-03-06 18:36:17Z raasch
147! netcdf module added
148!
149! 1725 2015-11-17 13:01:51Z hoffmann
150! Bugfix: Processor-dependent seed for random function is generated before it is
151! used.
152!
153! 1691 2015-10-26 16:17:44Z maronga
154! Renamed prandtl_layer to constant_flux_layer.
155!
156! 1685 2015-10-08 07:32:13Z raasch
157! bugfix concerning vertical index offset in case of ocean
158!
159! 1682 2015-10-07 23:56:08Z knoop
160! Code annotations made doxygen readable
161!
162! 1575 2015-03-27 09:56:27Z raasch
163! initial vertical particle position is allowed to follow the topography
164!
165! 1359 2014-04-11 17:15:14Z hoffmann
166! New particle structure integrated.
167! Kind definition added to all floating point numbers.
168! lpm_init changed form a subroutine to a module.
169!
170! 1327 2014-03-21 11:00:16Z raasch
171! -netcdf_output
172!
173! 1322 2014-03-20 16:38:49Z raasch
174! REAL functions provided with KIND-attribute
175!
176! 1320 2014-03-20 08:40:49Z raasch
177! ONLY-attribute added to USE-statements,
178! kind-parameters added to all INTEGER and REAL declaration statements,
179! kinds are defined in new module kinds,
180! revision history before 2012 removed,
181! comment fields (!:) to be used for variable explanations added to
182! all variable declaration statements
183! bugfix: #if defined( __parallel ) added
184!
185! 1314 2014-03-14 18:25:17Z suehring
186! Vertical logarithmic interpolation of horizontal particle speed for particles
187! between roughness height and first vertical grid level.
188!
189! 1092 2013-02-02 11:24:22Z raasch
190! unused variables removed
191!
192! 1036 2012-10-22 13:43:42Z raasch
193! code put under GPL (PALM 3.9)
194!
195! 849 2012-03-15 10:35:09Z raasch
196! routine renamed: init_particles -> lpm_init
197! de_dx, de_dy, de_dz are allocated here (instead of automatic arrays in
198! advec_particles),
199! sort_particles renamed lpm_sort_arrays, user_init_particles renamed lpm_init
200!
201! 828 2012-02-21 12:00:36Z raasch
202! call of init_kernels, particle feature color renamed class
203!
204! 824 2012-02-17 09:09:57Z raasch
205! particle attributes speed_x|y|z_sgs renamed rvar1|2|3,
206! array particles implemented as pointer
207!
208! 667 2010-12-23 12:06:00Z suehring/gryschka
209! nxl-1, nxr+1, nys-1, nyn+1 replaced by nxlg, nxrg, nysg, nyng for allocation
210! of arrays.
211!
212! Revision 1.1  1999/11/25 16:22:38  raasch
213! Initial revision
214!
215!
216! Description:
217! ------------
218!> This routine initializes a set of particles and their attributes (position,
219!> radius, ..) which are used by the Lagrangian particle model (see lpm).
220!------------------------------------------------------------------------------!
221 MODULE lpm_init_mod
222
223    USE, INTRINSIC ::  ISO_C_BINDING
224
225    USE arrays_3d,                                                             &
226        ONLY:  de_dx, de_dy, de_dz, dzw, zu, zw
227
228    USE control_parameters,                                                    &
229        ONLY:  cloud_droplets, constant_flux_layer, current_timestep_number,   &
230               dt_3d, dz, initializing_actions, message_string, ocean,         &
231               simulated_time
232
233    USE grid_variables,                                                        &
234        ONLY:  ddx, dx, ddy, dy
235
236    USE indices,                                                               &
237        ONLY:  nx, nxl, nxlg, nxrg, nxr, ny, nyn, nys, nyng, nysg, nz, nzb,    &
238               nzt, wall_flags_0
239
240    USE kinds
241
242    USE lpm_collision_kernels_mod,                                             &
243        ONLY:  init_kernels
244
245    USE netcdf_interface,                                                      &
246        ONLY:  netcdf_data_format
247
248    USE particle_attributes,                                                   &
249        ONLY:   alloc_factor, bc_par_b, bc_par_lr, bc_par_ns, bc_par_t,        &
250                block_offset, block_offset_def, collision_kernel,              &
251                curvature_solution_effects, density_ratio, grid_particles,     &
252                isf,i_splitting_mode, initial_weighting_factor, ibc_par_b,     &
253                ibc_par_lr, ibc_par_ns, ibc_par_t, iran_part, log_z_z0,        &
254                max_number_of_particle_groups, min_nr_particle,                &
255                number_concentration,                                          &
256                number_particles_per_gridbox,  number_of_particles,            &
257                number_of_particle_groups, number_of_sublayers,                &
258                offset_ocean_nzt, offset_ocean_nzt_m1,                         &
259                particles, particle_advection_start, particle_groups,          &
260                particle_groups_type, particles_per_point,                     &
261                particle_type, pdx, pdy, pdz,  prt_count, psb, psl, psn, psr,  &
262                pss, pst, radius, random_start_position,                       &
263                read_particles_from_restartfile, seed_follows_topography,      &
264                sgs_wf_part, sort_count, splitting_function, splitting_mode,   &
265                total_number_of_particles, use_sgs_for_particles,              &
266                write_particle_statistics, zero_particle, z0_av_global
267
268    USE pegrid
269
270    USE random_function_mod,                                                   &
271        ONLY:  random_function
272
273    USE surface_mod,                                                           &
274        ONLY:  get_topography_top_index_ji, surf_def_h, surf_lsm_h, surf_usm_h
275
276    USE pmc_particle_interface,                                                &
277        ONLY:  pmcp_g_init
278
279    IMPLICIT NONE
280
281    PRIVATE
282
283    INTEGER(iwp), PARAMETER         :: PHASE_INIT    = 1  !<
284    INTEGER(iwp), PARAMETER, PUBLIC :: PHASE_RELEASE = 2  !<
285
286    INTERFACE lpm_init
287       MODULE PROCEDURE lpm_init
288    END INTERFACE lpm_init
289
290    INTERFACE lpm_create_particle
291       MODULE PROCEDURE lpm_create_particle
292    END INTERFACE lpm_create_particle
293
294    PUBLIC lpm_init, lpm_create_particle
295
296 CONTAINS
297
298!------------------------------------------------------------------------------!
299! Description:
300! ------------
301!> @todo Missing subroutine description.
302!------------------------------------------------------------------------------!
303 SUBROUTINE lpm_init
304
305    USE lpm_collision_kernels_mod,                                             &
306        ONLY:  init_kernels
307
308    USE pmc_interface,                                                         &
309        ONLY: nested_run
310
311    IMPLICIT NONE
312
313    INTEGER(iwp) ::  i                           !<
314    INTEGER(iwp) ::  j                           !<
315    INTEGER(iwp) ::  k                           !<
316
317    REAL(wp) ::  div                             !<
318    REAL(wp) ::  height_int                      !<
319    REAL(wp) ::  height_p                        !<
320    REAL(wp) ::  z_p                             !<
321    REAL(wp) ::  z0_av_local                     !<
322
323
324!
325!-- In case of oceans runs, the vertical index calculations need an offset,
326!-- because otherwise the k indices will become negative
327    IF ( ocean )  THEN
328       offset_ocean_nzt    = nzt
329       offset_ocean_nzt_m1 = nzt - 1
330    ENDIF
331
332!
333!-- Define block offsets for dividing a gridcell in 8 sub cells
334!-- See documentation for List of subgrid boxes
335!-- See pack_and_sort in lpm_pack_arrays.f90 for assignment of the subgrid boxes
336    block_offset(0) = block_offset_def ( 0, 0, 0)
337    block_offset(1) = block_offset_def ( 0, 0,-1)
338    block_offset(2) = block_offset_def ( 0,-1, 0)
339    block_offset(3) = block_offset_def ( 0,-1,-1)
340    block_offset(4) = block_offset_def (-1, 0, 0)
341    block_offset(5) = block_offset_def (-1, 0,-1)
342    block_offset(6) = block_offset_def (-1,-1, 0)
343    block_offset(7) = block_offset_def (-1,-1,-1)
344!
345!-- Check the number of particle groups.
346    IF ( number_of_particle_groups > max_number_of_particle_groups )  THEN
347       WRITE( message_string, * ) 'max_number_of_particle_groups =',           &
348                                  max_number_of_particle_groups ,              &
349                                  '&number_of_particle_groups reset to ',      &
350                                  max_number_of_particle_groups
351       CALL message( 'lpm_init', 'PA0213', 0, 1, 0, 6, 0 )
352       number_of_particle_groups = max_number_of_particle_groups
353    ENDIF
354!
355!-- Check if downward-facing walls exist. This case, reflection boundary
356!-- conditions (as well as subgrid-scale velocities) may do not work
357!-- propably (not realized so far).
358    IF ( surf_def_h(1)%ns >= 1 )  THEN
359       WRITE( message_string, * ) 'Overhanging topography do not work '//      &
360                                  'with particles'
361       CALL message( 'lpm_init', 'PA0212', 0, 1, 0, 6, 0 )
362
363    ENDIF
364
365!
366!-- Set default start positions, if necessary
367    IF ( psl(1) == 9999999.9_wp )  psl(1) = 0.0_wp
368    IF ( psr(1) == 9999999.9_wp )  psr(1) = ( nx +1 ) * dx
369    IF ( pss(1) == 9999999.9_wp )  pss(1) = 0.0_wp
370    IF ( psn(1) == 9999999.9_wp )  psn(1) = ( ny +1 ) * dy
371    IF ( psb(1) == 9999999.9_wp )  psb(1) = zu(nz/2)
372    IF ( pst(1) == 9999999.9_wp )  pst(1) = psb(1)
373
374    IF ( pdx(1) == 9999999.9_wp  .OR.  pdx(1) == 0.0_wp )  pdx(1) = dx
375    IF ( pdy(1) == 9999999.9_wp  .OR.  pdy(1) == 0.0_wp )  pdy(1) = dy
376    IF ( pdz(1) == 9999999.9_wp  .OR.  pdz(1) == 0.0_wp )  pdz(1) = zu(2) - zu(1)
377
378!
379!-- If number_particles_per_gridbox is set, the parametres pdx, pdy and pdz are
380!-- calculated diagnostically. Therfore an isotropic distribution is prescribed.
381    IF ( number_particles_per_gridbox /= -1 .AND.   &
382         number_particles_per_gridbox >= 1 )    THEN
383       pdx(1) = (( dx * dy * ( zu(2) - zu(1) ) ) /  &
384             REAL(number_particles_per_gridbox))**0.3333333_wp
385!
386!--    Ensure a smooth value (two significant digits) of distance between
387!--    particles (pdx, pdy, pdz).
388       div = 1000.0_wp
389       DO  WHILE ( pdx(1) < div )
390          div = div / 10.0_wp
391       ENDDO
392       pdx(1) = NINT( pdx(1) * 100.0_wp / div ) * div / 100.0_wp
393       pdy(1) = pdx(1)
394       pdz(1) = pdx(1)
395
396    ENDIF
397
398    DO  j = 2, number_of_particle_groups
399       IF ( psl(j) == 9999999.9_wp )  psl(j) = psl(j-1)
400       IF ( psr(j) == 9999999.9_wp )  psr(j) = psr(j-1)
401       IF ( pss(j) == 9999999.9_wp )  pss(j) = pss(j-1)
402       IF ( psn(j) == 9999999.9_wp )  psn(j) = psn(j-1)
403       IF ( psb(j) == 9999999.9_wp )  psb(j) = psb(j-1)
404       IF ( pst(j) == 9999999.9_wp )  pst(j) = pst(j-1)
405       IF ( pdx(j) == 9999999.9_wp  .OR.  pdx(j) == 0.0_wp )  pdx(j) = pdx(j-1)
406       IF ( pdy(j) == 9999999.9_wp  .OR.  pdy(j) == 0.0_wp )  pdy(j) = pdy(j-1)
407       IF ( pdz(j) == 9999999.9_wp  .OR.  pdz(j) == 0.0_wp )  pdz(j) = pdz(j-1)
408    ENDDO
409
410!
411!-- Allocate arrays required for calculating particle SGS velocities.
412!-- Initialize prefactor required for stoachastic Weil equation.
413    IF ( use_sgs_for_particles  .AND.  .NOT. cloud_droplets )  THEN
414       ALLOCATE( de_dx(nzb:nzt+1,nysg:nyng,nxlg:nxrg), &
415                 de_dy(nzb:nzt+1,nysg:nyng,nxlg:nxrg), &
416                 de_dz(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
417
418       sgs_wf_part = 1.0_wp / 3.0_wp
419    ENDIF
420
421!
422!-- Allocate array required for logarithmic vertical interpolation of
423!-- horizontal particle velocities between the surface and the first vertical
424!-- grid level. In order to avoid repeated CPU cost-intensive CALLS of
425!-- intrinsic FORTRAN procedure LOG(z/z0), LOG(z/z0) is precalculated for
426!-- several heights. Splitting into 20 sublayers turned out to be sufficient.
427!-- To obtain exact height levels of particles, linear interpolation is applied
428!-- (see lpm_advec.f90).
429    IF ( constant_flux_layer )  THEN
430
431       ALLOCATE ( log_z_z0(0:number_of_sublayers) )
432       z_p = zu(nzb+1) - zw(nzb)
433
434!
435!--    Calculate horizontal mean value of z0 used for logartihmic
436!--    interpolation. Note: this is not exact for heterogeneous z0.
437!--    However, sensitivity studies showed that the effect is
438!--    negligible.
439       z0_av_local  = SUM( surf_def_h(0)%z0 ) + SUM( surf_lsm_h%z0 ) +         &
440                      SUM( surf_usm_h%z0 )
441       z0_av_global = 0.0_wp
442
443#if defined( __parallel )
444       CALL MPI_ALLREDUCE(z0_av_local, z0_av_global, 1, MPI_REAL, MPI_SUM, &
445                          comm2d, ierr )
446#else
447       z0_av_global = z0_av_local
448#endif
449
450       z0_av_global = z0_av_global  / ( ( ny + 1 ) * ( nx + 1 ) )
451!
452!--    Horizontal wind speed is zero below and at z0
453       log_z_z0(0) = 0.0_wp
454!
455!--    Calculate vertical depth of the sublayers
456       height_int  = ( z_p - z0_av_global ) / REAL( number_of_sublayers, KIND=wp )
457!
458!--    Precalculate LOG(z/z0)
459       height_p    = z0_av_global
460       DO  k = 1, number_of_sublayers
461
462          height_p    = height_p + height_int
463          log_z_z0(k) = LOG( height_p / z0_av_global )
464
465       ENDDO
466
467    ENDIF
468
469!
470!-- Check boundary condition and set internal variables
471    SELECT CASE ( bc_par_b )
472
473       CASE ( 'absorb' )
474          ibc_par_b = 1
475
476       CASE ( 'reflect' )
477          ibc_par_b = 2
478
479       CASE DEFAULT
480          WRITE( message_string, * )  'unknown boundary condition ',           &
481                                       'bc_par_b = "', TRIM( bc_par_b ), '"'
482          CALL message( 'lpm_init', 'PA0217', 1, 2, 0, 6, 0 )
483
484    END SELECT
485    SELECT CASE ( bc_par_t )
486
487       CASE ( 'absorb' )
488          ibc_par_t = 1
489
490       CASE ( 'reflect' )
491          ibc_par_t = 2
492         
493       CASE ( 'nested' )
494          ibc_par_t = 3
495
496       CASE DEFAULT
497          WRITE( message_string, * ) 'unknown boundary condition ',            &
498                                     'bc_par_t = "', TRIM( bc_par_t ), '"'
499          CALL message( 'lpm_init', 'PA0218', 1, 2, 0, 6, 0 )
500
501    END SELECT
502    SELECT CASE ( bc_par_lr )
503
504       CASE ( 'cyclic' )
505          ibc_par_lr = 0
506
507       CASE ( 'absorb' )
508          ibc_par_lr = 1
509
510       CASE ( 'reflect' )
511          ibc_par_lr = 2
512         
513       CASE ( 'nested' )
514          ibc_par_lr = 3
515
516       CASE DEFAULT
517          WRITE( message_string, * ) 'unknown boundary condition ',   &
518                                     'bc_par_lr = "', TRIM( bc_par_lr ), '"'
519          CALL message( 'lpm_init', 'PA0219', 1, 2, 0, 6, 0 )
520
521    END SELECT
522    SELECT CASE ( bc_par_ns )
523
524       CASE ( 'cyclic' )
525          ibc_par_ns = 0
526
527       CASE ( 'absorb' )
528          ibc_par_ns = 1
529
530       CASE ( 'reflect' )
531          ibc_par_ns = 2
532         
533       CASE ( 'nested' )
534          ibc_par_ns = 3
535
536       CASE DEFAULT
537          WRITE( message_string, * ) 'unknown boundary condition ',   &
538                                     'bc_par_ns = "', TRIM( bc_par_ns ), '"'
539          CALL message( 'lpm_init', 'PA0220', 1, 2, 0, 6, 0 )
540
541    END SELECT
542    SELECT CASE ( splitting_mode )
543
544       CASE ( 'const' )
545          i_splitting_mode = 1
546
547       CASE ( 'cl_av' )
548          i_splitting_mode = 2
549
550       CASE ( 'gb_av' )
551          i_splitting_mode = 3
552
553       CASE DEFAULT
554          WRITE( message_string, * )  'unknown splitting_mode = "',            &
555                                      TRIM( splitting_mode ), '"'
556          CALL message( 'lpm_init', 'PA0146', 1, 2, 0, 6, 0 )
557
558    END SELECT
559    SELECT CASE ( splitting_function )
560
561       CASE ( 'gamma' )
562          isf = 1
563
564       CASE ( 'log' )
565          isf = 2
566
567       CASE ( 'exp' )
568          isf = 3
569
570       CASE DEFAULT
571          WRITE( message_string, * )  'unknown splitting function = "',        &
572                                       TRIM( splitting_function ), '"'
573          CALL message( 'lpm_init', 'PA0147', 1, 2, 0, 6, 0 )
574
575    END SELECT
576
577
578!
579!-- Initialize collision kernels
580    IF ( collision_kernel /= 'none' )  CALL init_kernels
581
582!
583!-- For the first model run of a possible job chain initialize the
584!-- particles, otherwise read the particle data from restart file.
585    IF ( TRIM( initializing_actions ) == 'read_restart_data'  &
586         .AND.  read_particles_from_restartfile )  THEN
587
588       CALL lpm_read_restart_file
589
590    ELSE
591
592!
593!--    Allocate particle arrays and set attributes of the initial set of
594!--    particles, which can be also periodically released at later times.
595       ALLOCATE( prt_count(nzb:nzt+1,nysg:nyng,nxlg:nxrg), &
596                 grid_particles(nzb+1:nzt,nys:nyn,nxl:nxr) )
597
598       number_of_particles         = 0
599
600       sort_count = 0
601       prt_count  = 0
602
603!
604!--    initialize counter for particle IDs
605       grid_particles%id_counter = 1
606
607!
608!--    Initialize all particles with dummy values (otherwise errors may
609!--    occur within restart runs). The reason for this is still not clear
610!--    and may be presumably caused by errors in the respective user-interface.
611       zero_particle = particle_type( 0.0_wp, 0.0_wp, 0.0_wp, 0.0_wp, 0.0_wp,  &
612                                      0.0_wp, 0.0_wp, 0.0_wp, 0.0_wp, 0.0_wp,  &
613                                      0.0_wp, 0.0_wp, 0.0_wp, 0.0_wp, 0.0_wp,  &
614                                      0.0_wp, 0.0_wp, 0.0_wp, 0.0_wp, 0.0_wp,  &
615                                      0, 0, 0_idp, .FALSE., -1 )
616
617       particle_groups = particle_groups_type( 0.0_wp, 0.0_wp, 0.0_wp, 0.0_wp )
618
619!
620!--    Set values for the density ratio and radius for all particle
621!--    groups, if necessary
622       IF ( density_ratio(1) == 9999999.9_wp )  density_ratio(1) = 0.0_wp
623       IF ( radius(1)        == 9999999.9_wp )  radius(1) = 0.0_wp
624       DO  i = 2, number_of_particle_groups
625          IF ( density_ratio(i) == 9999999.9_wp )  THEN
626             density_ratio(i) = density_ratio(i-1)
627          ENDIF
628          IF ( radius(i) == 9999999.9_wp )  radius(i) = radius(i-1)
629       ENDDO
630
631       DO  i = 1, number_of_particle_groups
632          IF ( density_ratio(i) /= 0.0_wp  .AND.  radius(i) == 0 )  THEN
633             WRITE( message_string, * ) 'particle group #', i, ' has a',       &
634                                        'density ratio /= 0 but radius = 0'
635             CALL message( 'lpm_init', 'PA0215', 1, 2, 0, 6, 0 )
636          ENDIF
637          particle_groups(i)%density_ratio = density_ratio(i)
638          particle_groups(i)%radius        = radius(i)
639       ENDDO
640
641!
642!--    Set a seed value for the random number generator to be exclusively
643!--    used for the particle code. The generated random numbers should be
644!--    different on the different PEs.
645       iran_part = iran_part + myid
646
647       CALL lpm_create_particle (PHASE_INIT)
648!
649!--    User modification of initial particles
650       CALL user_lpm_init
651
652!
653!--    Open file for statistical informations about particle conditions
654       IF ( write_particle_statistics )  THEN
655          CALL check_open( 80 )
656          WRITE ( 80, 8000 )  current_timestep_number, simulated_time,         &
657                              number_of_particles
658          CALL close_file( 80 )
659       ENDIF
660
661    ENDIF
662
663    IF ( nested_run )  CALL pmcp_g_init
664
665!
666!-- To avoid programm abort, assign particles array to the local version of
667!-- first grid cell
668    number_of_particles = prt_count(nzb+1,nys,nxl)
669    particles => grid_particles(nzb+1,nys,nxl)%particles(1:number_of_particles)
670!
671!-- Formats
6728000 FORMAT (I6,1X,F7.2,4X,I10,71X,I10)
673
674 END SUBROUTINE lpm_init
675
676!------------------------------------------------------------------------------!
677! Description:
678! ------------
679!> @todo Missing subroutine description.
680!------------------------------------------------------------------------------!
681 SUBROUTINE lpm_create_particle (phase)
682   
683    USE arrays_3d,                                                             &
684       ONLY:  zw
685    USE lpm_exchange_horiz_mod,                                                &
686        ONLY: lpm_exchange_horiz, lpm_move_particle, realloc_particles_array
687
688    USE lpm_pack_and_sort_mod,                                                 &
689        ONLY: lpm_sort_in_subboxes
690
691    USE particle_attributes,                                                   &
692        ONLY: deleted_particles
693
694    IMPLICIT  NONE
695
696    INTEGER(iwp)               ::  alloc_size  !< relative increase of allocated memory for particles
697    INTEGER(iwp)               ::  i           !< loop variable ( particle groups )
698    INTEGER(iwp)               ::  ip          !< index variable along x
699    INTEGER(iwp)               ::  j           !< loop variable ( particles per point )
700    INTEGER(iwp)               ::  jp          !< index variable along y
701    INTEGER(iwp)               ::  k           !< index variable along z
702    INTEGER(iwp)               ::  k_surf      !< index of surface grid point
703    INTEGER(iwp)               ::  kp          !< index variable along z
704    INTEGER(iwp)               ::  loop_stride !< loop variable for initialization
705    INTEGER(iwp)               ::  n           !< loop variable ( number of particles )
706    INTEGER(iwp)               ::  new_size    !< new size of allocated memory for particles
707
708    INTEGER(iwp), INTENT(IN)   ::  phase       !< mode of inititialization
709
710    INTEGER(iwp), DIMENSION(nzb:nzt+1,nysg:nyng,nxlg:nxrg) ::  local_count !< start address of new particle
711    INTEGER(iwp), DIMENSION(nzb:nzt+1,nysg:nyng,nxlg:nxrg) ::  local_start !< start address of new particle
712
713    LOGICAL                    ::  first_stride !< flag for initialization
714
715    REAL(wp)                   ::  pos_x      !< increment for particle position in x
716    REAL(wp)                   ::  pos_y      !< increment for particle position in y
717    REAL(wp)                   ::  pos_z      !< increment for particle position in z
718    REAL(wp)                   ::  rand_contr !< dummy argument for random position
719
720    TYPE(particle_type),TARGET ::  tmp_particle !< temporary particle used for initialization
721
722!
723!-- Calculate particle positions and store particle attributes, if
724!-- particle is situated on this PE
725    DO  loop_stride = 1, 2
726       first_stride = (loop_stride == 1)
727       IF ( first_stride )   THEN
728          local_count = 0           ! count number of particles
729       ELSE
730          local_count = prt_count   ! Start address of new particles
731       ENDIF
732
733!
734!--    Calculate initial_weighting_factor diagnostically
735       IF ( number_concentration /= -1.0_wp .AND. number_concentration > 0.0_wp ) THEN
736          initial_weighting_factor =  number_concentration * 1.0E6_wp *             &
737                                      pdx(1) * pdy(1) * pdz(1)
738       END IF
739
740       n = 0
741       DO  i = 1, number_of_particle_groups
742
743          pos_z = psb(i)
744
745          DO WHILE ( pos_z <= pst(i) )
746
747             IF ( pos_z >= zw(0) .AND.  pos_z < zw(nzt) )  THEN
748
749
750                pos_y = pss(i)
751
752                DO WHILE ( pos_y <= psn(i) )
753
754                   IF ( pos_y >= nys * dy  .AND.                  &
755                        pos_y <  ( nyn + 1 ) * dy  ) THEN
756
757                      pos_x = psl(i)
758
759               xloop: DO WHILE ( pos_x <= psr(i) )
760
761                         IF ( pos_x >= nxl * dx  .AND.            &
762                              pos_x <  ( nxr + 1) * dx ) THEN
763
764                            DO  j = 1, particles_per_point
765
766
767                               n = n + 1
768                               tmp_particle%x             = pos_x
769                               tmp_particle%y             = pos_y
770                               tmp_particle%z             = pos_z
771                               tmp_particle%age           = 0.0_wp
772                               tmp_particle%age_m         = 0.0_wp
773                               tmp_particle%dt_sum        = 0.0_wp
774                               tmp_particle%e_m           = 0.0_wp
775                               tmp_particle%rvar1         = 0.0_wp
776                               tmp_particle%rvar2         = 0.0_wp
777                               tmp_particle%rvar3         = 0.0_wp
778                               tmp_particle%speed_x       = 0.0_wp
779                               tmp_particle%speed_y       = 0.0_wp
780                               tmp_particle%speed_z       = 0.0_wp
781                               tmp_particle%origin_x      = pos_x
782                               tmp_particle%origin_y      = pos_y
783                               tmp_particle%origin_z      = pos_z
784                               IF ( curvature_solution_effects )  THEN
785                                  tmp_particle%aux1      = 0.0_wp    ! dry aerosol radius
786                                  tmp_particle%aux2      = dt_3d     ! last Rosenbrock timestep
787                               ELSE
788                                  tmp_particle%aux1      = 0.0_wp    ! free to use
789                                  tmp_particle%aux2      = 0.0_wp    ! free to use
790                               ENDIF
791                               tmp_particle%radius        = particle_groups(i)%radius
792                               tmp_particle%weight_factor = initial_weighting_factor
793                               tmp_particle%class         = 1
794                               tmp_particle%group         = i
795                               tmp_particle%id            = 0_idp
796                               tmp_particle%particle_mask = .TRUE.
797                               tmp_particle%block_nr      = -1
798!
799!--                            Determine the grid indices of the particle position
800                               ip = tmp_particle%x * ddx
801                               jp = tmp_particle%y * ddy
802                               kp = tmp_particle%z / dz(1) + 1 + offset_ocean_nzt                               
803                               DO WHILE( zw(kp) < tmp_particle%z ) 
804                                  kp = kp + 1
805                               ENDDO
806                               DO WHILE( zw(kp-1) > tmp_particle%z )
807                                  kp = kp - 1
808                               ENDDO 
809!
810!--                            Determine surface level. Therefore, check for
811!--                            upward-facing wall on w-grid.
812                               k_surf = get_topography_top_index_ji( jp, ip, 'w' )
813
814                               IF ( seed_follows_topography )  THEN
815!
816!--                               Particle height is given relative to topography
817                                  kp = kp + k_surf
818                                  tmp_particle%z = tmp_particle%z + zw(k_surf)
819!--                               Skip particle release if particle position is
820!--                               above model top, or within topography in case
821!--                               of overhanging structures.
822                                  IF ( kp > nzt  .OR.                          &
823                                 .NOT. BTEST( wall_flags_0(kp,jp,ip), 0 ) )  THEN
824                                     pos_x = pos_x + pdx(i)
825                                     CYCLE xloop
826                                  ENDIF
827!
828!--                            Skip particle release if particle position is
829!--                            below surface, or within topography in case
830!--                            of overhanging structures.
831                               ELSEIF ( .NOT. seed_follows_topography .AND.    &
832                                         tmp_particle%z <= zw(k_surf)  .OR.    &
833                                        .NOT. BTEST( wall_flags_0(kp,jp,ip), 0 ) )&
834                               THEN
835                                  pos_x = pos_x + pdx(i)
836                                  CYCLE xloop
837                               ENDIF
838
839                               local_count(kp,jp,ip) = local_count(kp,jp,ip) + 1
840
841                               IF ( .NOT. first_stride )  THEN
842                                  IF ( ip < nxl  .OR.  jp < nys  .OR.  kp < nzb+1 )  THEN
843                                     write(6,*) 'xl ',ip,jp,kp,nxl,nys,nzb+1
844                                  ENDIF
845                                  IF ( ip > nxr  .OR.  jp > nyn  .OR.  kp > nzt )  THEN
846                                     write(6,*) 'xu ',ip,jp,kp,nxr,nyn,nzt
847                                  ENDIF
848                                  grid_particles(kp,jp,ip)%particles(local_count(kp,jp,ip)) = tmp_particle
849
850                               ENDIF
851                            ENDDO
852
853                         ENDIF
854
855                         pos_x = pos_x + pdx(i)
856
857                      ENDDO xloop
858
859                   ENDIF
860
861                   pos_y = pos_y + pdy(i)
862
863                ENDDO
864
865             ENDIF
866
867             pos_z = pos_z + pdz(i)
868
869          ENDDO
870
871       ENDDO
872
873       IF ( first_stride )  THEN
874          DO  ip = nxl, nxr
875             DO  jp = nys, nyn
876                DO  kp = nzb+1, nzt
877                   IF ( phase == PHASE_INIT )  THEN
878                      IF ( local_count(kp,jp,ip) > 0 )  THEN
879                         alloc_size = MAX( INT( local_count(kp,jp,ip) *        &
880                            ( 1.0_wp + alloc_factor / 100.0_wp ) ),            &
881                            min_nr_particle )
882                      ELSE
883                         alloc_size = min_nr_particle
884                      ENDIF
885                      ALLOCATE(grid_particles(kp,jp,ip)%particles(1:alloc_size))
886                      DO  n = 1, alloc_size
887                         grid_particles(kp,jp,ip)%particles(n) = zero_particle
888                      ENDDO
889                   ELSEIF ( phase == PHASE_RELEASE )  THEN
890                      IF ( local_count(kp,jp,ip) > 0 )  THEN
891                         new_size   = local_count(kp,jp,ip) + prt_count(kp,jp,ip)
892                         alloc_size = MAX( INT( new_size * ( 1.0_wp +          &
893                            alloc_factor / 100.0_wp ) ), min_nr_particle )
894                         IF( alloc_size > SIZE( grid_particles(kp,jp,ip)%particles) )  THEN
895                            CALL realloc_particles_array(ip,jp,kp,alloc_size)
896                         ENDIF
897                      ENDIF
898                   ENDIF
899                ENDDO
900             ENDDO
901          ENDDO
902       ENDIF
903
904    ENDDO
905
906
907
908    local_start = prt_count+1
909    prt_count   = local_count
910
911!
912!-- Calculate particle IDs
913    DO  ip = nxl, nxr
914       DO  jp = nys, nyn
915          DO  kp = nzb+1, nzt
916             number_of_particles = prt_count(kp,jp,ip)
917             IF ( number_of_particles <= 0 )  CYCLE
918             particles => grid_particles(kp,jp,ip)%particles(1:number_of_particles)
919
920             DO  n = local_start(kp,jp,ip), number_of_particles  !only new particles
921
922                particles(n)%id = 10000_idp**3 * grid_particles(kp,jp,ip)%id_counter + &
923                                  10000_idp**2 * kp + 10000_idp * jp + ip
924!
925!--             Count the number of particles that have been released before
926                grid_particles(kp,jp,ip)%id_counter =                          &
927                                         grid_particles(kp,jp,ip)%id_counter + 1
928
929             ENDDO
930
931          ENDDO
932       ENDDO
933    ENDDO
934
935!
936!-- Initialize aerosol background spectrum
937    IF ( curvature_solution_effects )  THEN
938       CALL lpm_init_aerosols(local_start)
939    ENDIF
940
941!
942!-- Add random fluctuation to particle positions.
943    IF ( random_start_position )  THEN
944       DO  ip = nxl, nxr
945          DO  jp = nys, nyn
946             DO  kp = nzb+1, nzt
947                number_of_particles = prt_count(kp,jp,ip)
948                IF ( number_of_particles <= 0 )  CYCLE
949                particles => grid_particles(kp,jp,ip)%particles(1:number_of_particles)
950!
951!--             Move only new particles. Moreover, limit random fluctuation
952!--             in order to prevent that particles move more than one grid box,
953!--             which would lead to problems concerning particle exchange
954!--             between processors in case pdx/pdy are larger than dx/dy,
955!--             respectively.
956                DO  n = local_start(kp,jp,ip), number_of_particles
957                   IF ( psl(particles(n)%group) /= psr(particles(n)%group) )  THEN
958                      rand_contr = ( random_function( iran_part ) - 0.5_wp ) * &
959                                     pdx(particles(n)%group)
960                      particles(n)%x = particles(n)%x +                        &
961                              MERGE( rand_contr, SIGN( dx, rand_contr ),       &
962                                     ABS( rand_contr ) < dx                    &
963                                   )
964                   ENDIF
965                   IF ( pss(particles(n)%group) /= psn(particles(n)%group) )  THEN
966                      rand_contr = ( random_function( iran_part ) - 0.5_wp ) * &
967                                     pdy(particles(n)%group)
968                      particles(n)%y = particles(n)%y +                        &
969                              MERGE( rand_contr, SIGN( dy, rand_contr ),       &
970                                     ABS( rand_contr ) < dy                    &
971                                   )
972                   ENDIF
973                   IF ( psb(particles(n)%group) /= pst(particles(n)%group) )  THEN
974                      rand_contr = ( random_function( iran_part ) - 0.5_wp ) * &
975                                     pdz(particles(n)%group)
976                      particles(n)%z = particles(n)%z +                        &
977                              MERGE( rand_contr, SIGN( dzw(kp), rand_contr ),  &
978                                     ABS( rand_contr ) < dzw(kp)               &
979                                   )
980                   ENDIF
981                ENDDO
982!
983!--             Identify particles located outside the model domain and reflect
984!--             or absorb them if necessary.
985                CALL lpm_boundary_conds( 'bottom/top', i, j, k )
986!
987!--             Furthermore, remove particles located in topography. Note, as
988!--             the particle speed is still zero at this point, wall
989!--             reflection boundary conditions will not work in this case.
990                particles =>                                                   &
991                       grid_particles(kp,jp,ip)%particles(1:number_of_particles)
992                DO  n = local_start(kp,jp,ip), number_of_particles
993                   i = particles(n)%x * ddx
994                   j = particles(n)%y * ddy
995                   k = particles(n)%z / dz(1) + 1 + offset_ocean_nzt
996                   DO WHILE( zw(k) < particles(n)%z )
997                      k = k + 1
998                   ENDDO
999                   DO WHILE( zw(k-1) > particles(n)%z )
1000                      k = k - 1
1001                   ENDDO
1002!
1003!--                Check if particle is within topography
1004                   IF ( .NOT. BTEST( wall_flags_0(k,j,i), 0 ) )  THEN
1005                      particles(n)%particle_mask = .FALSE.
1006                      deleted_particles = deleted_particles + 1
1007                   ENDIF
1008
1009                ENDDO
1010             ENDDO
1011          ENDDO
1012       ENDDO
1013!
1014!--    Exchange particles between grid cells and processors
1015       CALL lpm_move_particle
1016       CALL lpm_exchange_horiz
1017
1018    ENDIF
1019!
1020!-- In case of random_start_position, delete particles identified by
1021!-- lpm_exchange_horiz and lpm_boundary_conds. Then sort particles into blocks,
1022!-- which is needed for a fast interpolation of the LES fields on the particle
1023!-- position.
1024    CALL lpm_sort_in_subboxes
1025
1026!
1027!-- Determine the current number of particles
1028    DO  ip = nxl, nxr
1029       DO  jp = nys, nyn
1030          DO  kp = nzb+1, nzt
1031             number_of_particles         = number_of_particles                 &
1032                                           + prt_count(kp,jp,ip)
1033          ENDDO
1034       ENDDO
1035    ENDDO
1036!
1037!-- Calculate the number of particles of the total domain
1038#if defined( __parallel )
1039    IF ( collective_wait )  CALL MPI_BARRIER( comm2d, ierr )
1040    CALL MPI_ALLREDUCE( number_of_particles, total_number_of_particles, 1, &
1041    MPI_INTEGER, MPI_SUM, comm2d, ierr )
1042#else
1043    total_number_of_particles = number_of_particles
1044#endif
1045
1046    RETURN
1047
1048 END SUBROUTINE lpm_create_particle
1049
1050 SUBROUTINE lpm_init_aerosols(local_start)
1051
1052    USE arrays_3d,                                                             &
1053        ONLY: hyp, pt, q
1054
1055    USE cloud_parameters,                                                      &
1056        ONLY: molecular_weight_of_solute, molecular_weight_of_water, rho_l,    &
1057              r_v, rho_s, vanthoff
1058
1059    USE constants,                                                             &
1060        ONLY: pi
1061
1062    USE diagnostic_quantities_mod,                                             &
1063        ONLY:  magnus
1064
1065
1066    USE kinds
1067
1068    USE particle_attributes,                                                   &
1069        ONLY: aero_species, aero_type, aero_weight, log_sigma, na, rm
1070
1071    IMPLICIT NONE
1072
1073    REAL(wp)  :: afactor            !< curvature effects
1074    REAL(wp)  :: bfactor            !< solute effects
1075    REAL(wp)  :: dlogr              !< logarithmic width of radius bin
1076    REAL(wp)  :: e_a                !< vapor pressure
1077    REAL(wp)  :: e_s                !< saturation vapor pressure
1078    REAL(wp)  :: rmin = 0.005e-6_wp !< minimum aerosol radius
1079    REAL(wp)  :: rmax = 10.0e-6_wp  !< maximum aerosol radius
1080    REAL(wp)  :: r_mid              !< mean radius of bin
1081    REAL(wp)  :: r_l                !< left radius of bin
1082    REAL(wp)  :: r_r                !< right radius of bin
1083    REAL(wp)  :: sigma              !< surface tension
1084    REAL(wp)  :: t_int              !< temperature
1085
1086    INTEGER(iwp), DIMENSION(nzb:nzt+1,nysg:nyng,nxlg:nxrg), INTENT(IN) ::  local_start !<
1087
1088    INTEGER(iwp)  :: n              !<
1089    INTEGER(iwp)  :: ip             !<
1090    INTEGER(iwp)  :: jp             !<
1091    INTEGER(iwp)  :: kp             !<
1092
1093!
1094!-- Set constants for different aerosol species
1095    IF ( TRIM(aero_species) .EQ. 'nacl' ) THEN
1096       molecular_weight_of_solute = 0.05844_wp 
1097       rho_s                      = 2165.0_wp
1098       vanthoff                   = 2.0_wp
1099    ELSEIF ( TRIM(aero_species) .EQ. 'c3h4o4' ) THEN
1100       molecular_weight_of_solute = 0.10406_wp 
1101       rho_s                      = 1600.0_wp
1102       vanthoff                   = 1.37_wp
1103    ELSEIF ( TRIM(aero_species) .EQ. 'nh4o3' ) THEN
1104       molecular_weight_of_solute = 0.08004_wp 
1105       rho_s                      = 1720.0_wp
1106       vanthoff                   = 2.31_wp
1107    ELSE
1108       WRITE( message_string, * ) 'unknown aerosol species ',   &
1109                                'aero_species = "', TRIM( aero_species ), '"'
1110       CALL message( 'lpm_init', 'PA0470', 1, 2, 0, 6, 0 )
1111    ENDIF
1112!
1113!-- The following typical aerosol spectra are taken from Jaenicke (1993):
1114!-- Tropospheric aerosols. Published in Aerosol-Cloud-Climate Interactions.
1115    IF ( TRIM(aero_type) .EQ. 'polar' )  THEN
1116       na        = (/ 2.17e1, 1.86e-1, 3.04e-4 /) * 1.0E6
1117       rm        = (/ 0.0689, 0.375, 4.29 /) * 1.0E-6
1118       log_sigma = (/ 0.245, 0.300, 0.291 /)
1119    ELSEIF ( TRIM(aero_type) .EQ. 'background' )  THEN
1120       na        = (/ 1.29e2, 5.97e1, 6.35e1 /) * 1.0E6
1121       rm        = (/ 0.0036, 0.127, 0.259 /) * 1.0E-6
1122       log_sigma = (/ 0.645, 0.253, 0.425 /)
1123    ELSEIF ( TRIM(aero_type) .EQ. 'maritime' )  THEN
1124       na        = (/ 1.33e2, 6.66e1, 3.06e0 /) * 1.0E6
1125       rm        = (/ 0.0039, 0.133, 0.29 /) * 1.0E-6
1126       log_sigma = (/ 0.657, 0.210, 0.396 /)
1127    ELSEIF ( TRIM(aero_type) .EQ. 'continental' )  THEN
1128       na        = (/ 3.20e3, 2.90e3, 3.00e-1 /) * 1.0E6
1129       rm        = (/ 0.01, 0.058, 0.9 /) * 1.0E-6
1130       log_sigma = (/ 0.161, 0.217, 0.380 /)
1131    ELSEIF ( TRIM(aero_type) .EQ. 'desert' )  THEN
1132       na        = (/ 7.26e2, 1.14e3, 1.78e-1 /) * 1.0E6
1133       rm        = (/ 0.001, 0.0188, 10.8 /) * 1.0E-6
1134       log_sigma = (/ 0.247, 0.770, 0.438 /)
1135    ELSEIF ( TRIM(aero_type) .EQ. 'rural' )  THEN
1136       na        = (/ 6.65e3, 1.47e2, 1.99e3 /) * 1.0E6
1137       rm        = (/ 0.00739, 0.0269, 0.0419 /) * 1.0E-6
1138       log_sigma = (/ 0.225, 0.557, 0.266 /)
1139    ELSEIF ( TRIM(aero_type) .EQ. 'urban' )  THEN
1140       na        = (/ 9.93e4, 1.11e3, 3.64e4 /) * 1.0E6
1141       rm        = (/ 0.00651, 0.00714, 0.0248 /) * 1.0E-6
1142       log_sigma = (/ 0.245, 0.666, 0.337 /)
1143    ELSEIF ( TRIM(aero_type) .EQ. 'user' )  THEN
1144       CONTINUE
1145    ELSE
1146       WRITE( message_string, * ) 'unknown aerosol type ',   &
1147                                'aero_type = "', TRIM( aero_type ), '"'
1148       CALL message( 'lpm_init', 'PA0459', 1, 2, 0, 6, 0 )
1149    ENDIF
1150
1151    DO  ip = nxl, nxr
1152       DO  jp = nys, nyn
1153          DO  kp = nzb+1, nzt
1154
1155             number_of_particles = prt_count(kp,jp,ip)
1156             IF ( number_of_particles <= 0 )  CYCLE
1157             particles => grid_particles(kp,jp,ip)%particles(1:number_of_particles)
1158
1159             dlogr   = ( LOG10(rmax) - LOG10(rmin) ) / ( number_of_particles - local_start(kp,jp,ip) + 1 )
1160!
1161!--          Initialize the aerosols with a predefined spectral distribution
1162!--          of the dry radius (logarithmically increasing bins) and a varying
1163!--          weighting factor
1164             DO  n = local_start(kp,jp,ip), number_of_particles  !only new particles
1165
1166                r_l   = 10.0**( LOG10( rmin ) + (n-1) * dlogr )
1167                r_r   = 10.0**( LOG10( rmin ) + n * dlogr )
1168                r_mid = SQRT( r_l * r_r )
1169
1170                particles(n)%aux1          = r_mid
1171                particles(n)%weight_factor =                                           &
1172                   ( na(1) / ( SQRT( 2.0 * pi ) * log_sigma(1) ) *                     &
1173                     EXP( - LOG10( r_mid / rm(1) )**2 / ( 2.0 * log_sigma(1)**2 ) ) +  &
1174                     na(2) / ( SQRT( 2.0 * pi ) * log_sigma(2) ) *                     &
1175                     EXP( - LOG10( r_mid / rm(2) )**2 / ( 2.0 * log_sigma(2)**2 ) ) +  &
1176                     na(3) / ( SQRT( 2.0 * pi ) * log_sigma(3) ) *                     &
1177                     EXP( - LOG10( r_mid / rm(3) )**2 / ( 2.0 * log_sigma(3)**2 ) )    &
1178                   ) * ( LOG10(r_r) - LOG10(r_l) ) * ( dx * dy * dzw(kp) )
1179
1180!
1181!--             Multiply weight_factor with the namelist parameter aero_weight
1182!--             to increase or decrease the number of simulated aerosols
1183                particles(n)%weight_factor = particles(n)%weight_factor * aero_weight
1184
1185                IF ( particles(n)%weight_factor - FLOOR(particles(n)%weight_factor,KIND=wp) &
1186                     .GT. random_function( iran_part ) )  THEN
1187                   particles(n)%weight_factor = FLOOR(particles(n)%weight_factor,KIND=wp) + 1.0
1188                ELSE
1189                   particles(n)%weight_factor = FLOOR(particles(n)%weight_factor,KIND=wp)
1190                ENDIF
1191!
1192!--             Unnecessary particles will be deleted
1193                IF ( particles(n)%weight_factor .LE. 0.0 )  particles(n)%particle_mask = .FALSE.
1194
1195             ENDDO
1196!
1197!--          Set particle radius to equilibrium radius based on the environmental
1198!--          supersaturation (Khvorostyanov and Curry, 2007, JGR). This avoids
1199!--          the sometimes lengthy growth toward their equilibrium radius within
1200!--          the simulation.
1201             t_int  = pt(kp,jp,ip) * ( hyp(kp) / 100000.0_wp )**0.286_wp
1202
1203             e_s = magnus( t_int )
1204             e_a = q(kp,jp,ip) * hyp(kp) / ( q(kp,jp,ip) + 0.622_wp )
1205
1206             sigma   = 0.0761_wp - 0.000155_wp * ( t_int - 273.15_wp )
1207             afactor = 2.0_wp * sigma / ( rho_l * r_v * t_int )
1208
1209             bfactor = vanthoff * molecular_weight_of_water *    &
1210                       rho_s / ( molecular_weight_of_solute * rho_l )
1211!
1212!--          The formula is only valid for subsaturated environments. For
1213!--          supersaturations higher than -5 %, the supersaturation is set to -5%.
1214             IF ( e_a / e_s >= 0.95_wp )  e_a = 0.95_wp * e_s
1215
1216             DO  n = local_start(kp,jp,ip), number_of_particles  !only new particles
1217!
1218!--             For details on this equation, see Eq. (14) of Khvorostyanov and
1219!--             Curry (2007, JGR)
1220                particles(n)%radius = bfactor**0.3333333_wp *                  &
1221                   particles(n)%aux1 / ( 1.0_wp - e_a / e_s )**0.3333333_wp / &
1222                   ( 1.0_wp + ( afactor / ( 3.0_wp * bfactor**0.3333333_wp *   &
1223                     particles(n)%aux1 ) ) /                                  &
1224                     ( 1.0_wp - e_a / e_s )**0.6666666_wp                      &
1225                   )
1226
1227             ENDDO
1228
1229          ENDDO
1230       ENDDO
1231    ENDDO
1232
1233 END SUBROUTINE lpm_init_aerosols
1234
1235END MODULE lpm_init_mod
Note: See TracBrowser for help on using the repository browser.