source: palm/trunk/SOURCE/lpm_sort_arrays.f90 @ 1319

Last change on this file since 1319 was 1319, checked in by raasch, 10 years ago

last commit documented

  • Property svn:keywords set to Id
File size: 4.1 KB
Line 
1 SUBROUTINE lpm_sort_arrays
2
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!
17! Copyright 1997-2014 Leibniz Universitaet Hannover
18!--------------------------------------------------------------------------------!
19!
20! Current revisions:
21! ------------------
22!
23!
24! Former revisions:
25! -----------------
26! $Id: lpm_sort_arrays.f90 1319 2014-03-17 15:08:44Z raasch $
27!
28! 1318 2014-03-17 13:35:16Z raasch
29! module interfaces removed
30!
31! 1036 2012-10-22 13:43:42Z raasch
32! code put under GPL (PALM 3.9)
33!
34! 849 2012-03-15 10:35:09Z raasch
35! initial revision (former part of advec_particles)
36!
37!
38! Description:
39! ------------
40! Sort particles in the sequence the grid boxes are stored in memory.
41!------------------------------------------------------------------------------!
42
43    USE arrays_3d
44    USE control_parameters
45    USE cpulog
46    USE grid_variables
47    USE indices
48    USE particle_attributes
49
50    IMPLICIT NONE
51
52    INTEGER ::  i, ilow, j, k, n
53
54    TYPE(particle_type), DIMENSION(:), POINTER ::  particles_temp
55
56
57    CALL cpu_log( log_point_s(47), 'lpm_sort_arrays', 'start' )
58
59!
60!-- Initialize counters and set pointer of the temporary array into which
61!-- particles are sorted to free memory
62    prt_count  = 0
63    sort_count = sort_count +1
64
65    SELECT CASE ( MOD( sort_count, 2 ) )
66
67       CASE ( 0 )
68
69          particles_temp => part_1
70
71       CASE ( 1 )
72
73          particles_temp => part_2
74
75    END SELECT
76
77!
78!-- Count the particles per gridbox
79    DO  n = 1, number_of_particles
80
81       i = ( particles(n)%x + 0.5 * dx ) * ddx
82       j = ( particles(n)%y + 0.5 * dy ) * ddy
83       k = particles(n)%z / dz + 1 + offset_ocean_nzt
84           ! only exact if equidistant
85
86       prt_count(k,j,i) = prt_count(k,j,i) + 1
87
88       IF ( i < nxl .OR. i > nxr .OR. j < nys .OR. j > nyn .OR. k < nzb+1 .OR. &
89            k > nzt )  THEN
90          WRITE( message_string, * ) ' particle out of range: i=', i, ' j=', &
91                          j, ' k=', k,                                       &
92                          ' nxl=', nxl, ' nxr=', nxr,                        &
93                          ' nys=', nys, ' nyn=', nyn,                        &
94                          ' nzb=', nzb, ' nzt=', nzt
95         CALL message( 'lpm_sort_arrays', 'PA0149', 1, 2, 0, 6, 0 ) 
96       ENDIF
97
98    ENDDO
99
100!
101!-- Calculate the lower indices of those ranges of the particles-array
102!-- containing particles which belong to the same gridpox i,j,k
103    ilow = 1
104    DO  i = nxl, nxr
105       DO  j = nys, nyn
106          DO  k = nzb+1, nzt
107             prt_start_index(k,j,i) = ilow
108             ilow = ilow + prt_count(k,j,i)
109          ENDDO
110       ENDDO
111    ENDDO
112
113!
114!-- Sorting the particles
115    DO  n = 1, number_of_particles
116
117       i = ( particles(n)%x + 0.5 * dx ) * ddx
118       j = ( particles(n)%y + 0.5 * dy ) * ddy
119       k = particles(n)%z / dz + 1 + offset_ocean_nzt
120           ! only exact if equidistant
121
122       particles_temp(prt_start_index(k,j,i)) = particles(n)
123
124       prt_start_index(k,j,i) = prt_start_index(k,j,i) + 1
125
126    ENDDO
127
128!
129!-- Redirect the particles pointer to the sorted array
130    SELECT CASE ( MOD( sort_count, 2 ) )
131
132       CASE ( 0 )
133
134          particles => part_1
135
136       CASE ( 1 )
137
138          particles => part_2
139
140    END SELECT
141
142!
143!-- Reset the index array to the actual start position
144    DO  i = nxl, nxr
145       DO  j = nys, nyn
146          DO  k = nzb+1, nzt
147             prt_start_index(k,j,i) = prt_start_index(k,j,i) - prt_count(k,j,i)
148          ENDDO
149       ENDDO
150    ENDDO
151
152    CALL cpu_log( log_point_s(47), 'lpm_sort_arrays', 'stop' )
153
154
155 END SUBROUTINE lpm_sort_arrays
Note: See TracBrowser for help on using the repository browser.