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

Last change on this file since 2000 was 2000, checked in by knoop, 8 years ago

Forced header and separation lines into 80 columns

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