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

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

Adjustments according new topography and surface-modelling concept implemented

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