1 | SUBROUTINE lpm_init |
---|
2 | |
---|
3 | !--------------------------------------------------------------------------------! |
---|
4 | ! This file is part of PALM. |
---|
5 | ! |
---|
6 | ! PALM is free software: you can redistribute it and/or modify it under the terms |
---|
7 | ! of the GNU General Public License as published by the Free Software Foundation, |
---|
8 | ! either version 3 of the License, or (at your option) any later 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-2014 Leibniz Universitaet Hannover |
---|
18 | !--------------------------------------------------------------------------------! |
---|
19 | ! |
---|
20 | ! Current revisions: |
---|
21 | ! ----------------- |
---|
22 | ! ONLY-attribute added to USE-statements, |
---|
23 | ! kind-parameters added to all INTEGER and REAL declaration statements, |
---|
24 | ! kinds are defined in new module kinds, |
---|
25 | ! revision history before 2012 removed, |
---|
26 | ! comment fields (!:) to be used for variable explanations added to |
---|
27 | ! all variable declaration statements |
---|
28 | ! bugfix: #if defined( __parallel ) added |
---|
29 | ! |
---|
30 | ! Former revisions: |
---|
31 | ! ----------------- |
---|
32 | ! $Id: lpm_init.f90 1320 2014-03-20 08:40:49Z raasch $ |
---|
33 | ! |
---|
34 | ! 1314 2014-03-14 18:25:17Z suehring |
---|
35 | ! Vertical logarithmic interpolation of horizontal particle speed for particles |
---|
36 | ! between roughness height and first vertical grid level. |
---|
37 | ! |
---|
38 | ! 1092 2013-02-02 11:24:22Z raasch |
---|
39 | ! unused variables removed |
---|
40 | ! |
---|
41 | ! 1036 2012-10-22 13:43:42Z raasch |
---|
42 | ! code put under GPL (PALM 3.9) |
---|
43 | ! |
---|
44 | ! 849 2012-03-15 10:35:09Z raasch |
---|
45 | ! routine renamed: init_particles -> lpm_init |
---|
46 | ! de_dx, de_dy, de_dz are allocated here (instead of automatic arrays in |
---|
47 | ! advec_particles), |
---|
48 | ! sort_particles renamed lpm_sort_arrays, user_init_particles renamed lpm_init |
---|
49 | ! |
---|
50 | ! 828 2012-02-21 12:00:36Z raasch |
---|
51 | ! call of init_kernels, particle feature color renamed class |
---|
52 | ! |
---|
53 | ! 824 2012-02-17 09:09:57Z raasch |
---|
54 | ! particle attributes speed_x|y|z_sgs renamed rvar1|2|3, |
---|
55 | ! array particles implemented as pointer |
---|
56 | ! |
---|
57 | ! 667 2010-12-23 12:06:00Z suehring/gryschka |
---|
58 | ! nxl-1, nxr+1, nys-1, nyn+1 replaced by nxlg, nxrg, nysg, nyng for allocation |
---|
59 | ! of arrays. |
---|
60 | ! |
---|
61 | ! Revision 1.1 1999/11/25 16:22:38 raasch |
---|
62 | ! Initial revision |
---|
63 | ! |
---|
64 | ! |
---|
65 | ! Description: |
---|
66 | ! ------------ |
---|
67 | ! This routine initializes a set of particles and their attributes (position, |
---|
68 | ! radius, ..) which are used by the Lagrangian particle model (see lpm). |
---|
69 | !------------------------------------------------------------------------------! |
---|
70 | |
---|
71 | USE arrays_3d, & |
---|
72 | ONLY: de_dx, de_dy, de_dz, zu, zw, z0 |
---|
73 | |
---|
74 | USE cloud_parameters, & |
---|
75 | ONLY: curvature_solution_effects |
---|
76 | |
---|
77 | USE control_parameters, & |
---|
78 | ONLY: cloud_droplets, current_timestep_number, initializing_actions, & |
---|
79 | message_string, netcdf_output,netcdf_data_format, ocean, & |
---|
80 | prandtl_layer, simulated_time |
---|
81 | |
---|
82 | USE dvrp_variables, & |
---|
83 | ONLY: particle_color, particle_dvrpsize |
---|
84 | |
---|
85 | USE grid_variables, & |
---|
86 | ONLY: dx, dy |
---|
87 | |
---|
88 | USE indices, & |
---|
89 | ONLY: nx, nxl, nxlg, nxrg, nxr, ny, nyn, nys, nyng, nysg, nz, nzb, nzt |
---|
90 | |
---|
91 | USE kinds |
---|
92 | |
---|
93 | USE lpm_collision_kernels_mod, & |
---|
94 | ONLY: init_kernels |
---|
95 | |
---|
96 | USE particle_attributes, & |
---|
97 | ONLY: bc_par_b, bc_par_lr, bc_par_ns, bc_par_t, collision_kernel, & |
---|
98 | density_ratio, dvrp_psize, initial_weighting_factor, ibc_par_b,& |
---|
99 | ibc_par_lr, ibc_par_ns, ibc_par_t, initial_particles, & |
---|
100 | iran_part, log_z_z0, max_number_of_particle_groups, & |
---|
101 | maximum_number_of_particles, maximum_number_of_tailpoints, & |
---|
102 | minimum_tailpoint_distance, maximum_number_of_tails, & |
---|
103 | mpi_particle_type, new_tail_id, number_of_initial_particles, & |
---|
104 | number_of_initial_tails, number_of_particles, & |
---|
105 | number_of_particle_groups, number_of_sublayers, & |
---|
106 | number_of_tails, offset_ocean_nzt, offset_ocean_nzt_m1, part_1,& |
---|
107 | part_2, particles, particle_advection_start, particle_groups, & |
---|
108 | particle_groups_type, particle_mask, particles_per_point, & |
---|
109 | particle_tail_coordinates, particle_type, pdx, pdy, pdz, & |
---|
110 | prt_count, prt_start_index, psb, psl, psn, psr, pss, pst, & |
---|
111 | radius, random_start_position, read_particles_from_restartfile,& |
---|
112 | skip_particles_for_tail, sort_count, tail_mask, & |
---|
113 | total_number_of_particles, total_number_of_tails, & |
---|
114 | use_particle_tails, use_sgs_for_particles, & |
---|
115 | write_particle_statistics, uniform_particles, z0_av_global |
---|
116 | |
---|
117 | USE pegrid |
---|
118 | |
---|
119 | USE random_function_mod, & |
---|
120 | ONLY: random_function |
---|
121 | |
---|
122 | |
---|
123 | IMPLICIT NONE |
---|
124 | |
---|
125 | INTEGER(iwp) :: i !: |
---|
126 | INTEGER(iwp) :: j !: |
---|
127 | INTEGER(iwp) :: k !: |
---|
128 | INTEGER(iwp) :: n !: |
---|
129 | INTEGER(iwp) :: nn !: |
---|
130 | |
---|
131 | #if defined( __parallel ) |
---|
132 | INTEGER(iwp), DIMENSION(3) :: blocklengths !: |
---|
133 | INTEGER(iwp), DIMENSION(3) :: displacements !: |
---|
134 | INTEGER(iwp), DIMENSION(3) :: types !: |
---|
135 | #endif |
---|
136 | LOGICAL :: uniform_particles_l !: |
---|
137 | |
---|
138 | REAL(wp) :: height_int !: |
---|
139 | REAL(wp) :: height_p !: |
---|
140 | REAL(wp) :: pos_x !: |
---|
141 | REAL(wp) :: pos_y !: |
---|
142 | REAL(wp) :: pos_z !: |
---|
143 | REAL(wp) :: z_p !: |
---|
144 | REAL(wp) :: z0_av_local = 0.0 !: |
---|
145 | |
---|
146 | |
---|
147 | |
---|
148 | |
---|
149 | #if defined( __parallel ) |
---|
150 | ! |
---|
151 | !-- Define MPI derived datatype for FORTRAN datatype particle_type (see module |
---|
152 | !-- particle_attributes). Integer length is 4 byte, Real is 8 byte |
---|
153 | blocklengths(1) = 19; blocklengths(2) = 4; blocklengths(3) = 1 |
---|
154 | displacements(1) = 0; displacements(2) = 152; displacements(3) = 168 |
---|
155 | |
---|
156 | types(1) = MPI_REAL |
---|
157 | types(2) = MPI_INTEGER |
---|
158 | types(3) = MPI_UB |
---|
159 | CALL MPI_TYPE_STRUCT( 3, blocklengths, displacements, types, & |
---|
160 | mpi_particle_type, ierr ) |
---|
161 | CALL MPI_TYPE_COMMIT( mpi_particle_type, ierr ) |
---|
162 | #endif |
---|
163 | |
---|
164 | ! |
---|
165 | !-- In case of oceans runs, the vertical index calculations need an offset, |
---|
166 | !-- because otherwise the k indices will become negative |
---|
167 | IF ( ocean ) THEN |
---|
168 | offset_ocean_nzt = nzt |
---|
169 | offset_ocean_nzt_m1 = nzt - 1 |
---|
170 | ENDIF |
---|
171 | |
---|
172 | |
---|
173 | ! |
---|
174 | !-- Check the number of particle groups. |
---|
175 | IF ( number_of_particle_groups > max_number_of_particle_groups ) THEN |
---|
176 | WRITE( message_string, * ) 'max_number_of_particle_groups =', & |
---|
177 | max_number_of_particle_groups , & |
---|
178 | '&number_of_particle_groups reset to ', & |
---|
179 | max_number_of_particle_groups |
---|
180 | CALL message( 'lpm_init', 'PA0213', 0, 1, 0, 6, 0 ) |
---|
181 | number_of_particle_groups = max_number_of_particle_groups |
---|
182 | ENDIF |
---|
183 | |
---|
184 | ! |
---|
185 | !-- Set default start positions, if necessary |
---|
186 | IF ( psl(1) == 9999999.9 ) psl(1) = -0.5 * dx |
---|
187 | IF ( psr(1) == 9999999.9 ) psr(1) = ( nx + 0.5 ) * dx |
---|
188 | IF ( pss(1) == 9999999.9 ) pss(1) = -0.5 * dy |
---|
189 | IF ( psn(1) == 9999999.9 ) psn(1) = ( ny + 0.5 ) * dy |
---|
190 | IF ( psb(1) == 9999999.9 ) psb(1) = zu(nz/2) |
---|
191 | IF ( pst(1) == 9999999.9 ) pst(1) = psb(1) |
---|
192 | |
---|
193 | IF ( pdx(1) == 9999999.9 .OR. pdx(1) == 0.0 ) pdx(1) = dx |
---|
194 | IF ( pdy(1) == 9999999.9 .OR. pdy(1) == 0.0 ) pdy(1) = dy |
---|
195 | IF ( pdz(1) == 9999999.9 .OR. pdz(1) == 0.0 ) pdz(1) = zu(2) - zu(1) |
---|
196 | |
---|
197 | DO j = 2, number_of_particle_groups |
---|
198 | IF ( psl(j) == 9999999.9 ) psl(j) = psl(j-1) |
---|
199 | IF ( psr(j) == 9999999.9 ) psr(j) = psr(j-1) |
---|
200 | IF ( pss(j) == 9999999.9 ) pss(j) = pss(j-1) |
---|
201 | IF ( psn(j) == 9999999.9 ) psn(j) = psn(j-1) |
---|
202 | IF ( psb(j) == 9999999.9 ) psb(j) = psb(j-1) |
---|
203 | IF ( pst(j) == 9999999.9 ) pst(j) = pst(j-1) |
---|
204 | IF ( pdx(j) == 9999999.9 .OR. pdx(j) == 0.0 ) pdx(j) = pdx(j-1) |
---|
205 | IF ( pdy(j) == 9999999.9 .OR. pdy(j) == 0.0 ) pdy(j) = pdy(j-1) |
---|
206 | IF ( pdz(j) == 9999999.9 .OR. pdz(j) == 0.0 ) pdz(j) = pdz(j-1) |
---|
207 | ENDDO |
---|
208 | |
---|
209 | ! |
---|
210 | !-- Allocate arrays required for calculating particle SGS velocities |
---|
211 | IF ( use_sgs_for_particles ) THEN |
---|
212 | ALLOCATE( de_dx(nzb:nzt+1,nysg:nyng,nxlg:nxrg), & |
---|
213 | de_dy(nzb:nzt+1,nysg:nyng,nxlg:nxrg), & |
---|
214 | de_dz(nzb:nzt+1,nysg:nyng,nxlg:nxrg) ) |
---|
215 | ENDIF |
---|
216 | |
---|
217 | ! |
---|
218 | !-- Allocate array required for logarithmic vertical interpolation of |
---|
219 | !-- horizontal particle velocities between the surface and the first vertical |
---|
220 | !-- grid level. In order to avoid repeated CPU cost-intensive CALLS of |
---|
221 | !-- intrinsic FORTRAN procedure LOG(z/z0), LOG(z/z0) is precalculated for |
---|
222 | !-- several heights. Splitting into 20 sublayers turned out to be sufficient. |
---|
223 | !-- To obtain exact height levels of particles, linear interpolation is applied |
---|
224 | !-- (see lpm_advec.f90). |
---|
225 | IF ( prandtl_layer ) THEN |
---|
226 | |
---|
227 | ALLOCATE ( log_z_z0(0:number_of_sublayers) ) |
---|
228 | z_p = zu(nzb+1) - zw(nzb) |
---|
229 | |
---|
230 | ! |
---|
231 | !-- Calculate horizontal mean value of z0 used for logartihmic |
---|
232 | !-- interpolation. Note: this is not exact for heterogeneous z0. |
---|
233 | !-- However, sensitivity studies showed that the effect is |
---|
234 | !-- negligible. |
---|
235 | z0_av_local = SUM( z0(nys:nyn,nxl:nxr) ) |
---|
236 | z0_av_global = 0.0 |
---|
237 | |
---|
238 | #if defined( __parallel ) |
---|
239 | CALL MPI_ALLREDUCE(z0_av_local, z0_av_global, 1, MPI_REAL, MPI_SUM, & |
---|
240 | comm2d, ierr ) |
---|
241 | #else |
---|
242 | z0_av_global = z0_av_local |
---|
243 | #endif |
---|
244 | |
---|
245 | z0_av_global = z0_av_global / ( ( ny + 1 ) * ( nx + 1 ) ) |
---|
246 | ! |
---|
247 | !-- Horizontal wind speed is zero below and at z0 |
---|
248 | log_z_z0(0) = 0.0 |
---|
249 | ! |
---|
250 | !-- Calculate vertical depth of the sublayers |
---|
251 | height_int = ( z_p - z0_av_global ) / REAL( number_of_sublayers ) |
---|
252 | ! |
---|
253 | !-- Precalculate LOG(z/z0) |
---|
254 | height_p = 0.0 |
---|
255 | DO k = 1, number_of_sublayers |
---|
256 | |
---|
257 | height_p = height_p + height_int |
---|
258 | log_z_z0(k) = LOG( height_p / z0_av_global ) |
---|
259 | |
---|
260 | ENDDO |
---|
261 | |
---|
262 | |
---|
263 | ENDIF |
---|
264 | |
---|
265 | ! |
---|
266 | !-- Initialize collision kernels |
---|
267 | IF ( collision_kernel /= 'none' ) CALL init_kernels |
---|
268 | |
---|
269 | ! |
---|
270 | !-- For the first model run of a possible job chain initialize the |
---|
271 | !-- particles, otherwise read the particle data from restart file. |
---|
272 | IF ( TRIM( initializing_actions ) == 'read_restart_data' & |
---|
273 | .AND. read_particles_from_restartfile ) THEN |
---|
274 | |
---|
275 | CALL lpm_read_restart_file |
---|
276 | |
---|
277 | ELSE |
---|
278 | |
---|
279 | ! |
---|
280 | !-- Allocate particle arrays and set attributes of the initial set of |
---|
281 | !-- particles, which can be also periodically released at later times. |
---|
282 | !-- Also allocate array for particle tail coordinates, if needed. |
---|
283 | ALLOCATE( prt_count(nzb:nzt+1,nysg:nyng,nxlg:nxrg), & |
---|
284 | prt_start_index(nzb:nzt+1,nysg:nyng,nxlg:nxrg), & |
---|
285 | particle_mask(maximum_number_of_particles), & |
---|
286 | part_1(maximum_number_of_particles), & |
---|
287 | part_2(maximum_number_of_particles) ) |
---|
288 | |
---|
289 | particles => part_1 |
---|
290 | |
---|
291 | sort_count = 0 |
---|
292 | |
---|
293 | ! |
---|
294 | !-- Initialize all particles with dummy values (otherwise errors may |
---|
295 | !-- occur within restart runs). The reason for this is still not clear |
---|
296 | !-- and may be presumably caused by errors in the respective user-interface. |
---|
297 | particles = particle_type( 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, & |
---|
298 | 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, & |
---|
299 | 0.0, 0, 0, 0, 0 ) |
---|
300 | particle_groups = particle_groups_type( 0.0, 0.0, 0.0, 0.0 ) |
---|
301 | |
---|
302 | ! |
---|
303 | !-- Set the default particle size used for dvrp plots |
---|
304 | IF ( dvrp_psize == 9999999.9 ) dvrp_psize = 0.2 * dx |
---|
305 | |
---|
306 | ! |
---|
307 | !-- Set values for the density ratio and radius for all particle |
---|
308 | !-- groups, if necessary |
---|
309 | IF ( density_ratio(1) == 9999999.9 ) density_ratio(1) = 0.0 |
---|
310 | IF ( radius(1) == 9999999.9 ) radius(1) = 0.0 |
---|
311 | DO i = 2, number_of_particle_groups |
---|
312 | IF ( density_ratio(i) == 9999999.9 ) THEN |
---|
313 | density_ratio(i) = density_ratio(i-1) |
---|
314 | ENDIF |
---|
315 | IF ( radius(i) == 9999999.9 ) radius(i) = radius(i-1) |
---|
316 | ENDDO |
---|
317 | |
---|
318 | DO i = 1, number_of_particle_groups |
---|
319 | IF ( density_ratio(i) /= 0.0 .AND. radius(i) == 0 ) THEN |
---|
320 | WRITE( message_string, * ) 'particle group #', i, 'has a', & |
---|
321 | 'density ratio /= 0 but radius = 0' |
---|
322 | CALL message( 'lpm_init', 'PA0215', 1, 2, 0, 6, 0 ) |
---|
323 | ENDIF |
---|
324 | particle_groups(i)%density_ratio = density_ratio(i) |
---|
325 | particle_groups(i)%radius = radius(i) |
---|
326 | ENDDO |
---|
327 | |
---|
328 | ! |
---|
329 | !-- Calculate particle positions and store particle attributes, if |
---|
330 | !-- particle is situated on this PE |
---|
331 | n = 0 |
---|
332 | |
---|
333 | DO i = 1, number_of_particle_groups |
---|
334 | |
---|
335 | pos_z = psb(i) |
---|
336 | |
---|
337 | DO WHILE ( pos_z <= pst(i) ) |
---|
338 | |
---|
339 | pos_y = pss(i) |
---|
340 | |
---|
341 | DO WHILE ( pos_y <= psn(i) ) |
---|
342 | |
---|
343 | IF ( pos_y >= ( nys - 0.5 ) * dy .AND. & |
---|
344 | pos_y < ( nyn + 0.5 ) * dy ) THEN |
---|
345 | |
---|
346 | pos_x = psl(i) |
---|
347 | |
---|
348 | DO WHILE ( pos_x <= psr(i) ) |
---|
349 | |
---|
350 | IF ( pos_x >= ( nxl - 0.5 ) * dx .AND. & |
---|
351 | pos_x < ( nxr + 0.5 ) * dx ) THEN |
---|
352 | |
---|
353 | DO j = 1, particles_per_point |
---|
354 | |
---|
355 | n = n + 1 |
---|
356 | IF ( n > maximum_number_of_particles ) THEN |
---|
357 | WRITE( message_string, * ) 'number of initial', & |
---|
358 | 'particles (', n, ') exceeds', & |
---|
359 | '&maximum_number_of_particles (', & |
---|
360 | maximum_number_of_particles, ') on PE ', & |
---|
361 | myid |
---|
362 | CALL message( 'lpm_init', 'PA0216', 2, 2, -1, 6,& |
---|
363 | 1 ) |
---|
364 | ENDIF |
---|
365 | particles(n)%x = pos_x |
---|
366 | particles(n)%y = pos_y |
---|
367 | particles(n)%z = pos_z |
---|
368 | particles(n)%age = 0.0 |
---|
369 | particles(n)%age_m = 0.0 |
---|
370 | particles(n)%dt_sum = 0.0 |
---|
371 | particles(n)%dvrp_psize = dvrp_psize |
---|
372 | particles(n)%e_m = 0.0 |
---|
373 | IF ( curvature_solution_effects ) THEN |
---|
374 | ! |
---|
375 | !-- Initial values (internal timesteps, derivative) |
---|
376 | !-- for Rosenbrock method |
---|
377 | particles(n)%rvar1 = 1.0E-12 |
---|
378 | particles(n)%rvar2 = 1.0E-3 |
---|
379 | particles(n)%rvar3 = -9999999.9 |
---|
380 | ELSE |
---|
381 | ! |
---|
382 | !-- Initial values for SGS velocities |
---|
383 | particles(n)%rvar1 = 0.0 |
---|
384 | particles(n)%rvar2 = 0.0 |
---|
385 | particles(n)%rvar3 = 0.0 |
---|
386 | ENDIF |
---|
387 | particles(n)%speed_x = 0.0 |
---|
388 | particles(n)%speed_y = 0.0 |
---|
389 | particles(n)%speed_z = 0.0 |
---|
390 | particles(n)%origin_x = pos_x |
---|
391 | particles(n)%origin_y = pos_y |
---|
392 | particles(n)%origin_z = pos_z |
---|
393 | particles(n)%radius = particle_groups(i)%radius |
---|
394 | particles(n)%weight_factor =initial_weighting_factor |
---|
395 | particles(n)%class = 1 |
---|
396 | particles(n)%group = i |
---|
397 | particles(n)%tailpoints = 0 |
---|
398 | IF ( use_particle_tails .AND. & |
---|
399 | MOD( n, skip_particles_for_tail ) == 0 ) THEN |
---|
400 | number_of_tails = number_of_tails + 1 |
---|
401 | ! |
---|
402 | !-- This is a temporary provisional setting (see |
---|
403 | !-- further below!) |
---|
404 | particles(n)%tail_id = number_of_tails |
---|
405 | ELSE |
---|
406 | particles(n)%tail_id = 0 |
---|
407 | ENDIF |
---|
408 | |
---|
409 | ENDDO |
---|
410 | |
---|
411 | ENDIF |
---|
412 | |
---|
413 | pos_x = pos_x + pdx(i) |
---|
414 | |
---|
415 | ENDDO |
---|
416 | |
---|
417 | ENDIF |
---|
418 | |
---|
419 | pos_y = pos_y + pdy(i) |
---|
420 | |
---|
421 | ENDDO |
---|
422 | |
---|
423 | pos_z = pos_z + pdz(i) |
---|
424 | |
---|
425 | ENDDO |
---|
426 | |
---|
427 | ENDDO |
---|
428 | |
---|
429 | number_of_initial_particles = n |
---|
430 | number_of_particles = n |
---|
431 | |
---|
432 | ! |
---|
433 | !-- Calculate the number of particles and tails of the total domain |
---|
434 | #if defined( __parallel ) |
---|
435 | IF ( collective_wait ) CALL MPI_BARRIER( comm2d, ierr ) |
---|
436 | CALL MPI_ALLREDUCE( number_of_particles, total_number_of_particles, 1, & |
---|
437 | MPI_INTEGER, MPI_SUM, comm2d, ierr ) |
---|
438 | IF ( collective_wait ) CALL MPI_BARRIER( comm2d, ierr ) |
---|
439 | CALL MPI_ALLREDUCE( number_of_tails, total_number_of_tails, 1, & |
---|
440 | MPI_INTEGER, MPI_SUM, comm2d, ierr ) |
---|
441 | #else |
---|
442 | total_number_of_particles = number_of_particles |
---|
443 | total_number_of_tails = number_of_tails |
---|
444 | #endif |
---|
445 | |
---|
446 | ! |
---|
447 | !-- Set a seed value for the random number generator to be exclusively |
---|
448 | !-- used for the particle code. The generated random numbers should be |
---|
449 | !-- different on the different PEs. |
---|
450 | iran_part = iran_part + myid |
---|
451 | |
---|
452 | ! |
---|
453 | !-- User modification of initial particles |
---|
454 | CALL user_lpm_init |
---|
455 | |
---|
456 | ! |
---|
457 | !-- Store the initial set of particles for release at later times |
---|
458 | IF ( number_of_initial_particles /= 0 ) THEN |
---|
459 | ALLOCATE( initial_particles(1:number_of_initial_particles) ) |
---|
460 | initial_particles(1:number_of_initial_particles) = & |
---|
461 | particles(1:number_of_initial_particles) |
---|
462 | ENDIF |
---|
463 | |
---|
464 | ! |
---|
465 | !-- Add random fluctuation to particle positions |
---|
466 | IF ( random_start_position ) THEN |
---|
467 | |
---|
468 | DO n = 1, number_of_initial_particles |
---|
469 | IF ( psl(particles(n)%group) /= psr(particles(n)%group) ) THEN |
---|
470 | particles(n)%x = particles(n)%x + & |
---|
471 | ( random_function( iran_part ) - 0.5 ) * & |
---|
472 | pdx(particles(n)%group) |
---|
473 | IF ( particles(n)%x <= ( nxl - 0.5 ) * dx ) THEN |
---|
474 | particles(n)%x = ( nxl - 0.4999999999 ) * dx |
---|
475 | ELSEIF ( particles(n)%x >= ( nxr + 0.5 ) * dx ) THEN |
---|
476 | particles(n)%x = ( nxr + 0.4999999999 ) * dx |
---|
477 | ENDIF |
---|
478 | ENDIF |
---|
479 | IF ( pss(particles(n)%group) /= psn(particles(n)%group) ) THEN |
---|
480 | particles(n)%y = particles(n)%y + & |
---|
481 | ( random_function( iran_part ) - 0.5 ) * & |
---|
482 | pdy(particles(n)%group) |
---|
483 | IF ( particles(n)%y <= ( nys - 0.5 ) * dy ) THEN |
---|
484 | particles(n)%y = ( nys - 0.4999999999 ) * dy |
---|
485 | ELSEIF ( particles(n)%y >= ( nyn + 0.5 ) * dy ) THEN |
---|
486 | particles(n)%y = ( nyn + 0.4999999999 ) * dy |
---|
487 | ENDIF |
---|
488 | ENDIF |
---|
489 | IF ( psb(particles(n)%group) /= pst(particles(n)%group) ) THEN |
---|
490 | particles(n)%z = particles(n)%z + & |
---|
491 | ( random_function( iran_part ) - 0.5 ) * & |
---|
492 | pdz(particles(n)%group) |
---|
493 | ENDIF |
---|
494 | ENDDO |
---|
495 | ENDIF |
---|
496 | |
---|
497 | ! |
---|
498 | !-- Sort particles in the sequence the gridboxes are stored in the memory. |
---|
499 | !-- Only required if cloud droplets are used. |
---|
500 | IF ( cloud_droplets ) CALL lpm_sort_arrays |
---|
501 | |
---|
502 | ! |
---|
503 | !-- Open file for statistical informations about particle conditions |
---|
504 | IF ( write_particle_statistics ) THEN |
---|
505 | CALL check_open( 80 ) |
---|
506 | WRITE ( 80, 8000 ) current_timestep_number, simulated_time, & |
---|
507 | number_of_initial_particles, & |
---|
508 | maximum_number_of_particles |
---|
509 | CALL close_file( 80 ) |
---|
510 | ENDIF |
---|
511 | |
---|
512 | ! |
---|
513 | !-- Check if particles are really uniform in color and radius (dvrp_size) |
---|
514 | !-- (uniform_particles is preset TRUE) |
---|
515 | IF ( uniform_particles ) THEN |
---|
516 | IF ( number_of_initial_particles == 0 ) THEN |
---|
517 | uniform_particles_l = .TRUE. |
---|
518 | ELSE |
---|
519 | n = number_of_initial_particles |
---|
520 | IF ( MINVAL( particles(1:n)%dvrp_psize ) == & |
---|
521 | MAXVAL( particles(1:n)%dvrp_psize ) .AND. & |
---|
522 | MINVAL( particles(1:n)%class ) == & |
---|
523 | MAXVAL( particles(1:n)%class ) ) THEN |
---|
524 | uniform_particles_l = .TRUE. |
---|
525 | ELSE |
---|
526 | uniform_particles_l = .FALSE. |
---|
527 | ENDIF |
---|
528 | ENDIF |
---|
529 | |
---|
530 | #if defined( __parallel ) |
---|
531 | IF ( collective_wait ) CALL MPI_BARRIER( comm2d, ierr ) |
---|
532 | CALL MPI_ALLREDUCE( uniform_particles_l, uniform_particles, 1, & |
---|
533 | MPI_LOGICAL, MPI_LAND, comm2d, ierr ) |
---|
534 | #else |
---|
535 | uniform_particles = uniform_particles_l |
---|
536 | #endif |
---|
537 | |
---|
538 | ENDIF |
---|
539 | |
---|
540 | ! |
---|
541 | !-- Particles will probably become none-uniform, if their size and color |
---|
542 | !-- will be determined by flow variables |
---|
543 | IF ( particle_color /= 'none' .OR. particle_dvrpsize /= 'none' ) THEN |
---|
544 | uniform_particles = .FALSE. |
---|
545 | ENDIF |
---|
546 | |
---|
547 | ! |
---|
548 | !-- Set the beginning of the particle tails and their age |
---|
549 | IF ( use_particle_tails ) THEN |
---|
550 | ! |
---|
551 | !-- Choose the maximum number of tails with respect to the maximum number |
---|
552 | !-- of particles and skip_particles_for_tail |
---|
553 | maximum_number_of_tails = maximum_number_of_particles / & |
---|
554 | skip_particles_for_tail |
---|
555 | |
---|
556 | ! |
---|
557 | !-- Create a minimum number of tails in case that there is no tail |
---|
558 | !-- initially (otherwise, index errors will occur when adressing the |
---|
559 | !-- arrays below) |
---|
560 | IF ( maximum_number_of_tails == 0 ) maximum_number_of_tails = 10 |
---|
561 | |
---|
562 | ALLOCATE( particle_tail_coordinates(maximum_number_of_tailpoints,5, & |
---|
563 | maximum_number_of_tails), & |
---|
564 | new_tail_id(maximum_number_of_tails), & |
---|
565 | tail_mask(maximum_number_of_tails) ) |
---|
566 | |
---|
567 | particle_tail_coordinates = 0.0 |
---|
568 | minimum_tailpoint_distance = minimum_tailpoint_distance**2 |
---|
569 | number_of_initial_tails = number_of_tails |
---|
570 | |
---|
571 | nn = 0 |
---|
572 | DO n = 1, number_of_particles |
---|
573 | ! |
---|
574 | !-- Only for those particles marked above with a provisional tail_id |
---|
575 | !-- tails will be created. Particles now get their final tail_id. |
---|
576 | IF ( particles(n)%tail_id /= 0 ) THEN |
---|
577 | |
---|
578 | nn = nn + 1 |
---|
579 | particles(n)%tail_id = nn |
---|
580 | |
---|
581 | particle_tail_coordinates(1,1,nn) = particles(n)%x |
---|
582 | particle_tail_coordinates(1,2,nn) = particles(n)%y |
---|
583 | particle_tail_coordinates(1,3,nn) = particles(n)%z |
---|
584 | particle_tail_coordinates(1,4,nn) = particles(n)%class |
---|
585 | particles(n)%tailpoints = 1 |
---|
586 | IF ( minimum_tailpoint_distance /= 0.0 ) THEN |
---|
587 | particle_tail_coordinates(2,1,nn) = particles(n)%x |
---|
588 | particle_tail_coordinates(2,2,nn) = particles(n)%y |
---|
589 | particle_tail_coordinates(2,3,nn) = particles(n)%z |
---|
590 | particle_tail_coordinates(2,4,nn) = particles(n)%class |
---|
591 | particle_tail_coordinates(1:2,5,nn) = 0.0 |
---|
592 | particles(n)%tailpoints = 2 |
---|
593 | ENDIF |
---|
594 | |
---|
595 | ENDIF |
---|
596 | ENDDO |
---|
597 | ENDIF |
---|
598 | |
---|
599 | ! |
---|
600 | !-- Plot initial positions of particles (only if particle advection is |
---|
601 | !-- switched on from the beginning of the simulation (t=0)) |
---|
602 | IF ( particle_advection_start == 0.0 ) CALL data_output_dvrp |
---|
603 | |
---|
604 | ENDIF |
---|
605 | |
---|
606 | ! |
---|
607 | !-- Check boundary condition and set internal variables |
---|
608 | SELECT CASE ( bc_par_b ) |
---|
609 | |
---|
610 | CASE ( 'absorb' ) |
---|
611 | ibc_par_b = 1 |
---|
612 | |
---|
613 | CASE ( 'reflect' ) |
---|
614 | ibc_par_b = 2 |
---|
615 | |
---|
616 | CASE DEFAULT |
---|
617 | WRITE( message_string, * ) 'unknown boundary condition ', & |
---|
618 | 'bc_par_b = "', TRIM( bc_par_b ), '"' |
---|
619 | CALL message( 'lpm_init', 'PA0217', 1, 2, 0, 6, 0 ) |
---|
620 | |
---|
621 | END SELECT |
---|
622 | SELECT CASE ( bc_par_t ) |
---|
623 | |
---|
624 | CASE ( 'absorb' ) |
---|
625 | ibc_par_t = 1 |
---|
626 | |
---|
627 | CASE ( 'reflect' ) |
---|
628 | ibc_par_t = 2 |
---|
629 | |
---|
630 | CASE DEFAULT |
---|
631 | WRITE( message_string, * ) 'unknown boundary condition ', & |
---|
632 | 'bc_par_t = "', TRIM( bc_par_t ), '"' |
---|
633 | CALL message( 'lpm_init', 'PA0218', 1, 2, 0, 6, 0 ) |
---|
634 | |
---|
635 | END SELECT |
---|
636 | SELECT CASE ( bc_par_lr ) |
---|
637 | |
---|
638 | CASE ( 'cyclic' ) |
---|
639 | ibc_par_lr = 0 |
---|
640 | |
---|
641 | CASE ( 'absorb' ) |
---|
642 | ibc_par_lr = 1 |
---|
643 | |
---|
644 | CASE ( 'reflect' ) |
---|
645 | ibc_par_lr = 2 |
---|
646 | |
---|
647 | CASE DEFAULT |
---|
648 | WRITE( message_string, * ) 'unknown boundary condition ', & |
---|
649 | 'bc_par_lr = "', TRIM( bc_par_lr ), '"' |
---|
650 | CALL message( 'lpm_init', 'PA0219', 1, 2, 0, 6, 0 ) |
---|
651 | |
---|
652 | END SELECT |
---|
653 | SELECT CASE ( bc_par_ns ) |
---|
654 | |
---|
655 | CASE ( 'cyclic' ) |
---|
656 | ibc_par_ns = 0 |
---|
657 | |
---|
658 | CASE ( 'absorb' ) |
---|
659 | ibc_par_ns = 1 |
---|
660 | |
---|
661 | CASE ( 'reflect' ) |
---|
662 | ibc_par_ns = 2 |
---|
663 | |
---|
664 | CASE DEFAULT |
---|
665 | WRITE( message_string, * ) 'unknown boundary condition ', & |
---|
666 | 'bc_par_ns = "', TRIM( bc_par_ns ), '"' |
---|
667 | CALL message( 'lpm_init', 'PA0220', 1, 2, 0, 6, 0 ) |
---|
668 | |
---|
669 | END SELECT |
---|
670 | ! |
---|
671 | !-- Formats |
---|
672 | 8000 FORMAT (I6,1X,F7.2,4X,I6,71X,I6) |
---|
673 | |
---|
674 | END SUBROUTINE lpm_init |
---|