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

Last change on this file since 3839 was 3805, checked in by raasch, 5 years ago

output format adjusted, unused variable removed

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