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

Last change on this file since 1961 was 1961, checked in by suehring, 8 years ago

last commit documented

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