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

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

last commit documented

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