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

Last change on this file since 2001 was 2001, checked in by knoop, 8 years ago

last commit documented

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