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

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

changes in LPM and bulk cloud microphysics

  • Property svn:keywords set to Id
File size: 28.3 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! Unused variables removed.
22!
23! Former revisions:
24! -----------------
25! $Id: lpm_init.f90 1822 2016-04-07 07:49:42Z hoffmann $
26!
27! 1783 2016-03-06 18:36:17Z raasch
28! netcdf module added
29!
30! 1725 2015-11-17 13:01:51Z hoffmann
31! Bugfix: Processor-dependent seed for random function is generated before it is
32! used.
33!
34! 1691 2015-10-26 16:17:44Z maronga
35! Renamed prandtl_layer to constant_flux_layer.
36!
37! 1685 2015-10-08 07:32:13Z raasch
38! bugfix concerning vertical index offset in case of ocean
39!
40! 1682 2015-10-07 23:56:08Z knoop
41! Code annotations made doxygen readable
42!
43! 1575 2015-03-27 09:56:27Z raasch
44! initial vertical particle position is allowed to follow the topography
45!
46! 1359 2014-04-11 17:15:14Z hoffmann
47! New particle structure integrated.
48! Kind definition added to all floating point numbers.
49! lpm_init changed form a subroutine to a module.
50!
51! 1327 2014-03-21 11:00:16Z raasch
52! -netcdf_output
53!
54! 1322 2014-03-20 16:38:49Z raasch
55! REAL functions provided with KIND-attribute
56!
57! 1320 2014-03-20 08:40:49Z raasch
58! ONLY-attribute added to USE-statements,
59! kind-parameters added to all INTEGER and REAL declaration statements,
60! kinds are defined in new module kinds,
61! revision history before 2012 removed,
62! comment fields (!:) to be used for variable explanations added to
63! all variable declaration statements
64! bugfix: #if defined( __parallel ) added
65!
66! 1314 2014-03-14 18:25:17Z suehring
67! Vertical logarithmic interpolation of horizontal particle speed for particles
68! between roughness height and first vertical grid level.
69!
70! 1092 2013-02-02 11:24:22Z raasch
71! unused variables removed
72!
73! 1036 2012-10-22 13:43:42Z raasch
74! code put under GPL (PALM 3.9)
75!
76! 849 2012-03-15 10:35:09Z raasch
77! routine renamed: init_particles -> lpm_init
78! de_dx, de_dy, de_dz are allocated here (instead of automatic arrays in
79! advec_particles),
80! sort_particles renamed lpm_sort_arrays, user_init_particles renamed lpm_init
81!
82! 828 2012-02-21 12:00:36Z raasch
83! call of init_kernels, particle feature color renamed class
84!
85! 824 2012-02-17 09:09:57Z raasch
86! particle attributes speed_x|y|z_sgs renamed rvar1|2|3,
87! array particles implemented as pointer
88!
89! 667 2010-12-23 12:06:00Z suehring/gryschka
90! nxl-1, nxr+1, nys-1, nyn+1 replaced by nxlg, nxrg, nysg, nyng for allocation
91! of arrays.
92!
93! Revision 1.1  1999/11/25 16:22:38  raasch
94! Initial revision
95!
96!
97! Description:
98! ------------
99!> This routine initializes a set of particles and their attributes (position,
100!> radius, ..) which are used by the Lagrangian particle model (see lpm).
101!------------------------------------------------------------------------------!
102 MODULE lpm_init_mod
103 
104
105    USE arrays_3d,                                                             &
106        ONLY:  de_dx, de_dy, de_dz, zu, zw, z0
107
108    USE cloud_parameters,                                                      &
109        ONLY:  curvature_solution_effects
110
111    USE control_parameters,                                                    &
112        ONLY:  cloud_droplets, constant_flux_layer, current_timestep_number,   &
113               dz, initializing_actions, message_string, ocean, simulated_time
114
115    USE grid_variables,                                                        &
116        ONLY:  ddx, dx, ddy, dy
117
118    USE indices,                                                               &
119        ONLY:  nx, nxl, nxlg, nxrg, nxr, ny, nyn, nys, nyng, nysg, nz, nzb,    &
120               nzb_w_inner, nzt
121
122    USE kinds
123
124    USE lpm_collision_kernels_mod,                                             &
125        ONLY:  init_kernels
126
127    USE netcdf_interface,                                                      &
128        ONLY:  netcdf_data_format
129
130    USE particle_attributes,                                                   &
131        ONLY:   alloc_factor, bc_par_b, bc_par_lr, bc_par_ns, bc_par_t,        &
132                block_offset, block_offset_def, collision_kernel,              &
133                density_ratio, grid_particles,                                 &
134                initial_weighting_factor, ibc_par_b, ibc_par_lr, ibc_par_ns,   &
135                ibc_par_t, iran_part, log_z_z0,                                &
136                max_number_of_particle_groups, maximum_number_of_particles,    &
137                min_nr_particle, mpi_particle_type,                            &
138                number_of_particles,                                           &
139                number_of_particle_groups, number_of_sublayers,                &
140                offset_ocean_nzt, offset_ocean_nzt_m1,                         &
141                particles, particle_advection_start, particle_groups,          &
142                particle_groups_type, particles_per_point,                     &
143                particle_type, pdx, pdy, pdz,                                  &
144                prt_count, psb, psl, psn, psr, pss, pst,                       &
145                radius, random_start_position, read_particles_from_restartfile,&
146                seed_follows_topography, sort_count,                           &
147                total_number_of_particles,                                     &
148                use_sgs_for_particles,                                         &
149                write_particle_statistics, uniform_particles, zero_particle,   &
150                z0_av_global
151
152    USE pegrid
153
154    USE random_function_mod,                                                   &
155        ONLY:  random_function
156
157    IMPLICIT NONE
158
159    PRIVATE
160
161    INTEGER(iwp), PARAMETER         :: PHASE_INIT    = 1  !<
162    INTEGER(iwp), PARAMETER, PUBLIC :: PHASE_RELEASE = 2  !<
163
164    INTERFACE lpm_init
165       MODULE PROCEDURE lpm_init
166    END INTERFACE lpm_init
167
168    INTERFACE lpm_create_particle
169       MODULE PROCEDURE lpm_create_particle
170    END INTERFACE lpm_create_particle
171
172    PUBLIC lpm_init, lpm_create_particle
173
174CONTAINS
175
176!------------------------------------------------------------------------------!
177! Description:
178! ------------
179!> @todo Missing subroutine description.
180!------------------------------------------------------------------------------!
181 SUBROUTINE lpm_init
182
183    USE lpm_collision_kernels_mod,                                             &
184        ONLY:  init_kernels
185
186    IMPLICIT NONE
187
188    INTEGER(iwp) ::  i                           !<
189    INTEGER(iwp) ::  j                           !<
190    INTEGER(iwp) ::  k                           !<
191
192#if defined( __parallel )
193    INTEGER(iwp), DIMENSION(3) ::  blocklengths  !<
194    INTEGER(iwp), DIMENSION(3) ::  displacements !<
195    INTEGER(iwp), DIMENSION(3) ::  types         !<
196#endif
197
198    REAL(wp) ::  height_int                      !<
199    REAL(wp) ::  height_p                        !<
200    REAL(wp) ::  z_p                             !<
201    REAL(wp) ::  z0_av_local                     !<
202
203#if defined( __parallel )
204!
205!-- Define MPI derived datatype for FORTRAN datatype particle_type (see module
206!-- particle_attributes). Integer length is 4 byte, Real is 8 byte
207    blocklengths(1)  = 19;  blocklengths(2)  =   6;  blocklengths(3)  =   1
208    displacements(1) =  0;  displacements(2) = 152;  displacements(3) = 176
209
210    types(1) = MPI_REAL
211    types(2) = MPI_INTEGER
212    types(3) = MPI_UB
213    CALL MPI_TYPE_STRUCT( 3, blocklengths, displacements, types, &
214                          mpi_particle_type, ierr )
215    CALL MPI_TYPE_COMMIT( mpi_particle_type, ierr )
216#endif
217
218!
219!-- In case of oceans runs, the vertical index calculations need an offset,
220!-- because otherwise the k indices will become negative
221    IF ( ocean )  THEN
222       offset_ocean_nzt    = nzt
223       offset_ocean_nzt_m1 = nzt - 1
224    ENDIF
225
226!
227!-- Define block offsets for dividing a gridcell in 8 sub cells
228
229    block_offset(0) = block_offset_def (-1,-1,-1)
230    block_offset(1) = block_offset_def (-1,-1, 0)
231    block_offset(2) = block_offset_def (-1, 0,-1)
232    block_offset(3) = block_offset_def (-1, 0, 0)
233    block_offset(4) = block_offset_def ( 0,-1,-1)
234    block_offset(5) = block_offset_def ( 0,-1, 0)
235    block_offset(6) = block_offset_def ( 0, 0,-1)
236    block_offset(7) = block_offset_def ( 0, 0, 0)
237!
238!-- Check the number of particle groups.
239    IF ( number_of_particle_groups > max_number_of_particle_groups )  THEN
240       WRITE( message_string, * ) 'max_number_of_particle_groups =',      &
241                                  max_number_of_particle_groups ,         &
242                                  '&number_of_particle_groups reset to ', &
243                                  max_number_of_particle_groups
244       CALL message( 'lpm_init', 'PA0213', 0, 1, 0, 6, 0 )
245       number_of_particle_groups = max_number_of_particle_groups
246    ENDIF
247
248!
249!-- Set default start positions, if necessary
250    IF ( psl(1) == 9999999.9_wp )  psl(1) = -0.5_wp * dx
251    IF ( psr(1) == 9999999.9_wp )  psr(1) = ( nx + 0.5_wp ) * dx
252    IF ( pss(1) == 9999999.9_wp )  pss(1) = -0.5_wp * dy
253    IF ( psn(1) == 9999999.9_wp )  psn(1) = ( ny + 0.5_wp ) * dy
254    IF ( psb(1) == 9999999.9_wp )  psb(1) = zu(nz/2)
255    IF ( pst(1) == 9999999.9_wp )  pst(1) = psb(1)
256
257    IF ( pdx(1) == 9999999.9_wp  .OR.  pdx(1) == 0.0_wp )  pdx(1) = dx
258    IF ( pdy(1) == 9999999.9_wp  .OR.  pdy(1) == 0.0_wp )  pdy(1) = dy
259    IF ( pdz(1) == 9999999.9_wp  .OR.  pdz(1) == 0.0_wp )  pdz(1) = zu(2) - zu(1)
260
261    DO  j = 2, number_of_particle_groups
262       IF ( psl(j) == 9999999.9_wp )  psl(j) = psl(j-1)
263       IF ( psr(j) == 9999999.9_wp )  psr(j) = psr(j-1)
264       IF ( pss(j) == 9999999.9_wp )  pss(j) = pss(j-1)
265       IF ( psn(j) == 9999999.9_wp )  psn(j) = psn(j-1)
266       IF ( psb(j) == 9999999.9_wp )  psb(j) = psb(j-1)
267       IF ( pst(j) == 9999999.9_wp )  pst(j) = pst(j-1)
268       IF ( pdx(j) == 9999999.9_wp  .OR.  pdx(j) == 0.0_wp )  pdx(j) = pdx(j-1)
269       IF ( pdy(j) == 9999999.9_wp  .OR.  pdy(j) == 0.0_wp )  pdy(j) = pdy(j-1)
270       IF ( pdz(j) == 9999999.9_wp  .OR.  pdz(j) == 0.0_wp )  pdz(j) = pdz(j-1)
271    ENDDO
272
273!
274!-- Allocate arrays required for calculating particle SGS velocities
275    IF ( use_sgs_for_particles  .AND.  .NOT. cloud_droplets )  THEN
276       ALLOCATE( de_dx(nzb:nzt+1,nysg:nyng,nxlg:nxrg), &
277                 de_dy(nzb:nzt+1,nysg:nyng,nxlg:nxrg), &
278                 de_dz(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
279    ENDIF
280
281!
282!-- Allocate array required for logarithmic vertical interpolation of
283!-- horizontal particle velocities between the surface and the first vertical
284!-- grid level. In order to avoid repeated CPU cost-intensive CALLS of
285!-- intrinsic FORTRAN procedure LOG(z/z0), LOG(z/z0) is precalculated for
286!-- several heights. Splitting into 20 sublayers turned out to be sufficient.
287!-- To obtain exact height levels of particles, linear interpolation is applied
288!-- (see lpm_advec.f90).
289    IF ( constant_flux_layer )  THEN
290       
291       ALLOCATE ( log_z_z0(0:number_of_sublayers) ) 
292       z_p         = zu(nzb+1) - zw(nzb)
293
294!
295!--    Calculate horizontal mean value of z0 used for logartihmic
296!--    interpolation. Note: this is not exact for heterogeneous z0.
297!--    However, sensitivity studies showed that the effect is
298!--    negligible.
299       z0_av_local  = SUM( z0(nys:nyn,nxl:nxr) )
300       z0_av_global = 0.0_wp
301
302#if defined( __parallel )
303       CALL MPI_ALLREDUCE(z0_av_local, z0_av_global, 1, MPI_REAL, MPI_SUM, &
304                          comm2d, ierr )
305#else
306       z0_av_global = z0_av_local
307#endif
308
309       z0_av_global = z0_av_global  / ( ( ny + 1 ) * ( nx + 1 ) )
310!
311!--    Horizontal wind speed is zero below and at z0
312       log_z_z0(0) = 0.0_wp
313!
314!--    Calculate vertical depth of the sublayers
315       height_int  = ( z_p - z0_av_global ) / REAL( number_of_sublayers, KIND=wp )
316!
317!--    Precalculate LOG(z/z0)
318       height_p    = 0.0_wp
319       DO  k = 1, number_of_sublayers
320
321          height_p    = height_p + height_int
322          log_z_z0(k) = LOG( height_p / z0_av_global )
323
324       ENDDO
325
326
327    ENDIF
328
329!
330!-- Check boundary condition and set internal variables
331    SELECT CASE ( bc_par_b )
332   
333       CASE ( 'absorb' )
334          ibc_par_b = 1
335
336       CASE ( 'reflect' )
337          ibc_par_b = 2
338         
339       CASE DEFAULT
340          WRITE( message_string, * )  'unknown boundary condition ',   &
341                                       'bc_par_b = "', TRIM( bc_par_b ), '"'
342          CALL message( 'lpm_init', 'PA0217', 1, 2, 0, 6, 0 )
343         
344    END SELECT
345    SELECT CASE ( bc_par_t )
346   
347       CASE ( 'absorb' )
348          ibc_par_t = 1
349
350       CASE ( 'reflect' )
351          ibc_par_t = 2
352         
353       CASE DEFAULT
354          WRITE( message_string, * ) 'unknown boundary condition ',   &
355                                     'bc_par_t = "', TRIM( bc_par_t ), '"'
356          CALL message( 'lpm_init', 'PA0218', 1, 2, 0, 6, 0 )
357         
358    END SELECT
359    SELECT CASE ( bc_par_lr )
360
361       CASE ( 'cyclic' )
362          ibc_par_lr = 0
363
364       CASE ( 'absorb' )
365          ibc_par_lr = 1
366
367       CASE ( 'reflect' )
368          ibc_par_lr = 2
369         
370       CASE DEFAULT
371          WRITE( message_string, * ) 'unknown boundary condition ',   &
372                                     'bc_par_lr = "', TRIM( bc_par_lr ), '"'
373          CALL message( 'lpm_init', 'PA0219', 1, 2, 0, 6, 0 )
374         
375    END SELECT
376    SELECT CASE ( bc_par_ns )
377
378       CASE ( 'cyclic' )
379          ibc_par_ns = 0
380
381       CASE ( 'absorb' )
382          ibc_par_ns = 1
383
384       CASE ( 'reflect' )
385          ibc_par_ns = 2
386         
387       CASE DEFAULT
388          WRITE( message_string, * ) 'unknown boundary condition ',   &
389                                     'bc_par_ns = "', TRIM( bc_par_ns ), '"'
390          CALL message( 'lpm_init', 'PA0220', 1, 2, 0, 6, 0 )
391         
392    END SELECT
393
394!
395!-- Initialize collision kernels
396    IF ( collision_kernel /= 'none' )  CALL init_kernels
397
398!
399!-- For the first model run of a possible job chain initialize the
400!-- particles, otherwise read the particle data from restart file.
401    IF ( TRIM( initializing_actions ) == 'read_restart_data'  &
402         .AND.  read_particles_from_restartfile )  THEN
403
404       CALL lpm_read_restart_file
405
406    ELSE
407
408!
409!--    Allocate particle arrays and set attributes of the initial set of
410!--    particles, which can be also periodically released at later times.
411       ALLOCATE( prt_count(nzb:nzt+1,nysg:nyng,nxlg:nxrg), &
412                 grid_particles(nzb+1:nzt,nys:nyn,nxl:nxr) )
413
414       maximum_number_of_particles = 0
415       number_of_particles         = 0
416
417       sort_count = 0
418       prt_count  = 0
419
420!
421!--    Initialize all particles with dummy values (otherwise errors may
422!--    occur within restart runs). The reason for this is still not clear
423!--    and may be presumably caused by errors in the respective user-interface.
424       zero_particle = particle_type( 0.0_wp, 0.0_wp, 0.0_wp, 0.0_wp, 0.0_wp,  &
425                                      0.0_wp, 0.0_wp, 0.0_wp, 0.0_wp, 0.0_wp,  &
426                                      0.0_wp, 0.0_wp, 0.0_wp, 0.0_wp, 0.0_wp,  &
427                                      0.0_wp, 0.0_wp, 0.0_wp, 0.0_wp, 0, 0, 0, &
428                                      0, .FALSE., -1)
429
430       particle_groups = particle_groups_type( 0.0_wp, 0.0_wp, 0.0_wp, 0.0_wp )
431
432!
433!--    Set values for the density ratio and radius for all particle
434!--    groups, if necessary
435       IF ( density_ratio(1) == 9999999.9_wp )  density_ratio(1) = 0.0_wp
436       IF ( radius(1)        == 9999999.9_wp )  radius(1) = 0.0_wp
437       DO  i = 2, number_of_particle_groups
438          IF ( density_ratio(i) == 9999999.9_wp )  THEN
439             density_ratio(i) = density_ratio(i-1)
440          ENDIF
441          IF ( radius(i) == 9999999.9_wp )  radius(i) = radius(i-1)
442       ENDDO
443
444       DO  i = 1, number_of_particle_groups
445          IF ( density_ratio(i) /= 0.0_wp  .AND.  radius(i) == 0 )  THEN
446             WRITE( message_string, * ) 'particle group #', i, 'has a', &
447                                        'density ratio /= 0 but radius = 0'
448             CALL message( 'lpm_init', 'PA0215', 1, 2, 0, 6, 0 )
449          ENDIF
450          particle_groups(i)%density_ratio = density_ratio(i)
451          particle_groups(i)%radius        = radius(i)
452       ENDDO
453
454!
455!--    Set a seed value for the random number generator to be exclusively
456!--    used for the particle code. The generated random numbers should be
457!--    different on the different PEs.
458       iran_part = iran_part + myid
459
460       CALL lpm_create_particle (PHASE_INIT)
461
462!
463!--    User modification of initial particles
464       CALL user_lpm_init
465
466!
467!--    Open file for statistical informations about particle conditions
468       IF ( write_particle_statistics )  THEN
469          CALL check_open( 80 )
470          WRITE ( 80, 8000 )  current_timestep_number, simulated_time,         &
471                              number_of_particles,                             &
472                              maximum_number_of_particles
473          CALL close_file( 80 )
474       ENDIF
475
476    ENDIF
477
478!
479!-- To avoid programm abort, assign particles array to the local version of
480!-- first grid cell
481    number_of_particles = prt_count(nzb+1,nys,nxl)
482    particles => grid_particles(nzb+1,nys,nxl)%particles(1:number_of_particles)
483
484!
485!-- Formats
4868000 FORMAT (I6,1X,F7.2,4X,I10,71X,I10)
487
488 END SUBROUTINE lpm_init
489
490!------------------------------------------------------------------------------!
491! Description:
492! ------------
493!> @todo Missing subroutine description.
494!------------------------------------------------------------------------------!
495 SUBROUTINE lpm_create_particle (phase)
496
497    USE lpm_exchange_horiz_mod,                                                &
498        ONLY: lpm_exchange_horiz, lpm_move_particle, realloc_particles_array
499
500    USE lpm_pack_arrays_mod,                                                   &
501        ONLY: lpm_pack_all_arrays
502
503    IMPLICIT  NONE
504
505    INTEGER(iwp)               ::  alloc_size  !<
506    INTEGER(iwp)               ::  i           !<
507    INTEGER(iwp)               ::  ip          !<
508    INTEGER(iwp)               ::  j           !<
509    INTEGER(iwp)               ::  jp          !<
510    INTEGER(iwp)               ::  kp          !<
511    INTEGER(iwp)               ::  loop_stride !<
512    INTEGER(iwp)               ::  n           !<
513    INTEGER(iwp)               ::  new_size    !<
514
515    INTEGER(iwp), INTENT(IN)   ::  phase       !<
516
517    INTEGER(iwp), DIMENSION(nzb:nzt+1,nysg:nyng,nxlg:nxrg) ::  local_count !<
518    INTEGER(iwp), DIMENSION(nzb:nzt+1,nysg:nyng,nxlg:nxrg) ::  local_start !<
519
520    LOGICAL                    ::  first_stride !<
521
522    REAL(wp)                   ::  pos_x !<
523    REAL(wp)                   ::  pos_y !<
524    REAL(wp)                   ::  pos_z !<
525
526    TYPE(particle_type),TARGET ::  tmp_particle !<
527
528!
529!-- Calculate particle positions and store particle attributes, if
530!-- particle is situated on this PE
531    DO  loop_stride = 1, 2
532       first_stride = (loop_stride == 1)
533       IF ( first_stride )   THEN
534          local_count = 0           ! count number of particles
535       ELSE
536          local_count = prt_count   ! Start address of new particles
537       ENDIF
538
539       n = 0
540       DO  i = 1, number_of_particle_groups
541
542          pos_z = psb(i)
543
544          DO WHILE ( pos_z <= pst(i) )
545
546             pos_y = pss(i)
547
548             DO WHILE ( pos_y <= psn(i) )
549
550                IF ( pos_y >= ( nys - 0.5_wp ) * dy  .AND.  &
551                     pos_y <  ( nyn + 0.5_wp ) * dy )  THEN
552
553                   pos_x = psl(i)
554
555            xloop: DO WHILE ( pos_x <= psr(i) )
556
557                      IF ( pos_x >= ( nxl - 0.5_wp ) * dx  .AND.  &
558                           pos_x <  ( nxr + 0.5_wp ) * dx )  THEN
559
560                         DO  j = 1, particles_per_point
561
562                            n = n + 1
563                            tmp_particle%x             = pos_x
564                            tmp_particle%y             = pos_y
565                            tmp_particle%z             = pos_z
566                            tmp_particle%age           = 0.0_wp
567                            tmp_particle%age_m         = 0.0_wp
568                            tmp_particle%dt_sum        = 0.0_wp
569                            tmp_particle%dvrp_psize    = 0.0_wp !unused
570                            tmp_particle%e_m           = 0.0_wp
571                            IF ( curvature_solution_effects )  THEN
572!
573!--                            Initial values (internal timesteps, derivative)
574!--                            for Rosenbrock method
575                               tmp_particle%rvar1      = 1.0E-12_wp
576                               tmp_particle%rvar2      = 1.0E-3_wp
577                               tmp_particle%rvar3      = -9999999.9_wp
578                            ELSE
579!
580!--                            Initial values for SGS velocities
581                               tmp_particle%rvar1      = 0.0_wp
582                               tmp_particle%rvar2      = 0.0_wp
583                               tmp_particle%rvar3      = 0.0_wp
584                            ENDIF
585                            tmp_particle%speed_x       = 0.0_wp
586                            tmp_particle%speed_y       = 0.0_wp
587                            tmp_particle%speed_z       = 0.0_wp
588                            tmp_particle%origin_x      = pos_x
589                            tmp_particle%origin_y      = pos_y
590                            tmp_particle%origin_z      = pos_z
591                            tmp_particle%radius        = particle_groups(i)%radius
592                            tmp_particle%weight_factor = initial_weighting_factor
593                            tmp_particle%class         = 1
594                            tmp_particle%group         = i
595                            tmp_particle%tailpoints    = 0     !unused
596                            tmp_particle%particle_mask = .TRUE.
597                            tmp_particle%tail_id       = 0     !unused
598
599!
600!--                         Determine the grid indices of the particle position
601                            ip = ( tmp_particle%x + 0.5_wp * dx ) * ddx
602                            jp = ( tmp_particle%y + 0.5_wp * dy ) * ddy
603                            kp = tmp_particle%z / dz + 1 + offset_ocean_nzt
604
605                            IF ( seed_follows_topography )  THEN
606!
607!--                            Particle height is given relative to topography
608                               kp = kp + nzb_w_inner(jp,ip)
609                               tmp_particle%z = tmp_particle%z + zw(kp)
610                               IF ( kp > nzt )  THEN
611                                  pos_x = pos_x + pdx(i)
612                                  CYCLE xloop
613                               ENDIF
614                            ENDIF
615
616                            local_count(kp,jp,ip) = local_count(kp,jp,ip) + 1
617                            IF ( .NOT. first_stride )  THEN
618                               IF ( ip < nxl  .OR.  jp < nys  .OR.  kp < nzb+1 )  THEN
619                                  write(6,*) 'xl ',ip,jp,kp,nxl,nys,nzb+1
620                               ENDIF
621                               IF ( ip > nxr  .OR.  jp > nyn  .OR.  kp > nzt )  THEN
622                                  write(6,*) 'xu ',ip,jp,kp,nxr,nyn,nzt
623                               ENDIF
624                               grid_particles(kp,jp,ip)%particles(local_count(kp,jp,ip)) = tmp_particle
625                            ENDIF
626                         ENDDO
627
628                      ENDIF
629
630                      pos_x = pos_x + pdx(i)
631
632                   ENDDO xloop
633
634                ENDIF
635
636                pos_y = pos_y + pdy(i)
637
638             ENDDO
639
640             pos_z = pos_z + pdz(i)
641
642          ENDDO
643
644       ENDDO
645
646       IF ( first_stride )  THEN
647          DO  ip = nxl, nxr
648             DO  jp = nys, nyn
649                DO  kp = nzb+1, nzt
650                   IF ( phase == PHASE_INIT )  THEN
651                      IF ( local_count(kp,jp,ip) > 0 )  THEN
652                         alloc_size = MAX( INT( local_count(kp,jp,ip) *        &
653                            ( 1.0_wp + alloc_factor / 100.0_wp ) ),            &
654                            min_nr_particle )
655                      ELSE
656                         alloc_size = min_nr_particle
657                      ENDIF
658                      ALLOCATE(grid_particles(kp,jp,ip)%particles(1:alloc_size))
659                      DO  n = 1, alloc_size
660                         grid_particles(kp,jp,ip)%particles(n) = zero_particle
661                      ENDDO
662                   ELSEIF ( phase == PHASE_RELEASE )  THEN
663                      IF ( local_count(kp,jp,ip) > 0 )  THEN
664                         new_size   = local_count(kp,jp,ip) + prt_count(kp,jp,ip)
665                         alloc_size = MAX( INT( new_size * ( 1.0_wp +          &
666                            alloc_factor / 100.0_wp ) ), min_nr_particle )
667                         IF( alloc_size > SIZE( grid_particles(kp,jp,ip)%particles) )  THEN
668                           CALL realloc_particles_array(ip,jp,kp,alloc_size)
669                         ENDIF
670                      ENDIF
671                   ENDIF
672                ENDDO
673             ENDDO
674          ENDDO
675       ENDIF
676    ENDDO
677
678    local_start = prt_count+1
679    prt_count   = local_count
680!
681!-- Add random fluctuation to particle positions
682    IF ( random_start_position )  THEN
683       DO  ip = nxl, nxr
684          DO  jp = nys, nyn
685             DO  kp = nzb+1, nzt
686                number_of_particles = prt_count(kp,jp,ip)
687                IF ( number_of_particles <= 0 )  CYCLE
688                particles => grid_particles(kp,jp,ip)%particles(1:number_of_particles)
689
690                DO  n = local_start(kp,jp,ip), number_of_particles              !Move only new particles
691                   IF ( psl(particles(n)%group) /= psr(particles(n)%group) )  THEN
692                      particles(n)%x = particles(n)%x +                        &
693                                   ( random_function( iran_part ) - 0.5_wp ) * &
694                                   pdx(particles(n)%group)
695                   ENDIF
696                   IF ( pss(particles(n)%group) /= psn(particles(n)%group) )  THEN
697                      particles(n)%y = particles(n)%y +                        &
698                                   ( random_function( iran_part ) - 0.5_wp ) * &
699                                   pdy(particles(n)%group)
700                   ENDIF
701                   IF ( psb(particles(n)%group) /= pst(particles(n)%group) )  THEN
702                      particles(n)%z = particles(n)%z +                        &
703                                   ( random_function( iran_part ) - 0.5_wp ) * &
704                                   pdz(particles(n)%group)
705                   ENDIF
706                ENDDO
707!
708!--             Identify particles located outside the model domain
709                CALL lpm_boundary_conds( 'bottom/top' )
710             ENDDO
711          ENDDO
712       ENDDO
713!
714!--    Exchange particles between grid cells and processors
715       CALL lpm_move_particle
716       CALL lpm_exchange_horiz
717
718    ENDIF
719!
720!-- In case of random_start_position, delete particles identified by
721!-- lpm_exchange_horiz and lpm_boundary_conds. Then sort particles into blocks,
722!-- which is needed for a fast interpolation of the LES fields on the particle
723!-- position.
724    CALL lpm_pack_all_arrays
725
726!
727!-- Determine maximum number of particles (i.e., all possible particles that
728!-- have been allocated) and the current number of particles
729    DO  ip = nxl, nxr
730       DO  jp = nys, nyn
731          DO  kp = nzb+1, nzt
732             maximum_number_of_particles = maximum_number_of_particles         &
733                                           + SIZE(grid_particles(kp,jp,ip)%particles)
734             number_of_particles         = number_of_particles                 &
735                                           + prt_count(kp,jp,ip)
736          ENDDO
737       ENDDO
738    ENDDO
739!
740!-- Calculate the number of particles of the total domain
741#if defined( __parallel )
742    IF ( collective_wait )  CALL MPI_BARRIER( comm2d, ierr )
743    CALL MPI_ALLREDUCE( number_of_particles, total_number_of_particles, 1, &
744    MPI_INTEGER, MPI_SUM, comm2d, ierr )
745#else
746    total_number_of_particles = number_of_particles
747#endif
748
749    RETURN
750
751 END SUBROUTINE lpm_create_particle
752
753END MODULE lpm_init_mod
Note: See TracBrowser for help on using the repository browser.