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