[1682] | 1 | !> @file inflow_turbulence.f90 |
---|
[1036] | 2 | !--------------------------------------------------------------------------------! |
---|
| 3 | ! This file is part of PALM. |
---|
| 4 | ! |
---|
| 5 | ! PALM is free software: you can redistribute it and/or modify it under the terms |
---|
| 6 | ! of the GNU General Public License as published by the Free Software Foundation, |
---|
| 7 | ! either version 3 of the License, or (at your option) any later version. |
---|
| 8 | ! |
---|
| 9 | ! PALM is distributed in the hope that it will be useful, but WITHOUT ANY |
---|
| 10 | ! WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR |
---|
| 11 | ! A PARTICULAR PURPOSE. See the GNU General Public License for more details. |
---|
| 12 | ! |
---|
| 13 | ! You should have received a copy of the GNU General Public License along with |
---|
| 14 | ! PALM. If not, see <http://www.gnu.org/licenses/>. |
---|
| 15 | ! |
---|
[1310] | 16 | ! Copyright 1997-2014 Leibniz Universitaet Hannover |
---|
[1036] | 17 | !--------------------------------------------------------------------------------! |
---|
| 18 | ! |
---|
[484] | 19 | ! Current revisions: |
---|
[151] | 20 | ! ----------------- |
---|
[1806] | 21 | ! Added comments to variables and code segments. Removed code redundancies. |
---|
[1354] | 22 | ! |
---|
[151] | 23 | ! Former revisions: |
---|
| 24 | ! ----------------- |
---|
| 25 | ! $Id: inflow_turbulence.f90 1806 2016-04-05 18:55:35Z gronemeier $ |
---|
| 26 | ! |
---|
[1683] | 27 | ! 1682 2015-10-07 23:56:08Z knoop |
---|
| 28 | ! Code annotations made doxygen readable |
---|
| 29 | ! |
---|
[1616] | 30 | ! 1615 2015-07-08 18:49:19Z suehring |
---|
| 31 | ! Enable turbulent inflow for passive_scalar and humidity |
---|
| 32 | ! |
---|
[1561] | 33 | ! 1560 2015-03-06 10:48:54Z keck |
---|
| 34 | ! Option recycling_yshift added. If this option is switched on, the turbulence |
---|
| 35 | ! data, which is mapped from the recycling plane to the inflow, is shifted in |
---|
| 36 | ! y direction (by ny * dy / 2 ) |
---|
| 37 | ! |
---|
[1354] | 38 | ! 1353 2014-04-08 15:21:23Z heinze |
---|
| 39 | ! REAL constants provided with KIND-attribute |
---|
| 40 | ! |
---|
[1347] | 41 | ! 1346 2014-03-27 13:18:20Z heinze |
---|
| 42 | ! Bugfix: REAL constants provided with KIND-attribute especially in call of |
---|
| 43 | ! intrinsic function like MAX, MIN, SIGN |
---|
| 44 | ! |
---|
[1321] | 45 | ! 1320 2014-03-20 08:40:49Z raasch |
---|
| 46 | ! ONLY-attribute added to USE-statements, |
---|
| 47 | ! kind-parameters added to all INTEGER and REAL declaration statements, |
---|
| 48 | ! kinds are defined in new module kinds, |
---|
| 49 | ! revision history before 2012 removed, |
---|
| 50 | ! comment fields (!:) to be used for variable explanations added to |
---|
| 51 | ! all variable declaration statements |
---|
| 52 | ! |
---|
[1093] | 53 | ! 1092 2013-02-02 11:24:22Z raasch |
---|
| 54 | ! unused variables removed |
---|
| 55 | ! |
---|
[1037] | 56 | ! 1036 2012-10-22 13:43:42Z raasch |
---|
| 57 | ! code put under GPL (PALM 3.9) |
---|
| 58 | ! |
---|
[198] | 59 | ! Initial version (2008/03/07) |
---|
[151] | 60 | ! |
---|
| 61 | ! Description: |
---|
| 62 | ! ------------ |
---|
[1682] | 63 | !> Imposing turbulence at the respective inflow using the turbulence |
---|
| 64 | !> recycling method of Kataoka and Mizuno (2002). |
---|
[151] | 65 | !------------------------------------------------------------------------------! |
---|
[1682] | 66 | SUBROUTINE inflow_turbulence |
---|
| 67 | |
---|
[151] | 68 | |
---|
[1320] | 69 | USE arrays_3d, & |
---|
[1615] | 70 | ONLY: e, inflow_damping_factor, mean_inflow_profiles, pt, q, u, v, w |
---|
[1320] | 71 | |
---|
| 72 | USE control_parameters, & |
---|
[1615] | 73 | ONLY: humidity, passive_scalar, recycling_plane, recycling_yshift |
---|
[1320] | 74 | |
---|
| 75 | USE cpulog, & |
---|
| 76 | ONLY: cpu_log, log_point |
---|
| 77 | |
---|
| 78 | USE indices, & |
---|
| 79 | ONLY: nbgp, nxl, ny, nyn, nys, nyng, nysg, nzb, nzt |
---|
| 80 | |
---|
| 81 | USE kinds |
---|
| 82 | |
---|
[151] | 83 | USE pegrid |
---|
| 84 | |
---|
| 85 | |
---|
| 86 | IMPLICIT NONE |
---|
| 87 | |
---|
[1806] | 88 | INTEGER(iwp) :: i !< loop index |
---|
| 89 | INTEGER(iwp) :: j !< loop index |
---|
| 90 | INTEGER(iwp) :: k !< loop index |
---|
| 91 | INTEGER(iwp) :: l !< loop index |
---|
| 92 | INTEGER(iwp) :: next !< ID of receiving PE for y-shift |
---|
| 93 | INTEGER(iwp) :: ngp_ifd !< number of grid points stored in avpr |
---|
| 94 | INTEGER(iwp) :: ngp_pr !< number of grid points stored in inflow_dist |
---|
| 95 | INTEGER(iwp) :: prev !< ID of sending PE for y-shift |
---|
[151] | 96 | |
---|
[1615] | 97 | REAL(wp), DIMENSION(nzb:nzt+1,6,nbgp) :: & |
---|
[1806] | 98 | avpr !< stores averaged profiles at recycling plane |
---|
| 99 | REAL(wp), DIMENSION(nzb:nzt+1,6,nbgp) :: & |
---|
| 100 | avpr_l !< auxiliary variable to calculate avpr |
---|
[1615] | 101 | REAL(wp), DIMENSION(nzb:nzt+1,nysg:nyng,6,nbgp) :: & |
---|
[1806] | 102 | inflow_dist !< turbulence signal of vars, added at inflow boundary |
---|
| 103 | REAL(wp), DIMENSION(nzb:nzt+1,nysg:nyng,6,nbgp) :: & |
---|
| 104 | local_inflow_dist !< auxiliary variable for inflow_dist, used for yshift |
---|
[151] | 105 | |
---|
| 106 | CALL cpu_log( log_point(40), 'inflow_turbulence', 'start' ) |
---|
| 107 | |
---|
| 108 | ! |
---|
[667] | 109 | !-- Carry out spanwise averaging in the recycling plane |
---|
[1353] | 110 | avpr_l = 0.0_wp |
---|
[1615] | 111 | ngp_pr = ( nzt - nzb + 2 ) * 6 * nbgp |
---|
[667] | 112 | ngp_ifd = ngp_pr * ( nyn - nys + 1 + 2 * nbgp ) |
---|
[151] | 113 | |
---|
| 114 | ! |
---|
| 115 | !-- First, local averaging within the recycling domain |
---|
[667] | 116 | i = recycling_plane |
---|
[151] | 117 | |
---|
[667] | 118 | #if defined( __parallel ) |
---|
| 119 | IF ( myidx == id_recycling ) THEN |
---|
| 120 | |
---|
| 121 | DO l = 1, nbgp |
---|
[151] | 122 | DO j = nys, nyn |
---|
[667] | 123 | DO k = nzb, nzt + 1 |
---|
[151] | 124 | |
---|
[667] | 125 | avpr_l(k,1,l) = avpr_l(k,1,l) + u(k,j,i) |
---|
| 126 | avpr_l(k,2,l) = avpr_l(k,2,l) + v(k,j,i) |
---|
| 127 | avpr_l(k,3,l) = avpr_l(k,3,l) + w(k,j,i) |
---|
| 128 | avpr_l(k,4,l) = avpr_l(k,4,l) + pt(k,j,i) |
---|
| 129 | avpr_l(k,5,l) = avpr_l(k,5,l) + e(k,j,i) |
---|
[1615] | 130 | IF ( humidity .OR. passive_scalar ) & |
---|
| 131 | avpr_l(k,6,l) = avpr_l(k,6,l) + q(k,j,i) |
---|
[151] | 132 | |
---|
| 133 | ENDDO |
---|
| 134 | ENDDO |
---|
[667] | 135 | i = i + 1 |
---|
[151] | 136 | ENDDO |
---|
| 137 | |
---|
| 138 | ENDIF |
---|
| 139 | ! |
---|
| 140 | !-- Now, averaging over all PEs |
---|
[622] | 141 | IF ( collective_wait ) CALL MPI_BARRIER( comm2d, ierr ) |
---|
[1615] | 142 | CALL MPI_ALLREDUCE( avpr_l(nzb,1,1), avpr(nzb,1,1), ngp_pr, MPI_REAL, & |
---|
[709] | 143 | MPI_SUM, comm2d, ierr ) |
---|
[667] | 144 | |
---|
[151] | 145 | #else |
---|
[667] | 146 | DO l = 1, nbgp |
---|
| 147 | DO j = nys, nyn |
---|
| 148 | DO k = nzb, nzt + 1 |
---|
| 149 | |
---|
| 150 | avpr_l(k,1,l) = avpr_l(k,1,l) + u(k,j,i) |
---|
| 151 | avpr_l(k,2,l) = avpr_l(k,2,l) + v(k,j,i) |
---|
| 152 | avpr_l(k,3,l) = avpr_l(k,3,l) + w(k,j,i) |
---|
| 153 | avpr_l(k,4,l) = avpr_l(k,4,l) + pt(k,j,i) |
---|
| 154 | avpr_l(k,5,l) = avpr_l(k,5,l) + e(k,j,i) |
---|
[1615] | 155 | IF ( humidity .OR. passive_scalar ) & |
---|
| 156 | avpr_l(k,6,l) = avpr_l(k,6,l) + q(k,j,i) |
---|
[667] | 157 | |
---|
| 158 | ENDDO |
---|
| 159 | ENDDO |
---|
| 160 | i = i + 1 |
---|
| 161 | ENDDO |
---|
| 162 | |
---|
[151] | 163 | avpr = avpr_l |
---|
| 164 | #endif |
---|
| 165 | |
---|
[667] | 166 | avpr = avpr / ( ny + 1 ) |
---|
[151] | 167 | ! |
---|
| 168 | !-- Calculate the disturbances at the recycling plane |
---|
| 169 | i = recycling_plane |
---|
| 170 | |
---|
[222] | 171 | #if defined( __parallel ) |
---|
[163] | 172 | IF ( myidx == id_recycling ) THEN |
---|
[667] | 173 | DO l = 1, nbgp |
---|
| 174 | DO j = nysg, nyng |
---|
| 175 | DO k = nzb, nzt + 1 |
---|
[151] | 176 | |
---|
[667] | 177 | inflow_dist(k,j,1,l) = u(k,j,i+1) - avpr(k,1,l) |
---|
| 178 | inflow_dist(k,j,2,l) = v(k,j,i) - avpr(k,2,l) |
---|
| 179 | inflow_dist(k,j,3,l) = w(k,j,i) - avpr(k,3,l) |
---|
| 180 | inflow_dist(k,j,4,l) = pt(k,j,i) - avpr(k,4,l) |
---|
| 181 | inflow_dist(k,j,5,l) = e(k,j,i) - avpr(k,5,l) |
---|
[1615] | 182 | IF ( humidity .OR. passive_scalar ) & |
---|
| 183 | inflow_dist(k,j,6,l) = q(k,j,i) - avpr(k,6,l) |
---|
[667] | 184 | ENDDO |
---|
[151] | 185 | ENDDO |
---|
[667] | 186 | i = i + 1 |
---|
[151] | 187 | ENDDO |
---|
| 188 | |
---|
| 189 | ENDIF |
---|
[222] | 190 | #else |
---|
[667] | 191 | DO l = 1, nbgp |
---|
| 192 | DO j = nysg, nyng |
---|
| 193 | DO k = nzb, nzt+1 |
---|
[151] | 194 | |
---|
[667] | 195 | inflow_dist(k,j,1,l) = u(k,j,i+1) - avpr(k,1,l) |
---|
| 196 | inflow_dist(k,j,2,l) = v(k,j,i) - avpr(k,2,l) |
---|
| 197 | inflow_dist(k,j,3,l) = w(k,j,i) - avpr(k,3,l) |
---|
| 198 | inflow_dist(k,j,4,l) = pt(k,j,i) - avpr(k,4,l) |
---|
| 199 | inflow_dist(k,j,5,l) = e(k,j,i) - avpr(k,5,l) |
---|
[1615] | 200 | IF ( humidity .OR. passive_scalar ) & |
---|
| 201 | inflow_dist(k,j,6,l) = q(k,j,i) - avpr(k,6,l) |
---|
[667] | 202 | |
---|
| 203 | ENDDO |
---|
[222] | 204 | ENDDO |
---|
[667] | 205 | i = i + 1 |
---|
[222] | 206 | ENDDO |
---|
| 207 | #endif |
---|
| 208 | |
---|
[151] | 209 | ! |
---|
| 210 | !-- For parallel runs, send the disturbances to the respective inflow PE |
---|
| 211 | #if defined( __parallel ) |
---|
[163] | 212 | IF ( myidx == id_recycling .AND. myidx /= id_inflow ) THEN |
---|
[151] | 213 | |
---|
[1560] | 214 | CALL MPI_SEND( inflow_dist(nzb,nysg,1,1), ngp_ifd, MPI_REAL, & |
---|
[151] | 215 | id_inflow, 1, comm1dx, ierr ) |
---|
| 216 | |
---|
[163] | 217 | ELSEIF ( myidx /= id_recycling .AND. myidx == id_inflow ) THEN |
---|
[151] | 218 | |
---|
[1353] | 219 | inflow_dist = 0.0_wp |
---|
[1560] | 220 | CALL MPI_RECV( inflow_dist(nzb,nysg,1,1), ngp_ifd, MPI_REAL, & |
---|
[163] | 221 | id_recycling, 1, comm1dx, status, ierr ) |
---|
[151] | 222 | |
---|
| 223 | ENDIF |
---|
[1560] | 224 | |
---|
[1806] | 225 | ! |
---|
| 226 | !-- y-shift for inflow_dist |
---|
| 227 | !-- Shift inflow_dist in positive y direction by a distance of INT( npey / 2 ) |
---|
[1560] | 228 | IF ( recycling_yshift .AND. myidx == id_inflow ) THEN |
---|
[1806] | 229 | ! |
---|
| 230 | !-- Calculate the ID of the PE which sends data to this PE (prev) and of the |
---|
| 231 | !-- PE which receives data from this PE (next). |
---|
| 232 | IF ( myidy >= INT( pdims(2) / 2 ) ) THEN |
---|
| 233 | prev = myidy - INT( pdims(2) / 2 ) |
---|
| 234 | ELSE |
---|
| 235 | prev = pdims(2) - ( INT( pdims(2) / 2 ) - myidy ) |
---|
[1560] | 236 | ENDIF |
---|
[1806] | 237 | |
---|
| 238 | IF ( myidy < pdims(2) - INT( pdims(2) / 2 ) ) THEN |
---|
| 239 | next = myidy + INT( pdims(2) / 2 ) |
---|
| 240 | ELSE |
---|
| 241 | next = INT( pdims(2) / 2 ) - ( pdims(2) - myidy ) |
---|
| 242 | ENDIF |
---|
[1560] | 243 | |
---|
| 244 | local_inflow_dist = 0.0_wp |
---|
[1806] | 245 | |
---|
[1560] | 246 | CALL MPI_SENDRECV( inflow_dist(nzb,nysg,1,1), ngp_ifd, MPI_REAL, & |
---|
| 247 | next, 1, local_inflow_dist(nzb,nysg,1,1), ngp_ifd, & |
---|
| 248 | MPI_REAL, prev, 1, comm1dy, status, ierr ) |
---|
[1806] | 249 | |
---|
| 250 | inflow_dist = local_inflow_dist |
---|
| 251 | |
---|
[1560] | 252 | ENDIF |
---|
| 253 | |
---|
[151] | 254 | #endif |
---|
| 255 | |
---|
| 256 | ! |
---|
| 257 | !-- Add the disturbance at the inflow |
---|
| 258 | IF ( nxl == 0 ) THEN |
---|
| 259 | |
---|
[1806] | 260 | DO j = nysg, nyng |
---|
| 261 | DO k = nzb, nzt + 1 |
---|
[151] | 262 | |
---|
[1806] | 263 | u(k,j,-nbgp+1:0) = mean_inflow_profiles(k,1) + & |
---|
| 264 | inflow_dist(k,j,1,1:nbgp) * inflow_damping_factor(k) |
---|
| 265 | v(k,j,-nbgp:-1) = mean_inflow_profiles(k,2) + & |
---|
| 266 | inflow_dist(k,j,2,1:nbgp) * inflow_damping_factor(k) |
---|
| 267 | w(k,j,-nbgp:-1) = & |
---|
| 268 | inflow_dist(k,j,3,1:nbgp) * inflow_damping_factor(k) |
---|
| 269 | pt(k,j,-nbgp:-1) = mean_inflow_profiles(k,4) + & |
---|
| 270 | inflow_dist(k,j,4,1:nbgp) * inflow_damping_factor(k) |
---|
| 271 | e(k,j,-nbgp:-1) = mean_inflow_profiles(k,5) + & |
---|
| 272 | inflow_dist(k,j,5,1:nbgp) * inflow_damping_factor(k) |
---|
| 273 | e(k,j,-nbgp:-1) = MAX( e(k,j,-nbgp:-1), 0.0_wp ) |
---|
[1560] | 274 | |
---|
[1806] | 275 | IF ( humidity .OR. passive_scalar ) & |
---|
| 276 | q(k,j,-nbgp:-1) = mean_inflow_profiles(k,6) + & |
---|
| 277 | inflow_dist(k,j,6,1:nbgp) * inflow_damping_factor(k) |
---|
[1615] | 278 | |
---|
[1560] | 279 | ENDDO |
---|
[1806] | 280 | ENDDO |
---|
[1560] | 281 | |
---|
[151] | 282 | ENDIF |
---|
| 283 | |
---|
[1560] | 284 | |
---|
[151] | 285 | CALL cpu_log( log_point(40), 'inflow_turbulence', 'stop' ) |
---|
| 286 | |
---|
| 287 | |
---|
| 288 | END SUBROUTINE inflow_turbulence |
---|