source: palm/tags/release-3.2b/SOURCE/calc_spectra.f90 @ 2007

Last change on this file since 2007 was 4, checked in by raasch, 17 years ago

Id keyword set as property for all *.f90 files

  • Property svn:keywords set to Id
File size: 10.3 KB
Line 
1 SUBROUTINE calc_spectra
2
3!------------------------------------------------------------------------------!
4! Actual revisions:
5! -----------------
6!
7!
8! Former revisions:
9! -----------------
10! $Id: calc_spectra.f90 4 2007-02-13 11:33:16Z kanani $
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, tend, d )
80          ELSE
81             CALL transpose_yxd( d, tend, 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, 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       PRINT*, '+++ preprocess_spectra: Spectra of ', &
183               TRIM( data_output_sp(m) ), ' can not be calculated'
184         
185    END SELECT
186
187!
188!-- Subtract horizontal mean from the array, for which spectra have to be
189!-- calculated
190    DO  i = nxl, nxr
191       DO  j = nys, nyn
192          DO  k = nzb+1, nzt
193             d(k,j,i) = d(k,j,i) - sums(k,pr)
194          ENDDO
195       ENDDO
196    ENDDO
197
198 END SUBROUTINE preprocess_spectra
199
200
201 SUBROUTINE calc_spectra_x( ddd, pr, m )
202
203    USE arrays_3d
204    USE constants
205    USE control_parameters
206    USE fft_xy
207    USE grid_variables
208    USE indices
209    USE pegrid
210    USE spectrum
211    USE statistics
212    USE transpose_indices
213
214    IMPLICIT NONE
215
216    INTEGER                    ::  i, ishape(1), j, k, m, n, pr
217
218    REAL                       ::  fac, exponent
219    REAL, DIMENSION(0:nx)      ::  work
220    REAL, DIMENSION(0:nx/2)    ::  sums_spectra_l
221    REAL, DIMENSION(0:nx/2,10) ::  sums_spectra
222
223    REAL, DIMENSION(0:nxa,nys_x:nyn_xa,nzb_x:nzt_xa) ::  ddd
224
225!
226!-- Exponent for geometric average
227    exponent = 1.0 / ( nx + 1.0 )
228
229!
230!-- Loop over all levels defined by the user
231    n = 1
232    DO WHILE ( comp_spectra_level(n) /= 999999  .AND.  n <= 10 )
233
234       k = comp_spectra_level(n)
235
236!
237!--    Calculate FFT only if the corresponding level is situated on this PE
238       IF ( k >= nzb_x  .AND.  k <= nzt_x )  THEN
239         
240          DO  j = nys_x, nyn_x
241
242             work = ddd(0:nx,j,k)
243             CALL fft_x( work, 'forward' )
244
245             ddd(0,j,k) = dx * work(0)**2
246             DO  i = 1, nx/2
247                ddd(i,j,k) = dx * ( work(i)**2 + work(nx+1-i)**2 )
248             ENDDO
249
250          ENDDO
251
252!
253!--       Local sum and geometric average of these spectra
254!--       (WARNING: no global sum should be performed, because floating
255!--       point overflow may occur)
256          DO  i = 0, nx/2
257
258             sums_spectra_l(i) = 1.0
259             DO  j = nys_x, nyn_x
260                sums_spectra_l(i) = sums_spectra_l(i) * ddd(i,j,k)**exponent
261             ENDDO
262
263          ENDDO
264         
265       ELSE
266
267          sums_spectra_l = 1.0
268
269       ENDIF
270
271!
272!--    Global sum of spectra on PE0 (from where they are written on file)
273       sums_spectra(:,n) = 0.0
274#if defined( __parallel )   
275       CALL MPI_BARRIER( comm2d, ierr )  ! Necessary?
276       CALL MPI_REDUCE( sums_spectra_l(0), sums_spectra(0,n), nx/2+1, &
277                        MPI_REAL, MPI_PROD, 0, comm2d, ierr )
278#else
279       sums_spectra(:,n) = sums_spectra_l
280#endif
281
282       n = n + 1
283
284    ENDDO
285    n = n - 1
286
287    IF ( myid == 0 )  THEN
288!
289!--    Sum of spectra for later averaging (see routine plot_spectra)
290!--    Temperton fft results need to be normalized
291       IF ( fft_method == 'temperton-algorithm' )  THEN
292          fac = nx + 1.0
293       ELSE
294          fac = 1.0
295       ENDIF
296       DO  i = 1, nx/2
297          DO k = 1, n
298             spectrum_x(i,k,m) = spectrum_x(i,k,m) + sums_spectra(i,k) * fac
299          ENDDO
300       ENDDO
301
302    ENDIF
303
304!
305!-- n_sp_x is needed by plot_spectra_x
306    n_sp_x = n
307
308 END SUBROUTINE calc_spectra_x
309
310
311 SUBROUTINE calc_spectra_y( ddd, pr, m )
312
313    USE arrays_3d
314    USE constants
315    USE control_parameters
316    USE fft_xy
317    USE grid_variables
318    USE indices
319    USE pegrid
320    USE spectrum
321    USE statistics
322    USE transpose_indices
323
324    IMPLICIT NONE
325
326    INTEGER :: i, j, jshape(1), k, m, n, pr
327
328    REAL                       ::  fac, exponent
329    REAL, DIMENSION(0:ny)      ::  work
330    REAL, DIMENSION(0:ny/2)    ::  sums_spectra_l
331    REAL, DIMENSION(0:ny/2,10) ::  sums_spectra
332
333    REAL, DIMENSION(0:nya,nxl_yd:nxr_yda,nzb_yd:nzt_yda) :: ddd
334
335
336!
337!-- Exponent for geometric average
338    exponent = 1.0 / ( nx + 1.0 )
339
340!
341!-- Loop over all levels defined by the user
342    n = 1
343    DO WHILE ( comp_spectra_level(n) /= 999999  .AND.  n <= 10 )
344
345       k = comp_spectra_level(n)
346
347!
348!--    Calculate FFT only if the corresponding level is situated on this PE
349       IF ( k >= nzb_yd  .AND.  k <= nzt_yd )  THEN
350         
351          DO  i = nxl_yd, nxr_yd
352
353             work = ddd(0:ny,i,k)
354             CALL fft_y( work, 'forward' )
355
356             ddd(0,i,k) = dy * work(0)**2
357             DO  j = 1, ny/2
358                ddd(j,i,k) = dy * ( work(j)**2 + work(ny+1-j)**2 )
359             ENDDO
360
361          ENDDO
362
363!
364!--       Local sum and geometric average of these spectra
365!--       (WARNING: no global sum should be performed, because floating
366!--       point overflow may occur)
367          DO  j = 0, ny/2
368
369             sums_spectra_l(j) = 1.0
370             DO  i = nxl_yd, nxr_yd
371                sums_spectra_l(j) = sums_spectra_l(j) * ddd(j,i,k)**exponent
372             ENDDO
373
374          ENDDO
375         
376       ELSE
377
378          sums_spectra_l = 1.0
379
380       ENDIF
381
382!
383!--    Global sum of spectra on PE0 (from where they are written on file)
384       sums_spectra(:,n) = 0.0
385#if defined( __parallel )   
386       CALL MPI_BARRIER( comm2d, ierr )  ! Necessary?
387       CALL MPI_REDUCE( sums_spectra_l(0), sums_spectra(0,n), ny/2+1, &
388                        MPI_REAL, MPI_PROD, 0, comm2d, ierr )
389#else
390       sums_spectra(:,n) = sums_spectra_l
391#endif
392
393       n = n + 1
394
395    ENDDO
396    n = n - 1
397
398
399    IF ( myid == 0 )  THEN
400!
401!--    Sum of spectra for later averaging (see routine plot_spectra)
402!--    Temperton fft results need to be normalized
403       IF ( fft_method == 'temperton-algorithm' )  THEN
404          fac = ny + 1.0
405       ELSE
406          fac = 1.0
407       ENDIF
408       DO  j = 1, ny/2
409          DO k = 1, n
410             spectrum_y(j,k,m) = spectrum_y(j,k,m) + sums_spectra(j,k) * fac
411          ENDDO
412       ENDDO
413
414    ENDIF
415
416!
417!-- n_sp_y is needed by plot_spectra_y
418    n_sp_y = n
419
420 END SUBROUTINE calc_spectra_y
421#endif
Note: See TracBrowser for help on using the repository browser.