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

Last change on this file since 1666 was 1616, checked in by suehring, 9 years ago

last commit documented

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