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