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

Last change on this file since 4180 was 4180, checked in by scharf, 5 years ago

removed comments in 'Former revisions' section that are older than 01.01.2019

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