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