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

Last change on this file since 1838 was 1823, checked in by hoffmann, 9 years ago

last commit documented

  • Property svn:keywords set to Id
File size: 7.3 KB
RevLine 
[1682]1!> @file lpm_pack_arrays.f90
[1036]2!--------------------------------------------------------------------------------!
3! This file is part of PALM.
4!
5! PALM is free software: you can redistribute it and/or modify it under the terms
6! of the GNU General Public License as published by the Free Software Foundation,
7! either version 3 of the License, or (at your option) any later version.
8!
9! PALM is distributed in the hope that it will be useful, but WITHOUT ANY
10! WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
11! A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
12!
13! You should have received a copy of the GNU General Public License along with
14! PALM. If not, see <http://www.gnu.org/licenses/>.
15!
[1818]16! Copyright 1997-2016 Leibniz Universitaet Hannover
[1036]17!--------------------------------------------------------------------------------!
18!
[849]19! Current revisions:
20! ------------------
[1686]21!
[1823]22!
[1321]23! Former revisions:
24! -----------------
25! $Id: lpm_pack_arrays.f90 1823 2016-04-07 08:57:52Z raasch $
26!
[1823]27! 1822 2016-04-07 07:49:42Z hoffmann
28! Tails removed. Unused variables removed.
29!
[1686]30! 1685 2015-10-08 07:32:13Z raasch
31! bugfix concerning vertical index calculation in case of ocean
32!
[1683]33! 1682 2015-10-07 23:56:08Z knoop
34! Code annotations made doxygen readable
35!
[1360]36! 1359 2014-04-11 17:15:14Z hoffmann
37! New particle structure integrated.
38! Kind definition added to all floating point numbers.
39!
[1321]40! 1320 2014-03-20 08:40:49Z raasch
[1320]41! ONLY-attribute added to USE-statements,
42! kind-parameters added to all INTEGER and REAL declaration statements,
43! kinds are defined in new module kinds,
44! comment fields (!:) to be used for variable explanations added to
45! all variable declaration statements
[849]46!
[1037]47! 1036 2012-10-22 13:43:42Z raasch
48! code put under GPL (PALM 3.9)
49!
[850]50! 849 2012-03-15 10:35:09Z raasch
51! initial revision (former part of advec_particles)
[849]52!
[850]53!
[849]54! Description:
55! ------------
[1822]56!> Pack particle arrays, which means eliminate those elements marked for
[1682]57!> deletion and move data with higher index values to these free indices.
58!> Determine the new number of particles.
[849]59!------------------------------------------------------------------------------!
[1682]60 MODULE lpm_pack_arrays_mod
61 
[849]62
[1320]63    USE particle_attributes,                                                   &
[1822]64        ONLY:  grid_particles, number_of_particles, offset_ocean_nzt,          &
65               particles, particle_type, prt_count
[849]66
[1359]67    PRIVATE
68    PUBLIC lpm_pack_all_arrays, lpm_pack_arrays
[849]69
[1359]70    INTERFACE lpm_pack_all_arrays
71       MODULE PROCEDURE lpm_pack_all_arrays
72    END INTERFACE lpm_pack_all_arrays
[849]73
[1359]74    INTERFACE lpm_pack_arrays
75       MODULE PROCEDURE lpm_pack_arrays
76    END INTERFACE lpm_pack_arrays
77
78CONTAINS
79
[1682]80!------------------------------------------------------------------------------!
81! Description:
82! ------------
83!> @todo Missing subroutine description.
84!------------------------------------------------------------------------------!
[1359]85    SUBROUTINE lpm_pack_all_arrays
86
87       USE cpulog,                                                             &
88           ONLY:  cpu_log, log_point_s
89
90       USE indices,                                                            &
91           ONLY:  nxl, nxr, nys, nyn, nzb, nzt
92
93       USE kinds
94
95       IMPLICIT NONE
96
[1682]97       INTEGER(iwp) ::  i !<
98       INTEGER(iwp) ::  j !<
99       INTEGER(iwp) ::  k !<
[1359]100
101       CALL cpu_log( log_point_s(51), 'lpm_pack_all_arrays', 'start' )
102       DO  i = nxl, nxr
103          DO  j = nys, nyn
104             DO  k = nzb+1, nzt
105                number_of_particles = prt_count(k,j,i)
106                IF ( number_of_particles <= 0 )  CYCLE
107                particles => grid_particles(k,j,i)%particles(1:number_of_particles)
108                CALL lpm_pack_and_sort(i,j,k)
109                prt_count(k,j,i) = number_of_particles
110             ENDDO
111          ENDDO
112       ENDDO
113       CALL cpu_log( log_point_s(51), 'lpm_pack_all_arrays', 'stop' )
114       RETURN
115
116    END SUBROUTINE lpm_pack_all_arrays
117
[1682]118!------------------------------------------------------------------------------!
119! Description:
120! ------------
121!> @todo Missing subroutine description.
122!------------------------------------------------------------------------------!
[1359]123    SUBROUTINE lpm_pack_arrays
124
125       USE kinds
126
127       IMPLICIT NONE
128
[1682]129       INTEGER(iwp) ::  n       !<
130       INTEGER(iwp) ::  nn      !<
[849]131!
[1359]132!--    Find out elements marked for deletion and move data from highest index
133!--    values to these free indices
134       nn = number_of_particles
[849]135
[1359]136       DO WHILE ( .NOT. particles(nn)%particle_mask )
137          nn = nn-1
138          IF ( nn == 0 )  EXIT
139       ENDDO
[849]140
[1359]141       IF ( nn > 0 )  THEN
142          DO  n = 1, number_of_particles
143             IF ( .NOT. particles(n)%particle_mask )  THEN
144                particles(n) = particles(nn)
145                nn = nn - 1
146                DO WHILE ( .NOT. particles(nn)%particle_mask )
147                   nn = nn-1
148                   IF ( n == nn )  EXIT
149                ENDDO
150             ENDIF
151             IF ( n == nn )  EXIT
152          ENDDO
[849]153       ENDIF
154
155!
[1359]156!--    The number of deleted particles has been determined in routines
157!--    lpm_boundary_conds, lpm_droplet_collision, and lpm_exchange_horiz
158       number_of_particles = nn
[849]159
[1359]160    END SUBROUTINE lpm_pack_arrays
161
[1682]162!------------------------------------------------------------------------------!
163! Description:
164! ------------
165!> @todo Missing subroutine description.
166!------------------------------------------------------------------------------!
[1359]167    SUBROUTINE lpm_pack_and_sort (ip,jp,kp)
168
169      USE control_parameters,                                                  &
[1685]170          ONLY: dz
[1359]171
172      USE kinds
173
174      USE grid_variables,                                                      &
175          ONLY: ddx, ddy
176
177      IMPLICIT NONE
178
[1685]179      INTEGER(iwp), INTENT(IN) :: ip
180      INTEGER(iwp), INTENT(IN) :: jp
181      INTEGER(iwp), INTENT(IN) :: kp
[1359]182
[1685]183      INTEGER(iwp)             :: i
184      INTEGER(iwp)             :: is
185      INTEGER(iwp)             :: j
186      INTEGER(iwp)             :: k
187      INTEGER(iwp)             :: n
188      INTEGER(iwp)             :: nn
189      INTEGER(iwp)             :: m
190      INTEGER(iwp)             :: sort_index
[1359]191
[1685]192      INTEGER(iwp), DIMENSION(0:7) :: sort_count
[1359]193
194      TYPE(particle_type), DIMENSION(number_of_particles,0:7) :: sort_particles
195
[849]196       nn = 0
[1359]197       sort_count = 0
[849]198
[1359]199       DO  n = 1, number_of_particles
200          sort_index = 0
[849]201
[1359]202          IF ( particles(n)%particle_mask )  THEN
[849]203             nn = nn + 1
[1359]204             i = particles(n)%x * ddx
205             j = particles(n)%y * ddy
[1685]206             k = ( particles(n)%z + 0.5_wp * dz ) / dz + offset_ocean_nzt
[1359]207             IF ( i == ip )  sort_index = sort_index+4
208             IF ( j == jp )  sort_index = sort_index+2
209             IF ( k == kp )  sort_index = sort_index+1
210             sort_count(sort_index) = sort_count(sort_index)+1
211             m = sort_count(sort_index)
212             sort_particles(m,sort_index) = particles(n)
213             sort_particles(m,sort_index)%block_nr = sort_index
[849]214          ENDIF
215
216       ENDDO
217
[1359]218       nn = 0
219
220       DO is = 0,7
221          grid_particles(kp,jp,ip)%start_index(is) = nn + 1
222          DO n = 1,sort_count(is)
223             nn = nn+1
224             particles(nn) = sort_particles(n,is)
225          ENDDO
226          grid_particles(kp,jp,ip)%end_index(is) = nn
[849]227       ENDDO
228
[1359]229       number_of_particles = nn
230       RETURN
[849]231
[1359]232    END SUBROUTINE lpm_pack_and_sort
[849]233
234
[1359]235 END module lpm_pack_arrays_mod
Note: See TracBrowser for help on using the repository browser.