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