source: palm/trunk/SOURCE/spectrum.f90 @ 1808

Last change on this file since 1808 was 1808, checked in by raasch, 8 years ago

preprocessor directives using machine dependent flags (lc, ibm, etc.) mostly removed from the code

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