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

Last change on this file since 4180 was 4180, checked in by scharf, 5 years ago

removed comments in 'Former revisions' section that are older than 01.01.2019

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