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

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

remove comment

  • Property svn:keywords set to Id
File size: 16.3 KB
RevLine 
[1682]1!> @file lpm.f90
[2000]2!------------------------------------------------------------------------------!
[1036]3! This file is part of PALM.
4!
[2000]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.
[1036]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!
[2101]17! Copyright 1997-2017 Leibniz Universitaet Hannover
[2000]18!------------------------------------------------------------------------------!
[1036]19!
[230]20! Current revisions:
[759]21! ------------------
[1823]22!
[2233]23!
[1823]24! Former revisions:
25! -----------------
26! $Id: lpm.f90 2418 2017-09-06 15:24:24Z raasch $
[2417]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
[2263]32! Implemented splitting and merging algorithm
33!
34! 2233 2017-05-30 18:08:54Z suehring
[1823]35!
[2233]36! 2232 2017-05-30 17:47:52Z suehring
37! Adjustments to new topography concept
38!
[2001]39! 2000 2016-08-20 18:09:15Z knoop
40! Forced header and separation lines into 80 columns
41!
[1937]42! 1936 2016-06-13 13:37:44Z suehring
43! Call routine for deallocation of unused memory.
44! Formatting adjustments
45!
[1930]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!
[1823]50! 1822 2016-04-07 07:49:42Z hoffmann
[1822]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.
[1321]59!
[1683]60! 1682 2015-10-07 23:56:08Z knoop
61! Code annotations made doxygen readable
62!
[1417]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!
[1360]68! 1359 2014-04-11 17:15:14Z hoffmann
69! New particle structure integrated.
70! Kind definition added to all floating point numbers.
71!
[1321]72! 1320 2014-03-20 08:40:49Z raasch
[1320]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
[829]79!
[1319]80! 1318 2014-03-17 13:35:16Z raasch
81! module interfaces removed
82!
[1037]83! 1036 2012-10-22 13:43:42Z raasch
84! code put under GPL (PALM 3.9)
85!
[852]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!
[850]90! 849 2012-03-15 10:35:09Z raasch
91! original routine advec_particles split into several subroutines and renamed
92! lpm
93!
[832]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!
[829]98! 828 2012-02-21 12:00:36Z raasch
[828]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
[826]103!
[828]104! Bugfix: transformation factor for dissipation changed from 1E5 to 1E4
105!
[826]106! 825 2012-02-19 03:03:44Z raasch
[825]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
[482]112!
[800]113!
[1]114! Revision 1.1  1999/11/25 16:16:06  raasch
115! Initial revision
116!
117!
118! Description:
119! ------------
[1682]120!> Particle advection
[1]121!------------------------------------------------------------------------------!
[1682]122 SUBROUTINE lpm
123 
[1]124
[1320]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,          &
[1359]130               molecular_viscosity, simulated_time, topography
[1320]131
132    USE cpulog,                                                                &
133        ONLY:  cpu_log, log_point, log_point_s
134
[1359]135    USE indices,                                                               &
[2232]136        ONLY: nxl, nxr, nys, nyn, nzb, nzb_max, nzt
[1359]137
[1320]138    USE kinds
139
[1359]140    USE lpm_exchange_horiz_mod,                                                &
[1936]141        ONLY:  dealloc_particles_array, lpm_exchange_horiz, lpm_move_particle
[1359]142
[1822]143    USE lpm_init_mod,                                                          &
144        ONLY: lpm_create_particle, PHASE_RELEASE
145
[1359]146    USE lpm_pack_arrays_mod,                                                   &
[2417]147        ONLY:  lpm_pack_all_arrays, lpm_sort
[1359]148
[1320]149    USE particle_attributes,                                                   &
[1936]150        ONLY:  collision_kernel, deleted_particles, deallocate_memory,         &
[1359]151               dt_write_particle_data, dt_prel, end_time_prel,                 &
[2263]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,       &
[1359]158               use_sgs_for_particles, write_particle_statistics
[2263]159                             
[1]160    USE pegrid
161
162    IMPLICIT NONE
163
[1682]164    INTEGER(iwp)       ::  i                  !<
165    INTEGER(iwp)       ::  ie                 !<
166    INTEGER(iwp)       ::  is                 !<
167    INTEGER(iwp)       ::  j                  !<
168    INTEGER(iwp)       ::  je                 !<
169    INTEGER(iwp)       ::  js                 !<
[1936]170    INTEGER(iwp), SAVE ::  lpm_count = 0      !<
[1682]171    INTEGER(iwp)       ::  k                  !<
172    INTEGER(iwp)       ::  ke                 !<
173    INTEGER(iwp)       ::  ks                 !<
174    INTEGER(iwp)       ::  m                  !<
175    INTEGER(iwp), SAVE ::  steps = 0          !<
[1]176
[1682]177    LOGICAL            ::  first_loop_stride  !<
[60]178
[849]179    CALL cpu_log( log_point(25), 'lpm', 'start' )
[824]180
[849]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
[1]188
[849]189       CALL lpm_data_output_particles
[824]190!
[849]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
[1]196
[849]197!
[1822]198!-- Initialize arrays for marking those particles to be deleted after the
[849]199!-- (sub-) timestep
200    deleted_particles = 0
[60]201
[1]202!
[849]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
[1]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
[1359]221       IF ( particle_groups(m)%density_ratio /= 0.0_wp )  THEN
[1]222          particle_groups(m)%exp_arg  =                                        &
[1359]223                    4.5_wp * particle_groups(m)%density_ratio *                &
[1]224                    molecular_viscosity / ( particle_groups(m)%radius )**2
[1359]225
226          particle_groups(m)%exp_term = EXP( -particle_groups(m)%exp_arg *     &
227                    dt_3d )
[1]228       ENDIF
229    ENDDO
230
231!
[1359]232!-- If necessary, release new set of particles
233    IF ( time_prel >= dt_prel  .AND.  end_time_prel > simulated_time )  THEN
[1]234
[1822]235       CALL lpm_create_particle(PHASE_RELEASE)
[1]236!
[1359]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 ) )
[1]240
[1359]241    ENDIF
[1]242!
[1359]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
[849]248    ENDIF
[420]249
[1359]250    first_loop_stride = .TRUE.
251    grid_particles(:,:,:)%time_loop_done = .TRUE.
[1]252!
[849]253!-- Timestep loop for particle advection.
[1]254!-- This loop has to be repeated until the advection time of every particle
[849]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
[1359]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.
[1]262    DO
[849]263       CALL cpu_log( log_point_s(44), 'lpm_advec', 'start' )
[1359]264       CALL cpu_log( log_point_s(44), 'lpm_advec', 'pause' )
[1416]265       
[1359]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)
[1822]271       IF ( use_sgs_for_particles  .AND.  .NOT. cloud_droplets )  THEN
272          CALL lpm_init_sgs_tke
273       ENDIF
[1359]274
[2417]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
[1359]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)
[1]290!
[1359]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
[1]296
[1359]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.
[1]303!
[1359]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
[1]321
[1359]322                ENDIF
[1]323!
[1359]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.
[57]329
330!
[1359]331!--             Particle advection
332                CALL lpm_advec(i,j,k)
333!
[1929]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
[2418]338                   CALL lpm_boundary_conds( 'walls' )
[1359]339                ENDIF
340!
341!--             User-defined actions after the calculation of the new particle
342!--             position
[1416]343                CALL user_lpm_advec(i,j,k)
[1359]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
[2418]348                CALL lpm_boundary_conds( 'bottom/top' )
[1359]349!
350!---            If not all particles of the actual grid cell have reached the
[2417]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.
[1359]356                IF ( .NOT. dt_3d_reached_l )  THEN
[2417]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)
[1359]363                   grid_particles(ks:ke,js:je,is:ie)%time_loop_done = .FALSE.
[2417]364                ELSE
365                   grid_particles(k,j,i)%time_loop_done = .TRUE.
[1359]366                ENDIF
[57]367
[1359]368             ENDDO
369          ENDDO
370       ENDDO
371
372       steps = steps + 1
373       dt_3d_reached_l = ALL(grid_particles(:,:,:)%time_loop_done)
[57]374!
[1]375!--    Find out, if all particles on every PE have completed the LES timestep
376!--    and set the switch corespondingly
377#if defined( __parallel )
[622]378       IF ( collective_wait )  CALL MPI_BARRIER( comm2d, ierr )
[1]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
[799]383#endif
[1]384
[849]385       CALL cpu_log( log_point_s(44), 'lpm_advec', 'stop' )
[1]386
387!
388!--    Increment time since last release
389       IF ( dt_3d_reached )  time_prel = time_prel + dt_3d
390!
[2263]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!
[1359]401!--    Move Particles local to PE to a different grid cell
402       CALL lpm_move_particle
[1]403
404!
[849]405!--    Horizontal boundary conditions including exchange between subdmains
406       CALL lpm_exchange_horiz
[1]407!
408!--    Pack particles (eliminate those marked for deletion),
409!--    determine new number of particles
[1359]410       CALL lpm_pack_all_arrays
[851]411!
[1359]412!--    Initialize variables for the next (sub-) timestep, i.e., for marking
413!--    those particles to be deleted after the timestep
[851]414       deleted_particles = 0
415
[1]416       IF ( dt_3d_reached )  EXIT
417
[1359]418       first_loop_stride = .FALSE.
[1]419    ENDDO   ! timestep loop
420
421!
[1359]422!-- Calculate the new liquid water content for each grid box
[1936]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
[116]431    ENDIF
432
[1]433!
[828]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.
[849]438    IF ( collision_kernel == 'none' )  CALL lpm_set_attributes
[264]439
440!
[1]441!-- Set particle attributes defined by the user
[849]442    CALL user_lpm_set_attributes
[1]443
444!
[849]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
[1]448
[849]449    CALL cpu_log( log_point(25), 'lpm', 'stop' )
[1]450
[849]451 END SUBROUTINE lpm
Note: See TracBrowser for help on using the repository browser.