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

Last change on this file since 1952 was 1818, checked in by maronga, 8 years ago

last commit documented / copyright update

  • Property svn:keywords set to Id
File size: 10.1 KB
Line 
1!> @file inflow_turbulence.f90
2!--------------------------------------------------------------------------------!
3! This file is part of PALM.
4!
5! PALM is free software: you can redistribute it and/or modify it under the terms
6! of the GNU General Public License as published by the Free Software Foundation,
7! either version 3 of the License, or (at your option) any later version.
8!
9! PALM is distributed in the hope that it will be useful, but WITHOUT ANY
10! WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
11! A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
12!
13! You should have received a copy of the GNU General Public License along with
14! PALM. If not, see <http://www.gnu.org/licenses/>.
15!
16! Copyright 1997-2016 Leibniz Universitaet Hannover
17!--------------------------------------------------------------------------------!
18!
19! Current revisions:
20! -----------------
21!
22!
23! Former revisions:
24! -----------------
25! $Id: inflow_turbulence.f90 1818 2016-04-06 15:53:27Z suehring $
26!
27! 1806 2016-04-05 18:55:35Z gronemeier
28! Added comments to variables and code segments. Removed code redundancies.
29!
30! 1682 2015-10-07 23:56:08Z knoop
31! Code annotations made doxygen readable
32!
33! 1615 2015-07-08 18:49:19Z suehring
34! Enable turbulent inflow for passive_scalar and humidity
35!
36! 1560 2015-03-06 10:48:54Z keck
37! Option recycling_yshift added. If this option is switched on, the turbulence
38! data, which is mapped from the recycling plane to the inflow, is shifted in
39! y direction (by ny * dy / 2 )
40!
41! 1353 2014-04-08 15:21:23Z heinze
42! REAL constants provided with KIND-attribute
43!
44! 1346 2014-03-27 13:18:20Z heinze
45! Bugfix: REAL constants provided with KIND-attribute especially in call of
46! intrinsic function like MAX, MIN, SIGN
47!
48! 1320 2014-03-20 08:40:49Z raasch
49! ONLY-attribute added to USE-statements,
50! kind-parameters added to all INTEGER and REAL declaration statements,
51! kinds are defined in new module kinds,
52! revision history before 2012 removed,
53! comment fields (!:) to be used for variable explanations added to
54! all variable declaration statements
55!
56! 1092 2013-02-02 11:24:22Z raasch
57! unused variables removed
58!
59! 1036 2012-10-22 13:43:42Z raasch
60! code put under GPL (PALM 3.9)
61!
62! Initial version (2008/03/07)
63!
64! Description:
65! ------------
66!> Imposing turbulence at the respective inflow using the turbulence
67!> recycling method of Kataoka and Mizuno (2002).
68!------------------------------------------------------------------------------!
69 SUBROUTINE inflow_turbulence
70 
71
72    USE arrays_3d,                                                             &
73        ONLY:  e, inflow_damping_factor, mean_inflow_profiles, pt, q, u, v, w
74       
75    USE control_parameters,                                                    &
76        ONLY:  humidity, passive_scalar, recycling_plane, recycling_yshift
77       
78    USE cpulog,                                                                &
79        ONLY:  cpu_log, log_point
80       
81    USE indices,                                                               &
82        ONLY:  nbgp, nxl, ny, nyn, nys, nyng, nysg, nzb, nzt
83       
84    USE kinds
85   
86    USE pegrid
87
88
89    IMPLICIT NONE
90
91    INTEGER(iwp) ::  i        !< loop index
92    INTEGER(iwp) ::  j        !< loop index
93    INTEGER(iwp) ::  k        !< loop index
94    INTEGER(iwp) ::  l        !< loop index
95    INTEGER(iwp) ::  next     !< ID of receiving PE for y-shift
96    INTEGER(iwp) ::  ngp_ifd  !< number of grid points stored in avpr
97    INTEGER(iwp) ::  ngp_pr   !< number of grid points stored in inflow_dist
98    INTEGER(iwp) ::  prev     !< ID of sending PE for y-shift
99
100    REAL(wp), DIMENSION(nzb:nzt+1,6,nbgp)           ::                         &
101       avpr               !< stores averaged profiles at recycling plane
102    REAL(wp), DIMENSION(nzb:nzt+1,6,nbgp)           ::                         &
103       avpr_l             !< auxiliary variable to calculate avpr
104    REAL(wp), DIMENSION(nzb:nzt+1,nysg:nyng,6,nbgp) ::                         &
105       inflow_dist        !< turbulence signal of vars, added at inflow boundary
106    REAL(wp), DIMENSION(nzb:nzt+1,nysg:nyng,6,nbgp) ::                         &
107       local_inflow_dist  !< auxiliary variable for inflow_dist, used for yshift
108
109    CALL cpu_log( log_point(40), 'inflow_turbulence', 'start' )
110
111!
112!-- Carry out spanwise averaging in the recycling plane
113    avpr_l = 0.0_wp
114    ngp_pr = ( nzt - nzb + 2 ) * 6 * nbgp
115    ngp_ifd = ngp_pr * ( nyn - nys + 1 + 2 * nbgp )
116
117!
118!-- First, local averaging within the recycling domain
119    i = recycling_plane
120
121#if defined( __parallel )
122    IF ( myidx == id_recycling )  THEN
123       
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  .OR.  passive_scalar )                          &
134                   avpr_l(k,6,l) = avpr_l(k,6,l) + q(k,j,i)
135
136             ENDDO
137          ENDDO
138          i = i + 1
139       ENDDO
140
141    ENDIF
142!
143!-- Now, averaging over all PEs
144    IF ( collective_wait )  CALL MPI_BARRIER( comm2d, ierr )
145    CALL MPI_ALLREDUCE( avpr_l(nzb,1,1), avpr(nzb,1,1), ngp_pr, MPI_REAL,      &
146                        MPI_SUM, comm2d, ierr )
147
148#else
149    DO  l = 1, nbgp
150       DO  j = nys, nyn
151          DO  k = nzb, nzt + 1
152
153             avpr_l(k,1,l) = avpr_l(k,1,l) + u(k,j,i)
154             avpr_l(k,2,l) = avpr_l(k,2,l) + v(k,j,i)
155             avpr_l(k,3,l) = avpr_l(k,3,l) + w(k,j,i)
156             avpr_l(k,4,l) = avpr_l(k,4,l) + pt(k,j,i)
157             avpr_l(k,5,l) = avpr_l(k,5,l) + e(k,j,i)
158             IF ( humidity  .OR.  passive_scalar )                             &
159                avpr_l(k,6,l) = avpr_l(k,6,l) + q(k,j,i)
160
161          ENDDO
162       ENDDO
163       i = i + 1 
164    ENDDO
165   
166    avpr = avpr_l
167#endif
168
169    avpr = avpr / ( ny + 1 )
170!
171!-- Calculate the disturbances at the recycling plane
172    i = recycling_plane
173
174#if defined( __parallel )
175    IF ( myidx == id_recycling )  THEN
176       DO  l = 1, nbgp
177          DO  j = nysg, nyng
178             DO  k = nzb, nzt + 1
179
180                inflow_dist(k,j,1,l) = u(k,j,i+1) - avpr(k,1,l)
181                inflow_dist(k,j,2,l) = v(k,j,i)   - avpr(k,2,l)
182                inflow_dist(k,j,3,l) = w(k,j,i)   - avpr(k,3,l)
183                inflow_dist(k,j,4,l) = pt(k,j,i)  - avpr(k,4,l)
184                inflow_dist(k,j,5,l) = e(k,j,i)   - avpr(k,5,l)
185                IF ( humidity  .OR.  passive_scalar )                          &
186                   inflow_dist(k,j,6,l) = q(k,j,i) - avpr(k,6,l)
187            ENDDO
188          ENDDO
189          i = i + 1
190       ENDDO
191
192    ENDIF
193#else
194    DO  l = 1, nbgp
195       DO  j = nysg, nyng
196          DO  k = nzb, nzt+1
197
198             inflow_dist(k,j,1,l) = u(k,j,i+1) - avpr(k,1,l)
199             inflow_dist(k,j,2,l) = v(k,j,i)   - avpr(k,2,l)
200             inflow_dist(k,j,3,l) = w(k,j,i)   - avpr(k,3,l)
201             inflow_dist(k,j,4,l) = pt(k,j,i)  - avpr(k,4,l)
202             inflow_dist(k,j,5,l) = e(k,j,i)   - avpr(k,5,l)
203             IF ( humidity  .OR.  passive_scalar )                             &
204                inflow_dist(k,j,6,l) = q(k,j,i) - avpr(k,6,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             pt(k,j,-nbgp:-1) = mean_inflow_profiles(k,4) +                 &
273                        inflow_dist(k,j,4,1:nbgp) * inflow_damping_factor(k)
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  .OR.  passive_scalar )                          &
279                q(k,j,-nbgp:-1)  = mean_inflow_profiles(k,6) +              &
280                        inflow_dist(k,j,6,1:nbgp) * inflow_damping_factor(k)
281
282          ENDDO
283       ENDDO
284
285    ENDIF
286
287
288    CALL cpu_log( log_point(40), 'inflow_turbulence', 'stop' )
289
290
291 END SUBROUTINE inflow_turbulence
Note: See TracBrowser for help on using the repository browser.