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

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

added _mod string to several filenames to meet the naming convection for modules

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