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

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

introduction of a particle ID, improvement of equilibrium radius calculation, and reformatting

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