1 | !> @file inflow_turbulence.f90 |
---|
2 | !------------------------------------------------------------------------------! |
---|
3 | ! This file is part of the PALM model system. |
---|
4 | ! |
---|
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. |
---|
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-2019 Leibniz Universitaet Hannover |
---|
18 | !------------------------------------------------------------------------------! |
---|
19 | ! |
---|
20 | ! Current revisions: |
---|
21 | ! ----------------- |
---|
22 | ! |
---|
23 | ! |
---|
24 | ! Former revisions: |
---|
25 | ! ----------------- |
---|
26 | ! $Id: inflow_turbulence.f90 4301 2019-11-22 12:09:09Z motisi $ |
---|
27 | ! use y_shift instead of old parameter recycling_yshift |
---|
28 | ! |
---|
29 | ! 4297 2019-11-21 10:37:50Z oliver.maas |
---|
30 | ! changed recycling_yshift so that the y-shift can be a multiple of PE |
---|
31 | ! instead of y-shift of a half domain width |
---|
32 | ! |
---|
33 | ! 4183 2019-08-23 07:33:16Z oliver.maas |
---|
34 | ! simplified steering of recycling of absolute values by initialization |
---|
35 | ! parameter recycling_method_for_thermodynamic_quantities |
---|
36 | ! |
---|
37 | ! 4182 2019-08-22 15:20:23Z scharf |
---|
38 | ! Corrected "Former revisions" section |
---|
39 | ! |
---|
40 | ! 4172 2019-08-20 11:55:33Z oliver.maas |
---|
41 | ! added optional recycling of absolute values for pt and q |
---|
42 | ! |
---|
43 | ! 3655 2019-01-07 16:51:22Z knoop |
---|
44 | ! Corrected "Former revisions" section |
---|
45 | ! |
---|
46 | ! Initial version (2008/03/07) |
---|
47 | ! |
---|
48 | ! Description: |
---|
49 | ! ------------ |
---|
50 | !> Imposing turbulence at the respective inflow using the turbulence |
---|
51 | !> recycling method of Kataoka and Mizuno (2002). |
---|
52 | !------------------------------------------------------------------------------! |
---|
53 | SUBROUTINE inflow_turbulence |
---|
54 | |
---|
55 | |
---|
56 | USE arrays_3d, & |
---|
57 | ONLY: e, inflow_damping_factor, mean_inflow_profiles, pt, q, s, u, v, w |
---|
58 | |
---|
59 | USE control_parameters, & |
---|
60 | ONLY: humidity, passive_scalar, recycling_plane, y_shift, & |
---|
61 | recycling_method_for_thermodynamic_quantities |
---|
62 | |
---|
63 | USE cpulog, & |
---|
64 | ONLY: cpu_log, log_point |
---|
65 | |
---|
66 | USE indices, & |
---|
67 | ONLY: nbgp, nxl, ny, nyn, nys, nyng, nysg, nzb, nzt |
---|
68 | |
---|
69 | USE kinds |
---|
70 | |
---|
71 | USE pegrid |
---|
72 | |
---|
73 | |
---|
74 | IMPLICIT NONE |
---|
75 | |
---|
76 | INTEGER(iwp) :: i !< loop index |
---|
77 | INTEGER(iwp) :: j !< loop index |
---|
78 | INTEGER(iwp) :: k !< loop index |
---|
79 | INTEGER(iwp) :: l !< loop index |
---|
80 | INTEGER(iwp) :: next !< ID of receiving PE for y-shift |
---|
81 | INTEGER(iwp) :: ngp_ifd !< number of grid points stored in avpr |
---|
82 | INTEGER(iwp) :: ngp_pr !< number of grid points stored in inflow_dist |
---|
83 | INTEGER(iwp) :: prev !< ID of sending PE for y-shift |
---|
84 | |
---|
85 | REAL(wp), DIMENSION(nzb:nzt+1,7,nbgp) :: & |
---|
86 | avpr !< stores averaged profiles at recycling plane |
---|
87 | REAL(wp), DIMENSION(nzb:nzt+1,7,nbgp) :: & |
---|
88 | avpr_l !< auxiliary variable to calculate avpr |
---|
89 | REAL(wp), DIMENSION(nzb:nzt+1,nysg:nyng,7,nbgp) :: & |
---|
90 | inflow_dist !< turbulence signal of vars, added at inflow boundary |
---|
91 | REAL(wp), DIMENSION(nzb:nzt+1,nysg:nyng,7,nbgp) :: & |
---|
92 | local_inflow_dist !< auxiliary variable for inflow_dist, used for y-shift |
---|
93 | |
---|
94 | CALL cpu_log( log_point(40), 'inflow_turbulence', 'start' ) |
---|
95 | |
---|
96 | ! |
---|
97 | !-- Carry out spanwise averaging in the recycling plane |
---|
98 | avpr_l = 0.0_wp |
---|
99 | ngp_pr = ( nzt - nzb + 2 ) * 7 * nbgp |
---|
100 | ngp_ifd = ngp_pr * ( nyn - nys + 1 + 2 * nbgp ) |
---|
101 | |
---|
102 | ! |
---|
103 | !-- First, local averaging within the recycling domain |
---|
104 | i = recycling_plane |
---|
105 | |
---|
106 | #if defined( __parallel ) |
---|
107 | IF ( myidx == id_recycling ) THEN |
---|
108 | |
---|
109 | DO l = 1, nbgp |
---|
110 | DO j = nys, nyn |
---|
111 | DO k = nzb, nzt + 1 |
---|
112 | |
---|
113 | avpr_l(k,1,l) = avpr_l(k,1,l) + u(k,j,i) |
---|
114 | avpr_l(k,2,l) = avpr_l(k,2,l) + v(k,j,i) |
---|
115 | avpr_l(k,3,l) = avpr_l(k,3,l) + w(k,j,i) |
---|
116 | avpr_l(k,4,l) = avpr_l(k,4,l) + pt(k,j,i) |
---|
117 | avpr_l(k,5,l) = avpr_l(k,5,l) + e(k,j,i) |
---|
118 | IF ( humidity ) & |
---|
119 | avpr_l(k,6,l) = avpr_l(k,6,l) + q(k,j,i) |
---|
120 | IF ( passive_scalar ) & |
---|
121 | avpr_l(k,7,l) = avpr_l(k,7,l) + s(k,j,i) |
---|
122 | |
---|
123 | ENDDO |
---|
124 | ENDDO |
---|
125 | i = i + 1 |
---|
126 | ENDDO |
---|
127 | |
---|
128 | ENDIF |
---|
129 | ! |
---|
130 | !-- Now, averaging over all PEs |
---|
131 | IF ( collective_wait ) CALL MPI_BARRIER( comm2d, ierr ) |
---|
132 | CALL MPI_ALLREDUCE( avpr_l(nzb,1,1), avpr(nzb,1,1), ngp_pr, MPI_REAL, & |
---|
133 | MPI_SUM, comm2d, ierr ) |
---|
134 | |
---|
135 | #else |
---|
136 | DO l = 1, nbgp |
---|
137 | DO j = nys, nyn |
---|
138 | DO k = nzb, nzt + 1 |
---|
139 | |
---|
140 | avpr_l(k,1,l) = avpr_l(k,1,l) + u(k,j,i) |
---|
141 | avpr_l(k,2,l) = avpr_l(k,2,l) + v(k,j,i) |
---|
142 | avpr_l(k,3,l) = avpr_l(k,3,l) + w(k,j,i) |
---|
143 | avpr_l(k,4,l) = avpr_l(k,4,l) + pt(k,j,i) |
---|
144 | avpr_l(k,5,l) = avpr_l(k,5,l) + e(k,j,i) |
---|
145 | IF ( humidity ) & |
---|
146 | avpr_l(k,6,l) = avpr_l(k,6,l) + q(k,j,i) |
---|
147 | IF ( passive_scalar ) & |
---|
148 | avpr_l(k,7,l) = avpr_l(k,7,l) + s(k,j,i) |
---|
149 | |
---|
150 | ENDDO |
---|
151 | ENDDO |
---|
152 | i = i + 1 |
---|
153 | ENDDO |
---|
154 | |
---|
155 | avpr = avpr_l |
---|
156 | #endif |
---|
157 | |
---|
158 | avpr = avpr / ( ny + 1 ) |
---|
159 | ! |
---|
160 | !-- Calculate the disturbances at the recycling plane |
---|
161 | !-- for recycling of absolute quantities, the disturbance is defined as the absolute value |
---|
162 | !-- (and not as the deviation from the mean profile) |
---|
163 | i = recycling_plane |
---|
164 | |
---|
165 | #if defined( __parallel ) |
---|
166 | IF ( myidx == id_recycling ) THEN |
---|
167 | DO l = 1, nbgp |
---|
168 | DO j = nysg, nyng |
---|
169 | DO k = nzb, nzt + 1 |
---|
170 | inflow_dist(k,j,1,l) = u(k,j,i+1) - avpr(k,1,l) |
---|
171 | inflow_dist(k,j,2,l) = v(k,j,i) - avpr(k,2,l) |
---|
172 | inflow_dist(k,j,3,l) = w(k,j,i) - avpr(k,3,l) |
---|
173 | IF ( TRIM( recycling_method_for_thermodynamic_quantities ) & |
---|
174 | == 'turbulent_fluctuation' ) THEN |
---|
175 | inflow_dist(k,j,4,l) = pt(k,j,i) - avpr(k,4,l) |
---|
176 | ELSEIF ( TRIM( recycling_method_for_thermodynamic_quantities ) & |
---|
177 | == 'absolute_value' ) THEN |
---|
178 | inflow_dist(k,j,4,l) = pt(k,j,i) |
---|
179 | ENDIF |
---|
180 | inflow_dist(k,j,5,l) = e(k,j,i) - avpr(k,5,l) |
---|
181 | IF ( humidity ) THEN |
---|
182 | IF ( TRIM( recycling_method_for_thermodynamic_quantities ) & |
---|
183 | == 'turbulent_fluctuation' ) THEN |
---|
184 | inflow_dist(k,j,6,l) = q(k,j,i) - avpr(k,6,l) |
---|
185 | ELSEIF ( TRIM( recycling_method_for_thermodynamic_quantities ) & |
---|
186 | == 'absolute_value' ) THEN |
---|
187 | inflow_dist(k,j,6,l) = q(k,j,i) |
---|
188 | ENDIF |
---|
189 | ENDIF |
---|
190 | IF ( passive_scalar ) & |
---|
191 | inflow_dist(k,j,7,l) = s(k,j,i) - avpr(k,7,l) |
---|
192 | ENDDO |
---|
193 | ENDDO |
---|
194 | i = i + 1 |
---|
195 | ENDDO |
---|
196 | |
---|
197 | ENDIF |
---|
198 | #else |
---|
199 | DO l = 1, nbgp |
---|
200 | DO j = nysg, nyng |
---|
201 | DO k = nzb, nzt+1 |
---|
202 | inflow_dist(k,j,1,l) = u(k,j,i+1) - avpr(k,1,l) |
---|
203 | inflow_dist(k,j,2,l) = v(k,j,i) - avpr(k,2,l) |
---|
204 | inflow_dist(k,j,3,l) = w(k,j,i) - avpr(k,3,l) |
---|
205 | IF ( TRIM( recycling_method_for_thermodynamic_quantities ) & |
---|
206 | == 'turbulent_fluctuation' ) THEN |
---|
207 | inflow_dist(k,j,4,l) = pt(k,j,i) - avpr(k,4,l) |
---|
208 | ELSEIF ( TRIM( recycling_method_for_thermodynamic_quantities ) & |
---|
209 | == 'absolute_value' ) THEN |
---|
210 | inflow_dist(k,j,4,l) = pt(k,j,i) |
---|
211 | ENDIF |
---|
212 | inflow_dist(k,j,5,l) = e(k,j,i) - avpr(k,5,l) |
---|
213 | IF ( humidity ) THEN |
---|
214 | IF ( TRIM( recycling_method_for_thermodynamic_quantities ) & |
---|
215 | == 'turbulent_fluctuation' ) THEN |
---|
216 | inflow_dist(k,j,6,l) = q(k,j,i) - avpr(k,6,l) |
---|
217 | ELSEIF ( TRIM( recycling_method_for_thermodynamic_quantities ) & |
---|
218 | == 'absolute_value' ) THEN |
---|
219 | inflow_dist(k,j,6,l) = q(k,j,i) |
---|
220 | ENDIF |
---|
221 | ENDIF |
---|
222 | IF ( passive_scalar ) & |
---|
223 | inflow_dist(k,j,7,l) = s(k,j,i) - avpr(k,7,l) |
---|
224 | |
---|
225 | ENDDO |
---|
226 | ENDDO |
---|
227 | i = i + 1 |
---|
228 | ENDDO |
---|
229 | #endif |
---|
230 | |
---|
231 | ! |
---|
232 | !-- For parallel runs, send the disturbances to the respective inflow PE |
---|
233 | #if defined( __parallel ) |
---|
234 | IF ( myidx == id_recycling .AND. myidx /= id_inflow ) THEN |
---|
235 | |
---|
236 | CALL MPI_SEND( inflow_dist(nzb,nysg,1,1), ngp_ifd, MPI_REAL, & |
---|
237 | id_inflow, 1, comm1dx, ierr ) |
---|
238 | |
---|
239 | ELSEIF ( myidx /= id_recycling .AND. myidx == id_inflow ) THEN |
---|
240 | |
---|
241 | inflow_dist = 0.0_wp |
---|
242 | CALL MPI_RECV( inflow_dist(nzb,nysg,1,1), ngp_ifd, MPI_REAL, & |
---|
243 | id_recycling, 1, comm1dx, status, ierr ) |
---|
244 | |
---|
245 | ENDIF |
---|
246 | |
---|
247 | ! |
---|
248 | !-- y-shift for inflow_dist |
---|
249 | !-- Shift inflow_dist in positive y direction by a number of |
---|
250 | !-- PEs equal to y_shift |
---|
251 | IF ( ( y_shift /= 0 ) .AND. myidx == id_inflow ) THEN |
---|
252 | |
---|
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 | prev = MODULO(myidy - y_shift , pdims(2)) |
---|
257 | next = MODULO(myidy + y_shift , pdims(2)) |
---|
258 | |
---|
259 | local_inflow_dist = 0.0_wp |
---|
260 | |
---|
261 | CALL MPI_SENDRECV( inflow_dist(nzb,nysg,1,1), ngp_ifd, MPI_REAL, & |
---|
262 | next, 1, local_inflow_dist(nzb,nysg,1,1), ngp_ifd, & |
---|
263 | MPI_REAL, prev, 1, comm1dy, status, ierr ) |
---|
264 | |
---|
265 | inflow_dist = local_inflow_dist |
---|
266 | |
---|
267 | ENDIF |
---|
268 | |
---|
269 | #endif |
---|
270 | |
---|
271 | ! |
---|
272 | !-- Add the disturbance at the inflow |
---|
273 | IF ( nxl == 0 ) THEN |
---|
274 | |
---|
275 | DO j = nysg, nyng |
---|
276 | DO k = nzb, nzt + 1 |
---|
277 | |
---|
278 | u(k,j,-nbgp+1:0) = mean_inflow_profiles(k,1) + & |
---|
279 | inflow_dist(k,j,1,1:nbgp) * inflow_damping_factor(k) |
---|
280 | v(k,j,-nbgp:-1) = mean_inflow_profiles(k,2) + & |
---|
281 | inflow_dist(k,j,2,1:nbgp) * inflow_damping_factor(k) |
---|
282 | w(k,j,-nbgp:-1) = & |
---|
283 | inflow_dist(k,j,3,1:nbgp) * inflow_damping_factor(k) |
---|
284 | IF ( TRIM( recycling_method_for_thermodynamic_quantities ) & |
---|
285 | == 'turbulent_fluctuation' ) THEN |
---|
286 | pt(k,j,-nbgp:-1) = mean_inflow_profiles(k,4) + & |
---|
287 | inflow_dist(k,j,4,1:nbgp) * inflow_damping_factor(k) |
---|
288 | ELSEIF ( TRIM( recycling_method_for_thermodynamic_quantities ) & |
---|
289 | == 'absolute_value' ) THEN |
---|
290 | pt(k,j,-nbgp:-1) = inflow_dist(k,j,4,1:nbgp) |
---|
291 | ENDIF |
---|
292 | e(k,j,-nbgp:-1) = mean_inflow_profiles(k,5) + & |
---|
293 | inflow_dist(k,j,5,1:nbgp) * inflow_damping_factor(k) |
---|
294 | e(k,j,-nbgp:-1) = MAX( e(k,j,-nbgp:-1), 0.0_wp ) |
---|
295 | IF ( humidity ) THEN |
---|
296 | IF ( TRIM( recycling_method_for_thermodynamic_quantities ) & |
---|
297 | == 'turbulent_fluctuation' ) THEN |
---|
298 | q(k,j,-nbgp:-1) = mean_inflow_profiles(k,6) + & |
---|
299 | inflow_dist(k,j,6,1:nbgp) * inflow_damping_factor(k) |
---|
300 | ELSEIF ( TRIM( recycling_method_for_thermodynamic_quantities ) & |
---|
301 | == 'absolute_value' ) THEN |
---|
302 | q(k,j,-nbgp:-1) = inflow_dist(k,j,6,1:nbgp) |
---|
303 | ENDIF |
---|
304 | ENDIF |
---|
305 | IF ( passive_scalar ) & |
---|
306 | s(k,j,-nbgp:-1) = mean_inflow_profiles(k,7) + & |
---|
307 | inflow_dist(k,j,7,1:nbgp) * inflow_damping_factor(k) |
---|
308 | |
---|
309 | ENDDO |
---|
310 | ENDDO |
---|
311 | |
---|
312 | ENDIF |
---|
313 | |
---|
314 | |
---|
315 | CALL cpu_log( log_point(40), 'inflow_turbulence', 'stop' ) |
---|
316 | |
---|
317 | |
---|
318 | END SUBROUTINE inflow_turbulence |
---|