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

Last change on this file since 1691 was 1691, checked in by maronga, 9 years ago

various bugfixes and modifications of the atmosphere-land-surface-radiation interaction. Completely re-written routine to calculate surface fluxes (surface_layer_fluxes.f90) that replaces prandtl_fluxes. Minor formatting corrections and renamings

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