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

Last change on this file since 1682 was 1682, checked in by knoop, 9 years ago

Code annotations made doxygen readable

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