1 | !> @file lpm_init.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_init.f90 1823 2016-04-07 08:57:52Z gronemeier $ |
---|
26 | ! |
---|
27 | ! 1822 2016-04-07 07:49:42Z hoffmann |
---|
28 | ! Unused variables removed. |
---|
29 | ! |
---|
30 | ! 1783 2016-03-06 18:36:17Z raasch |
---|
31 | ! netcdf module added |
---|
32 | ! |
---|
33 | ! 1725 2015-11-17 13:01:51Z hoffmann |
---|
34 | ! Bugfix: Processor-dependent seed for random function is generated before it is |
---|
35 | ! used. |
---|
36 | ! |
---|
37 | ! 1691 2015-10-26 16:17:44Z maronga |
---|
38 | ! Renamed prandtl_layer to constant_flux_layer. |
---|
39 | ! |
---|
40 | ! 1685 2015-10-08 07:32:13Z raasch |
---|
41 | ! bugfix concerning vertical index offset in case of ocean |
---|
42 | ! |
---|
43 | ! 1682 2015-10-07 23:56:08Z knoop |
---|
44 | ! Code annotations made doxygen readable |
---|
45 | ! |
---|
46 | ! 1575 2015-03-27 09:56:27Z raasch |
---|
47 | ! initial vertical particle position is allowed to follow the topography |
---|
48 | ! |
---|
49 | ! 1359 2014-04-11 17:15:14Z hoffmann |
---|
50 | ! New particle structure integrated. |
---|
51 | ! Kind definition added to all floating point numbers. |
---|
52 | ! lpm_init changed form a subroutine to a module. |
---|
53 | ! |
---|
54 | ! 1327 2014-03-21 11:00:16Z raasch |
---|
55 | ! -netcdf_output |
---|
56 | ! |
---|
57 | ! 1322 2014-03-20 16:38:49Z raasch |
---|
58 | ! REAL functions provided with KIND-attribute |
---|
59 | ! |
---|
60 | ! 1320 2014-03-20 08:40:49Z raasch |
---|
61 | ! ONLY-attribute added to USE-statements, |
---|
62 | ! kind-parameters added to all INTEGER and REAL declaration statements, |
---|
63 | ! kinds are defined in new module kinds, |
---|
64 | ! revision history before 2012 removed, |
---|
65 | ! comment fields (!:) to be used for variable explanations added to |
---|
66 | ! all variable declaration statements |
---|
67 | ! bugfix: #if defined( __parallel ) added |
---|
68 | ! |
---|
69 | ! 1314 2014-03-14 18:25:17Z suehring |
---|
70 | ! Vertical logarithmic interpolation of horizontal particle speed for particles |
---|
71 | ! between roughness height and first vertical grid level. |
---|
72 | ! |
---|
73 | ! 1092 2013-02-02 11:24:22Z raasch |
---|
74 | ! unused variables removed |
---|
75 | ! |
---|
76 | ! 1036 2012-10-22 13:43:42Z raasch |
---|
77 | ! code put under GPL (PALM 3.9) |
---|
78 | ! |
---|
79 | ! 849 2012-03-15 10:35:09Z raasch |
---|
80 | ! routine renamed: init_particles -> lpm_init |
---|
81 | ! de_dx, de_dy, de_dz are allocated here (instead of automatic arrays in |
---|
82 | ! advec_particles), |
---|
83 | ! sort_particles renamed lpm_sort_arrays, user_init_particles renamed lpm_init |
---|
84 | ! |
---|
85 | ! 828 2012-02-21 12:00:36Z raasch |
---|
86 | ! call of init_kernels, particle feature color renamed class |
---|
87 | ! |
---|
88 | ! 824 2012-02-17 09:09:57Z raasch |
---|
89 | ! particle attributes speed_x|y|z_sgs renamed rvar1|2|3, |
---|
90 | ! array particles implemented as pointer |
---|
91 | ! |
---|
92 | ! 667 2010-12-23 12:06:00Z suehring/gryschka |
---|
93 | ! nxl-1, nxr+1, nys-1, nyn+1 replaced by nxlg, nxrg, nysg, nyng for allocation |
---|
94 | ! of arrays. |
---|
95 | ! |
---|
96 | ! Revision 1.1 1999/11/25 16:22:38 raasch |
---|
97 | ! Initial revision |
---|
98 | ! |
---|
99 | ! |
---|
100 | ! Description: |
---|
101 | ! ------------ |
---|
102 | !> This routine initializes a set of particles and their attributes (position, |
---|
103 | !> radius, ..) which are used by the Lagrangian particle model (see lpm). |
---|
104 | !------------------------------------------------------------------------------! |
---|
105 | MODULE lpm_init_mod |
---|
106 | |
---|
107 | |
---|
108 | USE arrays_3d, & |
---|
109 | ONLY: de_dx, de_dy, de_dz, zu, zw, z0 |
---|
110 | |
---|
111 | USE cloud_parameters, & |
---|
112 | ONLY: curvature_solution_effects |
---|
113 | |
---|
114 | USE control_parameters, & |
---|
115 | ONLY: cloud_droplets, constant_flux_layer, current_timestep_number, & |
---|
116 | dz, initializing_actions, message_string, ocean, simulated_time |
---|
117 | |
---|
118 | USE grid_variables, & |
---|
119 | ONLY: ddx, dx, ddy, dy |
---|
120 | |
---|
121 | USE indices, & |
---|
122 | ONLY: nx, nxl, nxlg, nxrg, nxr, ny, nyn, nys, nyng, nysg, nz, nzb, & |
---|
123 | nzb_w_inner, nzt |
---|
124 | |
---|
125 | USE kinds |
---|
126 | |
---|
127 | USE lpm_collision_kernels_mod, & |
---|
128 | ONLY: init_kernels |
---|
129 | |
---|
130 | USE netcdf_interface, & |
---|
131 | ONLY: netcdf_data_format |
---|
132 | |
---|
133 | USE particle_attributes, & |
---|
134 | ONLY: alloc_factor, bc_par_b, bc_par_lr, bc_par_ns, bc_par_t, & |
---|
135 | block_offset, block_offset_def, collision_kernel, & |
---|
136 | density_ratio, grid_particles, & |
---|
137 | initial_weighting_factor, ibc_par_b, ibc_par_lr, ibc_par_ns, & |
---|
138 | ibc_par_t, iran_part, log_z_z0, & |
---|
139 | max_number_of_particle_groups, maximum_number_of_particles, & |
---|
140 | min_nr_particle, mpi_particle_type, & |
---|
141 | number_of_particles, & |
---|
142 | number_of_particle_groups, number_of_sublayers, & |
---|
143 | offset_ocean_nzt, offset_ocean_nzt_m1, & |
---|
144 | particles, particle_advection_start, particle_groups, & |
---|
145 | particle_groups_type, particles_per_point, & |
---|
146 | particle_type, pdx, pdy, pdz, & |
---|
147 | prt_count, psb, psl, psn, psr, pss, pst, & |
---|
148 | radius, random_start_position, read_particles_from_restartfile,& |
---|
149 | seed_follows_topography, sort_count, & |
---|
150 | total_number_of_particles, & |
---|
151 | use_sgs_for_particles, & |
---|
152 | write_particle_statistics, uniform_particles, zero_particle, & |
---|
153 | z0_av_global |
---|
154 | |
---|
155 | USE pegrid |
---|
156 | |
---|
157 | USE random_function_mod, & |
---|
158 | ONLY: random_function |
---|
159 | |
---|
160 | IMPLICIT NONE |
---|
161 | |
---|
162 | PRIVATE |
---|
163 | |
---|
164 | INTEGER(iwp), PARAMETER :: PHASE_INIT = 1 !< |
---|
165 | INTEGER(iwp), PARAMETER, PUBLIC :: PHASE_RELEASE = 2 !< |
---|
166 | |
---|
167 | INTERFACE lpm_init |
---|
168 | MODULE PROCEDURE lpm_init |
---|
169 | END INTERFACE lpm_init |
---|
170 | |
---|
171 | INTERFACE lpm_create_particle |
---|
172 | MODULE PROCEDURE lpm_create_particle |
---|
173 | END INTERFACE lpm_create_particle |
---|
174 | |
---|
175 | PUBLIC lpm_init, lpm_create_particle |
---|
176 | |
---|
177 | CONTAINS |
---|
178 | |
---|
179 | !------------------------------------------------------------------------------! |
---|
180 | ! Description: |
---|
181 | ! ------------ |
---|
182 | !> @todo Missing subroutine description. |
---|
183 | !------------------------------------------------------------------------------! |
---|
184 | SUBROUTINE lpm_init |
---|
185 | |
---|
186 | USE lpm_collision_kernels_mod, & |
---|
187 | ONLY: init_kernels |
---|
188 | |
---|
189 | IMPLICIT NONE |
---|
190 | |
---|
191 | INTEGER(iwp) :: i !< |
---|
192 | INTEGER(iwp) :: j !< |
---|
193 | INTEGER(iwp) :: k !< |
---|
194 | |
---|
195 | #if defined( __parallel ) |
---|
196 | INTEGER(iwp), DIMENSION(3) :: blocklengths !< |
---|
197 | INTEGER(iwp), DIMENSION(3) :: displacements !< |
---|
198 | INTEGER(iwp), DIMENSION(3) :: types !< |
---|
199 | #endif |
---|
200 | |
---|
201 | REAL(wp) :: height_int !< |
---|
202 | REAL(wp) :: height_p !< |
---|
203 | REAL(wp) :: z_p !< |
---|
204 | REAL(wp) :: z0_av_local !< |
---|
205 | |
---|
206 | #if defined( __parallel ) |
---|
207 | ! |
---|
208 | !-- Define MPI derived datatype for FORTRAN datatype particle_type (see module |
---|
209 | !-- particle_attributes). Integer length is 4 byte, Real is 8 byte |
---|
210 | blocklengths(1) = 19; blocklengths(2) = 6; blocklengths(3) = 1 |
---|
211 | displacements(1) = 0; displacements(2) = 152; displacements(3) = 176 |
---|
212 | |
---|
213 | types(1) = MPI_REAL |
---|
214 | types(2) = MPI_INTEGER |
---|
215 | types(3) = MPI_UB |
---|
216 | CALL MPI_TYPE_STRUCT( 3, blocklengths, displacements, types, & |
---|
217 | mpi_particle_type, ierr ) |
---|
218 | CALL MPI_TYPE_COMMIT( mpi_particle_type, ierr ) |
---|
219 | #endif |
---|
220 | |
---|
221 | ! |
---|
222 | !-- In case of oceans runs, the vertical index calculations need an offset, |
---|
223 | !-- because otherwise the k indices will become negative |
---|
224 | IF ( ocean ) THEN |
---|
225 | offset_ocean_nzt = nzt |
---|
226 | offset_ocean_nzt_m1 = nzt - 1 |
---|
227 | ENDIF |
---|
228 | |
---|
229 | ! |
---|
230 | !-- Define block offsets for dividing a gridcell in 8 sub cells |
---|
231 | |
---|
232 | block_offset(0) = block_offset_def (-1,-1,-1) |
---|
233 | block_offset(1) = block_offset_def (-1,-1, 0) |
---|
234 | block_offset(2) = block_offset_def (-1, 0,-1) |
---|
235 | block_offset(3) = block_offset_def (-1, 0, 0) |
---|
236 | block_offset(4) = block_offset_def ( 0,-1,-1) |
---|
237 | block_offset(5) = block_offset_def ( 0,-1, 0) |
---|
238 | block_offset(6) = block_offset_def ( 0, 0,-1) |
---|
239 | block_offset(7) = block_offset_def ( 0, 0, 0) |
---|
240 | ! |
---|
241 | !-- Check the number of particle groups. |
---|
242 | IF ( number_of_particle_groups > max_number_of_particle_groups ) THEN |
---|
243 | WRITE( message_string, * ) 'max_number_of_particle_groups =', & |
---|
244 | max_number_of_particle_groups , & |
---|
245 | '&number_of_particle_groups reset to ', & |
---|
246 | max_number_of_particle_groups |
---|
247 | CALL message( 'lpm_init', 'PA0213', 0, 1, 0, 6, 0 ) |
---|
248 | number_of_particle_groups = max_number_of_particle_groups |
---|
249 | ENDIF |
---|
250 | |
---|
251 | ! |
---|
252 | !-- Set default start positions, if necessary |
---|
253 | IF ( psl(1) == 9999999.9_wp ) psl(1) = -0.5_wp * dx |
---|
254 | IF ( psr(1) == 9999999.9_wp ) psr(1) = ( nx + 0.5_wp ) * dx |
---|
255 | IF ( pss(1) == 9999999.9_wp ) pss(1) = -0.5_wp * dy |
---|
256 | IF ( psn(1) == 9999999.9_wp ) psn(1) = ( ny + 0.5_wp ) * dy |
---|
257 | IF ( psb(1) == 9999999.9_wp ) psb(1) = zu(nz/2) |
---|
258 | IF ( pst(1) == 9999999.9_wp ) pst(1) = psb(1) |
---|
259 | |
---|
260 | IF ( pdx(1) == 9999999.9_wp .OR. pdx(1) == 0.0_wp ) pdx(1) = dx |
---|
261 | IF ( pdy(1) == 9999999.9_wp .OR. pdy(1) == 0.0_wp ) pdy(1) = dy |
---|
262 | IF ( pdz(1) == 9999999.9_wp .OR. pdz(1) == 0.0_wp ) pdz(1) = zu(2) - zu(1) |
---|
263 | |
---|
264 | DO j = 2, number_of_particle_groups |
---|
265 | IF ( psl(j) == 9999999.9_wp ) psl(j) = psl(j-1) |
---|
266 | IF ( psr(j) == 9999999.9_wp ) psr(j) = psr(j-1) |
---|
267 | IF ( pss(j) == 9999999.9_wp ) pss(j) = pss(j-1) |
---|
268 | IF ( psn(j) == 9999999.9_wp ) psn(j) = psn(j-1) |
---|
269 | IF ( psb(j) == 9999999.9_wp ) psb(j) = psb(j-1) |
---|
270 | IF ( pst(j) == 9999999.9_wp ) pst(j) = pst(j-1) |
---|
271 | IF ( pdx(j) == 9999999.9_wp .OR. pdx(j) == 0.0_wp ) pdx(j) = pdx(j-1) |
---|
272 | IF ( pdy(j) == 9999999.9_wp .OR. pdy(j) == 0.0_wp ) pdy(j) = pdy(j-1) |
---|
273 | IF ( pdz(j) == 9999999.9_wp .OR. pdz(j) == 0.0_wp ) pdz(j) = pdz(j-1) |
---|
274 | ENDDO |
---|
275 | |
---|
276 | ! |
---|
277 | !-- Allocate arrays required for calculating particle SGS velocities |
---|
278 | IF ( use_sgs_for_particles .AND. .NOT. cloud_droplets ) THEN |
---|
279 | ALLOCATE( de_dx(nzb:nzt+1,nysg:nyng,nxlg:nxrg), & |
---|
280 | de_dy(nzb:nzt+1,nysg:nyng,nxlg:nxrg), & |
---|
281 | de_dz(nzb:nzt+1,nysg:nyng,nxlg:nxrg) ) |
---|
282 | ENDIF |
---|
283 | |
---|
284 | ! |
---|
285 | !-- Allocate array required for logarithmic vertical interpolation of |
---|
286 | !-- horizontal particle velocities between the surface and the first vertical |
---|
287 | !-- grid level. In order to avoid repeated CPU cost-intensive CALLS of |
---|
288 | !-- intrinsic FORTRAN procedure LOG(z/z0), LOG(z/z0) is precalculated for |
---|
289 | !-- several heights. Splitting into 20 sublayers turned out to be sufficient. |
---|
290 | !-- To obtain exact height levels of particles, linear interpolation is applied |
---|
291 | !-- (see lpm_advec.f90). |
---|
292 | IF ( constant_flux_layer ) THEN |
---|
293 | |
---|
294 | ALLOCATE ( log_z_z0(0:number_of_sublayers) ) |
---|
295 | z_p = zu(nzb+1) - zw(nzb) |
---|
296 | |
---|
297 | ! |
---|
298 | !-- Calculate horizontal mean value of z0 used for logartihmic |
---|
299 | !-- interpolation. Note: this is not exact for heterogeneous z0. |
---|
300 | !-- However, sensitivity studies showed that the effect is |
---|
301 | !-- negligible. |
---|
302 | z0_av_local = SUM( z0(nys:nyn,nxl:nxr) ) |
---|
303 | z0_av_global = 0.0_wp |
---|
304 | |
---|
305 | #if defined( __parallel ) |
---|
306 | CALL MPI_ALLREDUCE(z0_av_local, z0_av_global, 1, MPI_REAL, MPI_SUM, & |
---|
307 | comm2d, ierr ) |
---|
308 | #else |
---|
309 | z0_av_global = z0_av_local |
---|
310 | #endif |
---|
311 | |
---|
312 | z0_av_global = z0_av_global / ( ( ny + 1 ) * ( nx + 1 ) ) |
---|
313 | ! |
---|
314 | !-- Horizontal wind speed is zero below and at z0 |
---|
315 | log_z_z0(0) = 0.0_wp |
---|
316 | ! |
---|
317 | !-- Calculate vertical depth of the sublayers |
---|
318 | height_int = ( z_p - z0_av_global ) / REAL( number_of_sublayers, KIND=wp ) |
---|
319 | ! |
---|
320 | !-- Precalculate LOG(z/z0) |
---|
321 | height_p = 0.0_wp |
---|
322 | DO k = 1, number_of_sublayers |
---|
323 | |
---|
324 | height_p = height_p + height_int |
---|
325 | log_z_z0(k) = LOG( height_p / z0_av_global ) |
---|
326 | |
---|
327 | ENDDO |
---|
328 | |
---|
329 | |
---|
330 | ENDIF |
---|
331 | |
---|
332 | ! |
---|
333 | !-- Check boundary condition and set internal variables |
---|
334 | SELECT CASE ( bc_par_b ) |
---|
335 | |
---|
336 | CASE ( 'absorb' ) |
---|
337 | ibc_par_b = 1 |
---|
338 | |
---|
339 | CASE ( 'reflect' ) |
---|
340 | ibc_par_b = 2 |
---|
341 | |
---|
342 | CASE DEFAULT |
---|
343 | WRITE( message_string, * ) 'unknown boundary condition ', & |
---|
344 | 'bc_par_b = "', TRIM( bc_par_b ), '"' |
---|
345 | CALL message( 'lpm_init', 'PA0217', 1, 2, 0, 6, 0 ) |
---|
346 | |
---|
347 | END SELECT |
---|
348 | SELECT CASE ( bc_par_t ) |
---|
349 | |
---|
350 | CASE ( 'absorb' ) |
---|
351 | ibc_par_t = 1 |
---|
352 | |
---|
353 | CASE ( 'reflect' ) |
---|
354 | ibc_par_t = 2 |
---|
355 | |
---|
356 | CASE DEFAULT |
---|
357 | WRITE( message_string, * ) 'unknown boundary condition ', & |
---|
358 | 'bc_par_t = "', TRIM( bc_par_t ), '"' |
---|
359 | CALL message( 'lpm_init', 'PA0218', 1, 2, 0, 6, 0 ) |
---|
360 | |
---|
361 | END SELECT |
---|
362 | SELECT CASE ( bc_par_lr ) |
---|
363 | |
---|
364 | CASE ( 'cyclic' ) |
---|
365 | ibc_par_lr = 0 |
---|
366 | |
---|
367 | CASE ( 'absorb' ) |
---|
368 | ibc_par_lr = 1 |
---|
369 | |
---|
370 | CASE ( 'reflect' ) |
---|
371 | ibc_par_lr = 2 |
---|
372 | |
---|
373 | CASE DEFAULT |
---|
374 | WRITE( message_string, * ) 'unknown boundary condition ', & |
---|
375 | 'bc_par_lr = "', TRIM( bc_par_lr ), '"' |
---|
376 | CALL message( 'lpm_init', 'PA0219', 1, 2, 0, 6, 0 ) |
---|
377 | |
---|
378 | END SELECT |
---|
379 | SELECT CASE ( bc_par_ns ) |
---|
380 | |
---|
381 | CASE ( 'cyclic' ) |
---|
382 | ibc_par_ns = 0 |
---|
383 | |
---|
384 | CASE ( 'absorb' ) |
---|
385 | ibc_par_ns = 1 |
---|
386 | |
---|
387 | CASE ( 'reflect' ) |
---|
388 | ibc_par_ns = 2 |
---|
389 | |
---|
390 | CASE DEFAULT |
---|
391 | WRITE( message_string, * ) 'unknown boundary condition ', & |
---|
392 | 'bc_par_ns = "', TRIM( bc_par_ns ), '"' |
---|
393 | CALL message( 'lpm_init', 'PA0220', 1, 2, 0, 6, 0 ) |
---|
394 | |
---|
395 | END SELECT |
---|
396 | |
---|
397 | ! |
---|
398 | !-- Initialize collision kernels |
---|
399 | IF ( collision_kernel /= 'none' ) CALL init_kernels |
---|
400 | |
---|
401 | ! |
---|
402 | !-- For the first model run of a possible job chain initialize the |
---|
403 | !-- particles, otherwise read the particle data from restart file. |
---|
404 | IF ( TRIM( initializing_actions ) == 'read_restart_data' & |
---|
405 | .AND. read_particles_from_restartfile ) THEN |
---|
406 | |
---|
407 | CALL lpm_read_restart_file |
---|
408 | |
---|
409 | ELSE |
---|
410 | |
---|
411 | ! |
---|
412 | !-- Allocate particle arrays and set attributes of the initial set of |
---|
413 | !-- particles, which can be also periodically released at later times. |
---|
414 | ALLOCATE( prt_count(nzb:nzt+1,nysg:nyng,nxlg:nxrg), & |
---|
415 | grid_particles(nzb+1:nzt,nys:nyn,nxl:nxr) ) |
---|
416 | |
---|
417 | maximum_number_of_particles = 0 |
---|
418 | number_of_particles = 0 |
---|
419 | |
---|
420 | sort_count = 0 |
---|
421 | prt_count = 0 |
---|
422 | |
---|
423 | ! |
---|
424 | !-- Initialize all particles with dummy values (otherwise errors may |
---|
425 | !-- occur within restart runs). The reason for this is still not clear |
---|
426 | !-- and may be presumably caused by errors in the respective user-interface. |
---|
427 | zero_particle = particle_type( 0.0_wp, 0.0_wp, 0.0_wp, 0.0_wp, 0.0_wp, & |
---|
428 | 0.0_wp, 0.0_wp, 0.0_wp, 0.0_wp, 0.0_wp, & |
---|
429 | 0.0_wp, 0.0_wp, 0.0_wp, 0.0_wp, 0.0_wp, & |
---|
430 | 0.0_wp, 0.0_wp, 0.0_wp, 0.0_wp, 0, 0, 0, & |
---|
431 | 0, .FALSE., -1) |
---|
432 | |
---|
433 | particle_groups = particle_groups_type( 0.0_wp, 0.0_wp, 0.0_wp, 0.0_wp ) |
---|
434 | |
---|
435 | ! |
---|
436 | !-- Set values for the density ratio and radius for all particle |
---|
437 | !-- groups, if necessary |
---|
438 | IF ( density_ratio(1) == 9999999.9_wp ) density_ratio(1) = 0.0_wp |
---|
439 | IF ( radius(1) == 9999999.9_wp ) radius(1) = 0.0_wp |
---|
440 | DO i = 2, number_of_particle_groups |
---|
441 | IF ( density_ratio(i) == 9999999.9_wp ) THEN |
---|
442 | density_ratio(i) = density_ratio(i-1) |
---|
443 | ENDIF |
---|
444 | IF ( radius(i) == 9999999.9_wp ) radius(i) = radius(i-1) |
---|
445 | ENDDO |
---|
446 | |
---|
447 | DO i = 1, number_of_particle_groups |
---|
448 | IF ( density_ratio(i) /= 0.0_wp .AND. radius(i) == 0 ) THEN |
---|
449 | WRITE( message_string, * ) 'particle group #', i, 'has a', & |
---|
450 | 'density ratio /= 0 but radius = 0' |
---|
451 | CALL message( 'lpm_init', 'PA0215', 1, 2, 0, 6, 0 ) |
---|
452 | ENDIF |
---|
453 | particle_groups(i)%density_ratio = density_ratio(i) |
---|
454 | particle_groups(i)%radius = radius(i) |
---|
455 | ENDDO |
---|
456 | |
---|
457 | ! |
---|
458 | !-- Set a seed value for the random number generator to be exclusively |
---|
459 | !-- used for the particle code. The generated random numbers should be |
---|
460 | !-- different on the different PEs. |
---|
461 | iran_part = iran_part + myid |
---|
462 | |
---|
463 | CALL lpm_create_particle (PHASE_INIT) |
---|
464 | |
---|
465 | ! |
---|
466 | !-- User modification of initial particles |
---|
467 | CALL user_lpm_init |
---|
468 | |
---|
469 | ! |
---|
470 | !-- Open file for statistical informations about particle conditions |
---|
471 | IF ( write_particle_statistics ) THEN |
---|
472 | CALL check_open( 80 ) |
---|
473 | WRITE ( 80, 8000 ) current_timestep_number, simulated_time, & |
---|
474 | number_of_particles, & |
---|
475 | maximum_number_of_particles |
---|
476 | CALL close_file( 80 ) |
---|
477 | ENDIF |
---|
478 | |
---|
479 | ENDIF |
---|
480 | |
---|
481 | ! |
---|
482 | !-- To avoid programm abort, assign particles array to the local version of |
---|
483 | !-- first grid cell |
---|
484 | number_of_particles = prt_count(nzb+1,nys,nxl) |
---|
485 | particles => grid_particles(nzb+1,nys,nxl)%particles(1:number_of_particles) |
---|
486 | |
---|
487 | ! |
---|
488 | !-- Formats |
---|
489 | 8000 FORMAT (I6,1X,F7.2,4X,I10,71X,I10) |
---|
490 | |
---|
491 | END SUBROUTINE lpm_init |
---|
492 | |
---|
493 | !------------------------------------------------------------------------------! |
---|
494 | ! Description: |
---|
495 | ! ------------ |
---|
496 | !> @todo Missing subroutine description. |
---|
497 | !------------------------------------------------------------------------------! |
---|
498 | SUBROUTINE lpm_create_particle (phase) |
---|
499 | |
---|
500 | USE lpm_exchange_horiz_mod, & |
---|
501 | ONLY: lpm_exchange_horiz, lpm_move_particle, realloc_particles_array |
---|
502 | |
---|
503 | USE lpm_pack_arrays_mod, & |
---|
504 | ONLY: lpm_pack_all_arrays |
---|
505 | |
---|
506 | IMPLICIT NONE |
---|
507 | |
---|
508 | INTEGER(iwp) :: alloc_size !< |
---|
509 | INTEGER(iwp) :: i !< |
---|
510 | INTEGER(iwp) :: ip !< |
---|
511 | INTEGER(iwp) :: j !< |
---|
512 | INTEGER(iwp) :: jp !< |
---|
513 | INTEGER(iwp) :: kp !< |
---|
514 | INTEGER(iwp) :: loop_stride !< |
---|
515 | INTEGER(iwp) :: n !< |
---|
516 | INTEGER(iwp) :: new_size !< |
---|
517 | |
---|
518 | INTEGER(iwp), INTENT(IN) :: phase !< |
---|
519 | |
---|
520 | INTEGER(iwp), DIMENSION(nzb:nzt+1,nysg:nyng,nxlg:nxrg) :: local_count !< |
---|
521 | INTEGER(iwp), DIMENSION(nzb:nzt+1,nysg:nyng,nxlg:nxrg) :: local_start !< |
---|
522 | |
---|
523 | LOGICAL :: first_stride !< |
---|
524 | |
---|
525 | REAL(wp) :: pos_x !< |
---|
526 | REAL(wp) :: pos_y !< |
---|
527 | REAL(wp) :: pos_z !< |
---|
528 | |
---|
529 | TYPE(particle_type),TARGET :: tmp_particle !< |
---|
530 | |
---|
531 | ! |
---|
532 | !-- Calculate particle positions and store particle attributes, if |
---|
533 | !-- particle is situated on this PE |
---|
534 | DO loop_stride = 1, 2 |
---|
535 | first_stride = (loop_stride == 1) |
---|
536 | IF ( first_stride ) THEN |
---|
537 | local_count = 0 ! count number of particles |
---|
538 | ELSE |
---|
539 | local_count = prt_count ! Start address of new particles |
---|
540 | ENDIF |
---|
541 | |
---|
542 | n = 0 |
---|
543 | DO i = 1, number_of_particle_groups |
---|
544 | |
---|
545 | pos_z = psb(i) |
---|
546 | |
---|
547 | DO WHILE ( pos_z <= pst(i) ) |
---|
548 | |
---|
549 | pos_y = pss(i) |
---|
550 | |
---|
551 | DO WHILE ( pos_y <= psn(i) ) |
---|
552 | |
---|
553 | IF ( pos_y >= ( nys - 0.5_wp ) * dy .AND. & |
---|
554 | pos_y < ( nyn + 0.5_wp ) * dy ) THEN |
---|
555 | |
---|
556 | pos_x = psl(i) |
---|
557 | |
---|
558 | xloop: DO WHILE ( pos_x <= psr(i) ) |
---|
559 | |
---|
560 | IF ( pos_x >= ( nxl - 0.5_wp ) * dx .AND. & |
---|
561 | pos_x < ( nxr + 0.5_wp ) * dx ) THEN |
---|
562 | |
---|
563 | DO j = 1, particles_per_point |
---|
564 | |
---|
565 | n = n + 1 |
---|
566 | tmp_particle%x = pos_x |
---|
567 | tmp_particle%y = pos_y |
---|
568 | tmp_particle%z = pos_z |
---|
569 | tmp_particle%age = 0.0_wp |
---|
570 | tmp_particle%age_m = 0.0_wp |
---|
571 | tmp_particle%dt_sum = 0.0_wp |
---|
572 | tmp_particle%dvrp_psize = 0.0_wp !unused |
---|
573 | tmp_particle%e_m = 0.0_wp |
---|
574 | IF ( curvature_solution_effects ) THEN |
---|
575 | ! |
---|
576 | !-- Initial values (internal timesteps, derivative) |
---|
577 | !-- for Rosenbrock method |
---|
578 | tmp_particle%rvar1 = 1.0E-12_wp |
---|
579 | tmp_particle%rvar2 = 1.0E-3_wp |
---|
580 | tmp_particle%rvar3 = -9999999.9_wp |
---|
581 | ELSE |
---|
582 | ! |
---|
583 | !-- Initial values for SGS velocities |
---|
584 | tmp_particle%rvar1 = 0.0_wp |
---|
585 | tmp_particle%rvar2 = 0.0_wp |
---|
586 | tmp_particle%rvar3 = 0.0_wp |
---|
587 | ENDIF |
---|
588 | tmp_particle%speed_x = 0.0_wp |
---|
589 | tmp_particle%speed_y = 0.0_wp |
---|
590 | tmp_particle%speed_z = 0.0_wp |
---|
591 | tmp_particle%origin_x = pos_x |
---|
592 | tmp_particle%origin_y = pos_y |
---|
593 | tmp_particle%origin_z = pos_z |
---|
594 | tmp_particle%radius = particle_groups(i)%radius |
---|
595 | tmp_particle%weight_factor = initial_weighting_factor |
---|
596 | tmp_particle%class = 1 |
---|
597 | tmp_particle%group = i |
---|
598 | tmp_particle%tailpoints = 0 !unused |
---|
599 | tmp_particle%particle_mask = .TRUE. |
---|
600 | tmp_particle%tail_id = 0 !unused |
---|
601 | |
---|
602 | ! |
---|
603 | !-- Determine the grid indices of the particle position |
---|
604 | ip = ( tmp_particle%x + 0.5_wp * dx ) * ddx |
---|
605 | jp = ( tmp_particle%y + 0.5_wp * dy ) * ddy |
---|
606 | kp = tmp_particle%z / dz + 1 + offset_ocean_nzt |
---|
607 | |
---|
608 | IF ( seed_follows_topography ) THEN |
---|
609 | ! |
---|
610 | !-- Particle height is given relative to topography |
---|
611 | kp = kp + nzb_w_inner(jp,ip) |
---|
612 | tmp_particle%z = tmp_particle%z + zw(kp) |
---|
613 | IF ( kp > nzt ) THEN |
---|
614 | pos_x = pos_x + pdx(i) |
---|
615 | CYCLE xloop |
---|
616 | ENDIF |
---|
617 | ENDIF |
---|
618 | |
---|
619 | local_count(kp,jp,ip) = local_count(kp,jp,ip) + 1 |
---|
620 | IF ( .NOT. first_stride ) THEN |
---|
621 | IF ( ip < nxl .OR. jp < nys .OR. kp < nzb+1 ) THEN |
---|
622 | write(6,*) 'xl ',ip,jp,kp,nxl,nys,nzb+1 |
---|
623 | ENDIF |
---|
624 | IF ( ip > nxr .OR. jp > nyn .OR. kp > nzt ) THEN |
---|
625 | write(6,*) 'xu ',ip,jp,kp,nxr,nyn,nzt |
---|
626 | ENDIF |
---|
627 | grid_particles(kp,jp,ip)%particles(local_count(kp,jp,ip)) = tmp_particle |
---|
628 | ENDIF |
---|
629 | ENDDO |
---|
630 | |
---|
631 | ENDIF |
---|
632 | |
---|
633 | pos_x = pos_x + pdx(i) |
---|
634 | |
---|
635 | ENDDO xloop |
---|
636 | |
---|
637 | ENDIF |
---|
638 | |
---|
639 | pos_y = pos_y + pdy(i) |
---|
640 | |
---|
641 | ENDDO |
---|
642 | |
---|
643 | pos_z = pos_z + pdz(i) |
---|
644 | |
---|
645 | ENDDO |
---|
646 | |
---|
647 | ENDDO |
---|
648 | |
---|
649 | IF ( first_stride ) THEN |
---|
650 | DO ip = nxl, nxr |
---|
651 | DO jp = nys, nyn |
---|
652 | DO kp = nzb+1, nzt |
---|
653 | IF ( phase == PHASE_INIT ) THEN |
---|
654 | IF ( local_count(kp,jp,ip) > 0 ) THEN |
---|
655 | alloc_size = MAX( INT( local_count(kp,jp,ip) * & |
---|
656 | ( 1.0_wp + alloc_factor / 100.0_wp ) ), & |
---|
657 | min_nr_particle ) |
---|
658 | ELSE |
---|
659 | alloc_size = min_nr_particle |
---|
660 | ENDIF |
---|
661 | ALLOCATE(grid_particles(kp,jp,ip)%particles(1:alloc_size)) |
---|
662 | DO n = 1, alloc_size |
---|
663 | grid_particles(kp,jp,ip)%particles(n) = zero_particle |
---|
664 | ENDDO |
---|
665 | ELSEIF ( phase == PHASE_RELEASE ) THEN |
---|
666 | IF ( local_count(kp,jp,ip) > 0 ) THEN |
---|
667 | new_size = local_count(kp,jp,ip) + prt_count(kp,jp,ip) |
---|
668 | alloc_size = MAX( INT( new_size * ( 1.0_wp + & |
---|
669 | alloc_factor / 100.0_wp ) ), min_nr_particle ) |
---|
670 | IF( alloc_size > SIZE( grid_particles(kp,jp,ip)%particles) ) THEN |
---|
671 | CALL realloc_particles_array(ip,jp,kp,alloc_size) |
---|
672 | ENDIF |
---|
673 | ENDIF |
---|
674 | ENDIF |
---|
675 | ENDDO |
---|
676 | ENDDO |
---|
677 | ENDDO |
---|
678 | ENDIF |
---|
679 | ENDDO |
---|
680 | |
---|
681 | local_start = prt_count+1 |
---|
682 | prt_count = local_count |
---|
683 | ! |
---|
684 | !-- Add random fluctuation to particle positions |
---|
685 | IF ( random_start_position ) THEN |
---|
686 | DO ip = nxl, nxr |
---|
687 | DO jp = nys, nyn |
---|
688 | DO kp = nzb+1, nzt |
---|
689 | number_of_particles = prt_count(kp,jp,ip) |
---|
690 | IF ( number_of_particles <= 0 ) CYCLE |
---|
691 | particles => grid_particles(kp,jp,ip)%particles(1:number_of_particles) |
---|
692 | |
---|
693 | DO n = local_start(kp,jp,ip), number_of_particles !Move only new particles |
---|
694 | IF ( psl(particles(n)%group) /= psr(particles(n)%group) ) THEN |
---|
695 | particles(n)%x = particles(n)%x + & |
---|
696 | ( random_function( iran_part ) - 0.5_wp ) * & |
---|
697 | pdx(particles(n)%group) |
---|
698 | ENDIF |
---|
699 | IF ( pss(particles(n)%group) /= psn(particles(n)%group) ) THEN |
---|
700 | particles(n)%y = particles(n)%y + & |
---|
701 | ( random_function( iran_part ) - 0.5_wp ) * & |
---|
702 | pdy(particles(n)%group) |
---|
703 | ENDIF |
---|
704 | IF ( psb(particles(n)%group) /= pst(particles(n)%group) ) THEN |
---|
705 | particles(n)%z = particles(n)%z + & |
---|
706 | ( random_function( iran_part ) - 0.5_wp ) * & |
---|
707 | pdz(particles(n)%group) |
---|
708 | ENDIF |
---|
709 | ENDDO |
---|
710 | ! |
---|
711 | !-- Identify particles located outside the model domain |
---|
712 | CALL lpm_boundary_conds( 'bottom/top' ) |
---|
713 | ENDDO |
---|
714 | ENDDO |
---|
715 | ENDDO |
---|
716 | ! |
---|
717 | !-- Exchange particles between grid cells and processors |
---|
718 | CALL lpm_move_particle |
---|
719 | CALL lpm_exchange_horiz |
---|
720 | |
---|
721 | ENDIF |
---|
722 | ! |
---|
723 | !-- In case of random_start_position, delete particles identified by |
---|
724 | !-- lpm_exchange_horiz and lpm_boundary_conds. Then sort particles into blocks, |
---|
725 | !-- which is needed for a fast interpolation of the LES fields on the particle |
---|
726 | !-- position. |
---|
727 | CALL lpm_pack_all_arrays |
---|
728 | |
---|
729 | ! |
---|
730 | !-- Determine maximum number of particles (i.e., all possible particles that |
---|
731 | !-- have been allocated) and the current number of particles |
---|
732 | DO ip = nxl, nxr |
---|
733 | DO jp = nys, nyn |
---|
734 | DO kp = nzb+1, nzt |
---|
735 | maximum_number_of_particles = maximum_number_of_particles & |
---|
736 | + SIZE(grid_particles(kp,jp,ip)%particles) |
---|
737 | number_of_particles = number_of_particles & |
---|
738 | + prt_count(kp,jp,ip) |
---|
739 | ENDDO |
---|
740 | ENDDO |
---|
741 | ENDDO |
---|
742 | ! |
---|
743 | !-- Calculate the number of particles of the total domain |
---|
744 | #if defined( __parallel ) |
---|
745 | IF ( collective_wait ) CALL MPI_BARRIER( comm2d, ierr ) |
---|
746 | CALL MPI_ALLREDUCE( number_of_particles, total_number_of_particles, 1, & |
---|
747 | MPI_INTEGER, MPI_SUM, comm2d, ierr ) |
---|
748 | #else |
---|
749 | total_number_of_particles = number_of_particles |
---|
750 | #endif |
---|
751 | |
---|
752 | RETURN |
---|
753 | |
---|
754 | END SUBROUTINE lpm_create_particle |
---|
755 | |
---|
756 | END MODULE lpm_init_mod |
---|