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