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

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

last commit documented

  • Property svn:keywords set to Id
File size: 14.9 KB
Line 
1!> @file lpm.f90
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!
16! Copyright 1997-2016 Leibniz Universitaet Hannover
17!--------------------------------------------------------------------------------!
18!
19! Current revisions:
20! ------------------
21!
22!
23! Former revisions:
24! -----------------
25! $Id: lpm.f90 1937 2016-06-13 13:40:04Z suehring $
26!
27! 1936 2016-06-13 13:37:44Z suehring
28! Call routine for deallocation of unused memory.
29! Formatting adjustments
30!
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!
35! 1822 2016-04-07 07:49:42Z hoffmann
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.
44!
45! 1682 2015-10-07 23:56:08Z knoop
46! Code annotations made doxygen readable
47!
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!
53! 1359 2014-04-11 17:15:14Z hoffmann
54! New particle structure integrated.
55! Kind definition added to all floating point numbers.
56!
57! 1320 2014-03-20 08:40:49Z raasch
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
64!
65! 1318 2014-03-17 13:35:16Z raasch
66! module interfaces removed
67!
68! 1036 2012-10-22 13:43:42Z raasch
69! code put under GPL (PALM 3.9)
70!
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!
75! 849 2012-03-15 10:35:09Z raasch
76! original routine advec_particles split into several subroutines and renamed
77! lpm
78!
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!
83! 828 2012-02-21 12:00:36Z raasch
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
88!
89! Bugfix: transformation factor for dissipation changed from 1E5 to 1E4
90!
91! 825 2012-02-19 03:03:44Z raasch
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
97!
98!
99! Revision 1.1  1999/11/25 16:16:06  raasch
100! Initial revision
101!
102!
103! Description:
104! ------------
105!> Particle advection
106!------------------------------------------------------------------------------!
107 SUBROUTINE lpm
108 
109
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,          &
115               molecular_viscosity, simulated_time, topography
116
117    USE cpulog,                                                                &
118        ONLY:  cpu_log, log_point, log_point_s
119
120    USE indices,                                                               &
121        ONLY: nxl, nxr, nys, nyn, nzb, nzb_max, nzt, nzb_w_inner
122
123    USE kinds
124
125    USE lpm_exchange_horiz_mod,                                                &
126        ONLY:  dealloc_particles_array, lpm_exchange_horiz, lpm_move_particle
127
128    USE lpm_init_mod,                                                          &
129        ONLY: lpm_create_particle, PHASE_RELEASE
130
131    USE lpm_pack_arrays_mod,                                                   &
132        ONLY:  lpm_pack_all_arrays
133
134    USE particle_attributes,                                                   &
135        ONLY:  collision_kernel, deleted_particles, deallocate_memory,         &
136               dt_write_particle_data, dt_prel, end_time_prel,                 &
137               grid_particles, number_of_particles, number_of_particle_groups, &
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,                            &
141               trnp_count_recv_sum, trrp_count_sum, trrp_count_recv_sum,       &
142               trsp_count_sum, trsp_count_recv_sum,                            &
143               use_sgs_for_particles, write_particle_statistics
144
145    USE pegrid
146
147    IMPLICIT NONE
148
149    INTEGER(iwp)       ::  i                  !<
150    INTEGER(iwp)       ::  ie                 !<
151    INTEGER(iwp)       ::  is                 !<
152    INTEGER(iwp)       ::  j                  !<
153    INTEGER(iwp)       ::  je                 !<
154    INTEGER(iwp)       ::  js                 !<
155    INTEGER(iwp), SAVE ::  lpm_count = 0      !<
156    INTEGER(iwp)       ::  k                  !<
157    INTEGER(iwp)       ::  ke                 !<
158    INTEGER(iwp)       ::  ks                 !<
159    INTEGER(iwp)       ::  m                  !<
160    INTEGER(iwp), SAVE ::  steps = 0          !<
161
162    LOGICAL            ::  first_loop_stride  !<
163
164    CALL cpu_log( log_point(25), 'lpm', 'start' )
165
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
173
174       CALL lpm_data_output_particles
175!
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
181
182!
183!-- Initialize arrays for marking those particles to be deleted after the
184!-- (sub-) timestep
185    deleted_particles = 0
186
187!
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
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
206       IF ( particle_groups(m)%density_ratio /= 0.0_wp )  THEN
207          particle_groups(m)%exp_arg  =                                        &
208                    4.5_wp * particle_groups(m)%density_ratio *                &
209                    molecular_viscosity / ( particle_groups(m)%radius )**2
210
211          particle_groups(m)%exp_term = EXP( -particle_groups(m)%exp_arg *     &
212                    dt_3d )
213       ENDIF
214    ENDDO
215
216!
217!-- If necessary, release new set of particles
218    IF ( time_prel >= dt_prel  .AND.  end_time_prel > simulated_time )  THEN
219
220       CALL lpm_create_particle(PHASE_RELEASE)
221!
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 ) )
225
226    ENDIF
227!
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
233    ENDIF
234
235    first_loop_stride = .TRUE.
236    grid_particles(:,:,:)%time_loop_done = .TRUE.
237!
238!-- Timestep loop for particle advection.
239!-- This loop has to be repeated until the advection time of every particle
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
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.
247    DO
248       CALL cpu_log( log_point_s(44), 'lpm_advec', 'start' )
249       CALL cpu_log( log_point_s(44), 'lpm_advec', 'pause' )
250       
251       grid_particles(:,:,:)%time_loop_done = .TRUE.
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)
257
258       IF ( use_sgs_for_particles  .AND.  .NOT. cloud_droplets )  THEN
259          CALL lpm_init_sgs_tke
260       ENDIF
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)
267!
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
273
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.
280!
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
298
299                ENDIF
300!
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.
306
307!
308!--             Particle advection
309                CALL lpm_advec(i,j,k)
310!
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
315                   CALL lpm_boundary_conds( 'walls' )
316                ENDIF
317!
318!--             User-defined actions after the calculation of the new particle
319!--             position
320                CALL user_lpm_advec(i,j,k)
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
340
341             ENDDO
342          ENDDO
343       ENDDO
344
345       steps = steps + 1
346       dt_3d_reached_l = ALL(grid_particles(:,:,:)%time_loop_done)
347!
348!--    Find out, if all particles on every PE have completed the LES timestep
349!--    and set the switch corespondingly
350#if defined( __parallel )
351       IF ( collective_wait )  CALL MPI_BARRIER( comm2d, ierr )
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
356#endif
357
358       CALL cpu_log( log_point_s(44), 'lpm_advec', 'stop' )
359
360!
361!--    Increment time since last release
362       IF ( dt_3d_reached )  time_prel = time_prel + dt_3d
363
364!
365!--    Move Particles local to PE to a different grid cell
366       CALL lpm_move_particle
367
368!
369!--    Horizontal boundary conditions including exchange between subdmains
370       CALL lpm_exchange_horiz
371!
372!--    Pack particles (eliminate those marked for deletion),
373!--    determine new number of particles
374       CALL lpm_pack_all_arrays
375
376!
377!--    Initialize variables for the next (sub-) timestep, i.e., for marking
378!--    those particles to be deleted after the timestep
379       deleted_particles = 0
380
381       IF ( dt_3d_reached )  EXIT
382
383       first_loop_stride = .FALSE.
384    ENDDO   ! timestep loop
385
386!
387!-- Calculate the new liquid water content for each grid box
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
396    ENDIF
397
398!
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.
403    IF ( collision_kernel == 'none' )  CALL lpm_set_attributes
404
405!
406!-- Set particle attributes defined by the user
407    CALL user_lpm_set_attributes
408
409!
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
413
414    CALL cpu_log( log_point(25), 'lpm', 'stop' )
415
416 END SUBROUTINE lpm
Note: See TracBrowser for help on using the repository browser.