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

Last change on this file since 4297 was 4297, checked in by oliver.maas, 4 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
Line 
1!> @file inflow_turbulence.f90
2!------------------------------------------------------------------------------!
3! This file is part of the PALM model system.
4!
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.
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!
17! Copyright 1997-2019 Leibniz Universitaet Hannover
18!------------------------------------------------------------------------------!
19!
20! Current revisions:
21! -----------------
22!
23!
24! Former revisions:
25! -----------------
26! $Id: inflow_turbulence.f90 4297 2019-11-21 10:37:50Z oliver.maas $
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
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
35! Corrected "Former revisions" section
36!
37! 4172 2019-08-20 11:55:33Z oliver.maas
38! added optional recycling of absolute values for pt and q
39!
40! 3655 2019-01-07 16:51:22Z knoop
41! Corrected "Former revisions" section
42!
43! Initial version (2008/03/07)
44!
45! Description:
46! ------------
47!> Imposing turbulence at the respective inflow using the turbulence
48!> recycling method of Kataoka and Mizuno (2002).
49!------------------------------------------------------------------------------!
50 SUBROUTINE inflow_turbulence
51 
52
53    USE arrays_3d,                                                             &
54        ONLY:  e, inflow_damping_factor, mean_inflow_profiles, pt, q, s, u, v, w
55       
56    USE control_parameters,                                                    &
57        ONLY:  humidity, passive_scalar, recycling_plane, recycling_yshift,    &
58               recycling_method_for_thermodynamic_quantities
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   
68    USE pegrid
69
70
71    IMPLICIT NONE
72   
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
81
82    REAL(wp), DIMENSION(nzb:nzt+1,7,nbgp)           ::                         &
83       avpr               !< stores averaged profiles at recycling plane
84    REAL(wp), DIMENSION(nzb:nzt+1,7,nbgp)           ::                         &
85       avpr_l             !< auxiliary variable to calculate avpr
86    REAL(wp), DIMENSION(nzb:nzt+1,nysg:nyng,7,nbgp) ::                         &
87       inflow_dist        !< turbulence signal of vars, added at inflow boundary
88    REAL(wp), DIMENSION(nzb:nzt+1,nysg:nyng,7,nbgp) ::                         &
89       local_inflow_dist  !< auxiliary variable for inflow_dist, used for yshift
90   
91    CALL cpu_log( log_point(40), 'inflow_turbulence', 'start' )
92   
93!
94!-- Carry out spanwise averaging in the recycling plane
95    avpr_l = 0.0_wp
96    ngp_pr = ( nzt - nzb + 2 ) * 7 * nbgp
97    ngp_ifd = ngp_pr * ( nyn - nys + 1 + 2 * nbgp )
98
99!
100!-- First, local averaging within the recycling domain
101    i = recycling_plane
102
103#if defined( __parallel )
104    IF ( myidx == id_recycling )  THEN
105       
106       DO  l = 1, nbgp
107          DO  j = nys, nyn
108             DO  k = nzb, nzt + 1
109
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)
115                IF ( humidity )                                                &
116                   avpr_l(k,6,l) = avpr_l(k,6,l) + q(k,j,i)
117                IF ( passive_scalar )                                          &
118                   avpr_l(k,7,l) = avpr_l(k,7,l) + s(k,j,i)
119
120             ENDDO
121          ENDDO
122          i = i + 1
123       ENDDO
124
125    ENDIF
126!
127!-- Now, averaging over all PEs
128    IF ( collective_wait )  CALL MPI_BARRIER( comm2d, ierr )
129    CALL MPI_ALLREDUCE( avpr_l(nzb,1,1), avpr(nzb,1,1), ngp_pr, MPI_REAL,      &
130                        MPI_SUM, comm2d, ierr )
131
132#else
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)
142             IF ( humidity )                                                   &
143                avpr_l(k,6,l) = avpr_l(k,6,l) + q(k,j,i)
144             IF ( passive_scalar )                                             &
145                avpr_l(k,7,l) = avpr_l(k,7,l) + s(k,j,i)
146
147          ENDDO
148       ENDDO
149       i = i + 1 
150    ENDDO
151   
152    avpr = avpr_l
153#endif
154
155    avpr = avpr / ( ny + 1 )
156!
157!-- Calculate the disturbances at the recycling plane
158!-- for recycling of absolute quantities, the disturbance is defined as the absolute value
159!-- (and not as the deviation from the mean profile)
160    i = recycling_plane
161
162#if defined( __parallel )
163    IF ( myidx == id_recycling )  THEN
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)
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
175                   inflow_dist(k,j,4,l) = pt(k,j,i)
176                ENDIF
177                inflow_dist(k,j,5,l) = e(k,j,i)   - avpr(k,5,l)
178                IF ( humidity ) THEN
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
184                      inflow_dist(k,j,6,l) = q(k,j,i)
185                   ENDIF
186                ENDIF
187                IF ( passive_scalar )                                          &
188                   inflow_dist(k,j,7,l) = s(k,j,i) - avpr(k,7,l)
189            ENDDO
190          ENDDO
191          i = i + 1
192       ENDDO
193
194    ENDIF
195#else
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)
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
207                inflow_dist(k,j,4,l) = pt(k,j,i)
208             ENDIF
209             inflow_dist(k,j,5,l) = e(k,j,i)   - avpr(k,5,l)
210             IF ( humidity )  THEN
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
216                   inflow_dist(k,j,6,l) = q(k,j,i)
217                ENDIF
218             ENDIF
219             IF ( passive_scalar )                                             &
220                inflow_dist(k,j,7,l) = s(k,j,i) - avpr(k,7,l)
221             
222          ENDDO
223       ENDDO
224       i = i + 1
225    ENDDO
226#endif
227
228!
229!-- For parallel runs, send the disturbances to the respective inflow PE
230#if defined( __parallel )
231    IF ( myidx == id_recycling  .AND.  myidx /= id_inflow )  THEN
232
233       CALL MPI_SEND( inflow_dist(nzb,nysg,1,1), ngp_ifd, MPI_REAL,            &
234                      id_inflow, 1, comm1dx, ierr )
235
236    ELSEIF ( myidx /= id_recycling  .AND.  myidx == id_inflow )  THEN
237
238       inflow_dist = 0.0_wp
239       CALL MPI_RECV( inflow_dist(nzb,nysg,1,1), ngp_ifd, MPI_REAL,            &
240                      id_recycling, 1, comm1dx, status, ierr )
241
242    ENDIF
243
244!
245!-- y-shift for inflow_dist
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
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).
253       prev = MODULO(myidy - recycling_yshift , pdims(2))
254       next = MODULO(myidy + recycling_yshift , pdims(2))
255       
256       local_inflow_dist = 0.0_wp
257
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 )
261
262       inflow_dist = local_inflow_dist
263
264    ENDIF
265
266#endif
267
268!
269!-- Add the disturbance at the inflow
270    IF ( nxl == 0 )  THEN
271
272       DO  j = nysg, nyng
273          DO  k = nzb, nzt + 1
274
275             u(k,j,-nbgp+1:0) = mean_inflow_profiles(k,1) +                    &
276                        inflow_dist(k,j,1,1:nbgp) * inflow_damping_factor(k)
277             v(k,j,-nbgp:-1)  = mean_inflow_profiles(k,2) +                    &
278                        inflow_dist(k,j,2,1:nbgp) * inflow_damping_factor(k)
279             w(k,j,-nbgp:-1)  =                                                &
280                        inflow_dist(k,j,3,1:nbgp) * inflow_damping_factor(k)
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
287                pt(k,j,-nbgp:-1) = inflow_dist(k,j,4,1:nbgp)
288             ENDIF
289             e(k,j,-nbgp:-1)  = mean_inflow_profiles(k,5) +                    &
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 )
292             IF ( humidity )  THEN
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
299                   q(k,j,-nbgp:-1)  = inflow_dist(k,j,6,1:nbgp)
300                ENDIF
301             ENDIF
302             IF ( passive_scalar )                                             &
303                s(k,j,-nbgp:-1)  = mean_inflow_profiles(k,7) +                 &
304                        inflow_dist(k,j,7,1:nbgp) * inflow_damping_factor(k)
305                       
306          ENDDO
307       ENDDO
308
309    ENDIF
310
311
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.