1 | !> @file calc_spectra.f90 |
---|
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 | ! |
---|
16 | ! Copyright 1997-2014 Leibniz Universitaet Hannover |
---|
17 | !--------------------------------------------------------------------------------! |
---|
18 | ! |
---|
19 | ! Current revisions: |
---|
20 | ! ----------------- |
---|
21 | ! |
---|
22 | ! |
---|
23 | ! Former revisions: |
---|
24 | ! ----------------- |
---|
25 | ! $Id: calc_spectra.f90 1683 2015-10-07 23:57:51Z hoffmann $ |
---|
26 | ! |
---|
27 | ! 1682 2015-10-07 23:56:08Z knoop |
---|
28 | ! Code annotations made doxygen readable |
---|
29 | ! |
---|
30 | ! 1575 2015-03-27 09:56:27Z raasch |
---|
31 | ! adjustments for psolver-queries |
---|
32 | ! |
---|
33 | ! 1511 2014-12-16 15:54:16Z suehring |
---|
34 | ! Bugfix concerning spectra normalization |
---|
35 | ! |
---|
36 | ! 1431 2014-07-15 14:47:17Z suehring |
---|
37 | ! Wavenumber-integrated spectra coincide with respective variance. |
---|
38 | ! |
---|
39 | ! 1342 2014-03-26 17:04:47Z kanani |
---|
40 | ! REAL constants defined as wp-kinds |
---|
41 | ! |
---|
42 | ! 1324 2014-03-21 09:13:16Z suehring |
---|
43 | ! Bugfix: nzb_x, nzb_yd, nyn_x, nyn_x, nzt_x, nzt_yd belong to transpose_indices |
---|
44 | ! |
---|
45 | ! 1320 2014-03-20 08:40:49Z raasch |
---|
46 | ! ONLY-attribute added to USE-statements, |
---|
47 | ! kind-parameters added to all INTEGER and REAL declaration statements, |
---|
48 | ! kinds are defined in new module kinds, |
---|
49 | ! revision history before 2012 removed, |
---|
50 | ! comment fields (!:) to be used for variable explanations added to |
---|
51 | ! all variable declaration statements |
---|
52 | ! |
---|
53 | ! 1318 2014-03-17 13:35:16Z raasch |
---|
54 | ! module interfaces removed |
---|
55 | ! |
---|
56 | ! 1216 2013-08-26 09:31:42Z raasch |
---|
57 | ! resorting of array moved to separate routine resort_for_zx, |
---|
58 | ! one argument removed from the transpose_..d routines |
---|
59 | ! |
---|
60 | ! 1120 2013-04-05 15:11:35Z raasch |
---|
61 | ! bugfix: calls of fft_x|y replaced by fft_x|y_1d |
---|
62 | ! |
---|
63 | ! 1036 2012-10-22 13:43:42Z raasch |
---|
64 | ! code put under GPL (PALM 3.9) |
---|
65 | ! |
---|
66 | ! 1003 2012-09-14 14:35:53Z raasch |
---|
67 | ! adjustment of array tend for cases with unequal subdomain sizes removed |
---|
68 | ! |
---|
69 | ! Revision 1.1 2001/01/05 15:08:07 raasch |
---|
70 | ! Initial revision |
---|
71 | ! |
---|
72 | ! |
---|
73 | ! Description: |
---|
74 | ! ------------ |
---|
75 | !> Calculate horizontal spectra along x and y. |
---|
76 | !> ATTENTION: 1d-decomposition along y still needs improvement, because in that |
---|
77 | !> case the gridpoint number along z still depends on the PE number |
---|
78 | !> because transpose_xz has to be used (and possibly also |
---|
79 | !> transpose_zyd needs modification). |
---|
80 | !------------------------------------------------------------------------------! |
---|
81 | SUBROUTINE calc_spectra |
---|
82 | |
---|
83 | |
---|
84 | #if defined( __spectra ) |
---|
85 | USE arrays_3d, & |
---|
86 | ONLY: d, tend |
---|
87 | |
---|
88 | USE control_parameters, & |
---|
89 | ONLY: average_count_sp, bc_lr_cyc, bc_ns_cyc, message_string, psolver |
---|
90 | |
---|
91 | USE cpulog, & |
---|
92 | ONLY: cpu_log, log_point |
---|
93 | |
---|
94 | USE fft_xy, & |
---|
95 | ONLY: fft_init |
---|
96 | |
---|
97 | USE indices, & |
---|
98 | ONLY: nxl, nxr, nyn, nys, nzb, nzt |
---|
99 | |
---|
100 | USE kinds |
---|
101 | |
---|
102 | USE pegrid |
---|
103 | |
---|
104 | USE spectrum, & |
---|
105 | ONLY: data_output_sp, spectra_direction |
---|
106 | |
---|
107 | |
---|
108 | IMPLICIT NONE |
---|
109 | |
---|
110 | INTEGER(iwp) :: m !< |
---|
111 | INTEGER(iwp) :: pr !< |
---|
112 | |
---|
113 | |
---|
114 | CALL cpu_log( log_point(30), 'calc_spectra', 'start' ) |
---|
115 | |
---|
116 | ! |
---|
117 | !-- Initialize ffts |
---|
118 | CALL fft_init |
---|
119 | |
---|
120 | ! |
---|
121 | !-- Reallocate array d in required size |
---|
122 | IF ( psolver(1:9) == 'multigrid' ) THEN |
---|
123 | DEALLOCATE( d ) |
---|
124 | ALLOCATE( d(nzb+1:nzt,nys:nyn,nxl:nxr) ) |
---|
125 | ENDIF |
---|
126 | |
---|
127 | m = 1 |
---|
128 | DO WHILE ( data_output_sp(m) /= ' ' .AND. m <= 10 ) |
---|
129 | ! |
---|
130 | !-- Transposition from z --> x ( y --> x in case of a 1d-decomposition |
---|
131 | !-- along x) |
---|
132 | IF ( INDEX( spectra_direction(m), 'x' ) /= 0 ) THEN |
---|
133 | |
---|
134 | ! |
---|
135 | !-- Calculation of spectra works for cyclic boundary conditions only |
---|
136 | IF ( .NOT. bc_lr_cyc ) THEN |
---|
137 | |
---|
138 | message_string = 'non-cyclic lateral boundaries along x do not'// & |
---|
139 | '& allow calculation of spectra along x' |
---|
140 | CALL message( 'calc_spectra', 'PA0160', 1, 2, 0, 6, 0 ) |
---|
141 | ENDIF |
---|
142 | |
---|
143 | CALL preprocess_spectra( m, pr ) |
---|
144 | |
---|
145 | #if defined( __parallel ) |
---|
146 | IF ( pdims(2) /= 1 ) THEN |
---|
147 | CALL resort_for_zx( d, tend ) |
---|
148 | CALL transpose_zx( tend, d ) |
---|
149 | ELSE |
---|
150 | CALL transpose_yxd( d, d ) |
---|
151 | ENDIF |
---|
152 | CALL calc_spectra_x( d, pr, m ) |
---|
153 | #else |
---|
154 | message_string = 'sorry, calculation of spectra in non parallel ' // & |
---|
155 | 'mode& is still not realized' |
---|
156 | CALL message( 'calc_spectra', 'PA0161', 1, 2, 0, 6, 0 ) |
---|
157 | #endif |
---|
158 | |
---|
159 | ENDIF |
---|
160 | |
---|
161 | ! |
---|
162 | !-- Transposition from z --> y (d is rearranged only in case of a |
---|
163 | !-- 1d-decomposition along x) |
---|
164 | IF ( INDEX( spectra_direction(m), 'y' ) /= 0 ) THEN |
---|
165 | |
---|
166 | ! |
---|
167 | !-- Calculation of spectra works for cyclic boundary conditions only |
---|
168 | IF ( .NOT. bc_ns_cyc ) THEN |
---|
169 | IF ( myid == 0 ) THEN |
---|
170 | message_string = 'non-cyclic lateral boundaries along y do' // & |
---|
171 | ' not & allow calculation of spectra along y' |
---|
172 | CALL message( 'calc_spectra', 'PA0162', 1, 2, 0, 6, 0 ) |
---|
173 | ENDIF |
---|
174 | CALL local_stop |
---|
175 | ENDIF |
---|
176 | |
---|
177 | CALL preprocess_spectra( m, pr ) |
---|
178 | |
---|
179 | #if defined( __parallel ) |
---|
180 | CALL transpose_zyd( d, d ) |
---|
181 | CALL calc_spectra_y( d, pr, m ) |
---|
182 | #else |
---|
183 | message_string = 'sorry, calculation of spectra in non parallel' // & |
---|
184 | 'mode& is still not realized' |
---|
185 | CALL message( 'calc_spectra', 'PA0161', 1, 2, 0, 6, 0 ) |
---|
186 | #endif |
---|
187 | |
---|
188 | ENDIF |
---|
189 | |
---|
190 | ! |
---|
191 | !-- Increase counter for next spectrum |
---|
192 | m = m + 1 |
---|
193 | |
---|
194 | ENDDO |
---|
195 | |
---|
196 | ! |
---|
197 | !-- Increase counter for averaging process in routine plot_spectra |
---|
198 | average_count_sp = average_count_sp + 1 |
---|
199 | |
---|
200 | CALL cpu_log( log_point(30), 'calc_spectra', 'stop' ) |
---|
201 | |
---|
202 | #endif |
---|
203 | END SUBROUTINE calc_spectra |
---|
204 | |
---|
205 | |
---|
206 | #if defined( __spectra ) |
---|
207 | !------------------------------------------------------------------------------! |
---|
208 | ! Description: |
---|
209 | ! ------------ |
---|
210 | !> @todo Missing subroutine description. |
---|
211 | !------------------------------------------------------------------------------! |
---|
212 | SUBROUTINE preprocess_spectra( m, pr ) |
---|
213 | |
---|
214 | USE arrays_3d, & |
---|
215 | ONLY: d, pt, q, u, v, w |
---|
216 | |
---|
217 | USE indices, & |
---|
218 | ONLY: ngp_2dh, nxl, nxr, nyn, nys, nzb, nzt |
---|
219 | |
---|
220 | USE kinds |
---|
221 | |
---|
222 | USE pegrid |
---|
223 | |
---|
224 | USE spectrum, & |
---|
225 | ONLY: data_output_sp |
---|
226 | |
---|
227 | USE statistics, & |
---|
228 | ONLY: hom, var_d |
---|
229 | |
---|
230 | |
---|
231 | IMPLICIT NONE |
---|
232 | |
---|
233 | INTEGER(iwp) :: i !< |
---|
234 | INTEGER(iwp) :: j !< |
---|
235 | INTEGER(iwp) :: k !< |
---|
236 | INTEGER(iwp) :: m !< |
---|
237 | INTEGER(iwp) :: pr !< |
---|
238 | |
---|
239 | REAL(wp), DIMENSION(nzb:nzt+1) :: var_d_l |
---|
240 | |
---|
241 | SELECT CASE ( TRIM( data_output_sp(m) ) ) |
---|
242 | |
---|
243 | CASE ( 'u' ) |
---|
244 | pr = 1 |
---|
245 | d(nzb+1:nzt,nys:nyn,nxl:nxr) = u(nzb+1:nzt,nys:nyn,nxl:nxr) |
---|
246 | |
---|
247 | CASE ( 'v' ) |
---|
248 | pr = 2 |
---|
249 | d(nzb+1:nzt,nys:nyn,nxl:nxr) = v(nzb+1:nzt,nys:nyn,nxl:nxr) |
---|
250 | |
---|
251 | CASE ( 'w' ) |
---|
252 | pr = 3 |
---|
253 | d(nzb+1:nzt,nys:nyn,nxl:nxr) = w(nzb+1:nzt,nys:nyn,nxl:nxr) |
---|
254 | |
---|
255 | CASE ( 'pt' ) |
---|
256 | pr = 4 |
---|
257 | d(nzb+1:nzt,nys:nyn,nxl:nxr) = pt(nzb+1:nzt,nys:nyn,nxl:nxr) |
---|
258 | |
---|
259 | CASE ( 'q' ) |
---|
260 | pr = 41 |
---|
261 | d(nzb+1:nzt,nys:nyn,nxl:nxr) = q(nzb+1:nzt,nys:nyn,nxl:nxr) |
---|
262 | |
---|
263 | CASE DEFAULT |
---|
264 | ! |
---|
265 | !-- The DEFAULT case is reached either if the parameter data_output_sp(m) |
---|
266 | !-- contains a wrong character string or if the user has coded a special |
---|
267 | !-- case in the user interface. There, the subroutine user_spectra |
---|
268 | !-- checks which of these two conditions applies. |
---|
269 | CALL user_spectra( 'preprocess', m, pr ) |
---|
270 | |
---|
271 | END SELECT |
---|
272 | |
---|
273 | ! |
---|
274 | !-- Subtract horizontal mean from the array, for which spectra have to be |
---|
275 | !-- calculated |
---|
276 | var_d_l(:) = 0.0_wp |
---|
277 | DO i = nxl, nxr |
---|
278 | DO j = nys, nyn |
---|
279 | DO k = nzb+1, nzt |
---|
280 | d(k,j,i) = d(k,j,i) - hom(k,1,pr,0) |
---|
281 | var_d_l(k) = var_d_l(k) + d(k,j,i) * d(k,j,i) |
---|
282 | ENDDO |
---|
283 | ENDDO |
---|
284 | ENDDO |
---|
285 | ! |
---|
286 | !-- Compute total variance from local variances |
---|
287 | var_d(:) = 0.0_wp |
---|
288 | #if defined( __parallel ) |
---|
289 | IF ( collective_wait ) CALL MPI_BARRIER( comm2d, ierr ) |
---|
290 | CALL MPI_ALLREDUCE( var_d_l(0), var_d(0), nzt+1-nzb, MPI_REAL, & |
---|
291 | MPI_SUM, comm2d, ierr ) |
---|
292 | #else |
---|
293 | var_d(:) = var_d_l(:) |
---|
294 | #endif |
---|
295 | var_d(:) = var_d(:) / ngp_2dh(0) |
---|
296 | |
---|
297 | END SUBROUTINE preprocess_spectra |
---|
298 | |
---|
299 | |
---|
300 | !------------------------------------------------------------------------------! |
---|
301 | ! Description: |
---|
302 | ! ------------ |
---|
303 | !> @todo Missing subroutine description. |
---|
304 | !------------------------------------------------------------------------------! |
---|
305 | SUBROUTINE calc_spectra_x( ddd, pr, m ) |
---|
306 | |
---|
307 | USE arrays_3d, & |
---|
308 | ONLY: |
---|
309 | |
---|
310 | USE control_parameters, & |
---|
311 | ONLY: fft_method |
---|
312 | |
---|
313 | USE fft_xy, & |
---|
314 | ONLY: fft_x_1d |
---|
315 | |
---|
316 | USE grid_variables, & |
---|
317 | ONLY: dx |
---|
318 | |
---|
319 | USE indices, & |
---|
320 | ONLY: nx, ny |
---|
321 | |
---|
322 | USE kinds |
---|
323 | |
---|
324 | USE pegrid |
---|
325 | |
---|
326 | USE spectrum, & |
---|
327 | ONLY: comp_spectra_level, n_sp_x |
---|
328 | |
---|
329 | USE statistics, & |
---|
330 | ONLY: spectrum_x, var_d |
---|
331 | |
---|
332 | USE transpose_indices, & |
---|
333 | ONLY: nyn_x, nys_x, nzb_x, nzt_x |
---|
334 | |
---|
335 | |
---|
336 | IMPLICIT NONE |
---|
337 | |
---|
338 | INTEGER(iwp) :: i !< |
---|
339 | INTEGER(iwp) :: ishape(1) !< |
---|
340 | INTEGER(iwp) :: j !< |
---|
341 | INTEGER(iwp) :: k !< |
---|
342 | INTEGER(iwp) :: m !< |
---|
343 | INTEGER(iwp) :: n !< |
---|
344 | INTEGER(iwp) :: pr !< |
---|
345 | |
---|
346 | REAL(wp) :: exponent !< |
---|
347 | REAL(wp) :: sum_spec_dum !< wavenumber-integrated spectrum |
---|
348 | |
---|
349 | REAL(wp), DIMENSION(0:nx) :: work !< |
---|
350 | |
---|
351 | REAL(wp), DIMENSION(0:nx/2) :: sums_spectra_l !< |
---|
352 | |
---|
353 | REAL(wp), DIMENSION(0:nx/2,100) :: sums_spectra !< |
---|
354 | |
---|
355 | REAL(wp), DIMENSION(0:nx,nys_x:nyn_x,nzb_x:nzt_x) :: ddd !< |
---|
356 | |
---|
357 | ! |
---|
358 | !-- Exponent for geometric average |
---|
359 | exponent = 1.0_wp / ( ny + 1.0_wp ) |
---|
360 | |
---|
361 | ! |
---|
362 | !-- Loop over all levels defined by the user |
---|
363 | n = 1 |
---|
364 | DO WHILE ( comp_spectra_level(n) /= 999999 .AND. n <= 100 ) |
---|
365 | |
---|
366 | k = comp_spectra_level(n) |
---|
367 | |
---|
368 | ! |
---|
369 | !-- Calculate FFT only if the corresponding level is situated on this PE |
---|
370 | IF ( k >= nzb_x .AND. k <= nzt_x ) THEN |
---|
371 | |
---|
372 | DO j = nys_x, nyn_x |
---|
373 | |
---|
374 | work = ddd(0:nx,j,k) |
---|
375 | CALL fft_x_1d( work, 'forward' ) |
---|
376 | |
---|
377 | ddd(0,j,k) = dx * work(0)**2 |
---|
378 | DO i = 1, nx/2 |
---|
379 | ddd(i,j,k) = dx * ( work(i)**2 + work(nx+1-i)**2 ) |
---|
380 | ENDDO |
---|
381 | |
---|
382 | ENDDO |
---|
383 | |
---|
384 | ! |
---|
385 | !-- Local sum and geometric average of these spectra |
---|
386 | !-- (WARNING: no global sum should be performed, because floating |
---|
387 | !-- point overflow may occur) |
---|
388 | DO i = 0, nx/2 |
---|
389 | |
---|
390 | sums_spectra_l(i) = 1.0_wp |
---|
391 | DO j = nys_x, nyn_x |
---|
392 | sums_spectra_l(i) = sums_spectra_l(i) * ddd(i,j,k)**exponent |
---|
393 | ENDDO |
---|
394 | |
---|
395 | ENDDO |
---|
396 | |
---|
397 | ELSE |
---|
398 | |
---|
399 | sums_spectra_l = 1.0_wp |
---|
400 | |
---|
401 | ENDIF |
---|
402 | |
---|
403 | ! |
---|
404 | !-- Global sum of spectra on PE0 (from where they are written on file) |
---|
405 | sums_spectra(:,n) = 0.0_wp |
---|
406 | #if defined( __parallel ) |
---|
407 | CALL MPI_BARRIER( comm2d, ierr ) ! Necessary? |
---|
408 | CALL MPI_REDUCE( sums_spectra_l(0), sums_spectra(0,n), nx/2+1, & |
---|
409 | MPI_REAL, MPI_PROD, 0, comm2d, ierr ) |
---|
410 | #else |
---|
411 | sums_spectra(:,n) = sums_spectra_l |
---|
412 | #endif |
---|
413 | ! |
---|
414 | !-- Normalize spectra by variance |
---|
415 | sum_spec_dum = SUM( sums_spectra(:,n) ) |
---|
416 | IF ( sum_spec_dum /= 0.0_wp ) THEN |
---|
417 | sums_spectra(:,n) = sums_spectra(:,n) * var_d(k) / sum_spec_dum |
---|
418 | ENDIF |
---|
419 | n = n + 1 |
---|
420 | |
---|
421 | ENDDO |
---|
422 | n = n - 1 |
---|
423 | |
---|
424 | IF ( myid == 0 ) THEN |
---|
425 | ! |
---|
426 | !-- Sum of spectra for later averaging (see routine data_output_spectra) |
---|
427 | DO i = 1, nx/2 |
---|
428 | DO k = 1, n |
---|
429 | spectrum_x(i,k,m) = spectrum_x(i,k,m) + sums_spectra(i,k) |
---|
430 | ENDDO |
---|
431 | ENDDO |
---|
432 | |
---|
433 | ENDIF |
---|
434 | ! |
---|
435 | !-- n_sp_x is needed by data_output_spectra_x |
---|
436 | n_sp_x = n |
---|
437 | |
---|
438 | END SUBROUTINE calc_spectra_x |
---|
439 | |
---|
440 | |
---|
441 | !------------------------------------------------------------------------------! |
---|
442 | ! Description: |
---|
443 | ! ------------ |
---|
444 | !> @todo Missing subroutine description. |
---|
445 | !------------------------------------------------------------------------------! |
---|
446 | SUBROUTINE calc_spectra_y( ddd, pr, m ) |
---|
447 | |
---|
448 | USE arrays_3d, & |
---|
449 | ONLY: |
---|
450 | |
---|
451 | USE control_parameters, & |
---|
452 | ONLY: fft_method |
---|
453 | |
---|
454 | USE fft_xy, & |
---|
455 | ONLY: fft_y_1d |
---|
456 | |
---|
457 | USE grid_variables, & |
---|
458 | ONLY: dy |
---|
459 | |
---|
460 | USE indices, & |
---|
461 | ONLY: nx, ny |
---|
462 | |
---|
463 | USE kinds |
---|
464 | |
---|
465 | USE pegrid |
---|
466 | |
---|
467 | USE spectrum, & |
---|
468 | ONLY: comp_spectra_level, n_sp_y |
---|
469 | |
---|
470 | USE statistics, & |
---|
471 | ONLY: spectrum_y, var_d |
---|
472 | |
---|
473 | USE transpose_indices, & |
---|
474 | ONLY: nxl_yd, nxr_yd, nzb_yd, nzt_yd |
---|
475 | |
---|
476 | |
---|
477 | IMPLICIT NONE |
---|
478 | |
---|
479 | INTEGER(iwp) :: i !< |
---|
480 | INTEGER(iwp) :: j !< |
---|
481 | INTEGER(iwp) :: jshape(1) !< |
---|
482 | INTEGER(iwp) :: k !< |
---|
483 | INTEGER(iwp) :: m !< |
---|
484 | INTEGER(iwp) :: n !< |
---|
485 | INTEGER(iwp) :: pr !< |
---|
486 | |
---|
487 | REAL(wp) :: exponent !< |
---|
488 | REAL(wp) :: sum_spec_dum !< wavenumber-integrated spectrum |
---|
489 | |
---|
490 | REAL(wp), DIMENSION(0:ny) :: work !< |
---|
491 | |
---|
492 | REAL(wp), DIMENSION(0:ny/2) :: sums_spectra_l !< |
---|
493 | |
---|
494 | REAL(wp), DIMENSION(0:ny/2,100) :: sums_spectra !< |
---|
495 | |
---|
496 | REAL(wp), DIMENSION(0:ny,nxl_yd:nxr_yd,nzb_yd:nzt_yd) :: ddd !< |
---|
497 | |
---|
498 | |
---|
499 | ! |
---|
500 | !-- Exponent for geometric average |
---|
501 | exponent = 1.0_wp / ( nx + 1.0_wp ) |
---|
502 | |
---|
503 | ! |
---|
504 | !-- Loop over all levels defined by the user |
---|
505 | n = 1 |
---|
506 | DO WHILE ( comp_spectra_level(n) /= 999999 .AND. n <= 100 ) |
---|
507 | |
---|
508 | k = comp_spectra_level(n) |
---|
509 | |
---|
510 | ! |
---|
511 | !-- Calculate FFT only if the corresponding level is situated on this PE |
---|
512 | IF ( k >= nzb_yd .AND. k <= nzt_yd ) THEN |
---|
513 | |
---|
514 | DO i = nxl_yd, nxr_yd |
---|
515 | |
---|
516 | work = ddd(0:ny,i,k) |
---|
517 | CALL fft_y_1d( work, 'forward' ) |
---|
518 | |
---|
519 | ddd(0,i,k) = dy * work(0)**2 |
---|
520 | DO j = 1, ny/2 |
---|
521 | ddd(j,i,k) = dy * ( work(j)**2 + work(ny+1-j)**2 ) |
---|
522 | ENDDO |
---|
523 | |
---|
524 | ENDDO |
---|
525 | |
---|
526 | ! |
---|
527 | !-- Local sum and geometric average of these spectra |
---|
528 | !-- (WARNING: no global sum should be performed, because floating |
---|
529 | !-- point overflow may occur) |
---|
530 | DO j = 0, ny/2 |
---|
531 | |
---|
532 | sums_spectra_l(j) = 1.0_wp |
---|
533 | DO i = nxl_yd, nxr_yd |
---|
534 | sums_spectra_l(j) = sums_spectra_l(j) * ddd(j,i,k)**exponent |
---|
535 | ENDDO |
---|
536 | |
---|
537 | ENDDO |
---|
538 | |
---|
539 | ELSE |
---|
540 | |
---|
541 | sums_spectra_l = 1.0_wp |
---|
542 | |
---|
543 | ENDIF |
---|
544 | |
---|
545 | ! |
---|
546 | !-- Global sum of spectra on PE0 (from where they are written on file) |
---|
547 | sums_spectra(:,n) = 0.0_wp |
---|
548 | #if defined( __parallel ) |
---|
549 | CALL MPI_BARRIER( comm2d, ierr ) ! Necessary? |
---|
550 | CALL MPI_REDUCE( sums_spectra_l(0), sums_spectra(0,n), ny/2+1, & |
---|
551 | MPI_REAL, MPI_PROD, 0, comm2d, ierr ) |
---|
552 | #else |
---|
553 | sums_spectra(:,n) = sums_spectra_l |
---|
554 | #endif |
---|
555 | ! |
---|
556 | !-- Normalize spectra by variance |
---|
557 | sum_spec_dum = SUM( sums_spectra(:,n) ) |
---|
558 | IF ( SUM(sums_spectra(:,n)) /= 0.0_wp ) THEN |
---|
559 | sums_spectra(:,n) = sums_spectra(:,n) * var_d(k) / SUM(sums_spectra(:,n)) |
---|
560 | ENDIF |
---|
561 | n = n + 1 |
---|
562 | |
---|
563 | ENDDO |
---|
564 | n = n - 1 |
---|
565 | |
---|
566 | |
---|
567 | IF ( myid == 0 ) THEN |
---|
568 | ! |
---|
569 | !-- Sum of spectra for later averaging (see routine data_output_spectra) |
---|
570 | DO j = 1, ny/2 |
---|
571 | DO k = 1, n |
---|
572 | spectrum_y(j,k,m) = spectrum_y(j,k,m) + sums_spectra(j,k) |
---|
573 | ENDDO |
---|
574 | ENDDO |
---|
575 | |
---|
576 | ENDIF |
---|
577 | |
---|
578 | ! |
---|
579 | !-- n_sp_y is needed by data_output_spectra_y |
---|
580 | n_sp_y = n |
---|
581 | |
---|
582 | END SUBROUTINE calc_spectra_y |
---|
583 | #endif |
---|