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

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

Revision history corrected

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