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

Last change on this file since 2129 was 2101, checked in by suehring, 8 years ago

last commit documented

  • Property svn:keywords set to Id
File size: 15.0 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
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.
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!
17! Copyright 1997-2017 Leibniz Universitaet Hannover
18!------------------------------------------------------------------------------!
19!
20! Current revisions:
21! ------------------
22!
23!
24! Former revisions:
25! -----------------
26! $Id: lpm.f90 2101 2017-01-05 16:42:31Z suehring $
27!
28! 2000 2016-08-20 18:09:15Z knoop
29! Forced header and separation lines into 80 columns
30!
31! 1936 2016-06-13 13:37:44Z suehring
32! Call routine for deallocation of unused memory.
33! Formatting adjustments
34!
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!
39! 1822 2016-04-07 07:49:42Z hoffmann
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.
48!
49! 1682 2015-10-07 23:56:08Z knoop
50! Code annotations made doxygen readable
51!
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!
57! 1359 2014-04-11 17:15:14Z hoffmann
58! New particle structure integrated.
59! Kind definition added to all floating point numbers.
60!
61! 1320 2014-03-20 08:40:49Z raasch
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
68!
69! 1318 2014-03-17 13:35:16Z raasch
70! module interfaces removed
71!
72! 1036 2012-10-22 13:43:42Z raasch
73! code put under GPL (PALM 3.9)
74!
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!
79! 849 2012-03-15 10:35:09Z raasch
80! original routine advec_particles split into several subroutines and renamed
81! lpm
82!
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!
87! 828 2012-02-21 12:00:36Z raasch
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
92!
93! Bugfix: transformation factor for dissipation changed from 1E5 to 1E4
94!
95! 825 2012-02-19 03:03:44Z raasch
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
101!
102!
103! Revision 1.1  1999/11/25 16:16:06  raasch
104! Initial revision
105!
106!
107! Description:
108! ------------
109!> Particle advection
110!------------------------------------------------------------------------------!
111 SUBROUTINE lpm
112 
113
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,          &
119               molecular_viscosity, simulated_time, topography
120
121    USE cpulog,                                                                &
122        ONLY:  cpu_log, log_point, log_point_s
123
124    USE indices,                                                               &
125        ONLY: nxl, nxr, nys, nyn, nzb, nzb_max, nzt, nzb_w_inner
126
127    USE kinds
128
129    USE lpm_exchange_horiz_mod,                                                &
130        ONLY:  dealloc_particles_array, lpm_exchange_horiz, lpm_move_particle
131
132    USE lpm_init_mod,                                                          &
133        ONLY: lpm_create_particle, PHASE_RELEASE
134
135    USE lpm_pack_arrays_mod,                                                   &
136        ONLY:  lpm_pack_all_arrays
137
138    USE particle_attributes,                                                   &
139        ONLY:  collision_kernel, deleted_particles, deallocate_memory,         &
140               dt_write_particle_data, dt_prel, end_time_prel,                 &
141               grid_particles, number_of_particles, number_of_particle_groups, &
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,                            &
145               trnp_count_recv_sum, trrp_count_sum, trrp_count_recv_sum,       &
146               trsp_count_sum, trsp_count_recv_sum,                            &
147               use_sgs_for_particles, write_particle_statistics
148
149    USE pegrid
150
151    IMPLICIT NONE
152
153    INTEGER(iwp)       ::  i                  !<
154    INTEGER(iwp)       ::  ie                 !<
155    INTEGER(iwp)       ::  is                 !<
156    INTEGER(iwp)       ::  j                  !<
157    INTEGER(iwp)       ::  je                 !<
158    INTEGER(iwp)       ::  js                 !<
159    INTEGER(iwp), SAVE ::  lpm_count = 0      !<
160    INTEGER(iwp)       ::  k                  !<
161    INTEGER(iwp)       ::  ke                 !<
162    INTEGER(iwp)       ::  ks                 !<
163    INTEGER(iwp)       ::  m                  !<
164    INTEGER(iwp), SAVE ::  steps = 0          !<
165
166    LOGICAL            ::  first_loop_stride  !<
167
168    CALL cpu_log( log_point(25), 'lpm', 'start' )
169
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
177
178       CALL lpm_data_output_particles
179!
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
185
186!
187!-- Initialize arrays for marking those particles to be deleted after the
188!-- (sub-) timestep
189    deleted_particles = 0
190
191!
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
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
210       IF ( particle_groups(m)%density_ratio /= 0.0_wp )  THEN
211          particle_groups(m)%exp_arg  =                                        &
212                    4.5_wp * particle_groups(m)%density_ratio *                &
213                    molecular_viscosity / ( particle_groups(m)%radius )**2
214
215          particle_groups(m)%exp_term = EXP( -particle_groups(m)%exp_arg *     &
216                    dt_3d )
217       ENDIF
218    ENDDO
219
220!
221!-- If necessary, release new set of particles
222    IF ( time_prel >= dt_prel  .AND.  end_time_prel > simulated_time )  THEN
223
224       CALL lpm_create_particle(PHASE_RELEASE)
225!
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 ) )
229
230    ENDIF
231!
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
237    ENDIF
238
239    first_loop_stride = .TRUE.
240    grid_particles(:,:,:)%time_loop_done = .TRUE.
241!
242!-- Timestep loop for particle advection.
243!-- This loop has to be repeated until the advection time of every particle
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
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.
251    DO
252       CALL cpu_log( log_point_s(44), 'lpm_advec', 'start' )
253       CALL cpu_log( log_point_s(44), 'lpm_advec', 'pause' )
254       
255       grid_particles(:,:,:)%time_loop_done = .TRUE.
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)
261
262       IF ( use_sgs_for_particles  .AND.  .NOT. cloud_droplets )  THEN
263          CALL lpm_init_sgs_tke
264       ENDIF
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)
271!
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
277
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.
284!
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
302
303                ENDIF
304!
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.
310
311!
312!--             Particle advection
313                CALL lpm_advec(i,j,k)
314!
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
319                   CALL lpm_boundary_conds( 'walls' )
320                ENDIF
321!
322!--             User-defined actions after the calculation of the new particle
323!--             position
324                CALL user_lpm_advec(i,j,k)
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
344
345             ENDDO
346          ENDDO
347       ENDDO
348
349       steps = steps + 1
350       dt_3d_reached_l = ALL(grid_particles(:,:,:)%time_loop_done)
351!
352!--    Find out, if all particles on every PE have completed the LES timestep
353!--    and set the switch corespondingly
354#if defined( __parallel )
355       IF ( collective_wait )  CALL MPI_BARRIER( comm2d, ierr )
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
360#endif
361
362       CALL cpu_log( log_point_s(44), 'lpm_advec', 'stop' )
363
364!
365!--    Increment time since last release
366       IF ( dt_3d_reached )  time_prel = time_prel + dt_3d
367
368!
369!--    Move Particles local to PE to a different grid cell
370       CALL lpm_move_particle
371
372!
373!--    Horizontal boundary conditions including exchange between subdmains
374       CALL lpm_exchange_horiz
375!
376!--    Pack particles (eliminate those marked for deletion),
377!--    determine new number of particles
378       CALL lpm_pack_all_arrays
379
380!
381!--    Initialize variables for the next (sub-) timestep, i.e., for marking
382!--    those particles to be deleted after the timestep
383       deleted_particles = 0
384
385       IF ( dt_3d_reached )  EXIT
386
387       first_loop_stride = .FALSE.
388    ENDDO   ! timestep loop
389
390!
391!-- Calculate the new liquid water content for each grid box
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
400    ENDIF
401
402!
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.
407    IF ( collision_kernel == 'none' )  CALL lpm_set_attributes
408
409!
410!-- Set particle attributes defined by the user
411    CALL user_lpm_set_attributes
412
413!
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
417
418    CALL cpu_log( log_point(25), 'lpm', 'stop' )
419
420 END SUBROUTINE lpm
Note: See TracBrowser for help on using the repository browser.