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

Last change on this file since 2000 was 2000, checked in by knoop, 8 years ago

Forced header and separation lines into 80 columns

  • Property svn:keywords set to Id
File size: 43.0 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
6! terms of the GNU General Public License as published by the Free Software
7! Foundation, either version 3 of the License, or (at your option) any later
8! version.
9!
10! PALM is distributed in the hope that it will be useful, but WITHOUT ANY
11! WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12! A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
13!
14! You should have received a copy of the GNU General Public License along with
15! PALM. If not, see <http://www.gnu.org/licenses/>.
16!
17! Copyright 1997-2016 Leibniz Universitaet Hannover
18!------------------------------------------------------------------------------!
19!
20! Current revisions:
21! -----------------
22! Forced header and separation lines into 80 columns
23!
24! Former revisions:
25! -----------------
26! $Id: lpm_init.f90 2000 2016-08-20 18:09:15Z knoop $
27!
28! 2016-06-09 16:25:25Z suehring
29! Bugfix in determining initial particle height and grid index in case of
30! seed_follows_topography.
31! Bugfix concerning random positions, ensure that particles do not move more
32! than one grid length.
33! Bugfix logarithmic interpolation.
34! Initial setting of sgs_wf_part.
35!
36! 1890 2016-04-22 08:52:11Z hoffmann
37! Initialization of aerosol equilibrium radius not possible in supersaturated
38! environments. Therefore, a maximum supersaturation of -1 % is assumed during
39! initialization.
40!
41! 1873 2016-04-18 14:50:06Z maronga
42! Module renamed (removed _mod
43
44!
45! 1871 2016-04-15 11:46:09Z hoffmann
46! Initialization of aerosols added.
47!
48! 1850 2016-04-08 13:29:27Z maronga
49! Module renamed
50!
51! 1831 2016-04-07 13:15:51Z hoffmann
52! curvature_solution_effects moved to particle_attributes
53!
54! 1822 2016-04-07 07:49:42Z hoffmann
55! Unused variables removed.
56!
57! 1783 2016-03-06 18:36:17Z raasch
58! netcdf module added
59!
60! 1725 2015-11-17 13:01:51Z hoffmann
61! Bugfix: Processor-dependent seed for random function is generated before it is
62! used.
63!
64! 1691 2015-10-26 16:17:44Z maronga
65! Renamed prandtl_layer to constant_flux_layer.
66!
67! 1685 2015-10-08 07:32:13Z raasch
68! bugfix concerning vertical index offset in case of ocean
69!
70! 1682 2015-10-07 23:56:08Z knoop
71! Code annotations made doxygen readable
72!
73! 1575 2015-03-27 09:56:27Z raasch
74! initial vertical particle position is allowed to follow the topography
75!
76! 1359 2014-04-11 17:15:14Z hoffmann
77! New particle structure integrated.
78! Kind definition added to all floating point numbers.
79! lpm_init changed form a subroutine to a module.
80!
81! 1327 2014-03-21 11:00:16Z raasch
82! -netcdf_output
83!
84! 1322 2014-03-20 16:38:49Z raasch
85! REAL functions provided with KIND-attribute
86!
87! 1320 2014-03-20 08:40:49Z raasch
88! ONLY-attribute added to USE-statements,
89! kind-parameters added to all INTEGER and REAL declaration statements,
90! kinds are defined in new module kinds,
91! revision history before 2012 removed,
92! comment fields (!:) to be used for variable explanations added to
93! all variable declaration statements
94! bugfix: #if defined( __parallel ) added
95!
96! 1314 2014-03-14 18:25:17Z suehring
97! Vertical logarithmic interpolation of horizontal particle speed for particles
98! between roughness height and first vertical grid level.
99!
100! 1092 2013-02-02 11:24:22Z raasch
101! unused variables removed
102!
103! 1036 2012-10-22 13:43:42Z raasch
104! code put under GPL (PALM 3.9)
105!
106! 849 2012-03-15 10:35:09Z raasch
107! routine renamed: init_particles -> lpm_init
108! de_dx, de_dy, de_dz are allocated here (instead of automatic arrays in
109! advec_particles),
110! sort_particles renamed lpm_sort_arrays, user_init_particles renamed lpm_init
111!
112! 828 2012-02-21 12:00:36Z raasch
113! call of init_kernels, particle feature color renamed class
114!
115! 824 2012-02-17 09:09:57Z raasch
116! particle attributes speed_x|y|z_sgs renamed rvar1|2|3,
117! array particles implemented as pointer
118!
119! 667 2010-12-23 12:06:00Z suehring/gryschka
120! nxl-1, nxr+1, nys-1, nyn+1 replaced by nxlg, nxrg, nysg, nyng for allocation
121! of arrays.
122!
123! Revision 1.1  1999/11/25 16:22:38  raasch
124! Initial revision
125!
126!
127! Description:
128! ------------
129!> This routine initializes a set of particles and their attributes (position,
130!> radius, ..) which are used by the Lagrangian particle model (see lpm).
131!------------------------------------------------------------------------------!
132 MODULE lpm_init_mod
133 
134
135    USE arrays_3d,                                                             &
136        ONLY:  de_dx, de_dy, de_dz, zu, zw, z0
137
138    USE control_parameters,                                                    &
139        ONLY:  cloud_droplets, constant_flux_layer, current_timestep_number,   &
140               dz, initializing_actions, message_string, ocean, simulated_time
141
142    USE grid_variables,                                                        &
143        ONLY:  ddx, dx, ddy, dy
144
145    USE indices,                                                               &
146        ONLY:  nx, nxl, nxlg, nxrg, nxr, ny, nyn, nys, nyng, nysg, nz, nzb,    &
147               nzb_w_inner, nzt
148
149    USE kinds
150
151    USE lpm_collision_kernels_mod,                                             &
152        ONLY:  init_kernels
153
154    USE netcdf_interface,                                                      &
155        ONLY:  netcdf_data_format
156
157    USE particle_attributes,                                                   &
158        ONLY:   alloc_factor, bc_par_b, bc_par_lr, bc_par_ns, bc_par_t,        &
159                block_offset, block_offset_def, collision_kernel,              &
160                curvature_solution_effects,                                    &
161                density_ratio, grid_particles,                                 &
162                initial_weighting_factor, ibc_par_b, ibc_par_lr, ibc_par_ns,   &
163                ibc_par_t, iran_part, log_z_z0,                                &
164                max_number_of_particle_groups, maximum_number_of_particles,    &
165                min_nr_particle, mpi_particle_type,                            &
166                number_of_particles,                                           &
167                number_of_particle_groups, number_of_sublayers,                &
168                offset_ocean_nzt, offset_ocean_nzt_m1,                         &
169                particles, particle_advection_start, particle_groups,          &
170                particle_groups_type, particles_per_point,                     &
171                particle_type, pdx, pdy, pdz,                                  &
172                prt_count, psb, psl, psn, psr, pss, pst,                       &
173                radius, random_start_position, read_particles_from_restartfile,&
174                seed_follows_topography, sgs_wf_part, sort_count,              &
175                total_number_of_particles,                                     &
176                use_sgs_for_particles,                                         &
177                write_particle_statistics, uniform_particles, zero_particle,   &
178                z0_av_global
179
180    USE pegrid
181
182    USE random_function_mod,                                                   &
183        ONLY:  random_function
184
185    IMPLICIT NONE
186
187    PRIVATE
188
189    INTEGER(iwp), PARAMETER         :: PHASE_INIT    = 1  !<
190    INTEGER(iwp), PARAMETER, PUBLIC :: PHASE_RELEASE = 2  !<
191
192    INTERFACE lpm_init
193       MODULE PROCEDURE lpm_init
194    END INTERFACE lpm_init
195
196    INTERFACE lpm_create_particle
197       MODULE PROCEDURE lpm_create_particle
198    END INTERFACE lpm_create_particle
199
200    PUBLIC lpm_init, lpm_create_particle
201
202 CONTAINS
203
204!------------------------------------------------------------------------------!
205! Description:
206! ------------
207!> @todo Missing subroutine description.
208!------------------------------------------------------------------------------!
209 SUBROUTINE lpm_init
210
211    USE lpm_collision_kernels_mod,                                             &
212        ONLY:  init_kernels
213
214    IMPLICIT NONE
215
216    INTEGER(iwp) ::  i                           !<
217    INTEGER(iwp) ::  j                           !<
218    INTEGER(iwp) ::  k                           !<
219
220#if defined( __parallel )
221    INTEGER(iwp), DIMENSION(3) ::  blocklengths  !<
222    INTEGER(iwp), DIMENSION(3) ::  displacements !<
223    INTEGER(iwp), DIMENSION(3) ::  types         !<
224#endif
225
226    REAL(wp) ::  height_int                      !<
227    REAL(wp) ::  height_p                        !<
228    REAL(wp) ::  z_p                             !<
229    REAL(wp) ::  z0_av_local                     !<
230
231#if defined( __parallel )
232!
233!-- Define MPI derived datatype for FORTRAN datatype particle_type (see module
234!-- particle_attributes). Integer length is 4 byte, Real is 8 byte
235    blocklengths(1)  = 19;  blocklengths(2)  =   6;  blocklengths(3)  =   1
236    displacements(1) =  0;  displacements(2) = 152;  displacements(3) = 176
237
238    types(1) = MPI_REAL
239    types(2) = MPI_INTEGER
240    types(3) = MPI_UB
241    CALL MPI_TYPE_STRUCT( 3, blocklengths, displacements, types, &
242                          mpi_particle_type, ierr )
243    CALL MPI_TYPE_COMMIT( mpi_particle_type, ierr )
244#endif
245
246!
247!-- In case of oceans runs, the vertical index calculations need an offset,
248!-- because otherwise the k indices will become negative
249    IF ( ocean )  THEN
250       offset_ocean_nzt    = nzt
251       offset_ocean_nzt_m1 = nzt - 1
252    ENDIF
253
254!
255!-- Define block offsets for dividing a gridcell in 8 sub cells
256
257    block_offset(0) = block_offset_def (-1,-1,-1)
258    block_offset(1) = block_offset_def (-1,-1, 0)
259    block_offset(2) = block_offset_def (-1, 0,-1)
260    block_offset(3) = block_offset_def (-1, 0, 0)
261    block_offset(4) = block_offset_def ( 0,-1,-1)
262    block_offset(5) = block_offset_def ( 0,-1, 0)
263    block_offset(6) = block_offset_def ( 0, 0,-1)
264    block_offset(7) = block_offset_def ( 0, 0, 0)
265!
266!-- Check the number of particle groups.
267    IF ( number_of_particle_groups > max_number_of_particle_groups )  THEN
268       WRITE( message_string, * ) 'max_number_of_particle_groups =',      &
269                                  max_number_of_particle_groups ,         &
270                                  '&number_of_particle_groups reset to ', &
271                                  max_number_of_particle_groups
272       CALL message( 'lpm_init', 'PA0213', 0, 1, 0, 6, 0 )
273       number_of_particle_groups = max_number_of_particle_groups
274    ENDIF
275
276!
277!-- Set default start positions, if necessary
278    IF ( psl(1) == 9999999.9_wp )  psl(1) = -0.5_wp * dx
279    IF ( psr(1) == 9999999.9_wp )  psr(1) = ( nx + 0.5_wp ) * dx
280    IF ( pss(1) == 9999999.9_wp )  pss(1) = -0.5_wp * dy
281    IF ( psn(1) == 9999999.9_wp )  psn(1) = ( ny + 0.5_wp ) * dy
282    IF ( psb(1) == 9999999.9_wp )  psb(1) = zu(nz/2)
283    IF ( pst(1) == 9999999.9_wp )  pst(1) = psb(1)
284
285    IF ( pdx(1) == 9999999.9_wp  .OR.  pdx(1) == 0.0_wp )  pdx(1) = dx
286    IF ( pdy(1) == 9999999.9_wp  .OR.  pdy(1) == 0.0_wp )  pdy(1) = dy
287    IF ( pdz(1) == 9999999.9_wp  .OR.  pdz(1) == 0.0_wp )  pdz(1) = zu(2) - zu(1)
288
289    DO  j = 2, number_of_particle_groups
290       IF ( psl(j) == 9999999.9_wp )  psl(j) = psl(j-1)
291       IF ( psr(j) == 9999999.9_wp )  psr(j) = psr(j-1)
292       IF ( pss(j) == 9999999.9_wp )  pss(j) = pss(j-1)
293       IF ( psn(j) == 9999999.9_wp )  psn(j) = psn(j-1)
294       IF ( psb(j) == 9999999.9_wp )  psb(j) = psb(j-1)
295       IF ( pst(j) == 9999999.9_wp )  pst(j) = pst(j-1)
296       IF ( pdx(j) == 9999999.9_wp  .OR.  pdx(j) == 0.0_wp )  pdx(j) = pdx(j-1)
297       IF ( pdy(j) == 9999999.9_wp  .OR.  pdy(j) == 0.0_wp )  pdy(j) = pdy(j-1)
298       IF ( pdz(j) == 9999999.9_wp  .OR.  pdz(j) == 0.0_wp )  pdz(j) = pdz(j-1)
299    ENDDO
300
301!
302!-- Allocate arrays required for calculating particle SGS velocities.
303!-- Initialize prefactor required for stoachastic Weil equation.
304    IF ( use_sgs_for_particles  .AND.  .NOT. cloud_droplets )  THEN
305       ALLOCATE( de_dx(nzb:nzt+1,nysg:nyng,nxlg:nxrg), &
306                 de_dy(nzb:nzt+1,nysg:nyng,nxlg:nxrg), &
307                 de_dz(nzb:nzt+1,nysg:nyng,nxlg:nxrg) )
308
309       sgs_wf_part = 1.0_wp / 3.0_wp   
310    ENDIF
311
312!
313!-- Allocate array required for logarithmic vertical interpolation of
314!-- horizontal particle velocities between the surface and the first vertical
315!-- grid level. In order to avoid repeated CPU cost-intensive CALLS of
316!-- intrinsic FORTRAN procedure LOG(z/z0), LOG(z/z0) is precalculated for
317!-- several heights. Splitting into 20 sublayers turned out to be sufficient.
318!-- To obtain exact height levels of particles, linear interpolation is applied
319!-- (see lpm_advec.f90).
320    IF ( constant_flux_layer )  THEN
321       
322       ALLOCATE ( log_z_z0(0:number_of_sublayers) ) 
323       z_p         = zu(nzb+1) - zw(nzb)
324
325!
326!--    Calculate horizontal mean value of z0 used for logartihmic
327!--    interpolation. Note: this is not exact for heterogeneous z0.
328!--    However, sensitivity studies showed that the effect is
329!--    negligible.
330       z0_av_local  = SUM( z0(nys:nyn,nxl:nxr) )
331       z0_av_global = 0.0_wp
332
333#if defined( __parallel )
334       CALL MPI_ALLREDUCE(z0_av_local, z0_av_global, 1, MPI_REAL, MPI_SUM, &
335                          comm2d, ierr )
336#else
337       z0_av_global = z0_av_local
338#endif
339
340       z0_av_global = z0_av_global  / ( ( ny + 1 ) * ( nx + 1 ) )
341!
342!--    Horizontal wind speed is zero below and at z0
343       log_z_z0(0) = 0.0_wp
344!
345!--    Calculate vertical depth of the sublayers
346       height_int  = ( z_p - z0_av_global ) / REAL( number_of_sublayers, KIND=wp )
347!
348!--    Precalculate LOG(z/z0)
349       height_p    = z0_av_global
350       DO  k = 1, number_of_sublayers
351
352          height_p    = height_p + height_int
353          log_z_z0(k) = LOG( height_p / z0_av_global )
354
355       ENDDO
356
357    ENDIF
358
359!
360!-- Check boundary condition and set internal variables
361    SELECT CASE ( bc_par_b )
362   
363       CASE ( 'absorb' )
364          ibc_par_b = 1
365
366       CASE ( 'reflect' )
367          ibc_par_b = 2
368         
369       CASE DEFAULT
370          WRITE( message_string, * )  'unknown boundary condition ',   &
371                                       'bc_par_b = "', TRIM( bc_par_b ), '"'
372          CALL message( 'lpm_init', 'PA0217', 1, 2, 0, 6, 0 )
373         
374    END SELECT
375    SELECT CASE ( bc_par_t )
376   
377       CASE ( 'absorb' )
378          ibc_par_t = 1
379
380       CASE ( 'reflect' )
381          ibc_par_t = 2
382         
383       CASE DEFAULT
384          WRITE( message_string, * ) 'unknown boundary condition ',   &
385                                     'bc_par_t = "', TRIM( bc_par_t ), '"'
386          CALL message( 'lpm_init', 'PA0218', 1, 2, 0, 6, 0 )
387         
388    END SELECT
389    SELECT CASE ( bc_par_lr )
390
391       CASE ( 'cyclic' )
392          ibc_par_lr = 0
393
394       CASE ( 'absorb' )
395          ibc_par_lr = 1
396
397       CASE ( 'reflect' )
398          ibc_par_lr = 2
399         
400       CASE DEFAULT
401          WRITE( message_string, * ) 'unknown boundary condition ',   &
402                                     'bc_par_lr = "', TRIM( bc_par_lr ), '"'
403          CALL message( 'lpm_init', 'PA0219', 1, 2, 0, 6, 0 )
404         
405    END SELECT
406    SELECT CASE ( bc_par_ns )
407
408       CASE ( 'cyclic' )
409          ibc_par_ns = 0
410
411       CASE ( 'absorb' )
412          ibc_par_ns = 1
413
414       CASE ( 'reflect' )
415          ibc_par_ns = 2
416         
417       CASE DEFAULT
418          WRITE( message_string, * ) 'unknown boundary condition ',   &
419                                     'bc_par_ns = "', TRIM( bc_par_ns ), '"'
420          CALL message( 'lpm_init', 'PA0220', 1, 2, 0, 6, 0 )
421         
422    END SELECT
423
424!
425!-- Initialize collision kernels
426    IF ( collision_kernel /= 'none' )  CALL init_kernels
427
428!
429!-- For the first model run of a possible job chain initialize the
430!-- particles, otherwise read the particle data from restart file.
431    IF ( TRIM( initializing_actions ) == 'read_restart_data'  &
432         .AND.  read_particles_from_restartfile )  THEN
433
434       CALL lpm_read_restart_file
435
436    ELSE
437
438!
439!--    Allocate particle arrays and set attributes of the initial set of
440!--    particles, which can be also periodically released at later times.
441       ALLOCATE( prt_count(nzb:nzt+1,nysg:nyng,nxlg:nxrg), &
442                 grid_particles(nzb+1:nzt,nys:nyn,nxl:nxr) )
443
444       maximum_number_of_particles = 0
445       number_of_particles         = 0
446
447       sort_count = 0
448       prt_count  = 0
449
450!
451!--    Initialize all particles with dummy values (otherwise errors may
452!--    occur within restart runs). The reason for this is still not clear
453!--    and may be presumably caused by errors in the respective user-interface.
454       zero_particle = particle_type( 0.0_wp, 0.0_wp, 0.0_wp, 0.0_wp, 0.0_wp,  &
455                                      0.0_wp, 0.0_wp, 0.0_wp, 0.0_wp, 0.0_wp,  &
456                                      0.0_wp, 0.0_wp, 0.0_wp, 0.0_wp, 0.0_wp,  &
457                                      0.0_wp, 0.0_wp, 0.0_wp, 0.0_wp, 0, 0, 0, &
458                                      0, .FALSE., -1 )
459
460       particle_groups = particle_groups_type( 0.0_wp, 0.0_wp, 0.0_wp, 0.0_wp )
461
462!
463!--    Set values for the density ratio and radius for all particle
464!--    groups, if necessary
465       IF ( density_ratio(1) == 9999999.9_wp )  density_ratio(1) = 0.0_wp
466       IF ( radius(1)        == 9999999.9_wp )  radius(1) = 0.0_wp
467       DO  i = 2, number_of_particle_groups
468          IF ( density_ratio(i) == 9999999.9_wp )  THEN
469             density_ratio(i) = density_ratio(i-1)
470          ENDIF
471          IF ( radius(i) == 9999999.9_wp )  radius(i) = radius(i-1)
472       ENDDO
473
474       DO  i = 1, number_of_particle_groups
475          IF ( density_ratio(i) /= 0.0_wp  .AND.  radius(i) == 0 )  THEN
476             WRITE( message_string, * ) 'particle group #', i, 'has a', &
477                                        'density ratio /= 0 but radius = 0'
478             CALL message( 'lpm_init', 'PA0215', 1, 2, 0, 6, 0 )
479          ENDIF
480          particle_groups(i)%density_ratio = density_ratio(i)
481          particle_groups(i)%radius        = radius(i)
482       ENDDO
483
484!
485!--    Set a seed value for the random number generator to be exclusively
486!--    used for the particle code. The generated random numbers should be
487!--    different on the different PEs.
488       iran_part = iran_part + myid
489
490       CALL lpm_create_particle (PHASE_INIT)
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    ENDIF
506
507!
508!-- To avoid programm abort, assign particles array to the local version of
509!-- first grid cell
510    number_of_particles = prt_count(nzb+1,nys,nxl)
511    particles => grid_particles(nzb+1,nys,nxl)%particles(1:number_of_particles)
512!
513!-- Formats
5148000 FORMAT (I6,1X,F7.2,4X,I10,71X,I10)
515
516 END SUBROUTINE lpm_init
517
518!------------------------------------------------------------------------------!
519! Description:
520! ------------
521!> @todo Missing subroutine description.
522!------------------------------------------------------------------------------!
523 SUBROUTINE lpm_create_particle (phase)
524
525    USE lpm_exchange_horiz_mod,                                                &
526        ONLY: lpm_exchange_horiz, lpm_move_particle, realloc_particles_array
527
528    USE lpm_pack_arrays_mod,                                                   &
529        ONLY: lpm_pack_all_arrays
530
531    USE particle_attributes,                                                   &
532        ONLY: deleted_particles, monodisperse_aerosols
533
534    IMPLICIT  NONE
535
536    INTEGER(iwp)               ::  alloc_size  !< relative increase of allocated memory for particles
537    INTEGER(iwp)               ::  i           !< loop variable ( particle groups )
538    INTEGER(iwp)               ::  ip          !< index variable along x
539    INTEGER(iwp)               ::  j           !< loop variable ( particles per point )
540    INTEGER(iwp)               ::  jp          !< index variable along y
541    INTEGER(iwp)               ::  kp          !< index variable along z
542    INTEGER(iwp)               ::  loop_stride !< loop variable for initialization
543    INTEGER(iwp)               ::  n           !< loop variable ( number of particles )
544    INTEGER(iwp)               ::  new_size    !< new size of allocated memory for particles
545
546    INTEGER(iwp), INTENT(IN)   ::  phase       !< mode of inititialization
547
548    INTEGER(iwp), DIMENSION(nzb:nzt+1,nysg:nyng,nxlg:nxrg) ::  local_count !< start address of new particle
549    INTEGER(iwp), DIMENSION(nzb:nzt+1,nysg:nyng,nxlg:nxrg) ::  local_start !< start address of new particle
550
551    LOGICAL                    ::  first_stride !< flag for initialization
552
553    REAL(wp)                   ::  pos_x      !< increment for particle position in x     
554    REAL(wp)                   ::  pos_y      !< increment for particle position in y 
555    REAL(wp)                   ::  pos_z      !< increment for particle position in z     
556    REAL(wp)                   ::  rand_contr !< dummy argument for random position
557
558    TYPE(particle_type),TARGET ::  tmp_particle !< temporary particle used for initialization
559
560!
561!-- Calculate particle positions and store particle attributes, if
562!-- particle is situated on this PE
563    DO  loop_stride = 1, 2
564       first_stride = (loop_stride == 1)
565       IF ( first_stride )   THEN
566          local_count = 0           ! count number of particles
567       ELSE
568          local_count = prt_count   ! Start address of new particles
569       ENDIF
570
571       n = 0
572       DO  i = 1, number_of_particle_groups
573
574          pos_z = psb(i)
575
576          DO WHILE ( pos_z <= pst(i) )
577
578             pos_y = pss(i)
579
580             DO WHILE ( pos_y <= psn(i) )
581
582                IF ( pos_y >= ( nys - 0.5_wp ) * dy  .AND.  &
583                     pos_y <  ( nyn + 0.5_wp ) * dy )  THEN
584
585                   pos_x = psl(i)
586
587            xloop: DO WHILE ( pos_x <= psr(i) )
588
589                      IF ( pos_x >= ( nxl - 0.5_wp ) * dx  .AND.  &
590                           pos_x <  ( nxr + 0.5_wp ) * dx )  THEN
591
592                         DO  j = 1, particles_per_point
593
594                            n = n + 1
595                            tmp_particle%x             = pos_x
596                            tmp_particle%y             = pos_y
597                            tmp_particle%z             = pos_z
598                            tmp_particle%age           = 0.0_wp
599                            tmp_particle%age_m         = 0.0_wp
600                            tmp_particle%dt_sum        = 0.0_wp
601                            tmp_particle%dvrp_psize    = 0.0_wp !unused
602                            tmp_particle%e_m           = 0.0_wp
603                            IF ( curvature_solution_effects )  THEN
604!
605!--                            Initial values (internal timesteps, derivative)
606!--                            for Rosenbrock method
607                               tmp_particle%rvar1      = 1.0E-6_wp     !last Rosenbrock timestep
608                               tmp_particle%rvar2      = 0.1E-6_wp     !dry aerosol radius
609                               tmp_particle%rvar3      = -9999999.9_wp !unused
610                            ELSE
611!
612!--                            Initial values for SGS velocities
613                               tmp_particle%rvar1      = 0.0_wp
614                               tmp_particle%rvar2      = 0.0_wp
615                               tmp_particle%rvar3      = 0.0_wp
616                            ENDIF
617                            tmp_particle%speed_x       = 0.0_wp
618                            tmp_particle%speed_y       = 0.0_wp
619                            tmp_particle%speed_z       = 0.0_wp
620                            tmp_particle%origin_x      = pos_x
621                            tmp_particle%origin_y      = pos_y
622                            tmp_particle%origin_z      = pos_z
623                            tmp_particle%radius        = particle_groups(i)%radius
624                            tmp_particle%weight_factor = initial_weighting_factor
625                            tmp_particle%class         = 1
626                            tmp_particle%group         = i
627                            tmp_particle%tailpoints    = 0     !unused
628                            tmp_particle%particle_mask = .TRUE.
629                            tmp_particle%tail_id       = 0     !unused
630
631
632!
633!--                         Determine the grid indices of the particle position
634                            ip = ( tmp_particle%x + 0.5_wp * dx ) * ddx
635                            jp = ( tmp_particle%y + 0.5_wp * dy ) * ddy
636                            kp = tmp_particle%z / dz + 1 + offset_ocean_nzt
637
638                            IF ( seed_follows_topography )  THEN
639!
640!--                            Particle height is given relative to topography
641                               kp = kp + nzb_w_inner(jp,ip)
642                               tmp_particle%z = tmp_particle%z +               &
643                                                         zw(nzb_w_inner(jp,ip))
644                               IF ( kp > nzt )  THEN
645                                  pos_x = pos_x + pdx(i)
646                                  CYCLE xloop
647                               ENDIF
648                            ELSEIF ( .NOT. seed_follows_topography .AND.       &
649                                     tmp_particle%z <= zw(nzb_w_inner(jp,ip)) )  THEN
650                               pos_x = pos_x + pdx(i)
651                               CYCLE xloop                               
652                            ENDIF
653
654                            local_count(kp,jp,ip) = local_count(kp,jp,ip) + 1
655                            IF ( .NOT. first_stride )  THEN
656                               IF ( ip < nxl  .OR.  jp < nys  .OR.  kp < nzb+1 )  THEN
657                                  write(6,*) 'xl ',ip,jp,kp,nxl,nys,nzb+1
658                               ENDIF
659                               IF ( ip > nxr  .OR.  jp > nyn  .OR.  kp > nzt )  THEN
660                                  write(6,*) 'xu ',ip,jp,kp,nxr,nyn,nzt
661                               ENDIF
662                               grid_particles(kp,jp,ip)%particles(local_count(kp,jp,ip)) = tmp_particle
663
664                            ENDIF
665                         ENDDO
666
667                      ENDIF
668
669                      pos_x = pos_x + pdx(i)
670
671                   ENDDO xloop
672
673                ENDIF
674
675                pos_y = pos_y + pdy(i)
676
677             ENDDO
678
679             pos_z = pos_z + pdz(i)
680
681          ENDDO
682
683       ENDDO
684
685       IF ( first_stride )  THEN
686          DO  ip = nxl, nxr
687             DO  jp = nys, nyn
688                DO  kp = nzb+1, nzt
689                   IF ( phase == PHASE_INIT )  THEN
690                      IF ( local_count(kp,jp,ip) > 0 )  THEN
691                         alloc_size = MAX( INT( local_count(kp,jp,ip) *        &
692                            ( 1.0_wp + alloc_factor / 100.0_wp ) ),            &
693                            min_nr_particle )
694                      ELSE
695                         alloc_size = min_nr_particle
696                      ENDIF
697                      ALLOCATE(grid_particles(kp,jp,ip)%particles(1:alloc_size))
698                      DO  n = 1, alloc_size
699                         grid_particles(kp,jp,ip)%particles(n) = zero_particle
700                      ENDDO
701                   ELSEIF ( phase == PHASE_RELEASE )  THEN
702                      IF ( local_count(kp,jp,ip) > 0 )  THEN
703                         new_size   = local_count(kp,jp,ip) + prt_count(kp,jp,ip)
704                         alloc_size = MAX( INT( new_size * ( 1.0_wp +          &
705                            alloc_factor / 100.0_wp ) ), min_nr_particle )
706                         IF( alloc_size > SIZE( grid_particles(kp,jp,ip)%particles) )  THEN
707                           CALL realloc_particles_array(ip,jp,kp,alloc_size)
708                         ENDIF
709                      ENDIF
710                   ENDIF
711
712                ENDDO
713             ENDDO
714          ENDDO
715       ENDIF
716
717    ENDDO
718
719    local_start = prt_count+1
720    prt_count   = local_count
721
722!
723!-- Initialize aerosol background spectrum
724    IF ( curvature_solution_effects  .AND.  .NOT. monodisperse_aerosols )  THEN
725       CALL lpm_init_aerosols(local_start)
726    ENDIF
727
728!
729!-- Add random fluctuation to particle positions.
730    IF ( random_start_position )  THEN
731       DO  ip = nxl, nxr
732          DO  jp = nys, nyn
733             DO  kp = nzb+1, nzt
734                number_of_particles = prt_count(kp,jp,ip)
735                IF ( number_of_particles <= 0 )  CYCLE
736                particles => grid_particles(kp,jp,ip)%particles(1:number_of_particles)
737!
738!--             Move only new particles. Moreover, limit random fluctuation
739!--             in order to prevent that particles move more than one grid box,
740!--             which would lead to problems concerning particle exchange
741!--             between processors in case pdx/pdy are larger than dx/dy,
742!--             respectively. 
743                DO  n = local_start(kp,jp,ip), number_of_particles
744                   IF ( psl(particles(n)%group) /= psr(particles(n)%group) )  THEN
745                      rand_contr = ( random_function( iran_part ) - 0.5_wp ) * &
746                                     pdx(particles(n)%group)
747                      particles(n)%x = particles(n)%x +                        &
748                              MERGE( rand_contr, SIGN( dx, rand_contr ), &
749                                     ABS( rand_contr ) < dx                    &
750                                   ) 
751                   ENDIF
752                   IF ( pss(particles(n)%group) /= psn(particles(n)%group) )  THEN
753                      rand_contr = ( random_function( iran_part ) - 0.5_wp ) * &
754                                     pdy(particles(n)%group)
755                      particles(n)%y = particles(n)%y +                        &
756                              MERGE( rand_contr, SIGN( dy, rand_contr ), &
757                                     ABS( rand_contr ) < dy                    &
758                                   ) 
759                   ENDIF
760                   IF ( psb(particles(n)%group) /= pst(particles(n)%group) )  THEN
761                      rand_contr = ( random_function( iran_part ) - 0.5_wp ) * &
762                                     pdz(particles(n)%group)
763                      particles(n)%z = particles(n)%z +                        &
764                              MERGE( rand_contr, SIGN( dz, rand_contr ), &
765                                     ABS( rand_contr ) < dz                    &
766                                   ) 
767                   ENDIF
768                ENDDO
769!
770!--             Identify particles located outside the model domain and reflect
771!--             or absorb them if necessary.
772                CALL lpm_boundary_conds( 'bottom/top' )
773!
774!--             Furthermore, remove particles located in topography. Note, as
775!--             the particle speed is still zero at this point, wall
776!--             reflection boundary conditions will not work in this case.
777                particles =>                                                   &
778                       grid_particles(kp,jp,ip)%particles(1:number_of_particles)
779                DO  n = local_start(kp,jp,ip), number_of_particles
780                   i = ( particles(n)%x + 0.5_wp * dx ) * ddx
781                   j = ( particles(n)%y + 0.5_wp * dy ) * ddy
782                   IF ( particles(n)%z <= zw(nzb_w_inner(j,i)) )  THEN
783                      particles(n)%particle_mask = .FALSE.
784                      deleted_particles = deleted_particles + 1
785                   ENDIF
786                ENDDO
787             ENDDO
788          ENDDO
789       ENDDO
790!
791!--    Exchange particles between grid cells and processors
792       CALL lpm_move_particle
793       CALL lpm_exchange_horiz
794
795    ENDIF
796!
797!-- In case of random_start_position, delete particles identified by
798!-- lpm_exchange_horiz and lpm_boundary_conds. Then sort particles into blocks,
799!-- which is needed for a fast interpolation of the LES fields on the particle
800!-- position.
801    CALL lpm_pack_all_arrays
802
803!
804!-- Determine maximum number of particles (i.e., all possible particles that
805!-- have been allocated) and the current number of particles
806    DO  ip = nxl, nxr
807       DO  jp = nys, nyn
808          DO  kp = nzb+1, nzt
809             maximum_number_of_particles = maximum_number_of_particles         &
810                                           + SIZE(grid_particles(kp,jp,ip)%particles)
811             number_of_particles         = number_of_particles                 &
812                                           + prt_count(kp,jp,ip)
813          ENDDO
814       ENDDO
815    ENDDO
816!
817!-- Calculate the number of particles of the total domain
818#if defined( __parallel )
819    IF ( collective_wait )  CALL MPI_BARRIER( comm2d, ierr )
820    CALL MPI_ALLREDUCE( number_of_particles, total_number_of_particles, 1, &
821    MPI_INTEGER, MPI_SUM, comm2d, ierr )
822#else
823    total_number_of_particles = number_of_particles
824#endif
825
826    RETURN
827
828 END SUBROUTINE lpm_create_particle
829
830 SUBROUTINE lpm_init_aerosols(local_start)
831
832    USE arrays_3d,                                                             &
833        ONLY: hyp, pt, q 
834
835    USE cloud_parameters,                                                      &
836        ONLY: l_d_rv, rho_l
837
838    USE constants,                                                             &
839        ONLY: pi
840
841    USE kinds
842
843    USE particle_attributes,                                                   &
844        ONLY: init_aerosol_probabilistic, molecular_weight_of_solute,          &
845              molecular_weight_of_water, n1, n2, n3, rho_s, rm1, rm2, rm3,     &
846              s1, s2, s3, vanthoff
847
848    IMPLICIT NONE
849
850    REAL(wp), DIMENSION(:), ALLOCATABLE ::  cdf     !< CDF of aerosol spectrum
851    REAL(wp), DIMENSION(:), ALLOCATABLE ::  r_temp  !< dry aerosol radius spectrum
852
853    REAL(wp)  :: bfactor            !< solute effects
854    REAL(wp)  :: dr                 !< width of radius bin
855    REAL(wp)  :: e_a                !< vapor pressure
856    REAL(wp)  :: e_s                !< saturation vapor pressure
857    REAL(wp)  :: n_init             !< sum of all aerosol concentrations
858    REAL(wp)  :: pdf                !< PDF of aerosol spectrum
859    REAL(wp)  :: rmin = 1.0e-8_wp   !< minimum aerosol radius
860    REAL(wp)  :: rmax = 1.0e-6_wp   !< maximum aerosol radius
861    REAL(wp)  :: rs_rand            !< random number
862    REAL(wp)  :: r_mid              !< mean radius
863    REAL(wp)  :: t_int              !< temperature
864    REAL(wp)  :: weight_sum         !< sum of all weighting factors
865
866    INTEGER(iwp), DIMENSION(nzb:nzt+1,nysg:nyng,nxlg:nxrg), INTENT(IN) ::  local_start !<
867
868    INTEGER(iwp)  :: n              !<
869    INTEGER(iwp)  :: nn             !<
870    INTEGER(iwp)  :: no_bins = 999  !< number of bins
871    INTEGER(iwp)  :: ip             !<
872    INTEGER(iwp)  :: jp             !<
873    INTEGER(iwp)  :: kp             !<
874
875    LOGICAL ::  new_pdf = .FALSE.   !< check if aerosol PDF has to be recalculated
876
877!
878!-- Compute aerosol background distribution
879    IF ( init_aerosol_probabilistic )  THEN
880       ALLOCATE( cdf(0:no_bins), r_temp(0:no_bins) )
881       DO n = 0, no_bins
882          r_temp(n) = EXP( LOG(rmin) + ( LOG(rmax) - LOG(rmin ) ) /            &
883                           REAL(no_bins, KIND=wp) * REAL(n, KIND=wp) )
884
885          cdf(n) = 0.0_wp
886          n_init = n1 + n2 + n3
887          IF ( n1 > 0.0_wp )  THEN
888             cdf(n) = cdf(n) + n1 / n_init * ( 0.5_wp + 0.5_wp *        &
889                                  ERF( LOG( r_temp(n) / rm1 ) /         &
890                                       ( SQRT(2.0_wp) * LOG(s1) )       &
891                                     ) )
892          ENDIF
893          IF ( n2 > 0.0_wp )  THEN
894             cdf(n) = cdf(n) + n2 / n_init * ( 0.5_wp + 0.5_wp *        &
895                                  ERF( LOG( r_temp(n) / rm2 ) /         &
896                                       ( SQRT(2.0_wp) * LOG(s2) )       &
897                                     ) )
898          ENDIF
899          IF ( n3 > 0.0_wp )  THEN
900             cdf(n) = cdf(n) + n3 / n_init * ( 0.5_wp + 0.5_wp *        &
901                                  ERF( LOG( r_temp(n) / rm3 ) /         &
902                                       ( SQRT(2.0_wp) * LOG(s3) )       &
903                                     ) )
904          ENDIF
905
906       ENDDO
907    ENDIF
908
909    DO  ip = nxl, nxr
910       DO  jp = nys, nyn
911          DO  kp = nzb+1, nzt
912
913             number_of_particles = prt_count(kp,jp,ip)
914             IF ( number_of_particles <= 0 )  CYCLE
915             particles => grid_particles(kp,jp,ip)%particles(1:number_of_particles)
916!
917!--          Initialize the aerosols with a predefined spectral distribution
918!--          of the dry radius (logarithmically increasing bins) and a varying
919!--          weighting factor
920             IF ( .NOT. init_aerosol_probabilistic )  THEN
921
922                new_pdf = .FALSE.
923                IF ( .NOT. ALLOCATED( r_temp ) )  THEN
924                   new_pdf = .TRUE.
925                ELSE
926                   IF ( SIZE( r_temp ) .NE. &
927                        number_of_particles - local_start(kp,jp,ip) + 2 )  THEN
928                      new_pdf = .TRUE.
929                      DEALLOCATE( r_temp )
930                   ENDIF
931                ENDIF
932
933                IF ( new_pdf )  THEN
934
935                   no_bins = number_of_particles + 1 - local_start(kp,jp,ip)
936                   ALLOCATE( r_temp(0:no_bins) )
937
938                   DO n = 0, no_bins
939                      r_temp(n) = EXP( LOG(rmin) + ( LOG(rmax) - LOG(rmin ) ) / &
940                                       REAL(no_bins, KIND=wp) *                 &
941                                       REAL(n, KIND=wp) )
942                   ENDDO
943
944                ENDIF
945
946!
947!--             Calculate radius and concentration of each aerosol
948                DO n = local_start(kp,jp,ip), number_of_particles
949
950                   nn = n - local_start(kp,jp,ip)
951
952                   r_mid = SQRT( r_temp(nn) * r_temp(nn+1) )
953                   dr    = r_temp(nn+1) - r_temp(nn)
954
955                   pdf    = 0.0_wp
956                   n_init = n1 + n2 + n3
957                   IF ( n1 > 0.0_wp )  THEN
958                      pdf = pdf + n1 / n_init * ( 1.0_wp / ( r_mid * LOG(s1) *      &
959                                                             SQRT( 2.0_wp * pi )    &
960                                                           ) *                      &
961                                                  EXP( -( LOG( r_mid / rm1 ) )**2 / &
962                                                       ( 2.0_wp * LOG(s1)**2 )      &
963                                                     )                              &
964                                                )
965                   ENDIF
966                   IF ( n2 > 0.0_wp )  THEN
967                      pdf = pdf + n2 / n_init * ( 1.0_wp / ( r_mid * LOG(s2) *      &
968                                                             SQRT( 2.0_wp * pi )    &
969                                                           ) *                      &
970                                                  EXP( -( LOG( r_mid / rm2 ) )**2 / &
971                                                       ( 2.0_wp * LOG(s2)**2 )      &
972                                                     )                              &
973                                                )
974                   ENDIF
975                   IF ( n3 > 0.0_wp )  THEN
976                      pdf = pdf + n3 / n_init * ( 1.0_wp / ( r_mid * LOG(s3) *      &
977                                                             SQRT( 2.0_wp * pi )    &
978                                                           ) *                      &
979                                                  EXP( -( LOG( r_mid / rm3 ) )**2 / &
980                                                       ( 2.0_wp * LOG(s3)**2 )      &
981                                                     )                              &
982                                                )
983                   ENDIF
984
985                   particles(n)%rvar2         = r_mid
986                   particles(n)%weight_factor = pdf * dr
987
988                END DO
989!
990!--             Adjust weighting factors to initialize the same number of aerosols
991!--             in every grid box
992                weight_sum = SUM(particles(local_start(kp,jp,ip):number_of_particles)%weight_factor)
993
994                particles(local_start(kp,jp,ip):number_of_particles)%weight_factor =     &
995                   particles(local_start(kp,jp,ip):number_of_particles)%weight_factor /  &
996                   weight_sum * initial_weighting_factor * ( no_bins + 1 )
997
998             ENDIF
999!
1000!--          Initialize the aerosols with a predefined weighting factor but
1001!--          a randomly choosen dry radius
1002             IF ( init_aerosol_probabilistic )  THEN
1003
1004                DO  n = local_start(kp,jp,ip), number_of_particles  !only new particles
1005
1006                   rs_rand = -1.0_wp
1007                   DO WHILE ( rs_rand .LT. cdf(0)  .OR.  rs_rand .GE. cdf(no_bins)  )
1008                      rs_rand = random_function( iran_part )
1009                   ENDDO
1010!
1011!--                Determine aerosol dry radius by a random number generator
1012                   DO nn = 0, no_bins-1
1013                      IF ( cdf(nn) .LE. rs_rand  .AND.  cdf(nn+1) .GT. rs_rand )  THEN
1014                         particles(n)%rvar2 = r_temp(nn) + ( r_temp(nn+1) - r_temp(nn) ) / &
1015                                              ( cdf(nn+1) - cdf(nn) ) * ( rs_rand - cdf(nn) )
1016                         EXIT
1017                      ENDIF
1018                   ENDDO
1019
1020                ENDDO
1021
1022             ENDIF
1023
1024!
1025!--          Set particle radius to equilibrium radius based on the environmental
1026!--          supersaturation (Khvorostyanov and Curry, 2007, JGR). This avoids
1027!--          the sometimes lengthy growth toward their equilibrium radius within
1028!--          the simulation.
1029             t_int  = pt(kp,jp,ip) * ( hyp(kp) / 100000.0_wp )**0.286_wp
1030
1031             e_s = 611.0_wp * EXP( l_d_rv * ( 3.6609E-3_wp - 1.0_wp / t_int ) )
1032             e_a = q(kp,jp,ip) * hyp(kp) / ( 0.378_wp * q(kp,jp,ip) + 0.622_wp )
1033
1034!
1035!--          The formula is only valid for subsaturated environments. For
1036!--          supersaturations higher than -1 %, the supersaturation is set to -1%.
1037             IF ( e_a / e_s < 0.99_wp )  THEN
1038
1039                DO  n = local_start(kp,jp,ip), number_of_particles  !only new particles
1040
1041                   bfactor             = vanthoff * molecular_weight_of_water *    &
1042                                         rho_s * particles(n)%rvar2**3 /           &
1043                                         ( molecular_weight_of_solute * rho_l )
1044                   particles(n)%radius = particles(n)%rvar2 * ( bfactor /          &
1045                                         particles(n)%rvar2**3 )**(1.0_wp/3.0_wp) *&
1046                                         ( 1.0_wp - e_a / e_s )**(-1.0_wp/3.0_wp)
1047
1048                ENDDO
1049
1050             ELSE
1051
1052                DO  n = local_start(kp,jp,ip), number_of_particles  !only new particles
1053
1054                   bfactor             = vanthoff * molecular_weight_of_water *    &
1055                                         rho_s * particles(n)%rvar2**3 /           &
1056                                         ( molecular_weight_of_solute * rho_l )
1057                   particles(n)%radius = particles(n)%rvar2 * ( bfactor /          &
1058                                         particles(n)%rvar2**3 )**(1.0_wp/3.0_wp) *&
1059                                         0.01_wp**(-1.0_wp/3.0_wp)
1060
1061                ENDDO
1062
1063             ENDIF
1064
1065          ENDDO
1066       ENDDO
1067    ENDDO
1068!
1069!-- Deallocate used arrays
1070    IF ( ALLOCATED(r_temp) )  DEALLOCATE( r_temp )
1071    IF ( ALLOCATED(cdf) )     DEALLOCATE( cdf )
1072
1073 END SUBROUTINE lpm_init_aerosols
1074
1075END MODULE lpm_init_mod
Note: See TracBrowser for help on using the repository browser.