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