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

Last change on this file since 4598 was 4429, checked in by raasch, 4 years ago

serial (non-MPI) test case added, several bugfixes for the serial mode

  • Property svn:keywords set to Id
File size: 12.7 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-2020 Leibniz Universitaet Hannover
18!------------------------------------------------------------------------------!
19!
20! Current revisions:
21! -----------------
22!
23!
24! Former revisions:
25! -----------------
26! $Id: inflow_turbulence.f90 4429 2020-02-27 15:24:30Z suehring $
27! bugfix: cpp-directives added for serial mode
28!
29! 4360 2020-01-07 11:25:50Z suehring
30! use y_shift instead of old parameter recycling_yshift
31!
32! 4297 2019-11-21 10:37:50Z oliver.maas
33! changed recycling_yshift so that the y-shift can be a multiple of PE
34! instead of y-shift of a half domain width
35!
36! 4183 2019-08-23 07:33:16Z oliver.maas
37! simplified steering of recycling of absolute values by initialization
38! parameter recycling_method_for_thermodynamic_quantities
39!
40! 4182 2019-08-22 15:20:23Z scharf
41! Corrected "Former revisions" section
42!
43! 4172 2019-08-20 11:55:33Z oliver.maas
44! added optional recycling of absolute values for pt and q
45!
46! 3655 2019-01-07 16:51:22Z knoop
47! Corrected "Former revisions" section
48!
49! Initial version (2008/03/07)
50!
51! Description:
52! ------------
53!> Imposing turbulence at the respective inflow using the turbulence
54!> recycling method of Kataoka and Mizuno (2002).
55!------------------------------------------------------------------------------!
56 SUBROUTINE inflow_turbulence
57 
58
59    USE arrays_3d,                                                             &
60        ONLY:  e, inflow_damping_factor, mean_inflow_profiles, pt, q, s, u, v, w
61       
62#if defined( __parallel )
63    USE control_parameters,                                                    &
64        ONLY:  humidity, passive_scalar, recycling_plane, y_shift,             &
65               recycling_method_for_thermodynamic_quantities
66#else
67    USE control_parameters,                                                    &
68        ONLY:  humidity, passive_scalar, recycling_plane,                      &
69               recycling_method_for_thermodynamic_quantities
70#endif
71       
72    USE cpulog,                                                                &
73        ONLY:  cpu_log, log_point
74       
75    USE indices,                                                               &
76        ONLY:  nbgp, nxl, ny, nyn, nys, nyng, nysg, nzb, nzt
77       
78    USE kinds
79   
80    USE pegrid
81
82
83    IMPLICIT NONE
84   
85    INTEGER(iwp) ::  i        !< loop index
86    INTEGER(iwp) ::  j        !< loop index
87    INTEGER(iwp) ::  k        !< loop index
88    INTEGER(iwp) ::  l        !< loop index
89    INTEGER(iwp) ::  ngp_ifd  !< number of grid points stored in avpr
90    INTEGER(iwp) ::  ngp_pr   !< number of grid points stored in inflow_dist
91#if defined( __parallel )
92    INTEGER(iwp) ::  next     !< ID of receiving PE for y-shift
93    INTEGER(iwp) ::  prev     !< ID of sending PE for y-shift
94#endif
95
96    REAL(wp), DIMENSION(nzb:nzt+1,7,nbgp)           ::                         &
97       avpr               !< stores averaged profiles at recycling plane
98    REAL(wp), DIMENSION(nzb:nzt+1,7,nbgp)           ::                         &
99       avpr_l             !< auxiliary variable to calculate avpr
100    REAL(wp), DIMENSION(nzb:nzt+1,nysg:nyng,7,nbgp) ::                         &
101       inflow_dist        !< turbulence signal of vars, added at inflow boundary
102#if defined( __parallel )
103    REAL(wp), DIMENSION(nzb:nzt+1,nysg:nyng,7,nbgp) ::                         &
104       local_inflow_dist  !< auxiliary variable for inflow_dist, used for y-shift
105#endif
106   
107    CALL cpu_log( log_point(40), 'inflow_turbulence', 'start' )
108   
109!
110!-- Carry out spanwise averaging in the recycling plane
111    avpr_l = 0.0_wp
112    ngp_pr = ( nzt - nzb + 2 ) * 7 * nbgp
113    ngp_ifd = ngp_pr * ( nyn - nys + 1 + 2 * nbgp )
114
115!
116!-- First, local averaging within the recycling domain
117    i = recycling_plane
118
119#if defined( __parallel )
120    IF ( myidx == id_recycling )  THEN
121       
122       DO  l = 1, nbgp
123          DO  j = nys, nyn
124             DO  k = nzb, nzt + 1
125
126                avpr_l(k,1,l) = avpr_l(k,1,l) + u(k,j,i)
127                avpr_l(k,2,l) = avpr_l(k,2,l) + v(k,j,i)
128                avpr_l(k,3,l) = avpr_l(k,3,l) + w(k,j,i)
129                avpr_l(k,4,l) = avpr_l(k,4,l) + pt(k,j,i)
130                avpr_l(k,5,l) = avpr_l(k,5,l) + e(k,j,i)
131                IF ( humidity )                                                &
132                   avpr_l(k,6,l) = avpr_l(k,6,l) + q(k,j,i)
133                IF ( passive_scalar )                                          &
134                   avpr_l(k,7,l) = avpr_l(k,7,l) + s(k,j,i)
135
136             ENDDO
137          ENDDO
138          i = i + 1
139       ENDDO
140
141    ENDIF
142!
143!-- Now, averaging over all PEs
144    IF ( collective_wait )  CALL MPI_BARRIER( comm2d, ierr )
145    CALL MPI_ALLREDUCE( avpr_l(nzb,1,1), avpr(nzb,1,1), ngp_pr, MPI_REAL,      &
146                        MPI_SUM, comm2d, ierr )
147
148#else
149    DO  l = 1, nbgp
150       DO  j = nys, nyn
151          DO  k = nzb, nzt + 1
152
153             avpr_l(k,1,l) = avpr_l(k,1,l) + u(k,j,i)
154             avpr_l(k,2,l) = avpr_l(k,2,l) + v(k,j,i)
155             avpr_l(k,3,l) = avpr_l(k,3,l) + w(k,j,i)
156             avpr_l(k,4,l) = avpr_l(k,4,l) + pt(k,j,i)
157             avpr_l(k,5,l) = avpr_l(k,5,l) + e(k,j,i)
158             IF ( humidity )                                                   &
159                avpr_l(k,6,l) = avpr_l(k,6,l) + q(k,j,i)
160             IF ( passive_scalar )                                             &
161                avpr_l(k,7,l) = avpr_l(k,7,l) + s(k,j,i)
162
163          ENDDO
164       ENDDO
165       i = i + 1 
166    ENDDO
167   
168    avpr = avpr_l
169#endif
170
171    avpr = avpr / ( ny + 1 )
172!
173!-- Calculate the disturbances at the recycling plane
174!-- for recycling of absolute quantities, the disturbance is defined as the absolute value
175!-- (and not as the deviation from the mean profile)
176    i = recycling_plane
177
178#if defined( __parallel )
179    IF ( myidx == id_recycling )  THEN
180       DO  l = 1, nbgp
181          DO  j = nysg, nyng
182             DO  k = nzb, nzt + 1
183                inflow_dist(k,j,1,l) = u(k,j,i+1) - avpr(k,1,l)
184                inflow_dist(k,j,2,l) = v(k,j,i)   - avpr(k,2,l)
185                inflow_dist(k,j,3,l) = w(k,j,i)   - avpr(k,3,l)
186                IF ( TRIM( recycling_method_for_thermodynamic_quantities )     &
187                   == 'turbulent_fluctuation' )  THEN
188                   inflow_dist(k,j,4,l) = pt(k,j,i) - avpr(k,4,l)
189                ELSEIF ( TRIM( recycling_method_for_thermodynamic_quantities ) &
190                   == 'absolute_value' )  THEN
191                   inflow_dist(k,j,4,l) = pt(k,j,i)
192                ENDIF
193                inflow_dist(k,j,5,l) = e(k,j,i)   - avpr(k,5,l)
194                IF ( humidity ) THEN
195                   IF ( TRIM( recycling_method_for_thermodynamic_quantities )  &
196                      == 'turbulent_fluctuation' )  THEN
197                      inflow_dist(k,j,6,l) = q(k,j,i) - avpr(k,6,l)
198                   ELSEIF ( TRIM( recycling_method_for_thermodynamic_quantities )  &
199                      == 'absolute_value' )  THEN
200                      inflow_dist(k,j,6,l) = q(k,j,i)
201                   ENDIF
202                ENDIF
203                IF ( passive_scalar )                                          &
204                   inflow_dist(k,j,7,l) = s(k,j,i) - avpr(k,7,l)
205            ENDDO
206          ENDDO
207          i = i + 1
208       ENDDO
209
210    ENDIF
211#else
212    DO  l = 1, nbgp
213       DO  j = nysg, nyng
214          DO  k = nzb, nzt+1
215             inflow_dist(k,j,1,l) = u(k,j,i+1) - avpr(k,1,l)
216             inflow_dist(k,j,2,l) = v(k,j,i)   - avpr(k,2,l)
217             inflow_dist(k,j,3,l) = w(k,j,i)   - avpr(k,3,l)
218             IF ( TRIM( recycling_method_for_thermodynamic_quantities )        &
219                   == 'turbulent_fluctuation' )  THEN
220                inflow_dist(k,j,4,l) = pt(k,j,i) - avpr(k,4,l)
221             ELSEIF ( TRIM( recycling_method_for_thermodynamic_quantities )    &
222                   == 'absolute_value' )  THEN
223                inflow_dist(k,j,4,l) = pt(k,j,i)
224             ENDIF
225             inflow_dist(k,j,5,l) = e(k,j,i)   - avpr(k,5,l)
226             IF ( humidity )  THEN
227                IF ( TRIM( recycling_method_for_thermodynamic_quantities )     &
228                      == 'turbulent_fluctuation' )  THEN
229                   inflow_dist(k,j,6,l) = q(k,j,i) - avpr(k,6,l)
230                ELSEIF ( TRIM( recycling_method_for_thermodynamic_quantities ) &
231                      == 'absolute_value' )  THEN
232                   inflow_dist(k,j,6,l) = q(k,j,i)
233                ENDIF
234             ENDIF
235             IF ( passive_scalar )                                             &
236                inflow_dist(k,j,7,l) = s(k,j,i) - avpr(k,7,l)
237             
238          ENDDO
239       ENDDO
240       i = i + 1
241    ENDDO
242#endif
243
244!
245!-- For parallel runs, send the disturbances to the respective inflow PE
246#if defined( __parallel )
247    IF ( myidx == id_recycling  .AND.  myidx /= id_inflow )  THEN
248
249       CALL MPI_SEND( inflow_dist(nzb,nysg,1,1), ngp_ifd, MPI_REAL,            &
250                      id_inflow, 1, comm1dx, ierr )
251
252    ELSEIF ( myidx /= id_recycling  .AND.  myidx == id_inflow )  THEN
253
254       inflow_dist = 0.0_wp
255       CALL MPI_RECV( inflow_dist(nzb,nysg,1,1), ngp_ifd, MPI_REAL,            &
256                      id_recycling, 1, comm1dx, status, ierr )
257
258    ENDIF
259
260!
261!-- y-shift for inflow_dist
262!-- Shift inflow_dist in positive y direction by a number of
263!-- PEs equal to y_shift
264    IF ( ( y_shift /= 0 ) .AND. myidx == id_inflow ) THEN
265
266!
267!--    Calculate the ID of the PE which sends data to this PE (prev) and of the
268!--    PE which receives data from this PE (next).
269       prev = MODULO(myidy - y_shift , pdims(2))
270       next = MODULO(myidy + y_shift , pdims(2))
271       
272       local_inflow_dist = 0.0_wp
273
274       CALL MPI_SENDRECV( inflow_dist(nzb,nysg,1,1), ngp_ifd, MPI_REAL,        &
275                          next, 1, local_inflow_dist(nzb,nysg,1,1), ngp_ifd,   &
276                          MPI_REAL, prev, 1, comm1dy, status, ierr )
277
278       inflow_dist = local_inflow_dist
279
280    ENDIF
281
282#endif
283
284!
285!-- Add the disturbance at the inflow
286    IF ( nxl == 0 )  THEN
287
288       DO  j = nysg, nyng
289          DO  k = nzb, nzt + 1
290
291             u(k,j,-nbgp+1:0) = mean_inflow_profiles(k,1) +                    &
292                        inflow_dist(k,j,1,1:nbgp) * inflow_damping_factor(k)
293             v(k,j,-nbgp:-1)  = mean_inflow_profiles(k,2) +                    &
294                        inflow_dist(k,j,2,1:nbgp) * inflow_damping_factor(k)
295             w(k,j,-nbgp:-1)  =                                                &
296                        inflow_dist(k,j,3,1:nbgp) * inflow_damping_factor(k)
297             IF ( TRIM( recycling_method_for_thermodynamic_quantities )        &
298                   == 'turbulent_fluctuation' )  THEN
299                pt(k,j,-nbgp:-1) = mean_inflow_profiles(k,4) +                 &
300                inflow_dist(k,j,4,1:nbgp) * inflow_damping_factor(k)
301             ELSEIF ( TRIM( recycling_method_for_thermodynamic_quantities )    &
302                   == 'absolute_value' )  THEN
303                pt(k,j,-nbgp:-1) = inflow_dist(k,j,4,1:nbgp)
304             ENDIF
305             e(k,j,-nbgp:-1)  = mean_inflow_profiles(k,5) +                    &
306                        inflow_dist(k,j,5,1:nbgp) * inflow_damping_factor(k)
307             e(k,j,-nbgp:-1)  = MAX( e(k,j,-nbgp:-1), 0.0_wp )
308             IF ( humidity )  THEN
309                IF ( TRIM( recycling_method_for_thermodynamic_quantities )     &
310                      == 'turbulent_fluctuation' )  THEN
311                   q(k,j,-nbgp:-1)  = mean_inflow_profiles(k,6) +              & 
312                      inflow_dist(k,j,6,1:nbgp) * inflow_damping_factor(k)
313                ELSEIF ( TRIM( recycling_method_for_thermodynamic_quantities ) &
314                      == 'absolute_value' )  THEN
315                   q(k,j,-nbgp:-1)  = inflow_dist(k,j,6,1:nbgp)
316                ENDIF
317             ENDIF
318             IF ( passive_scalar )                                             &
319                s(k,j,-nbgp:-1)  = mean_inflow_profiles(k,7) +                 &
320                        inflow_dist(k,j,7,1:nbgp) * inflow_damping_factor(k)
321                       
322          ENDDO
323       ENDDO
324
325    ENDIF
326
327
328    CALL cpu_log( log_point(40), 'inflow_turbulence', 'stop' )
329
330
331 END SUBROUTINE inflow_turbulence
Note: See TracBrowser for help on using the repository browser.