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