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