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