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

Last change on this file since 1822 was 1822, checked in by hoffmann, 5 years ago

changes in LPM and bulk cloud microphysics

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