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

Last change on this file since 4182 was 4182, checked in by scharf, 5 years ago
  • corrected "Former revisions" section
  • minor formatting in "Former revisions" section
  • added "Author" section
  • Property svn:keywords set to Id
File size: 10.8 KB
RevLine 
[1682]1!> @file inflow_turbulence.f90
[2000]2!------------------------------------------------------------------------------!
[2696]3! This file is part of the PALM model system.
[1036]4!
[2000]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.
[1036]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!
[3655]17! Copyright 1997-2019 Leibniz Universitaet Hannover
[2000]18!------------------------------------------------------------------------------!
[1036]19!
[484]20! Current revisions:
[151]21! -----------------
[1354]22!
[2001]23!
[151]24! Former revisions:
25! -----------------
26! $Id: inflow_turbulence.f90 4182 2019-08-22 15:20:23Z scharf $
[4182]27! Corrected "Former revisions" section
28!
29! 4172 2019-08-20 11:55:33Z oliver.maas
[4172]30! added optional recycling of absolute values for pt and q
31!
32! 3655 2019-01-07 16:51:22Z knoop
[2716]33! Corrected "Former revisions" section
[151]34!
[4182]35! Initial version (2008/03/07)
36!
[151]37! Description:
38! ------------
[1682]39!> Imposing turbulence at the respective inflow using the turbulence
40!> recycling method of Kataoka and Mizuno (2002).
[151]41!------------------------------------------------------------------------------!
[1682]42 SUBROUTINE inflow_turbulence
43 
[151]44
[1320]45    USE arrays_3d,                                                             &
[1960]46        ONLY:  e, inflow_damping_factor, mean_inflow_profiles, pt, q, s, u, v, w
[1320]47       
48    USE control_parameters,                                                    &
[4172]49        ONLY:  humidity, passive_scalar, recycling_plane, recycling_yshift, raq
[1320]50       
51    USE cpulog,                                                                &
52        ONLY:  cpu_log, log_point
53       
54    USE indices,                                                               &
55        ONLY:  nbgp, nxl, ny, nyn, nys, nyng, nysg, nzb, nzt
56       
57    USE kinds
58   
[151]59    USE pegrid
60
61
62    IMPLICIT NONE
[4172]63   
[1806]64    INTEGER(iwp) ::  i        !< loop index
65    INTEGER(iwp) ::  j        !< loop index
66    INTEGER(iwp) ::  k        !< loop index
67    INTEGER(iwp) ::  l        !< loop index
68    INTEGER(iwp) ::  next     !< ID of receiving PE for y-shift
69    INTEGER(iwp) ::  ngp_ifd  !< number of grid points stored in avpr
70    INTEGER(iwp) ::  ngp_pr   !< number of grid points stored in inflow_dist
71    INTEGER(iwp) ::  prev     !< ID of sending PE for y-shift
[151]72
[1960]73    REAL(wp), DIMENSION(nzb:nzt+1,7,nbgp)           ::                         &
[1806]74       avpr               !< stores averaged profiles at recycling plane
[1960]75    REAL(wp), DIMENSION(nzb:nzt+1,7,nbgp)           ::                         &
[1806]76       avpr_l             !< auxiliary variable to calculate avpr
[1960]77    REAL(wp), DIMENSION(nzb:nzt+1,nysg:nyng,7,nbgp) ::                         &
[1806]78       inflow_dist        !< turbulence signal of vars, added at inflow boundary
[1960]79    REAL(wp), DIMENSION(nzb:nzt+1,nysg:nyng,7,nbgp) ::                         &
[1806]80       local_inflow_dist  !< auxiliary variable for inflow_dist, used for yshift
[4172]81   
[151]82    CALL cpu_log( log_point(40), 'inflow_turbulence', 'start' )
[4172]83   
[151]84!
[667]85!-- Carry out spanwise averaging in the recycling plane
[1353]86    avpr_l = 0.0_wp
[1960]87    ngp_pr = ( nzt - nzb + 2 ) * 7 * nbgp
[667]88    ngp_ifd = ngp_pr * ( nyn - nys + 1 + 2 * nbgp )
[151]89
90!
91!-- First, local averaging within the recycling domain
[667]92    i = recycling_plane
[151]93
[667]94#if defined( __parallel )
95    IF ( myidx == id_recycling )  THEN
96       
97       DO  l = 1, nbgp
[151]98          DO  j = nys, nyn
[667]99             DO  k = nzb, nzt + 1
[151]100
[667]101                avpr_l(k,1,l) = avpr_l(k,1,l) + u(k,j,i)
102                avpr_l(k,2,l) = avpr_l(k,2,l) + v(k,j,i)
103                avpr_l(k,3,l) = avpr_l(k,3,l) + w(k,j,i)
104                avpr_l(k,4,l) = avpr_l(k,4,l) + pt(k,j,i)
105                avpr_l(k,5,l) = avpr_l(k,5,l) + e(k,j,i)
[1960]106                IF ( humidity )                                                &
[1615]107                   avpr_l(k,6,l) = avpr_l(k,6,l) + q(k,j,i)
[1960]108                IF ( passive_scalar )                                          &
109                   avpr_l(k,7,l) = avpr_l(k,7,l) + s(k,j,i)
[151]110
111             ENDDO
112          ENDDO
[667]113          i = i + 1
[151]114       ENDDO
115
116    ENDIF
117!
118!-- Now, averaging over all PEs
[622]119    IF ( collective_wait )  CALL MPI_BARRIER( comm2d, ierr )
[1615]120    CALL MPI_ALLREDUCE( avpr_l(nzb,1,1), avpr(nzb,1,1), ngp_pr, MPI_REAL,      &
[709]121                        MPI_SUM, comm2d, ierr )
[667]122
[151]123#else
[667]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)
[1960]133             IF ( humidity )                                                   &
[1615]134                avpr_l(k,6,l) = avpr_l(k,6,l) + q(k,j,i)
[1960]135             IF ( passive_scalar )                                             &
136                avpr_l(k,7,l) = avpr_l(k,7,l) + s(k,j,i)
[667]137
138          ENDDO
139       ENDDO
140       i = i + 1 
141    ENDDO
142   
[151]143    avpr = avpr_l
144#endif
145
[667]146    avpr = avpr / ( ny + 1 )
[151]147!
148!-- Calculate the disturbances at the recycling plane
[4172]149!-- for recycling of absolute quantities, the disturbance is defined as the absolute value
150!-- (and not as the deviation from the mean profile)
[151]151    i = recycling_plane
152
[222]153#if defined( __parallel )
[163]154    IF ( myidx == id_recycling )  THEN
[667]155       DO  l = 1, nbgp
156          DO  j = nysg, nyng
157             DO  k = nzb, nzt + 1
[151]158
[667]159                inflow_dist(k,j,1,l) = u(k,j,i+1) - avpr(k,1,l)
160                inflow_dist(k,j,2,l) = v(k,j,i)   - avpr(k,2,l)
161                inflow_dist(k,j,3,l) = w(k,j,i)   - avpr(k,3,l)
[4172]162                IF ( raq(4) )  THEN
163                   inflow_dist(k,j,4,l) = pt(k,j,i)
164                ELSE
165                   inflow_dist(k,j,4,l) = pt(k,j,i) - avpr(k,4,l)
166                ENDIF
[667]167                inflow_dist(k,j,5,l) = e(k,j,i)   - avpr(k,5,l)
[4172]168                IF ( humidity ) THEN
169                   IF ( raq(6) ) THEN
170                      inflow_dist(k,j,6,l) = q(k,j,i)
171                   ELSE
172                      inflow_dist(k,j,6,l) = q(k,j,i) - avpr(k,6,l)
173                   ENDIF
174                ENDIF
[1960]175                IF ( passive_scalar )                                          &
176                   inflow_dist(k,j,7,l) = s(k,j,i) - avpr(k,7,l)
[667]177            ENDDO
[151]178          ENDDO
[667]179          i = i + 1
[151]180       ENDDO
181
182    ENDIF
[222]183#else
[667]184    DO  l = 1, nbgp
185       DO  j = nysg, nyng
186          DO  k = nzb, nzt+1
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)
[4172]190             IF ( raq(4) )  THEN
191                inflow_dist(k,j,4,l) = pt(k,j,i)
192             ELSE
193                inflow_dist(k,j,4,l) = pt(k,j,i) - avpr(k,4,l) 
194             ENDIF
[667]195             inflow_dist(k,j,5,l) = e(k,j,i)   - avpr(k,5,l)
[4172]196             IF ( humidity )  THEN
197                IF ( raq(6) ) THEN
198                   inflow_dist(k,j,6,l) = q(k,j,i)
199                ELSE
200                   inflow_dist(k,j,6,l) = q(k,j,i) - avpr(k,6,l)
201                ENDIF
202             ENDIF
[1960]203             IF ( passive_scalar )                                             &
204                inflow_dist(k,j,7,l) = s(k,j,i) - avpr(k,7,l)
[667]205             
206          ENDDO
[222]207       ENDDO
[667]208       i = i + 1
[222]209    ENDDO
210#endif
211
[151]212!
213!-- For parallel runs, send the disturbances to the respective inflow PE
214#if defined( __parallel )
[163]215    IF ( myidx == id_recycling  .AND.  myidx /= id_inflow )  THEN
[151]216
[1560]217       CALL MPI_SEND( inflow_dist(nzb,nysg,1,1), ngp_ifd, MPI_REAL,            &
[151]218                      id_inflow, 1, comm1dx, ierr )
219
[163]220    ELSEIF ( myidx /= id_recycling  .AND.  myidx == id_inflow )  THEN
[151]221
[1353]222       inflow_dist = 0.0_wp
[1560]223       CALL MPI_RECV( inflow_dist(nzb,nysg,1,1), ngp_ifd, MPI_REAL,            &
[163]224                      id_recycling, 1, comm1dx, status, ierr )
[151]225
226    ENDIF
[1560]227
[1806]228!
229!-- y-shift for inflow_dist
230!-- Shift inflow_dist in positive y direction by a distance of INT( npey / 2 )
[1560]231    IF ( recycling_yshift .AND. myidx == id_inflow ) THEN
[1806]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 )
[1560]239       ENDIF
[1806]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
[1560]246
247       local_inflow_dist = 0.0_wp
[1806]248
[1560]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 )
[1806]252
253       inflow_dist = local_inflow_dist
254
[1560]255    ENDIF
256
[151]257#endif
258
259!
260!-- Add the disturbance at the inflow
261    IF ( nxl == 0 )  THEN
262
[1806]263       DO  j = nysg, nyng
264          DO  k = nzb, nzt + 1
[151]265
[1806]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)
[4172]272             IF ( raq(4) )  THEN
273                pt(k,j,-nbgp:-1) = inflow_dist(k,j,4,1:nbgp)
274             ELSE
275                pt(k,j,-nbgp:-1) = mean_inflow_profiles(k,4) +               &
276                inflow_dist(k,j,4,1:nbgp) * inflow_damping_factor(k)
277             ENDIF
278             e(k,j,-nbgp:-1)  = mean_inflow_profiles(k,5) +                  &
[1806]279                        inflow_dist(k,j,5,1:nbgp) * inflow_damping_factor(k)
280             e(k,j,-nbgp:-1)  = MAX( e(k,j,-nbgp:-1), 0.0_wp )
[1560]281
[4172]282             IF ( humidity )  THEN
283                IF ( raq(6) )  THEN
284                   q(k,j,-nbgp:-1)  = inflow_dist(k,j,6,1:nbgp)
285                ELSE
286                   q(k,j,-nbgp:-1)  = mean_inflow_profiles(k,6) +           & 
[1806]287                        inflow_dist(k,j,6,1:nbgp) * inflow_damping_factor(k)
[4172]288                ENDIF
289             ENDIF
[1960]290             IF ( passive_scalar )                                          &
291                s(k,j,-nbgp:-1)  = mean_inflow_profiles(k,7) +              &
292                        inflow_dist(k,j,7,1:nbgp) * inflow_damping_factor(k)
[1560]293          ENDDO
[1806]294       ENDDO
[1560]295
[151]296    ENDIF
297
[1560]298
[151]299    CALL cpu_log( log_point(40), 'inflow_turbulence', 'stop' )
300
301
302 END SUBROUTINE inflow_turbulence
Note: See TracBrowser for help on using the repository browser.