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