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

Last change on this file since 1817 was 1683, checked in by knoop, 9 years ago

last commit documented

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