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