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

Last change on this file since 1977 was 1930, checked in by suehring, 8 years ago

last commit documented

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