[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 | ! ----------------- |
---|
[1354] | 21 | ! |
---|
[1807] | 22 | ! |
---|
[151] | 23 | ! Former revisions: |
---|
| 24 | ! ----------------- |
---|
| 25 | ! $Id: inflow_turbulence.f90 1818 2016-04-06 15:53:27Z raasch $ |
---|
| 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, & |
---|
[1615] | 73 | ONLY: e, inflow_damping_factor, mean_inflow_profiles, pt, q, 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 | |
---|
[1615] | 100 | REAL(wp), DIMENSION(nzb:nzt+1,6,nbgp) :: & |
---|
[1806] | 101 | avpr !< stores averaged profiles at recycling plane |
---|
| 102 | REAL(wp), DIMENSION(nzb:nzt+1,6,nbgp) :: & |
---|
| 103 | avpr_l !< auxiliary variable to calculate avpr |
---|
[1615] | 104 | REAL(wp), DIMENSION(nzb:nzt+1,nysg:nyng,6,nbgp) :: & |
---|
[1806] | 105 | inflow_dist !< turbulence signal of vars, added at inflow boundary |
---|
| 106 | REAL(wp), DIMENSION(nzb:nzt+1,nysg:nyng,6,nbgp) :: & |
---|
| 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 |
---|
[1615] | 114 | ngp_pr = ( nzt - nzb + 2 ) * 6 * 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) |
---|
[1615] | 133 | IF ( humidity .OR. passive_scalar ) & |
---|
| 134 | avpr_l(k,6,l) = avpr_l(k,6,l) + q(k,j,i) |
---|
[151] | 135 | |
---|
| 136 | ENDDO |
---|
| 137 | ENDDO |
---|
[667] | 138 | i = i + 1 |
---|
[151] | 139 | ENDDO |
---|
| 140 | |
---|
| 141 | ENDIF |
---|
| 142 | ! |
---|
| 143 | !-- Now, averaging over all PEs |
---|
[622] | 144 | IF ( collective_wait ) CALL MPI_BARRIER( comm2d, ierr ) |
---|
[1615] | 145 | CALL MPI_ALLREDUCE( avpr_l(nzb,1,1), avpr(nzb,1,1), ngp_pr, MPI_REAL, & |
---|
[709] | 146 | MPI_SUM, comm2d, ierr ) |
---|
[667] | 147 | |
---|
[151] | 148 | #else |
---|
[667] | 149 | DO l = 1, nbgp |
---|
| 150 | DO j = nys, nyn |
---|
| 151 | DO k = nzb, nzt + 1 |
---|
| 152 | |
---|
| 153 | avpr_l(k,1,l) = avpr_l(k,1,l) + u(k,j,i) |
---|
| 154 | avpr_l(k,2,l) = avpr_l(k,2,l) + v(k,j,i) |
---|
| 155 | avpr_l(k,3,l) = avpr_l(k,3,l) + w(k,j,i) |
---|
| 156 | avpr_l(k,4,l) = avpr_l(k,4,l) + pt(k,j,i) |
---|
| 157 | avpr_l(k,5,l) = avpr_l(k,5,l) + e(k,j,i) |
---|
[1615] | 158 | IF ( humidity .OR. passive_scalar ) & |
---|
| 159 | avpr_l(k,6,l) = avpr_l(k,6,l) + q(k,j,i) |
---|
[667] | 160 | |
---|
| 161 | ENDDO |
---|
| 162 | ENDDO |
---|
| 163 | i = i + 1 |
---|
| 164 | ENDDO |
---|
| 165 | |
---|
[151] | 166 | avpr = avpr_l |
---|
| 167 | #endif |
---|
| 168 | |
---|
[667] | 169 | avpr = avpr / ( ny + 1 ) |
---|
[151] | 170 | ! |
---|
| 171 | !-- Calculate the disturbances at the recycling plane |
---|
| 172 | i = recycling_plane |
---|
| 173 | |
---|
[222] | 174 | #if defined( __parallel ) |
---|
[163] | 175 | IF ( myidx == id_recycling ) THEN |
---|
[667] | 176 | DO l = 1, nbgp |
---|
| 177 | DO j = nysg, nyng |
---|
| 178 | DO k = nzb, nzt + 1 |
---|
[151] | 179 | |
---|
[667] | 180 | inflow_dist(k,j,1,l) = u(k,j,i+1) - avpr(k,1,l) |
---|
| 181 | inflow_dist(k,j,2,l) = v(k,j,i) - avpr(k,2,l) |
---|
| 182 | inflow_dist(k,j,3,l) = w(k,j,i) - avpr(k,3,l) |
---|
| 183 | inflow_dist(k,j,4,l) = pt(k,j,i) - avpr(k,4,l) |
---|
| 184 | inflow_dist(k,j,5,l) = e(k,j,i) - avpr(k,5,l) |
---|
[1615] | 185 | IF ( humidity .OR. passive_scalar ) & |
---|
| 186 | inflow_dist(k,j,6,l) = q(k,j,i) - avpr(k,6,l) |
---|
[667] | 187 | ENDDO |
---|
[151] | 188 | ENDDO |
---|
[667] | 189 | i = i + 1 |
---|
[151] | 190 | ENDDO |
---|
| 191 | |
---|
| 192 | ENDIF |
---|
[222] | 193 | #else |
---|
[667] | 194 | DO l = 1, nbgp |
---|
| 195 | DO j = nysg, nyng |
---|
| 196 | DO k = nzb, nzt+1 |
---|
[151] | 197 | |
---|
[667] | 198 | inflow_dist(k,j,1,l) = u(k,j,i+1) - avpr(k,1,l) |
---|
| 199 | inflow_dist(k,j,2,l) = v(k,j,i) - avpr(k,2,l) |
---|
| 200 | inflow_dist(k,j,3,l) = w(k,j,i) - avpr(k,3,l) |
---|
| 201 | inflow_dist(k,j,4,l) = pt(k,j,i) - avpr(k,4,l) |
---|
| 202 | inflow_dist(k,j,5,l) = e(k,j,i) - avpr(k,5,l) |
---|
[1615] | 203 | IF ( humidity .OR. passive_scalar ) & |
---|
| 204 | inflow_dist(k,j,6,l) = q(k,j,i) - avpr(k,6,l) |
---|
[667] | 205 | |
---|
| 206 | ENDDO |
---|
[222] | 207 | ENDDO |
---|
[667] | 208 | i = i + 1 |
---|
[222] | 209 | ENDDO |
---|
| 210 | #endif |
---|
| 211 | |
---|
[151] | 212 | ! |
---|
| 213 | !-- For parallel runs, send the disturbances to the respective inflow PE |
---|
| 214 | #if defined( __parallel ) |
---|
[163] | 215 | IF ( myidx == id_recycling .AND. myidx /= id_inflow ) THEN |
---|
[151] | 216 | |
---|
[1560] | 217 | CALL MPI_SEND( inflow_dist(nzb,nysg,1,1), ngp_ifd, MPI_REAL, & |
---|
[151] | 218 | id_inflow, 1, comm1dx, ierr ) |
---|
| 219 | |
---|
[163] | 220 | ELSEIF ( myidx /= id_recycling .AND. myidx == id_inflow ) THEN |
---|
[151] | 221 | |
---|
[1353] | 222 | inflow_dist = 0.0_wp |
---|
[1560] | 223 | CALL MPI_RECV( inflow_dist(nzb,nysg,1,1), ngp_ifd, MPI_REAL, & |
---|
[163] | 224 | id_recycling, 1, comm1dx, status, ierr ) |
---|
[151] | 225 | |
---|
| 226 | ENDIF |
---|
[1560] | 227 | |
---|
[1806] | 228 | ! |
---|
| 229 | !-- y-shift for inflow_dist |
---|
| 230 | !-- Shift inflow_dist in positive y direction by a distance of INT( npey / 2 ) |
---|
[1560] | 231 | IF ( recycling_yshift .AND. myidx == id_inflow ) THEN |
---|
[1806] | 232 | ! |
---|
| 233 | !-- Calculate the ID of the PE which sends data to this PE (prev) and of the |
---|
| 234 | !-- PE which receives data from this PE (next). |
---|
| 235 | IF ( myidy >= INT( pdims(2) / 2 ) ) THEN |
---|
| 236 | prev = myidy - INT( pdims(2) / 2 ) |
---|
| 237 | ELSE |
---|
| 238 | prev = pdims(2) - ( INT( pdims(2) / 2 ) - myidy ) |
---|
[1560] | 239 | ENDIF |
---|
[1806] | 240 | |
---|
| 241 | IF ( myidy < pdims(2) - INT( pdims(2) / 2 ) ) THEN |
---|
| 242 | next = myidy + INT( pdims(2) / 2 ) |
---|
| 243 | ELSE |
---|
| 244 | next = INT( pdims(2) / 2 ) - ( pdims(2) - myidy ) |
---|
| 245 | ENDIF |
---|
[1560] | 246 | |
---|
| 247 | local_inflow_dist = 0.0_wp |
---|
[1806] | 248 | |
---|
[1560] | 249 | CALL MPI_SENDRECV( inflow_dist(nzb,nysg,1,1), ngp_ifd, MPI_REAL, & |
---|
| 250 | next, 1, local_inflow_dist(nzb,nysg,1,1), ngp_ifd, & |
---|
| 251 | MPI_REAL, prev, 1, comm1dy, status, ierr ) |
---|
[1806] | 252 | |
---|
| 253 | inflow_dist = local_inflow_dist |
---|
| 254 | |
---|
[1560] | 255 | ENDIF |
---|
| 256 | |
---|
[151] | 257 | #endif |
---|
| 258 | |
---|
| 259 | ! |
---|
| 260 | !-- Add the disturbance at the inflow |
---|
| 261 | IF ( nxl == 0 ) THEN |
---|
| 262 | |
---|
[1806] | 263 | DO j = nysg, nyng |
---|
| 264 | DO k = nzb, nzt + 1 |
---|
[151] | 265 | |
---|
[1806] | 266 | u(k,j,-nbgp+1:0) = mean_inflow_profiles(k,1) + & |
---|
| 267 | inflow_dist(k,j,1,1:nbgp) * inflow_damping_factor(k) |
---|
| 268 | v(k,j,-nbgp:-1) = mean_inflow_profiles(k,2) + & |
---|
| 269 | inflow_dist(k,j,2,1:nbgp) * inflow_damping_factor(k) |
---|
| 270 | w(k,j,-nbgp:-1) = & |
---|
| 271 | inflow_dist(k,j,3,1:nbgp) * inflow_damping_factor(k) |
---|
| 272 | pt(k,j,-nbgp:-1) = mean_inflow_profiles(k,4) + & |
---|
| 273 | inflow_dist(k,j,4,1:nbgp) * inflow_damping_factor(k) |
---|
| 274 | e(k,j,-nbgp:-1) = mean_inflow_profiles(k,5) + & |
---|
| 275 | inflow_dist(k,j,5,1:nbgp) * inflow_damping_factor(k) |
---|
| 276 | e(k,j,-nbgp:-1) = MAX( e(k,j,-nbgp:-1), 0.0_wp ) |
---|
[1560] | 277 | |
---|
[1806] | 278 | IF ( humidity .OR. passive_scalar ) & |
---|
| 279 | q(k,j,-nbgp:-1) = mean_inflow_profiles(k,6) + & |
---|
| 280 | inflow_dist(k,j,6,1:nbgp) * inflow_damping_factor(k) |
---|
[1615] | 281 | |
---|
[1560] | 282 | ENDDO |
---|
[1806] | 283 | ENDDO |
---|
[1560] | 284 | |
---|
[151] | 285 | ENDIF |
---|
| 286 | |
---|
[1560] | 287 | |
---|
[151] | 288 | CALL cpu_log( log_point(40), 'inflow_turbulence', 'stop' ) |
---|
| 289 | |
---|
| 290 | |
---|
| 291 | END SUBROUTINE inflow_turbulence |
---|