source: palm/trunk/SOURCE/spectra_mod.f90 @ 2823

Last change on this file since 2823 was 2718, checked in by maronga, 6 years ago

deleting of deprecated files; headers updated where needed

  • Property svn:keywords set to Id
File size: 27.1 KB
Line 
1!> @file spectra_mod.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-2018 Leibniz Universitaet Hannover
18!------------------------------------------------------------------------------!
19!
20! Current revisions:
21! -----------------
22!
23!
24! Former revisions:
25! -----------------
26! $Id: spectra_mod.f90 2718 2018-01-02 08:49:38Z Giersch $
27! Corrected "Former revisions" section
28!
29! 2696 2017-12-14 17:12:51Z kanani
30! Change in file header (GPL part)
31!
32! 2216 2017-04-28 12:54:20Z suehring
33!
34! 2193 2017-03-22 04:21:28Z raasch
35! Normalization of spectra output adjusted
36!
37! 2192 2017-03-22 04:14:10Z raasch
38! bugfix for index bounds of arrays spectrum_x and spectrum_y
39!
40! 2000 2016-08-20 18:09:15Z knoop
41! Forced header and separation lines into 80 columns
42!
43! 1960 2016-07-12 16:34:24Z suehring
44! Additional default spectra for passive scalar
45!
46! 1833 2016-04-07 14:23:03Z raasch
47! file renamed, reading the spectra_par NAMELIST moved from package_parin to
48! here
49!
50! 1815 2016-04-06 13:49:59Z raasch
51! bugfix: preprocessor directives included for the non-parallel case
52!
53! 1808 2016-04-05 19:44:00Z raasch
54! MPI module used by default on all machines
55!
56! 1786 2016-03-08 05:49:27Z raasch
57! routine is modularized, filename renamed from calc_spectra to spectrum,
58! privious data module spectrum moved from modules.f90 to here,
59! cpp-direktives for spectra removed, immediate return if no spectra levels are
60! given
61!
62! 1682 2015-10-07 23:56:08Z knoop
63! Code annotations made doxygen readable
64!
65! 1575 2015-03-27 09:56:27Z raasch
66! adjustments for psolver-queries
67!
68! 1511 2014-12-16 15:54:16Z suehring
69! Bugfix concerning spectra normalization
70!
71! 1431 2014-07-15 14:47:17Z suehring
72! Wavenumber-integrated spectra coincide with respective variance.
73!
74! 1342 2014-03-26 17:04:47Z kanani
75! REAL constants defined as wp-kinds
76!
77! 1324 2014-03-21 09:13:16Z suehring
78! Bugfix: nzb_x, nzb_yd, nyn_x, nyn_x, nzt_x, nzt_yd belong to transpose_indices
79!
80! 1320 2014-03-20 08:40:49Z raasch
81! ONLY-attribute added to USE-statements,
82! kind-parameters added to all INTEGER and REAL declaration statements,
83! kinds are defined in new module kinds,
84! revision history before 2012 removed,
85! comment fields (!:) to be used for variable explanations added to
86! all variable declaration statements
87!
88! 1318 2014-03-17 13:35:16Z raasch
89! module interfaces removed
90!
91! 1216 2013-08-26 09:31:42Z raasch
92! resorting of array moved to separate routine resort_for_zx,
93! one argument removed from the transpose_..d routines
94!
95! 1120 2013-04-05 15:11:35Z raasch
96! bugfix: calls of fft_x|y replaced by fft_x|y_1d
97!
98! 1036 2012-10-22 13:43:42Z raasch
99! code put under GPL (PALM 3.9)
100!
101! 1003 2012-09-14 14:35:53Z raasch
102! adjustment of array tend for cases with unequal subdomain sizes removed
103!
104! Revision 1.1  2001/01/05 15:08:07  raasch
105! Initial revision
106!
107!
108! Description:
109! ------------
110!> Calculate horizontal spectra along x and y.
111!> ATTENTION: 1d-decomposition along y still needs improvement, because in that
112!>            case the gridpoint number along z still depends on the PE number
113!>            because transpose_xz has to be used (and possibly also
114!>            transpose_zyd needs modification).
115!------------------------------------------------------------------------------!
116 MODULE spectra_mod
117
118    USE kinds
119
120    PRIVATE
121
122    CHARACTER (LEN=2),  DIMENSION(10) ::  spectra_direction = 'x'
123    CHARACTER (LEN=10), DIMENSION(10) ::  data_output_sp  = ' '
124
125    INTEGER(iwp) ::  average_count_sp = 0
126    INTEGER(iwp) ::  dosp_time_count = 0
127    INTEGER(iwp) ::  n_sp_x = 0, n_sp_y = 0
128
129    INTEGER(iwp) ::  comp_spectra_level(100) = 999999
130
131    LOGICAL ::  calculate_spectra   = .FALSE.  !< internal switch that spectra are calculated
132    LOGICAL ::  spectra_initialized = .FALSE.  !< internal switch that spectra related quantities are initialized
133
134    REAL(wp) ::  averaging_interval_sp = 9999999.9_wp  !< averaging interval for spectra output
135    REAL(wp) ::  dt_dosp = 9999999.9_wp                !< time interval for spectra output
136    REAL(wp) ::  skip_time_dosp = 9999999.9_wp         !< no output of spectra data before this interval has passed
137
138    REAL(wp), DIMENSION(:), ALLOCATABLE ::  var_d
139
140    REAL(wp), DIMENSION(:,:,:), ALLOCATABLE ::  spectrum_x, spectrum_y
141
142    SAVE
143
144    INTERFACE calc_spectra
145       MODULE PROCEDURE calc_spectra
146    END INTERFACE calc_spectra
147
148    INTERFACE preprocess_spectra
149       MODULE PROCEDURE preprocess_spectra
150    END INTERFACE preprocess_spectra
151
152    INTERFACE calc_spectra_x
153       MODULE PROCEDURE calc_spectra_x
154    END INTERFACE calc_spectra_x
155
156    INTERFACE calc_spectra_y
157       MODULE PROCEDURE calc_spectra_y
158    END INTERFACE calc_spectra_y
159
160    INTERFACE spectra_check_parameters
161       MODULE PROCEDURE spectra_check_parameters
162    END INTERFACE spectra_check_parameters
163
164    INTERFACE spectra_header
165       MODULE PROCEDURE spectra_header
166    END INTERFACE spectra_header
167
168    INTERFACE spectra_init
169       MODULE PROCEDURE spectra_init
170    END INTERFACE spectra_init
171
172    INTERFACE spectra_parin
173       MODULE PROCEDURE spectra_parin
174    END INTERFACE spectra_parin
175
176    PUBLIC average_count_sp, averaging_interval_sp, calc_spectra,              &
177           calculate_spectra, comp_spectra_level, data_output_sp,              &
178           dosp_time_count, dt_dosp, n_sp_x, n_sp_y, plot_spectra_level,       &
179           skip_time_dosp, spectra_check_parameters, spectra_direction,        &
180           spectra_header, spectra_init, spectra_parin, spectrum_x,            &
181           spectrum_y, var_d
182
183
184 CONTAINS
185
186!------------------------------------------------------------------------------!
187! Description:
188! ------------
189!> Parin for &spectra_par for calculating spectra
190!------------------------------------------------------------------------------!
191    SUBROUTINE spectra_parin
192
193       USE control_parameters,                                                 &
194           ONLY:  dt_data_output
195
196       IMPLICIT NONE
197
198       CHARACTER (LEN=80) ::  line  !< dummy string that contains the current  &
199                                    !< line of the parameter file
200
201       NAMELIST /spectra_par/  averaging_interval_sp, comp_spectra_level,      &
202                               data_output_sp, dt_dosp, skip_time_dosp,        &
203                               spectra_direction
204
205
206!
207!--    Position the namelist-file at the beginning (it was already opened in
208!--    parin), search for the namelist-group of the package and position the
209!--    file at this line.
210       line = ' '
211
212!
213!--    Try to find the spectra package
214       REWIND ( 11 )
215       line = ' '
216       DO   WHILE ( INDEX( line, '&spectra_par' ) == 0 )
217          READ ( 11, '(A)', END=10 )  line
218       ENDDO
219       BACKSPACE ( 11 )
220
221!
222!--    Read namelist
223       READ ( 11, spectra_par )
224
225!
226!--    Default setting of dt_dosp here (instead of check_parameters), because
227!--    its current value is needed in init_pegrid
228       IF ( dt_dosp == 9999999.9_wp )  dt_dosp = dt_data_output
229
230!
231!--    Set general switch that spectra shall be calculated
232       calculate_spectra = .TRUE.
233
234 10    CONTINUE
235
236    END SUBROUTINE spectra_parin
237
238
239
240!------------------------------------------------------------------------------!
241! Description:
242! ------------
243!> Initialization of spectra related variables
244!------------------------------------------------------------------------------!
245    SUBROUTINE spectra_init
246
247       USE indices,                                                            &
248           ONLY:  nx, ny, nzb, nzt
249
250       IMPLICIT NONE
251
252       IF ( spectra_initialized )  RETURN
253
254       IF ( dt_dosp /= 9999999.9_wp )  THEN
255          ALLOCATE( spectrum_x( 1:nx/2, 1:100, 1:10 ),                         &
256                    spectrum_y( 1:ny/2, 1:100, 1:10 ) )
257          spectrum_x = 0.0_wp
258          spectrum_y = 0.0_wp
259
260          ALLOCATE( var_d(nzb:nzt+1) )
261          var_d = 0.0_wp
262       ENDIF
263
264       spectra_initialized = .TRUE.
265
266    END SUBROUTINE spectra_init
267
268
269
270!------------------------------------------------------------------------------!
271! Description:
272! ------------
273!> Check spectra related quantities
274!------------------------------------------------------------------------------!
275    SUBROUTINE spectra_check_parameters
276
277       USE control_parameters,                                                 &
278           ONLY:  averaging_interval, message_string, skip_time_data_output
279
280       IMPLICIT NONE
281
282!
283!--    Check the average interval
284       IF ( averaging_interval_sp == 9999999.9_wp )  THEN
285          averaging_interval_sp = averaging_interval
286       ENDIF
287
288       IF ( averaging_interval_sp > dt_dosp )  THEN
289          WRITE( message_string, * )  'averaging_interval_sp = ',              &
290                averaging_interval_sp, ' must be <= dt_dosp = ', dt_dosp
291          CALL message( 'spectra_check_parameters', 'PA0087', 1, 2, 0, 6, 0 )
292       ENDIF
293
294!
295!--    Set the default skip time interval for data output, if necessary
296       IF ( skip_time_dosp == 9999999.9_wp )                                   &
297                                          skip_time_dosp = skip_time_data_output
298
299    END SUBROUTINE spectra_check_parameters
300
301
302
303!------------------------------------------------------------------------------!
304! Description:
305! ------------
306!> Header output for spectra
307!>
308!> @todo Output of netcdf data format and compression level
309!------------------------------------------------------------------------------!
310    SUBROUTINE spectra_header ( io )
311
312       USE control_parameters,                                                 &
313           ONLY:  dt_averaging_input_pr
314
315!       USE netcdf_interface,                                                  &
316!           ONLY:  netcdf_data_format_string, netcdf_deflate
317
318       IMPLICIT NONE
319
320       CHARACTER (LEN=40) ::  output_format       !< internal string
321
322       INTEGER(iwp) ::  i                         !< internal counter
323       INTEGER(iwp), INTENT(IN) ::  io            !< Unit of the output file
324
325!
326!--    Spectra output
327       IF ( dt_dosp /= 9999999.9_wp )  THEN
328          WRITE ( io, 1 )
329
330!          output_format = netcdf_data_format_string
331!          IF ( netcdf_deflate == 0 )  THEN
332!             WRITE ( io, 2 )  output_format
333!          ELSE
334!             WRITE ( io, 3 )  TRIM( output_format ), netcdf_deflate
335!          ENDIF
336          WRITE ( io, 2 )  'see profiles or other quantities'
337          WRITE ( io, 4 )  dt_dosp
338          IF ( skip_time_dosp /= 0.0_wp )  WRITE ( io, 5 )  skip_time_dosp
339          WRITE ( io, 6 )  ( data_output_sp(i), i = 1,10 ),     &
340                           ( spectra_direction(i), i = 1,10 ),  &
341                           ( comp_spectra_level(i), i = 1,100 ), &
342                           averaging_interval_sp, dt_averaging_input_pr
343       ENDIF
344
345     1 FORMAT ('    Spectra:')
346     2 FORMAT ('       Output format: ',A/)
347     3 FORMAT ('       Output format: ',A, '   compressed with level: ',I1/)
348     4 FORMAT ('       Output every ',F7.1,' s'/)
349     5 FORMAT ('       No output during initial ',F8.2,' s')
350     6 FORMAT ('       Arrays:     ', 10(A5,',')/                         &
351               '       Directions: ', 10(A5,',')/                         &
352               '       height levels  k = ', 20(I3,',')/                  &
353               '                          ', 20(I3,',')/                  &
354               '                          ', 20(I3,',')/                  &
355               '                          ', 20(I3,',')/                  &
356               '                          ', 19(I3,','),I3,'.'/           &
357               '       Time averaged over ', F7.1, ' s,' /                &
358               '       Profiles for the time averaging are taken every ', &
359                    F6.1,' s')
360
361    END SUBROUTINE spectra_header
362
363
364
365    SUBROUTINE calc_spectra
366
367       USE arrays_3d,                                                          &
368           ONLY:  d, tend
369
370       USE control_parameters,                                                 &
371           ONLY:  bc_lr_cyc, bc_ns_cyc, message_string, psolver
372
373       USE cpulog,                                                             &
374           ONLY:  cpu_log, log_point
375
376       USE fft_xy,                                                             &
377           ONLY:  fft_init
378
379       USE indices,                                                            &
380           ONLY:  nxl, nxr, nyn, nys, nzb, nzt
381
382       USE kinds
383
384       USE pegrid,                                                             &
385           ONLY:  myid, pdims
386
387       IMPLICIT NONE
388
389       INTEGER(iwp) ::  m  !<
390       INTEGER(iwp) ::  pr !<
391
392
393!
394!--    Check if user gave any levels for spectra to be calculated
395       IF ( comp_spectra_level(1) == 999999 )  RETURN
396
397       CALL cpu_log( log_point(30), 'calc_spectra', 'start' )
398
399!
400!--    Initialize spectra related quantities
401       CALL spectra_init
402
403!
404!--    Initialize ffts
405       CALL fft_init
406
407!
408!--    Reallocate array d in required size
409       IF ( psolver(1:9) == 'multigrid' )  THEN
410          DEALLOCATE( d )
411          ALLOCATE( d(nzb+1:nzt,nys:nyn,nxl:nxr) )
412       ENDIF
413
414       m = 1
415       DO WHILE ( data_output_sp(m) /= ' '  .AND.  m <= 10 )
416!
417!--       Transposition from z --> x  ( y --> x in case of a 1d-decomposition
418!--       along x)
419          IF ( INDEX( spectra_direction(m), 'x' ) /= 0 )  THEN
420
421!
422!--          Calculation of spectra works for cyclic boundary conditions only
423             IF ( .NOT. bc_lr_cyc )  THEN
424
425                message_string = 'non-cyclic lateral boundaries along x do'//  &
426                                 ' not & allow calculation of spectra along x'
427                CALL message( 'calc_spectra', 'PA0160', 1, 2, 0, 6, 0 )
428             ENDIF
429
430             CALL preprocess_spectra( m, pr )
431
432#if defined( __parallel )
433             IF ( pdims(2) /= 1 )  THEN
434                CALL resort_for_zx( d, tend )
435                CALL transpose_zx( tend, d )
436             ELSE
437                CALL transpose_yxd( d, d )
438             ENDIF
439             CALL calc_spectra_x( d, pr, m )
440#else
441             message_string = 'sorry, calculation of spectra in non paral' //  &
442                              'lel mode& is still not realized'
443             CALL message( 'calc_spectra', 'PA0161', 1, 2, 0, 6, 0 )
444#endif
445
446          ENDIF
447
448!
449!--       Transposition from z --> y (d is rearranged only in case of a
450!--       1d-decomposition along x)
451          IF ( INDEX( spectra_direction(m), 'y' ) /= 0 )  THEN
452
453!
454!--          Calculation of spectra works for cyclic boundary conditions only
455             IF ( .NOT. bc_ns_cyc )  THEN
456                IF ( myid == 0 )  THEN
457                   message_string = 'non-cyclic lateral boundaries along y' // &
458                                    ' do not & allow calculation of spectr' // &
459                                    'a along y'
460                   CALL message( 'calc_spectra', 'PA0162', 1, 2, 0, 6, 0 )
461                ENDIF
462                CALL local_stop
463             ENDIF
464
465             CALL preprocess_spectra( m, pr )
466
467#if defined( __parallel )
468             CALL transpose_zyd( d, d )
469             CALL calc_spectra_y( d, pr, m )
470#else
471             message_string = 'sorry, calculation of spectra in non paral' //  &
472                              'lel mode& is still not realized'
473             CALL message( 'calc_spectra', 'PA0161', 1, 2, 0, 6, 0 )
474#endif
475
476          ENDIF
477
478!
479!--       Increase counter for next spectrum
480          m = m + 1
481         
482       ENDDO
483
484!
485!--    Increase counter for averaging process in routine plot_spectra
486       average_count_sp = average_count_sp + 1
487
488       CALL cpu_log( log_point(30), 'calc_spectra', 'stop' )
489
490    END SUBROUTINE calc_spectra
491
492
493!------------------------------------------------------------------------------!
494! Description:
495! ------------
496!> @todo Missing subroutine description.
497!------------------------------------------------------------------------------!
498    SUBROUTINE preprocess_spectra( m, pr )
499
500       USE arrays_3d,                                                          &
501           ONLY:  d, pt, q, s, u, v, w
502
503       USE indices,                                                            &
504           ONLY:  ngp_2dh, nxl, nxr, nyn, nys, nzb, nzt
505
506       USE kinds
507
508#if defined( __parallel )
509#if defined( __mpifh )
510       INCLUDE "mpif.h"
511#else
512       USE MPI
513#endif
514#endif
515       USE pegrid,                                                             &
516           ONLY:  collective_wait, comm2d, ierr
517
518       USE statistics,                                                         &
519           ONLY:  hom
520
521
522       IMPLICIT NONE
523
524       INTEGER(iwp) :: i  !<
525       INTEGER(iwp) :: j  !<
526       INTEGER(iwp) :: k  !<
527       INTEGER(iwp) :: m  !<
528       INTEGER(iwp) :: pr !<
529
530       REAL(wp), DIMENSION(nzb:nzt+1) :: var_d_l
531
532       SELECT CASE ( TRIM( data_output_sp(m) ) )
533         
534       CASE ( 'u' )
535          pr = 1
536          d(nzb+1:nzt,nys:nyn,nxl:nxr) = u(nzb+1:nzt,nys:nyn,nxl:nxr)
537       
538       CASE ( 'v' )
539          pr = 2
540          d(nzb+1:nzt,nys:nyn,nxl:nxr) = v(nzb+1:nzt,nys:nyn,nxl:nxr)
541       
542       CASE ( 'w' )
543          pr = 3
544          d(nzb+1:nzt,nys:nyn,nxl:nxr) = w(nzb+1:nzt,nys:nyn,nxl:nxr)
545       
546       CASE ( 'pt' )
547          pr = 4
548          d(nzb+1:nzt,nys:nyn,nxl:nxr) = pt(nzb+1:nzt,nys:nyn,nxl:nxr)
549       
550       CASE ( 'q' )
551          pr = 41
552          d(nzb+1:nzt,nys:nyn,nxl:nxr) = q(nzb+1:nzt,nys:nyn,nxl:nxr)
553         
554       CASE ( 's' )
555          pr = 117
556          d(nzb+1:nzt,nys:nyn,nxl:nxr) = s(nzb+1:nzt,nys:nyn,nxl:nxr)
557       
558       CASE DEFAULT
559!
560!--       The DEFAULT case is reached either if the parameter data_output_sp(m)
561!--       contains a wrong character string or if the user has coded a special
562!--       case in the user interface. There, the subroutine user_spectra
563!--       checks which of these two conditions applies.
564          CALL user_spectra( 'preprocess', m, pr )
565         
566       END SELECT
567
568!
569!--    Subtract horizontal mean from the array, for which spectra have to be
570!--    calculated. Moreover, calculate variance of the respective quantitiy,
571!--    later used for normalizing spectra output.
572       var_d_l(:) = 0.0_wp
573       DO  i = nxl, nxr
574          DO  j = nys, nyn
575             DO  k = nzb+1, nzt
576                d(k,j,i)   = d(k,j,i) - hom(k,1,pr,0)
577                var_d_l(k) = var_d_l(k) + d(k,j,i) * d(k,j,i)
578             ENDDO
579          ENDDO
580       ENDDO
581!
582!--    Compute total variance from local variances
583       var_d(:) = 0.0_wp
584#if defined( __parallel ) 
585       IF ( collective_wait )  CALL MPI_BARRIER( comm2d, ierr )
586       CALL MPI_ALLREDUCE( var_d_l(0), var_d(0), nzt+1-nzb, MPI_REAL, MPI_SUM, &
587                           comm2d, ierr )
588#else
589       var_d(:) = var_d_l(:)
590#endif
591       var_d(:) = var_d(:) / ngp_2dh(0)
592
593    END SUBROUTINE preprocess_spectra
594
595
596!------------------------------------------------------------------------------!
597! Description:
598! ------------
599!> @todo Missing subroutine description.
600!------------------------------------------------------------------------------!
601    SUBROUTINE calc_spectra_x( ddd, pr, m )
602
603       USE control_parameters,                                                 &
604           ONLY:  fft_method
605
606       USE fft_xy,                                                             &
607           ONLY:  fft_x_1d
608
609       USE grid_variables,                                                     &
610           ONLY:  dx
611
612       USE indices,                                                            &
613           ONLY:  nx, ny
614
615       USE kinds
616
617#if defined( __parallel )
618#if defined( __mpifh )
619       INCLUDE "mpif.h"
620#else
621       USE MPI
622#endif
623#endif
624       USE pegrid,                                                             &
625           ONLY:  comm2d, ierr, myid
626
627       USE transpose_indices,                                                  &
628           ONLY:  nyn_x, nys_x, nzb_x, nzt_x
629
630
631       IMPLICIT NONE
632
633       INTEGER(iwp) ::  i         !<
634       INTEGER(iwp) ::  ishape(1) !<
635       INTEGER(iwp) ::  j         !<
636       INTEGER(iwp) ::  k         !<
637       INTEGER(iwp) ::  m         !<
638       INTEGER(iwp) ::  n         !<
639       INTEGER(iwp) ::  pr        !<
640
641       REAL(wp) ::  exponent     !<
642       REAL(wp) ::  sum_spec_dum !< wavenumber-integrated spectrum
643   
644       REAL(wp), DIMENSION(0:nx) ::  work !<
645   
646       REAL(wp), DIMENSION(0:nx/2) ::  sums_spectra_l !<
647   
648       REAL(wp), DIMENSION(0:nx/2,100) ::  sums_spectra !<
649   
650       REAL(wp), DIMENSION(0:nx,nys_x:nyn_x,nzb_x:nzt_x) ::  ddd !<
651
652!
653!--    Exponent for geometric average
654       exponent = 1.0_wp / ( ny + 1.0_wp )
655
656!
657!--    Loop over all levels defined by the user
658       n = 1
659       DO WHILE ( comp_spectra_level(n) /= 999999  .AND.  n <= 100 )
660
661          k = comp_spectra_level(n)
662
663!
664!--       Calculate FFT only if the corresponding level is situated on this PE
665          IF ( k >= nzb_x  .AND.  k <= nzt_x )  THEN
666         
667             DO  j = nys_x, nyn_x
668
669                work = ddd(0:nx,j,k)
670                CALL fft_x_1d( work, 'forward' )
671
672                ddd(0,j,k) = dx * work(0)**2
673                DO  i = 1, nx/2
674                   ddd(i,j,k) = dx * ( work(i)**2 + work(nx+1-i)**2 )
675                ENDDO
676
677             ENDDO
678
679!
680!--          Local sum and geometric average of these spectra
681!--          (WARNING: no global sum should be performed, because floating
682!--          point overflow may occur)
683             DO  i = 0, nx/2
684
685                sums_spectra_l(i) = 1.0_wp
686                DO  j = nys_x, nyn_x
687                   sums_spectra_l(i) = sums_spectra_l(i) * ddd(i,j,k)**exponent
688                ENDDO
689
690             ENDDO
691         
692          ELSE
693
694             sums_spectra_l = 1.0_wp
695
696          ENDIF
697
698!
699!--       Global sum of spectra on PE0 (from where they are written on file)
700          sums_spectra(:,n) = 0.0_wp
701#if defined( __parallel )   
702          CALL MPI_BARRIER( comm2d, ierr )  ! Necessary?
703          CALL MPI_REDUCE( sums_spectra_l(0), sums_spectra(0,n), nx/2+1,       &
704                           MPI_REAL, MPI_PROD, 0, comm2d, ierr )
705#else
706          sums_spectra(:,n) = sums_spectra_l
707#endif
708!
709!--       Normalize spectra by variance
710          sum_spec_dum = SUM( sums_spectra(1:nx/2,n) )
711
712          IF ( sum_spec_dum /= 0.0_wp )  THEN
713             sums_spectra(1:nx/2,n) = sums_spectra(1:nx/2,n) *                 &
714                                      var_d(k) / sum_spec_dum
715          ENDIF
716          n = n + 1
717
718       ENDDO
719       n = n - 1
720
721       IF ( myid == 0 )  THEN
722!
723!--       Sum of spectra for later averaging (see routine data_output_spectra)
724          DO  i = 1, nx/2
725             DO k = 1, n
726                spectrum_x(i,k,m) = spectrum_x(i,k,m) + sums_spectra(i,k)
727             ENDDO
728          ENDDO
729
730       ENDIF
731!
732!--    n_sp_x is needed by data_output_spectra_x
733       n_sp_x = n
734
735    END SUBROUTINE calc_spectra_x
736
737
738!------------------------------------------------------------------------------!
739! Description:
740! ------------
741!> @todo Missing subroutine description.
742!------------------------------------------------------------------------------!
743    SUBROUTINE calc_spectra_y( ddd, pr, m )
744
745       USE control_parameters,                                                 &
746           ONLY:  fft_method
747
748       USE fft_xy,                                                             &
749           ONLY:  fft_y_1d
750
751       USE grid_variables,                                                     &
752           ONLY:  dy
753
754       USE indices,                                                            &
755           ONLY:  nx, ny
756
757       USE kinds
758
759#if defined( __parallel )
760#if defined( __mpifh )
761       INCLUDE "mpif.h"
762#else
763       USE MPI
764#endif
765#endif
766       USE pegrid,                                                             &
767           ONLY:  comm2d, ierr, myid
768
769       USE transpose_indices,                                                  &
770           ONLY:  nxl_yd, nxr_yd, nzb_yd, nzt_yd
771
772
773       IMPLICIT NONE
774
775       INTEGER(iwp) ::  i         !<
776       INTEGER(iwp) ::  j         !<
777       INTEGER(iwp) ::  jshape(1) !<
778       INTEGER(iwp) ::  k         !<
779       INTEGER(iwp) ::  m         !<
780       INTEGER(iwp) ::  n         !<
781       INTEGER(iwp) ::  pr        !<
782
783       REAL(wp) ::  exponent !<
784       REAL(wp) ::  sum_spec_dum !< wavenumber-integrated spectrum
785   
786       REAL(wp), DIMENSION(0:ny) ::  work !<
787   
788       REAL(wp), DIMENSION(0:ny/2) ::  sums_spectra_l !<
789   
790       REAL(wp), DIMENSION(0:ny/2,100) ::  sums_spectra !<
791   
792       REAL(wp), DIMENSION(0:ny,nxl_yd:nxr_yd,nzb_yd:nzt_yd) :: ddd !<
793
794
795!
796!--    Exponent for geometric average
797       exponent = 1.0_wp / ( nx + 1.0_wp )
798
799!
800!--    Loop over all levels defined by the user
801       n = 1
802       DO WHILE ( comp_spectra_level(n) /= 999999  .AND.  n <= 100 )
803
804          k = comp_spectra_level(n)
805
806!
807!--       Calculate FFT only if the corresponding level is situated on this PE
808          IF ( k >= nzb_yd  .AND.  k <= nzt_yd )  THEN
809         
810             DO  i = nxl_yd, nxr_yd
811
812                work = ddd(0:ny,i,k)
813                CALL fft_y_1d( work, 'forward' )
814
815                ddd(0,i,k) = dy * work(0)**2
816                DO  j = 1, ny/2
817                   ddd(j,i,k) = dy * ( work(j)**2 + work(ny+1-j)**2 )
818                ENDDO
819
820             ENDDO
821
822!
823!--          Local sum and geometric average of these spectra
824!--          (WARNING: no global sum should be performed, because floating
825!--          point overflow may occur)
826             DO  j = 0, ny/2
827
828                sums_spectra_l(j) = 1.0_wp
829                DO  i = nxl_yd, nxr_yd
830                   sums_spectra_l(j) = sums_spectra_l(j) * ddd(j,i,k)**exponent
831                ENDDO
832
833             ENDDO
834         
835          ELSE
836
837             sums_spectra_l = 1.0_wp
838
839          ENDIF
840
841!
842!--       Global sum of spectra on PE0 (from where they are written on file)
843          sums_spectra(:,n) = 0.0_wp
844#if defined( __parallel )   
845          CALL MPI_BARRIER( comm2d, ierr )  ! Necessary?
846          CALL MPI_REDUCE( sums_spectra_l(0), sums_spectra(0,n), ny/2+1,       &
847                           MPI_REAL, MPI_PROD, 0, comm2d, ierr )
848#else
849          sums_spectra(:,n) = sums_spectra_l
850#endif
851!
852!--       Normalize spectra by variance
853          sum_spec_dum = SUM( sums_spectra(1:ny/2,n) )
854          IF ( sum_spec_dum /= 0.0_wp )  THEN
855             sums_spectra(1:ny/2,n) = sums_spectra(1:ny/2,n) *                 &
856                                      var_d(k) / sum_spec_dum
857          ENDIF
858          n = n + 1
859
860       ENDDO
861       n = n - 1
862
863
864       IF ( myid == 0 )  THEN
865!
866!--       Sum of spectra for later averaging (see routine data_output_spectra)
867          DO  j = 1, ny/2
868             DO k = 1, n
869                spectrum_y(j,k,m) = spectrum_y(j,k,m) + sums_spectra(j,k)
870             ENDDO
871          ENDDO
872
873       ENDIF
874
875!
876!--    n_sp_y is needed by data_output_spectra_y
877       n_sp_y = n
878
879    END SUBROUTINE calc_spectra_y
880
881 END MODULE spectra_mod
Note: See TracBrowser for help on using the repository browser.