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