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

Last change on this file since 2604 was 2418, checked in by suehring, 7 years ago

remove comment

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