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