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

Last change on this file since 1822 was 1822, checked in by hoffmann, 8 years ago

changes in LPM and bulk cloud microphysics

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