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

Last change on this file since 1575 was 1575, checked in by raasch, 9 years ago

optimized multigrid method installed, new parameter seed_follows_topography for particle release, small adjustment in subjob for HLRN

  • Property svn:keywords set to Id
File size: 35.6 KB
Line 
1 MODULE lpm_init_mod
2
3!--------------------------------------------------------------------------------!
4! This file is part of PALM.
5!
6! PALM is free software: you can redistribute it and/or modify it under the terms
7! of the GNU General Public License as published by the Free Software Foundation,
8! either version 3 of the License, or (at your option) any later version.
9!
10! PALM is distributed in the hope that it will be useful, but WITHOUT ANY
11! WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12! A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
13!
14! You should have received a copy of the GNU General Public License along with
15! PALM. If not, see <http://www.gnu.org/licenses/>.
16!
17! Copyright 1997-2014 Leibniz Universitaet Hannover
18!--------------------------------------------------------------------------------!
19!
20! Current revisions:
21! -----------------
22! initial vertical particle position is allowed to follow the topography
23!
24! Former revisions:
25! -----------------
26! $Id: lpm_init.f90 1575 2015-03-27 09:56:27Z raasch $
27!
28! 1359 2014-04-11 17:15:14Z hoffmann
29! New particle structure integrated.
30! Kind definition added to all floating point numbers.
31! lpm_init changed form a subroutine to a module.
32!
33! 1327 2014-03-21 11:00:16Z raasch
34! -netcdf_output
35!
36! 1322 2014-03-20 16:38:49Z raasch
37! REAL functions provided with KIND-attribute
38!
39! 1320 2014-03-20 08:40:49Z raasch
40! ONLY-attribute added to USE-statements,
41! kind-parameters added to all INTEGER and REAL declaration statements,
42! kinds are defined in new module kinds,
43! revision history before 2012 removed,
44! comment fields (!:) to be used for variable explanations added to
45! all variable declaration statements
46! bugfix: #if defined( __parallel ) added
47!
48! 1314 2014-03-14 18:25:17Z suehring
49! Vertical logarithmic interpolation of horizontal particle speed for particles
50! between roughness height and first vertical grid level.
51!
52! 1092 2013-02-02 11:24:22Z raasch
53! unused variables removed
54!
55! 1036 2012-10-22 13:43:42Z raasch
56! code put under GPL (PALM 3.9)
57!
58! 849 2012-03-15 10:35:09Z raasch
59! routine renamed: init_particles -> lpm_init
60! de_dx, de_dy, de_dz are allocated here (instead of automatic arrays in
61! advec_particles),
62! sort_particles renamed lpm_sort_arrays, user_init_particles renamed lpm_init
63!
64! 828 2012-02-21 12:00:36Z raasch
65! call of init_kernels, particle feature color renamed class
66!
67! 824 2012-02-17 09:09:57Z raasch
68! particle attributes speed_x|y|z_sgs renamed rvar1|2|3,
69! array particles implemented as pointer
70!
71! 667 2010-12-23 12:06:00Z suehring/gryschka
72! nxl-1, nxr+1, nys-1, nyn+1 replaced by nxlg, nxrg, nysg, nyng for allocation
73! of arrays.
74!
75! Revision 1.1  1999/11/25 16:22:38  raasch
76! Initial revision
77!
78!
79! Description:
80! ------------
81! This routine initializes a set of particles and their attributes (position,
82! radius, ..) which are used by the Lagrangian particle model (see lpm).
83!------------------------------------------------------------------------------!
84
85    USE arrays_3d,                                                             &
86        ONLY:  de_dx, de_dy, de_dz, zu, zw, z0
87
88    USE cloud_parameters,                                                      &
89        ONLY:  curvature_solution_effects
90
91    USE control_parameters,                                                    &
92        ONLY:  cloud_droplets, current_timestep_number, dz,                    &
93               initializing_actions, message_string, netcdf_data_format,       &
94               ocean, prandtl_layer, simulated_time
95
96    USE dvrp_variables,                                                        &
97        ONLY:  particle_color, particle_dvrpsize
98
99    USE grid_variables,                                                        &
100        ONLY:  ddx, dx, ddy, dy
101
102    USE indices,                                                               &
103        ONLY:  nx, nxl, nxlg, nxrg, nxr, ny, nyn, nys, nyng, nysg, nz, nzb,    &
104               nzb_w_inner, nzt
105
106    USE kinds
107
108    USE lpm_collision_kernels_mod,                                             &
109        ONLY:  init_kernels
110
111    USE particle_attributes,                                                   &
112        ONLY:   alloc_factor, bc_par_b, bc_par_lr, bc_par_ns, bc_par_t,        &
113                block_offset, block_offset_def, collision_kernel,              &
114                density_ratio, dvrp_psize, grid_particles,                     &
115                initial_weighting_factor, ibc_par_b, ibc_par_lr, ibc_par_ns,   &
116                ibc_par_t, iran_part, log_z_z0,                                &
117                max_number_of_particle_groups, maximum_number_of_particles,    &
118                maximum_number_of_tailpoints, maximum_number_of_tails,         &
119                minimum_tailpoint_distance, min_nr_particle,                   &
120                mpi_particle_type, new_tail_id,                                &
121                number_of_initial_tails, number_of_particles,                  &
122                number_of_particle_groups, number_of_sublayers,                &
123                number_of_tails, offset_ocean_nzt, offset_ocean_nzt_m1,        & 
124                particles, particle_advection_start, particle_groups,          &
125                particle_groups_type, particles_per_point,                     &
126                particle_tail_coordinates,  particle_type, pdx, pdy, pdz,      &
127                prt_count, psb, psl, psn, psr, pss, pst,                       &
128                radius, random_start_position, read_particles_from_restartfile,&
129                seed_follows_topography, skip_particles_for_tail, sort_count,  &
130                tail_mask, total_number_of_particles, total_number_of_tails,   &
131                use_particle_tails, use_sgs_for_particles,                     &
132                write_particle_statistics, uniform_particles, zero_particle,   &
133                z0_av_global
134
135    USE pegrid
136
137    USE random_function_mod,                                                   &
138        ONLY:  random_function
139
140    IMPLICIT NONE
141
142    PRIVATE
143
144    INTEGER(iwp), PARAMETER         :: PHASE_INIT    = 1  !:
145    INTEGER(iwp), PARAMETER, PUBLIC :: PHASE_RELEASE = 2  !:
146
147    INTERFACE lpm_init
148       MODULE PROCEDURE lpm_init
149    END INTERFACE lpm_init
150
151    INTERFACE lpm_create_particle
152       MODULE PROCEDURE lpm_create_particle
153    END INTERFACE lpm_create_particle
154
155    PUBLIC lpm_init, lpm_create_particle
156
157CONTAINS
158
159 SUBROUTINE lpm_init
160
161    USE lpm_collision_kernels_mod,                                             &
162        ONLY:  init_kernels
163
164    IMPLICIT NONE
165
166    INTEGER(iwp) ::  i                           !:
167    INTEGER(iwp) ::  ip                          !:
168    INTEGER(iwp) ::  j                           !:
169    INTEGER(iwp) ::  jp                          !:
170    INTEGER(iwp) ::  k                           !:
171    INTEGER(iwp) ::  kp                          !:
172    INTEGER(iwp) ::  n                           !:
173    INTEGER(iwp) ::  nn                          !:
174
175#if defined( __parallel )
176    INTEGER(iwp), DIMENSION(3) ::  blocklengths  !:
177    INTEGER(iwp), DIMENSION(3) ::  displacements !:
178    INTEGER(iwp), DIMENSION(3) ::  types         !:
179#endif
180    LOGICAL ::  uniform_particles_l              !:
181
182    REAL(wp) ::  height_int                      !:
183    REAL(wp) ::  height_p                        !:
184    REAL(wp) ::  z_p                             !:
185    REAL(wp) ::  z0_av_local                     !:
186
187#if defined( __parallel )
188!
189!-- Define MPI derived datatype for FORTRAN datatype particle_type (see module
190!-- particle_attributes). Integer length is 4 byte, Real is 8 byte
191#if defined( __twocachelines )
192    blocklengths(1)  =  7;  blocklengths(2)  =  18;  blocklengths(3)  =   1
193    displacements(1) =  0;  displacements(2) =  64;  displacements(3) = 128
194
195    types(1) = MPI_REAL                               ! 64 bit words
196    types(2) = MPI_INTEGER                            ! 32 Bit words
197    types(3) = MPI_UB
198#else
199    blocklengths(1)  = 19;  blocklengths(2)  =   6;  blocklengths(3)  =   1
200    displacements(1) =  0;  displacements(2) = 152;  displacements(3) = 176
201
202    types(1) = MPI_REAL
203    types(2) = MPI_INTEGER
204    types(3) = MPI_UB
205#endif
206    CALL MPI_TYPE_STRUCT( 3, blocklengths, displacements, types, &
207                          mpi_particle_type, ierr )
208    CALL MPI_TYPE_COMMIT( mpi_particle_type, ierr )
209#endif
210
211!
212!-- In case of oceans runs, the vertical index calculations need an offset,
213!-- because otherwise the k indices will become negative
214    IF ( ocean )  THEN
215       offset_ocean_nzt    = nzt
216       offset_ocean_nzt_m1 = nzt - 1
217    ENDIF
218
219!
220!-- Define block offsets for dividing a gridcell in 8 sub cells
221
222    block_offset(0) = block_offset_def (-1,-1,-1)
223    block_offset(1) = block_offset_def (-1,-1, 0)
224    block_offset(2) = block_offset_def (-1, 0,-1)
225    block_offset(3) = block_offset_def (-1, 0, 0)
226    block_offset(4) = block_offset_def ( 0,-1,-1)
227    block_offset(5) = block_offset_def ( 0,-1, 0)
228    block_offset(6) = block_offset_def ( 0, 0,-1)
229    block_offset(7) = block_offset_def ( 0, 0, 0)
230!
231!-- Check the number of particle groups.
232    IF ( number_of_particle_groups > max_number_of_particle_groups )  THEN
233       WRITE( message_string, * ) 'max_number_of_particle_groups =',      &
234                                  max_number_of_particle_groups ,         &
235                                  '&number_of_particle_groups reset to ', &
236                                  max_number_of_particle_groups
237       CALL message( 'lpm_init', 'PA0213', 0, 1, 0, 6, 0 )
238       number_of_particle_groups = max_number_of_particle_groups
239    ENDIF
240
241!
242!-- Set default start positions, if necessary
243    IF ( psl(1) == 9999999.9_wp )  psl(1) = -0.5_wp * dx
244    IF ( psr(1) == 9999999.9_wp )  psr(1) = ( nx + 0.5_wp ) * dx
245    IF ( pss(1) == 9999999.9_wp )  pss(1) = -0.5_wp * dy
246    IF ( psn(1) == 9999999.9_wp )  psn(1) = ( ny + 0.5_wp ) * dy
247    IF ( psb(1) == 9999999.9_wp )  psb(1) = zu(nz/2)
248    IF ( pst(1) == 9999999.9_wp )  pst(1) = psb(1)
249
250    IF ( pdx(1) == 9999999.9_wp  .OR.  pdx(1) == 0.0_wp )  pdx(1) = dx
251    IF ( pdy(1) == 9999999.9_wp  .OR.  pdy(1) == 0.0_wp )  pdy(1) = dy
252    IF ( pdz(1) == 9999999.9_wp  .OR.  pdz(1) == 0.0_wp )  pdz(1) = zu(2) - zu(1)
253
254    DO  j = 2, number_of_particle_groups
255       IF ( psl(j) == 9999999.9_wp )  psl(j) = psl(j-1)
256       IF ( psr(j) == 9999999.9_wp )  psr(j) = psr(j-1)
257       IF ( pss(j) == 9999999.9_wp )  pss(j) = pss(j-1)
258       IF ( psn(j) == 9999999.9_wp )  psn(j) = psn(j-1)
259       IF ( psb(j) == 9999999.9_wp )  psb(j) = psb(j-1)
260       IF ( pst(j) == 9999999.9_wp )  pst(j) = pst(j-1)
261       IF ( pdx(j) == 9999999.9_wp  .OR.  pdx(j) == 0.0_wp )  pdx(j) = pdx(j-1)
262       IF ( pdy(j) == 9999999.9_wp  .OR.  pdy(j) == 0.0_wp )  pdy(j) = pdy(j-1)
263       IF ( pdz(j) == 9999999.9_wp  .OR.  pdz(j) == 0.0_wp )  pdz(j) = pdz(j-1)
264    ENDDO
265
266!
267!-- Allocate arrays required for calculating particle SGS velocities
268    IF ( use_sgs_for_particles )  THEN
269       ALLOCATE( de_dx(nzb:nzt+1,nysg:nyng,nxlg:nxrg), &
270                 de_dy(nzb:nzt+1,nysg:nyng,nxlg:nxrg), &
271                 de_dz(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
272    ENDIF
273
274!
275!-- Allocate array required for logarithmic vertical interpolation of
276!-- horizontal particle velocities between the surface and the first vertical
277!-- grid level. In order to avoid repeated CPU cost-intensive CALLS of
278!-- intrinsic FORTRAN procedure LOG(z/z0), LOG(z/z0) is precalculated for
279!-- several heights. Splitting into 20 sublayers turned out to be sufficient.
280!-- To obtain exact height levels of particles, linear interpolation is applied
281!-- (see lpm_advec.f90).
282    IF ( prandtl_layer )  THEN
283       
284       ALLOCATE ( log_z_z0(0:number_of_sublayers) ) 
285       z_p         = zu(nzb+1) - zw(nzb)
286
287!
288!--    Calculate horizontal mean value of z0 used for logartihmic
289!--    interpolation. Note: this is not exact for heterogeneous z0.
290!--    However, sensitivity studies showed that the effect is
291!--    negligible.
292       z0_av_local  = SUM( z0(nys:nyn,nxl:nxr) )
293       z0_av_global = 0.0_wp
294
295#if defined( __parallel )
296       CALL MPI_ALLREDUCE(z0_av_local, z0_av_global, 1, MPI_REAL, MPI_SUM, &
297                          comm2d, ierr )
298#else
299       z0_av_global = z0_av_local
300#endif
301
302       z0_av_global = z0_av_global  / ( ( ny + 1 ) * ( nx + 1 ) )
303!
304!--    Horizontal wind speed is zero below and at z0
305       log_z_z0(0) = 0.0_wp
306!
307!--    Calculate vertical depth of the sublayers
308       height_int  = ( z_p - z0_av_global ) / REAL( number_of_sublayers, KIND=wp )
309!
310!--    Precalculate LOG(z/z0)
311       height_p    = 0.0_wp
312       DO  k = 1, number_of_sublayers
313
314          height_p    = height_p + height_int
315          log_z_z0(k) = LOG( height_p / z0_av_global )
316
317       ENDDO
318
319
320    ENDIF
321
322!
323!-- Check boundary condition and set internal variables
324    SELECT CASE ( bc_par_b )
325   
326       CASE ( 'absorb' )
327          ibc_par_b = 1
328
329       CASE ( 'reflect' )
330          ibc_par_b = 2
331         
332       CASE DEFAULT
333          WRITE( message_string, * )  'unknown boundary condition ',   &
334                                       'bc_par_b = "', TRIM( bc_par_b ), '"'
335          CALL message( 'lpm_init', 'PA0217', 1, 2, 0, 6, 0 )
336         
337    END SELECT
338    SELECT CASE ( bc_par_t )
339   
340       CASE ( 'absorb' )
341          ibc_par_t = 1
342
343       CASE ( 'reflect' )
344          ibc_par_t = 2
345         
346       CASE DEFAULT
347          WRITE( message_string, * ) 'unknown boundary condition ',   &
348                                     'bc_par_t = "', TRIM( bc_par_t ), '"'
349          CALL message( 'lpm_init', 'PA0218', 1, 2, 0, 6, 0 )
350         
351    END SELECT
352    SELECT CASE ( bc_par_lr )
353
354       CASE ( 'cyclic' )
355          ibc_par_lr = 0
356
357       CASE ( 'absorb' )
358          ibc_par_lr = 1
359
360       CASE ( 'reflect' )
361          ibc_par_lr = 2
362         
363       CASE DEFAULT
364          WRITE( message_string, * ) 'unknown boundary condition ',   &
365                                     'bc_par_lr = "', TRIM( bc_par_lr ), '"'
366          CALL message( 'lpm_init', 'PA0219', 1, 2, 0, 6, 0 )
367         
368    END SELECT
369    SELECT CASE ( bc_par_ns )
370
371       CASE ( 'cyclic' )
372          ibc_par_ns = 0
373
374       CASE ( 'absorb' )
375          ibc_par_ns = 1
376
377       CASE ( 'reflect' )
378          ibc_par_ns = 2
379         
380       CASE DEFAULT
381          WRITE( message_string, * ) 'unknown boundary condition ',   &
382                                     'bc_par_ns = "', TRIM( bc_par_ns ), '"'
383          CALL message( 'lpm_init', 'PA0220', 1, 2, 0, 6, 0 )
384         
385    END SELECT
386
387!
388!-- Initialize collision kernels
389    IF ( collision_kernel /= 'none' )  CALL init_kernels
390
391!
392!-- For the first model run of a possible job chain initialize the
393!-- particles, otherwise read the particle data from restart file.
394    IF ( TRIM( initializing_actions ) == 'read_restart_data'  &
395         .AND.  read_particles_from_restartfile )  THEN
396
397       CALL lpm_read_restart_file
398
399    ELSE
400
401!
402!--    Allocate particle arrays and set attributes of the initial set of
403!--    particles, which can be also periodically released at later times.
404!--    Also allocate array for particle tail coordinates, if needed.
405       ALLOCATE( prt_count(nzb:nzt+1,nysg:nyng,nxlg:nxrg), &
406                 grid_particles(nzb+1:nzt,nys:nyn,nxl:nxr) )
407
408       maximum_number_of_particles = 0
409       number_of_particles         = 0
410
411       sort_count = 0
412       prt_count  = 0
413
414!
415!--    Initialize all particles with dummy values (otherwise errors may
416!--    occur within restart runs). The reason for this is still not clear
417!--    and may be presumably caused by errors in the respective user-interface.
418#if defined( __twocachelines )
419       zero_particle = particle_type( 0.0_wp, 0.0_sp, 0.0_sp, 0.0_sp, 0.0_sp,  &
420                                      0.0_sp, 0.0_sp, 0.0_wp, 0.0_wp, 0.0_wp,  &
421                                      0, .FALSE., 0.0_wp, 0.0_wp, 0.0_wp,      &
422                                      0.0_sp, 0.0_sp, 0.0_sp, 0.0_sp, 0.0_sp,  &
423                                      0.0_sp, 0, 0, 0, -1)
424#else
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#endif
431       particle_groups = particle_groups_type( 0.0_wp, 0.0_wp, 0.0_wp, 0.0_wp )
432
433!
434!--    Set the default particle size used for dvrp plots
435       IF ( dvrp_psize == 9999999.9_wp )  dvrp_psize = 0.2_wp * dx
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       CALL lpm_create_particle (PHASE_INIT)
460!
461!--    Set a seed value for the random number generator to be exclusively
462!--    used for the particle code. The generated random numbers should be
463!--    different on the different PEs.
464       iran_part = iran_part + myid
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!
481!--    Check if particles are really uniform in color and radius (dvrp_size)
482!--    (uniform_particles is preset TRUE)
483       IF ( uniform_particles )  THEN
484          DO  ip = nxl, nxr
485             DO  jp = nys, nyn
486                DO  kp = nzb+1, nzt
487
488                   n = prt_count(kp,jp,ip)
489                   IF ( MINVAL( grid_particles(kp,jp,ip)%particles(1:n)%dvrp_psize  ) ==     &
490                        MAXVAL( grid_particles(kp,jp,ip)%particles(1:n)%dvrp_psize  )  .AND. &
491                        MINVAL( grid_particles(kp,jp,ip)%particles(1:n)%class ) ==           &
492                        MAXVAL( grid_particles(kp,jp,ip)%particles(1:n)%class ) )  THEN
493                      uniform_particles_l = .TRUE.
494                   ELSE
495                      uniform_particles_l = .FALSE.
496                   ENDIF
497
498                ENDDO
499             ENDDO
500          ENDDO
501
502#if defined( __parallel )
503          IF ( collective_wait )  CALL MPI_BARRIER( comm2d, ierr )
504          CALL MPI_ALLREDUCE( uniform_particles_l, uniform_particles, 1,       &
505                              MPI_LOGICAL, MPI_LAND, comm2d, ierr )
506#else
507          uniform_particles = uniform_particles_l
508#endif
509
510       ENDIF
511
512!
513!--    Particles will probably become none-uniform, if their size and color
514!--    will be determined by flow variables
515       IF ( particle_color /= 'none'  .OR.  particle_dvrpsize /= 'none' )  THEN
516          uniform_particles = .FALSE.
517       ENDIF
518
519! !kk    Not implemented aft individual particle array fort every gridcell
520! !
521! !--    Set the beginning of the particle tails and their age
522!        IF ( use_particle_tails )  THEN
523! !
524! !--       Choose the maximum number of tails with respect to the maximum number
525! !--       of particles and skip_particles_for_tail
526!           maximum_number_of_tails = maximum_number_of_particles / &
527!                                     skip_particles_for_tail
528!
529! !
530! !--       Create a minimum number of tails in case that there is no tail
531! !--       initially (otherwise, index errors will occur when adressing the
532! !--       arrays below)
533!           IF ( maximum_number_of_tails == 0 )  maximum_number_of_tails = 10
534!
535!           ALLOCATE( particle_tail_coordinates(maximum_number_of_tailpoints,5, &
536!                     maximum_number_of_tails),                                 &
537!                     new_tail_id(maximum_number_of_tails),                     &
538!                     tail_mask(maximum_number_of_tails) )
539!
540!           particle_tail_coordinates  = 0.0_wp
541!           minimum_tailpoint_distance = minimum_tailpoint_distance**2
542!           number_of_initial_tails    = number_of_tails
543!
544!           nn = 0
545!           DO  n = 1, number_of_particles
546! !
547! !--          Only for those particles marked above with a provisional tail_id
548! !--          tails will be created. Particles now get their final tail_id.
549!              IF ( particles(n)%tail_id /= 0 )  THEN
550!
551!                 nn = nn + 1
552!                 particles(n)%tail_id = nn
553!
554!                 particle_tail_coordinates(1,1,nn) = particles(n)%x
555!                 particle_tail_coordinates(1,2,nn) = particles(n)%y
556!                 particle_tail_coordinates(1,3,nn) = particles(n)%z
557!                 particle_tail_coordinates(1,4,nn) = particles(n)%class
558!                 particles(n)%tailpoints = 1
559!                 IF ( minimum_tailpoint_distance /= 0.0_wp )  THEN
560!                    particle_tail_coordinates(2,1,nn) = particles(n)%x
561!                    particle_tail_coordinates(2,2,nn) = particles(n)%y
562!                    particle_tail_coordinates(2,3,nn) = particles(n)%z
563!                    particle_tail_coordinates(2,4,nn) = particles(n)%class
564!                    particle_tail_coordinates(1:2,5,nn) = 0.0_wp
565!                    particles(n)%tailpoints = 2
566!                 ENDIF
567!
568!              ENDIF
569!           ENDDO
570!        ENDIF
571!
572! !
573! !--    Plot initial positions of particles (only if particle advection is
574! !--    switched on from the beginning of the simulation (t=0))
575!        IF ( particle_advection_start == 0.0_wp )  CALL data_output_dvrp
576
577    ENDIF
578
579!
580!-- To avoid programm abort, assign particles array to the local version of
581!-- first grid cell
582    number_of_particles = prt_count(nzb+1,nys,nxl)
583    particles => grid_particles(nzb+1,nys,nxl)%particles(1:number_of_particles)
584
585!
586!-- Formats
5878000 FORMAT (I6,1X,F7.2,4X,I10,71X,I10)
588
589 END SUBROUTINE lpm_init
590
591 SUBROUTINE lpm_create_particle (phase)
592
593    USE lpm_exchange_horiz_mod,                                                &
594        ONLY: lpm_exchange_horiz, lpm_move_particle, realloc_particles_array
595
596    USE lpm_pack_arrays_mod,                                                   &
597        ONLY: lpm_pack_all_arrays
598
599    IMPLICIT  NONE
600
601    INTEGER(iwp)               ::  alloc_size  !:
602    INTEGER(iwp)               ::  i           !:
603    INTEGER(iwp)               ::  ip          !:
604    INTEGER(iwp)               ::  j           !:
605    INTEGER(iwp)               ::  jp          !:
606    INTEGER(iwp)               ::  kp          !:
607    INTEGER(iwp)               ::  loop_stride !:
608    INTEGER(iwp)               ::  n           !:
609    INTEGER(iwp)               ::  new_size    !:
610    INTEGER(iwp)               ::  nn          !:
611
612    INTEGER(iwp), INTENT(IN)   ::  phase       !:
613
614    INTEGER(iwp), DIMENSION(nzb:nzt+1,nysg:nyng,nxlg:nxrg) ::  local_count !:
615    INTEGER(iwp), DIMENSION(nzb:nzt+1,nysg:nyng,nxlg:nxrg) ::  local_start !:
616
617    LOGICAL                    ::  first_stride !:
618
619    REAL(wp)                   ::  pos_x !:
620    REAL(wp)                   ::  pos_y !:
621    REAL(wp)                   ::  pos_z !:
622
623    TYPE(particle_type),TARGET ::  tmp_particle !:
624
625!
626!-- Calculate particle positions and store particle attributes, if
627!-- particle is situated on this PE
628    DO  loop_stride = 1, 2
629       first_stride = (loop_stride == 1)
630       IF ( first_stride )   THEN
631          local_count = 0           ! count number of particles
632       ELSE
633          local_count = prt_count   ! Start address of new particles
634       ENDIF
635
636       n = 0
637       DO  i = 1, number_of_particle_groups
638
639          pos_z = psb(i)
640
641          DO WHILE ( pos_z <= pst(i) )
642
643             pos_y = pss(i)
644
645             DO WHILE ( pos_y <= psn(i) )
646
647                IF ( pos_y >= ( nys - 0.5_wp ) * dy  .AND.  &
648                     pos_y <  ( nyn + 0.5_wp ) * dy )  THEN
649
650                   pos_x = psl(i)
651
652            xloop: DO WHILE ( pos_x <= psr(i) )
653
654                      IF ( pos_x >= ( nxl - 0.5_wp ) * dx  .AND.  &
655                           pos_x <  ( nxr + 0.5_wp ) * dx )  THEN
656
657                         DO  j = 1, particles_per_point
658
659                            n = n + 1
660#if defined( __twocachelines )
661                            tmp_particle%x             = pos_x
662                            tmp_particle%y             = pos_y
663                            tmp_particle%z             = pos_z
664                            tmp_particle%age           = 0.0_sp
665                            tmp_particle%age_m         = 0.0_sp
666                            tmp_particle%dt_sum        = 0.0_wp
667                            tmp_particle%dvrp_psize    = dvrp_psize
668                            tmp_particle%e_m           = 0.0_sp
669                            IF ( curvature_solution_effects )  THEN
670!
671!--                            Initial values (internal timesteps, derivative)
672!--                            for Rosenbrock method
673                               tmp_particle%rvar1      = 1.0E-12_wp
674                               tmp_particle%rvar2      = 1.0E-3_wp
675                               tmp_particle%rvar3      = -9999999.9_wp
676                            ELSE
677!
678!--                            Initial values for SGS velocities
679                               tmp_particle%rvar1      = 0.0_wp
680                               tmp_particle%rvar2      = 0.0_wp
681                               tmp_particle%rvar3      = 0.0_wp
682                            ENDIF
683                            tmp_particle%speed_x       = 0.0_sp
684                            tmp_particle%speed_y       = 0.0_sp
685                            tmp_particle%speed_z       = 0.0_sp
686                            tmp_particle%origin_x      = pos_x
687                            tmp_particle%origin_y      = pos_y
688                            tmp_particle%origin_z      = pos_z
689                            tmp_particle%radius        = particle_groups(i)%radius
690                            tmp_particle%weight_factor = initial_weighting_factor
691                            tmp_particle%class         = 1
692                            tmp_particle%group         = i
693                            tmp_particle%tailpoints    = 0
694                            tmp_particle%particle_mask = .TRUE.
695#else
696                            tmp_particle%x             = pos_x
697                            tmp_particle%y             = pos_y
698                            tmp_particle%z             = pos_z
699                            tmp_particle%age           = 0.0_wp
700                            tmp_particle%age_m         = 0.0_wp
701                            tmp_particle%dt_sum        = 0.0_wp
702                            tmp_particle%dvrp_psize    = dvrp_psize
703                            tmp_particle%e_m           = 0.0_wp
704                            IF ( curvature_solution_effects )  THEN
705!
706!--                            Initial values (internal timesteps, derivative)
707!--                            for Rosenbrock method
708                               tmp_particle%rvar1      = 1.0E-12_wp
709                               tmp_particle%rvar2      = 1.0E-3_wp
710                               tmp_particle%rvar3      = -9999999.9_wp
711                            ELSE
712!
713!--                            Initial values for SGS velocities
714                               tmp_particle%rvar1      = 0.0_wp
715                               tmp_particle%rvar2      = 0.0_wp
716                               tmp_particle%rvar3      = 0.0_wp
717                            ENDIF
718                            tmp_particle%speed_x       = 0.0_wp
719                            tmp_particle%speed_y       = 0.0_wp
720                            tmp_particle%speed_z       = 0.0_wp
721                            tmp_particle%origin_x      = pos_x
722                            tmp_particle%origin_y      = pos_y
723                            tmp_particle%origin_z      = pos_z
724                            tmp_particle%radius        = particle_groups(i)%radius
725                            tmp_particle%weight_factor = initial_weighting_factor
726                            tmp_particle%class         = 1
727                            tmp_particle%group         = i
728                            tmp_particle%tailpoints    = 0
729                            tmp_particle%particle_mask = .TRUE.
730#endif
731                            IF ( use_particle_tails  .AND. &
732                                 MOD( n, skip_particles_for_tail ) == 0 )  THEN
733                               number_of_tails         = number_of_tails + 1
734!
735!--                            This is a temporary provisional setting (see
736!--                            further below!)
737                               tmp_particle%tail_id    = number_of_tails
738                            ELSE
739                               tmp_particle%tail_id    = 0
740                            ENDIF
741!
742!--                         Determine the grid indices of the particle position
743                            ip = ( tmp_particle%x + 0.5_wp * dx ) * ddx
744                            jp = ( tmp_particle%y + 0.5_wp * dy ) * ddy
745                            kp = tmp_particle%z / dz + 1 + offset_ocean_nzt_m1
746
747                            IF ( seed_follows_topography )  THEN
748!
749!--                            Particle height is given relative to topography
750                               kp = kp + nzb_w_inner(jp,ip)
751                               tmp_particle%z = tmp_particle%z + zw(kp)
752                               IF ( kp > nzt )  THEN
753                                  pos_x = pos_x + pdx(i)
754                                  CYCLE xloop
755                               ENDIF
756                            ENDIF
757
758                            local_count(kp,jp,ip) = local_count(kp,jp,ip) + 1
759                            IF ( .NOT. first_stride )  THEN
760                               IF ( ip < nxl  .OR.  jp < nys  .OR.  kp < nzb+1 )  THEN
761                                  write(6,*) 'xl ',ip,jp,kp,nxl,nys,nzb+1
762                               ENDIF
763                               IF ( ip > nxr  .OR.  jp > nyn  .OR.  kp > nzt )  THEN
764                                  write(6,*) 'xu ',ip,jp,kp,nxr,nyn,nzt
765                               ENDIF
766                               grid_particles(kp,jp,ip)%particles(local_count(kp,jp,ip)) = tmp_particle
767                            ENDIF
768                         ENDDO
769
770                      ENDIF
771
772                      pos_x = pos_x + pdx(i)
773
774                   ENDDO xloop
775
776                ENDIF
777
778                pos_y = pos_y + pdy(i)
779
780             ENDDO
781
782             pos_z = pos_z + pdz(i)
783
784          ENDDO
785
786       ENDDO
787
788       IF ( first_stride )  THEN
789          DO  ip = nxl, nxr
790             DO  jp = nys, nyn
791                DO  kp = nzb+1, nzt
792                   IF ( phase == PHASE_INIT )  THEN
793                      IF ( local_count(kp,jp,ip) > 0 )  THEN
794                         alloc_size = MAX( INT( local_count(kp,jp,ip) *        &
795                            ( 1.0_wp + alloc_factor / 100.0_wp ) ),            &
796                            min_nr_particle )
797                      ELSE
798                         alloc_size = min_nr_particle
799                      ENDIF
800                      ALLOCATE(grid_particles(kp,jp,ip)%particles(1:alloc_size))
801                      DO  n = 1, alloc_size
802                         grid_particles(kp,jp,ip)%particles(n) = zero_particle
803                      ENDDO
804                   ELSEIF ( phase == PHASE_RELEASE )  THEN
805                      IF ( local_count(kp,jp,ip) > 0 )  THEN
806                         new_size   = local_count(kp,jp,ip) + prt_count(kp,jp,ip)
807                         alloc_size = MAX( INT( new_size * ( 1.0_wp +          &
808                            alloc_factor / 100.0_wp ) ), min_nr_particle )
809                         IF( alloc_size > SIZE( grid_particles(kp,jp,ip)%particles) )  THEN
810                           CALL realloc_particles_array(ip,jp,kp,alloc_size)
811                         ENDIF
812                      ENDIF
813                   ENDIF
814                ENDDO
815             ENDDO
816          ENDDO
817       ENDIF
818    ENDDO
819
820    local_start = prt_count+1
821    prt_count   = local_count
822!
823!-- Add random fluctuation to particle positions
824    IF ( random_start_position )  THEN
825       DO  ip = nxl, nxr
826          DO  jp = nys, nyn
827             DO  kp = nzb+1, nzt
828                number_of_particles = prt_count(kp,jp,ip)
829                IF ( number_of_particles <= 0 )  CYCLE
830                particles => grid_particles(kp,jp,ip)%particles(1:number_of_particles)
831
832                DO  n = local_start(kp,jp,ip), number_of_particles              !Move only new particles
833                   IF ( psl(particles(n)%group) /= psr(particles(n)%group) )  THEN
834                      particles(n)%x = particles(n)%x +                        &
835                                   ( random_function( iran_part ) - 0.5_wp ) * &
836                                   pdx(particles(n)%group)
837                   ENDIF
838                   IF ( pss(particles(n)%group) /= psn(particles(n)%group) )  THEN
839                      particles(n)%y = particles(n)%y +                        &
840                                   ( random_function( iran_part ) - 0.5_wp ) * &
841                                   pdy(particles(n)%group)
842                   ENDIF
843                   IF ( psb(particles(n)%group) /= pst(particles(n)%group) )  THEN
844                      particles(n)%z = particles(n)%z +                        &
845                                   ( random_function( iran_part ) - 0.5_wp ) * &
846                                   pdz(particles(n)%group)
847                   ENDIF
848                ENDDO
849!
850!--             Identify particles located outside the model domain
851                CALL lpm_boundary_conds( 'bottom/top' )
852             ENDDO
853          ENDDO
854       ENDDO
855!
856!--    Exchange particles between grid cells and processors
857       CALL lpm_move_particle
858       CALL lpm_exchange_horiz
859
860    ENDIF
861!
862!-- In case of random_start_position, delete particles identified by
863!-- lpm_exchange_horiz and lpm_boundary_conds. Then sort particles into blocks,
864!-- which is needed for a fast interpolation of the LES fields on the particle
865!-- position.
866    CALL lpm_pack_all_arrays
867
868!
869!-- Determine maximum number of particles (i.e., all possible particles that
870!-- have been allocated) and the current number of particles
871    DO  ip = nxl, nxr
872       DO  jp = nys, nyn
873          DO  kp = nzb+1, nzt
874             maximum_number_of_particles = maximum_number_of_particles         &
875                                           + SIZE(grid_particles(kp,jp,ip)%particles)
876             number_of_particles         = number_of_particles                 &
877                                           + prt_count(kp,jp,ip)
878          ENDDO
879       ENDDO
880    ENDDO
881!
882!-- Calculate the number of particles and tails of the total domain
883#if defined( __parallel )
884    IF ( collective_wait )  CALL MPI_BARRIER( comm2d, ierr )
885    CALL MPI_ALLREDUCE( number_of_particles, total_number_of_particles, 1, &
886    MPI_INTEGER, MPI_SUM, comm2d, ierr )
887    IF ( collective_wait )  CALL MPI_BARRIER( comm2d, ierr )
888    CALL MPI_ALLREDUCE( number_of_tails, total_number_of_tails, 1, &
889    MPI_INTEGER, MPI_SUM, comm2d, ierr )
890#else
891    total_number_of_particles = number_of_particles
892    total_number_of_tails     = number_of_tails
893#endif
894
895    RETURN
896
897 END SUBROUTINE lpm_create_particle
898
899END MODULE lpm_init_mod
Note: See TracBrowser for help on using the repository browser.