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 1321 2014-03-20 09:40:40Z heinze $ |
---|
27 | ! |
---|
28 | ! 1320 2014-03-20 08:40:49Z raasch |
---|
29 | ! ONLY-attribute added to USE-statements, |
---|
30 | ! kind-parameters added to all INTEGER and REAL declaration statements, |
---|
31 | ! kinds are defined in new module kinds, |
---|
32 | ! comment fields (!:) to be used for variable explanations added to |
---|
33 | ! all variable declaration statements |
---|
34 | ! |
---|
35 | ! 1318 2014-03-17 13:35:16Z raasch |
---|
36 | ! module interfaces removed |
---|
37 | ! |
---|
38 | ! 1036 2012-10-22 13:43:42Z raasch |
---|
39 | ! code put under GPL (PALM 3.9) |
---|
40 | ! |
---|
41 | ! 849 2012-03-15 10:35:09Z raasch |
---|
42 | ! initial revision (former part of advec_particles) |
---|
43 | ! |
---|
44 | ! |
---|
45 | ! Description: |
---|
46 | ! ------------ |
---|
47 | ! Sort particles in the sequence the grid boxes are stored in memory. |
---|
48 | !------------------------------------------------------------------------------! |
---|
49 | |
---|
50 | USE control_parameters, & |
---|
51 | ONLY: message_string, dz |
---|
52 | |
---|
53 | USE cpulog, & |
---|
54 | ONLY: cpu_log, log_point_s |
---|
55 | |
---|
56 | USE grid_variables, & |
---|
57 | ONLY: ddx, dx, ddy, dy |
---|
58 | |
---|
59 | USE indices, & |
---|
60 | ONLY: nxl, nxr, nyn, nys, nzb, nzt |
---|
61 | |
---|
62 | USE kinds |
---|
63 | |
---|
64 | USE particle_attributes, & |
---|
65 | ONLY: number_of_particles, offset_ocean_nzt, part_1, part_2, particles,& |
---|
66 | particle_type, prt_count, prt_start_index, sort_count |
---|
67 | |
---|
68 | IMPLICIT NONE |
---|
69 | |
---|
70 | INTEGER(iwp) :: i !: |
---|
71 | INTEGER(iwp) :: ilow !: |
---|
72 | INTEGER(iwp) :: j !: |
---|
73 | INTEGER(iwp) :: k !: |
---|
74 | INTEGER(iwp) :: n !: |
---|
75 | |
---|
76 | TYPE(particle_type), DIMENSION(:), POINTER :: particles_temp !: |
---|
77 | |
---|
78 | |
---|
79 | CALL cpu_log( log_point_s(47), 'lpm_sort_arrays', 'start' ) |
---|
80 | |
---|
81 | ! |
---|
82 | !-- Initialize counters and set pointer of the temporary array into which |
---|
83 | !-- particles are sorted to free memory |
---|
84 | prt_count = 0 |
---|
85 | sort_count = sort_count +1 |
---|
86 | |
---|
87 | SELECT CASE ( MOD( sort_count, 2 ) ) |
---|
88 | |
---|
89 | CASE ( 0 ) |
---|
90 | |
---|
91 | particles_temp => part_1 |
---|
92 | |
---|
93 | CASE ( 1 ) |
---|
94 | |
---|
95 | particles_temp => part_2 |
---|
96 | |
---|
97 | END SELECT |
---|
98 | |
---|
99 | ! |
---|
100 | !-- Count the particles per gridbox |
---|
101 | DO n = 1, number_of_particles |
---|
102 | |
---|
103 | i = ( particles(n)%x + 0.5 * dx ) * ddx |
---|
104 | j = ( particles(n)%y + 0.5 * dy ) * ddy |
---|
105 | k = particles(n)%z / dz + 1 + offset_ocean_nzt |
---|
106 | ! only exact if equidistant |
---|
107 | |
---|
108 | prt_count(k,j,i) = prt_count(k,j,i) + 1 |
---|
109 | |
---|
110 | IF ( i < nxl .OR. i > nxr .OR. j < nys .OR. j > nyn .OR. k < nzb+1 .OR. & |
---|
111 | k > nzt ) THEN |
---|
112 | WRITE( message_string, * ) ' particle out of range: i=', i, ' j=', & |
---|
113 | j, ' k=', k, & |
---|
114 | ' nxl=', nxl, ' nxr=', nxr, & |
---|
115 | ' nys=', nys, ' nyn=', nyn, & |
---|
116 | ' nzb=', nzb, ' nzt=', nzt |
---|
117 | CALL message( 'lpm_sort_arrays', 'PA0149', 1, 2, 0, 6, 0 ) |
---|
118 | ENDIF |
---|
119 | |
---|
120 | ENDDO |
---|
121 | |
---|
122 | ! |
---|
123 | !-- Calculate the lower indices of those ranges of the particles-array |
---|
124 | !-- containing particles which belong to the same gridpox i,j,k |
---|
125 | ilow = 1 |
---|
126 | DO i = nxl, nxr |
---|
127 | DO j = nys, nyn |
---|
128 | DO k = nzb+1, nzt |
---|
129 | prt_start_index(k,j,i) = ilow |
---|
130 | ilow = ilow + prt_count(k,j,i) |
---|
131 | ENDDO |
---|
132 | ENDDO |
---|
133 | ENDDO |
---|
134 | |
---|
135 | ! |
---|
136 | !-- Sorting the particles |
---|
137 | DO n = 1, number_of_particles |
---|
138 | |
---|
139 | i = ( particles(n)%x + 0.5 * dx ) * ddx |
---|
140 | j = ( particles(n)%y + 0.5 * dy ) * ddy |
---|
141 | k = particles(n)%z / dz + 1 + offset_ocean_nzt |
---|
142 | ! only exact if equidistant |
---|
143 | |
---|
144 | particles_temp(prt_start_index(k,j,i)) = particles(n) |
---|
145 | |
---|
146 | prt_start_index(k,j,i) = prt_start_index(k,j,i) + 1 |
---|
147 | |
---|
148 | ENDDO |
---|
149 | |
---|
150 | ! |
---|
151 | !-- Redirect the particles pointer to the sorted array |
---|
152 | SELECT CASE ( MOD( sort_count, 2 ) ) |
---|
153 | |
---|
154 | CASE ( 0 ) |
---|
155 | |
---|
156 | particles => part_1 |
---|
157 | |
---|
158 | CASE ( 1 ) |
---|
159 | |
---|
160 | particles => part_2 |
---|
161 | |
---|
162 | END SELECT |
---|
163 | |
---|
164 | ! |
---|
165 | !-- Reset the index array to the actual start position |
---|
166 | DO i = nxl, nxr |
---|
167 | DO j = nys, nyn |
---|
168 | DO k = nzb+1, nzt |
---|
169 | prt_start_index(k,j,i) = prt_start_index(k,j,i) - prt_count(k,j,i) |
---|
170 | ENDDO |
---|
171 | ENDDO |
---|
172 | ENDDO |
---|
173 | |
---|
174 | CALL cpu_log( log_point_s(47), 'lpm_sort_arrays', 'stop' ) |
---|
175 | |
---|
176 | |
---|
177 | END SUBROUTINE lpm_sort_arrays |
---|