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