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

Last change on this file since 1615 was 1615, checked in by suehring, 9 years ago

Enable turbulent inflow for passive_scalar and humidity

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