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

Last change on this file since 1318 was 1318, checked in by raasch, 8 years ago

former files/routines cpu_log and cpu_statistics combined to one module,
which also includes the former data module cpulog from the modules-file,
module interfaces removed

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