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

Last change on this file since 1833 was 1833, checked in by raasch, 8 years ago

spectrum renamed spactra_par and further modularized, POINTER-attributes added in coupler-routines to avoid gfortran error messages

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