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