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

Last change on this file since 3428 was 3241, checked in by raasch, 6 years ago

various changes to avoid compiler warnings (mainly removal of unused variables)

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