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

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

last commit documented

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