[849] | 1 | SUBROUTINE lpm_init |
---|
[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 | ! ----------------- |
---|
[1322] | 22 | ! REAL functions provided with KIND-attribute |
---|
[1321] | 23 | ! |
---|
| 24 | ! Former revisions: |
---|
| 25 | ! ----------------- |
---|
| 26 | ! $Id: lpm_init.f90 1322 2014-03-20 16:38:49Z raasch $ |
---|
| 27 | ! |
---|
| 28 | ! 1320 2014-03-20 08:40:49Z raasch |
---|
[1320] | 29 | ! ONLY-attribute added to USE-statements, |
---|
| 30 | ! kind-parameters added to all INTEGER and REAL declaration statements, |
---|
| 31 | ! kinds are defined in new module kinds, |
---|
| 32 | ! revision history before 2012 removed, |
---|
| 33 | ! comment fields (!:) to be used for variable explanations added to |
---|
| 34 | ! all variable declaration statements |
---|
| 35 | ! bugfix: #if defined( __parallel ) added |
---|
[850] | 36 | ! |
---|
[1315] | 37 | ! 1314 2014-03-14 18:25:17Z suehring |
---|
| 38 | ! Vertical logarithmic interpolation of horizontal particle speed for particles |
---|
| 39 | ! between roughness height and first vertical grid level. |
---|
| 40 | ! |
---|
[1093] | 41 | ! 1092 2013-02-02 11:24:22Z raasch |
---|
| 42 | ! unused variables removed |
---|
| 43 | ! |
---|
[1037] | 44 | ! 1036 2012-10-22 13:43:42Z raasch |
---|
| 45 | ! code put under GPL (PALM 3.9) |
---|
| 46 | ! |
---|
[850] | 47 | ! 849 2012-03-15 10:35:09Z raasch |
---|
[849] | 48 | ! routine renamed: init_particles -> lpm_init |
---|
| 49 | ! de_dx, de_dy, de_dz are allocated here (instead of automatic arrays in |
---|
| 50 | ! advec_particles), |
---|
| 51 | ! sort_particles renamed lpm_sort_arrays, user_init_particles renamed lpm_init |
---|
[392] | 52 | ! |
---|
[829] | 53 | ! 828 2012-02-21 12:00:36Z raasch |
---|
| 54 | ! call of init_kernels, particle feature color renamed class |
---|
| 55 | ! |
---|
[826] | 56 | ! 824 2012-02-17 09:09:57Z raasch |
---|
| 57 | ! particle attributes speed_x|y|z_sgs renamed rvar1|2|3, |
---|
| 58 | ! array particles implemented as pointer |
---|
| 59 | ! |
---|
[668] | 60 | ! 667 2010-12-23 12:06:00Z suehring/gryschka |
---|
| 61 | ! nxl-1, nxr+1, nys-1, nyn+1 replaced by nxlg, nxrg, nysg, nyng for allocation |
---|
| 62 | ! of arrays. |
---|
| 63 | ! |
---|
[1] | 64 | ! Revision 1.1 1999/11/25 16:22:38 raasch |
---|
| 65 | ! Initial revision |
---|
| 66 | ! |
---|
| 67 | ! |
---|
| 68 | ! Description: |
---|
| 69 | ! ------------ |
---|
| 70 | ! This routine initializes a set of particles and their attributes (position, |
---|
[849] | 71 | ! radius, ..) which are used by the Lagrangian particle model (see lpm). |
---|
[1] | 72 | !------------------------------------------------------------------------------! |
---|
| 73 | |
---|
[1320] | 74 | USE arrays_3d, & |
---|
| 75 | ONLY: de_dx, de_dy, de_dz, zu, zw, z0 |
---|
| 76 | |
---|
| 77 | USE cloud_parameters, & |
---|
| 78 | ONLY: curvature_solution_effects |
---|
| 79 | |
---|
| 80 | USE control_parameters, & |
---|
| 81 | ONLY: cloud_droplets, current_timestep_number, initializing_actions, & |
---|
| 82 | message_string, netcdf_output,netcdf_data_format, ocean, & |
---|
| 83 | prandtl_layer, simulated_time |
---|
| 84 | |
---|
| 85 | USE dvrp_variables, & |
---|
| 86 | ONLY: particle_color, particle_dvrpsize |
---|
| 87 | |
---|
| 88 | USE grid_variables, & |
---|
| 89 | ONLY: dx, dy |
---|
| 90 | |
---|
| 91 | USE indices, & |
---|
| 92 | ONLY: nx, nxl, nxlg, nxrg, nxr, ny, nyn, nys, nyng, nysg, nz, nzb, nzt |
---|
| 93 | |
---|
| 94 | USE kinds |
---|
| 95 | |
---|
| 96 | USE lpm_collision_kernels_mod, & |
---|
| 97 | ONLY: init_kernels |
---|
| 98 | |
---|
| 99 | USE particle_attributes, & |
---|
| 100 | ONLY: bc_par_b, bc_par_lr, bc_par_ns, bc_par_t, collision_kernel, & |
---|
| 101 | density_ratio, dvrp_psize, initial_weighting_factor, ibc_par_b,& |
---|
| 102 | ibc_par_lr, ibc_par_ns, ibc_par_t, initial_particles, & |
---|
| 103 | iran_part, log_z_z0, max_number_of_particle_groups, & |
---|
| 104 | maximum_number_of_particles, maximum_number_of_tailpoints, & |
---|
| 105 | minimum_tailpoint_distance, maximum_number_of_tails, & |
---|
| 106 | mpi_particle_type, new_tail_id, number_of_initial_particles, & |
---|
| 107 | number_of_initial_tails, number_of_particles, & |
---|
| 108 | number_of_particle_groups, number_of_sublayers, & |
---|
| 109 | number_of_tails, offset_ocean_nzt, offset_ocean_nzt_m1, part_1,& |
---|
| 110 | part_2, particles, particle_advection_start, particle_groups, & |
---|
| 111 | particle_groups_type, particle_mask, particles_per_point, & |
---|
| 112 | particle_tail_coordinates, particle_type, pdx, pdy, pdz, & |
---|
| 113 | prt_count, prt_start_index, psb, psl, psn, psr, pss, pst, & |
---|
| 114 | radius, random_start_position, read_particles_from_restartfile,& |
---|
| 115 | skip_particles_for_tail, sort_count, tail_mask, & |
---|
| 116 | total_number_of_particles, total_number_of_tails, & |
---|
| 117 | use_particle_tails, use_sgs_for_particles, & |
---|
| 118 | write_particle_statistics, uniform_particles, z0_av_global |
---|
| 119 | |
---|
[1] | 120 | USE pegrid |
---|
| 121 | |
---|
[1320] | 122 | USE random_function_mod, & |
---|
| 123 | ONLY: random_function |
---|
[1] | 124 | |
---|
[1320] | 125 | |
---|
[1] | 126 | IMPLICIT NONE |
---|
| 127 | |
---|
[1320] | 128 | INTEGER(iwp) :: i !: |
---|
| 129 | INTEGER(iwp) :: j !: |
---|
| 130 | INTEGER(iwp) :: k !: |
---|
| 131 | INTEGER(iwp) :: n !: |
---|
| 132 | INTEGER(iwp) :: nn !: |
---|
| 133 | |
---|
[1] | 134 | #if defined( __parallel ) |
---|
[1320] | 135 | INTEGER(iwp), DIMENSION(3) :: blocklengths !: |
---|
| 136 | INTEGER(iwp), DIMENSION(3) :: displacements !: |
---|
| 137 | INTEGER(iwp), DIMENSION(3) :: types !: |
---|
[1] | 138 | #endif |
---|
[1320] | 139 | LOGICAL :: uniform_particles_l !: |
---|
[1] | 140 | |
---|
[1320] | 141 | REAL(wp) :: height_int !: |
---|
| 142 | REAL(wp) :: height_p !: |
---|
| 143 | REAL(wp) :: pos_x !: |
---|
| 144 | REAL(wp) :: pos_y !: |
---|
| 145 | REAL(wp) :: pos_z !: |
---|
| 146 | REAL(wp) :: z_p !: |
---|
| 147 | REAL(wp) :: z0_av_local = 0.0 !: |
---|
[1] | 148 | |
---|
[1320] | 149 | |
---|
| 150 | |
---|
| 151 | |
---|
[1] | 152 | #if defined( __parallel ) |
---|
| 153 | ! |
---|
| 154 | !-- Define MPI derived datatype for FORTRAN datatype particle_type (see module |
---|
[82] | 155 | !-- particle_attributes). Integer length is 4 byte, Real is 8 byte |
---|
| 156 | blocklengths(1) = 19; blocklengths(2) = 4; blocklengths(3) = 1 |
---|
| 157 | displacements(1) = 0; displacements(2) = 152; displacements(3) = 168 |
---|
| 158 | |
---|
[1] | 159 | types(1) = MPI_REAL |
---|
| 160 | types(2) = MPI_INTEGER |
---|
| 161 | types(3) = MPI_UB |
---|
| 162 | CALL MPI_TYPE_STRUCT( 3, blocklengths, displacements, types, & |
---|
| 163 | mpi_particle_type, ierr ) |
---|
| 164 | CALL MPI_TYPE_COMMIT( mpi_particle_type, ierr ) |
---|
| 165 | #endif |
---|
| 166 | |
---|
| 167 | ! |
---|
[150] | 168 | !-- In case of oceans runs, the vertical index calculations need an offset, |
---|
| 169 | !-- because otherwise the k indices will become negative |
---|
| 170 | IF ( ocean ) THEN |
---|
| 171 | offset_ocean_nzt = nzt |
---|
| 172 | offset_ocean_nzt_m1 = nzt - 1 |
---|
| 173 | ENDIF |
---|
| 174 | |
---|
| 175 | |
---|
| 176 | ! |
---|
[1] | 177 | !-- Check the number of particle groups. |
---|
| 178 | IF ( number_of_particle_groups > max_number_of_particle_groups ) THEN |
---|
[274] | 179 | WRITE( message_string, * ) 'max_number_of_particle_groups =', & |
---|
| 180 | max_number_of_particle_groups , & |
---|
[254] | 181 | '&number_of_particle_groups reset to ', & |
---|
| 182 | max_number_of_particle_groups |
---|
[849] | 183 | CALL message( 'lpm_init', 'PA0213', 0, 1, 0, 6, 0 ) |
---|
[1] | 184 | number_of_particle_groups = max_number_of_particle_groups |
---|
| 185 | ENDIF |
---|
| 186 | |
---|
| 187 | ! |
---|
| 188 | !-- Set default start positions, if necessary |
---|
| 189 | IF ( psl(1) == 9999999.9 ) psl(1) = -0.5 * dx |
---|
| 190 | IF ( psr(1) == 9999999.9 ) psr(1) = ( nx + 0.5 ) * dx |
---|
| 191 | IF ( pss(1) == 9999999.9 ) pss(1) = -0.5 * dy |
---|
| 192 | IF ( psn(1) == 9999999.9 ) psn(1) = ( ny + 0.5 ) * dy |
---|
| 193 | IF ( psb(1) == 9999999.9 ) psb(1) = zu(nz/2) |
---|
| 194 | IF ( pst(1) == 9999999.9 ) pst(1) = psb(1) |
---|
| 195 | |
---|
| 196 | IF ( pdx(1) == 9999999.9 .OR. pdx(1) == 0.0 ) pdx(1) = dx |
---|
| 197 | IF ( pdy(1) == 9999999.9 .OR. pdy(1) == 0.0 ) pdy(1) = dy |
---|
| 198 | IF ( pdz(1) == 9999999.9 .OR. pdz(1) == 0.0 ) pdz(1) = zu(2) - zu(1) |
---|
| 199 | |
---|
| 200 | DO j = 2, number_of_particle_groups |
---|
| 201 | IF ( psl(j) == 9999999.9 ) psl(j) = psl(j-1) |
---|
| 202 | IF ( psr(j) == 9999999.9 ) psr(j) = psr(j-1) |
---|
| 203 | IF ( pss(j) == 9999999.9 ) pss(j) = pss(j-1) |
---|
| 204 | IF ( psn(j) == 9999999.9 ) psn(j) = psn(j-1) |
---|
| 205 | IF ( psb(j) == 9999999.9 ) psb(j) = psb(j-1) |
---|
| 206 | IF ( pst(j) == 9999999.9 ) pst(j) = pst(j-1) |
---|
| 207 | IF ( pdx(j) == 9999999.9 .OR. pdx(j) == 0.0 ) pdx(j) = pdx(j-1) |
---|
| 208 | IF ( pdy(j) == 9999999.9 .OR. pdy(j) == 0.0 ) pdy(j) = pdy(j-1) |
---|
| 209 | IF ( pdz(j) == 9999999.9 .OR. pdz(j) == 0.0 ) pdz(j) = pdz(j-1) |
---|
| 210 | ENDDO |
---|
| 211 | |
---|
| 212 | ! |
---|
[849] | 213 | !-- Allocate arrays required for calculating particle SGS velocities |
---|
| 214 | IF ( use_sgs_for_particles ) THEN |
---|
| 215 | ALLOCATE( de_dx(nzb:nzt+1,nysg:nyng,nxlg:nxrg), & |
---|
| 216 | de_dy(nzb:nzt+1,nysg:nyng,nxlg:nxrg), & |
---|
| 217 | de_dz(nzb:nzt+1,nysg:nyng,nxlg:nxrg) ) |
---|
| 218 | ENDIF |
---|
| 219 | |
---|
| 220 | ! |
---|
[1314] | 221 | !-- Allocate array required for logarithmic vertical interpolation of |
---|
| 222 | !-- horizontal particle velocities between the surface and the first vertical |
---|
| 223 | !-- grid level. In order to avoid repeated CPU cost-intensive CALLS of |
---|
| 224 | !-- intrinsic FORTRAN procedure LOG(z/z0), LOG(z/z0) is precalculated for |
---|
| 225 | !-- several heights. Splitting into 20 sublayers turned out to be sufficient. |
---|
| 226 | !-- To obtain exact height levels of particles, linear interpolation is applied |
---|
| 227 | !-- (see lpm_advec.f90). |
---|
| 228 | IF ( prandtl_layer ) THEN |
---|
| 229 | |
---|
| 230 | ALLOCATE ( log_z_z0(0:number_of_sublayers) ) |
---|
| 231 | z_p = zu(nzb+1) - zw(nzb) |
---|
| 232 | |
---|
| 233 | ! |
---|
| 234 | !-- Calculate horizontal mean value of z0 used for logartihmic |
---|
| 235 | !-- interpolation. Note: this is not exact for heterogeneous z0. |
---|
| 236 | !-- However, sensitivity studies showed that the effect is |
---|
| 237 | !-- negligible. |
---|
| 238 | z0_av_local = SUM( z0(nys:nyn,nxl:nxr) ) |
---|
| 239 | z0_av_global = 0.0 |
---|
| 240 | |
---|
[1320] | 241 | #if defined( __parallel ) |
---|
[1314] | 242 | CALL MPI_ALLREDUCE(z0_av_local, z0_av_global, 1, MPI_REAL, MPI_SUM, & |
---|
| 243 | comm2d, ierr ) |
---|
[1320] | 244 | #else |
---|
| 245 | z0_av_global = z0_av_local |
---|
| 246 | #endif |
---|
[1314] | 247 | |
---|
| 248 | z0_av_global = z0_av_global / ( ( ny + 1 ) * ( nx + 1 ) ) |
---|
| 249 | ! |
---|
| 250 | !-- Horizontal wind speed is zero below and at z0 |
---|
| 251 | log_z_z0(0) = 0.0 |
---|
| 252 | ! |
---|
| 253 | !-- Calculate vertical depth of the sublayers |
---|
[1322] | 254 | height_int = ( z_p - z0_av_global ) / REAL( number_of_sublayers, KIND=wp ) |
---|
[1314] | 255 | ! |
---|
| 256 | !-- Precalculate LOG(z/z0) |
---|
| 257 | height_p = 0.0 |
---|
| 258 | DO k = 1, number_of_sublayers |
---|
| 259 | |
---|
| 260 | height_p = height_p + height_int |
---|
| 261 | log_z_z0(k) = LOG( height_p / z0_av_global ) |
---|
| 262 | |
---|
| 263 | ENDDO |
---|
| 264 | |
---|
| 265 | |
---|
| 266 | ENDIF |
---|
| 267 | |
---|
| 268 | ! |
---|
[828] | 269 | !-- Initialize collision kernels |
---|
| 270 | IF ( collision_kernel /= 'none' ) CALL init_kernels |
---|
| 271 | |
---|
| 272 | ! |
---|
[1] | 273 | !-- For the first model run of a possible job chain initialize the |
---|
[849] | 274 | !-- particles, otherwise read the particle data from restart file. |
---|
[1] | 275 | IF ( TRIM( initializing_actions ) == 'read_restart_data' & |
---|
| 276 | .AND. read_particles_from_restartfile ) THEN |
---|
| 277 | |
---|
[849] | 278 | CALL lpm_read_restart_file |
---|
[1] | 279 | |
---|
| 280 | ELSE |
---|
| 281 | |
---|
| 282 | ! |
---|
| 283 | !-- Allocate particle arrays and set attributes of the initial set of |
---|
| 284 | !-- particles, which can be also periodically released at later times. |
---|
| 285 | !-- Also allocate array for particle tail coordinates, if needed. |
---|
[667] | 286 | ALLOCATE( prt_count(nzb:nzt+1,nysg:nyng,nxlg:nxrg), & |
---|
| 287 | prt_start_index(nzb:nzt+1,nysg:nyng,nxlg:nxrg), & |
---|
[792] | 288 | particle_mask(maximum_number_of_particles), & |
---|
| 289 | part_1(maximum_number_of_particles), & |
---|
| 290 | part_2(maximum_number_of_particles) ) |
---|
[1] | 291 | |
---|
[792] | 292 | particles => part_1 |
---|
| 293 | |
---|
| 294 | sort_count = 0 |
---|
| 295 | |
---|
[1] | 296 | ! |
---|
| 297 | !-- Initialize all particles with dummy values (otherwise errors may |
---|
| 298 | !-- occur within restart runs). The reason for this is still not clear |
---|
| 299 | !-- and may be presumably caused by errors in the respective user-interface. |
---|
| 300 | particles = particle_type( 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, & |
---|
| 301 | 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, & |
---|
[57] | 302 | 0.0, 0, 0, 0, 0 ) |
---|
[1] | 303 | particle_groups = particle_groups_type( 0.0, 0.0, 0.0, 0.0 ) |
---|
| 304 | |
---|
| 305 | ! |
---|
| 306 | !-- Set the default particle size used for dvrp plots |
---|
| 307 | IF ( dvrp_psize == 9999999.9 ) dvrp_psize = 0.2 * dx |
---|
| 308 | |
---|
| 309 | ! |
---|
| 310 | !-- Set values for the density ratio and radius for all particle |
---|
| 311 | !-- groups, if necessary |
---|
| 312 | IF ( density_ratio(1) == 9999999.9 ) density_ratio(1) = 0.0 |
---|
| 313 | IF ( radius(1) == 9999999.9 ) radius(1) = 0.0 |
---|
| 314 | DO i = 2, number_of_particle_groups |
---|
| 315 | IF ( density_ratio(i) == 9999999.9 ) THEN |
---|
| 316 | density_ratio(i) = density_ratio(i-1) |
---|
| 317 | ENDIF |
---|
| 318 | IF ( radius(i) == 9999999.9 ) radius(i) = radius(i-1) |
---|
| 319 | ENDDO |
---|
| 320 | |
---|
| 321 | DO i = 1, number_of_particle_groups |
---|
| 322 | IF ( density_ratio(i) /= 0.0 .AND. radius(i) == 0 ) THEN |
---|
[254] | 323 | WRITE( message_string, * ) 'particle group #', i, 'has a', & |
---|
| 324 | 'density ratio /= 0 but radius = 0' |
---|
[849] | 325 | CALL message( 'lpm_init', 'PA0215', 1, 2, 0, 6, 0 ) |
---|
[1] | 326 | ENDIF |
---|
| 327 | particle_groups(i)%density_ratio = density_ratio(i) |
---|
| 328 | particle_groups(i)%radius = radius(i) |
---|
| 329 | ENDDO |
---|
| 330 | |
---|
| 331 | ! |
---|
| 332 | !-- Calculate particle positions and store particle attributes, if |
---|
| 333 | !-- particle is situated on this PE |
---|
| 334 | n = 0 |
---|
| 335 | |
---|
| 336 | DO i = 1, number_of_particle_groups |
---|
| 337 | |
---|
| 338 | pos_z = psb(i) |
---|
| 339 | |
---|
| 340 | DO WHILE ( pos_z <= pst(i) ) |
---|
| 341 | |
---|
| 342 | pos_y = pss(i) |
---|
| 343 | |
---|
| 344 | DO WHILE ( pos_y <= psn(i) ) |
---|
| 345 | |
---|
| 346 | IF ( pos_y >= ( nys - 0.5 ) * dy .AND. & |
---|
| 347 | pos_y < ( nyn + 0.5 ) * dy ) THEN |
---|
| 348 | |
---|
| 349 | pos_x = psl(i) |
---|
| 350 | |
---|
| 351 | DO WHILE ( pos_x <= psr(i) ) |
---|
| 352 | |
---|
| 353 | IF ( pos_x >= ( nxl - 0.5 ) * dx .AND. & |
---|
| 354 | pos_x < ( nxr + 0.5 ) * dx ) THEN |
---|
| 355 | |
---|
| 356 | DO j = 1, particles_per_point |
---|
| 357 | |
---|
| 358 | n = n + 1 |
---|
| 359 | IF ( n > maximum_number_of_particles ) THEN |
---|
[254] | 360 | WRITE( message_string, * ) 'number of initial', & |
---|
[274] | 361 | 'particles (', n, ') exceeds', & |
---|
| 362 | '&maximum_number_of_particles (', & |
---|
| 363 | maximum_number_of_particles, ') on PE ', & |
---|
[254] | 364 | myid |
---|
[849] | 365 | CALL message( 'lpm_init', 'PA0216', 2, 2, -1, 6,& |
---|
| 366 | 1 ) |
---|
[1] | 367 | ENDIF |
---|
| 368 | particles(n)%x = pos_x |
---|
| 369 | particles(n)%y = pos_y |
---|
| 370 | particles(n)%z = pos_z |
---|
| 371 | particles(n)%age = 0.0 |
---|
[57] | 372 | particles(n)%age_m = 0.0 |
---|
[1] | 373 | particles(n)%dt_sum = 0.0 |
---|
| 374 | particles(n)%dvrp_psize = dvrp_psize |
---|
| 375 | particles(n)%e_m = 0.0 |
---|
[824] | 376 | IF ( curvature_solution_effects ) THEN |
---|
| 377 | ! |
---|
| 378 | !-- Initial values (internal timesteps, derivative) |
---|
| 379 | !-- for Rosenbrock method |
---|
| 380 | particles(n)%rvar1 = 1.0E-12 |
---|
| 381 | particles(n)%rvar2 = 1.0E-3 |
---|
| 382 | particles(n)%rvar3 = -9999999.9 |
---|
| 383 | ELSE |
---|
| 384 | ! |
---|
| 385 | !-- Initial values for SGS velocities |
---|
| 386 | particles(n)%rvar1 = 0.0 |
---|
| 387 | particles(n)%rvar2 = 0.0 |
---|
| 388 | particles(n)%rvar3 = 0.0 |
---|
| 389 | ENDIF |
---|
[1] | 390 | particles(n)%speed_x = 0.0 |
---|
| 391 | particles(n)%speed_y = 0.0 |
---|
| 392 | particles(n)%speed_z = 0.0 |
---|
| 393 | particles(n)%origin_x = pos_x |
---|
| 394 | particles(n)%origin_y = pos_y |
---|
| 395 | particles(n)%origin_z = pos_z |
---|
| 396 | particles(n)%radius = particle_groups(i)%radius |
---|
| 397 | particles(n)%weight_factor =initial_weighting_factor |
---|
[828] | 398 | particles(n)%class = 1 |
---|
[1] | 399 | particles(n)%group = i |
---|
| 400 | particles(n)%tailpoints = 0 |
---|
| 401 | IF ( use_particle_tails .AND. & |
---|
| 402 | MOD( n, skip_particles_for_tail ) == 0 ) THEN |
---|
| 403 | number_of_tails = number_of_tails + 1 |
---|
| 404 | ! |
---|
| 405 | !-- This is a temporary provisional setting (see |
---|
| 406 | !-- further below!) |
---|
| 407 | particles(n)%tail_id = number_of_tails |
---|
| 408 | ELSE |
---|
| 409 | particles(n)%tail_id = 0 |
---|
| 410 | ENDIF |
---|
| 411 | |
---|
| 412 | ENDDO |
---|
| 413 | |
---|
| 414 | ENDIF |
---|
| 415 | |
---|
| 416 | pos_x = pos_x + pdx(i) |
---|
| 417 | |
---|
| 418 | ENDDO |
---|
| 419 | |
---|
| 420 | ENDIF |
---|
| 421 | |
---|
| 422 | pos_y = pos_y + pdy(i) |
---|
| 423 | |
---|
| 424 | ENDDO |
---|
| 425 | |
---|
| 426 | pos_z = pos_z + pdz(i) |
---|
| 427 | |
---|
| 428 | ENDDO |
---|
| 429 | |
---|
| 430 | ENDDO |
---|
| 431 | |
---|
| 432 | number_of_initial_particles = n |
---|
| 433 | number_of_particles = n |
---|
| 434 | |
---|
| 435 | ! |
---|
| 436 | !-- Calculate the number of particles and tails of the total domain |
---|
| 437 | #if defined( __parallel ) |
---|
[622] | 438 | IF ( collective_wait ) CALL MPI_BARRIER( comm2d, ierr ) |
---|
[1] | 439 | CALL MPI_ALLREDUCE( number_of_particles, total_number_of_particles, 1, & |
---|
[16] | 440 | MPI_INTEGER, MPI_SUM, comm2d, ierr ) |
---|
[622] | 441 | IF ( collective_wait ) CALL MPI_BARRIER( comm2d, ierr ) |
---|
[1] | 442 | CALL MPI_ALLREDUCE( number_of_tails, total_number_of_tails, 1, & |
---|
[16] | 443 | MPI_INTEGER, MPI_SUM, comm2d, ierr ) |
---|
[1] | 444 | #else |
---|
| 445 | total_number_of_particles = number_of_particles |
---|
| 446 | total_number_of_tails = number_of_tails |
---|
| 447 | #endif |
---|
| 448 | |
---|
| 449 | ! |
---|
| 450 | !-- Set a seed value for the random number generator to be exclusively |
---|
| 451 | !-- used for the particle code. The generated random numbers should be |
---|
| 452 | !-- different on the different PEs. |
---|
| 453 | iran_part = iran_part + myid |
---|
| 454 | |
---|
| 455 | ! |
---|
| 456 | !-- User modification of initial particles |
---|
[849] | 457 | CALL user_lpm_init |
---|
[1] | 458 | |
---|
| 459 | ! |
---|
| 460 | !-- Store the initial set of particles for release at later times |
---|
| 461 | IF ( number_of_initial_particles /= 0 ) THEN |
---|
| 462 | ALLOCATE( initial_particles(1:number_of_initial_particles) ) |
---|
| 463 | initial_particles(1:number_of_initial_particles) = & |
---|
| 464 | particles(1:number_of_initial_particles) |
---|
| 465 | ENDIF |
---|
| 466 | |
---|
| 467 | ! |
---|
| 468 | !-- Add random fluctuation to particle positions |
---|
| 469 | IF ( random_start_position ) THEN |
---|
| 470 | |
---|
| 471 | DO n = 1, number_of_initial_particles |
---|
| 472 | IF ( psl(particles(n)%group) /= psr(particles(n)%group) ) THEN |
---|
| 473 | particles(n)%x = particles(n)%x + & |
---|
[106] | 474 | ( random_function( iran_part ) - 0.5 ) * & |
---|
[1] | 475 | pdx(particles(n)%group) |
---|
| 476 | IF ( particles(n)%x <= ( nxl - 0.5 ) * dx ) THEN |
---|
| 477 | particles(n)%x = ( nxl - 0.4999999999 ) * dx |
---|
| 478 | ELSEIF ( particles(n)%x >= ( nxr + 0.5 ) * dx ) THEN |
---|
| 479 | particles(n)%x = ( nxr + 0.4999999999 ) * dx |
---|
| 480 | ENDIF |
---|
| 481 | ENDIF |
---|
| 482 | IF ( pss(particles(n)%group) /= psn(particles(n)%group) ) THEN |
---|
| 483 | particles(n)%y = particles(n)%y + & |
---|
[106] | 484 | ( random_function( iran_part ) - 0.5 ) * & |
---|
[1] | 485 | pdy(particles(n)%group) |
---|
| 486 | IF ( particles(n)%y <= ( nys - 0.5 ) * dy ) THEN |
---|
| 487 | particles(n)%y = ( nys - 0.4999999999 ) * dy |
---|
| 488 | ELSEIF ( particles(n)%y >= ( nyn + 0.5 ) * dy ) THEN |
---|
| 489 | particles(n)%y = ( nyn + 0.4999999999 ) * dy |
---|
| 490 | ENDIF |
---|
| 491 | ENDIF |
---|
| 492 | IF ( psb(particles(n)%group) /= pst(particles(n)%group) ) THEN |
---|
| 493 | particles(n)%z = particles(n)%z + & |
---|
[106] | 494 | ( random_function( iran_part ) - 0.5 ) * & |
---|
[1] | 495 | pdz(particles(n)%group) |
---|
| 496 | ENDIF |
---|
| 497 | ENDDO |
---|
| 498 | ENDIF |
---|
| 499 | |
---|
| 500 | ! |
---|
[117] | 501 | !-- Sort particles in the sequence the gridboxes are stored in the memory. |
---|
| 502 | !-- Only required if cloud droplets are used. |
---|
[849] | 503 | IF ( cloud_droplets ) CALL lpm_sort_arrays |
---|
[1] | 504 | |
---|
| 505 | ! |
---|
| 506 | !-- Open file for statistical informations about particle conditions |
---|
| 507 | IF ( write_particle_statistics ) THEN |
---|
| 508 | CALL check_open( 80 ) |
---|
| 509 | WRITE ( 80, 8000 ) current_timestep_number, simulated_time, & |
---|
| 510 | number_of_initial_particles, & |
---|
| 511 | maximum_number_of_particles |
---|
| 512 | CALL close_file( 80 ) |
---|
| 513 | ENDIF |
---|
| 514 | |
---|
| 515 | ! |
---|
| 516 | !-- Check if particles are really uniform in color and radius (dvrp_size) |
---|
| 517 | !-- (uniform_particles is preset TRUE) |
---|
| 518 | IF ( uniform_particles ) THEN |
---|
| 519 | IF ( number_of_initial_particles == 0 ) THEN |
---|
| 520 | uniform_particles_l = .TRUE. |
---|
| 521 | ELSE |
---|
| 522 | n = number_of_initial_particles |
---|
| 523 | IF ( MINVAL( particles(1:n)%dvrp_psize ) == & |
---|
| 524 | MAXVAL( particles(1:n)%dvrp_psize ) .AND. & |
---|
[828] | 525 | MINVAL( particles(1:n)%class ) == & |
---|
| 526 | MAXVAL( particles(1:n)%class ) ) THEN |
---|
[1] | 527 | uniform_particles_l = .TRUE. |
---|
| 528 | ELSE |
---|
| 529 | uniform_particles_l = .FALSE. |
---|
| 530 | ENDIF |
---|
| 531 | ENDIF |
---|
| 532 | |
---|
| 533 | #if defined( __parallel ) |
---|
[622] | 534 | IF ( collective_wait ) CALL MPI_BARRIER( comm2d, ierr ) |
---|
[1] | 535 | CALL MPI_ALLREDUCE( uniform_particles_l, uniform_particles, 1, & |
---|
| 536 | MPI_LOGICAL, MPI_LAND, comm2d, ierr ) |
---|
| 537 | #else |
---|
| 538 | uniform_particles = uniform_particles_l |
---|
| 539 | #endif |
---|
| 540 | |
---|
| 541 | ENDIF |
---|
| 542 | |
---|
| 543 | ! |
---|
[336] | 544 | !-- Particles will probably become none-uniform, if their size and color |
---|
| 545 | !-- will be determined by flow variables |
---|
| 546 | IF ( particle_color /= 'none' .OR. particle_dvrpsize /= 'none' ) THEN |
---|
| 547 | uniform_particles = .FALSE. |
---|
| 548 | ENDIF |
---|
| 549 | |
---|
| 550 | ! |
---|
[1] | 551 | !-- Set the beginning of the particle tails and their age |
---|
| 552 | IF ( use_particle_tails ) THEN |
---|
| 553 | ! |
---|
[276] | 554 | !-- Choose the maximum number of tails with respect to the maximum number |
---|
| 555 | !-- of particles and skip_particles_for_tail |
---|
| 556 | maximum_number_of_tails = maximum_number_of_particles / & |
---|
| 557 | skip_particles_for_tail |
---|
| 558 | |
---|
[229] | 559 | ! |
---|
| 560 | !-- Create a minimum number of tails in case that there is no tail |
---|
| 561 | !-- initially (otherwise, index errors will occur when adressing the |
---|
| 562 | !-- arrays below) |
---|
| 563 | IF ( maximum_number_of_tails == 0 ) maximum_number_of_tails = 10 |
---|
[1] | 564 | |
---|
| 565 | ALLOCATE( particle_tail_coordinates(maximum_number_of_tailpoints,5, & |
---|
| 566 | maximum_number_of_tails), & |
---|
| 567 | new_tail_id(maximum_number_of_tails), & |
---|
| 568 | tail_mask(maximum_number_of_tails) ) |
---|
| 569 | |
---|
| 570 | particle_tail_coordinates = 0.0 |
---|
| 571 | minimum_tailpoint_distance = minimum_tailpoint_distance**2 |
---|
| 572 | number_of_initial_tails = number_of_tails |
---|
| 573 | |
---|
| 574 | nn = 0 |
---|
| 575 | DO n = 1, number_of_particles |
---|
| 576 | ! |
---|
| 577 | !-- Only for those particles marked above with a provisional tail_id |
---|
| 578 | !-- tails will be created. Particles now get their final tail_id. |
---|
| 579 | IF ( particles(n)%tail_id /= 0 ) THEN |
---|
| 580 | |
---|
| 581 | nn = nn + 1 |
---|
| 582 | particles(n)%tail_id = nn |
---|
| 583 | |
---|
| 584 | particle_tail_coordinates(1,1,nn) = particles(n)%x |
---|
| 585 | particle_tail_coordinates(1,2,nn) = particles(n)%y |
---|
| 586 | particle_tail_coordinates(1,3,nn) = particles(n)%z |
---|
[828] | 587 | particle_tail_coordinates(1,4,nn) = particles(n)%class |
---|
[1] | 588 | particles(n)%tailpoints = 1 |
---|
| 589 | IF ( minimum_tailpoint_distance /= 0.0 ) THEN |
---|
| 590 | particle_tail_coordinates(2,1,nn) = particles(n)%x |
---|
| 591 | particle_tail_coordinates(2,2,nn) = particles(n)%y |
---|
| 592 | particle_tail_coordinates(2,3,nn) = particles(n)%z |
---|
[828] | 593 | particle_tail_coordinates(2,4,nn) = particles(n)%class |
---|
[1] | 594 | particle_tail_coordinates(1:2,5,nn) = 0.0 |
---|
| 595 | particles(n)%tailpoints = 2 |
---|
| 596 | ENDIF |
---|
| 597 | |
---|
| 598 | ENDIF |
---|
| 599 | ENDDO |
---|
| 600 | ENDIF |
---|
| 601 | |
---|
| 602 | ! |
---|
| 603 | !-- Plot initial positions of particles (only if particle advection is |
---|
| 604 | !-- switched on from the beginning of the simulation (t=0)) |
---|
| 605 | IF ( particle_advection_start == 0.0 ) CALL data_output_dvrp |
---|
| 606 | |
---|
| 607 | ENDIF |
---|
| 608 | |
---|
| 609 | ! |
---|
| 610 | !-- Check boundary condition and set internal variables |
---|
| 611 | SELECT CASE ( bc_par_b ) |
---|
| 612 | |
---|
| 613 | CASE ( 'absorb' ) |
---|
| 614 | ibc_par_b = 1 |
---|
| 615 | |
---|
| 616 | CASE ( 'reflect' ) |
---|
| 617 | ibc_par_b = 2 |
---|
| 618 | |
---|
| 619 | CASE DEFAULT |
---|
[254] | 620 | WRITE( message_string, * ) 'unknown boundary condition ', & |
---|
| 621 | 'bc_par_b = "', TRIM( bc_par_b ), '"' |
---|
[849] | 622 | CALL message( 'lpm_init', 'PA0217', 1, 2, 0, 6, 0 ) |
---|
[1] | 623 | |
---|
| 624 | END SELECT |
---|
| 625 | SELECT CASE ( bc_par_t ) |
---|
| 626 | |
---|
| 627 | CASE ( 'absorb' ) |
---|
| 628 | ibc_par_t = 1 |
---|
| 629 | |
---|
| 630 | CASE ( 'reflect' ) |
---|
| 631 | ibc_par_t = 2 |
---|
| 632 | |
---|
| 633 | CASE DEFAULT |
---|
[254] | 634 | WRITE( message_string, * ) 'unknown boundary condition ', & |
---|
| 635 | 'bc_par_t = "', TRIM( bc_par_t ), '"' |
---|
[849] | 636 | CALL message( 'lpm_init', 'PA0218', 1, 2, 0, 6, 0 ) |
---|
[1] | 637 | |
---|
| 638 | END SELECT |
---|
| 639 | SELECT CASE ( bc_par_lr ) |
---|
| 640 | |
---|
| 641 | CASE ( 'cyclic' ) |
---|
| 642 | ibc_par_lr = 0 |
---|
| 643 | |
---|
| 644 | CASE ( 'absorb' ) |
---|
| 645 | ibc_par_lr = 1 |
---|
| 646 | |
---|
| 647 | CASE ( 'reflect' ) |
---|
| 648 | ibc_par_lr = 2 |
---|
| 649 | |
---|
| 650 | CASE DEFAULT |
---|
[254] | 651 | WRITE( message_string, * ) 'unknown boundary condition ', & |
---|
| 652 | 'bc_par_lr = "', TRIM( bc_par_lr ), '"' |
---|
[849] | 653 | CALL message( 'lpm_init', 'PA0219', 1, 2, 0, 6, 0 ) |
---|
[1] | 654 | |
---|
| 655 | END SELECT |
---|
| 656 | SELECT CASE ( bc_par_ns ) |
---|
| 657 | |
---|
| 658 | CASE ( 'cyclic' ) |
---|
| 659 | ibc_par_ns = 0 |
---|
| 660 | |
---|
| 661 | CASE ( 'absorb' ) |
---|
| 662 | ibc_par_ns = 1 |
---|
| 663 | |
---|
| 664 | CASE ( 'reflect' ) |
---|
| 665 | ibc_par_ns = 2 |
---|
| 666 | |
---|
| 667 | CASE DEFAULT |
---|
[254] | 668 | WRITE( message_string, * ) 'unknown boundary condition ', & |
---|
| 669 | 'bc_par_ns = "', TRIM( bc_par_ns ), '"' |
---|
[849] | 670 | CALL message( 'lpm_init', 'PA0220', 1, 2, 0, 6, 0 ) |
---|
[1] | 671 | |
---|
| 672 | END SELECT |
---|
| 673 | ! |
---|
| 674 | !-- Formats |
---|
| 675 | 8000 FORMAT (I6,1X,F7.2,4X,I6,71X,I6) |
---|
| 676 | |
---|
[849] | 677 | END SUBROUTINE lpm_init |
---|