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
Line 
1!> @file lpm.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-2016 Leibniz Universitaet Hannover
17!--------------------------------------------------------------------------------!
18!
19! Current revisions:
20! ------------------
21! Call wall boundary conditions only if particles are in the vertical range of
22! topography.
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
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.
37!
38! 1682 2015-10-07 23:56:08Z knoop
39! Code annotations made doxygen readable
40!
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!
46! 1359 2014-04-11 17:15:14Z hoffmann
47! New particle structure integrated.
48! Kind definition added to all floating point numbers.
49!
50! 1320 2014-03-20 08:40:49Z raasch
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
57!
58! 1318 2014-03-17 13:35:16Z raasch
59! module interfaces removed
60!
61! 1036 2012-10-22 13:43:42Z raasch
62! code put under GPL (PALM 3.9)
63!
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!
68! 849 2012-03-15 10:35:09Z raasch
69! original routine advec_particles split into several subroutines and renamed
70! lpm
71!
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!
76! 828 2012-02-21 12:00:36Z raasch
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
81!
82! Bugfix: transformation factor for dissipation changed from 1E5 to 1E4
83!
84! 825 2012-02-19 03:03:44Z raasch
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
90!
91!
92! Revision 1.1  1999/11/25 16:16:06  raasch
93! Initial revision
94!
95!
96! Description:
97! ------------
98!> Particle advection
99!------------------------------------------------------------------------------!
100 SUBROUTINE lpm
101 
102
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,          &
108               molecular_viscosity, simulated_time, topography
109
110    USE cpulog,                                                                &
111        ONLY:  cpu_log, log_point, log_point_s
112
113    USE indices,                                                               &
114        ONLY: nxl, nxr, nys, nyn, nzb, nzb_max, nzt, nzb_w_inner
115
116    USE kinds
117
118    USE lpm_exchange_horiz_mod,                                                &
119        ONLY:  lpm_exchange_horiz, lpm_move_particle
120
121    USE lpm_init_mod,                                                          &
122        ONLY: lpm_create_particle, PHASE_RELEASE
123
124    USE lpm_pack_arrays_mod,                                                   &
125        ONLY:  lpm_pack_all_arrays
126
127    USE particle_attributes,                                                   &
128        ONLY:  collision_kernel, deleted_particles,                            &
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,          &
132               time_prel,                                                      &
133               time_write_particle_data, trlp_count_recv_sum, trnp_count_sum,  &
134               trnp_count_recv_sum, trrp_count_sum, trrp_count_recv_sum,       &
135               trsp_count_sum, trsp_count_recv_sum,                            &
136               use_sgs_for_particles, write_particle_statistics
137
138    USE pegrid
139
140    IMPLICIT NONE
141
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          !<
153
154    LOGICAL            ::  first_loop_stride  !<
155
156    CALL cpu_log( log_point(25), 'lpm', 'start' )
157
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
165
166       CALL lpm_data_output_particles
167!
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
173
174!
175!-- Initialize arrays for marking those particles to be deleted after the
176!-- (sub-) timestep
177    deleted_particles = 0
178
179!
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
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
198       IF ( particle_groups(m)%density_ratio /= 0.0_wp )  THEN
199          particle_groups(m)%exp_arg  =                                        &
200                    4.5_wp * particle_groups(m)%density_ratio *                &
201                    molecular_viscosity / ( particle_groups(m)%radius )**2
202
203          particle_groups(m)%exp_term = EXP( -particle_groups(m)%exp_arg *     &
204                    dt_3d )
205       ENDIF
206    ENDDO
207
208!
209!-- If necessary, release new set of particles
210    IF ( time_prel >= dt_prel  .AND.  end_time_prel > simulated_time )  THEN
211
212       CALL lpm_create_particle(PHASE_RELEASE)
213!
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 ) )
217
218    ENDIF
219!
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
225    ENDIF
226
227    first_loop_stride = .TRUE.
228    grid_particles(:,:,:)%time_loop_done = .TRUE.
229!
230!-- Timestep loop for particle advection.
231!-- This loop has to be repeated until the advection time of every particle
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
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.
239    DO
240       CALL cpu_log( log_point_s(44), 'lpm_advec', 'start' )
241       CALL cpu_log( log_point_s(44), 'lpm_advec', 'pause' )
242       
243       grid_particles(:,:,:)%time_loop_done = .TRUE.
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)
249
250       IF ( use_sgs_for_particles  .AND.  .NOT. cloud_droplets )  THEN
251          CALL lpm_init_sgs_tke
252       ENDIF
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)
259!
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
265
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.
272!
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
290
291                ENDIF
292!
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.
298
299!
300!--             Particle advection
301                CALL lpm_advec(i,j,k)
302!
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
307                   CALL lpm_boundary_conds( 'walls' )
308                ENDIF
309!
310!--             User-defined actions after the calculation of the new particle
311!--             position
312                CALL user_lpm_advec(i,j,k)
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
332
333             ENDDO
334          ENDDO
335       ENDDO
336
337       steps = steps + 1
338       dt_3d_reached_l = ALL(grid_particles(:,:,:)%time_loop_done)
339!
340!--    Find out, if all particles on every PE have completed the LES timestep
341!--    and set the switch corespondingly
342#if defined( __parallel )
343       IF ( collective_wait )  CALL MPI_BARRIER( comm2d, ierr )
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
348#endif
349
350       CALL cpu_log( log_point_s(44), 'lpm_advec', 'stop' )
351
352!
353!--    Increment time since last release
354       IF ( dt_3d_reached )  time_prel = time_prel + dt_3d
355
356!
357!--    Move Particles local to PE to a different grid cell
358       CALL lpm_move_particle
359
360!
361!--    Horizontal boundary conditions including exchange between subdmains
362       CALL lpm_exchange_horiz
363!
364!--    Pack particles (eliminate those marked for deletion),
365!--    determine new number of particles
366       CALL lpm_pack_all_arrays
367
368!
369!--    Initialize variables for the next (sub-) timestep, i.e., for marking
370!--    those particles to be deleted after the timestep
371       deleted_particles = 0
372
373       IF ( dt_3d_reached )  EXIT
374
375       first_loop_stride = .FALSE.
376    ENDDO   ! timestep loop
377
378!
379!-- Calculate the new liquid water content for each grid box
380    IF ( cloud_droplets )  THEN
381       CALL lpm_calc_liquid_water_content
382    ENDIF
383
384
385
386!
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.
391    IF ( collision_kernel == 'none' )  CALL lpm_set_attributes
392
393!
394!-- Set particle attributes defined by the user
395    CALL user_lpm_set_attributes
396
397!
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
401
402    CALL cpu_log( log_point(25), 'lpm', 'stop' )
403
404 END SUBROUTINE lpm
Note: See TracBrowser for help on using the repository browser.