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

Last change on this file since 2938 was 2932, checked in by maronga, 6 years ago

renamed all Fortran NAMELISTS

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