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

Last change on this file since 2307 was 2305, checked in by hoffmann, 7 years ago

Improved calculation of particle IDs.

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