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

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

pmc-change in server-client get-put, spectra-directives removed, spectra-package modularized

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