[1] | 1 | SUBROUTINE calc_spectra |
---|
| 2 | |
---|
| 3 | !------------------------------------------------------------------------------! |
---|
[247] | 4 | ! Current revisions: |
---|
[1] | 5 | ! ----------------- |
---|
[198] | 6 | ! |
---|
| 7 | ! Former revisions: |
---|
| 8 | ! ----------------- |
---|
| 9 | ! $Id: calc_spectra.f90 668 2010-12-23 13:22:58Z suehring $ |
---|
| 10 | ! |
---|
[668] | 11 | ! 667 2010-12-23 12:06:00Z suehring/gryschka |
---|
| 12 | ! nxl-1, nxr+1, nys-1, nyn+1 replaced by nxlg, nxrg, nysg, nyng for allocation |
---|
| 13 | ! of tend |
---|
| 14 | ! |
---|
[392] | 15 | ! 274 2009-03-26 15:11:21Z heinze |
---|
| 16 | ! Output of messages replaced by message handling routine |
---|
| 17 | ! |
---|
[226] | 18 | ! 225 2009-01-26 14:44:20Z raasch |
---|
| 19 | ! Bugfix: array d is reallocated in case that multigrid is used |
---|
| 20 | ! |
---|
[198] | 21 | ! 192 2008-08-27 16:51:49Z letzel |
---|
[192] | 22 | ! bugfix in calc_spectra_x: exponent = 1.0 / ( ny + 1.0 ) |
---|
[189] | 23 | ! allow 100 spectra levels instead of 10 for consistency with |
---|
| 24 | ! define_netcdf_header |
---|
[164] | 25 | ! user-defined spectra, arguments removed from transpose routines |
---|
[1] | 26 | ! |
---|
[198] | 27 | ! February 2007 |
---|
[3] | 28 | ! RCS Log replace by Id keyword, revision history cleaned up |
---|
| 29 | ! |
---|
[1] | 30 | ! Revision 1.9 2006/04/11 14:56:00 raasch |
---|
| 31 | ! pl_spectra renamed data_output_sp |
---|
| 32 | ! |
---|
| 33 | ! Revision 1.1 2001/01/05 15:08:07 raasch |
---|
| 34 | ! Initial revision |
---|
| 35 | ! |
---|
| 36 | ! |
---|
| 37 | ! Description: |
---|
| 38 | ! ------------ |
---|
| 39 | ! Calculate horizontal spectra along x and y. |
---|
| 40 | ! ATTENTION: 1d-decomposition along y still needs improvement, because in that |
---|
| 41 | ! case the gridpoint number along z still depends on the PE number |
---|
| 42 | ! because transpose_xz has to be used (and possibly also |
---|
| 43 | ! transpose_zyd needs modification). |
---|
| 44 | !------------------------------------------------------------------------------! |
---|
| 45 | |
---|
| 46 | #if defined( __spectra ) |
---|
| 47 | USE arrays_3d |
---|
| 48 | USE control_parameters |
---|
| 49 | USE cpulog |
---|
| 50 | USE fft_xy |
---|
| 51 | USE indices |
---|
| 52 | USE interfaces |
---|
| 53 | USE pegrid |
---|
| 54 | USE spectrum |
---|
| 55 | |
---|
| 56 | IMPLICIT NONE |
---|
| 57 | |
---|
| 58 | INTEGER :: m, pr |
---|
| 59 | |
---|
| 60 | |
---|
| 61 | CALL cpu_log( log_point(30), 'calc_spectra', 'start' ) |
---|
| 62 | |
---|
| 63 | ! |
---|
| 64 | !-- Initialize ffts |
---|
| 65 | CALL fft_init |
---|
| 66 | |
---|
| 67 | ! |
---|
[225] | 68 | !-- Reallocate array d in required size |
---|
| 69 | IF ( psolver == 'multigrid' ) THEN |
---|
| 70 | DEALLOCATE( d ) |
---|
| 71 | ALLOCATE( d(nzb+1:nzta,nys:nyna,nxl:nxra) ) |
---|
| 72 | ENDIF |
---|
| 73 | |
---|
| 74 | ! |
---|
[1] | 75 | !-- Enlarge the size of tend, used as a working array for the transpositions |
---|
| 76 | IF ( nxra > nxr .OR. nyna > nyn .OR. nza > nz ) THEN |
---|
| 77 | DEALLOCATE( tend ) |
---|
| 78 | ALLOCATE( tend(1:nza,nys:nyna,nxl:nxra) ) |
---|
| 79 | ENDIF |
---|
| 80 | |
---|
| 81 | m = 1 |
---|
| 82 | DO WHILE ( data_output_sp(m) /= ' ' .AND. m <= 10 ) |
---|
| 83 | ! |
---|
| 84 | !-- Transposition from z --> x ( y --> x in case of a 1d-decomposition |
---|
| 85 | !-- along x) |
---|
| 86 | IF ( INDEX( spectra_direction(m), 'x' ) /= 0 ) THEN |
---|
| 87 | |
---|
| 88 | ! |
---|
| 89 | !-- Calculation of spectra works for cyclic boundary conditions only |
---|
| 90 | IF ( bc_lr /= 'cyclic' ) THEN |
---|
[247] | 91 | |
---|
[274] | 92 | message_string = 'non-cyclic lateral boundaries along x do not'// & |
---|
[247] | 93 | '& allow calculation of spectra along x' |
---|
| 94 | CALL message( 'calc_spectra', 'PA0160', 1, 2, 0, 6, 0 ) |
---|
[1] | 95 | ENDIF |
---|
| 96 | |
---|
| 97 | CALL preprocess_spectra( m, pr ) |
---|
| 98 | |
---|
| 99 | #if defined( __parallel ) |
---|
| 100 | IF ( pdims(2) /= 1 ) THEN |
---|
[164] | 101 | CALL transpose_zx( d, tend, d ) |
---|
[1] | 102 | ELSE |
---|
[164] | 103 | CALL transpose_yxd( d, tend, d ) |
---|
[1] | 104 | ENDIF |
---|
| 105 | CALL calc_spectra_x( d, pr, m ) |
---|
| 106 | #else |
---|
[274] | 107 | message_string = 'sorry, calculation of spectra in non parallel ' // & |
---|
| 108 | 'mode& is still not realized' |
---|
[247] | 109 | CALL message( 'calc_spectra', 'PA0161', 1, 2, 0, 6, 0 ) |
---|
[1] | 110 | #endif |
---|
| 111 | |
---|
| 112 | ENDIF |
---|
| 113 | |
---|
| 114 | ! |
---|
| 115 | !-- Transposition from z --> y (d is rearranged only in case of a |
---|
| 116 | !-- 1d-decomposition along x) |
---|
| 117 | IF ( INDEX( spectra_direction(m), 'y' ) /= 0 ) THEN |
---|
| 118 | |
---|
| 119 | ! |
---|
| 120 | !-- Calculation of spectra works for cyclic boundary conditions only |
---|
| 121 | IF ( bc_ns /= 'cyclic' ) THEN |
---|
| 122 | IF ( myid == 0 ) THEN |
---|
[274] | 123 | message_string = 'non-cyclic lateral boundaries along y do' // & |
---|
| 124 | ' not & allow calculation of spectra along y' |
---|
[247] | 125 | CALL message( 'calc_spectra', 'PA0162', 1, 2, 0, 6, 0 ) |
---|
[1] | 126 | ENDIF |
---|
| 127 | CALL local_stop |
---|
| 128 | ENDIF |
---|
| 129 | |
---|
| 130 | CALL preprocess_spectra( m, pr ) |
---|
| 131 | |
---|
| 132 | #if defined( __parallel ) |
---|
[164] | 133 | CALL transpose_zyd( d, tend, d ) |
---|
[1] | 134 | CALL calc_spectra_y( d, pr, m ) |
---|
| 135 | #else |
---|
[274] | 136 | message_string = 'sorry, calculation of spectra in non parallel' // & |
---|
| 137 | 'mode& is still not realized' |
---|
[247] | 138 | CALL message( 'calc_spectra', 'PA0161', 1, 2, 0, 6, 0 ) |
---|
[1] | 139 | #endif |
---|
| 140 | |
---|
| 141 | ENDIF |
---|
| 142 | |
---|
| 143 | ! |
---|
| 144 | !-- Increase counter for next spectrum |
---|
| 145 | m = m + 1 |
---|
| 146 | |
---|
| 147 | ENDDO |
---|
| 148 | |
---|
| 149 | ! |
---|
| 150 | !-- Increase counter for averaging process in routine plot_spectra |
---|
| 151 | average_count_sp = average_count_sp + 1 |
---|
| 152 | |
---|
| 153 | ! |
---|
| 154 | !-- Resize tend to its normal size |
---|
| 155 | IF ( nxra > nxr .OR. nyna > nyn .OR. nza > nz ) THEN |
---|
| 156 | DEALLOCATE( tend ) |
---|
[667] | 157 | ALLOCATE( tend(nzb:nzt+1,nysg:nyng,nxlg:nxrg) ) |
---|
[1] | 158 | ENDIF |
---|
| 159 | |
---|
| 160 | CALL cpu_log( log_point(30), 'calc_spectra', 'stop' ) |
---|
| 161 | |
---|
| 162 | #endif |
---|
| 163 | END SUBROUTINE calc_spectra |
---|
| 164 | |
---|
| 165 | |
---|
| 166 | #if defined( __spectra ) |
---|
| 167 | SUBROUTINE preprocess_spectra( m, pr ) |
---|
| 168 | |
---|
| 169 | USE arrays_3d |
---|
| 170 | USE indices |
---|
| 171 | USE pegrid |
---|
| 172 | USE spectrum |
---|
| 173 | USE statistics |
---|
| 174 | |
---|
| 175 | IMPLICIT NONE |
---|
| 176 | |
---|
| 177 | INTEGER :: i, j, k, m, pr |
---|
| 178 | |
---|
| 179 | SELECT CASE ( TRIM( data_output_sp(m) ) ) |
---|
| 180 | |
---|
| 181 | CASE ( 'u' ) |
---|
| 182 | pr = 1 |
---|
| 183 | d(nzb+1:nzt,nys:nyn,nxl:nxr) = u(nzb+1:nzt,nys:nyn,nxl:nxr) |
---|
| 184 | |
---|
| 185 | CASE ( 'v' ) |
---|
| 186 | pr = 2 |
---|
| 187 | d(nzb+1:nzt,nys:nyn,nxl:nxr) = v(nzb+1:nzt,nys:nyn,nxl:nxr) |
---|
| 188 | |
---|
| 189 | CASE ( 'w' ) |
---|
| 190 | pr = 3 |
---|
| 191 | d(nzb+1:nzt,nys:nyn,nxl:nxr) = w(nzb+1:nzt,nys:nyn,nxl:nxr) |
---|
| 192 | |
---|
| 193 | CASE ( 'pt' ) |
---|
| 194 | pr = 4 |
---|
| 195 | d(nzb+1:nzt,nys:nyn,nxl:nxr) = pt(nzb+1:nzt,nys:nyn,nxl:nxr) |
---|
| 196 | |
---|
| 197 | CASE ( 'q' ) |
---|
| 198 | pr = 41 |
---|
| 199 | d(nzb+1:nzt,nys:nyn,nxl:nxr) = q(nzb+1:nzt,nys:nyn,nxl:nxr) |
---|
| 200 | |
---|
| 201 | CASE DEFAULT |
---|
[144] | 202 | ! |
---|
| 203 | !-- The DEFAULT case is reached either if the parameter data_output_sp(m) |
---|
| 204 | !-- contains a wrong character string or if the user has coded a special |
---|
| 205 | !-- case in the user interface. There, the subroutine user_spectra |
---|
| 206 | !-- checks which of these two conditions applies. |
---|
| 207 | CALL user_spectra( 'preprocess', m, pr ) |
---|
[1] | 208 | |
---|
| 209 | END SELECT |
---|
| 210 | |
---|
| 211 | ! |
---|
| 212 | !-- Subtract horizontal mean from the array, for which spectra have to be |
---|
| 213 | !-- calculated |
---|
| 214 | DO i = nxl, nxr |
---|
| 215 | DO j = nys, nyn |
---|
| 216 | DO k = nzb+1, nzt |
---|
| 217 | d(k,j,i) = d(k,j,i) - sums(k,pr) |
---|
| 218 | ENDDO |
---|
| 219 | ENDDO |
---|
| 220 | ENDDO |
---|
| 221 | |
---|
| 222 | END SUBROUTINE preprocess_spectra |
---|
| 223 | |
---|
| 224 | |
---|
| 225 | SUBROUTINE calc_spectra_x( ddd, pr, m ) |
---|
| 226 | |
---|
| 227 | USE arrays_3d |
---|
| 228 | USE constants |
---|
| 229 | USE control_parameters |
---|
| 230 | USE fft_xy |
---|
| 231 | USE grid_variables |
---|
| 232 | USE indices |
---|
| 233 | USE pegrid |
---|
| 234 | USE spectrum |
---|
| 235 | USE statistics |
---|
| 236 | USE transpose_indices |
---|
| 237 | |
---|
| 238 | IMPLICIT NONE |
---|
| 239 | |
---|
| 240 | INTEGER :: i, ishape(1), j, k, m, n, pr |
---|
| 241 | |
---|
| 242 | REAL :: fac, exponent |
---|
| 243 | REAL, DIMENSION(0:nx) :: work |
---|
| 244 | REAL, DIMENSION(0:nx/2) :: sums_spectra_l |
---|
[189] | 245 | REAL, DIMENSION(0:nx/2,100):: sums_spectra |
---|
[1] | 246 | |
---|
| 247 | REAL, DIMENSION(0:nxa,nys_x:nyn_xa,nzb_x:nzt_xa) :: ddd |
---|
| 248 | |
---|
| 249 | ! |
---|
| 250 | !-- Exponent for geometric average |
---|
[192] | 251 | exponent = 1.0 / ( ny + 1.0 ) |
---|
[1] | 252 | |
---|
| 253 | ! |
---|
| 254 | !-- Loop over all levels defined by the user |
---|
| 255 | n = 1 |
---|
[189] | 256 | DO WHILE ( comp_spectra_level(n) /= 999999 .AND. n <= 100 ) |
---|
[1] | 257 | |
---|
| 258 | k = comp_spectra_level(n) |
---|
| 259 | |
---|
| 260 | ! |
---|
| 261 | !-- Calculate FFT only if the corresponding level is situated on this PE |
---|
| 262 | IF ( k >= nzb_x .AND. k <= nzt_x ) THEN |
---|
| 263 | |
---|
| 264 | DO j = nys_x, nyn_x |
---|
| 265 | |
---|
| 266 | work = ddd(0:nx,j,k) |
---|
| 267 | CALL fft_x( work, 'forward' ) |
---|
| 268 | |
---|
| 269 | ddd(0,j,k) = dx * work(0)**2 |
---|
| 270 | DO i = 1, nx/2 |
---|
| 271 | ddd(i,j,k) = dx * ( work(i)**2 + work(nx+1-i)**2 ) |
---|
| 272 | ENDDO |
---|
| 273 | |
---|
| 274 | ENDDO |
---|
| 275 | |
---|
| 276 | ! |
---|
| 277 | !-- Local sum and geometric average of these spectra |
---|
| 278 | !-- (WARNING: no global sum should be performed, because floating |
---|
| 279 | !-- point overflow may occur) |
---|
| 280 | DO i = 0, nx/2 |
---|
| 281 | |
---|
| 282 | sums_spectra_l(i) = 1.0 |
---|
| 283 | DO j = nys_x, nyn_x |
---|
| 284 | sums_spectra_l(i) = sums_spectra_l(i) * ddd(i,j,k)**exponent |
---|
| 285 | ENDDO |
---|
| 286 | |
---|
| 287 | ENDDO |
---|
| 288 | |
---|
| 289 | ELSE |
---|
| 290 | |
---|
| 291 | sums_spectra_l = 1.0 |
---|
| 292 | |
---|
| 293 | ENDIF |
---|
| 294 | |
---|
| 295 | ! |
---|
| 296 | !-- Global sum of spectra on PE0 (from where they are written on file) |
---|
| 297 | sums_spectra(:,n) = 0.0 |
---|
| 298 | #if defined( __parallel ) |
---|
| 299 | CALL MPI_BARRIER( comm2d, ierr ) ! Necessary? |
---|
| 300 | CALL MPI_REDUCE( sums_spectra_l(0), sums_spectra(0,n), nx/2+1, & |
---|
| 301 | MPI_REAL, MPI_PROD, 0, comm2d, ierr ) |
---|
| 302 | #else |
---|
| 303 | sums_spectra(:,n) = sums_spectra_l |
---|
| 304 | #endif |
---|
| 305 | |
---|
| 306 | n = n + 1 |
---|
| 307 | |
---|
| 308 | ENDDO |
---|
| 309 | n = n - 1 |
---|
| 310 | |
---|
| 311 | IF ( myid == 0 ) THEN |
---|
| 312 | ! |
---|
[146] | 313 | !-- Sum of spectra for later averaging (see routine data_output_spectra) |
---|
[1] | 314 | !-- Temperton fft results need to be normalized |
---|
| 315 | IF ( fft_method == 'temperton-algorithm' ) THEN |
---|
| 316 | fac = nx + 1.0 |
---|
| 317 | ELSE |
---|
| 318 | fac = 1.0 |
---|
| 319 | ENDIF |
---|
| 320 | DO i = 1, nx/2 |
---|
| 321 | DO k = 1, n |
---|
| 322 | spectrum_x(i,k,m) = spectrum_x(i,k,m) + sums_spectra(i,k) * fac |
---|
| 323 | ENDDO |
---|
| 324 | ENDDO |
---|
| 325 | |
---|
| 326 | ENDIF |
---|
| 327 | |
---|
| 328 | ! |
---|
[146] | 329 | !-- n_sp_x is needed by data_output_spectra_x |
---|
[1] | 330 | n_sp_x = n |
---|
| 331 | |
---|
| 332 | END SUBROUTINE calc_spectra_x |
---|
| 333 | |
---|
| 334 | |
---|
| 335 | SUBROUTINE calc_spectra_y( ddd, pr, m ) |
---|
| 336 | |
---|
| 337 | USE arrays_3d |
---|
| 338 | USE constants |
---|
| 339 | USE control_parameters |
---|
| 340 | USE fft_xy |
---|
| 341 | USE grid_variables |
---|
| 342 | USE indices |
---|
| 343 | USE pegrid |
---|
| 344 | USE spectrum |
---|
| 345 | USE statistics |
---|
| 346 | USE transpose_indices |
---|
| 347 | |
---|
| 348 | IMPLICIT NONE |
---|
| 349 | |
---|
| 350 | INTEGER :: i, j, jshape(1), k, m, n, pr |
---|
| 351 | |
---|
| 352 | REAL :: fac, exponent |
---|
| 353 | REAL, DIMENSION(0:ny) :: work |
---|
| 354 | REAL, DIMENSION(0:ny/2) :: sums_spectra_l |
---|
[189] | 355 | REAL, DIMENSION(0:ny/2,100):: sums_spectra |
---|
[1] | 356 | |
---|
| 357 | REAL, DIMENSION(0:nya,nxl_yd:nxr_yda,nzb_yd:nzt_yda) :: ddd |
---|
| 358 | |
---|
| 359 | |
---|
| 360 | ! |
---|
| 361 | !-- Exponent for geometric average |
---|
| 362 | exponent = 1.0 / ( nx + 1.0 ) |
---|
| 363 | |
---|
| 364 | ! |
---|
| 365 | !-- Loop over all levels defined by the user |
---|
| 366 | n = 1 |
---|
[189] | 367 | DO WHILE ( comp_spectra_level(n) /= 999999 .AND. n <= 100 ) |
---|
[1] | 368 | |
---|
| 369 | k = comp_spectra_level(n) |
---|
| 370 | |
---|
| 371 | ! |
---|
| 372 | !-- Calculate FFT only if the corresponding level is situated on this PE |
---|
| 373 | IF ( k >= nzb_yd .AND. k <= nzt_yd ) THEN |
---|
| 374 | |
---|
| 375 | DO i = nxl_yd, nxr_yd |
---|
| 376 | |
---|
| 377 | work = ddd(0:ny,i,k) |
---|
| 378 | CALL fft_y( work, 'forward' ) |
---|
| 379 | |
---|
| 380 | ddd(0,i,k) = dy * work(0)**2 |
---|
| 381 | DO j = 1, ny/2 |
---|
| 382 | ddd(j,i,k) = dy * ( work(j)**2 + work(ny+1-j)**2 ) |
---|
| 383 | ENDDO |
---|
| 384 | |
---|
| 385 | ENDDO |
---|
| 386 | |
---|
| 387 | ! |
---|
| 388 | !-- Local sum and geometric average of these spectra |
---|
| 389 | !-- (WARNING: no global sum should be performed, because floating |
---|
| 390 | !-- point overflow may occur) |
---|
| 391 | DO j = 0, ny/2 |
---|
| 392 | |
---|
| 393 | sums_spectra_l(j) = 1.0 |
---|
| 394 | DO i = nxl_yd, nxr_yd |
---|
| 395 | sums_spectra_l(j) = sums_spectra_l(j) * ddd(j,i,k)**exponent |
---|
| 396 | ENDDO |
---|
| 397 | |
---|
| 398 | ENDDO |
---|
| 399 | |
---|
| 400 | ELSE |
---|
| 401 | |
---|
| 402 | sums_spectra_l = 1.0 |
---|
| 403 | |
---|
| 404 | ENDIF |
---|
| 405 | |
---|
| 406 | ! |
---|
| 407 | !-- Global sum of spectra on PE0 (from where they are written on file) |
---|
| 408 | sums_spectra(:,n) = 0.0 |
---|
| 409 | #if defined( __parallel ) |
---|
| 410 | CALL MPI_BARRIER( comm2d, ierr ) ! Necessary? |
---|
| 411 | CALL MPI_REDUCE( sums_spectra_l(0), sums_spectra(0,n), ny/2+1, & |
---|
| 412 | MPI_REAL, MPI_PROD, 0, comm2d, ierr ) |
---|
| 413 | #else |
---|
| 414 | sums_spectra(:,n) = sums_spectra_l |
---|
| 415 | #endif |
---|
| 416 | |
---|
| 417 | n = n + 1 |
---|
| 418 | |
---|
| 419 | ENDDO |
---|
| 420 | n = n - 1 |
---|
| 421 | |
---|
| 422 | |
---|
| 423 | IF ( myid == 0 ) THEN |
---|
| 424 | ! |
---|
[146] | 425 | !-- Sum of spectra for later averaging (see routine data_output_spectra) |
---|
[1] | 426 | !-- Temperton fft results need to be normalized |
---|
| 427 | IF ( fft_method == 'temperton-algorithm' ) THEN |
---|
| 428 | fac = ny + 1.0 |
---|
| 429 | ELSE |
---|
| 430 | fac = 1.0 |
---|
| 431 | ENDIF |
---|
| 432 | DO j = 1, ny/2 |
---|
| 433 | DO k = 1, n |
---|
| 434 | spectrum_y(j,k,m) = spectrum_y(j,k,m) + sums_spectra(j,k) * fac |
---|
| 435 | ENDDO |
---|
| 436 | ENDDO |
---|
| 437 | |
---|
| 438 | ENDIF |
---|
| 439 | |
---|
| 440 | ! |
---|
[146] | 441 | !-- n_sp_y is needed by data_output_spectra_y |
---|
[1] | 442 | n_sp_y = n |
---|
| 443 | |
---|
| 444 | END SUBROUTINE calc_spectra_y |
---|
| 445 | #endif |
---|