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