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

Last change on this file since 2618 was 2606, checked in by schwenkel, 7 years ago

Modified particle box location and further changes in particle model

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