[1] | 1 | SUBROUTINE calc_spectra |
---|
| 2 | |
---|
[1036] | 3 | !--------------------------------------------------------------------------------! |
---|
| 4 | ! This file is part of PALM. |
---|
| 5 | ! |
---|
| 6 | ! PALM is free software: you can redistribute it and/or modify it under the terms |
---|
| 7 | ! of the GNU General Public License as published by the Free Software Foundation, |
---|
| 8 | ! either version 3 of the License, or (at your option) any later version. |
---|
| 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 | ! |
---|
[1310] | 17 | ! Copyright 1997-2014 Leibniz Universitaet Hannover |
---|
[1036] | 18 | !--------------------------------------------------------------------------------! |
---|
| 19 | ! |
---|
[247] | 20 | ! Current revisions: |
---|
[1] | 21 | ! ----------------- |
---|
[1343] | 22 | ! |
---|
[1576] | 23 | ! |
---|
[1321] | 24 | ! Former revisions: |
---|
| 25 | ! ----------------- |
---|
| 26 | ! $Id: calc_spectra.f90 1576 2015-03-27 10:23:30Z maronga $ |
---|
| 27 | ! |
---|
[1576] | 28 | ! 1575 2015-03-27 09:56:27Z raasch |
---|
| 29 | ! adjustments for psolver-queries |
---|
| 30 | ! |
---|
[1512] | 31 | ! 1511 2014-12-16 15:54:16Z suehring |
---|
| 32 | ! Bugfix concerning spectra normalization |
---|
| 33 | ! |
---|
[1432] | 34 | ! 1431 2014-07-15 14:47:17Z suehring |
---|
| 35 | ! Wavenumber-integrated spectra coincide with respective variance. |
---|
| 36 | ! |
---|
[1343] | 37 | ! 1342 2014-03-26 17:04:47Z kanani |
---|
| 38 | ! REAL constants defined as wp-kinds |
---|
| 39 | ! |
---|
[1325] | 40 | ! 1324 2014-03-21 09:13:16Z suehring |
---|
| 41 | ! Bugfix: nzb_x, nzb_yd, nyn_x, nyn_x, nzt_x, nzt_yd belong to transpose_indices |
---|
| 42 | ! |
---|
[1321] | 43 | ! 1320 2014-03-20 08:40:49Z raasch |
---|
[1320] | 44 | ! ONLY-attribute added to USE-statements, |
---|
| 45 | ! kind-parameters added to all INTEGER and REAL declaration statements, |
---|
| 46 | ! kinds are defined in new module kinds, |
---|
| 47 | ! revision history before 2012 removed, |
---|
| 48 | ! comment fields (!:) to be used for variable explanations added to |
---|
| 49 | ! all variable declaration statements |
---|
[198] | 50 | ! |
---|
[1319] | 51 | ! 1318 2014-03-17 13:35:16Z raasch |
---|
| 52 | ! module interfaces removed |
---|
| 53 | ! |
---|
[1217] | 54 | ! 1216 2013-08-26 09:31:42Z raasch |
---|
| 55 | ! resorting of array moved to separate routine resort_for_zx, |
---|
| 56 | ! one argument removed from the transpose_..d routines |
---|
| 57 | ! |
---|
[1121] | 58 | ! 1120 2013-04-05 15:11:35Z raasch |
---|
| 59 | ! bugfix: calls of fft_x|y replaced by fft_x|y_1d |
---|
| 60 | ! |
---|
[1037] | 61 | ! 1036 2012-10-22 13:43:42Z raasch |
---|
| 62 | ! code put under GPL (PALM 3.9) |
---|
| 63 | ! |
---|
[1004] | 64 | ! 1003 2012-09-14 14:35:53Z raasch |
---|
| 65 | ! adjustment of array tend for cases with unequal subdomain sizes removed |
---|
| 66 | ! |
---|
[1] | 67 | ! Revision 1.1 2001/01/05 15:08:07 raasch |
---|
| 68 | ! Initial revision |
---|
| 69 | ! |
---|
| 70 | ! |
---|
| 71 | ! Description: |
---|
| 72 | ! ------------ |
---|
| 73 | ! Calculate horizontal spectra along x and y. |
---|
| 74 | ! ATTENTION: 1d-decomposition along y still needs improvement, because in that |
---|
| 75 | ! case the gridpoint number along z still depends on the PE number |
---|
| 76 | ! because transpose_xz has to be used (and possibly also |
---|
| 77 | ! transpose_zyd needs modification). |
---|
| 78 | !------------------------------------------------------------------------------! |
---|
| 79 | |
---|
| 80 | #if defined( __spectra ) |
---|
[1320] | 81 | USE arrays_3d, & |
---|
| 82 | ONLY: d, tend |
---|
| 83 | |
---|
| 84 | USE control_parameters, & |
---|
| 85 | ONLY: average_count_sp, bc_lr_cyc, bc_ns_cyc, message_string, psolver |
---|
| 86 | |
---|
| 87 | USE cpulog, & |
---|
| 88 | ONLY: cpu_log, log_point |
---|
| 89 | |
---|
| 90 | USE fft_xy, & |
---|
| 91 | ONLY: fft_init |
---|
| 92 | |
---|
| 93 | USE indices, & |
---|
[1324] | 94 | ONLY: nxl, nxr, nyn, nys, nzb, nzt |
---|
[1320] | 95 | |
---|
| 96 | USE kinds |
---|
| 97 | |
---|
[1] | 98 | USE pegrid |
---|
| 99 | |
---|
[1320] | 100 | USE spectrum, & |
---|
| 101 | ONLY: data_output_sp, spectra_direction |
---|
| 102 | |
---|
| 103 | |
---|
[1] | 104 | IMPLICIT NONE |
---|
| 105 | |
---|
[1320] | 106 | INTEGER(iwp) :: m !: |
---|
| 107 | INTEGER(iwp) :: pr !: |
---|
[1] | 108 | |
---|
| 109 | |
---|
| 110 | CALL cpu_log( log_point(30), 'calc_spectra', 'start' ) |
---|
| 111 | |
---|
| 112 | ! |
---|
| 113 | !-- Initialize ffts |
---|
| 114 | CALL fft_init |
---|
| 115 | |
---|
| 116 | ! |
---|
[225] | 117 | !-- Reallocate array d in required size |
---|
[1575] | 118 | IF ( psolver(1:9) == 'multigrid' ) THEN |
---|
[225] | 119 | DEALLOCATE( d ) |
---|
[1003] | 120 | ALLOCATE( d(nzb+1:nzt,nys:nyn,nxl:nxr) ) |
---|
[225] | 121 | ENDIF |
---|
| 122 | |
---|
[1] | 123 | m = 1 |
---|
| 124 | DO WHILE ( data_output_sp(m) /= ' ' .AND. m <= 10 ) |
---|
| 125 | ! |
---|
| 126 | !-- Transposition from z --> x ( y --> x in case of a 1d-decomposition |
---|
| 127 | !-- along x) |
---|
| 128 | IF ( INDEX( spectra_direction(m), 'x' ) /= 0 ) THEN |
---|
| 129 | |
---|
| 130 | ! |
---|
| 131 | !-- Calculation of spectra works for cyclic boundary conditions only |
---|
[707] | 132 | IF ( .NOT. bc_lr_cyc ) THEN |
---|
[247] | 133 | |
---|
[274] | 134 | message_string = 'non-cyclic lateral boundaries along x do not'// & |
---|
[247] | 135 | '& allow calculation of spectra along x' |
---|
| 136 | CALL message( 'calc_spectra', 'PA0160', 1, 2, 0, 6, 0 ) |
---|
[1] | 137 | ENDIF |
---|
| 138 | |
---|
| 139 | CALL preprocess_spectra( m, pr ) |
---|
| 140 | |
---|
| 141 | #if defined( __parallel ) |
---|
| 142 | IF ( pdims(2) /= 1 ) THEN |
---|
[1216] | 143 | CALL resort_for_zx( d, tend ) |
---|
| 144 | CALL transpose_zx( tend, d ) |
---|
[1] | 145 | ELSE |
---|
[1216] | 146 | CALL transpose_yxd( d, d ) |
---|
[1] | 147 | ENDIF |
---|
| 148 | CALL calc_spectra_x( d, pr, m ) |
---|
| 149 | #else |
---|
[274] | 150 | message_string = 'sorry, calculation of spectra in non parallel ' // & |
---|
| 151 | 'mode& is still not realized' |
---|
[247] | 152 | CALL message( 'calc_spectra', 'PA0161', 1, 2, 0, 6, 0 ) |
---|
[1] | 153 | #endif |
---|
| 154 | |
---|
| 155 | ENDIF |
---|
| 156 | |
---|
| 157 | ! |
---|
| 158 | !-- Transposition from z --> y (d is rearranged only in case of a |
---|
| 159 | !-- 1d-decomposition along x) |
---|
| 160 | IF ( INDEX( spectra_direction(m), 'y' ) /= 0 ) THEN |
---|
| 161 | |
---|
| 162 | ! |
---|
| 163 | !-- Calculation of spectra works for cyclic boundary conditions only |
---|
[707] | 164 | IF ( .NOT. bc_ns_cyc ) THEN |
---|
[1] | 165 | IF ( myid == 0 ) THEN |
---|
[274] | 166 | message_string = 'non-cyclic lateral boundaries along y do' // & |
---|
| 167 | ' not & allow calculation of spectra along y' |
---|
[247] | 168 | CALL message( 'calc_spectra', 'PA0162', 1, 2, 0, 6, 0 ) |
---|
[1] | 169 | ENDIF |
---|
| 170 | CALL local_stop |
---|
| 171 | ENDIF |
---|
| 172 | |
---|
| 173 | CALL preprocess_spectra( m, pr ) |
---|
| 174 | |
---|
| 175 | #if defined( __parallel ) |
---|
[1216] | 176 | CALL transpose_zyd( d, d ) |
---|
[1] | 177 | CALL calc_spectra_y( d, pr, m ) |
---|
| 178 | #else |
---|
[1320] | 179 | message_string = 'sorry, calculation of spectra in non parallel' // & |
---|
[274] | 180 | 'mode& is still not realized' |
---|
[247] | 181 | CALL message( 'calc_spectra', 'PA0161', 1, 2, 0, 6, 0 ) |
---|
[1] | 182 | #endif |
---|
| 183 | |
---|
| 184 | ENDIF |
---|
| 185 | |
---|
| 186 | ! |
---|
| 187 | !-- Increase counter for next spectrum |
---|
| 188 | m = m + 1 |
---|
| 189 | |
---|
| 190 | ENDDO |
---|
| 191 | |
---|
| 192 | ! |
---|
| 193 | !-- Increase counter for averaging process in routine plot_spectra |
---|
| 194 | average_count_sp = average_count_sp + 1 |
---|
| 195 | |
---|
| 196 | CALL cpu_log( log_point(30), 'calc_spectra', 'stop' ) |
---|
| 197 | |
---|
| 198 | #endif |
---|
| 199 | END SUBROUTINE calc_spectra |
---|
| 200 | |
---|
| 201 | |
---|
| 202 | #if defined( __spectra ) |
---|
| 203 | SUBROUTINE preprocess_spectra( m, pr ) |
---|
| 204 | |
---|
[1320] | 205 | USE arrays_3d, & |
---|
| 206 | ONLY: d, pt, q, u, v, w |
---|
| 207 | |
---|
| 208 | USE indices, & |
---|
[1431] | 209 | ONLY: ngp_2dh, nxl, nxr, nyn, nys, nzb, nzt |
---|
[1320] | 210 | |
---|
| 211 | USE kinds |
---|
| 212 | |
---|
[1] | 213 | USE pegrid |
---|
| 214 | |
---|
[1320] | 215 | USE spectrum, & |
---|
| 216 | ONLY: data_output_sp |
---|
| 217 | |
---|
| 218 | USE statistics, & |
---|
[1431] | 219 | ONLY: hom, var_d |
---|
[1320] | 220 | |
---|
| 221 | |
---|
[1] | 222 | IMPLICIT NONE |
---|
| 223 | |
---|
[1320] | 224 | INTEGER(iwp) :: i !: |
---|
| 225 | INTEGER(iwp) :: j !: |
---|
| 226 | INTEGER(iwp) :: k !: |
---|
| 227 | INTEGER(iwp) :: m !: |
---|
| 228 | INTEGER(iwp) :: pr !: |
---|
[1] | 229 | |
---|
[1431] | 230 | REAL(wp), DIMENSION(nzb:nzt+1) :: var_d_l |
---|
| 231 | |
---|
[1] | 232 | SELECT CASE ( TRIM( data_output_sp(m) ) ) |
---|
| 233 | |
---|
| 234 | CASE ( 'u' ) |
---|
| 235 | pr = 1 |
---|
| 236 | d(nzb+1:nzt,nys:nyn,nxl:nxr) = u(nzb+1:nzt,nys:nyn,nxl:nxr) |
---|
| 237 | |
---|
| 238 | CASE ( 'v' ) |
---|
| 239 | pr = 2 |
---|
| 240 | d(nzb+1:nzt,nys:nyn,nxl:nxr) = v(nzb+1:nzt,nys:nyn,nxl:nxr) |
---|
| 241 | |
---|
| 242 | CASE ( 'w' ) |
---|
| 243 | pr = 3 |
---|
| 244 | d(nzb+1:nzt,nys:nyn,nxl:nxr) = w(nzb+1:nzt,nys:nyn,nxl:nxr) |
---|
| 245 | |
---|
| 246 | CASE ( 'pt' ) |
---|
| 247 | pr = 4 |
---|
| 248 | d(nzb+1:nzt,nys:nyn,nxl:nxr) = pt(nzb+1:nzt,nys:nyn,nxl:nxr) |
---|
| 249 | |
---|
| 250 | CASE ( 'q' ) |
---|
| 251 | pr = 41 |
---|
| 252 | d(nzb+1:nzt,nys:nyn,nxl:nxr) = q(nzb+1:nzt,nys:nyn,nxl:nxr) |
---|
| 253 | |
---|
| 254 | CASE DEFAULT |
---|
[144] | 255 | ! |
---|
| 256 | !-- The DEFAULT case is reached either if the parameter data_output_sp(m) |
---|
| 257 | !-- contains a wrong character string or if the user has coded a special |
---|
| 258 | !-- case in the user interface. There, the subroutine user_spectra |
---|
| 259 | !-- checks which of these two conditions applies. |
---|
| 260 | CALL user_spectra( 'preprocess', m, pr ) |
---|
[1] | 261 | |
---|
| 262 | END SELECT |
---|
| 263 | |
---|
| 264 | ! |
---|
| 265 | !-- Subtract horizontal mean from the array, for which spectra have to be |
---|
| 266 | !-- calculated |
---|
[1431] | 267 | var_d_l(:) = 0.0_wp |
---|
[1] | 268 | DO i = nxl, nxr |
---|
| 269 | DO j = nys, nyn |
---|
| 270 | DO k = nzb+1, nzt |
---|
[1431] | 271 | d(k,j,i) = d(k,j,i) - hom(k,1,pr,0) |
---|
| 272 | var_d_l(k) = var_d_l(k) + d(k,j,i) * d(k,j,i) |
---|
[1] | 273 | ENDDO |
---|
| 274 | ENDDO |
---|
| 275 | ENDDO |
---|
[1431] | 276 | ! |
---|
| 277 | !-- Compute total variance from local variances |
---|
| 278 | var_d(:) = 0.0_wp |
---|
| 279 | #if defined( __parallel ) |
---|
| 280 | IF ( collective_wait ) CALL MPI_BARRIER( comm2d, ierr ) |
---|
| 281 | CALL MPI_ALLREDUCE( var_d_l(0), var_d(0), nzt+1-nzb, MPI_REAL, & |
---|
| 282 | MPI_SUM, comm2d, ierr ) |
---|
| 283 | #else |
---|
| 284 | var_d(:) = var_d_l(:) |
---|
| 285 | #endif |
---|
| 286 | var_d(:) = var_d(:) / ngp_2dh(0) |
---|
[1] | 287 | |
---|
| 288 | END SUBROUTINE preprocess_spectra |
---|
| 289 | |
---|
| 290 | |
---|
| 291 | SUBROUTINE calc_spectra_x( ddd, pr, m ) |
---|
| 292 | |
---|
[1320] | 293 | USE arrays_3d, & |
---|
| 294 | ONLY: |
---|
| 295 | |
---|
| 296 | USE control_parameters, & |
---|
| 297 | ONLY: fft_method |
---|
| 298 | |
---|
| 299 | USE fft_xy, & |
---|
| 300 | ONLY: fft_x_1d |
---|
| 301 | |
---|
| 302 | USE grid_variables, & |
---|
| 303 | ONLY: dx |
---|
| 304 | |
---|
| 305 | USE indices, & |
---|
[1324] | 306 | ONLY: nx, ny |
---|
[1320] | 307 | |
---|
| 308 | USE kinds |
---|
| 309 | |
---|
[1] | 310 | USE pegrid |
---|
[1320] | 311 | |
---|
| 312 | USE spectrum, & |
---|
| 313 | ONLY: comp_spectra_level, n_sp_x |
---|
| 314 | |
---|
| 315 | USE statistics, & |
---|
[1431] | 316 | ONLY: spectrum_x, var_d |
---|
[1320] | 317 | |
---|
[1324] | 318 | USE transpose_indices, & |
---|
| 319 | ONLY: nyn_x, nys_x, nzb_x, nzt_x |
---|
[1] | 320 | |
---|
[1320] | 321 | |
---|
[1] | 322 | IMPLICIT NONE |
---|
| 323 | |
---|
[1320] | 324 | INTEGER(iwp) :: i !: |
---|
| 325 | INTEGER(iwp) :: ishape(1) !: |
---|
| 326 | INTEGER(iwp) :: j !: |
---|
| 327 | INTEGER(iwp) :: k !: |
---|
| 328 | INTEGER(iwp) :: m !: |
---|
| 329 | INTEGER(iwp) :: n !: |
---|
| 330 | INTEGER(iwp) :: pr !: |
---|
[1] | 331 | |
---|
[1431] | 332 | REAL(wp) :: exponent !: |
---|
| 333 | REAL(wp) :: sum_spec_dum !: wavenumber-integrated spectrum |
---|
[1320] | 334 | |
---|
| 335 | REAL(wp), DIMENSION(0:nx) :: work !: |
---|
| 336 | |
---|
| 337 | REAL(wp), DIMENSION(0:nx/2) :: sums_spectra_l !: |
---|
| 338 | |
---|
| 339 | REAL(wp), DIMENSION(0:nx/2,100) :: sums_spectra !: |
---|
| 340 | |
---|
| 341 | REAL(wp), DIMENSION(0:nx,nys_x:nyn_x,nzb_x:nzt_x) :: ddd !: |
---|
[1] | 342 | |
---|
| 343 | ! |
---|
| 344 | !-- Exponent for geometric average |
---|
[1342] | 345 | exponent = 1.0_wp / ( ny + 1.0_wp ) |
---|
[1] | 346 | |
---|
| 347 | ! |
---|
| 348 | !-- Loop over all levels defined by the user |
---|
| 349 | n = 1 |
---|
[189] | 350 | DO WHILE ( comp_spectra_level(n) /= 999999 .AND. n <= 100 ) |
---|
[1] | 351 | |
---|
| 352 | k = comp_spectra_level(n) |
---|
| 353 | |
---|
| 354 | ! |
---|
| 355 | !-- Calculate FFT only if the corresponding level is situated on this PE |
---|
| 356 | IF ( k >= nzb_x .AND. k <= nzt_x ) THEN |
---|
| 357 | |
---|
| 358 | DO j = nys_x, nyn_x |
---|
| 359 | |
---|
| 360 | work = ddd(0:nx,j,k) |
---|
[1120] | 361 | CALL fft_x_1d( work, 'forward' ) |
---|
[1] | 362 | |
---|
| 363 | ddd(0,j,k) = dx * work(0)**2 |
---|
| 364 | DO i = 1, nx/2 |
---|
| 365 | ddd(i,j,k) = dx * ( work(i)**2 + work(nx+1-i)**2 ) |
---|
| 366 | ENDDO |
---|
| 367 | |
---|
| 368 | ENDDO |
---|
| 369 | |
---|
| 370 | ! |
---|
| 371 | !-- Local sum and geometric average of these spectra |
---|
| 372 | !-- (WARNING: no global sum should be performed, because floating |
---|
| 373 | !-- point overflow may occur) |
---|
| 374 | DO i = 0, nx/2 |
---|
| 375 | |
---|
[1342] | 376 | sums_spectra_l(i) = 1.0_wp |
---|
[1] | 377 | DO j = nys_x, nyn_x |
---|
| 378 | sums_spectra_l(i) = sums_spectra_l(i) * ddd(i,j,k)**exponent |
---|
| 379 | ENDDO |
---|
| 380 | |
---|
| 381 | ENDDO |
---|
| 382 | |
---|
| 383 | ELSE |
---|
| 384 | |
---|
[1342] | 385 | sums_spectra_l = 1.0_wp |
---|
[1] | 386 | |
---|
| 387 | ENDIF |
---|
| 388 | |
---|
| 389 | ! |
---|
| 390 | !-- Global sum of spectra on PE0 (from where they are written on file) |
---|
[1342] | 391 | sums_spectra(:,n) = 0.0_wp |
---|
[1] | 392 | #if defined( __parallel ) |
---|
| 393 | CALL MPI_BARRIER( comm2d, ierr ) ! Necessary? |
---|
[1320] | 394 | CALL MPI_REDUCE( sums_spectra_l(0), sums_spectra(0,n), nx/2+1, & |
---|
[1] | 395 | MPI_REAL, MPI_PROD, 0, comm2d, ierr ) |
---|
| 396 | #else |
---|
| 397 | sums_spectra(:,n) = sums_spectra_l |
---|
| 398 | #endif |
---|
[1431] | 399 | ! |
---|
| 400 | !-- Normalize spectra by variance |
---|
| 401 | sum_spec_dum = SUM( sums_spectra(:,n) ) |
---|
| 402 | IF ( sum_spec_dum /= 0.0_wp ) THEN |
---|
| 403 | sums_spectra(:,n) = sums_spectra(:,n) * var_d(k) / sum_spec_dum |
---|
| 404 | ENDIF |
---|
[1] | 405 | n = n + 1 |
---|
| 406 | |
---|
| 407 | ENDDO |
---|
| 408 | n = n - 1 |
---|
| 409 | |
---|
| 410 | IF ( myid == 0 ) THEN |
---|
| 411 | ! |
---|
[146] | 412 | !-- Sum of spectra for later averaging (see routine data_output_spectra) |
---|
[1] | 413 | DO i = 1, nx/2 |
---|
| 414 | DO k = 1, n |
---|
[1511] | 415 | spectrum_x(i,k,m) = spectrum_x(i,k,m) + sums_spectra(i,k) |
---|
[1] | 416 | ENDDO |
---|
| 417 | ENDDO |
---|
| 418 | |
---|
| 419 | ENDIF |
---|
| 420 | ! |
---|
[146] | 421 | !-- n_sp_x is needed by data_output_spectra_x |
---|
[1] | 422 | n_sp_x = n |
---|
| 423 | |
---|
| 424 | END SUBROUTINE calc_spectra_x |
---|
| 425 | |
---|
| 426 | |
---|
| 427 | SUBROUTINE calc_spectra_y( ddd, pr, m ) |
---|
| 428 | |
---|
[1320] | 429 | USE arrays_3d, & |
---|
| 430 | ONLY: |
---|
| 431 | |
---|
| 432 | USE control_parameters, & |
---|
| 433 | ONLY: fft_method |
---|
| 434 | |
---|
| 435 | USE fft_xy, & |
---|
| 436 | ONLY: fft_y_1d |
---|
| 437 | |
---|
| 438 | USE grid_variables, & |
---|
| 439 | ONLY: dy |
---|
| 440 | |
---|
| 441 | USE indices, & |
---|
[1324] | 442 | ONLY: nx, ny |
---|
[1320] | 443 | |
---|
| 444 | USE kinds |
---|
| 445 | |
---|
[1] | 446 | USE pegrid |
---|
[1320] | 447 | |
---|
| 448 | USE spectrum, & |
---|
| 449 | ONLY: comp_spectra_level, n_sp_y |
---|
| 450 | |
---|
| 451 | USE statistics, & |
---|
[1431] | 452 | ONLY: spectrum_y, var_d |
---|
[1320] | 453 | |
---|
[1324] | 454 | USE transpose_indices, & |
---|
| 455 | ONLY: nxl_yd, nxr_yd, nzb_yd, nzt_yd |
---|
[1] | 456 | |
---|
[1320] | 457 | |
---|
[1] | 458 | IMPLICIT NONE |
---|
| 459 | |
---|
[1320] | 460 | INTEGER(iwp) :: i !: |
---|
| 461 | INTEGER(iwp) :: j !: |
---|
| 462 | INTEGER(iwp) :: jshape(1) !: |
---|
| 463 | INTEGER(iwp) :: k !: |
---|
| 464 | INTEGER(iwp) :: m !: |
---|
| 465 | INTEGER(iwp) :: n !: |
---|
| 466 | INTEGER(iwp) :: pr !: |
---|
[1] | 467 | |
---|
[1320] | 468 | REAL(wp) :: exponent !: |
---|
[1431] | 469 | REAL(wp) :: sum_spec_dum !: wavenumber-integrated spectrum |
---|
[1320] | 470 | |
---|
| 471 | REAL(wp), DIMENSION(0:ny) :: work !: |
---|
| 472 | |
---|
| 473 | REAL(wp), DIMENSION(0:ny/2) :: sums_spectra_l !: |
---|
| 474 | |
---|
| 475 | REAL(wp), DIMENSION(0:ny/2,100) :: sums_spectra !: |
---|
| 476 | |
---|
| 477 | REAL(wp), DIMENSION(0:ny,nxl_yd:nxr_yd,nzb_yd:nzt_yd) :: ddd !: |
---|
[1] | 478 | |
---|
| 479 | |
---|
| 480 | ! |
---|
| 481 | !-- Exponent for geometric average |
---|
[1342] | 482 | exponent = 1.0_wp / ( nx + 1.0_wp ) |
---|
[1] | 483 | |
---|
| 484 | ! |
---|
| 485 | !-- Loop over all levels defined by the user |
---|
| 486 | n = 1 |
---|
[189] | 487 | DO WHILE ( comp_spectra_level(n) /= 999999 .AND. n <= 100 ) |
---|
[1] | 488 | |
---|
| 489 | k = comp_spectra_level(n) |
---|
| 490 | |
---|
| 491 | ! |
---|
| 492 | !-- Calculate FFT only if the corresponding level is situated on this PE |
---|
| 493 | IF ( k >= nzb_yd .AND. k <= nzt_yd ) THEN |
---|
| 494 | |
---|
| 495 | DO i = nxl_yd, nxr_yd |
---|
| 496 | |
---|
| 497 | work = ddd(0:ny,i,k) |
---|
[1120] | 498 | CALL fft_y_1d( work, 'forward' ) |
---|
[1] | 499 | |
---|
| 500 | ddd(0,i,k) = dy * work(0)**2 |
---|
| 501 | DO j = 1, ny/2 |
---|
| 502 | ddd(j,i,k) = dy * ( work(j)**2 + work(ny+1-j)**2 ) |
---|
| 503 | ENDDO |
---|
| 504 | |
---|
| 505 | ENDDO |
---|
| 506 | |
---|
| 507 | ! |
---|
| 508 | !-- Local sum and geometric average of these spectra |
---|
| 509 | !-- (WARNING: no global sum should be performed, because floating |
---|
| 510 | !-- point overflow may occur) |
---|
| 511 | DO j = 0, ny/2 |
---|
| 512 | |
---|
[1342] | 513 | sums_spectra_l(j) = 1.0_wp |
---|
[1] | 514 | DO i = nxl_yd, nxr_yd |
---|
| 515 | sums_spectra_l(j) = sums_spectra_l(j) * ddd(j,i,k)**exponent |
---|
| 516 | ENDDO |
---|
| 517 | |
---|
| 518 | ENDDO |
---|
| 519 | |
---|
| 520 | ELSE |
---|
| 521 | |
---|
[1342] | 522 | sums_spectra_l = 1.0_wp |
---|
[1] | 523 | |
---|
| 524 | ENDIF |
---|
| 525 | |
---|
| 526 | ! |
---|
| 527 | !-- Global sum of spectra on PE0 (from where they are written on file) |
---|
[1342] | 528 | sums_spectra(:,n) = 0.0_wp |
---|
[1] | 529 | #if defined( __parallel ) |
---|
| 530 | CALL MPI_BARRIER( comm2d, ierr ) ! Necessary? |
---|
[1320] | 531 | CALL MPI_REDUCE( sums_spectra_l(0), sums_spectra(0,n), ny/2+1, & |
---|
[1] | 532 | MPI_REAL, MPI_PROD, 0, comm2d, ierr ) |
---|
| 533 | #else |
---|
| 534 | sums_spectra(:,n) = sums_spectra_l |
---|
| 535 | #endif |
---|
[1431] | 536 | ! |
---|
| 537 | !-- Normalize spectra by variance |
---|
| 538 | sum_spec_dum = SUM( sums_spectra(:,n) ) |
---|
| 539 | IF ( SUM(sums_spectra(:,n)) /= 0.0_wp ) THEN |
---|
| 540 | sums_spectra(:,n) = sums_spectra(:,n) * var_d(k) / SUM(sums_spectra(:,n)) |
---|
| 541 | ENDIF |
---|
[1] | 542 | n = n + 1 |
---|
| 543 | |
---|
| 544 | ENDDO |
---|
| 545 | n = n - 1 |
---|
| 546 | |
---|
| 547 | |
---|
| 548 | IF ( myid == 0 ) THEN |
---|
| 549 | ! |
---|
[146] | 550 | !-- Sum of spectra for later averaging (see routine data_output_spectra) |
---|
[1] | 551 | DO j = 1, ny/2 |
---|
| 552 | DO k = 1, n |
---|
[1511] | 553 | spectrum_y(j,k,m) = spectrum_y(j,k,m) + sums_spectra(j,k) |
---|
[1] | 554 | ENDDO |
---|
| 555 | ENDDO |
---|
| 556 | |
---|
| 557 | ENDIF |
---|
| 558 | |
---|
| 559 | ! |
---|
[146] | 560 | !-- n_sp_y is needed by data_output_spectra_y |
---|
[1] | 561 | n_sp_y = n |
---|
| 562 | |
---|
| 563 | END SUBROUTINE calc_spectra_y |
---|
| 564 | #endif |
---|