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