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