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

Last change on this file since 4297 was 4297, checked in by oliver.maas, 5 years ago

In case of turbulent inflow: Adjusted recycling_yshift, so that y-shift can be given as multiples of PE (as in y_shift for cyclic BCs).

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