source: palm/trunk/SOURCE/lpm_init_mod.f90 @ 1871

Last change on this file since 1871 was 1871, checked in by hoffmann, 8 years ago

initialization of aerosol spectra added

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