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

Last change on this file since 1783 was 1783, checked in by raasch, 8 years ago

NetCDF routines modularized; new parameter netcdf_deflate; further changes in the pmc

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