[1833] | 1 | !> @file spectra_mod.f90 |
---|
[2000] | 2 | !------------------------------------------------------------------------------! |
---|
[2696] | 3 | ! This file is part of the PALM model system. |
---|
[1036] | 4 | ! |
---|
[2000] | 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. |
---|
[1036] | 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 | ! |
---|
[2718] | 17 | ! Copyright 1997-2018 Leibniz Universitaet Hannover |
---|
[2000] | 18 | !------------------------------------------------------------------------------! |
---|
[1036] | 19 | ! |
---|
[247] | 20 | ! Current revisions: |
---|
[1] | 21 | ! ----------------- |
---|
[2216] | 22 | ! |
---|
| 23 | ! |
---|
[1787] | 24 | ! Former revisions: |
---|
| 25 | ! ----------------- |
---|
| 26 | ! $Id: spectra_mod.f90 2932 2018-03-26 09:39:22Z suehring $ |
---|
[2932] | 27 | ! renamed spectra_par to spectra_parameters |
---|
| 28 | ! |
---|
| 29 | ! 2841 2018-02-27 15:02:57Z knoop |
---|
[2841] | 30 | ! Bugfix: wrong placement of include 'mpif.h' corrected |
---|
| 31 | ! |
---|
| 32 | ! 2718 2018-01-02 08:49:38Z maronga |
---|
[2716] | 33 | ! Corrected "Former revisions" section |
---|
| 34 | ! |
---|
| 35 | ! 2696 2017-12-14 17:12:51Z kanani |
---|
| 36 | ! Change in file header (GPL part) |
---|
[1787] | 37 | ! |
---|
[2716] | 38 | ! 2216 2017-04-28 12:54:20Z suehring |
---|
| 39 | ! |
---|
[2216] | 40 | ! 2193 2017-03-22 04:21:28Z raasch |
---|
| 41 | ! Normalization of spectra output adjusted |
---|
| 42 | ! |
---|
[2193] | 43 | ! 2192 2017-03-22 04:14:10Z raasch |
---|
| 44 | ! bugfix for index bounds of arrays spectrum_x and spectrum_y |
---|
| 45 | ! |
---|
[2001] | 46 | ! 2000 2016-08-20 18:09:15Z knoop |
---|
| 47 | ! Forced header and separation lines into 80 columns |
---|
| 48 | ! |
---|
[1961] | 49 | ! 1960 2016-07-12 16:34:24Z suehring |
---|
| 50 | ! Additional default spectra for passive scalar |
---|
| 51 | ! |
---|
[1834] | 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 | ! |
---|
[1816] | 56 | ! 1815 2016-04-06 13:49:59Z raasch |
---|
| 57 | ! bugfix: preprocessor directives included for the non-parallel case |
---|
| 58 | ! |
---|
[1809] | 59 | ! 1808 2016-04-05 19:44:00Z raasch |
---|
| 60 | ! MPI module used by default on all machines |
---|
| 61 | ! |
---|
[1787] | 62 | ! 1786 2016-03-08 05:49:27Z raasch |
---|
[1786] | 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 |
---|
[1321] | 67 | ! |
---|
[1683] | 68 | ! 1682 2015-10-07 23:56:08Z knoop |
---|
| 69 | ! Code annotations made doxygen readable |
---|
| 70 | ! |
---|
[1576] | 71 | ! 1575 2015-03-27 09:56:27Z raasch |
---|
| 72 | ! adjustments for psolver-queries |
---|
| 73 | ! |
---|
[1512] | 74 | ! 1511 2014-12-16 15:54:16Z suehring |
---|
| 75 | ! Bugfix concerning spectra normalization |
---|
| 76 | ! |
---|
[1432] | 77 | ! 1431 2014-07-15 14:47:17Z suehring |
---|
| 78 | ! Wavenumber-integrated spectra coincide with respective variance. |
---|
| 79 | ! |
---|
[1343] | 80 | ! 1342 2014-03-26 17:04:47Z kanani |
---|
| 81 | ! REAL constants defined as wp-kinds |
---|
| 82 | ! |
---|
[1325] | 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 | ! |
---|
[1321] | 86 | ! 1320 2014-03-20 08:40:49Z raasch |
---|
[1320] | 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 |
---|
[198] | 93 | ! |
---|
[1319] | 94 | ! 1318 2014-03-17 13:35:16Z raasch |
---|
| 95 | ! module interfaces removed |
---|
| 96 | ! |
---|
[1217] | 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 | ! |
---|
[1121] | 101 | ! 1120 2013-04-05 15:11:35Z raasch |
---|
| 102 | ! bugfix: calls of fft_x|y replaced by fft_x|y_1d |
---|
| 103 | ! |
---|
[1037] | 104 | ! 1036 2012-10-22 13:43:42Z raasch |
---|
| 105 | ! code put under GPL (PALM 3.9) |
---|
| 106 | ! |
---|
[1004] | 107 | ! 1003 2012-09-14 14:35:53Z raasch |
---|
| 108 | ! adjustment of array tend for cases with unequal subdomain sizes removed |
---|
| 109 | ! |
---|
[1] | 110 | ! Revision 1.1 2001/01/05 15:08:07 raasch |
---|
| 111 | ! Initial revision |
---|
| 112 | ! |
---|
| 113 | ! |
---|
| 114 | ! Description: |
---|
| 115 | ! ------------ |
---|
[1682] | 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). |
---|
[1] | 121 | !------------------------------------------------------------------------------! |
---|
[1833] | 122 | MODULE spectra_mod |
---|
[1] | 123 | |
---|
[1786] | 124 | USE kinds |
---|
[1320] | 125 | |
---|
[1786] | 126 | PRIVATE |
---|
[1320] | 127 | |
---|
[1833] | 128 | CHARACTER (LEN=2), DIMENSION(10) :: spectra_direction = 'x' |
---|
| 129 | CHARACTER (LEN=10), DIMENSION(10) :: data_output_sp = ' ' |
---|
[1320] | 130 | |
---|
[1833] | 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 |
---|
[1320] | 134 | |
---|
[1833] | 135 | INTEGER(iwp) :: comp_spectra_level(100) = 999999 |
---|
[1320] | 136 | |
---|
[1833] | 137 | LOGICAL :: calculate_spectra = .FALSE. !< internal switch that spectra are calculated |
---|
| 138 | LOGICAL :: spectra_initialized = .FALSE. !< internal switch that spectra related quantities are initialized |
---|
[1320] | 139 | |
---|
[1833] | 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 |
---|
[1] | 143 | |
---|
[1833] | 144 | REAL(wp), DIMENSION(:), ALLOCATABLE :: var_d |
---|
| 145 | |
---|
| 146 | REAL(wp), DIMENSION(:,:,:), ALLOCATABLE :: spectrum_x, spectrum_y |
---|
| 147 | |
---|
[1786] | 148 | SAVE |
---|
[1320] | 149 | |
---|
[1786] | 150 | INTERFACE calc_spectra |
---|
| 151 | MODULE PROCEDURE calc_spectra |
---|
| 152 | END INTERFACE calc_spectra |
---|
[1320] | 153 | |
---|
[1786] | 154 | INTERFACE preprocess_spectra |
---|
| 155 | MODULE PROCEDURE preprocess_spectra |
---|
| 156 | END INTERFACE preprocess_spectra |
---|
[1] | 157 | |
---|
[1786] | 158 | INTERFACE calc_spectra_x |
---|
| 159 | MODULE PROCEDURE calc_spectra_x |
---|
| 160 | END INTERFACE calc_spectra_x |
---|
[1] | 161 | |
---|
[1786] | 162 | INTERFACE calc_spectra_y |
---|
| 163 | MODULE PROCEDURE calc_spectra_y |
---|
| 164 | END INTERFACE calc_spectra_y |
---|
[1] | 165 | |
---|
[1833] | 166 | INTERFACE spectra_check_parameters |
---|
| 167 | MODULE PROCEDURE spectra_check_parameters |
---|
| 168 | END INTERFACE spectra_check_parameters |
---|
[1] | 169 | |
---|
[1833] | 170 | INTERFACE spectra_header |
---|
| 171 | MODULE PROCEDURE spectra_header |
---|
| 172 | END INTERFACE spectra_header |
---|
[1786] | 173 | |
---|
[1833] | 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 | |
---|
[1786] | 190 | CONTAINS |
---|
| 191 | |
---|
[1833] | 192 | !------------------------------------------------------------------------------! |
---|
| 193 | ! Description: |
---|
| 194 | ! ------------ |
---|
| 195 | !> Parin for &spectra_par for calculating spectra |
---|
| 196 | !------------------------------------------------------------------------------! |
---|
| 197 | SUBROUTINE spectra_parin |
---|
| 198 | |
---|
| 199 | USE control_parameters, & |
---|
[2932] | 200 | ONLY: dt_data_output, message_string |
---|
[1833] | 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 | |
---|
[2932] | 211 | NAMELIST /spectra_parameters/ & |
---|
| 212 | averaging_interval_sp, comp_spectra_level, & |
---|
| 213 | data_output_sp, dt_dosp, skip_time_dosp, & |
---|
| 214 | spectra_direction |
---|
[1833] | 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 = ' ' |
---|
[2932] | 225 | DO WHILE ( INDEX( line, '&spectra_parameters' ) == 0 ) |
---|
[1833] | 226 | READ ( 11, '(A)', END=10 ) line |
---|
| 227 | ENDDO |
---|
| 228 | BACKSPACE ( 11 ) |
---|
| 229 | |
---|
| 230 | ! |
---|
| 231 | !-- Read namelist |
---|
[2932] | 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 |
---|
[1833] | 255 | READ ( 11, spectra_par ) |
---|
| 256 | |
---|
[2932] | 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 ) |
---|
[1833] | 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. |
---|
[2932] | 270 | |
---|
| 271 | |
---|
| 272 | 12 CONTINUE |
---|
[1833] | 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 |
---|
[2192] | 293 | ALLOCATE( spectrum_x( 1:nx/2, 1:100, 1:10 ), & |
---|
| 294 | spectrum_y( 1:ny/2, 1:100, 1:10 ) ) |
---|
[1833] | 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 | |
---|
[1786] | 403 | SUBROUTINE calc_spectra |
---|
| 404 | |
---|
| 405 | USE arrays_3d, & |
---|
| 406 | ONLY: d, tend |
---|
| 407 | |
---|
| 408 | USE control_parameters, & |
---|
[1833] | 409 | ONLY: bc_lr_cyc, bc_ns_cyc, message_string, psolver |
---|
[1786] | 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 | |
---|
[1] | 431 | ! |
---|
[1786] | 432 | !-- Check if user gave any levels for spectra to be calculated |
---|
| 433 | IF ( comp_spectra_level(1) == 999999 ) RETURN |
---|
[1] | 434 | |
---|
[1786] | 435 | CALL cpu_log( log_point(30), 'calc_spectra', 'start' ) |
---|
| 436 | |
---|
[1] | 437 | ! |
---|
[1833] | 438 | !-- Initialize spectra related quantities |
---|
| 439 | CALL spectra_init |
---|
| 440 | |
---|
| 441 | ! |
---|
[1786] | 442 | !-- Initialize ffts |
---|
| 443 | CALL fft_init |
---|
[225] | 444 | |
---|
[1] | 445 | ! |
---|
[1786] | 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 |
---|
[1] | 451 | |
---|
[1786] | 452 | m = 1 |
---|
| 453 | DO WHILE ( data_output_sp(m) /= ' ' .AND. m <= 10 ) |
---|
[1] | 454 | ! |
---|
[1786] | 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 |
---|
[247] | 458 | |
---|
[1786] | 459 | ! |
---|
| 460 | !-- Calculation of spectra works for cyclic boundary conditions only |
---|
| 461 | IF ( .NOT. bc_lr_cyc ) THEN |
---|
[1] | 462 | |
---|
[1786] | 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 |
---|
[1] | 467 | |
---|
[1786] | 468 | CALL preprocess_spectra( m, pr ) |
---|
| 469 | |
---|
[1] | 470 | #if defined( __parallel ) |
---|
[1786] | 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 ) |
---|
[1] | 478 | #else |
---|
[1786] | 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 ) |
---|
[1] | 482 | #endif |
---|
| 483 | |
---|
[1786] | 484 | ENDIF |
---|
[1] | 485 | |
---|
| 486 | ! |
---|
[1786] | 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 |
---|
[1] | 490 | |
---|
| 491 | ! |
---|
[1786] | 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 |
---|
[1] | 501 | ENDIF |
---|
| 502 | |
---|
[1786] | 503 | CALL preprocess_spectra( m, pr ) |
---|
[1] | 504 | |
---|
| 505 | #if defined( __parallel ) |
---|
[1786] | 506 | CALL transpose_zyd( d, d ) |
---|
| 507 | CALL calc_spectra_y( d, pr, m ) |
---|
[1] | 508 | #else |
---|
[1786] | 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 ) |
---|
[1] | 512 | #endif |
---|
| 513 | |
---|
[1786] | 514 | ENDIF |
---|
[1] | 515 | |
---|
| 516 | ! |
---|
[1786] | 517 | !-- Increase counter for next spectrum |
---|
| 518 | m = m + 1 |
---|
[1] | 519 | |
---|
[1786] | 520 | ENDDO |
---|
[1] | 521 | |
---|
| 522 | ! |
---|
[1786] | 523 | !-- Increase counter for averaging process in routine plot_spectra |
---|
| 524 | average_count_sp = average_count_sp + 1 |
---|
[1] | 525 | |
---|
[1786] | 526 | CALL cpu_log( log_point(30), 'calc_spectra', 'stop' ) |
---|
[1] | 527 | |
---|
[1786] | 528 | END SUBROUTINE calc_spectra |
---|
[1] | 529 | |
---|
| 530 | |
---|
[1682] | 531 | !------------------------------------------------------------------------------! |
---|
| 532 | ! Description: |
---|
| 533 | ! ------------ |
---|
| 534 | !> @todo Missing subroutine description. |
---|
| 535 | !------------------------------------------------------------------------------! |
---|
[1786] | 536 | SUBROUTINE preprocess_spectra( m, pr ) |
---|
[1] | 537 | |
---|
[1786] | 538 | USE arrays_3d, & |
---|
[1960] | 539 | ONLY: d, pt, q, s, u, v, w |
---|
[1320] | 540 | |
---|
[1786] | 541 | USE indices, & |
---|
| 542 | ONLY: ngp_2dh, nxl, nxr, nyn, nys, nzb, nzt |
---|
[1320] | 543 | |
---|
[1786] | 544 | USE kinds |
---|
[1320] | 545 | |
---|
[1815] | 546 | #if defined( __parallel ) |
---|
[2841] | 547 | #if !defined( __mpifh ) |
---|
[1786] | 548 | USE MPI |
---|
| 549 | #endif |
---|
[1815] | 550 | #endif |
---|
[2841] | 551 | |
---|
[1786] | 552 | USE pegrid, & |
---|
| 553 | ONLY: collective_wait, comm2d, ierr |
---|
[1] | 554 | |
---|
[1786] | 555 | USE statistics, & |
---|
[1833] | 556 | ONLY: hom |
---|
[1320] | 557 | |
---|
| 558 | |
---|
[1786] | 559 | IMPLICIT NONE |
---|
[1320] | 560 | |
---|
[2841] | 561 | #if defined( __parallel ) |
---|
| 562 | #if defined( __mpifh ) |
---|
| 563 | INCLUDE "mpif.h" |
---|
| 564 | #endif |
---|
| 565 | #endif |
---|
| 566 | |
---|
[1786] | 567 | INTEGER(iwp) :: i !< |
---|
| 568 | INTEGER(iwp) :: j !< |
---|
| 569 | INTEGER(iwp) :: k !< |
---|
| 570 | INTEGER(iwp) :: m !< |
---|
| 571 | INTEGER(iwp) :: pr !< |
---|
[1] | 572 | |
---|
[1786] | 573 | REAL(wp), DIMENSION(nzb:nzt+1) :: var_d_l |
---|
[1] | 574 | |
---|
[1786] | 575 | SELECT CASE ( TRIM( data_output_sp(m) ) ) |
---|
[1] | 576 | |
---|
[1786] | 577 | CASE ( 'u' ) |
---|
| 578 | pr = 1 |
---|
| 579 | d(nzb+1:nzt,nys:nyn,nxl:nxr) = u(nzb+1:nzt,nys:nyn,nxl:nxr) |
---|
[1] | 580 | |
---|
[1786] | 581 | CASE ( 'v' ) |
---|
| 582 | pr = 2 |
---|
| 583 | d(nzb+1:nzt,nys:nyn,nxl:nxr) = v(nzb+1:nzt,nys:nyn,nxl:nxr) |
---|
[1] | 584 | |
---|
[1786] | 585 | CASE ( 'w' ) |
---|
| 586 | pr = 3 |
---|
| 587 | d(nzb+1:nzt,nys:nyn,nxl:nxr) = w(nzb+1:nzt,nys:nyn,nxl:nxr) |
---|
[1] | 588 | |
---|
[1786] | 589 | CASE ( 'pt' ) |
---|
| 590 | pr = 4 |
---|
| 591 | d(nzb+1:nzt,nys:nyn,nxl:nxr) = pt(nzb+1:nzt,nys:nyn,nxl:nxr) |
---|
[1] | 592 | |
---|
[1786] | 593 | CASE ( 'q' ) |
---|
| 594 | pr = 41 |
---|
| 595 | d(nzb+1:nzt,nys:nyn,nxl:nxr) = q(nzb+1:nzt,nys:nyn,nxl:nxr) |
---|
[1960] | 596 | |
---|
| 597 | CASE ( 's' ) |
---|
| 598 | pr = 117 |
---|
| 599 | d(nzb+1:nzt,nys:nyn,nxl:nxr) = s(nzb+1:nzt,nys:nyn,nxl:nxr) |
---|
[1] | 600 | |
---|
[1786] | 601 | CASE DEFAULT |
---|
[144] | 602 | ! |
---|
[1786] | 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 ) |
---|
[1] | 608 | |
---|
[1786] | 609 | END SELECT |
---|
[1] | 610 | |
---|
| 611 | ! |
---|
[1786] | 612 | !-- Subtract horizontal mean from the array, for which spectra have to be |
---|
[2215] | 613 | !-- calculated. Moreover, calculate variance of the respective quantitiy, |
---|
| 614 | !-- later used for normalizing spectra output. |
---|
[1786] | 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 |
---|
[1] | 622 | ENDDO |
---|
| 623 | ENDDO |
---|
[1431] | 624 | ! |
---|
[1786] | 625 | !-- Compute total variance from local variances |
---|
| 626 | var_d(:) = 0.0_wp |
---|
[1431] | 627 | #if defined( __parallel ) |
---|
[1786] | 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 ) |
---|
[1431] | 631 | #else |
---|
[1786] | 632 | var_d(:) = var_d_l(:) |
---|
[1431] | 633 | #endif |
---|
[1786] | 634 | var_d(:) = var_d(:) / ngp_2dh(0) |
---|
[1] | 635 | |
---|
[1786] | 636 | END SUBROUTINE preprocess_spectra |
---|
[1] | 637 | |
---|
| 638 | |
---|
[1682] | 639 | !------------------------------------------------------------------------------! |
---|
| 640 | ! Description: |
---|
| 641 | ! ------------ |
---|
| 642 | !> @todo Missing subroutine description. |
---|
| 643 | !------------------------------------------------------------------------------! |
---|
[1786] | 644 | SUBROUTINE calc_spectra_x( ddd, pr, m ) |
---|
[1] | 645 | |
---|
[1786] | 646 | USE control_parameters, & |
---|
| 647 | ONLY: fft_method |
---|
[1320] | 648 | |
---|
[1786] | 649 | USE fft_xy, & |
---|
| 650 | ONLY: fft_x_1d |
---|
[1320] | 651 | |
---|
[1786] | 652 | USE grid_variables, & |
---|
| 653 | ONLY: dx |
---|
[1320] | 654 | |
---|
[1786] | 655 | USE indices, & |
---|
| 656 | ONLY: nx, ny |
---|
[1320] | 657 | |
---|
[1786] | 658 | USE kinds |
---|
[1320] | 659 | |
---|
[1816] | 660 | #if defined( __parallel ) |
---|
[2841] | 661 | #if !defined( __mpifh ) |
---|
[1786] | 662 | USE MPI |
---|
| 663 | #endif |
---|
[1815] | 664 | #endif |
---|
[2841] | 665 | |
---|
[1786] | 666 | USE pegrid, & |
---|
| 667 | ONLY: comm2d, ierr, myid |
---|
[1320] | 668 | |
---|
[1786] | 669 | USE transpose_indices, & |
---|
| 670 | ONLY: nyn_x, nys_x, nzb_x, nzt_x |
---|
[1320] | 671 | |
---|
| 672 | |
---|
[1786] | 673 | IMPLICIT NONE |
---|
[1] | 674 | |
---|
[2841] | 675 | #if defined( __parallel ) |
---|
| 676 | #if defined( __mpifh ) |
---|
| 677 | INCLUDE "mpif.h" |
---|
| 678 | #endif |
---|
| 679 | #endif |
---|
| 680 | |
---|
[1786] | 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 !< |
---|
[1320] | 688 | |
---|
[1786] | 689 | REAL(wp) :: exponent !< |
---|
| 690 | REAL(wp) :: sum_spec_dum !< wavenumber-integrated spectrum |
---|
[1320] | 691 | |
---|
[1786] | 692 | REAL(wp), DIMENSION(0:nx) :: work !< |
---|
[1320] | 693 | |
---|
[1786] | 694 | REAL(wp), DIMENSION(0:nx/2) :: sums_spectra_l !< |
---|
[1320] | 695 | |
---|
[1786] | 696 | REAL(wp), DIMENSION(0:nx/2,100) :: sums_spectra !< |
---|
[1320] | 697 | |
---|
[1786] | 698 | REAL(wp), DIMENSION(0:nx,nys_x:nyn_x,nzb_x:nzt_x) :: ddd !< |
---|
[1] | 699 | |
---|
| 700 | ! |
---|
[1786] | 701 | !-- Exponent for geometric average |
---|
| 702 | exponent = 1.0_wp / ( ny + 1.0_wp ) |
---|
[1] | 703 | |
---|
| 704 | ! |
---|
[1786] | 705 | !-- Loop over all levels defined by the user |
---|
| 706 | n = 1 |
---|
| 707 | DO WHILE ( comp_spectra_level(n) /= 999999 .AND. n <= 100 ) |
---|
[1] | 708 | |
---|
[1786] | 709 | k = comp_spectra_level(n) |
---|
[1] | 710 | |
---|
| 711 | ! |
---|
[1786] | 712 | !-- Calculate FFT only if the corresponding level is situated on this PE |
---|
| 713 | IF ( k >= nzb_x .AND. k <= nzt_x ) THEN |
---|
[1] | 714 | |
---|
[1786] | 715 | DO j = nys_x, nyn_x |
---|
[1] | 716 | |
---|
[1786] | 717 | work = ddd(0:nx,j,k) |
---|
| 718 | CALL fft_x_1d( work, 'forward' ) |
---|
[1] | 719 | |
---|
[1786] | 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 | |
---|
[1] | 725 | ENDDO |
---|
| 726 | |
---|
| 727 | ! |
---|
[1786] | 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 |
---|
[1] | 732 | |
---|
[1786] | 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 | |
---|
[1] | 738 | ENDDO |
---|
| 739 | |
---|
[1786] | 740 | ELSE |
---|
[1] | 741 | |
---|
[1786] | 742 | sums_spectra_l = 1.0_wp |
---|
[1] | 743 | |
---|
[1786] | 744 | ENDIF |
---|
[1] | 745 | |
---|
| 746 | ! |
---|
[1786] | 747 | !-- Global sum of spectra on PE0 (from where they are written on file) |
---|
| 748 | sums_spectra(:,n) = 0.0_wp |
---|
[1] | 749 | #if defined( __parallel ) |
---|
[1786] | 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 ) |
---|
[1] | 753 | #else |
---|
[1786] | 754 | sums_spectra(:,n) = sums_spectra_l |
---|
[1] | 755 | #endif |
---|
[1431] | 756 | ! |
---|
[1786] | 757 | !-- Normalize spectra by variance |
---|
[2215] | 758 | sum_spec_dum = SUM( sums_spectra(1:nx/2,n) ) |
---|
| 759 | |
---|
[1786] | 760 | IF ( sum_spec_dum /= 0.0_wp ) THEN |
---|
[2215] | 761 | sums_spectra(1:nx/2,n) = sums_spectra(1:nx/2,n) * & |
---|
| 762 | var_d(k) / sum_spec_dum |
---|
[1786] | 763 | ENDIF |
---|
| 764 | n = n + 1 |
---|
[1] | 765 | |
---|
[1786] | 766 | ENDDO |
---|
| 767 | n = n - 1 |
---|
[1] | 768 | |
---|
[1786] | 769 | IF ( myid == 0 ) THEN |
---|
[1] | 770 | ! |
---|
[1786] | 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 |
---|
[1] | 776 | ENDDO |
---|
| 777 | |
---|
[1786] | 778 | ENDIF |
---|
[1] | 779 | ! |
---|
[1786] | 780 | !-- n_sp_x is needed by data_output_spectra_x |
---|
| 781 | n_sp_x = n |
---|
[1] | 782 | |
---|
[1786] | 783 | END SUBROUTINE calc_spectra_x |
---|
[1] | 784 | |
---|
| 785 | |
---|
[1682] | 786 | !------------------------------------------------------------------------------! |
---|
| 787 | ! Description: |
---|
| 788 | ! ------------ |
---|
| 789 | !> @todo Missing subroutine description. |
---|
| 790 | !------------------------------------------------------------------------------! |
---|
[1786] | 791 | SUBROUTINE calc_spectra_y( ddd, pr, m ) |
---|
[1] | 792 | |
---|
[1786] | 793 | USE control_parameters, & |
---|
| 794 | ONLY: fft_method |
---|
[1320] | 795 | |
---|
[1786] | 796 | USE fft_xy, & |
---|
| 797 | ONLY: fft_y_1d |
---|
[1320] | 798 | |
---|
[1786] | 799 | USE grid_variables, & |
---|
| 800 | ONLY: dy |
---|
[1320] | 801 | |
---|
[1786] | 802 | USE indices, & |
---|
| 803 | ONLY: nx, ny |
---|
[1320] | 804 | |
---|
[1786] | 805 | USE kinds |
---|
[1320] | 806 | |
---|
[1815] | 807 | #if defined( __parallel ) |
---|
[2841] | 808 | #if !defined( __mpifh ) |
---|
[1786] | 809 | USE MPI |
---|
| 810 | #endif |
---|
[1815] | 811 | #endif |
---|
[2841] | 812 | |
---|
[1786] | 813 | USE pegrid, & |
---|
| 814 | ONLY: comm2d, ierr, myid |
---|
[1320] | 815 | |
---|
[1786] | 816 | USE transpose_indices, & |
---|
| 817 | ONLY: nxl_yd, nxr_yd, nzb_yd, nzt_yd |
---|
[1320] | 818 | |
---|
| 819 | |
---|
[1786] | 820 | IMPLICIT NONE |
---|
[1] | 821 | |
---|
[2841] | 822 | #if defined( __parallel ) |
---|
| 823 | #if defined( __mpifh ) |
---|
| 824 | INCLUDE "mpif.h" |
---|
| 825 | #endif |
---|
| 826 | #endif |
---|
| 827 | |
---|
[1786] | 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 !< |
---|
[1320] | 835 | |
---|
[1786] | 836 | REAL(wp) :: exponent !< |
---|
| 837 | REAL(wp) :: sum_spec_dum !< wavenumber-integrated spectrum |
---|
[1320] | 838 | |
---|
[1786] | 839 | REAL(wp), DIMENSION(0:ny) :: work !< |
---|
[1320] | 840 | |
---|
[1786] | 841 | REAL(wp), DIMENSION(0:ny/2) :: sums_spectra_l !< |
---|
[1320] | 842 | |
---|
[1786] | 843 | REAL(wp), DIMENSION(0:ny/2,100) :: sums_spectra !< |
---|
[1320] | 844 | |
---|
[1786] | 845 | REAL(wp), DIMENSION(0:ny,nxl_yd:nxr_yd,nzb_yd:nzt_yd) :: ddd !< |
---|
[1] | 846 | |
---|
| 847 | |
---|
| 848 | ! |
---|
[1786] | 849 | !-- Exponent for geometric average |
---|
| 850 | exponent = 1.0_wp / ( nx + 1.0_wp ) |
---|
[1] | 851 | |
---|
| 852 | ! |
---|
[1786] | 853 | !-- Loop over all levels defined by the user |
---|
| 854 | n = 1 |
---|
| 855 | DO WHILE ( comp_spectra_level(n) /= 999999 .AND. n <= 100 ) |
---|
[1] | 856 | |
---|
[1786] | 857 | k = comp_spectra_level(n) |
---|
[1] | 858 | |
---|
| 859 | ! |
---|
[1786] | 860 | !-- Calculate FFT only if the corresponding level is situated on this PE |
---|
| 861 | IF ( k >= nzb_yd .AND. k <= nzt_yd ) THEN |
---|
[1] | 862 | |
---|
[1786] | 863 | DO i = nxl_yd, nxr_yd |
---|
[1] | 864 | |
---|
[1786] | 865 | work = ddd(0:ny,i,k) |
---|
| 866 | CALL fft_y_1d( work, 'forward' ) |
---|
[1] | 867 | |
---|
[1786] | 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 | |
---|
[1] | 873 | ENDDO |
---|
| 874 | |
---|
| 875 | ! |
---|
[1786] | 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 |
---|
[1] | 880 | |
---|
[1786] | 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 | |
---|
[1] | 886 | ENDDO |
---|
| 887 | |
---|
[1786] | 888 | ELSE |
---|
[1] | 889 | |
---|
[1786] | 890 | sums_spectra_l = 1.0_wp |
---|
[1] | 891 | |
---|
[1786] | 892 | ENDIF |
---|
[1] | 893 | |
---|
| 894 | ! |
---|
[1786] | 895 | !-- Global sum of spectra on PE0 (from where they are written on file) |
---|
| 896 | sums_spectra(:,n) = 0.0_wp |
---|
[1] | 897 | #if defined( __parallel ) |
---|
[1786] | 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 ) |
---|
[1] | 901 | #else |
---|
[1786] | 902 | sums_spectra(:,n) = sums_spectra_l |
---|
[1] | 903 | #endif |
---|
[1431] | 904 | ! |
---|
[1786] | 905 | !-- Normalize spectra by variance |
---|
[2215] | 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 |
---|
[1786] | 910 | ENDIF |
---|
| 911 | n = n + 1 |
---|
[1] | 912 | |
---|
[1786] | 913 | ENDDO |
---|
| 914 | n = n - 1 |
---|
[1] | 915 | |
---|
| 916 | |
---|
[1786] | 917 | IF ( myid == 0 ) THEN |
---|
[1] | 918 | ! |
---|
[1786] | 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 |
---|
[1] | 924 | ENDDO |
---|
| 925 | |
---|
[1786] | 926 | ENDIF |
---|
[1] | 927 | |
---|
| 928 | ! |
---|
[1786] | 929 | !-- n_sp_y is needed by data_output_spectra_y |
---|
| 930 | n_sp_y = n |
---|
[1] | 931 | |
---|
[1786] | 932 | END SUBROUTINE calc_spectra_y |
---|
| 933 | |
---|
[1833] | 934 | END MODULE spectra_mod |
---|