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