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

Last change on this file since 3045 was 3045, checked in by Giersch, 6 years ago

Code adjusted according to coding standards, renamed namelists, error messages revised until PA0347, output CASE 108 disabled

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