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

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

cloud physics variables renamed

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