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

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

last commit documented

  • Property svn:keywords set to Id
File size: 28.5 KB
Line 
1!> @file lpm_init_mod.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!
22!
23! Former revisions:
24! -----------------
25! $Id: lpm_init_mod.f90 1851 2016-04-08 13:32:50Z maronga $
26!
27! 1850 2016-04-08 13:29:27Z maronga
28! Module renamed
29!
30!
31! 1831 2016-04-07 13:15:51Z hoffmann
32! curvature_solution_effects moved to particle_attributes
33!
34! 1822 2016-04-07 07:49:42Z hoffmann
35! Unused variables removed.
36!
37! 1783 2016-03-06 18:36:17Z raasch
38! netcdf module added
39!
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!
44! 1691 2015-10-26 16:17:44Z maronga
45! Renamed prandtl_layer to constant_flux_layer.
46!
47! 1685 2015-10-08 07:32:13Z raasch
48! bugfix concerning vertical index offset in case of ocean
49!
50! 1682 2015-10-07 23:56:08Z knoop
51! Code annotations made doxygen readable
52!
53! 1575 2015-03-27 09:56:27Z raasch
54! initial vertical particle position is allowed to follow the topography
55!
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!
61! 1327 2014-03-21 11:00:16Z raasch
62! -netcdf_output
63!
64! 1322 2014-03-20 16:38:49Z raasch
65! REAL functions provided with KIND-attribute
66!
67! 1320 2014-03-20 08:40:49Z raasch
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
75!
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!
80! 1092 2013-02-02 11:24:22Z raasch
81! unused variables removed
82!
83! 1036 2012-10-22 13:43:42Z raasch
84! code put under GPL (PALM 3.9)
85!
86! 849 2012-03-15 10:35:09Z raasch
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
91!
92! 828 2012-02-21 12:00:36Z raasch
93! call of init_kernels, particle feature color renamed class
94!
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!
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!
103! Revision 1.1  1999/11/25 16:22:38  raasch
104! Initial revision
105!
106!
107! Description:
108! ------------
109!> This routine initializes a set of particles and their attributes (position,
110!> radius, ..) which are used by the Lagrangian particle model (see lpm).
111!------------------------------------------------------------------------------!
112 MODULE lpm_init_mod
113 
114
115    USE arrays_3d,                                                             &
116        ONLY:  de_dx, de_dy, de_dz, zu, zw, z0
117
118    USE control_parameters,                                                    &
119        ONLY:  cloud_droplets, constant_flux_layer, current_timestep_number,   &
120               dz, initializing_actions, message_string, ocean, simulated_time
121
122    USE grid_variables,                                                        &
123        ONLY:  ddx, dx, ddy, dy
124
125    USE indices,                                                               &
126        ONLY:  nx, nxl, nxlg, nxrg, nxr, ny, nyn, nys, nyng, nysg, nz, nzb,    &
127               nzb_w_inner, nzt
128
129    USE kinds
130
131    USE lpm_collision_kernels_mod,                                             &
132        ONLY:  init_kernels
133
134    USE netcdf_interface,                                                      &
135        ONLY:  netcdf_data_format
136
137    USE particle_attributes,                                                   &
138        ONLY:   alloc_factor, bc_par_b, bc_par_lr, bc_par_ns, bc_par_t,        &
139                block_offset, block_offset_def, collision_kernel,              &
140                curvature_solution_effects,                                    &
141                density_ratio, grid_particles,                                 &
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,    &
145                min_nr_particle, mpi_particle_type,                            &
146                number_of_particles,                                           &
147                number_of_particle_groups, number_of_sublayers,                &
148                offset_ocean_nzt, offset_ocean_nzt_m1,                         &
149                particles, particle_advection_start, particle_groups,          &
150                particle_groups_type, particles_per_point,                     &
151                particle_type, pdx, pdy, pdz,                                  &
152                prt_count, psb, psl, psn, psr, pss, pst,                       &
153                radius, random_start_position, read_particles_from_restartfile,&
154                seed_follows_topography, sort_count,                           &
155                total_number_of_particles,                                     &
156                use_sgs_for_particles,                                         &
157                write_particle_statistics, uniform_particles, zero_particle,   &
158                z0_av_global
159
160    USE pegrid
161
162    USE random_function_mod,                                                   &
163        ONLY:  random_function
164
165    IMPLICIT NONE
166
167    PRIVATE
168
169    INTEGER(iwp), PARAMETER         :: PHASE_INIT    = 1  !<
170    INTEGER(iwp), PARAMETER, PUBLIC :: PHASE_RELEASE = 2  !<
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
184!------------------------------------------------------------------------------!
185! Description:
186! ------------
187!> @todo Missing subroutine description.
188!------------------------------------------------------------------------------!
189 SUBROUTINE lpm_init
190
191    USE lpm_collision_kernels_mod,                                             &
192        ONLY:  init_kernels
193
194    IMPLICIT NONE
195
196    INTEGER(iwp) ::  i                           !<
197    INTEGER(iwp) ::  j                           !<
198    INTEGER(iwp) ::  k                           !<
199
200#if defined( __parallel )
201    INTEGER(iwp), DIMENSION(3) ::  blocklengths  !<
202    INTEGER(iwp), DIMENSION(3) ::  displacements !<
203    INTEGER(iwp), DIMENSION(3) ::  types         !<
204#endif
205
206    REAL(wp) ::  height_int                      !<
207    REAL(wp) ::  height_p                        !<
208    REAL(wp) ::  z_p                             !<
209    REAL(wp) ::  z0_av_local                     !<
210
211#if defined( __parallel )
212!
213!-- Define MPI derived datatype for FORTRAN datatype particle_type (see module
214!-- particle_attributes). Integer length is 4 byte, Real is 8 byte
215    blocklengths(1)  = 19;  blocklengths(2)  =   6;  blocklengths(3)  =   1
216    displacements(1) =  0;  displacements(2) = 152;  displacements(3) = 176
217
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!
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
234!
235!-- Define block offsets for dividing a gridcell in 8 sub cells
236
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)
245!
246!-- Check the number of particle groups.
247    IF ( number_of_particle_groups > max_number_of_particle_groups )  THEN
248       WRITE( message_string, * ) 'max_number_of_particle_groups =',      &
249                                  max_number_of_particle_groups ,         &
250                                  '&number_of_particle_groups reset to ', &
251                                  max_number_of_particle_groups
252       CALL message( 'lpm_init', 'PA0213', 0, 1, 0, 6, 0 )
253       number_of_particle_groups = max_number_of_particle_groups
254    ENDIF
255
256!
257!-- Set default start positions, if necessary
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)
264
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)
268
269    DO  j = 2, number_of_particle_groups
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)
279    ENDDO
280
281!
282!-- Allocate arrays required for calculating particle SGS velocities
283    IF ( use_sgs_for_particles  .AND.  .NOT. cloud_droplets )  THEN
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!
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).
297    IF ( constant_flux_layer )  THEN
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) )
308       z0_av_global = 0.0_wp
309
310#if defined( __parallel )
311       CALL MPI_ALLREDUCE(z0_av_local, z0_av_global, 1, MPI_REAL, MPI_SUM, &
312                          comm2d, ierr )
313#else
314       z0_av_global = z0_av_local
315#endif
316
317       z0_av_global = z0_av_global  / ( ( ny + 1 ) * ( nx + 1 ) )
318!
319!--    Horizontal wind speed is zero below and at z0
320       log_z_z0(0) = 0.0_wp
321!
322!--    Calculate vertical depth of the sublayers
323       height_int  = ( z_p - z0_av_global ) / REAL( number_of_sublayers, KIND=wp )
324!
325!--    Precalculate LOG(z/z0)
326       height_p    = 0.0_wp
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!
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!
403!-- Initialize collision kernels
404    IF ( collision_kernel /= 'none' )  CALL init_kernels
405
406!
407!-- For the first model run of a possible job chain initialize the
408!-- particles, otherwise read the particle data from restart file.
409    IF ( TRIM( initializing_actions ) == 'read_restart_data'  &
410         .AND.  read_particles_from_restartfile )  THEN
411
412       CALL lpm_read_restart_file
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.
419       ALLOCATE( prt_count(nzb:nzt+1,nysg:nyng,nxlg:nxrg), &
420                 grid_particles(nzb+1:nzt,nys:nyn,nxl:nxr) )
421
422       maximum_number_of_particles = 0
423       number_of_particles         = 0
424
425       sort_count = 0
426       prt_count  = 0
427
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.
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)
437
438       particle_groups = particle_groups_type( 0.0_wp, 0.0_wp, 0.0_wp, 0.0_wp )
439
440!
441!--    Set values for the density ratio and radius for all particle
442!--    groups, if necessary
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
445       DO  i = 2, number_of_particle_groups
446          IF ( density_ratio(i) == 9999999.9_wp )  THEN
447             density_ratio(i) = density_ratio(i-1)
448          ENDIF
449          IF ( radius(i) == 9999999.9_wp )  radius(i) = radius(i-1)
450       ENDDO
451
452       DO  i = 1, number_of_particle_groups
453          IF ( density_ratio(i) /= 0.0_wp  .AND.  radius(i) == 0 )  THEN
454             WRITE( message_string, * ) 'particle group #', i, 'has a', &
455                                        'density ratio /= 0 but radius = 0'
456             CALL message( 'lpm_init', 'PA0215', 1, 2, 0, 6, 0 )
457          ENDIF
458          particle_groups(i)%density_ratio = density_ratio(i)
459          particle_groups(i)%radius        = radius(i)
460       ENDDO
461
462!
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
468       CALL lpm_create_particle (PHASE_INIT)
469
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
498!------------------------------------------------------------------------------!
499! Description:
500! ------------
501!> @todo Missing subroutine description.
502!------------------------------------------------------------------------------!
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
511    IMPLICIT  NONE
512
513    INTEGER(iwp)               ::  alloc_size  !<
514    INTEGER(iwp)               ::  i           !<
515    INTEGER(iwp)               ::  ip          !<
516    INTEGER(iwp)               ::  j           !<
517    INTEGER(iwp)               ::  jp          !<
518    INTEGER(iwp)               ::  kp          !<
519    INTEGER(iwp)               ::  loop_stride !<
520    INTEGER(iwp)               ::  n           !<
521    INTEGER(iwp)               ::  new_size    !<
522
523    INTEGER(iwp), INTENT(IN)   ::  phase       !<
524
525    INTEGER(iwp), DIMENSION(nzb:nzt+1,nysg:nyng,nxlg:nxrg) ::  local_count !<
526    INTEGER(iwp), DIMENSION(nzb:nzt+1,nysg:nyng,nxlg:nxrg) ::  local_start !<
527
528    LOGICAL                    ::  first_stride !<
529
530    REAL(wp)                   ::  pos_x !<
531    REAL(wp)                   ::  pos_y !<
532    REAL(wp)                   ::  pos_z !<
533
534    TYPE(particle_type),TARGET ::  tmp_particle !<
535
536!
537!-- Calculate particle positions and store particle attributes, if
538!-- particle is situated on this PE
539    DO  loop_stride = 1, 2
540       first_stride = (loop_stride == 1)
541       IF ( first_stride )   THEN
542          local_count = 0           ! count number of particles
543       ELSE
544          local_count = prt_count   ! Start address of new particles
545       ENDIF
546
547       n = 0
548       DO  i = 1, number_of_particle_groups
549
550          pos_z = psb(i)
551
552          DO WHILE ( pos_z <= pst(i) )
553
554             pos_y = pss(i)
555
556             DO WHILE ( pos_y <= psn(i) )
557
558                IF ( pos_y >= ( nys - 0.5_wp ) * dy  .AND.  &
559                     pos_y <  ( nyn + 0.5_wp ) * dy )  THEN
560
561                   pos_x = psl(i)
562
563            xloop: DO WHILE ( pos_x <= psr(i) )
564
565                      IF ( pos_x >= ( nxl - 0.5_wp ) * dx  .AND.  &
566                           pos_x <  ( nxr + 0.5_wp ) * dx )  THEN
567
568                         DO  j = 1, particles_per_point
569
570                            n = n + 1
571                            tmp_particle%x             = pos_x
572                            tmp_particle%y             = pos_y
573                            tmp_particle%z             = pos_z
574                            tmp_particle%age           = 0.0_wp
575                            tmp_particle%age_m         = 0.0_wp
576                            tmp_particle%dt_sum        = 0.0_wp
577                            tmp_particle%dvrp_psize    = 0.0_wp !unused
578                            tmp_particle%e_m           = 0.0_wp
579                            IF ( curvature_solution_effects )  THEN
580!
581!--                            Initial values (internal timesteps, derivative)
582!--                            for Rosenbrock method
583                               tmp_particle%rvar1      = 1.0E-12_wp
584                               tmp_particle%rvar2      = 1.0E-3_wp
585                               tmp_particle%rvar3      = -9999999.9_wp
586                            ELSE
587!
588!--                            Initial values for SGS velocities
589                               tmp_particle%rvar1      = 0.0_wp
590                               tmp_particle%rvar2      = 0.0_wp
591                               tmp_particle%rvar3      = 0.0_wp
592                            ENDIF
593                            tmp_particle%speed_x       = 0.0_wp
594                            tmp_particle%speed_y       = 0.0_wp
595                            tmp_particle%speed_z       = 0.0_wp
596                            tmp_particle%origin_x      = pos_x
597                            tmp_particle%origin_y      = pos_y
598                            tmp_particle%origin_z      = pos_z
599                            tmp_particle%radius        = particle_groups(i)%radius
600                            tmp_particle%weight_factor = initial_weighting_factor
601                            tmp_particle%class         = 1
602                            tmp_particle%group         = i
603                            tmp_particle%tailpoints    = 0     !unused
604                            tmp_particle%particle_mask = .TRUE.
605                            tmp_particle%tail_id       = 0     !unused
606
607!
608!--                         Determine the grid indices of the particle position
609                            ip = ( tmp_particle%x + 0.5_wp * dx ) * ddx
610                            jp = ( tmp_particle%y + 0.5_wp * dy ) * ddy
611                            kp = tmp_particle%z / dz + 1 + offset_ocean_nzt
612
613                            IF ( seed_follows_topography )  THEN
614!
615!--                            Particle height is given relative to topography
616                               kp = kp + nzb_w_inner(jp,ip)
617                               tmp_particle%z = tmp_particle%z + zw(kp)
618                               IF ( kp > nzt )  THEN
619                                  pos_x = pos_x + pdx(i)
620                                  CYCLE xloop
621                               ENDIF
622                            ENDIF
623
624                            local_count(kp,jp,ip) = local_count(kp,jp,ip) + 1
625                            IF ( .NOT. first_stride )  THEN
626                               IF ( ip < nxl  .OR.  jp < nys  .OR.  kp < nzb+1 )  THEN
627                                  write(6,*) 'xl ',ip,jp,kp,nxl,nys,nzb+1
628                               ENDIF
629                               IF ( ip > nxr  .OR.  jp > nyn  .OR.  kp > nzt )  THEN
630                                  write(6,*) 'xu ',ip,jp,kp,nxr,nyn,nzt
631                               ENDIF
632                               grid_particles(kp,jp,ip)%particles(local_count(kp,jp,ip)) = tmp_particle
633                            ENDIF
634                         ENDDO
635
636                      ENDIF
637
638                      pos_x = pos_x + pdx(i)
639
640                   ENDDO xloop
641
642                ENDIF
643
644                pos_y = pos_y + pdy(i)
645
646             ENDDO
647
648             pos_z = pos_z + pdz(i)
649
650          ENDDO
651
652       ENDDO
653
654       IF ( first_stride )  THEN
655          DO  ip = nxl, nxr
656             DO  jp = nys, nyn
657                DO  kp = nzb+1, nzt
658                   IF ( phase == PHASE_INIT )  THEN
659                      IF ( local_count(kp,jp,ip) > 0 )  THEN
660                         alloc_size = MAX( INT( local_count(kp,jp,ip) *        &
661                            ( 1.0_wp + alloc_factor / 100.0_wp ) ),            &
662                            min_nr_particle )
663                      ELSE
664                         alloc_size = min_nr_particle
665                      ENDIF
666                      ALLOCATE(grid_particles(kp,jp,ip)%particles(1:alloc_size))
667                      DO  n = 1, alloc_size
668                         grid_particles(kp,jp,ip)%particles(n) = zero_particle
669                      ENDDO
670                   ELSEIF ( phase == PHASE_RELEASE )  THEN
671                      IF ( local_count(kp,jp,ip) > 0 )  THEN
672                         new_size   = local_count(kp,jp,ip) + prt_count(kp,jp,ip)
673                         alloc_size = MAX( INT( new_size * ( 1.0_wp +          &
674                            alloc_factor / 100.0_wp ) ), min_nr_particle )
675                         IF( alloc_size > SIZE( grid_particles(kp,jp,ip)%particles) )  THEN
676                           CALL realloc_particles_array(ip,jp,kp,alloc_size)
677                         ENDIF
678                      ENDIF
679                   ENDIF
680                ENDDO
681             ENDDO
682          ENDDO
683       ENDIF
684    ENDDO
685
686    local_start = prt_count+1
687    prt_count   = local_count
688!
689!-- Add random fluctuation to particle positions
690    IF ( random_start_position )  THEN
691       DO  ip = nxl, nxr
692          DO  jp = nys, nyn
693             DO  kp = nzb+1, nzt
694                number_of_particles = prt_count(kp,jp,ip)
695                IF ( number_of_particles <= 0 )  CYCLE
696                particles => grid_particles(kp,jp,ip)%particles(1:number_of_particles)
697
698                DO  n = local_start(kp,jp,ip), number_of_particles              !Move only new particles
699                   IF ( psl(particles(n)%group) /= psr(particles(n)%group) )  THEN
700                      particles(n)%x = particles(n)%x +                        &
701                                   ( random_function( iran_part ) - 0.5_wp ) * &
702                                   pdx(particles(n)%group)
703                   ENDIF
704                   IF ( pss(particles(n)%group) /= psn(particles(n)%group) )  THEN
705                      particles(n)%y = particles(n)%y +                        &
706                                   ( random_function( iran_part ) - 0.5_wp ) * &
707                                   pdy(particles(n)%group)
708                   ENDIF
709                   IF ( psb(particles(n)%group) /= pst(particles(n)%group) )  THEN
710                      particles(n)%z = particles(n)%z +                        &
711                                   ( random_function( iran_part ) - 0.5_wp ) * &
712                                   pdz(particles(n)%group)
713                   ENDIF
714                ENDDO
715!
716!--             Identify particles located outside the model domain
717                CALL lpm_boundary_conds( 'bottom/top' )
718             ENDDO
719          ENDDO
720       ENDDO
721!
722!--    Exchange particles between grid cells and processors
723       CALL lpm_move_particle
724       CALL lpm_exchange_horiz
725
726    ENDIF
727!
728!-- In case of random_start_position, delete particles identified by
729!-- lpm_exchange_horiz and lpm_boundary_conds. Then sort particles into blocks,
730!-- which is needed for a fast interpolation of the LES fields on the particle
731!-- position.
732    CALL lpm_pack_all_arrays
733
734!
735!-- Determine maximum number of particles (i.e., all possible particles that
736!-- have been allocated) and the current number of particles
737    DO  ip = nxl, nxr
738       DO  jp = nys, nyn
739          DO  kp = nzb+1, nzt
740             maximum_number_of_particles = maximum_number_of_particles         &
741                                           + SIZE(grid_particles(kp,jp,ip)%particles)
742             number_of_particles         = number_of_particles                 &
743                                           + prt_count(kp,jp,ip)
744          ENDDO
745       ENDDO
746    ENDDO
747!
748!-- Calculate the number of particles of the total domain
749#if defined( __parallel )
750    IF ( collective_wait )  CALL MPI_BARRIER( comm2d, ierr )
751    CALL MPI_ALLREDUCE( number_of_particles, total_number_of_particles, 1, &
752    MPI_INTEGER, MPI_SUM, comm2d, ierr )
753#else
754    total_number_of_particles = number_of_particles
755#endif
756
757    RETURN
758
759 END SUBROUTINE lpm_create_particle
760
761END MODULE lpm_init_mod
Note: See TracBrowser for help on using the repository browser.