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

Last change on this file since 2716 was 2716, checked in by kanani, 6 years ago

Correction of "Former revisions" section

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