source: palm/trunk/SOURCE/inflow_turbulence.f90 @ 4175

Last change on this file since 4175 was 4172, checked in by oliver.maas, 5 years ago

Added optional method for recycling of absolute values of pt and q instead of recycling only the deviations from the mean profile at the recycling plane. With the new method two problems are solved: 1. A horizontally homogeneous temperature and humidity field is achieved, even for non-neutral boundary layers and thus no thermal circulation is triggered. 2. No gravity waves build up at the inflow due to cyclic boundary conditions for pt and q.

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