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