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

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