source: palm/trunk/SOURCE/lpm_pack_arrays.f90 @ 1685

Last change on this file since 1685 was 1685, checked in by raasch, 9 years ago

bugfix concerning vertical index calculation for particles in case of ocean runs

  • Property svn:keywords set to Id
File size: 8.4 KB
Line 
1!> @file lpm_pack_arrays.f90
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!
16! Copyright 1997-2014 Leibniz Universitaet Hannover
17!--------------------------------------------------------------------------------!
18!
19! Current revisions:
20! ------------------
21! bugfix concerning vertical index calculation in case of ocean
22!
23! Former revisions:
24! -----------------
25! $Id: lpm_pack_arrays.f90 1685 2015-10-08 07:32:13Z raasch $
26!
27! 1682 2015-10-07 23:56:08Z knoop
28! Code annotations made doxygen readable
29!
30! 1359 2014-04-11 17:15:14Z hoffmann
31! New particle structure integrated.
32! Kind definition added to all floating point numbers.
33!
34! 1320 2014-03-20 08:40:49Z raasch
35! ONLY-attribute added to USE-statements,
36! kind-parameters added to all INTEGER and REAL declaration statements,
37! kinds are defined in new module kinds,
38! comment fields (!:) to be used for variable explanations added to
39! all variable declaration statements
40!
41! 1036 2012-10-22 13:43:42Z raasch
42! code put under GPL (PALM 3.9)
43!
44! 849 2012-03-15 10:35:09Z raasch
45! initial revision (former part of advec_particles)
46!
47!
48! Description:
49! ------------
50!> Pack particle and tail arrays, which means eliminate those elements marked for
51!> deletion and move data with higher index values to these free indices.
52!> Determine the new number of particles.
53!------------------------------------------------------------------------------!
54 MODULE lpm_pack_arrays_mod
55 
56
57    USE particle_attributes,                                                   &
58        ONLY:  deleted_tails, grid_particles, new_tail_id,                     &
59               number_of_particles, number_of_tails, offset_ocean_nzt,         &
60               particles, particle_type, prt_count,                            &
61               particle_tail_coordinates, tail_mask, use_particle_tails
62
63    PRIVATE
64    PUBLIC lpm_pack_all_arrays, lpm_pack_arrays
65
66    INTERFACE lpm_pack_all_arrays
67       MODULE PROCEDURE lpm_pack_all_arrays
68    END INTERFACE lpm_pack_all_arrays
69
70    INTERFACE lpm_pack_arrays
71       MODULE PROCEDURE lpm_pack_arrays
72    END INTERFACE lpm_pack_arrays
73
74CONTAINS
75
76!------------------------------------------------------------------------------!
77! Description:
78! ------------
79!> @todo Missing subroutine description.
80!------------------------------------------------------------------------------!
81    SUBROUTINE lpm_pack_all_arrays
82
83       USE cpulog,                                                             &
84           ONLY:  cpu_log, log_point_s
85
86       USE indices,                                                            &
87           ONLY:  nxl, nxr, nys, nyn, nzb, nzt
88
89       USE kinds
90
91       IMPLICIT NONE
92
93       INTEGER(iwp) ::  i !<
94       INTEGER(iwp) ::  j !<
95       INTEGER(iwp) ::  k !<
96
97       CALL cpu_log( log_point_s(51), 'lpm_pack_all_arrays', 'start' )
98       DO  i = nxl, nxr
99          DO  j = nys, nyn
100             DO  k = nzb+1, nzt
101                number_of_particles = prt_count(k,j,i)
102                IF ( number_of_particles <= 0 )  CYCLE
103                particles => grid_particles(k,j,i)%particles(1:number_of_particles)
104                CALL lpm_pack_and_sort(i,j,k)
105                prt_count(k,j,i) = number_of_particles
106             ENDDO
107          ENDDO
108       ENDDO
109       CALL cpu_log( log_point_s(51), 'lpm_pack_all_arrays', 'stop' )
110       RETURN
111
112    END SUBROUTINE lpm_pack_all_arrays
113
114!------------------------------------------------------------------------------!
115! Description:
116! ------------
117!> @todo Missing subroutine description.
118!------------------------------------------------------------------------------!
119    SUBROUTINE lpm_pack_arrays
120
121       USE kinds
122
123       IMPLICIT NONE
124
125       INTEGER(iwp) ::  n       !<
126       INTEGER(iwp) ::  nd      !<
127       INTEGER(iwp) ::  nn      !<
128!
129!--    Find out elements marked for deletion and move data from highest index
130!--    values to these free indices
131       nn = number_of_particles
132
133       DO WHILE ( .NOT. particles(nn)%particle_mask )
134          nn = nn-1
135          IF ( nn == 0 )  EXIT
136       ENDDO
137
138       IF ( nn > 0 )  THEN
139          DO  n = 1, number_of_particles
140             IF ( .NOT. particles(n)%particle_mask )  THEN
141                particles(n) = particles(nn)
142                nn = nn - 1
143                DO WHILE ( .NOT. particles(nn)%particle_mask )
144                   nn = nn-1
145                   IF ( n == nn )  EXIT
146                ENDDO
147             ENDIF
148             IF ( n == nn )  EXIT
149          ENDDO
150       ENDIF
151
152!
153!--    The number of deleted particles has been determined in routines
154!--    lpm_boundary_conds, lpm_droplet_collision, and lpm_exchange_horiz
155       number_of_particles = nn
156
157!
158!-- particle tails are currently not available
159!
160!-- Handle tail array in the same way, store the new tail ids and re-assign it
161!-- to the respective particles
162!    IF ( use_particle_tails )  THEN
163!
164!       nn = 0
165!       nd = 0
166!
167!       DO  n = 1, number_of_tails
168!
169!          IF ( tail_mask(n) )  THEN
170!             nn = nn + 1
171!             particle_tail_coordinates(:,:,nn) = &
172!                                                particle_tail_coordinates(:,:,n)
173!             new_tail_id(n) = nn
174!          ELSE
175!             nd = nd + 1
176!          ENDIF
177!
178!       ENDDO
179!
180!       DO  n = 1, number_of_particles
181!          IF ( particles(n)%tail_id /= 0 )  THEN
182!             particles(n)%tail_id = new_tail_id(particles(n)%tail_id)
183!          ENDIF
184!       ENDDO
185!
186!    ENDIF
187
188!
189!-- The number of deleted tails has been determined in routines
190!-- lpm_boundary_conds and lpm_exchange_horiz
191!   number_of_tails = number_of_tails - deleted_tails
192
193
194    END SUBROUTINE lpm_pack_arrays
195
196!------------------------------------------------------------------------------!
197! Description:
198! ------------
199!> @todo Missing subroutine description.
200!------------------------------------------------------------------------------!
201    SUBROUTINE lpm_pack_and_sort (ip,jp,kp)
202
203      USE control_parameters,                                                  &
204          ONLY: dz
205
206      USE indices,                                                             &
207          ONLY: nxl, nxr, nys, nyn, nzb, nzt
208
209      USE kinds
210
211      USE grid_variables,                                                      &
212          ONLY: ddx, ddy
213
214      IMPLICIT NONE
215
216      INTEGER(iwp), INTENT(IN) :: ip
217      INTEGER(iwp), INTENT(IN) :: jp
218      INTEGER(iwp), INTENT(IN) :: kp
219
220      INTEGER(iwp)             :: i
221      INTEGER(iwp)             :: is
222      INTEGER(iwp)             :: j
223      INTEGER(iwp)             :: k
224      INTEGER(iwp)             :: n
225      INTEGER(iwp)             :: nn
226      INTEGER(iwp)             :: m
227      INTEGER(iwp)             :: sort_index
228
229      INTEGER(iwp), DIMENSION(0:7) :: sort_count
230
231      TYPE(particle_type), DIMENSION(number_of_particles,0:7) :: sort_particles
232
233       nn = 0
234       sort_count = 0
235
236       DO  n = 1, number_of_particles
237          sort_index = 0
238
239          IF ( particles(n)%particle_mask )  THEN
240             nn = nn + 1
241             i = particles(n)%x * ddx
242             j = particles(n)%y * ddy
243             k = ( particles(n)%z + 0.5_wp * dz ) / dz + offset_ocean_nzt
244             IF ( i == ip )  sort_index = sort_index+4
245             IF ( j == jp )  sort_index = sort_index+2
246             IF ( k == kp )  sort_index = sort_index+1
247             sort_count(sort_index) = sort_count(sort_index)+1
248             m = sort_count(sort_index)
249             sort_particles(m,sort_index) = particles(n)
250             sort_particles(m,sort_index)%block_nr = sort_index
251          ENDIF
252
253       ENDDO
254
255       nn = 0
256
257       DO is = 0,7
258          grid_particles(kp,jp,ip)%start_index(is) = nn + 1
259          DO n = 1,sort_count(is)
260             nn = nn+1
261             particles(nn) = sort_particles(n,is)
262          ENDDO
263          grid_particles(kp,jp,ip)%end_index(is) = nn
264       ENDDO
265
266       number_of_particles = nn
267       RETURN
268
269    END SUBROUTINE lpm_pack_and_sort
270
271
272 END module lpm_pack_arrays_mod
Note: See TracBrowser for help on using the repository browser.