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