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

Last change on this file since 3464 was 3361, checked in by knoop, 5 years ago

Introduced global constant rd_d_rv=0.622

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