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

Last change on this file since 1036 was 1036, checked in by raasch, 11 years ago

code has been put under the GNU General Public License (v3)

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