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

Last change on this file since 1981 was 1937, checked in by suehring, 8 years ago

last commit documented

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