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

Last change on this file since 1873 was 1873, checked in by maronga, 8 years ago

revised renaming of modules

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