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

Last change on this file since 2000 was 2000, checked in by knoop, 8 years ago

Forced header and separation lines into 80 columns

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