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

Last change on this file since 2233 was 2233, checked in by suehring, 7 years ago

last commit documented

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