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 |
---|
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-2017 Leibniz Universitaet Hannover |
---|
18 | !------------------------------------------------------------------------------! |
---|
19 | ! |
---|
20 | ! Current revisions: |
---|
21 | ! ----------------- |
---|
22 | ! |
---|
23 | ! |
---|
24 | ! Former revisions: |
---|
25 | ! ----------------- |
---|
26 | ! $Id: lpm_init.f90 2101 2017-01-05 16:42:31Z suehring $ |
---|
27 | ! |
---|
28 | ! 2000 2016-08-20 18:09:15Z knoop |
---|
29 | ! Forced header and separation lines into 80 columns |
---|
30 | ! |
---|
31 | ! 2016-06-09 16:25:25Z suehring |
---|
32 | ! Bugfix in determining initial particle height and grid index in case of |
---|
33 | ! seed_follows_topography. |
---|
34 | ! Bugfix concerning random positions, ensure that particles do not move more |
---|
35 | ! than one grid length. |
---|
36 | ! Bugfix logarithmic interpolation. |
---|
37 | ! Initial setting of sgs_wf_part. |
---|
38 | ! |
---|
39 | ! 1890 2016-04-22 08:52:11Z hoffmann |
---|
40 | ! Initialization of aerosol equilibrium radius not possible in supersaturated |
---|
41 | ! environments. Therefore, a maximum supersaturation of -1 % is assumed during |
---|
42 | ! initialization. |
---|
43 | ! |
---|
44 | ! 1873 2016-04-18 14:50:06Z maronga |
---|
45 | ! Module renamed (removed _mod |
---|
46 | |
---|
47 | ! |
---|
48 | ! 1871 2016-04-15 11:46:09Z hoffmann |
---|
49 | ! Initialization of aerosols added. |
---|
50 | ! |
---|
51 | ! 1850 2016-04-08 13:29:27Z maronga |
---|
52 | ! Module renamed |
---|
53 | ! |
---|
54 | ! 1831 2016-04-07 13:15:51Z hoffmann |
---|
55 | ! curvature_solution_effects moved to particle_attributes |
---|
56 | ! |
---|
57 | ! 1822 2016-04-07 07:49:42Z hoffmann |
---|
58 | ! Unused variables removed. |
---|
59 | ! |
---|
60 | ! 1783 2016-03-06 18:36:17Z raasch |
---|
61 | ! netcdf module added |
---|
62 | ! |
---|
63 | ! 1725 2015-11-17 13:01:51Z hoffmann |
---|
64 | ! Bugfix: Processor-dependent seed for random function is generated before it is |
---|
65 | ! used. |
---|
66 | ! |
---|
67 | ! 1691 2015-10-26 16:17:44Z maronga |
---|
68 | ! Renamed prandtl_layer to constant_flux_layer. |
---|
69 | ! |
---|
70 | ! 1685 2015-10-08 07:32:13Z raasch |
---|
71 | ! bugfix concerning vertical index offset in case of ocean |
---|
72 | ! |
---|
73 | ! 1682 2015-10-07 23:56:08Z knoop |
---|
74 | ! Code annotations made doxygen readable |
---|
75 | ! |
---|
76 | ! 1575 2015-03-27 09:56:27Z raasch |
---|
77 | ! initial vertical particle position is allowed to follow the topography |
---|
78 | ! |
---|
79 | ! 1359 2014-04-11 17:15:14Z hoffmann |
---|
80 | ! New particle structure integrated. |
---|
81 | ! Kind definition added to all floating point numbers. |
---|
82 | ! lpm_init changed form a subroutine to a module. |
---|
83 | ! |
---|
84 | ! 1327 2014-03-21 11:00:16Z raasch |
---|
85 | ! -netcdf_output |
---|
86 | ! |
---|
87 | ! 1322 2014-03-20 16:38:49Z raasch |
---|
88 | ! REAL functions provided with KIND-attribute |
---|
89 | ! |
---|
90 | ! 1320 2014-03-20 08:40:49Z raasch |
---|
91 | ! ONLY-attribute added to USE-statements, |
---|
92 | ! kind-parameters added to all INTEGER and REAL declaration statements, |
---|
93 | ! kinds are defined in new module kinds, |
---|
94 | ! revision history before 2012 removed, |
---|
95 | ! comment fields (!:) to be used for variable explanations added to |
---|
96 | ! all variable declaration statements |
---|
97 | ! bugfix: #if defined( __parallel ) added |
---|
98 | ! |
---|
99 | ! 1314 2014-03-14 18:25:17Z suehring |
---|
100 | ! Vertical logarithmic interpolation of horizontal particle speed for particles |
---|
101 | ! between roughness height and first vertical grid level. |
---|
102 | ! |
---|
103 | ! 1092 2013-02-02 11:24:22Z raasch |
---|
104 | ! unused variables removed |
---|
105 | ! |
---|
106 | ! 1036 2012-10-22 13:43:42Z raasch |
---|
107 | ! code put under GPL (PALM 3.9) |
---|
108 | ! |
---|
109 | ! 849 2012-03-15 10:35:09Z raasch |
---|
110 | ! routine renamed: init_particles -> lpm_init |
---|
111 | ! de_dx, de_dy, de_dz are allocated here (instead of automatic arrays in |
---|
112 | ! advec_particles), |
---|
113 | ! sort_particles renamed lpm_sort_arrays, user_init_particles renamed lpm_init |
---|
114 | ! |
---|
115 | ! 828 2012-02-21 12:00:36Z raasch |
---|
116 | ! call of init_kernels, particle feature color renamed class |
---|
117 | ! |
---|
118 | ! 824 2012-02-17 09:09:57Z raasch |
---|
119 | ! particle attributes speed_x|y|z_sgs renamed rvar1|2|3, |
---|
120 | ! array particles implemented as pointer |
---|
121 | ! |
---|
122 | ! 667 2010-12-23 12:06:00Z suehring/gryschka |
---|
123 | ! nxl-1, nxr+1, nys-1, nyn+1 replaced by nxlg, nxrg, nysg, nyng for allocation |
---|
124 | ! of arrays. |
---|
125 | ! |
---|
126 | ! Revision 1.1 1999/11/25 16:22:38 raasch |
---|
127 | ! Initial revision |
---|
128 | ! |
---|
129 | ! |
---|
130 | ! Description: |
---|
131 | ! ------------ |
---|
132 | !> This routine initializes a set of particles and their attributes (position, |
---|
133 | !> radius, ..) which are used by the Lagrangian particle model (see lpm). |
---|
134 | !------------------------------------------------------------------------------! |
---|
135 | MODULE lpm_init_mod |
---|
136 | |
---|
137 | |
---|
138 | USE arrays_3d, & |
---|
139 | ONLY: de_dx, de_dy, de_dz, zu, zw, z0 |
---|
140 | |
---|
141 | USE control_parameters, & |
---|
142 | ONLY: cloud_droplets, constant_flux_layer, current_timestep_number, & |
---|
143 | dz, initializing_actions, message_string, ocean, simulated_time |
---|
144 | |
---|
145 | USE grid_variables, & |
---|
146 | ONLY: ddx, dx, ddy, dy |
---|
147 | |
---|
148 | USE indices, & |
---|
149 | ONLY: nx, nxl, nxlg, nxrg, nxr, ny, nyn, nys, nyng, nysg, nz, nzb, & |
---|
150 | nzb_w_inner, nzt |
---|
151 | |
---|
152 | USE kinds |
---|
153 | |
---|
154 | USE lpm_collision_kernels_mod, & |
---|
155 | ONLY: init_kernels |
---|
156 | |
---|
157 | USE netcdf_interface, & |
---|
158 | ONLY: netcdf_data_format |
---|
159 | |
---|
160 | USE particle_attributes, & |
---|
161 | ONLY: alloc_factor, bc_par_b, bc_par_lr, bc_par_ns, bc_par_t, & |
---|
162 | block_offset, block_offset_def, collision_kernel, & |
---|
163 | curvature_solution_effects, & |
---|
164 | density_ratio, grid_particles, & |
---|
165 | initial_weighting_factor, ibc_par_b, ibc_par_lr, ibc_par_ns, & |
---|
166 | ibc_par_t, iran_part, log_z_z0, & |
---|
167 | max_number_of_particle_groups, maximum_number_of_particles, & |
---|
168 | min_nr_particle, mpi_particle_type, & |
---|
169 | number_of_particles, & |
---|
170 | number_of_particle_groups, number_of_sublayers, & |
---|
171 | offset_ocean_nzt, offset_ocean_nzt_m1, & |
---|
172 | particles, particle_advection_start, particle_groups, & |
---|
173 | particle_groups_type, particles_per_point, & |
---|
174 | particle_type, pdx, pdy, pdz, & |
---|
175 | prt_count, psb, psl, psn, psr, pss, pst, & |
---|
176 | radius, random_start_position, read_particles_from_restartfile,& |
---|
177 | seed_follows_topography, sgs_wf_part, sort_count, & |
---|
178 | total_number_of_particles, & |
---|
179 | use_sgs_for_particles, & |
---|
180 | write_particle_statistics, uniform_particles, zero_particle, & |
---|
181 | z0_av_global |
---|
182 | |
---|
183 | USE pegrid |
---|
184 | |
---|
185 | USE random_function_mod, & |
---|
186 | ONLY: random_function |
---|
187 | |
---|
188 | IMPLICIT NONE |
---|
189 | |
---|
190 | PRIVATE |
---|
191 | |
---|
192 | INTEGER(iwp), PARAMETER :: PHASE_INIT = 1 !< |
---|
193 | INTEGER(iwp), PARAMETER, PUBLIC :: PHASE_RELEASE = 2 !< |
---|
194 | |
---|
195 | INTERFACE lpm_init |
---|
196 | MODULE PROCEDURE lpm_init |
---|
197 | END INTERFACE lpm_init |
---|
198 | |
---|
199 | INTERFACE lpm_create_particle |
---|
200 | MODULE PROCEDURE lpm_create_particle |
---|
201 | END INTERFACE lpm_create_particle |
---|
202 | |
---|
203 | PUBLIC lpm_init, lpm_create_particle |
---|
204 | |
---|
205 | CONTAINS |
---|
206 | |
---|
207 | !------------------------------------------------------------------------------! |
---|
208 | ! Description: |
---|
209 | ! ------------ |
---|
210 | !> @todo Missing subroutine description. |
---|
211 | !------------------------------------------------------------------------------! |
---|
212 | SUBROUTINE lpm_init |
---|
213 | |
---|
214 | USE lpm_collision_kernels_mod, & |
---|
215 | ONLY: init_kernels |
---|
216 | |
---|
217 | IMPLICIT NONE |
---|
218 | |
---|
219 | INTEGER(iwp) :: i !< |
---|
220 | INTEGER(iwp) :: j !< |
---|
221 | INTEGER(iwp) :: k !< |
---|
222 | |
---|
223 | #if defined( __parallel ) |
---|
224 | INTEGER(iwp), DIMENSION(3) :: blocklengths !< |
---|
225 | INTEGER(iwp), DIMENSION(3) :: displacements !< |
---|
226 | INTEGER(iwp), DIMENSION(3) :: types !< |
---|
227 | #endif |
---|
228 | |
---|
229 | REAL(wp) :: height_int !< |
---|
230 | REAL(wp) :: height_p !< |
---|
231 | REAL(wp) :: z_p !< |
---|
232 | REAL(wp) :: z0_av_local !< |
---|
233 | |
---|
234 | #if defined( __parallel ) |
---|
235 | ! |
---|
236 | !-- Define MPI derived datatype for FORTRAN datatype particle_type (see module |
---|
237 | !-- particle_attributes). Integer length is 4 byte, Real is 8 byte |
---|
238 | blocklengths(1) = 19; blocklengths(2) = 6; blocklengths(3) = 1 |
---|
239 | displacements(1) = 0; displacements(2) = 152; displacements(3) = 176 |
---|
240 | |
---|
241 | types(1) = MPI_REAL |
---|
242 | types(2) = MPI_INTEGER |
---|
243 | types(3) = MPI_UB |
---|
244 | CALL MPI_TYPE_STRUCT( 3, blocklengths, displacements, types, & |
---|
245 | mpi_particle_type, ierr ) |
---|
246 | CALL MPI_TYPE_COMMIT( mpi_particle_type, ierr ) |
---|
247 | #endif |
---|
248 | |
---|
249 | ! |
---|
250 | !-- In case of oceans runs, the vertical index calculations need an offset, |
---|
251 | !-- because otherwise the k indices will become negative |
---|
252 | IF ( ocean ) THEN |
---|
253 | offset_ocean_nzt = nzt |
---|
254 | offset_ocean_nzt_m1 = nzt - 1 |
---|
255 | ENDIF |
---|
256 | |
---|
257 | ! |
---|
258 | !-- Define block offsets for dividing a gridcell in 8 sub cells |
---|
259 | |
---|
260 | block_offset(0) = block_offset_def (-1,-1,-1) |
---|
261 | block_offset(1) = block_offset_def (-1,-1, 0) |
---|
262 | block_offset(2) = block_offset_def (-1, 0,-1) |
---|
263 | block_offset(3) = block_offset_def (-1, 0, 0) |
---|
264 | block_offset(4) = block_offset_def ( 0,-1,-1) |
---|
265 | block_offset(5) = block_offset_def ( 0,-1, 0) |
---|
266 | block_offset(6) = block_offset_def ( 0, 0,-1) |
---|
267 | block_offset(7) = block_offset_def ( 0, 0, 0) |
---|
268 | ! |
---|
269 | !-- Check the number of particle groups. |
---|
270 | IF ( number_of_particle_groups > max_number_of_particle_groups ) THEN |
---|
271 | WRITE( message_string, * ) 'max_number_of_particle_groups =', & |
---|
272 | max_number_of_particle_groups , & |
---|
273 | '&number_of_particle_groups reset to ', & |
---|
274 | max_number_of_particle_groups |
---|
275 | CALL message( 'lpm_init', 'PA0213', 0, 1, 0, 6, 0 ) |
---|
276 | number_of_particle_groups = max_number_of_particle_groups |
---|
277 | ENDIF |
---|
278 | |
---|
279 | ! |
---|
280 | !-- Set default start positions, if necessary |
---|
281 | IF ( psl(1) == 9999999.9_wp ) psl(1) = -0.5_wp * dx |
---|
282 | IF ( psr(1) == 9999999.9_wp ) psr(1) = ( nx + 0.5_wp ) * dx |
---|
283 | IF ( pss(1) == 9999999.9_wp ) pss(1) = -0.5_wp * dy |
---|
284 | IF ( psn(1) == 9999999.9_wp ) psn(1) = ( ny + 0.5_wp ) * dy |
---|
285 | IF ( psb(1) == 9999999.9_wp ) psb(1) = zu(nz/2) |
---|
286 | IF ( pst(1) == 9999999.9_wp ) pst(1) = psb(1) |
---|
287 | |
---|
288 | IF ( pdx(1) == 9999999.9_wp .OR. pdx(1) == 0.0_wp ) pdx(1) = dx |
---|
289 | IF ( pdy(1) == 9999999.9_wp .OR. pdy(1) == 0.0_wp ) pdy(1) = dy |
---|
290 | IF ( pdz(1) == 9999999.9_wp .OR. pdz(1) == 0.0_wp ) pdz(1) = zu(2) - zu(1) |
---|
291 | |
---|
292 | DO j = 2, number_of_particle_groups |
---|
293 | IF ( psl(j) == 9999999.9_wp ) psl(j) = psl(j-1) |
---|
294 | IF ( psr(j) == 9999999.9_wp ) psr(j) = psr(j-1) |
---|
295 | IF ( pss(j) == 9999999.9_wp ) pss(j) = pss(j-1) |
---|
296 | IF ( psn(j) == 9999999.9_wp ) psn(j) = psn(j-1) |
---|
297 | IF ( psb(j) == 9999999.9_wp ) psb(j) = psb(j-1) |
---|
298 | IF ( pst(j) == 9999999.9_wp ) pst(j) = pst(j-1) |
---|
299 | IF ( pdx(j) == 9999999.9_wp .OR. pdx(j) == 0.0_wp ) pdx(j) = pdx(j-1) |
---|
300 | IF ( pdy(j) == 9999999.9_wp .OR. pdy(j) == 0.0_wp ) pdy(j) = pdy(j-1) |
---|
301 | IF ( pdz(j) == 9999999.9_wp .OR. pdz(j) == 0.0_wp ) pdz(j) = pdz(j-1) |
---|
302 | ENDDO |
---|
303 | |
---|
304 | ! |
---|
305 | !-- Allocate arrays required for calculating particle SGS velocities. |
---|
306 | !-- Initialize prefactor required for stoachastic Weil equation. |
---|
307 | IF ( use_sgs_for_particles .AND. .NOT. cloud_droplets ) THEN |
---|
308 | ALLOCATE( de_dx(nzb:nzt+1,nysg:nyng,nxlg:nxrg), & |
---|
309 | de_dy(nzb:nzt+1,nysg:nyng,nxlg:nxrg), & |
---|
310 | de_dz(nzb:nzt+1,nysg:nyng,nxlg:nxrg) ) |
---|
311 | |
---|
312 | sgs_wf_part = 1.0_wp / 3.0_wp |
---|
313 | ENDIF |
---|
314 | |
---|
315 | ! |
---|
316 | !-- Allocate array required for logarithmic vertical interpolation of |
---|
317 | !-- horizontal particle velocities between the surface and the first vertical |
---|
318 | !-- grid level. In order to avoid repeated CPU cost-intensive CALLS of |
---|
319 | !-- intrinsic FORTRAN procedure LOG(z/z0), LOG(z/z0) is precalculated for |
---|
320 | !-- several heights. Splitting into 20 sublayers turned out to be sufficient. |
---|
321 | !-- To obtain exact height levels of particles, linear interpolation is applied |
---|
322 | !-- (see lpm_advec.f90). |
---|
323 | IF ( constant_flux_layer ) THEN |
---|
324 | |
---|
325 | ALLOCATE ( log_z_z0(0:number_of_sublayers) ) |
---|
326 | z_p = zu(nzb+1) - zw(nzb) |
---|
327 | |
---|
328 | ! |
---|
329 | !-- Calculate horizontal mean value of z0 used for logartihmic |
---|
330 | !-- interpolation. Note: this is not exact for heterogeneous z0. |
---|
331 | !-- However, sensitivity studies showed that the effect is |
---|
332 | !-- negligible. |
---|
333 | z0_av_local = SUM( z0(nys:nyn,nxl:nxr) ) |
---|
334 | z0_av_global = 0.0_wp |
---|
335 | |
---|
336 | #if defined( __parallel ) |
---|
337 | CALL MPI_ALLREDUCE(z0_av_local, z0_av_global, 1, MPI_REAL, MPI_SUM, & |
---|
338 | comm2d, ierr ) |
---|
339 | #else |
---|
340 | z0_av_global = z0_av_local |
---|
341 | #endif |
---|
342 | |
---|
343 | z0_av_global = z0_av_global / ( ( ny + 1 ) * ( nx + 1 ) ) |
---|
344 | ! |
---|
345 | !-- Horizontal wind speed is zero below and at z0 |
---|
346 | log_z_z0(0) = 0.0_wp |
---|
347 | ! |
---|
348 | !-- Calculate vertical depth of the sublayers |
---|
349 | height_int = ( z_p - z0_av_global ) / REAL( number_of_sublayers, KIND=wp ) |
---|
350 | ! |
---|
351 | !-- Precalculate LOG(z/z0) |
---|
352 | height_p = z0_av_global |
---|
353 | DO k = 1, number_of_sublayers |
---|
354 | |
---|
355 | height_p = height_p + height_int |
---|
356 | log_z_z0(k) = LOG( height_p / z0_av_global ) |
---|
357 | |
---|
358 | ENDDO |
---|
359 | |
---|
360 | ENDIF |
---|
361 | |
---|
362 | ! |
---|
363 | !-- Check boundary condition and set internal variables |
---|
364 | SELECT CASE ( bc_par_b ) |
---|
365 | |
---|
366 | CASE ( 'absorb' ) |
---|
367 | ibc_par_b = 1 |
---|
368 | |
---|
369 | CASE ( 'reflect' ) |
---|
370 | ibc_par_b = 2 |
---|
371 | |
---|
372 | CASE DEFAULT |
---|
373 | WRITE( message_string, * ) 'unknown boundary condition ', & |
---|
374 | 'bc_par_b = "', TRIM( bc_par_b ), '"' |
---|
375 | CALL message( 'lpm_init', 'PA0217', 1, 2, 0, 6, 0 ) |
---|
376 | |
---|
377 | END SELECT |
---|
378 | SELECT CASE ( bc_par_t ) |
---|
379 | |
---|
380 | CASE ( 'absorb' ) |
---|
381 | ibc_par_t = 1 |
---|
382 | |
---|
383 | CASE ( 'reflect' ) |
---|
384 | ibc_par_t = 2 |
---|
385 | |
---|
386 | CASE DEFAULT |
---|
387 | WRITE( message_string, * ) 'unknown boundary condition ', & |
---|
388 | 'bc_par_t = "', TRIM( bc_par_t ), '"' |
---|
389 | CALL message( 'lpm_init', 'PA0218', 1, 2, 0, 6, 0 ) |
---|
390 | |
---|
391 | END SELECT |
---|
392 | SELECT CASE ( bc_par_lr ) |
---|
393 | |
---|
394 | CASE ( 'cyclic' ) |
---|
395 | ibc_par_lr = 0 |
---|
396 | |
---|
397 | CASE ( 'absorb' ) |
---|
398 | ibc_par_lr = 1 |
---|
399 | |
---|
400 | CASE ( 'reflect' ) |
---|
401 | ibc_par_lr = 2 |
---|
402 | |
---|
403 | CASE DEFAULT |
---|
404 | WRITE( message_string, * ) 'unknown boundary condition ', & |
---|
405 | 'bc_par_lr = "', TRIM( bc_par_lr ), '"' |
---|
406 | CALL message( 'lpm_init', 'PA0219', 1, 2, 0, 6, 0 ) |
---|
407 | |
---|
408 | END SELECT |
---|
409 | SELECT CASE ( bc_par_ns ) |
---|
410 | |
---|
411 | CASE ( 'cyclic' ) |
---|
412 | ibc_par_ns = 0 |
---|
413 | |
---|
414 | CASE ( 'absorb' ) |
---|
415 | ibc_par_ns = 1 |
---|
416 | |
---|
417 | CASE ( 'reflect' ) |
---|
418 | ibc_par_ns = 2 |
---|
419 | |
---|
420 | CASE DEFAULT |
---|
421 | WRITE( message_string, * ) 'unknown boundary condition ', & |
---|
422 | 'bc_par_ns = "', TRIM( bc_par_ns ), '"' |
---|
423 | CALL message( 'lpm_init', 'PA0220', 1, 2, 0, 6, 0 ) |
---|
424 | |
---|
425 | END SELECT |
---|
426 | |
---|
427 | ! |
---|
428 | !-- Initialize collision kernels |
---|
429 | IF ( collision_kernel /= 'none' ) CALL init_kernels |
---|
430 | |
---|
431 | ! |
---|
432 | !-- For the first model run of a possible job chain initialize the |
---|
433 | !-- particles, otherwise read the particle data from restart file. |
---|
434 | IF ( TRIM( initializing_actions ) == 'read_restart_data' & |
---|
435 | .AND. read_particles_from_restartfile ) THEN |
---|
436 | |
---|
437 | CALL lpm_read_restart_file |
---|
438 | |
---|
439 | ELSE |
---|
440 | |
---|
441 | ! |
---|
442 | !-- Allocate particle arrays and set attributes of the initial set of |
---|
443 | !-- particles, which can be also periodically released at later times. |
---|
444 | ALLOCATE( prt_count(nzb:nzt+1,nysg:nyng,nxlg:nxrg), & |
---|
445 | grid_particles(nzb+1:nzt,nys:nyn,nxl:nxr) ) |
---|
446 | |
---|
447 | maximum_number_of_particles = 0 |
---|
448 | number_of_particles = 0 |
---|
449 | |
---|
450 | sort_count = 0 |
---|
451 | prt_count = 0 |
---|
452 | |
---|
453 | ! |
---|
454 | !-- Initialize all particles with dummy values (otherwise errors may |
---|
455 | !-- occur within restart runs). The reason for this is still not clear |
---|
456 | !-- and may be presumably caused by errors in the respective user-interface. |
---|
457 | zero_particle = particle_type( 0.0_wp, 0.0_wp, 0.0_wp, 0.0_wp, 0.0_wp, & |
---|
458 | 0.0_wp, 0.0_wp, 0.0_wp, 0.0_wp, 0.0_wp, & |
---|
459 | 0.0_wp, 0.0_wp, 0.0_wp, 0.0_wp, 0.0_wp, & |
---|
460 | 0.0_wp, 0.0_wp, 0.0_wp, 0.0_wp, 0, 0, 0, & |
---|
461 | 0, .FALSE., -1 ) |
---|
462 | |
---|
463 | particle_groups = particle_groups_type( 0.0_wp, 0.0_wp, 0.0_wp, 0.0_wp ) |
---|
464 | |
---|
465 | ! |
---|
466 | !-- Set values for the density ratio and radius for all particle |
---|
467 | !-- groups, if necessary |
---|
468 | IF ( density_ratio(1) == 9999999.9_wp ) density_ratio(1) = 0.0_wp |
---|
469 | IF ( radius(1) == 9999999.9_wp ) radius(1) = 0.0_wp |
---|
470 | DO i = 2, number_of_particle_groups |
---|
471 | IF ( density_ratio(i) == 9999999.9_wp ) THEN |
---|
472 | density_ratio(i) = density_ratio(i-1) |
---|
473 | ENDIF |
---|
474 | IF ( radius(i) == 9999999.9_wp ) radius(i) = radius(i-1) |
---|
475 | ENDDO |
---|
476 | |
---|
477 | DO i = 1, number_of_particle_groups |
---|
478 | IF ( density_ratio(i) /= 0.0_wp .AND. radius(i) == 0 ) THEN |
---|
479 | WRITE( message_string, * ) 'particle group #', i, 'has a', & |
---|
480 | 'density ratio /= 0 but radius = 0' |
---|
481 | CALL message( 'lpm_init', 'PA0215', 1, 2, 0, 6, 0 ) |
---|
482 | ENDIF |
---|
483 | particle_groups(i)%density_ratio = density_ratio(i) |
---|
484 | particle_groups(i)%radius = radius(i) |
---|
485 | ENDDO |
---|
486 | |
---|
487 | ! |
---|
488 | !-- Set a seed value for the random number generator to be exclusively |
---|
489 | !-- used for the particle code. The generated random numbers should be |
---|
490 | !-- different on the different PEs. |
---|
491 | iran_part = iran_part + myid |
---|
492 | |
---|
493 | CALL lpm_create_particle (PHASE_INIT) |
---|
494 | ! |
---|
495 | !-- User modification of initial particles |
---|
496 | CALL user_lpm_init |
---|
497 | |
---|
498 | ! |
---|
499 | !-- Open file for statistical informations about particle conditions |
---|
500 | IF ( write_particle_statistics ) THEN |
---|
501 | CALL check_open( 80 ) |
---|
502 | WRITE ( 80, 8000 ) current_timestep_number, simulated_time, & |
---|
503 | number_of_particles, & |
---|
504 | maximum_number_of_particles |
---|
505 | CALL close_file( 80 ) |
---|
506 | ENDIF |
---|
507 | |
---|
508 | ENDIF |
---|
509 | |
---|
510 | ! |
---|
511 | !-- To avoid programm abort, assign particles array to the local version of |
---|
512 | !-- first grid cell |
---|
513 | number_of_particles = prt_count(nzb+1,nys,nxl) |
---|
514 | particles => grid_particles(nzb+1,nys,nxl)%particles(1:number_of_particles) |
---|
515 | ! |
---|
516 | !-- Formats |
---|
517 | 8000 FORMAT (I6,1X,F7.2,4X,I10,71X,I10) |
---|
518 | |
---|
519 | END SUBROUTINE lpm_init |
---|
520 | |
---|
521 | !------------------------------------------------------------------------------! |
---|
522 | ! Description: |
---|
523 | ! ------------ |
---|
524 | !> @todo Missing subroutine description. |
---|
525 | !------------------------------------------------------------------------------! |
---|
526 | SUBROUTINE lpm_create_particle (phase) |
---|
527 | |
---|
528 | USE lpm_exchange_horiz_mod, & |
---|
529 | ONLY: lpm_exchange_horiz, lpm_move_particle, realloc_particles_array |
---|
530 | |
---|
531 | USE lpm_pack_arrays_mod, & |
---|
532 | ONLY: lpm_pack_all_arrays |
---|
533 | |
---|
534 | USE particle_attributes, & |
---|
535 | ONLY: deleted_particles, monodisperse_aerosols |
---|
536 | |
---|
537 | IMPLICIT NONE |
---|
538 | |
---|
539 | INTEGER(iwp) :: alloc_size !< relative increase of allocated memory for particles |
---|
540 | INTEGER(iwp) :: i !< loop variable ( particle groups ) |
---|
541 | INTEGER(iwp) :: ip !< index variable along x |
---|
542 | INTEGER(iwp) :: j !< loop variable ( particles per point ) |
---|
543 | INTEGER(iwp) :: jp !< index variable along y |
---|
544 | INTEGER(iwp) :: kp !< index variable along z |
---|
545 | INTEGER(iwp) :: loop_stride !< loop variable for initialization |
---|
546 | INTEGER(iwp) :: n !< loop variable ( number of particles ) |
---|
547 | INTEGER(iwp) :: new_size !< new size of allocated memory for particles |
---|
548 | |
---|
549 | INTEGER(iwp), INTENT(IN) :: phase !< mode of inititialization |
---|
550 | |
---|
551 | INTEGER(iwp), DIMENSION(nzb:nzt+1,nysg:nyng,nxlg:nxrg) :: local_count !< start address of new particle |
---|
552 | INTEGER(iwp), DIMENSION(nzb:nzt+1,nysg:nyng,nxlg:nxrg) :: local_start !< start address of new particle |
---|
553 | |
---|
554 | LOGICAL :: first_stride !< flag for initialization |
---|
555 | |
---|
556 | REAL(wp) :: pos_x !< increment for particle position in x |
---|
557 | REAL(wp) :: pos_y !< increment for particle position in y |
---|
558 | REAL(wp) :: pos_z !< increment for particle position in z |
---|
559 | REAL(wp) :: rand_contr !< dummy argument for random position |
---|
560 | |
---|
561 | TYPE(particle_type),TARGET :: tmp_particle !< temporary particle used for initialization |
---|
562 | |
---|
563 | ! |
---|
564 | !-- Calculate particle positions and store particle attributes, if |
---|
565 | !-- particle is situated on this PE |
---|
566 | DO loop_stride = 1, 2 |
---|
567 | first_stride = (loop_stride == 1) |
---|
568 | IF ( first_stride ) THEN |
---|
569 | local_count = 0 ! count number of particles |
---|
570 | ELSE |
---|
571 | local_count = prt_count ! Start address of new particles |
---|
572 | ENDIF |
---|
573 | |
---|
574 | n = 0 |
---|
575 | DO i = 1, number_of_particle_groups |
---|
576 | |
---|
577 | pos_z = psb(i) |
---|
578 | |
---|
579 | DO WHILE ( pos_z <= pst(i) ) |
---|
580 | |
---|
581 | pos_y = pss(i) |
---|
582 | |
---|
583 | DO WHILE ( pos_y <= psn(i) ) |
---|
584 | |
---|
585 | IF ( pos_y >= ( nys - 0.5_wp ) * dy .AND. & |
---|
586 | pos_y < ( nyn + 0.5_wp ) * dy ) THEN |
---|
587 | |
---|
588 | pos_x = psl(i) |
---|
589 | |
---|
590 | xloop: DO WHILE ( pos_x <= psr(i) ) |
---|
591 | |
---|
592 | IF ( pos_x >= ( nxl - 0.5_wp ) * dx .AND. & |
---|
593 | pos_x < ( nxr + 0.5_wp ) * dx ) THEN |
---|
594 | |
---|
595 | DO j = 1, particles_per_point |
---|
596 | |
---|
597 | n = n + 1 |
---|
598 | tmp_particle%x = pos_x |
---|
599 | tmp_particle%y = pos_y |
---|
600 | tmp_particle%z = pos_z |
---|
601 | tmp_particle%age = 0.0_wp |
---|
602 | tmp_particle%age_m = 0.0_wp |
---|
603 | tmp_particle%dt_sum = 0.0_wp |
---|
604 | tmp_particle%dvrp_psize = 0.0_wp !unused |
---|
605 | tmp_particle%e_m = 0.0_wp |
---|
606 | IF ( curvature_solution_effects ) THEN |
---|
607 | ! |
---|
608 | !-- Initial values (internal timesteps, derivative) |
---|
609 | !-- for Rosenbrock method |
---|
610 | tmp_particle%rvar1 = 1.0E-6_wp !last Rosenbrock timestep |
---|
611 | tmp_particle%rvar2 = 0.1E-6_wp !dry aerosol radius |
---|
612 | tmp_particle%rvar3 = -9999999.9_wp !unused |
---|
613 | ELSE |
---|
614 | ! |
---|
615 | !-- Initial values for SGS velocities |
---|
616 | tmp_particle%rvar1 = 0.0_wp |
---|
617 | tmp_particle%rvar2 = 0.0_wp |
---|
618 | tmp_particle%rvar3 = 0.0_wp |
---|
619 | ENDIF |
---|
620 | tmp_particle%speed_x = 0.0_wp |
---|
621 | tmp_particle%speed_y = 0.0_wp |
---|
622 | tmp_particle%speed_z = 0.0_wp |
---|
623 | tmp_particle%origin_x = pos_x |
---|
624 | tmp_particle%origin_y = pos_y |
---|
625 | tmp_particle%origin_z = pos_z |
---|
626 | tmp_particle%radius = particle_groups(i)%radius |
---|
627 | tmp_particle%weight_factor = initial_weighting_factor |
---|
628 | tmp_particle%class = 1 |
---|
629 | tmp_particle%group = i |
---|
630 | tmp_particle%tailpoints = 0 !unused |
---|
631 | tmp_particle%particle_mask = .TRUE. |
---|
632 | tmp_particle%tail_id = 0 !unused |
---|
633 | |
---|
634 | |
---|
635 | ! |
---|
636 | !-- Determine the grid indices of the particle position |
---|
637 | ip = ( tmp_particle%x + 0.5_wp * dx ) * ddx |
---|
638 | jp = ( tmp_particle%y + 0.5_wp * dy ) * ddy |
---|
639 | kp = tmp_particle%z / dz + 1 + offset_ocean_nzt |
---|
640 | |
---|
641 | IF ( seed_follows_topography ) THEN |
---|
642 | ! |
---|
643 | !-- Particle height is given relative to topography |
---|
644 | kp = kp + nzb_w_inner(jp,ip) |
---|
645 | tmp_particle%z = tmp_particle%z + & |
---|
646 | zw(nzb_w_inner(jp,ip)) |
---|
647 | IF ( kp > nzt ) THEN |
---|
648 | pos_x = pos_x + pdx(i) |
---|
649 | CYCLE xloop |
---|
650 | ENDIF |
---|
651 | ELSEIF ( .NOT. seed_follows_topography .AND. & |
---|
652 | tmp_particle%z <= zw(nzb_w_inner(jp,ip)) ) THEN |
---|
653 | pos_x = pos_x + pdx(i) |
---|
654 | CYCLE xloop |
---|
655 | ENDIF |
---|
656 | |
---|
657 | local_count(kp,jp,ip) = local_count(kp,jp,ip) + 1 |
---|
658 | IF ( .NOT. first_stride ) THEN |
---|
659 | IF ( ip < nxl .OR. jp < nys .OR. kp < nzb+1 ) THEN |
---|
660 | write(6,*) 'xl ',ip,jp,kp,nxl,nys,nzb+1 |
---|
661 | ENDIF |
---|
662 | IF ( ip > nxr .OR. jp > nyn .OR. kp > nzt ) THEN |
---|
663 | write(6,*) 'xu ',ip,jp,kp,nxr,nyn,nzt |
---|
664 | ENDIF |
---|
665 | grid_particles(kp,jp,ip)%particles(local_count(kp,jp,ip)) = tmp_particle |
---|
666 | |
---|
667 | ENDIF |
---|
668 | ENDDO |
---|
669 | |
---|
670 | ENDIF |
---|
671 | |
---|
672 | pos_x = pos_x + pdx(i) |
---|
673 | |
---|
674 | ENDDO xloop |
---|
675 | |
---|
676 | ENDIF |
---|
677 | |
---|
678 | pos_y = pos_y + pdy(i) |
---|
679 | |
---|
680 | ENDDO |
---|
681 | |
---|
682 | pos_z = pos_z + pdz(i) |
---|
683 | |
---|
684 | ENDDO |
---|
685 | |
---|
686 | ENDDO |
---|
687 | |
---|
688 | IF ( first_stride ) THEN |
---|
689 | DO ip = nxl, nxr |
---|
690 | DO jp = nys, nyn |
---|
691 | DO kp = nzb+1, nzt |
---|
692 | IF ( phase == PHASE_INIT ) THEN |
---|
693 | IF ( local_count(kp,jp,ip) > 0 ) THEN |
---|
694 | alloc_size = MAX( INT( local_count(kp,jp,ip) * & |
---|
695 | ( 1.0_wp + alloc_factor / 100.0_wp ) ), & |
---|
696 | min_nr_particle ) |
---|
697 | ELSE |
---|
698 | alloc_size = min_nr_particle |
---|
699 | ENDIF |
---|
700 | ALLOCATE(grid_particles(kp,jp,ip)%particles(1:alloc_size)) |
---|
701 | DO n = 1, alloc_size |
---|
702 | grid_particles(kp,jp,ip)%particles(n) = zero_particle |
---|
703 | ENDDO |
---|
704 | ELSEIF ( phase == PHASE_RELEASE ) THEN |
---|
705 | IF ( local_count(kp,jp,ip) > 0 ) THEN |
---|
706 | new_size = local_count(kp,jp,ip) + prt_count(kp,jp,ip) |
---|
707 | alloc_size = MAX( INT( new_size * ( 1.0_wp + & |
---|
708 | alloc_factor / 100.0_wp ) ), min_nr_particle ) |
---|
709 | IF( alloc_size > SIZE( grid_particles(kp,jp,ip)%particles) ) THEN |
---|
710 | CALL realloc_particles_array(ip,jp,kp,alloc_size) |
---|
711 | ENDIF |
---|
712 | ENDIF |
---|
713 | ENDIF |
---|
714 | |
---|
715 | ENDDO |
---|
716 | ENDDO |
---|
717 | ENDDO |
---|
718 | ENDIF |
---|
719 | |
---|
720 | ENDDO |
---|
721 | |
---|
722 | local_start = prt_count+1 |
---|
723 | prt_count = local_count |
---|
724 | |
---|
725 | ! |
---|
726 | !-- Initialize aerosol background spectrum |
---|
727 | IF ( curvature_solution_effects .AND. .NOT. monodisperse_aerosols ) THEN |
---|
728 | CALL lpm_init_aerosols(local_start) |
---|
729 | ENDIF |
---|
730 | |
---|
731 | ! |
---|
732 | !-- Add random fluctuation to particle positions. |
---|
733 | IF ( random_start_position ) THEN |
---|
734 | DO ip = nxl, nxr |
---|
735 | DO jp = nys, nyn |
---|
736 | DO kp = nzb+1, nzt |
---|
737 | number_of_particles = prt_count(kp,jp,ip) |
---|
738 | IF ( number_of_particles <= 0 ) CYCLE |
---|
739 | particles => grid_particles(kp,jp,ip)%particles(1:number_of_particles) |
---|
740 | ! |
---|
741 | !-- Move only new particles. Moreover, limit random fluctuation |
---|
742 | !-- in order to prevent that particles move more than one grid box, |
---|
743 | !-- which would lead to problems concerning particle exchange |
---|
744 | !-- between processors in case pdx/pdy are larger than dx/dy, |
---|
745 | !-- respectively. |
---|
746 | DO n = local_start(kp,jp,ip), number_of_particles |
---|
747 | IF ( psl(particles(n)%group) /= psr(particles(n)%group) ) THEN |
---|
748 | rand_contr = ( random_function( iran_part ) - 0.5_wp ) * & |
---|
749 | pdx(particles(n)%group) |
---|
750 | particles(n)%x = particles(n)%x + & |
---|
751 | MERGE( rand_contr, SIGN( dx, rand_contr ), & |
---|
752 | ABS( rand_contr ) < dx & |
---|
753 | ) |
---|
754 | ENDIF |
---|
755 | IF ( pss(particles(n)%group) /= psn(particles(n)%group) ) THEN |
---|
756 | rand_contr = ( random_function( iran_part ) - 0.5_wp ) * & |
---|
757 | pdy(particles(n)%group) |
---|
758 | particles(n)%y = particles(n)%y + & |
---|
759 | MERGE( rand_contr, SIGN( dy, rand_contr ), & |
---|
760 | ABS( rand_contr ) < dy & |
---|
761 | ) |
---|
762 | ENDIF |
---|
763 | IF ( psb(particles(n)%group) /= pst(particles(n)%group) ) THEN |
---|
764 | rand_contr = ( random_function( iran_part ) - 0.5_wp ) * & |
---|
765 | pdz(particles(n)%group) |
---|
766 | particles(n)%z = particles(n)%z + & |
---|
767 | MERGE( rand_contr, SIGN( dz, rand_contr ), & |
---|
768 | ABS( rand_contr ) < dz & |
---|
769 | ) |
---|
770 | ENDIF |
---|
771 | ENDDO |
---|
772 | ! |
---|
773 | !-- Identify particles located outside the model domain and reflect |
---|
774 | !-- or absorb them if necessary. |
---|
775 | CALL lpm_boundary_conds( 'bottom/top' ) |
---|
776 | ! |
---|
777 | !-- Furthermore, remove particles located in topography. Note, as |
---|
778 | !-- the particle speed is still zero at this point, wall |
---|
779 | !-- reflection boundary conditions will not work in this case. |
---|
780 | particles => & |
---|
781 | grid_particles(kp,jp,ip)%particles(1:number_of_particles) |
---|
782 | DO n = local_start(kp,jp,ip), number_of_particles |
---|
783 | i = ( particles(n)%x + 0.5_wp * dx ) * ddx |
---|
784 | j = ( particles(n)%y + 0.5_wp * dy ) * ddy |
---|
785 | IF ( particles(n)%z <= zw(nzb_w_inner(j,i)) ) THEN |
---|
786 | particles(n)%particle_mask = .FALSE. |
---|
787 | deleted_particles = deleted_particles + 1 |
---|
788 | ENDIF |
---|
789 | ENDDO |
---|
790 | ENDDO |
---|
791 | ENDDO |
---|
792 | ENDDO |
---|
793 | ! |
---|
794 | !-- Exchange particles between grid cells and processors |
---|
795 | CALL lpm_move_particle |
---|
796 | CALL lpm_exchange_horiz |
---|
797 | |
---|
798 | ENDIF |
---|
799 | ! |
---|
800 | !-- In case of random_start_position, delete particles identified by |
---|
801 | !-- lpm_exchange_horiz and lpm_boundary_conds. Then sort particles into blocks, |
---|
802 | !-- which is needed for a fast interpolation of the LES fields on the particle |
---|
803 | !-- position. |
---|
804 | CALL lpm_pack_all_arrays |
---|
805 | |
---|
806 | ! |
---|
807 | !-- Determine maximum number of particles (i.e., all possible particles that |
---|
808 | !-- have been allocated) and the current number of particles |
---|
809 | DO ip = nxl, nxr |
---|
810 | DO jp = nys, nyn |
---|
811 | DO kp = nzb+1, nzt |
---|
812 | maximum_number_of_particles = maximum_number_of_particles & |
---|
813 | + SIZE(grid_particles(kp,jp,ip)%particles) |
---|
814 | number_of_particles = number_of_particles & |
---|
815 | + prt_count(kp,jp,ip) |
---|
816 | ENDDO |
---|
817 | ENDDO |
---|
818 | ENDDO |
---|
819 | ! |
---|
820 | !-- Calculate the number of particles of the total domain |
---|
821 | #if defined( __parallel ) |
---|
822 | IF ( collective_wait ) CALL MPI_BARRIER( comm2d, ierr ) |
---|
823 | CALL MPI_ALLREDUCE( number_of_particles, total_number_of_particles, 1, & |
---|
824 | MPI_INTEGER, MPI_SUM, comm2d, ierr ) |
---|
825 | #else |
---|
826 | total_number_of_particles = number_of_particles |
---|
827 | #endif |
---|
828 | |
---|
829 | RETURN |
---|
830 | |
---|
831 | END SUBROUTINE lpm_create_particle |
---|
832 | |
---|
833 | SUBROUTINE lpm_init_aerosols(local_start) |
---|
834 | |
---|
835 | USE arrays_3d, & |
---|
836 | ONLY: hyp, pt, q |
---|
837 | |
---|
838 | USE cloud_parameters, & |
---|
839 | ONLY: l_d_rv, rho_l |
---|
840 | |
---|
841 | USE constants, & |
---|
842 | ONLY: pi |
---|
843 | |
---|
844 | USE kinds |
---|
845 | |
---|
846 | USE particle_attributes, & |
---|
847 | ONLY: init_aerosol_probabilistic, molecular_weight_of_solute, & |
---|
848 | molecular_weight_of_water, n1, n2, n3, rho_s, rm1, rm2, rm3, & |
---|
849 | s1, s2, s3, vanthoff |
---|
850 | |
---|
851 | IMPLICIT NONE |
---|
852 | |
---|
853 | REAL(wp), DIMENSION(:), ALLOCATABLE :: cdf !< CDF of aerosol spectrum |
---|
854 | REAL(wp), DIMENSION(:), ALLOCATABLE :: r_temp !< dry aerosol radius spectrum |
---|
855 | |
---|
856 | REAL(wp) :: bfactor !< solute effects |
---|
857 | REAL(wp) :: dr !< width of radius bin |
---|
858 | REAL(wp) :: e_a !< vapor pressure |
---|
859 | REAL(wp) :: e_s !< saturation vapor pressure |
---|
860 | REAL(wp) :: n_init !< sum of all aerosol concentrations |
---|
861 | REAL(wp) :: pdf !< PDF of aerosol spectrum |
---|
862 | REAL(wp) :: rmin = 1.0e-8_wp !< minimum aerosol radius |
---|
863 | REAL(wp) :: rmax = 1.0e-6_wp !< maximum aerosol radius |
---|
864 | REAL(wp) :: rs_rand !< random number |
---|
865 | REAL(wp) :: r_mid !< mean radius |
---|
866 | REAL(wp) :: t_int !< temperature |
---|
867 | REAL(wp) :: weight_sum !< sum of all weighting factors |
---|
868 | |
---|
869 | INTEGER(iwp), DIMENSION(nzb:nzt+1,nysg:nyng,nxlg:nxrg), INTENT(IN) :: local_start !< |
---|
870 | |
---|
871 | INTEGER(iwp) :: n !< |
---|
872 | INTEGER(iwp) :: nn !< |
---|
873 | INTEGER(iwp) :: no_bins = 999 !< number of bins |
---|
874 | INTEGER(iwp) :: ip !< |
---|
875 | INTEGER(iwp) :: jp !< |
---|
876 | INTEGER(iwp) :: kp !< |
---|
877 | |
---|
878 | LOGICAL :: new_pdf = .FALSE. !< check if aerosol PDF has to be recalculated |
---|
879 | |
---|
880 | ! |
---|
881 | !-- Compute aerosol background distribution |
---|
882 | IF ( init_aerosol_probabilistic ) THEN |
---|
883 | ALLOCATE( cdf(0:no_bins), r_temp(0:no_bins) ) |
---|
884 | DO n = 0, no_bins |
---|
885 | r_temp(n) = EXP( LOG(rmin) + ( LOG(rmax) - LOG(rmin ) ) / & |
---|
886 | REAL(no_bins, KIND=wp) * REAL(n, KIND=wp) ) |
---|
887 | |
---|
888 | cdf(n) = 0.0_wp |
---|
889 | n_init = n1 + n2 + n3 |
---|
890 | IF ( n1 > 0.0_wp ) THEN |
---|
891 | cdf(n) = cdf(n) + n1 / n_init * ( 0.5_wp + 0.5_wp * & |
---|
892 | ERF( LOG( r_temp(n) / rm1 ) / & |
---|
893 | ( SQRT(2.0_wp) * LOG(s1) ) & |
---|
894 | ) ) |
---|
895 | ENDIF |
---|
896 | IF ( n2 > 0.0_wp ) THEN |
---|
897 | cdf(n) = cdf(n) + n2 / n_init * ( 0.5_wp + 0.5_wp * & |
---|
898 | ERF( LOG( r_temp(n) / rm2 ) / & |
---|
899 | ( SQRT(2.0_wp) * LOG(s2) ) & |
---|
900 | ) ) |
---|
901 | ENDIF |
---|
902 | IF ( n3 > 0.0_wp ) THEN |
---|
903 | cdf(n) = cdf(n) + n3 / n_init * ( 0.5_wp + 0.5_wp * & |
---|
904 | ERF( LOG( r_temp(n) / rm3 ) / & |
---|
905 | ( SQRT(2.0_wp) * LOG(s3) ) & |
---|
906 | ) ) |
---|
907 | ENDIF |
---|
908 | |
---|
909 | ENDDO |
---|
910 | ENDIF |
---|
911 | |
---|
912 | DO ip = nxl, nxr |
---|
913 | DO jp = nys, nyn |
---|
914 | DO kp = nzb+1, nzt |
---|
915 | |
---|
916 | number_of_particles = prt_count(kp,jp,ip) |
---|
917 | IF ( number_of_particles <= 0 ) CYCLE |
---|
918 | particles => grid_particles(kp,jp,ip)%particles(1:number_of_particles) |
---|
919 | ! |
---|
920 | !-- Initialize the aerosols with a predefined spectral distribution |
---|
921 | !-- of the dry radius (logarithmically increasing bins) and a varying |
---|
922 | !-- weighting factor |
---|
923 | IF ( .NOT. init_aerosol_probabilistic ) THEN |
---|
924 | |
---|
925 | new_pdf = .FALSE. |
---|
926 | IF ( .NOT. ALLOCATED( r_temp ) ) THEN |
---|
927 | new_pdf = .TRUE. |
---|
928 | ELSE |
---|
929 | IF ( SIZE( r_temp ) .NE. & |
---|
930 | number_of_particles - local_start(kp,jp,ip) + 2 ) THEN |
---|
931 | new_pdf = .TRUE. |
---|
932 | DEALLOCATE( r_temp ) |
---|
933 | ENDIF |
---|
934 | ENDIF |
---|
935 | |
---|
936 | IF ( new_pdf ) THEN |
---|
937 | |
---|
938 | no_bins = number_of_particles + 1 - local_start(kp,jp,ip) |
---|
939 | ALLOCATE( r_temp(0:no_bins) ) |
---|
940 | |
---|
941 | DO n = 0, no_bins |
---|
942 | r_temp(n) = EXP( LOG(rmin) + ( LOG(rmax) - LOG(rmin ) ) / & |
---|
943 | REAL(no_bins, KIND=wp) * & |
---|
944 | REAL(n, KIND=wp) ) |
---|
945 | ENDDO |
---|
946 | |
---|
947 | ENDIF |
---|
948 | |
---|
949 | ! |
---|
950 | !-- Calculate radius and concentration of each aerosol |
---|
951 | DO n = local_start(kp,jp,ip), number_of_particles |
---|
952 | |
---|
953 | nn = n - local_start(kp,jp,ip) |
---|
954 | |
---|
955 | r_mid = SQRT( r_temp(nn) * r_temp(nn+1) ) |
---|
956 | dr = r_temp(nn+1) - r_temp(nn) |
---|
957 | |
---|
958 | pdf = 0.0_wp |
---|
959 | n_init = n1 + n2 + n3 |
---|
960 | IF ( n1 > 0.0_wp ) THEN |
---|
961 | pdf = pdf + n1 / n_init * ( 1.0_wp / ( r_mid * LOG(s1) * & |
---|
962 | SQRT( 2.0_wp * pi ) & |
---|
963 | ) * & |
---|
964 | EXP( -( LOG( r_mid / rm1 ) )**2 / & |
---|
965 | ( 2.0_wp * LOG(s1)**2 ) & |
---|
966 | ) & |
---|
967 | ) |
---|
968 | ENDIF |
---|
969 | IF ( n2 > 0.0_wp ) THEN |
---|
970 | pdf = pdf + n2 / n_init * ( 1.0_wp / ( r_mid * LOG(s2) * & |
---|
971 | SQRT( 2.0_wp * pi ) & |
---|
972 | ) * & |
---|
973 | EXP( -( LOG( r_mid / rm2 ) )**2 / & |
---|
974 | ( 2.0_wp * LOG(s2)**2 ) & |
---|
975 | ) & |
---|
976 | ) |
---|
977 | ENDIF |
---|
978 | IF ( n3 > 0.0_wp ) THEN |
---|
979 | pdf = pdf + n3 / n_init * ( 1.0_wp / ( r_mid * LOG(s3) * & |
---|
980 | SQRT( 2.0_wp * pi ) & |
---|
981 | ) * & |
---|
982 | EXP( -( LOG( r_mid / rm3 ) )**2 / & |
---|
983 | ( 2.0_wp * LOG(s3)**2 ) & |
---|
984 | ) & |
---|
985 | ) |
---|
986 | ENDIF |
---|
987 | |
---|
988 | particles(n)%rvar2 = r_mid |
---|
989 | particles(n)%weight_factor = pdf * dr |
---|
990 | |
---|
991 | END DO |
---|
992 | ! |
---|
993 | !-- Adjust weighting factors to initialize the same number of aerosols |
---|
994 | !-- in every grid box |
---|
995 | weight_sum = SUM(particles(local_start(kp,jp,ip):number_of_particles)%weight_factor) |
---|
996 | |
---|
997 | particles(local_start(kp,jp,ip):number_of_particles)%weight_factor = & |
---|
998 | particles(local_start(kp,jp,ip):number_of_particles)%weight_factor / & |
---|
999 | weight_sum * initial_weighting_factor * ( no_bins + 1 ) |
---|
1000 | |
---|
1001 | ENDIF |
---|
1002 | ! |
---|
1003 | !-- Initialize the aerosols with a predefined weighting factor but |
---|
1004 | !-- a randomly choosen dry radius |
---|
1005 | IF ( init_aerosol_probabilistic ) THEN |
---|
1006 | |
---|
1007 | DO n = local_start(kp,jp,ip), number_of_particles !only new particles |
---|
1008 | |
---|
1009 | rs_rand = -1.0_wp |
---|
1010 | DO WHILE ( rs_rand .LT. cdf(0) .OR. rs_rand .GE. cdf(no_bins) ) |
---|
1011 | rs_rand = random_function( iran_part ) |
---|
1012 | ENDDO |
---|
1013 | ! |
---|
1014 | !-- Determine aerosol dry radius by a random number generator |
---|
1015 | DO nn = 0, no_bins-1 |
---|
1016 | IF ( cdf(nn) .LE. rs_rand .AND. cdf(nn+1) .GT. rs_rand ) THEN |
---|
1017 | particles(n)%rvar2 = r_temp(nn) + ( r_temp(nn+1) - r_temp(nn) ) / & |
---|
1018 | ( cdf(nn+1) - cdf(nn) ) * ( rs_rand - cdf(nn) ) |
---|
1019 | EXIT |
---|
1020 | ENDIF |
---|
1021 | ENDDO |
---|
1022 | |
---|
1023 | ENDDO |
---|
1024 | |
---|
1025 | ENDIF |
---|
1026 | |
---|
1027 | ! |
---|
1028 | !-- Set particle radius to equilibrium radius based on the environmental |
---|
1029 | !-- supersaturation (Khvorostyanov and Curry, 2007, JGR). This avoids |
---|
1030 | !-- the sometimes lengthy growth toward their equilibrium radius within |
---|
1031 | !-- the simulation. |
---|
1032 | t_int = pt(kp,jp,ip) * ( hyp(kp) / 100000.0_wp )**0.286_wp |
---|
1033 | |
---|
1034 | e_s = 611.0_wp * EXP( l_d_rv * ( 3.6609E-3_wp - 1.0_wp / t_int ) ) |
---|
1035 | e_a = q(kp,jp,ip) * hyp(kp) / ( 0.378_wp * q(kp,jp,ip) + 0.622_wp ) |
---|
1036 | |
---|
1037 | ! |
---|
1038 | !-- The formula is only valid for subsaturated environments. For |
---|
1039 | !-- supersaturations higher than -1 %, the supersaturation is set to -1%. |
---|
1040 | IF ( e_a / e_s < 0.99_wp ) THEN |
---|
1041 | |
---|
1042 | DO n = local_start(kp,jp,ip), number_of_particles !only new particles |
---|
1043 | |
---|
1044 | bfactor = vanthoff * molecular_weight_of_water * & |
---|
1045 | rho_s * particles(n)%rvar2**3 / & |
---|
1046 | ( molecular_weight_of_solute * rho_l ) |
---|
1047 | particles(n)%radius = particles(n)%rvar2 * ( bfactor / & |
---|
1048 | particles(n)%rvar2**3 )**(1.0_wp/3.0_wp) *& |
---|
1049 | ( 1.0_wp - e_a / e_s )**(-1.0_wp/3.0_wp) |
---|
1050 | |
---|
1051 | ENDDO |
---|
1052 | |
---|
1053 | ELSE |
---|
1054 | |
---|
1055 | DO n = local_start(kp,jp,ip), number_of_particles !only new particles |
---|
1056 | |
---|
1057 | bfactor = vanthoff * molecular_weight_of_water * & |
---|
1058 | rho_s * particles(n)%rvar2**3 / & |
---|
1059 | ( molecular_weight_of_solute * rho_l ) |
---|
1060 | particles(n)%radius = particles(n)%rvar2 * ( bfactor / & |
---|
1061 | particles(n)%rvar2**3 )**(1.0_wp/3.0_wp) *& |
---|
1062 | 0.01_wp**(-1.0_wp/3.0_wp) |
---|
1063 | |
---|
1064 | ENDDO |
---|
1065 | |
---|
1066 | ENDIF |
---|
1067 | |
---|
1068 | ENDDO |
---|
1069 | ENDDO |
---|
1070 | ENDDO |
---|
1071 | ! |
---|
1072 | !-- Deallocate used arrays |
---|
1073 | IF ( ALLOCATED(r_temp) ) DEALLOCATE( r_temp ) |
---|
1074 | IF ( ALLOCATED(cdf) ) DEALLOCATE( cdf ) |
---|
1075 | |
---|
1076 | END SUBROUTINE lpm_init_aerosols |
---|
1077 | |
---|
1078 | END MODULE lpm_init_mod |
---|