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

Last change on this file since 1806 was 1806, checked in by gronemeier, 5 years ago

adjustments to recycling_yshift

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