1 | !> @file inflow_turbulence.f90 |
---|
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 | ! |
---|
16 | ! Copyright 1997-2014 Leibniz Universitaet Hannover |
---|
17 | !--------------------------------------------------------------------------------! |
---|
18 | ! |
---|
19 | ! Current revisions: |
---|
20 | ! ----------------- |
---|
21 | ! |
---|
22 | ! |
---|
23 | ! Former revisions: |
---|
24 | ! ----------------- |
---|
25 | ! $Id: inflow_turbulence.f90 1683 2015-10-07 23:57:51Z maronga $ |
---|
26 | ! |
---|
27 | ! 1682 2015-10-07 23:56:08Z knoop |
---|
28 | ! Code annotations made doxygen readable |
---|
29 | ! |
---|
30 | ! 1615 2015-07-08 18:49:19Z suehring |
---|
31 | ! Enable turbulent inflow for passive_scalar and humidity |
---|
32 | ! |
---|
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 | ! |
---|
38 | ! 1353 2014-04-08 15:21:23Z heinze |
---|
39 | ! REAL constants provided with KIND-attribute |
---|
40 | ! |
---|
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 | ! |
---|
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 | ! |
---|
53 | ! 1092 2013-02-02 11:24:22Z raasch |
---|
54 | ! unused variables removed |
---|
55 | ! |
---|
56 | ! 1036 2012-10-22 13:43:42Z raasch |
---|
57 | ! code put under GPL (PALM 3.9) |
---|
58 | ! |
---|
59 | ! Initial version (2008/03/07) |
---|
60 | ! |
---|
61 | ! Description: |
---|
62 | ! ------------ |
---|
63 | !> Imposing turbulence at the respective inflow using the turbulence |
---|
64 | !> recycling method of Kataoka and Mizuno (2002). |
---|
65 | !------------------------------------------------------------------------------! |
---|
66 | SUBROUTINE inflow_turbulence |
---|
67 | |
---|
68 | |
---|
69 | USE arrays_3d, & |
---|
70 | ONLY: e, inflow_damping_factor, mean_inflow_profiles, pt, q, u, v, w |
---|
71 | |
---|
72 | USE control_parameters, & |
---|
73 | ONLY: humidity, passive_scalar, recycling_plane, recycling_yshift |
---|
74 | |
---|
75 | USE cpulog, & |
---|
76 | ONLY: cpu_log, log_point |
---|
77 | |
---|
78 | USE grid_variables, & |
---|
79 | ONLY: |
---|
80 | |
---|
81 | USE indices, & |
---|
82 | ONLY: nbgp, nxl, ny, nyn, nys, nyng, nysg, nzb, nzt |
---|
83 | |
---|
84 | USE kinds |
---|
85 | |
---|
86 | USE pegrid |
---|
87 | |
---|
88 | |
---|
89 | IMPLICIT NONE |
---|
90 | |
---|
91 | INTEGER(iwp) :: i !< |
---|
92 | INTEGER(iwp) :: j !< |
---|
93 | INTEGER(iwp) :: k !< |
---|
94 | INTEGER(iwp) :: l !< |
---|
95 | INTEGER(iwp) :: next !< |
---|
96 | INTEGER(iwp) :: ngp_ifd !< |
---|
97 | INTEGER(iwp) :: ngp_pr !< |
---|
98 | INTEGER(iwp) :: prev !< |
---|
99 | |
---|
100 | REAL(wp), DIMENSION(nzb:nzt+1,6,nbgp) :: & |
---|
101 | avpr, avpr_l !< |
---|
102 | REAL(wp), DIMENSION(nzb:nzt+1,nysg:nyng,6,nbgp) :: & |
---|
103 | inflow_dist, local_inflow_dist !< |
---|
104 | |
---|
105 | CALL cpu_log( log_point(40), 'inflow_turbulence', 'start' ) |
---|
106 | |
---|
107 | ! |
---|
108 | !-- Carry out spanwise averaging in the recycling plane |
---|
109 | avpr_l = 0.0_wp |
---|
110 | ngp_pr = ( nzt - nzb + 2 ) * 6 * nbgp |
---|
111 | ngp_ifd = ngp_pr * ( nyn - nys + 1 + 2 * nbgp ) |
---|
112 | |
---|
113 | ! |
---|
114 | !-- First, local averaging within the recycling domain |
---|
115 | i = recycling_plane |
---|
116 | |
---|
117 | #if defined( __parallel ) |
---|
118 | IF ( myidx == id_recycling ) THEN |
---|
119 | |
---|
120 | DO l = 1, nbgp |
---|
121 | DO j = nys, nyn |
---|
122 | DO k = nzb, nzt + 1 |
---|
123 | |
---|
124 | avpr_l(k,1,l) = avpr_l(k,1,l) + u(k,j,i) |
---|
125 | avpr_l(k,2,l) = avpr_l(k,2,l) + v(k,j,i) |
---|
126 | avpr_l(k,3,l) = avpr_l(k,3,l) + w(k,j,i) |
---|
127 | avpr_l(k,4,l) = avpr_l(k,4,l) + pt(k,j,i) |
---|
128 | avpr_l(k,5,l) = avpr_l(k,5,l) + e(k,j,i) |
---|
129 | IF ( humidity .OR. passive_scalar ) & |
---|
130 | avpr_l(k,6,l) = avpr_l(k,6,l) + q(k,j,i) |
---|
131 | |
---|
132 | ENDDO |
---|
133 | ENDDO |
---|
134 | i = i + 1 |
---|
135 | ENDDO |
---|
136 | |
---|
137 | ENDIF |
---|
138 | ! |
---|
139 | !-- Now, averaging over all PEs |
---|
140 | IF ( collective_wait ) CALL MPI_BARRIER( comm2d, ierr ) |
---|
141 | CALL MPI_ALLREDUCE( avpr_l(nzb,1,1), avpr(nzb,1,1), ngp_pr, MPI_REAL, & |
---|
142 | MPI_SUM, comm2d, ierr ) |
---|
143 | |
---|
144 | #else |
---|
145 | DO l = 1, nbgp |
---|
146 | DO j = nys, nyn |
---|
147 | DO k = nzb, nzt + 1 |
---|
148 | |
---|
149 | avpr_l(k,1,l) = avpr_l(k,1,l) + u(k,j,i) |
---|
150 | avpr_l(k,2,l) = avpr_l(k,2,l) + v(k,j,i) |
---|
151 | avpr_l(k,3,l) = avpr_l(k,3,l) + w(k,j,i) |
---|
152 | avpr_l(k,4,l) = avpr_l(k,4,l) + pt(k,j,i) |
---|
153 | avpr_l(k,5,l) = avpr_l(k,5,l) + e(k,j,i) |
---|
154 | IF ( humidity .OR. passive_scalar ) & |
---|
155 | avpr_l(k,6,l) = avpr_l(k,6,l) + q(k,j,i) |
---|
156 | |
---|
157 | ENDDO |
---|
158 | ENDDO |
---|
159 | i = i + 1 |
---|
160 | ENDDO |
---|
161 | |
---|
162 | avpr = avpr_l |
---|
163 | #endif |
---|
164 | |
---|
165 | avpr = avpr / ( ny + 1 ) |
---|
166 | ! |
---|
167 | !-- Calculate the disturbances at the recycling plane |
---|
168 | i = recycling_plane |
---|
169 | |
---|
170 | #if defined( __parallel ) |
---|
171 | IF ( myidx == id_recycling ) THEN |
---|
172 | DO l = 1, nbgp |
---|
173 | DO j = nysg, nyng |
---|
174 | DO k = nzb, nzt + 1 |
---|
175 | |
---|
176 | inflow_dist(k,j,1,l) = u(k,j,i+1) - avpr(k,1,l) |
---|
177 | inflow_dist(k,j,2,l) = v(k,j,i) - avpr(k,2,l) |
---|
178 | inflow_dist(k,j,3,l) = w(k,j,i) - avpr(k,3,l) |
---|
179 | inflow_dist(k,j,4,l) = pt(k,j,i) - avpr(k,4,l) |
---|
180 | inflow_dist(k,j,5,l) = e(k,j,i) - avpr(k,5,l) |
---|
181 | IF ( humidity .OR. passive_scalar ) & |
---|
182 | inflow_dist(k,j,6,l) = q(k,j,i) - avpr(k,6,l) |
---|
183 | ENDDO |
---|
184 | ENDDO |
---|
185 | i = i + 1 |
---|
186 | ENDDO |
---|
187 | |
---|
188 | ENDIF |
---|
189 | #else |
---|
190 | DO l = 1, nbgp |
---|
191 | DO j = nysg, nyng |
---|
192 | DO k = nzb, nzt+1 |
---|
193 | |
---|
194 | inflow_dist(k,j,1,l) = u(k,j,i+1) - avpr(k,1,l) |
---|
195 | inflow_dist(k,j,2,l) = v(k,j,i) - avpr(k,2,l) |
---|
196 | inflow_dist(k,j,3,l) = w(k,j,i) - avpr(k,3,l) |
---|
197 | inflow_dist(k,j,4,l) = pt(k,j,i) - avpr(k,4,l) |
---|
198 | inflow_dist(k,j,5,l) = e(k,j,i) - avpr(k,5,l) |
---|
199 | IF ( humidity .OR. passive_scalar ) & |
---|
200 | inflow_dist(k,j,6,l) = q(k,j,i) - avpr(k,6,l) |
---|
201 | |
---|
202 | ENDDO |
---|
203 | ENDDO |
---|
204 | i = i + 1 |
---|
205 | ENDDO |
---|
206 | #endif |
---|
207 | |
---|
208 | ! |
---|
209 | !-- For parallel runs, send the disturbances to the respective inflow PE |
---|
210 | #if defined( __parallel ) |
---|
211 | IF ( myidx == id_recycling .AND. myidx /= id_inflow ) THEN |
---|
212 | |
---|
213 | CALL MPI_SEND( inflow_dist(nzb,nysg,1,1), ngp_ifd, MPI_REAL, & |
---|
214 | id_inflow, 1, comm1dx, ierr ) |
---|
215 | |
---|
216 | ELSEIF ( myidx /= id_recycling .AND. myidx == id_inflow ) THEN |
---|
217 | |
---|
218 | inflow_dist = 0.0_wp |
---|
219 | CALL MPI_RECV( inflow_dist(nzb,nysg,1,1), ngp_ifd, MPI_REAL, & |
---|
220 | id_recycling, 1, comm1dx, status, ierr ) |
---|
221 | |
---|
222 | ENDIF |
---|
223 | |
---|
224 | |
---|
225 | IF ( recycling_yshift .AND. myidx == id_inflow ) THEN |
---|
226 | |
---|
227 | IF ( pdims(2) >= 2 ) THEN |
---|
228 | |
---|
229 | IF ( myidy >= INT( pdims(2) / 2 ) ) THEN |
---|
230 | prev = myidy - INT( pdims(2) / 2 ) |
---|
231 | ELSE |
---|
232 | prev = pdims(2) - ( INT( pdims(2) / 2 ) - myidy ) |
---|
233 | ENDIF |
---|
234 | |
---|
235 | IF ( myidy < pdims(2) - INT( pdims(2) / 2 ) ) THEN |
---|
236 | next = myidy + INT( pdims(2) / 2 ) |
---|
237 | ELSE |
---|
238 | next = INT( pdims(2) / 2 ) - ( pdims(2) - myidy ) |
---|
239 | ENDIF |
---|
240 | |
---|
241 | ENDIF |
---|
242 | |
---|
243 | local_inflow_dist = 0.0_wp |
---|
244 | |
---|
245 | CALL MPI_SENDRECV( inflow_dist(nzb,nysg,1,1), ngp_ifd, MPI_REAL, & |
---|
246 | next, 1, local_inflow_dist(nzb,nysg,1,1), ngp_ifd, & |
---|
247 | MPI_REAL, prev, 1, comm1dy, status, ierr ) |
---|
248 | |
---|
249 | ENDIF |
---|
250 | |
---|
251 | #endif |
---|
252 | |
---|
253 | ! |
---|
254 | !-- Add the disturbance at the inflow |
---|
255 | IF ( nxl == 0 ) THEN |
---|
256 | |
---|
257 | IF ( recycling_yshift ) THEN |
---|
258 | |
---|
259 | DO j = nysg, nyng |
---|
260 | DO k = nzb, nzt + 1 |
---|
261 | |
---|
262 | u(k,j,-nbgp+1:0) = mean_inflow_profiles(k,1) + & |
---|
263 | local_inflow_dist(k,j,1,1:nbgp) * & |
---|
264 | inflow_damping_factor(k) |
---|
265 | v(k,j,-nbgp:-1) = mean_inflow_profiles(k,2) + & |
---|
266 | local_inflow_dist(k,j,2,1:nbgp) * & |
---|
267 | inflow_damping_factor(k) |
---|
268 | w(k,j,-nbgp:-1) = & |
---|
269 | local_inflow_dist(k,j,3,1:nbgp) * & |
---|
270 | inflow_damping_factor(k) |
---|
271 | pt(k,j,-nbgp:-1) = mean_inflow_profiles(k,4) + & |
---|
272 | local_inflow_dist(k,j,4,1:nbgp) * & |
---|
273 | inflow_damping_factor(k) |
---|
274 | e(k,j,-nbgp:-1) = mean_inflow_profiles(k,5) + & |
---|
275 | local_inflow_dist(k,j,5,1:nbgp) * & |
---|
276 | inflow_damping_factor(k) |
---|
277 | e(k,j,-nbgp:-1) = MAX( e(k,j,-nbgp:-1), 0.0_wp ) |
---|
278 | |
---|
279 | IF ( humidity .OR. passive_scalar ) & |
---|
280 | q(k,j,-nbgp:-1) = mean_inflow_profiles(k,6) + & |
---|
281 | local_inflow_dist(k,j,6,1:nbgp) * & |
---|
282 | inflow_damping_factor(k) |
---|
283 | |
---|
284 | ENDDO |
---|
285 | ENDDO |
---|
286 | |
---|
287 | ELSE |
---|
288 | |
---|
289 | DO j = nysg, nyng |
---|
290 | DO k = nzb, nzt + 1 |
---|
291 | |
---|
292 | u(k,j,-nbgp+1:0) = mean_inflow_profiles(k,1) + & |
---|
293 | inflow_dist(k,j,1,1:nbgp) * inflow_damping_factor(k) |
---|
294 | v(k,j,-nbgp:-1) = mean_inflow_profiles(k,2) + & |
---|
295 | inflow_dist(k,j,2,1:nbgp) * inflow_damping_factor(k) |
---|
296 | w(k,j,-nbgp:-1) = & |
---|
297 | inflow_dist(k,j,3,1:nbgp) * inflow_damping_factor(k) |
---|
298 | pt(k,j,-nbgp:-1) = mean_inflow_profiles(k,4) + & |
---|
299 | inflow_dist(k,j,4,1:nbgp) * inflow_damping_factor(k) |
---|
300 | e(k,j,-nbgp:-1) = mean_inflow_profiles(k,5) + & |
---|
301 | inflow_dist(k,j,5,1:nbgp) * inflow_damping_factor(k) |
---|
302 | e(k,j,-nbgp:-1) = MAX( e(k,j,-nbgp:-1), 0.0_wp ) |
---|
303 | |
---|
304 | IF ( humidity .OR. passive_scalar ) & |
---|
305 | q(k,j,-nbgp:-1) = mean_inflow_profiles(k,6) + & |
---|
306 | inflow_dist(k,j,6,1:nbgp) * inflow_damping_factor(k) |
---|
307 | |
---|
308 | ENDDO |
---|
309 | ENDDO |
---|
310 | |
---|
311 | ENDIF |
---|
312 | |
---|
313 | ENDIF |
---|
314 | |
---|
315 | |
---|
316 | CALL cpu_log( log_point(40), 'inflow_turbulence', 'stop' ) |
---|
317 | |
---|
318 | |
---|
319 | END SUBROUTINE inflow_turbulence |
---|