source: palm/trunk/SOURCE/lpm_boundary_conds.f90 @ 3183

Last change on this file since 3183 was 3067, checked in by suehring, 6 years ago

Remove write statements

  • Property svn:keywords set to Id
File size: 27.1 KB
RevLine 
[1682]1!> @file lpm_boundary_conds.f90
[2000]2!------------------------------------------------------------------------------!
[2696]3! This file is part of the PALM model system.
[1036]4!
[2000]5! PALM is free software: you can redistribute it and/or modify it under the
6! terms of the GNU General Public License as published by the Free Software
7! Foundation, either version 3 of the License, or (at your option) any later
8! version.
[1036]9!
10! PALM is distributed in the hope that it will be useful, but WITHOUT ANY
11! WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12! A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
13!
14! You should have received a copy of the GNU General Public License along with
15! PALM. If not, see <http://www.gnu.org/licenses/>.
16!
[2718]17! Copyright 1997-2018 Leibniz Universitaet Hannover
[2000]18!------------------------------------------------------------------------------!
[1036]19!
[484]20! Current revisions:
[58]21! -----------------
[2701]22!
23!
24! Former revisions:
25! -----------------
26! $Id: lpm_boundary_conds.f90 3067 2018-06-12 14:04:34Z suehring $
[3067]27! Remove write statements
28!
29! 2801 2018-02-14 16:01:55Z thiele
[2801]30! Introduce particle transfer in nested models.
31!
32! 2718 2018-01-02 08:49:38Z maronga
[2716]33! Corrected "Former revisions" section
34!
35! 2701 2017-12-15 15:40:50Z suehring
36! Changes from last commit documented
37!
38! 2698 2017-12-14 18:46:24Z suehring
[2698]39! Particle reflections at downward-facing walls implemented. Moreover,
40! reflections are adjusted to revised particle grid box location.
[2716]41! (responsible Philipp Thiele)
42!
43! 2696 2017-12-14 17:12:51Z kanani
44! Change in file header (GPL part)
45!
46! 2606 2017-11-10 10:36:31Z schwenkel
[2606]47! Changed particle box locations: center of particle box now coincides
48! with scalar grid point of same index.
49! Renamed module and subroutines: lpm_pack_arrays_mod -> lpm_pack_and_sort_mod
50! lpm_pack_all_arrays -> lpm_sort_in_subboxes, lpm_pack_arrays -> lpm_pack
51! lpm_sort -> lpm_sort_timeloop_done
52!
53! 2318 2017-07-20 17:27:44Z suehring
[2318]54! Get topography top index via Function call
55!
56! 2317 2017-07-20 17:27:19Z suehring
[1321]57!
[2233]58! 2232 2017-05-30 17:47:52Z suehring
59! Adjustments to new topography and surface concept
60! Rename character range into location, as range is an intrinsic.
61!
[2001]62! 2000 2016-08-20 18:09:15Z knoop
63! Forced header and separation lines into 80 columns
64!
[1930]65! 1929 2016-06-09 16:25:25Z suehring
66! Rewritten wall reflection
67!
[1823]68! 1822 2016-04-07 07:49:42Z hoffmann
69! Tails removed. Unused variables removed.
70!
[1683]71! 1682 2015-10-07 23:56:08Z knoop
72! Code annotations made doxygen readable
73!
[1360]74! 1359 2014-04-11 17:15:14Z hoffmann
75! New particle structure integrated.
76! Kind definition added to all floating point numbers.
77!
[1321]78! 1320 2014-03-20 08:40:49Z raasch
[1320]79! ONLY-attribute added to USE-statements,
80! kind-parameters added to all INTEGER and REAL declaration statements,
81! kinds are defined in new module kinds,
82! revision history before 2012 removed,
83! comment fields (!:) to be used for variable explanations added to
84! all variable declaration statements
[58]85!
[1037]86! 1036 2012-10-22 13:43:42Z raasch
87! code put under GPL (PALM 3.9)
88!
[850]89! 849 2012-03-15 10:35:09Z raasch
90! routine renamed lpm_boundary_conds, bottom and top boundary conditions
91! included (former part of advec_particles)
92!
[826]93! 824 2012-02-17 09:09:57Z raasch
94! particle attributes speed_x|y|z_sgs renamed rvar1|2|3
95!
[58]96! Initial version (2007/03/09)
97!
98! Description:
99! ------------
[1682]100!> Boundary conditions for the Lagrangian particles.
101!> The routine consists of two different parts. One handles the bottom (flat)
102!> and top boundary. In this part, also particles which exceeded their lifetime
103!> are deleted.
104!> The other part handles the reflection of particles from vertical walls.
105!> This part was developed by Jin Zhang during 2006-2007.
106!>
107!> To do: Code structure for finding the t_index values and for checking the
108!> -----  reflection conditions is basically the same for all four cases, so it
109!>        should be possible to further simplify/shorten it.
110!>
111!> THE WALLS PART OF THIS ROUTINE HAS NOT BEEN TESTED FOR OCEAN RUNS SO FAR!!!!
112!> (see offset_ocean_*)
[58]113!------------------------------------------------------------------------------!
[2698]114 SUBROUTINE lpm_boundary_conds( location , i, j, k )
[1682]115 
[58]116
[1320]117    USE arrays_3d,                                                             &
118        ONLY:  zu, zw
[58]119
[1320]120    USE control_parameters,                                                    &
[1822]121        ONLY:  dz, message_string, particle_maximum_age
[58]122
[1320]123    USE cpulog,                                                                &
124        ONLY:  cpu_log, log_point_s
[849]125
[1320]126    USE grid_variables,                                                        &
127        ONLY:  ddx, dx, ddy, dy
[58]128
[1320]129    USE indices,                                                               &
[2698]130        ONLY:  nxl, nxr, nyn, nys, nz, nzb, wall_flags_0,nyng,nysg
[61]131
[1320]132    USE kinds
[58]133
[1320]134    USE particle_attributes,                                                   &
[1822]135        ONLY:  deleted_particles, ibc_par_b, ibc_par_t, number_of_particles,   &
136               particles, particle_type, offset_ocean_nzt_m1,                  &
137               use_sgs_for_particles
[60]138
[1320]139    USE pegrid
[58]140
[1320]141    IMPLICIT NONE
[58]142
[2232]143    CHARACTER (LEN=*) ::  location     !<
[1320]144   
[2698]145    INTEGER(iwp), INTENT(IN) ::  i !<
146    INTEGER(iwp), INTENT(IN) ::  j !<
147    INTEGER(iwp), INTENT(IN) ::  k !<
148   
[1929]149    INTEGER(iwp) ::  inc            !< dummy for sorting algorithmus
150    INTEGER(iwp) ::  ir             !< dummy for sorting algorithmus
151    INTEGER(iwp) ::  i1             !< grid index (x) of old particle position
152    INTEGER(iwp) ::  i2             !< grid index (x) of current particle position
153    INTEGER(iwp) ::  i3             !< grid index (x) of intermediate particle position
154    INTEGER(iwp) ::  jr             !< dummy for sorting algorithmus
155    INTEGER(iwp) ::  j1             !< grid index (y) of old particle position
[2698]156    INTEGER(iwp) ::  j2             !< grid index (y) of current particle position
157    INTEGER(iwp) ::  j3             !< grid index (y) of intermediate particle position
158    INTEGER(iwp) ::  k1             !< grid index (z) of old particle position
159    INTEGER(iwp) ::  k2             !< grid index (z) of current particle position
160    INTEGER(iwp) ::  k3             !< grid index (z) of intermediate particle position
[1929]161    INTEGER(iwp) ::  n              !< particle number
162    INTEGER(iwp) ::  t_index        !< running index for intermediate particle timesteps in reflection algorithmus
163    INTEGER(iwp) ::  t_index_number !< number of intermediate particle timesteps in reflection algorithmus
[2698]164    INTEGER(iwp) ::  tmp_x          !< dummy for sorting algorithm
165    INTEGER(iwp) ::  tmp_y          !< dummy for sorting algorithm
166    INTEGER(iwp) ::  tmp_z          !< dummy for sorting algorithm
[1929]167
168    INTEGER(iwp), DIMENSION(0:10) :: x_ind(0:10) = 0 !< index array (x) of intermediate particle positions
[2698]169    INTEGER(iwp), DIMENSION(0:10) :: y_ind(0:10) = 0 !< index array (y) of intermediate particle positions
170    INTEGER(iwp), DIMENSION(0:10) :: z_ind(0:10) = 0 !< index array (z) of intermediate particle positions
[1320]171   
[1929]172    LOGICAL  ::  cross_wall_x    !< flag to check if particle reflection along x is necessary
173    LOGICAL  ::  cross_wall_y    !< flag to check if particle reflection along y is necessary
[2698]174    LOGICAL  ::  cross_wall_z    !< flag to check if particle reflection along z is necessary
[1929]175    LOGICAL  ::  reflect_x       !< flag to check if particle is already reflected along x
176    LOGICAL  ::  reflect_y       !< flag to check if particle is already reflected along y
177    LOGICAL  ::  reflect_z       !< flag to check if particle is already reflected along z
178    LOGICAL  ::  tmp_reach_x     !< dummy for sorting algorithmus
179    LOGICAL  ::  tmp_reach_y     !< dummy for sorting algorithmus
180    LOGICAL  ::  tmp_reach_z     !< dummy for sorting algorithmus
181    LOGICAL  ::  x_wall_reached  !< flag to check if particle has already reached wall
182    LOGICAL  ::  y_wall_reached  !< flag to check if particle has already reached wall
[2698]183    LOGICAL  ::  z_wall_reached  !< flag to check if particle has already reached wall
[1320]184
[1929]185    LOGICAL, DIMENSION(0:10) ::  reach_x  !< flag to check if particle is at a yz-wall
186    LOGICAL, DIMENSION(0:10) ::  reach_y  !< flag to check if particle is at a xz-wall
187    LOGICAL, DIMENSION(0:10) ::  reach_z  !< flag to check if particle is at a xy-wall
[1320]188
[1929]189    REAL(wp) ::  dt_particle    !< particle timestep
190    REAL(wp) ::  dum            !< dummy argument
191    REAL(wp) ::  eps = 1E-10_wp !< security number to check if particle has reached a wall
192    REAL(wp) ::  pos_x          !< intermediate particle position (x)
193    REAL(wp) ::  pos_x_old      !< particle position (x) at previous particle timestep
194    REAL(wp) ::  pos_y          !< intermediate particle position (y)
195    REAL(wp) ::  pos_y_old      !< particle position (y) at previous particle timestep
196    REAL(wp) ::  pos_z          !< intermediate particle position (z)
197    REAL(wp) ::  pos_z_old      !< particle position (z) at previous particle timestep
198    REAL(wp) ::  prt_x          !< current particle position (x)
199    REAL(wp) ::  prt_y          !< current particle position (y)
200    REAL(wp) ::  prt_z          !< current particle position (z)
201    REAL(wp) ::  t_old          !< previous reflection time
202    REAL(wp) ::  tmp_t          !< dummy for sorting algorithmus
203    REAL(wp) ::  xwall          !< location of wall in x
204    REAL(wp) ::  ywall          !< location of wall in y
[2698]205    REAL(wp) ::  zwall          !< location of wall in z
[1929]206
207    REAL(wp), DIMENSION(0:10) ::  t  !< reflection time
208
209
[2232]210    IF ( location == 'bottom/top' )  THEN
[58]211
[849]212!
213!--    Apply boundary conditions to those particles that have crossed the top or
214!--    bottom boundary and delete those particles, which are older than allowed
215       DO  n = 1, number_of_particles
[61]216
[849]217!
218!--       Stop if particles have moved further than the length of one
219!--       PE subdomain (newly released particles have age = age_m!)
220          IF ( particles(n)%age /= particles(n)%age_m )  THEN
221             IF ( ABS(particles(n)%speed_x) >                                  &
222                  ((nxr-nxl+2)*dx)/(particles(n)%age-particles(n)%age_m)  .OR. &
223                  ABS(particles(n)%speed_y) >                                  &
224                  ((nyn-nys+2)*dy)/(particles(n)%age-particles(n)%age_m) )  THEN
[60]225
[849]226                  WRITE( message_string, * )  'particle too fast.  n = ',  n 
227                  CALL message( 'lpm_boundary_conds', 'PA0148', 2, 2, -1, 6, 1 )
228             ENDIF
229          ENDIF
[58]230
[849]231          IF ( particles(n)%age > particle_maximum_age  .AND.  &
[1359]232               particles(n)%particle_mask )                              &
[849]233          THEN
[1359]234             particles(n)%particle_mask  = .FALSE.
[849]235             deleted_particles = deleted_particles + 1
236          ENDIF
[58]237
[2801]238          IF ( particles(n)%z >= zw(nz)  .AND.  particles(n)%particle_mask )  THEN
[849]239             IF ( ibc_par_t == 1 )  THEN
[61]240!
[849]241!--             Particle absorption
[1359]242                particles(n)%particle_mask  = .FALSE.
[849]243                deleted_particles = deleted_particles + 1
244             ELSEIF ( ibc_par_t == 2 )  THEN
245!
246!--             Particle reflection
[2801]247                particles(n)%z       = 2.0_wp * zw(nz) - particles(n)%z
[849]248                particles(n)%speed_z = -particles(n)%speed_z
249                IF ( use_sgs_for_particles  .AND. &
[1359]250                     particles(n)%rvar3 > 0.0_wp )  THEN
[849]251                   particles(n)%rvar3 = -particles(n)%rvar3
252                ENDIF
253             ENDIF
254          ENDIF
[1359]255         
256          IF ( particles(n)%z < zw(0)  .AND.  particles(n)%particle_mask )  THEN
[849]257             IF ( ibc_par_b == 1 )  THEN
258!
259!--             Particle absorption
[1359]260                particles(n)%particle_mask  = .FALSE.
[849]261                deleted_particles = deleted_particles + 1
262             ELSEIF ( ibc_par_b == 2 )  THEN
263!
264!--             Particle reflection
[1359]265                particles(n)%z       = 2.0_wp * zw(0) - particles(n)%z
[849]266                particles(n)%speed_z = -particles(n)%speed_z
267                IF ( use_sgs_for_particles  .AND. &
[1359]268                     particles(n)%rvar3 < 0.0_wp )  THEN
[849]269                   particles(n)%rvar3 = -particles(n)%rvar3
270                ENDIF
271             ENDIF
272          ENDIF
273       ENDDO
[58]274
[2232]275    ELSEIF ( location == 'walls' )  THEN
[58]276
[1929]277
[849]278       CALL cpu_log( log_point_s(48), 'lpm_wall_reflect', 'start' )
279
280       DO  n = 1, number_of_particles
[1929]281!
282!--       Recalculate particle timestep
[849]283          dt_particle = particles(n)%age - particles(n)%age_m
[1929]284!
285!--       Obtain x/y indices for current particle position
[2606]286          i2 = particles(n)%x * ddx
287          j2 = particles(n)%y * ddy
[2698]288          IF (zw(k)   < particles(n)%z ) k2 = k + 1
289          IF (zw(k-1) > particles(n)%z ) k2 = k - 1 
[1929]290!
291!--       Save current particle positions
[849]292          prt_x = particles(n)%x
293          prt_y = particles(n)%y
294          prt_z = particles(n)%z
[58]295!
[1929]296!--       Recalculate old particle positions
297          pos_x_old = particles(n)%x - particles(n)%speed_x * dt_particle
298          pos_y_old = particles(n)%y - particles(n)%speed_y * dt_particle
299          pos_z_old = particles(n)%z - particles(n)%speed_z * dt_particle
[849]300!
[1929]301!--       Obtain x/y indices for old particle positions
[2698]302          i1 = i
303          j1 = j
304          k1 = k
[58]305!
[1929]306!--       Determine horizontal as well as vertical walls at which particle can
307!--       be potentially reflected.
308!--       Start with walls aligned in yz layer.
309!--       Wall to the right
310          IF ( prt_x > pos_x_old )  THEN
[2698]311             xwall = ( i1 + 1 ) * dx
[1929]312!
313!--       Wall to the left
314          ELSE
[2698]315             xwall = i1 * dx
[1929]316          ENDIF
317!
318!--       Walls aligned in xz layer
319!--       Wall to the north
320          IF ( prt_y > pos_y_old )  THEN
[2698]321             ywall = ( j1 +1 ) * dy
[1929]322!--       Wall to the south
323          ELSE
[2698]324             ywall = j1 * dy
[1929]325          ENDIF
[2698]326
327          IF ( prt_z > pos_z_old ) THEN
328             zwall = zw(k)
329          ELSE
330             zwall = zw(k-1)
331          ENDIF     
[1929]332!
333!--       Initialize flags to check if particle reflection is necessary
334          cross_wall_x = .FALSE.
335          cross_wall_y = .FALSE.
[2698]336          cross_wall_z = .FALSE.
[1929]337!
338!--       Initialize flags to check if a wall is reached
339          reach_x      = .FALSE.
340          reach_y      = .FALSE.
341          reach_z      = .FALSE.
342!
343!--       Initialize flags to check if a particle was already reflected
[2698]344          reflect_x    = .FALSE.
345          reflect_y    = .FALSE.
346          reflect_z    = .FALSE.
[1929]347!
[2698]348!--       Initialize flags to check if a wall is already crossed.
[1929]349!--       ( Required to obtain correct indices. )
350          x_wall_reached = .FALSE.
351          y_wall_reached = .FALSE.
[2698]352          z_wall_reached = .FALSE.
[1929]353!
354!--       Initialize time array
355          t     = 0.0_wp
356!
357!--       Check if particle can reach any wall. This case, calculate the
358!--       fractional time needed to reach this wall. Store this fractional
359!--       timestep in array t. Moreover, store indices for these grid
360!--       boxes where the respective wall belongs to. 
361!--       Start with x-direction.
362          t_index    = 1
363          t(t_index) = ( xwall - pos_x_old )                                   &
364                     / MERGE( MAX( prt_x - pos_x_old,  1E-30_wp ),             &
365                              MIN( prt_x - pos_x_old, -1E-30_wp ),             &
366                              prt_x > pos_x_old )
367          x_ind(t_index)   = i2
368          y_ind(t_index)   = j1
[2698]369          z_ind(t_index)   = k1
[1929]370          reach_x(t_index) = .TRUE.
371          reach_y(t_index) = .FALSE.
372          reach_z(t_index) = .FALSE.
373!
374!--       Store these values only if particle really reaches any wall. t must
375!--       be in a interval between [0:1].
376          IF ( t(t_index) <= 1.0_wp .AND. t(t_index) >= 0.0_wp )  THEN
377             t_index      = t_index + 1
378             cross_wall_x = .TRUE.
379          ENDIF
380!
381!--       y-direction
382          t(t_index) = ( ywall - pos_y_old )                                   &
383                     / MERGE( MAX( prt_y - pos_y_old,  1E-30_wp ),             &
384                              MIN( prt_y - pos_y_old, -1E-30_wp ),             &
385                              prt_y > pos_y_old )
386          x_ind(t_index)   = i1
387          y_ind(t_index)   = j2
[2698]388          z_ind(t_index)   = k1
[1929]389          reach_x(t_index) = .FALSE.
390          reach_y(t_index) = .TRUE.
391          reach_z(t_index) = .FALSE.
392          IF ( t(t_index) <= 1.0_wp .AND. t(t_index) >= 0.0_wp )  THEN
393             t_index      = t_index + 1
394             cross_wall_y = .TRUE.
395          ENDIF
396!
397!--       z-direction
[2698]398          t(t_index) = (zwall - pos_z_old )                                    &
399                     / MERGE( MAX( prt_z - pos_z_old,  1E-30_wp ),             &
400                              MIN( prt_z - pos_z_old, -1E-30_wp ),             &
401                              prt_z > pos_z_old )
402                     
403          x_ind(t_index)   = i1
404          y_ind(t_index)   = j1
405          z_ind(t_index)   = k2
406          reach_x(t_index) = .FALSE.
407          reach_y(t_index) = .FALSE.
408          reach_z(t_index) = .TRUE.
409          IF( t(t_index) <= 1.0_wp .AND. t(t_index) >= 0.0_wp) THEN
410             t_index      = t_index + 1
411             cross_wall_z = .TRUE.
412          ENDIF
413         
[1929]414          t_index_number = t_index - 1
[58]415!
[1929]416!--       Carry out reflection only if particle reaches any wall
[2698]417          IF ( cross_wall_x .OR. cross_wall_y .OR. cross_wall_z )  THEN
[58]418!
[1929]419!--          Sort fractional timesteps in ascending order. Also sort the
420!--          corresponding indices and flag according to the time interval a 
421!--          particle reaches the respective wall.
422             inc = 1
423             jr  = 1
424             DO WHILE ( inc <= t_index_number )
425                inc = 3 * inc + 1
426             ENDDO
[58]427
[1929]428             DO WHILE ( inc > 1 )
429                inc = inc / 3
430                DO  ir = inc+1, t_index_number
431                   tmp_t       = t(ir)
432                   tmp_x       = x_ind(ir)
433                   tmp_y       = y_ind(ir)
[2698]434                   tmp_z       = z_ind(ir)
[1929]435                   tmp_reach_x = reach_x(ir)
436                   tmp_reach_y = reach_y(ir)
437                   tmp_reach_z = reach_z(ir)
438                   jr    = ir
439                   DO WHILE ( t(jr-inc) > tmp_t )
440                      t(jr)       = t(jr-inc)
441                      x_ind(jr)   = x_ind(jr-inc)
442                      y_ind(jr)   = y_ind(jr-inc)
[2698]443                      z_ind(jr)   = z_ind(jr-inc)
[1929]444                      reach_x(jr) = reach_x(jr-inc)
445                      reach_y(jr) = reach_y(jr-inc)
446                      reach_z(jr) = reach_z(jr-inc)
447                      jr    = jr - inc
448                      IF ( jr <= inc )  EXIT
[58]449                   ENDDO
[1929]450                   t(jr)       = tmp_t
451                   x_ind(jr)   = tmp_x
452                   y_ind(jr)   = tmp_y
[2698]453                   z_ind(jr)   = tmp_z
[1929]454                   reach_x(jr) = tmp_reach_x
455                   reach_y(jr) = tmp_reach_y
456                   reach_z(jr) = tmp_reach_z
[58]457                ENDDO
[1929]458             ENDDO
[58]459!
[1929]460!--          Initialize temporary particle positions
461             pos_x = pos_x_old
462             pos_y = pos_y_old
463             pos_z = pos_z_old
464!
465!--          Loop over all times a particle possibly moves into a new grid box
466             t_old = 0.0_wp
467             DO t_index = 1, t_index_number 
468!           
469!--             Calculate intermediate particle position according to the
470!--             timesteps a particle reaches any wall.
471                pos_x = pos_x + ( t(t_index) - t_old ) * dt_particle           &
472                                                       * particles(n)%speed_x
473                pos_y = pos_y + ( t(t_index) - t_old ) * dt_particle           &
474                                                       * particles(n)%speed_y
475                pos_z = pos_z + ( t(t_index) - t_old ) * dt_particle           &
476                                                       * particles(n)%speed_z
477!
478!--             Obtain x/y grid indices for intermediate particle position from
479!--             sorted index array
480                i3 = x_ind(t_index)
481                j3 = y_ind(t_index)
[2698]482                k3 = z_ind(t_index)
[1929]483!
484!--             Check which wall is already reached
485                IF ( .NOT. x_wall_reached )  x_wall_reached = reach_x(t_index) 
[2698]486                IF ( .NOT. y_wall_reached )  y_wall_reached = reach_y(t_index)
487                IF ( .NOT. z_wall_reached )  z_wall_reached = reach_z(t_index)
[1929]488!
489!--             Check if a particle needs to be reflected at any yz-wall. If
490!--             necessary, carry out reflection. Please note, a security
[2698]491!--             constant is required, as the particle position does not
[1929]492!--             necessarily exactly match the wall location due to rounding
[2698]493!--             errors.
494                IF ( reach_x(t_index)                      .AND.               & 
495                     ABS( pos_x - xwall ) < eps            .AND.               &
496                     .NOT. BTEST(wall_flags_0(k3,j3,i3),0) .AND.               &
[1929]497                     .NOT. reflect_x )  THEN
[2698]498!
499!
[1929]500!--                Reflection in x-direction.
501!--                Ensure correct reflection by MIN/MAX functions, depending on
502!--                direction of particle transport.
[2698]503!--                Due to rounding errors pos_x does not exactly match the wall
[1929]504!--                location, leading to erroneous reflection.             
505                   pos_x = MERGE( MIN( 2.0_wp * xwall - pos_x, xwall ),        &
506                                  MAX( 2.0_wp * xwall - pos_x, xwall ),        &
507                                  particles(n)%x > xwall )
508!
509!--                Change sign of particle speed                     
510                   particles(n)%speed_x = - particles(n)%speed_x
511!
[2698]512!--                Also change sign of subgrid-scale particle speed
[1929]513                   particles(n)%rvar1 = - particles(n)%rvar1
514!
515!--                Set flag that reflection along x is already done
516                   reflect_x          = .TRUE.
517!
[2698]518!--                As the particle does not cross any further yz-wall during
[1929]519!--                this timestep, set further x-indices to the current one.
520                   x_ind(t_index:t_index_number) = i1
521!
522!--             If particle already reached the wall but was not reflected,
523!--             set further x-indices to the new one.
524                ELSEIF ( x_wall_reached .AND. .NOT. reflect_x )  THEN
525                    x_ind(t_index:t_index_number) = i2
[2698]526                ENDIF !particle reflection in x direction done
527
[1929]528!
529!--             Check if a particle needs to be reflected at any xz-wall. If
[2698]530!--             necessary, carry out reflection. Please note, a security
531!--             constant is required, as the particle position does not
532!--             necessarily exactly match the wall location due to rounding
533!--             errors.
534                IF ( reach_y(t_index)                      .AND.               & 
535                     ABS( pos_y - ywall ) < eps            .AND.               &
536                     .NOT. BTEST(wall_flags_0(k3,j3,i3),0) .AND.               &
537                     .NOT. reflect_y )  THEN
538!
539!
540!--                Reflection in y-direction.
541!--                Ensure correct reflection by MIN/MAX functions, depending on
542!--                direction of particle transport.
543!--                Due to rounding errors pos_y does not exactly match the wall
544!--                location, leading to erroneous reflection.             
[1929]545                   pos_y = MERGE( MIN( 2.0_wp * ywall - pos_y, ywall ),        &
546                                  MAX( 2.0_wp * ywall - pos_y, ywall ),        &
[2698]547                                  particles(n)%y > ywall )
548!
549!--                Change sign of particle speed                     
550                   particles(n)%speed_y = - particles(n)%speed_y
551!
552!--                Also change sign of subgrid-scale particle speed
553                   particles(n)%rvar2 = - particles(n)%rvar2
554!
555!--                Set flag that reflection along y is already done
556                   reflect_y          = .TRUE.
557!
558!--                As the particle does not cross any further xz-wall during
559!--                this timestep, set further y-indices to the current one.
[1929]560                   y_ind(t_index:t_index_number) = j1
[2698]561!
562!--             If particle already reached the wall but was not reflected,
563!--             set further y-indices to the new one.
[1929]564                ELSEIF ( y_wall_reached .AND. .NOT. reflect_y )  THEN
[2698]565                    y_ind(t_index:t_index_number) = j2
566                ENDIF !particle reflection in y direction done
567               
[58]568!
[1929]569!--             Check if a particle needs to be reflected at any xy-wall. If
[2698]570!--             necessary, carry out reflection. Please note, a security
571!--             constant is required, as the particle position does not
572!--             necessarily exactly match the wall location due to rounding
573!--             errors.
574                IF ( reach_z(t_index)                      .AND.               & 
575                     ABS( pos_z - zwall ) < eps            .AND.               &
576                     .NOT. BTEST(wall_flags_0(k3,j3,i3),0) .AND.               &
[1929]577                     .NOT. reflect_z )  THEN
[2698]578!
579!
580!--                Reflection in z-direction.
581!--                Ensure correct reflection by MIN/MAX functions, depending on
582!--                direction of particle transport.
583!--                Due to rounding errors pos_z does not exactly match the wall
584!--                location, leading to erroneous reflection.             
585                   pos_z = MERGE( MIN( 2.0_wp * zwall - pos_z, zwall ),        &
586                                  MAX( 2.0_wp * zwall - pos_z, zwall ),        &
587                                  particles(n)%z > zwall )
[2232]588!
[2698]589!--                Change sign of particle speed                     
590                   particles(n)%speed_z = - particles(n)%speed_z
[58]591!
[2698]592!--                Also change sign of subgrid-scale particle speed
593                   particles(n)%rvar3 = - particles(n)%rvar3
594!
595!--                Set flag that reflection along z is already done
596                   reflect_z          = .TRUE.
597!
598!--                As the particle does not cross any further xy-wall during
599!--                this timestep, set further z-indices to the current one.
600                   z_ind(t_index:t_index_number) = k1
601!
602!--             If particle already reached the wall but was not reflected,
603!--             set further z-indices to the new one.
604                ELSEIF ( z_wall_reached .AND. .NOT. reflect_z )  THEN
605                    z_ind(t_index:t_index_number) = k2
606                ENDIF !particle reflection in z direction done               
607               
608!
[1929]609!--             Swap time
610                t_old = t(t_index)
[58]611
[1929]612             ENDDO
[61]613!
[1929]614!--          If a particle was reflected, calculate final position from last
615!--          intermediate position.
616             IF ( reflect_x .OR. reflect_y .OR. reflect_z )  THEN
[61]617
[1929]618                particles(n)%x = pos_x + ( 1.0_wp - t_old ) * dt_particle      &
619                                                         * particles(n)%speed_x
620                particles(n)%y = pos_y + ( 1.0_wp - t_old ) * dt_particle      &
621                                                         * particles(n)%speed_y
622                particles(n)%z = pos_z + ( 1.0_wp - t_old ) * dt_particle      &
623                                                         * particles(n)%speed_z
[61]624
[849]625             ENDIF
[61]626
[1929]627          ENDIF
[61]628
[849]629       ENDDO
[58]630
[849]631       CALL cpu_log( log_point_s(48), 'lpm_wall_reflect', 'stop' )
[58]632
[849]633    ENDIF
[61]634
[849]635 END SUBROUTINE lpm_boundary_conds
Note: See TracBrowser for help on using the repository browser.