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