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 4183 2019-08-23 07:33:16Z suehring $ |
---|
27 | ! simplified steering of recycling of absolute values by initialization |
---|
28 | ! parameter recycling_method_for_thermodynamic_quantities |
---|
29 | ! |
---|
30 | ! 4182 2019-08-22 15:20:23Z scharf |
---|
31 | ! Corrected "Former revisions" section |
---|
32 | ! |
---|
33 | ! 4172 2019-08-20 11:55:33Z oliver.maas |
---|
34 | ! added optional recycling of absolute values for pt and q |
---|
35 | ! |
---|
36 | ! 3655 2019-01-07 16:51:22Z knoop |
---|
37 | ! Corrected "Former revisions" section |
---|
38 | ! |
---|
39 | ! Initial version (2008/03/07) |
---|
40 | ! |
---|
41 | ! Description: |
---|
42 | ! ------------ |
---|
43 | !> Imposing turbulence at the respective inflow using the turbulence |
---|
44 | !> recycling method of Kataoka and Mizuno (2002). |
---|
45 | !------------------------------------------------------------------------------! |
---|
46 | SUBROUTINE inflow_turbulence |
---|
47 | |
---|
48 | |
---|
49 | USE arrays_3d, & |
---|
50 | ONLY: e, inflow_damping_factor, mean_inflow_profiles, pt, q, s, u, v, w |
---|
51 | |
---|
52 | USE control_parameters, & |
---|
53 | ONLY: humidity, passive_scalar, recycling_plane, recycling_yshift, & |
---|
54 | recycling_method_for_thermodynamic_quantities |
---|
55 | |
---|
56 | USE cpulog, & |
---|
57 | ONLY: cpu_log, log_point |
---|
58 | |
---|
59 | USE indices, & |
---|
60 | ONLY: nbgp, nxl, ny, nyn, nys, nyng, nysg, nzb, nzt |
---|
61 | |
---|
62 | USE kinds |
---|
63 | |
---|
64 | USE pegrid |
---|
65 | |
---|
66 | |
---|
67 | IMPLICIT NONE |
---|
68 | |
---|
69 | INTEGER(iwp) :: i !< loop index |
---|
70 | INTEGER(iwp) :: j !< loop index |
---|
71 | INTEGER(iwp) :: k !< loop index |
---|
72 | INTEGER(iwp) :: l !< loop index |
---|
73 | INTEGER(iwp) :: next !< ID of receiving PE for y-shift |
---|
74 | INTEGER(iwp) :: ngp_ifd !< number of grid points stored in avpr |
---|
75 | INTEGER(iwp) :: ngp_pr !< number of grid points stored in inflow_dist |
---|
76 | INTEGER(iwp) :: prev !< ID of sending PE for y-shift |
---|
77 | |
---|
78 | REAL(wp), DIMENSION(nzb:nzt+1,7,nbgp) :: & |
---|
79 | avpr !< stores averaged profiles at recycling plane |
---|
80 | REAL(wp), DIMENSION(nzb:nzt+1,7,nbgp) :: & |
---|
81 | avpr_l !< auxiliary variable to calculate avpr |
---|
82 | REAL(wp), DIMENSION(nzb:nzt+1,nysg:nyng,7,nbgp) :: & |
---|
83 | inflow_dist !< turbulence signal of vars, added at inflow boundary |
---|
84 | REAL(wp), DIMENSION(nzb:nzt+1,nysg:nyng,7,nbgp) :: & |
---|
85 | local_inflow_dist !< auxiliary variable for inflow_dist, used for yshift |
---|
86 | |
---|
87 | CALL cpu_log( log_point(40), 'inflow_turbulence', 'start' ) |
---|
88 | |
---|
89 | ! |
---|
90 | !-- Carry out spanwise averaging in the recycling plane |
---|
91 | avpr_l = 0.0_wp |
---|
92 | ngp_pr = ( nzt - nzb + 2 ) * 7 * nbgp |
---|
93 | ngp_ifd = ngp_pr * ( nyn - nys + 1 + 2 * nbgp ) |
---|
94 | |
---|
95 | ! |
---|
96 | !-- First, local averaging within the recycling domain |
---|
97 | i = recycling_plane |
---|
98 | |
---|
99 | #if defined( __parallel ) |
---|
100 | IF ( myidx == id_recycling ) THEN |
---|
101 | |
---|
102 | DO l = 1, nbgp |
---|
103 | DO j = nys, nyn |
---|
104 | DO k = nzb, nzt + 1 |
---|
105 | |
---|
106 | avpr_l(k,1,l) = avpr_l(k,1,l) + u(k,j,i) |
---|
107 | avpr_l(k,2,l) = avpr_l(k,2,l) + v(k,j,i) |
---|
108 | avpr_l(k,3,l) = avpr_l(k,3,l) + w(k,j,i) |
---|
109 | avpr_l(k,4,l) = avpr_l(k,4,l) + pt(k,j,i) |
---|
110 | avpr_l(k,5,l) = avpr_l(k,5,l) + e(k,j,i) |
---|
111 | IF ( humidity ) & |
---|
112 | avpr_l(k,6,l) = avpr_l(k,6,l) + q(k,j,i) |
---|
113 | IF ( passive_scalar ) & |
---|
114 | avpr_l(k,7,l) = avpr_l(k,7,l) + s(k,j,i) |
---|
115 | |
---|
116 | ENDDO |
---|
117 | ENDDO |
---|
118 | i = i + 1 |
---|
119 | ENDDO |
---|
120 | |
---|
121 | ENDIF |
---|
122 | ! |
---|
123 | !-- Now, averaging over all PEs |
---|
124 | IF ( collective_wait ) CALL MPI_BARRIER( comm2d, ierr ) |
---|
125 | CALL MPI_ALLREDUCE( avpr_l(nzb,1,1), avpr(nzb,1,1), ngp_pr, MPI_REAL, & |
---|
126 | MPI_SUM, comm2d, ierr ) |
---|
127 | |
---|
128 | #else |
---|
129 | DO l = 1, nbgp |
---|
130 | DO j = nys, nyn |
---|
131 | DO k = nzb, nzt + 1 |
---|
132 | |
---|
133 | avpr_l(k,1,l) = avpr_l(k,1,l) + u(k,j,i) |
---|
134 | avpr_l(k,2,l) = avpr_l(k,2,l) + v(k,j,i) |
---|
135 | avpr_l(k,3,l) = avpr_l(k,3,l) + w(k,j,i) |
---|
136 | avpr_l(k,4,l) = avpr_l(k,4,l) + pt(k,j,i) |
---|
137 | avpr_l(k,5,l) = avpr_l(k,5,l) + e(k,j,i) |
---|
138 | IF ( humidity ) & |
---|
139 | avpr_l(k,6,l) = avpr_l(k,6,l) + q(k,j,i) |
---|
140 | IF ( passive_scalar ) & |
---|
141 | avpr_l(k,7,l) = avpr_l(k,7,l) + s(k,j,i) |
---|
142 | |
---|
143 | ENDDO |
---|
144 | ENDDO |
---|
145 | i = i + 1 |
---|
146 | ENDDO |
---|
147 | |
---|
148 | avpr = avpr_l |
---|
149 | #endif |
---|
150 | |
---|
151 | avpr = avpr / ( ny + 1 ) |
---|
152 | ! |
---|
153 | !-- Calculate the disturbances at the recycling plane |
---|
154 | !-- for recycling of absolute quantities, the disturbance is defined as the absolute value |
---|
155 | !-- (and not as the deviation from the mean profile) |
---|
156 | i = recycling_plane |
---|
157 | |
---|
158 | #if defined( __parallel ) |
---|
159 | IF ( myidx == id_recycling ) THEN |
---|
160 | DO l = 1, nbgp |
---|
161 | DO j = nysg, nyng |
---|
162 | DO k = nzb, nzt + 1 |
---|
163 | inflow_dist(k,j,1,l) = u(k,j,i+1) - avpr(k,1,l) |
---|
164 | inflow_dist(k,j,2,l) = v(k,j,i) - avpr(k,2,l) |
---|
165 | inflow_dist(k,j,3,l) = w(k,j,i) - avpr(k,3,l) |
---|
166 | IF ( TRIM( recycling_method_for_thermodynamic_quantities ) & |
---|
167 | == 'turbulent_fluctuation' ) THEN |
---|
168 | inflow_dist(k,j,4,l) = pt(k,j,i) - avpr(k,4,l) |
---|
169 | ELSEIF ( TRIM( recycling_method_for_thermodynamic_quantities ) & |
---|
170 | == 'absolute_value' ) THEN |
---|
171 | inflow_dist(k,j,4,l) = pt(k,j,i) |
---|
172 | ENDIF |
---|
173 | inflow_dist(k,j,5,l) = e(k,j,i) - avpr(k,5,l) |
---|
174 | IF ( humidity ) THEN |
---|
175 | IF ( TRIM( recycling_method_for_thermodynamic_quantities ) & |
---|
176 | == 'turbulent_fluctuation' ) THEN |
---|
177 | inflow_dist(k,j,6,l) = q(k,j,i) - avpr(k,6,l) |
---|
178 | ELSEIF ( TRIM( recycling_method_for_thermodynamic_quantities ) & |
---|
179 | == 'absolute_value' ) THEN |
---|
180 | inflow_dist(k,j,6,l) = q(k,j,i) |
---|
181 | ENDIF |
---|
182 | ENDIF |
---|
183 | IF ( passive_scalar ) & |
---|
184 | inflow_dist(k,j,7,l) = s(k,j,i) - avpr(k,7,l) |
---|
185 | ENDDO |
---|
186 | ENDDO |
---|
187 | i = i + 1 |
---|
188 | ENDDO |
---|
189 | |
---|
190 | ENDIF |
---|
191 | #else |
---|
192 | DO l = 1, nbgp |
---|
193 | DO j = nysg, nyng |
---|
194 | DO k = nzb, nzt+1 |
---|
195 | inflow_dist(k,j,1,l) = u(k,j,i+1) - avpr(k,1,l) |
---|
196 | inflow_dist(k,j,2,l) = v(k,j,i) - avpr(k,2,l) |
---|
197 | inflow_dist(k,j,3,l) = w(k,j,i) - avpr(k,3,l) |
---|
198 | IF ( TRIM( recycling_method_for_thermodynamic_quantities ) & |
---|
199 | == 'turbulent_fluctuation' ) THEN |
---|
200 | inflow_dist(k,j,4,l) = pt(k,j,i) - avpr(k,4,l) |
---|
201 | ELSEIF ( TRIM( recycling_method_for_thermodynamic_quantities ) & |
---|
202 | == 'absolute_value' ) THEN |
---|
203 | inflow_dist(k,j,4,l) = pt(k,j,i) |
---|
204 | ENDIF |
---|
205 | inflow_dist(k,j,5,l) = e(k,j,i) - avpr(k,5,l) |
---|
206 | IF ( humidity ) THEN |
---|
207 | IF ( TRIM( recycling_method_for_thermodynamic_quantities ) & |
---|
208 | == 'turbulent_fluctuation' ) THEN |
---|
209 | inflow_dist(k,j,6,l) = q(k,j,i) - avpr(k,6,l) |
---|
210 | ELSEIF ( TRIM( recycling_method_for_thermodynamic_quantities ) & |
---|
211 | == 'absolute_value' ) THEN |
---|
212 | inflow_dist(k,j,6,l) = q(k,j,i) |
---|
213 | ENDIF |
---|
214 | ENDIF |
---|
215 | IF ( passive_scalar ) & |
---|
216 | inflow_dist(k,j,7,l) = s(k,j,i) - avpr(k,7,l) |
---|
217 | |
---|
218 | ENDDO |
---|
219 | ENDDO |
---|
220 | i = i + 1 |
---|
221 | ENDDO |
---|
222 | #endif |
---|
223 | |
---|
224 | ! |
---|
225 | !-- For parallel runs, send the disturbances to the respective inflow PE |
---|
226 | #if defined( __parallel ) |
---|
227 | IF ( myidx == id_recycling .AND. myidx /= id_inflow ) THEN |
---|
228 | |
---|
229 | CALL MPI_SEND( inflow_dist(nzb,nysg,1,1), ngp_ifd, MPI_REAL, & |
---|
230 | id_inflow, 1, comm1dx, ierr ) |
---|
231 | |
---|
232 | ELSEIF ( myidx /= id_recycling .AND. myidx == id_inflow ) THEN |
---|
233 | |
---|
234 | inflow_dist = 0.0_wp |
---|
235 | CALL MPI_RECV( inflow_dist(nzb,nysg,1,1), ngp_ifd, MPI_REAL, & |
---|
236 | id_recycling, 1, comm1dx, status, ierr ) |
---|
237 | |
---|
238 | ENDIF |
---|
239 | |
---|
240 | ! |
---|
241 | !-- y-shift for inflow_dist |
---|
242 | !-- Shift inflow_dist in positive y direction by a distance of INT( npey / 2 ) |
---|
243 | IF ( recycling_yshift .AND. myidx == id_inflow ) THEN |
---|
244 | ! |
---|
245 | !-- Calculate the ID of the PE which sends data to this PE (prev) and of the |
---|
246 | !-- PE which receives data from this PE (next). |
---|
247 | IF ( myidy >= INT( pdims(2) / 2 ) ) THEN |
---|
248 | prev = myidy - INT( pdims(2) / 2 ) |
---|
249 | ELSE |
---|
250 | prev = pdims(2) - ( INT( pdims(2) / 2 ) - myidy ) |
---|
251 | ENDIF |
---|
252 | |
---|
253 | IF ( myidy < pdims(2) - INT( pdims(2) / 2 ) ) THEN |
---|
254 | next = myidy + INT( pdims(2) / 2 ) |
---|
255 | ELSE |
---|
256 | next = INT( pdims(2) / 2 ) - ( pdims(2) - myidy ) |
---|
257 | ENDIF |
---|
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 |
---|