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

Last change on this file since 2798 was 2718, checked in by maronga, 7 years ago

deleting of deprecated files; headers updated where needed

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