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