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