source: palm/trunk/SOURCE/lpm.f90 @ 1929

Last change on this file since 1929 was 1929, checked in by suehring, 8 years ago

several bugfixes in particle model and serial mode

  • Property svn:keywords set to Id
File size: 14.5 KB
RevLine 
[1682]1!> @file lpm.f90
[1036]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!
[1818]16! Copyright 1997-2016 Leibniz Universitaet Hannover
[1036]17!--------------------------------------------------------------------------------!
18!
[230]19! Current revisions:
[759]20! ------------------
[1929]21! Call wall boundary conditions only if particles are in the vertical range of
22! topography.
[1823]23!
24! Former revisions:
25! -----------------
26! $Id: lpm.f90 1929 2016-06-09 16:25:25Z suehring $
27!
28! 1822 2016-04-07 07:49:42Z hoffmann
[1822]29! Tails removed.
30!
31! Initialization of sgs model not necessary for the use of cloud_droplets and
32! use_sgs_for_particles.
33!
34! lpm_release_set integrated.
35!
36! Unused variabled removed.
[1321]37!
[1683]38! 1682 2015-10-07 23:56:08Z knoop
39! Code annotations made doxygen readable
40!
[1417]41! 1416 2014-06-04 16:04:03Z suehring
42! user_lpm_advec is called for each gridpoint.
43! Bugfix: in order to prevent an infinite loop, time_loop_done is set .TRUE.
44! at the head of the do-loop. 
45!
[1360]46! 1359 2014-04-11 17:15:14Z hoffmann
47! New particle structure integrated.
48! Kind definition added to all floating point numbers.
49!
[1321]50! 1320 2014-03-20 08:40:49Z raasch
[1320]51! ONLY-attribute added to USE-statements,
52! kind-parameters added to all INTEGER and REAL declaration statements,
53! kinds are defined in new module kinds,
54! revision history before 2012 removed,
55! comment fields (!:) to be used for variable explanations added to
56! all variable declaration statements
[829]57!
[1319]58! 1318 2014-03-17 13:35:16Z raasch
59! module interfaces removed
60!
[1037]61! 1036 2012-10-22 13:43:42Z raasch
62! code put under GPL (PALM 3.9)
63!
[852]64! 851 2012-03-15 14:32:58Z raasch
65! Bugfix: resetting of particle_mask and tail mask moved from routine
66! lpm_exchange_horiz to here (end of sub-timestep loop)
67!
[850]68! 849 2012-03-15 10:35:09Z raasch
69! original routine advec_particles split into several subroutines and renamed
70! lpm
71!
[832]72! 831 2012-02-22 00:29:39Z raasch
73! thermal_conductivity_l and diff_coeff_l now depend on temperature and
74! pressure
75!
[829]76! 828 2012-02-21 12:00:36Z raasch
[828]77! fast hall/wang kernels with fixed radius/dissipation classes added,
78! particle feature color renamed class, routine colker renamed
79! recalculate_kernel,
80! lower limit for droplet radius changed from 1E-7 to 1E-8
[826]81!
[828]82! Bugfix: transformation factor for dissipation changed from 1E5 to 1E4
83!
[826]84! 825 2012-02-19 03:03:44Z raasch
[825]85! droplet growth by condensation may include curvature and solution effects,
86! initialisation of temporary particle array for resorting removed,
87! particle attributes speed_x|y|z_sgs renamed rvar1|2|3,
88! module wang_kernel_mod renamed lpm_collision_kernels_mod,
89! wang_collision_kernel renamed wang_kernel
[482]90!
[800]91!
[1]92! Revision 1.1  1999/11/25 16:16:06  raasch
93! Initial revision
94!
95!
96! Description:
97! ------------
[1682]98!> Particle advection
[1]99!------------------------------------------------------------------------------!
[1682]100 SUBROUTINE lpm
101 
[1]102
[1320]103    USE arrays_3d,                                                             &
104        ONLY:  ql_c, ql_v, ql_vp
105
106    USE control_parameters,                                                    &
107        ONLY:  cloud_droplets, dt_3d, dt_3d_reached, dt_3d_reached_l,          &
[1359]108               molecular_viscosity, simulated_time, topography
[1320]109
110    USE cpulog,                                                                &
111        ONLY:  cpu_log, log_point, log_point_s
112
[1359]113    USE indices,                                                               &
[1929]114        ONLY: nxl, nxr, nys, nyn, nzb, nzb_max, nzt, nzb_w_inner
[1359]115
[1320]116    USE kinds
117
[1359]118    USE lpm_exchange_horiz_mod,                                                &
119        ONLY:  lpm_exchange_horiz, lpm_move_particle
120
[1822]121    USE lpm_init_mod,                                                          &
122        ONLY: lpm_create_particle, PHASE_RELEASE
123
[1359]124    USE lpm_pack_arrays_mod,                                                   &
125        ONLY:  lpm_pack_all_arrays
126
[1320]127    USE particle_attributes,                                                   &
[1822]128        ONLY:  collision_kernel, deleted_particles,                            &
[1359]129               dt_write_particle_data, dt_prel, end_time_prel,                 &
130               grid_particles, number_of_particles, number_of_particle_groups, &
131               particles, particle_groups, prt_count, trlp_count_sum,          &
[1822]132               time_prel,                                                      &
[1359]133               time_write_particle_data, trlp_count_recv_sum, trnp_count_sum,  &
134               trnp_count_recv_sum, trrp_count_sum, trrp_count_recv_sum,       &
[1822]135               trsp_count_sum, trsp_count_recv_sum,                            &
[1359]136               use_sgs_for_particles, write_particle_statistics
[1320]137
[1]138    USE pegrid
139
140    IMPLICIT NONE
141
[1682]142    INTEGER(iwp)       ::  i                  !<
143    INTEGER(iwp)       ::  ie                 !<
144    INTEGER(iwp)       ::  is                 !<
145    INTEGER(iwp)       ::  j                  !<
146    INTEGER(iwp)       ::  je                 !<
147    INTEGER(iwp)       ::  js                 !<
148    INTEGER(iwp)       ::  k                  !<
149    INTEGER(iwp)       ::  ke                 !<
150    INTEGER(iwp)       ::  ks                 !<
151    INTEGER(iwp)       ::  m                  !<
152    INTEGER(iwp), SAVE ::  steps = 0          !<
[1]153
[1682]154    LOGICAL            ::  first_loop_stride  !<
[60]155
[849]156    CALL cpu_log( log_point(25), 'lpm', 'start' )
[824]157
[849]158!
159!-- Write particle data at current time on file.
160!-- This has to be done here, before particles are further processed,
161!-- because they may be deleted within this timestep (in case that
162!-- dt_write_particle_data = dt_prel = particle_maximum_age).
163    time_write_particle_data = time_write_particle_data + dt_3d
164    IF ( time_write_particle_data >= dt_write_particle_data )  THEN
[1]165
[849]166       CALL lpm_data_output_particles
[824]167!
[849]168!--    The MOD function allows for changes in the output interval with restart
169!--    runs.
170       time_write_particle_data = MOD( time_write_particle_data, &
171                                  MAX( dt_write_particle_data, dt_3d ) )
172    ENDIF
[1]173
[849]174!
[1822]175!-- Initialize arrays for marking those particles to be deleted after the
[849]176!-- (sub-) timestep
177    deleted_particles = 0
[60]178
[1]179!
[849]180!-- Initialize variables used for accumulating the number of particles
181!-- exchanged between the subdomains during all sub-timesteps (if sgs
182!-- velocities are included). These data are output further below on the
183!-- particle statistics file.
184    trlp_count_sum      = 0
185    trlp_count_recv_sum = 0
186    trrp_count_sum      = 0
187    trrp_count_recv_sum = 0
188    trsp_count_sum      = 0
189    trsp_count_recv_sum = 0
190    trnp_count_sum      = 0
191    trnp_count_recv_sum = 0
[1]192
193
194!
195!-- Calculate exponential term used in case of particle inertia for each
196!-- of the particle groups
197    DO  m = 1, number_of_particle_groups
[1359]198       IF ( particle_groups(m)%density_ratio /= 0.0_wp )  THEN
[1]199          particle_groups(m)%exp_arg  =                                        &
[1359]200                    4.5_wp * particle_groups(m)%density_ratio *                &
[1]201                    molecular_viscosity / ( particle_groups(m)%radius )**2
[1359]202
203          particle_groups(m)%exp_term = EXP( -particle_groups(m)%exp_arg *     &
204                    dt_3d )
[1]205       ENDIF
206    ENDDO
207
208!
[1359]209!-- If necessary, release new set of particles
210    IF ( time_prel >= dt_prel  .AND.  end_time_prel > simulated_time )  THEN
[1]211
[1822]212       CALL lpm_create_particle(PHASE_RELEASE)
[1]213!
[1359]214!--    The MOD function allows for changes in the output interval with
215!--    restart runs.
216       time_prel = MOD( time_prel, MAX( dt_prel, dt_3d ) )
[1]217
[1359]218    ENDIF
[1]219!
[1359]220!-- Reset summation arrays
221    IF ( cloud_droplets)  THEN
222       ql_c  = 0.0_wp
223       ql_v  = 0.0_wp
224       ql_vp = 0.0_wp
[849]225    ENDIF
[420]226
[1359]227    first_loop_stride = .TRUE.
228    grid_particles(:,:,:)%time_loop_done = .TRUE.
[1]229!
[849]230!-- Timestep loop for particle advection.
[1]231!-- This loop has to be repeated until the advection time of every particle
[849]232!-- (within the total domain!) has reached the LES timestep (dt_3d).
233!-- In case of including the SGS velocities, the particle timestep may be
[1359]234!-- smaller than the LES timestep (because of the Lagrangian timescale
235!-- restriction) and particles may require to undergo several particle
236!-- timesteps, before the LES timestep is reached. Because the number of these
237!-- particle timesteps to be carried out is unknown at first, these steps are
238!-- carried out in the following infinite loop with exit condition.
[1]239    DO
[849]240       CALL cpu_log( log_point_s(44), 'lpm_advec', 'start' )
[1359]241       CALL cpu_log( log_point_s(44), 'lpm_advec', 'pause' )
[1416]242       
243       grid_particles(:,:,:)%time_loop_done = .TRUE.
[1359]244!
245!--    If particle advection includes SGS velocity components, calculate the
246!--    required SGS quantities (i.e. gradients of the TKE, as well as
247!--    horizontally averaged profiles of the SGS TKE and the resolved-scale
248!--    velocity variances)
[1]249
[1822]250       IF ( use_sgs_for_particles  .AND.  .NOT. cloud_droplets )  THEN
251          CALL lpm_init_sgs_tke
252       ENDIF
[1359]253
254       DO  i = nxl, nxr
255          DO  j = nys, nyn
256             DO  k = nzb+1, nzt
257
258                number_of_particles = prt_count(k,j,i)
[1]259!
[1359]260!--             If grid cell gets empty, flag must be true
261                IF ( number_of_particles <= 0 )  THEN
262                   grid_particles(k,j,i)%time_loop_done = .TRUE.
263                   CYCLE
264                ENDIF
[1]265
[1359]266                IF ( .NOT. first_loop_stride  .AND.  &
267                     grid_particles(k,j,i)%time_loop_done ) CYCLE
268
269                particles => grid_particles(k,j,i)%particles(1:number_of_particles)
270
271                particles(1:number_of_particles)%particle_mask = .TRUE.
[1]272!
[1359]273!--             Initialize the variable storing the total time that a particle
274!--             has advanced within the timestep procedure
275                IF ( first_loop_stride )  THEN
276                   particles(1:number_of_particles)%dt_sum = 0.0_wp
277                ENDIF
278!
279!--             Particle (droplet) growth by condensation/evaporation and
280!--             collision
281                IF ( cloud_droplets  .AND.  first_loop_stride)  THEN
282!
283!--                Droplet growth by condensation / evaporation
284                   CALL lpm_droplet_condensation(i,j,k)
285!
286!--                Particle growth by collision
287                   IF ( collision_kernel /= 'none' )  THEN
288                      CALL lpm_droplet_collision(i,j,k)
289                   ENDIF
[1]290
[1359]291                ENDIF
[1]292!
[1359]293!--             Initialize the switch used for the loop exit condition checked
294!--             at the end of this loop. If at least one particle has failed to
295!--             reach the LES timestep, this switch will be set false in
296!--             lpm_advec.
297                dt_3d_reached_l = .TRUE.
[57]298
299!
[1359]300!--             Particle advection
301                CALL lpm_advec(i,j,k)
302!
[1929]303!--             Particle reflection from walls. Only applied if the particles
304!--             are in the vertical range of the topography. (Here, some
305!--             optimization is still possible.)
306                IF ( topography /= 'flat' .AND. k < nzb_max + 2 )  THEN
[1359]307                   CALL lpm_boundary_conds( 'walls' )
308                ENDIF
309!
310!--             User-defined actions after the calculation of the new particle
311!--             position
[1416]312                CALL user_lpm_advec(i,j,k)
[1359]313!
314!--             Apply boundary conditions to those particles that have crossed
315!--             the top or bottom boundary and delete those particles, which are
316!--             older than allowed
317                CALL lpm_boundary_conds( 'bottom/top' )
318!
319!---            If not all particles of the actual grid cell have reached the
320!--             LES timestep, this cell has to to another loop iteration. Due to
321!--             the fact that particles can move into neighboring grid cell,
322!--             these neighbor cells also have to perform another loop iteration
323                IF ( .NOT. dt_3d_reached_l )  THEN
324                   ks = MAX(nzb+1,k)
325                   ke = MIN(nzt,k)
326                   js = MAX(nys,j)
327                   je = MIN(nyn,j)
328                   is = MAX(nxl,i)
329                   ie = MIN(nxr,i)
330                   grid_particles(ks:ke,js:je,is:ie)%time_loop_done = .FALSE.
331                ENDIF
[57]332
[1359]333             ENDDO
334          ENDDO
335       ENDDO
336
337       steps = steps + 1
338       dt_3d_reached_l = ALL(grid_particles(:,:,:)%time_loop_done)
[57]339!
[1]340!--    Find out, if all particles on every PE have completed the LES timestep
341!--    and set the switch corespondingly
342#if defined( __parallel )
[622]343       IF ( collective_wait )  CALL MPI_BARRIER( comm2d, ierr )
[1]344       CALL MPI_ALLREDUCE( dt_3d_reached_l, dt_3d_reached, 1, MPI_LOGICAL, &
345                           MPI_LAND, comm2d, ierr )
346#else
347       dt_3d_reached = dt_3d_reached_l
[799]348#endif
[1]349
[849]350       CALL cpu_log( log_point_s(44), 'lpm_advec', 'stop' )
[1]351
352!
353!--    Increment time since last release
354       IF ( dt_3d_reached )  time_prel = time_prel + dt_3d
355
356!
[1359]357!--    Move Particles local to PE to a different grid cell
358       CALL lpm_move_particle
[1]359
360!
[849]361!--    Horizontal boundary conditions including exchange between subdmains
362       CALL lpm_exchange_horiz
[1]363!
364!--    Pack particles (eliminate those marked for deletion),
365!--    determine new number of particles
[1359]366       CALL lpm_pack_all_arrays
[1]367
[851]368!
[1359]369!--    Initialize variables for the next (sub-) timestep, i.e., for marking
370!--    those particles to be deleted after the timestep
[851]371       deleted_particles = 0
372
[1]373       IF ( dt_3d_reached )  EXIT
374
[1359]375       first_loop_stride = .FALSE.
[1]376    ENDDO   ! timestep loop
377
378!
[1359]379!-- Calculate the new liquid water content for each grid box
380    IF ( cloud_droplets )  THEN
381       CALL lpm_calc_liquid_water_content
[116]382    ENDIF
383
[1]384
385
386!
[828]387!-- Set particle attributes.
388!-- Feature is not available if collision is activated, because the respective
389!-- particle attribute (class) is then used for storing the particle radius
390!-- class.
[849]391    IF ( collision_kernel == 'none' )  CALL lpm_set_attributes
[264]392
393!
[1]394!-- Set particle attributes defined by the user
[849]395    CALL user_lpm_set_attributes
[1]396
397!
[849]398!-- Write particle statistics (in particular the number of particles
399!-- exchanged between the subdomains) on file
400    IF ( write_particle_statistics )  CALL lpm_write_exchange_statistics
[1]401
[849]402    CALL cpu_log( log_point(25), 'lpm', 'stop' )
[1]403
[849]404 END SUBROUTINE lpm
Note: See TracBrowser for help on using the repository browser.