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

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

bugfix concerning vertical index calculation for particles in case of ocean runs

  • Property svn:keywords set to Id
File size: 36.2 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-2014 Leibniz Universitaet Hannover
17!--------------------------------------------------------------------------------!
18!
19! Current revisions:
20! -----------------
21! bugfix concerning vertical index offset in case of ocean
22!
23! Former revisions:
24! -----------------
25! $Id: lpm_init.f90 1685 2015-10-08 07:32:13Z raasch $
26!
27! 1682 2015-10-07 23:56:08Z knoop
28! Code annotations made doxygen readable
29!
30! 1575 2015-03-27 09:56:27Z raasch
31! initial vertical particle position is allowed to follow the topography
32!
33! 1359 2014-04-11 17:15:14Z hoffmann
34! New particle structure integrated.
35! Kind definition added to all floating point numbers.
36! lpm_init changed form a subroutine to a module.
37!
38! 1327 2014-03-21 11:00:16Z raasch
39! -netcdf_output
40!
41! 1322 2014-03-20 16:38:49Z raasch
42! REAL functions provided with KIND-attribute
43!
44! 1320 2014-03-20 08:40:49Z raasch
45! ONLY-attribute added to USE-statements,
46! kind-parameters added to all INTEGER and REAL declaration statements,
47! kinds are defined in new module kinds,
48! revision history before 2012 removed,
49! comment fields (!:) to be used for variable explanations added to
50! all variable declaration statements
51! bugfix: #if defined( __parallel ) added
52!
53! 1314 2014-03-14 18:25:17Z suehring
54! Vertical logarithmic interpolation of horizontal particle speed for particles
55! between roughness height and first vertical grid level.
56!
57! 1092 2013-02-02 11:24:22Z raasch
58! unused variables removed
59!
60! 1036 2012-10-22 13:43:42Z raasch
61! code put under GPL (PALM 3.9)
62!
63! 849 2012-03-15 10:35:09Z raasch
64! routine renamed: init_particles -> lpm_init
65! de_dx, de_dy, de_dz are allocated here (instead of automatic arrays in
66! advec_particles),
67! sort_particles renamed lpm_sort_arrays, user_init_particles renamed lpm_init
68!
69! 828 2012-02-21 12:00:36Z raasch
70! call of init_kernels, particle feature color renamed class
71!
72! 824 2012-02-17 09:09:57Z raasch
73! particle attributes speed_x|y|z_sgs renamed rvar1|2|3,
74! array particles implemented as pointer
75!
76! 667 2010-12-23 12:06:00Z suehring/gryschka
77! nxl-1, nxr+1, nys-1, nyn+1 replaced by nxlg, nxrg, nysg, nyng for allocation
78! of arrays.
79!
80! Revision 1.1  1999/11/25 16:22:38  raasch
81! Initial revision
82!
83!
84! Description:
85! ------------
86!> This routine initializes a set of particles and their attributes (position,
87!> radius, ..) which are used by the Lagrangian particle model (see lpm).
88!------------------------------------------------------------------------------!
89 MODULE lpm_init_mod
90 
91
92    USE arrays_3d,                                                             &
93        ONLY:  de_dx, de_dy, de_dz, zu, zw, z0
94
95    USE cloud_parameters,                                                      &
96        ONLY:  curvature_solution_effects
97
98    USE control_parameters,                                                    &
99        ONLY:  cloud_droplets, current_timestep_number, dz,                    &
100               initializing_actions, message_string, netcdf_data_format,       &
101               ocean, prandtl_layer, simulated_time
102
103    USE dvrp_variables,                                                        &
104        ONLY:  particle_color, particle_dvrpsize
105
106    USE grid_variables,                                                        &
107        ONLY:  ddx, dx, ddy, dy
108
109    USE indices,                                                               &
110        ONLY:  nx, nxl, nxlg, nxrg, nxr, ny, nyn, nys, nyng, nysg, nz, nzb,    &
111               nzb_w_inner, nzt
112
113    USE kinds
114
115    USE lpm_collision_kernels_mod,                                             &
116        ONLY:  init_kernels
117
118    USE particle_attributes,                                                   &
119        ONLY:   alloc_factor, bc_par_b, bc_par_lr, bc_par_ns, bc_par_t,        &
120                block_offset, block_offset_def, collision_kernel,              &
121                density_ratio, dvrp_psize, grid_particles,                     &
122                initial_weighting_factor, ibc_par_b, ibc_par_lr, ibc_par_ns,   &
123                ibc_par_t, iran_part, log_z_z0,                                &
124                max_number_of_particle_groups, maximum_number_of_particles,    &
125                maximum_number_of_tailpoints, maximum_number_of_tails,         &
126                minimum_tailpoint_distance, min_nr_particle,                   &
127                mpi_particle_type, new_tail_id,                                &
128                number_of_initial_tails, number_of_particles,                  &
129                number_of_particle_groups, number_of_sublayers,                &
130                number_of_tails, offset_ocean_nzt, offset_ocean_nzt_m1,        &
131                particles, particle_advection_start, particle_groups,          &
132                particle_groups_type, particles_per_point,                     &
133                particle_tail_coordinates,  particle_type, pdx, pdy, pdz,      &
134                prt_count, psb, psl, psn, psr, pss, pst,                       &
135                radius, random_start_position, read_particles_from_restartfile,&
136                seed_follows_topography, skip_particles_for_tail, sort_count,  &
137                tail_mask, total_number_of_particles, total_number_of_tails,   &
138                use_particle_tails, use_sgs_for_particles,                     &
139                write_particle_statistics, uniform_particles, zero_particle,   &
140                z0_av_global
141
142    USE pegrid
143
144    USE random_function_mod,                                                   &
145        ONLY:  random_function
146
147    IMPLICIT NONE
148
149    PRIVATE
150
151    INTEGER(iwp), PARAMETER         :: PHASE_INIT    = 1  !<
152    INTEGER(iwp), PARAMETER, PUBLIC :: PHASE_RELEASE = 2  !<
153
154    INTERFACE lpm_init
155       MODULE PROCEDURE lpm_init
156    END INTERFACE lpm_init
157
158    INTERFACE lpm_create_particle
159       MODULE PROCEDURE lpm_create_particle
160    END INTERFACE lpm_create_particle
161
162    PUBLIC lpm_init, lpm_create_particle
163
164CONTAINS
165
166!------------------------------------------------------------------------------!
167! Description:
168! ------------
169!> @todo Missing subroutine description.
170!------------------------------------------------------------------------------!
171 SUBROUTINE lpm_init
172
173    USE lpm_collision_kernels_mod,                                             &
174        ONLY:  init_kernels
175
176    IMPLICIT NONE
177
178    INTEGER(iwp) ::  i                           !<
179    INTEGER(iwp) ::  ip                          !<
180    INTEGER(iwp) ::  j                           !<
181    INTEGER(iwp) ::  jp                          !<
182    INTEGER(iwp) ::  k                           !<
183    INTEGER(iwp) ::  kp                          !<
184    INTEGER(iwp) ::  n                           !<
185    INTEGER(iwp) ::  nn                          !<
186
187#if defined( __parallel )
188    INTEGER(iwp), DIMENSION(3) ::  blocklengths  !<
189    INTEGER(iwp), DIMENSION(3) ::  displacements !<
190    INTEGER(iwp), DIMENSION(3) ::  types         !<
191#endif
192    LOGICAL ::  uniform_particles_l              !<
193
194    REAL(wp) ::  height_int                      !<
195    REAL(wp) ::  height_p                        !<
196    REAL(wp) ::  z_p                             !<
197    REAL(wp) ::  z0_av_local                     !<
198
199#if defined( __parallel )
200!
201!-- Define MPI derived datatype for FORTRAN datatype particle_type (see module
202!-- particle_attributes). Integer length is 4 byte, Real is 8 byte
203#if defined( __twocachelines )
204    blocklengths(1)  =  7;  blocklengths(2)  =  18;  blocklengths(3)  =   1
205    displacements(1) =  0;  displacements(2) =  64;  displacements(3) = 128
206
207    types(1) = MPI_REAL                               ! 64 bit words
208    types(2) = MPI_INTEGER                            ! 32 Bit words
209    types(3) = MPI_UB
210#else
211    blocklengths(1)  = 19;  blocklengths(2)  =   6;  blocklengths(3)  =   1
212    displacements(1) =  0;  displacements(2) = 152;  displacements(3) = 176
213
214    types(1) = MPI_REAL
215    types(2) = MPI_INTEGER
216    types(3) = MPI_UB
217#endif
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 )  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 ( prandtl_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!--    Also allocate array for particle tail coordinates, if needed.
417       ALLOCATE( prt_count(nzb:nzt+1,nysg:nyng,nxlg:nxrg), &
418                 grid_particles(nzb+1:nzt,nys:nyn,nxl:nxr) )
419
420       maximum_number_of_particles = 0
421       number_of_particles         = 0
422
423       sort_count = 0
424       prt_count  = 0
425
426!
427!--    Initialize all particles with dummy values (otherwise errors may
428!--    occur within restart runs). The reason for this is still not clear
429!--    and may be presumably caused by errors in the respective user-interface.
430#if defined( __twocachelines )
431       zero_particle = particle_type( 0.0_wp, 0.0_sp, 0.0_sp, 0.0_sp, 0.0_sp,  &
432                                      0.0_sp, 0.0_sp, 0.0_wp, 0.0_wp, 0.0_wp,  &
433                                      0, .FALSE., 0.0_wp, 0.0_wp, 0.0_wp,      &
434                                      0.0_sp, 0.0_sp, 0.0_sp, 0.0_sp, 0.0_sp,  &
435                                      0.0_sp, 0, 0, 0, -1)
436#else
437       zero_particle = particle_type( 0.0_wp, 0.0_wp, 0.0_wp, 0.0_wp, 0.0_wp,  &
438                                      0.0_wp, 0.0_wp, 0.0_wp, 0.0_wp, 0.0_wp,  &
439                                      0.0_wp, 0.0_wp, 0.0_wp, 0.0_wp, 0.0_wp,  &
440                                      0.0_wp, 0.0_wp, 0.0_wp, 0.0_wp, 0, 0, 0, &
441                                      0, .FALSE., -1)
442#endif
443       particle_groups = particle_groups_type( 0.0_wp, 0.0_wp, 0.0_wp, 0.0_wp )
444
445!
446!--    Set the default particle size used for dvrp plots
447       IF ( dvrp_psize == 9999999.9_wp )  dvrp_psize = 0.2_wp * dx
448
449!
450!--    Set values for the density ratio and radius for all particle
451!--    groups, if necessary
452       IF ( density_ratio(1) == 9999999.9_wp )  density_ratio(1) = 0.0_wp
453       IF ( radius(1)        == 9999999.9_wp )  radius(1) = 0.0_wp
454       DO  i = 2, number_of_particle_groups
455          IF ( density_ratio(i) == 9999999.9_wp )  THEN
456             density_ratio(i) = density_ratio(i-1)
457          ENDIF
458          IF ( radius(i) == 9999999.9_wp )  radius(i) = radius(i-1)
459       ENDDO
460
461       DO  i = 1, number_of_particle_groups
462          IF ( density_ratio(i) /= 0.0_wp  .AND.  radius(i) == 0 )  THEN
463             WRITE( message_string, * ) 'particle group #', i, 'has a', &
464                                        'density ratio /= 0 but radius = 0'
465             CALL message( 'lpm_init', 'PA0215', 1, 2, 0, 6, 0 )
466          ENDIF
467          particle_groups(i)%density_ratio = density_ratio(i)
468          particle_groups(i)%radius        = radius(i)
469       ENDDO
470
471       CALL lpm_create_particle (PHASE_INIT)
472!
473!--    Set a seed value for the random number generator to be exclusively
474!--    used for the particle code. The generated random numbers should be
475!--    different on the different PEs.
476       iran_part = iran_part + myid
477
478!
479!--    User modification of initial particles
480       CALL user_lpm_init
481
482!
483!--    Open file for statistical informations about particle conditions
484       IF ( write_particle_statistics )  THEN
485          CALL check_open( 80 )
486          WRITE ( 80, 8000 )  current_timestep_number, simulated_time,         &
487                              number_of_particles,                             &
488                              maximum_number_of_particles
489          CALL close_file( 80 )
490       ENDIF
491
492!
493!--    Check if particles are really uniform in color and radius (dvrp_size)
494!--    (uniform_particles is preset TRUE)
495       IF ( uniform_particles )  THEN
496          DO  ip = nxl, nxr
497             DO  jp = nys, nyn
498                DO  kp = nzb+1, nzt
499
500                   n = prt_count(kp,jp,ip)
501                   IF ( MINVAL( grid_particles(kp,jp,ip)%particles(1:n)%dvrp_psize  ) ==     &
502                        MAXVAL( grid_particles(kp,jp,ip)%particles(1:n)%dvrp_psize  )  .AND. &
503                        MINVAL( grid_particles(kp,jp,ip)%particles(1:n)%class ) ==           &
504                        MAXVAL( grid_particles(kp,jp,ip)%particles(1:n)%class ) )  THEN
505                      uniform_particles_l = .TRUE.
506                   ELSE
507                      uniform_particles_l = .FALSE.
508                   ENDIF
509
510                ENDDO
511             ENDDO
512          ENDDO
513
514#if defined( __parallel )
515          IF ( collective_wait )  CALL MPI_BARRIER( comm2d, ierr )
516          CALL MPI_ALLREDUCE( uniform_particles_l, uniform_particles, 1,       &
517                              MPI_LOGICAL, MPI_LAND, comm2d, ierr )
518#else
519          uniform_particles = uniform_particles_l
520#endif
521
522       ENDIF
523
524!
525!--    Particles will probably become none-uniform, if their size and color
526!--    will be determined by flow variables
527       IF ( particle_color /= 'none'  .OR.  particle_dvrpsize /= 'none' )  THEN
528          uniform_particles = .FALSE.
529       ENDIF
530
531! !kk    Not implemented aft individual particle array fort every gridcell
532! !
533! !--    Set the beginning of the particle tails and their age
534!        IF ( use_particle_tails )  THEN
535! !
536! !--       Choose the maximum number of tails with respect to the maximum number
537! !--       of particles and skip_particles_for_tail
538!           maximum_number_of_tails = maximum_number_of_particles / &
539!                                     skip_particles_for_tail
540!
541! !
542! !--       Create a minimum number of tails in case that there is no tail
543! !--       initially (otherwise, index errors will occur when adressing the
544! !--       arrays below)
545!           IF ( maximum_number_of_tails == 0 )  maximum_number_of_tails = 10
546!
547!           ALLOCATE( particle_tail_coordinates(maximum_number_of_tailpoints,5, &
548!                     maximum_number_of_tails),                                 &
549!                     new_tail_id(maximum_number_of_tails),                     &
550!                     tail_mask(maximum_number_of_tails) )
551!
552!           particle_tail_coordinates  = 0.0_wp
553!           minimum_tailpoint_distance = minimum_tailpoint_distance**2
554!           number_of_initial_tails    = number_of_tails
555!
556!           nn = 0
557!           DO  n = 1, number_of_particles
558! !
559! !--          Only for those particles marked above with a provisional tail_id
560! !--          tails will be created. Particles now get their final tail_id.
561!              IF ( particles(n)%tail_id /= 0 )  THEN
562!
563!                 nn = nn + 1
564!                 particles(n)%tail_id = nn
565!
566!                 particle_tail_coordinates(1,1,nn) = particles(n)%x
567!                 particle_tail_coordinates(1,2,nn) = particles(n)%y
568!                 particle_tail_coordinates(1,3,nn) = particles(n)%z
569!                 particle_tail_coordinates(1,4,nn) = particles(n)%class
570!                 particles(n)%tailpoints = 1
571!                 IF ( minimum_tailpoint_distance /= 0.0_wp )  THEN
572!                    particle_tail_coordinates(2,1,nn) = particles(n)%x
573!                    particle_tail_coordinates(2,2,nn) = particles(n)%y
574!                    particle_tail_coordinates(2,3,nn) = particles(n)%z
575!                    particle_tail_coordinates(2,4,nn) = particles(n)%class
576!                    particle_tail_coordinates(1:2,5,nn) = 0.0_wp
577!                    particles(n)%tailpoints = 2
578!                 ENDIF
579!
580!              ENDIF
581!           ENDDO
582!        ENDIF
583!
584! !
585! !--    Plot initial positions of particles (only if particle advection is
586! !--    switched on from the beginning of the simulation (t=0))
587!        IF ( particle_advection_start == 0.0_wp )  CALL data_output_dvrp
588
589    ENDIF
590
591!
592!-- To avoid programm abort, assign particles array to the local version of
593!-- first grid cell
594    number_of_particles = prt_count(nzb+1,nys,nxl)
595    particles => grid_particles(nzb+1,nys,nxl)%particles(1:number_of_particles)
596
597!
598!-- Formats
5998000 FORMAT (I6,1X,F7.2,4X,I10,71X,I10)
600
601 END SUBROUTINE lpm_init
602
603!------------------------------------------------------------------------------!
604! Description:
605! ------------
606!> @todo Missing subroutine description.
607!------------------------------------------------------------------------------!
608 SUBROUTINE lpm_create_particle (phase)
609
610    USE lpm_exchange_horiz_mod,                                                &
611        ONLY: lpm_exchange_horiz, lpm_move_particle, realloc_particles_array
612
613    USE lpm_pack_arrays_mod,                                                   &
614        ONLY: lpm_pack_all_arrays
615
616    IMPLICIT  NONE
617
618    INTEGER(iwp)               ::  alloc_size  !<
619    INTEGER(iwp)               ::  i           !<
620    INTEGER(iwp)               ::  ip          !<
621    INTEGER(iwp)               ::  j           !<
622    INTEGER(iwp)               ::  jp          !<
623    INTEGER(iwp)               ::  kp          !<
624    INTEGER(iwp)               ::  loop_stride !<
625    INTEGER(iwp)               ::  n           !<
626    INTEGER(iwp)               ::  new_size    !<
627    INTEGER(iwp)               ::  nn          !<
628
629    INTEGER(iwp), INTENT(IN)   ::  phase       !<
630
631    INTEGER(iwp), DIMENSION(nzb:nzt+1,nysg:nyng,nxlg:nxrg) ::  local_count !<
632    INTEGER(iwp), DIMENSION(nzb:nzt+1,nysg:nyng,nxlg:nxrg) ::  local_start !<
633
634    LOGICAL                    ::  first_stride !<
635
636    REAL(wp)                   ::  pos_x !<
637    REAL(wp)                   ::  pos_y !<
638    REAL(wp)                   ::  pos_z !<
639
640    TYPE(particle_type),TARGET ::  tmp_particle !<
641
642!
643!-- Calculate particle positions and store particle attributes, if
644!-- particle is situated on this PE
645    DO  loop_stride = 1, 2
646       first_stride = (loop_stride == 1)
647       IF ( first_stride )   THEN
648          local_count = 0           ! count number of particles
649       ELSE
650          local_count = prt_count   ! Start address of new particles
651       ENDIF
652
653       n = 0
654       DO  i = 1, number_of_particle_groups
655
656          pos_z = psb(i)
657
658          DO WHILE ( pos_z <= pst(i) )
659
660             pos_y = pss(i)
661
662             DO WHILE ( pos_y <= psn(i) )
663
664                IF ( pos_y >= ( nys - 0.5_wp ) * dy  .AND.  &
665                     pos_y <  ( nyn + 0.5_wp ) * dy )  THEN
666
667                   pos_x = psl(i)
668
669            xloop: DO WHILE ( pos_x <= psr(i) )
670
671                      IF ( pos_x >= ( nxl - 0.5_wp ) * dx  .AND.  &
672                           pos_x <  ( nxr + 0.5_wp ) * dx )  THEN
673
674                         DO  j = 1, particles_per_point
675
676                            n = n + 1
677#if defined( __twocachelines )
678                            tmp_particle%x             = pos_x
679                            tmp_particle%y             = pos_y
680                            tmp_particle%z             = pos_z
681                            tmp_particle%age           = 0.0_sp
682                            tmp_particle%age_m         = 0.0_sp
683                            tmp_particle%dt_sum        = 0.0_wp
684                            tmp_particle%dvrp_psize    = dvrp_psize
685                            tmp_particle%e_m           = 0.0_sp
686                            IF ( curvature_solution_effects )  THEN
687!
688!--                            Initial values (internal timesteps, derivative)
689!--                            for Rosenbrock method
690                               tmp_particle%rvar1      = 1.0E-12_wp
691                               tmp_particle%rvar2      = 1.0E-3_wp
692                               tmp_particle%rvar3      = -9999999.9_wp
693                            ELSE
694!
695!--                            Initial values for SGS velocities
696                               tmp_particle%rvar1      = 0.0_wp
697                               tmp_particle%rvar2      = 0.0_wp
698                               tmp_particle%rvar3      = 0.0_wp
699                            ENDIF
700                            tmp_particle%speed_x       = 0.0_sp
701                            tmp_particle%speed_y       = 0.0_sp
702                            tmp_particle%speed_z       = 0.0_sp
703                            tmp_particle%origin_x      = pos_x
704                            tmp_particle%origin_y      = pos_y
705                            tmp_particle%origin_z      = pos_z
706                            tmp_particle%radius        = particle_groups(i)%radius
707                            tmp_particle%weight_factor = initial_weighting_factor
708                            tmp_particle%class         = 1
709                            tmp_particle%group         = i
710                            tmp_particle%tailpoints    = 0
711                            tmp_particle%particle_mask = .TRUE.
712#else
713                            tmp_particle%x             = pos_x
714                            tmp_particle%y             = pos_y
715                            tmp_particle%z             = pos_z
716                            tmp_particle%age           = 0.0_wp
717                            tmp_particle%age_m         = 0.0_wp
718                            tmp_particle%dt_sum        = 0.0_wp
719                            tmp_particle%dvrp_psize    = dvrp_psize
720                            tmp_particle%e_m           = 0.0_wp
721                            IF ( curvature_solution_effects )  THEN
722!
723!--                            Initial values (internal timesteps, derivative)
724!--                            for Rosenbrock method
725                               tmp_particle%rvar1      = 1.0E-12_wp
726                               tmp_particle%rvar2      = 1.0E-3_wp
727                               tmp_particle%rvar3      = -9999999.9_wp
728                            ELSE
729!
730!--                            Initial values for SGS velocities
731                               tmp_particle%rvar1      = 0.0_wp
732                               tmp_particle%rvar2      = 0.0_wp
733                               tmp_particle%rvar3      = 0.0_wp
734                            ENDIF
735                            tmp_particle%speed_x       = 0.0_wp
736                            tmp_particle%speed_y       = 0.0_wp
737                            tmp_particle%speed_z       = 0.0_wp
738                            tmp_particle%origin_x      = pos_x
739                            tmp_particle%origin_y      = pos_y
740                            tmp_particle%origin_z      = pos_z
741                            tmp_particle%radius        = particle_groups(i)%radius
742                            tmp_particle%weight_factor = initial_weighting_factor
743                            tmp_particle%class         = 1
744                            tmp_particle%group         = i
745                            tmp_particle%tailpoints    = 0
746                            tmp_particle%particle_mask = .TRUE.
747#endif
748                            IF ( use_particle_tails  .AND. &
749                                 MOD( n, skip_particles_for_tail ) == 0 )  THEN
750                               number_of_tails         = number_of_tails + 1
751!
752!--                            This is a temporary provisional setting (see
753!--                            further below!)
754                               tmp_particle%tail_id    = number_of_tails
755                            ELSE
756                               tmp_particle%tail_id    = 0
757                            ENDIF
758!
759!--                         Determine the grid indices of the particle position
760                            ip = ( tmp_particle%x + 0.5_wp * dx ) * ddx
761                            jp = ( tmp_particle%y + 0.5_wp * dy ) * ddy
762                            kp = tmp_particle%z / dz + 1 + offset_ocean_nzt
763
764                            IF ( seed_follows_topography )  THEN
765!
766!--                            Particle height is given relative to topography
767                               kp = kp + nzb_w_inner(jp,ip)
768                               tmp_particle%z = tmp_particle%z + zw(kp)
769                               IF ( kp > nzt )  THEN
770                                  pos_x = pos_x + pdx(i)
771                                  CYCLE xloop
772                               ENDIF
773                            ENDIF
774
775                            local_count(kp,jp,ip) = local_count(kp,jp,ip) + 1
776                            IF ( .NOT. first_stride )  THEN
777                               IF ( ip < nxl  .OR.  jp < nys  .OR.  kp < nzb+1 )  THEN
778                                  write(6,*) 'xl ',ip,jp,kp,nxl,nys,nzb+1
779                               ENDIF
780                               IF ( ip > nxr  .OR.  jp > nyn  .OR.  kp > nzt )  THEN
781                                  write(6,*) 'xu ',ip,jp,kp,nxr,nyn,nzt
782                               ENDIF
783                               grid_particles(kp,jp,ip)%particles(local_count(kp,jp,ip)) = tmp_particle
784                            ENDIF
785                         ENDDO
786
787                      ENDIF
788
789                      pos_x = pos_x + pdx(i)
790
791                   ENDDO xloop
792
793                ENDIF
794
795                pos_y = pos_y + pdy(i)
796
797             ENDDO
798
799             pos_z = pos_z + pdz(i)
800
801          ENDDO
802
803       ENDDO
804
805       IF ( first_stride )  THEN
806          DO  ip = nxl, nxr
807             DO  jp = nys, nyn
808                DO  kp = nzb+1, nzt
809                   IF ( phase == PHASE_INIT )  THEN
810                      IF ( local_count(kp,jp,ip) > 0 )  THEN
811                         alloc_size = MAX( INT( local_count(kp,jp,ip) *        &
812                            ( 1.0_wp + alloc_factor / 100.0_wp ) ),            &
813                            min_nr_particle )
814                      ELSE
815                         alloc_size = min_nr_particle
816                      ENDIF
817                      ALLOCATE(grid_particles(kp,jp,ip)%particles(1:alloc_size))
818                      DO  n = 1, alloc_size
819                         grid_particles(kp,jp,ip)%particles(n) = zero_particle
820                      ENDDO
821                   ELSEIF ( phase == PHASE_RELEASE )  THEN
822                      IF ( local_count(kp,jp,ip) > 0 )  THEN
823                         new_size   = local_count(kp,jp,ip) + prt_count(kp,jp,ip)
824                         alloc_size = MAX( INT( new_size * ( 1.0_wp +          &
825                            alloc_factor / 100.0_wp ) ), min_nr_particle )
826                         IF( alloc_size > SIZE( grid_particles(kp,jp,ip)%particles) )  THEN
827                           CALL realloc_particles_array(ip,jp,kp,alloc_size)
828                         ENDIF
829                      ENDIF
830                   ENDIF
831                ENDDO
832             ENDDO
833          ENDDO
834       ENDIF
835    ENDDO
836
837    local_start = prt_count+1
838    prt_count   = local_count
839!
840!-- Add random fluctuation to particle positions
841    IF ( random_start_position )  THEN
842       DO  ip = nxl, nxr
843          DO  jp = nys, nyn
844             DO  kp = nzb+1, nzt
845                number_of_particles = prt_count(kp,jp,ip)
846                IF ( number_of_particles <= 0 )  CYCLE
847                particles => grid_particles(kp,jp,ip)%particles(1:number_of_particles)
848
849                DO  n = local_start(kp,jp,ip), number_of_particles              !Move only new particles
850                   IF ( psl(particles(n)%group) /= psr(particles(n)%group) )  THEN
851                      particles(n)%x = particles(n)%x +                        &
852                                   ( random_function( iran_part ) - 0.5_wp ) * &
853                                   pdx(particles(n)%group)
854                   ENDIF
855                   IF ( pss(particles(n)%group) /= psn(particles(n)%group) )  THEN
856                      particles(n)%y = particles(n)%y +                        &
857                                   ( random_function( iran_part ) - 0.5_wp ) * &
858                                   pdy(particles(n)%group)
859                   ENDIF
860                   IF ( psb(particles(n)%group) /= pst(particles(n)%group) )  THEN
861                      particles(n)%z = particles(n)%z +                        &
862                                   ( random_function( iran_part ) - 0.5_wp ) * &
863                                   pdz(particles(n)%group)
864                   ENDIF
865                ENDDO
866!
867!--             Identify particles located outside the model domain
868                CALL lpm_boundary_conds( 'bottom/top' )
869             ENDDO
870          ENDDO
871       ENDDO
872!
873!--    Exchange particles between grid cells and processors
874       CALL lpm_move_particle
875       CALL lpm_exchange_horiz
876
877    ENDIF
878!
879!-- In case of random_start_position, delete particles identified by
880!-- lpm_exchange_horiz and lpm_boundary_conds. Then sort particles into blocks,
881!-- which is needed for a fast interpolation of the LES fields on the particle
882!-- position.
883    CALL lpm_pack_all_arrays
884
885!
886!-- Determine maximum number of particles (i.e., all possible particles that
887!-- have been allocated) and the current number of particles
888    DO  ip = nxl, nxr
889       DO  jp = nys, nyn
890          DO  kp = nzb+1, nzt
891             maximum_number_of_particles = maximum_number_of_particles         &
892                                           + SIZE(grid_particles(kp,jp,ip)%particles)
893             number_of_particles         = number_of_particles                 &
894                                           + prt_count(kp,jp,ip)
895          ENDDO
896       ENDDO
897    ENDDO
898!
899!-- Calculate the number of particles and tails of the total domain
900#if defined( __parallel )
901    IF ( collective_wait )  CALL MPI_BARRIER( comm2d, ierr )
902    CALL MPI_ALLREDUCE( number_of_particles, total_number_of_particles, 1, &
903    MPI_INTEGER, MPI_SUM, comm2d, ierr )
904    IF ( collective_wait )  CALL MPI_BARRIER( comm2d, ierr )
905    CALL MPI_ALLREDUCE( number_of_tails, total_number_of_tails, 1, &
906    MPI_INTEGER, MPI_SUM, comm2d, ierr )
907#else
908    total_number_of_particles = number_of_particles
909    total_number_of_tails     = number_of_tails
910#endif
911
912    RETURN
913
914 END SUBROUTINE lpm_create_particle
915
916END MODULE lpm_init_mod
Note: See TracBrowser for help on using the repository browser.