1 | !> @file spectra_mod.f90 |
---|
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 | ! |
---|
16 | ! Copyright 1997-2016 Leibniz Universitaet Hannover |
---|
17 | !--------------------------------------------------------------------------------! |
---|
18 | ! |
---|
19 | ! Current revisions: |
---|
20 | ! ----------------- |
---|
21 | ! |
---|
22 | ! |
---|
23 | ! Former revisions: |
---|
24 | ! ----------------- |
---|
25 | ! $Id: spectra_mod.f90 1834 2016-04-07 14:34:20Z suehring $ |
---|
26 | ! |
---|
27 | ! 1833 2016-04-07 14:23:03Z raasch |
---|
28 | ! file renamed, reading the spectra_par NAMELIST moved from package_parin to |
---|
29 | ! here |
---|
30 | ! |
---|
31 | ! 1815 2016-04-06 13:49:59Z raasch |
---|
32 | ! bugfix: preprocessor directives included for the non-parallel case |
---|
33 | ! |
---|
34 | ! 1808 2016-04-05 19:44:00Z raasch |
---|
35 | ! MPI module used by default on all machines |
---|
36 | ! |
---|
37 | ! 1786 2016-03-08 05:49:27Z raasch |
---|
38 | ! routine is modularized, filename renamed from calc_spectra to spectrum, |
---|
39 | ! privious data module spectrum moved from modules.f90 to here, |
---|
40 | ! cpp-direktives for spectra removed, immediate return if no spectra levels are |
---|
41 | ! given |
---|
42 | ! |
---|
43 | ! 1682 2015-10-07 23:56:08Z knoop |
---|
44 | ! Code annotations made doxygen readable |
---|
45 | ! |
---|
46 | ! 1575 2015-03-27 09:56:27Z raasch |
---|
47 | ! adjustments for psolver-queries |
---|
48 | ! |
---|
49 | ! 1511 2014-12-16 15:54:16Z suehring |
---|
50 | ! Bugfix concerning spectra normalization |
---|
51 | ! |
---|
52 | ! 1431 2014-07-15 14:47:17Z suehring |
---|
53 | ! Wavenumber-integrated spectra coincide with respective variance. |
---|
54 | ! |
---|
55 | ! 1342 2014-03-26 17:04:47Z kanani |
---|
56 | ! REAL constants defined as wp-kinds |
---|
57 | ! |
---|
58 | ! 1324 2014-03-21 09:13:16Z suehring |
---|
59 | ! Bugfix: nzb_x, nzb_yd, nyn_x, nyn_x, nzt_x, nzt_yd belong to transpose_indices |
---|
60 | ! |
---|
61 | ! 1320 2014-03-20 08:40:49Z raasch |
---|
62 | ! ONLY-attribute added to USE-statements, |
---|
63 | ! kind-parameters added to all INTEGER and REAL declaration statements, |
---|
64 | ! kinds are defined in new module kinds, |
---|
65 | ! revision history before 2012 removed, |
---|
66 | ! comment fields (!:) to be used for variable explanations added to |
---|
67 | ! all variable declaration statements |
---|
68 | ! |
---|
69 | ! 1318 2014-03-17 13:35:16Z raasch |
---|
70 | ! module interfaces removed |
---|
71 | ! |
---|
72 | ! 1216 2013-08-26 09:31:42Z raasch |
---|
73 | ! resorting of array moved to separate routine resort_for_zx, |
---|
74 | ! one argument removed from the transpose_..d routines |
---|
75 | ! |
---|
76 | ! 1120 2013-04-05 15:11:35Z raasch |
---|
77 | ! bugfix: calls of fft_x|y replaced by fft_x|y_1d |
---|
78 | ! |
---|
79 | ! 1036 2012-10-22 13:43:42Z raasch |
---|
80 | ! code put under GPL (PALM 3.9) |
---|
81 | ! |
---|
82 | ! 1003 2012-09-14 14:35:53Z raasch |
---|
83 | ! adjustment of array tend for cases with unequal subdomain sizes removed |
---|
84 | ! |
---|
85 | ! Revision 1.1 2001/01/05 15:08:07 raasch |
---|
86 | ! Initial revision |
---|
87 | ! |
---|
88 | ! |
---|
89 | ! Description: |
---|
90 | ! ------------ |
---|
91 | !> Calculate horizontal spectra along x and y. |
---|
92 | !> ATTENTION: 1d-decomposition along y still needs improvement, because in that |
---|
93 | !> case the gridpoint number along z still depends on the PE number |
---|
94 | !> because transpose_xz has to be used (and possibly also |
---|
95 | !> transpose_zyd needs modification). |
---|
96 | !------------------------------------------------------------------------------! |
---|
97 | MODULE spectra_mod |
---|
98 | |
---|
99 | USE kinds |
---|
100 | |
---|
101 | PRIVATE |
---|
102 | |
---|
103 | CHARACTER (LEN=2), DIMENSION(10) :: spectra_direction = 'x' |
---|
104 | CHARACTER (LEN=10), DIMENSION(10) :: data_output_sp = ' ' |
---|
105 | |
---|
106 | INTEGER(iwp) :: average_count_sp = 0 |
---|
107 | INTEGER(iwp) :: dosp_time_count = 0 |
---|
108 | INTEGER(iwp) :: n_sp_x = 0, n_sp_y = 0 |
---|
109 | |
---|
110 | INTEGER(iwp) :: comp_spectra_level(100) = 999999 |
---|
111 | |
---|
112 | LOGICAL :: calculate_spectra = .FALSE. !< internal switch that spectra are calculated |
---|
113 | LOGICAL :: spectra_initialized = .FALSE. !< internal switch that spectra related quantities are initialized |
---|
114 | |
---|
115 | REAL(wp) :: averaging_interval_sp = 9999999.9_wp !< averaging interval for spectra output |
---|
116 | REAL(wp) :: dt_dosp = 9999999.9_wp !< time interval for spectra output |
---|
117 | REAL(wp) :: skip_time_dosp = 9999999.9_wp !< no output of spectra data before this interval has passed |
---|
118 | |
---|
119 | REAL(wp), DIMENSION(:), ALLOCATABLE :: var_d |
---|
120 | |
---|
121 | REAL(wp), DIMENSION(:,:,:), ALLOCATABLE :: spectrum_x, spectrum_y |
---|
122 | |
---|
123 | SAVE |
---|
124 | |
---|
125 | INTERFACE calc_spectra |
---|
126 | MODULE PROCEDURE calc_spectra |
---|
127 | END INTERFACE calc_spectra |
---|
128 | |
---|
129 | INTERFACE preprocess_spectra |
---|
130 | MODULE PROCEDURE preprocess_spectra |
---|
131 | END INTERFACE preprocess_spectra |
---|
132 | |
---|
133 | INTERFACE calc_spectra_x |
---|
134 | MODULE PROCEDURE calc_spectra_x |
---|
135 | END INTERFACE calc_spectra_x |
---|
136 | |
---|
137 | INTERFACE calc_spectra_y |
---|
138 | MODULE PROCEDURE calc_spectra_y |
---|
139 | END INTERFACE calc_spectra_y |
---|
140 | |
---|
141 | INTERFACE spectra_check_parameters |
---|
142 | MODULE PROCEDURE spectra_check_parameters |
---|
143 | END INTERFACE spectra_check_parameters |
---|
144 | |
---|
145 | INTERFACE spectra_header |
---|
146 | MODULE PROCEDURE spectra_header |
---|
147 | END INTERFACE spectra_header |
---|
148 | |
---|
149 | INTERFACE spectra_init |
---|
150 | MODULE PROCEDURE spectra_init |
---|
151 | END INTERFACE spectra_init |
---|
152 | |
---|
153 | INTERFACE spectra_parin |
---|
154 | MODULE PROCEDURE spectra_parin |
---|
155 | END INTERFACE spectra_parin |
---|
156 | |
---|
157 | PUBLIC average_count_sp, averaging_interval_sp, calc_spectra, & |
---|
158 | calculate_spectra, comp_spectra_level, data_output_sp, & |
---|
159 | dosp_time_count, dt_dosp, n_sp_x, n_sp_y, plot_spectra_level, & |
---|
160 | skip_time_dosp, spectra_check_parameters, spectra_direction, & |
---|
161 | spectra_header, spectra_init, spectra_parin, spectrum_x, & |
---|
162 | spectrum_y, var_d |
---|
163 | |
---|
164 | |
---|
165 | CONTAINS |
---|
166 | |
---|
167 | !------------------------------------------------------------------------------! |
---|
168 | ! Description: |
---|
169 | ! ------------ |
---|
170 | !> Parin for &spectra_par for calculating spectra |
---|
171 | !------------------------------------------------------------------------------! |
---|
172 | SUBROUTINE spectra_parin |
---|
173 | |
---|
174 | USE control_parameters, & |
---|
175 | ONLY: dt_data_output |
---|
176 | |
---|
177 | IMPLICIT NONE |
---|
178 | |
---|
179 | CHARACTER (LEN=80) :: line !< dummy string that contains the current & |
---|
180 | !< line of the parameter file |
---|
181 | |
---|
182 | NAMELIST /spectra_par/ averaging_interval_sp, comp_spectra_level, & |
---|
183 | data_output_sp, dt_dosp, skip_time_dosp, & |
---|
184 | spectra_direction |
---|
185 | |
---|
186 | |
---|
187 | ! |
---|
188 | !-- Position the namelist-file at the beginning (it was already opened in |
---|
189 | !-- parin), search for the namelist-group of the package and position the |
---|
190 | !-- file at this line. |
---|
191 | line = ' ' |
---|
192 | |
---|
193 | ! |
---|
194 | !-- Try to find the spectra package |
---|
195 | REWIND ( 11 ) |
---|
196 | line = ' ' |
---|
197 | DO WHILE ( INDEX( line, '&spectra_par' ) == 0 ) |
---|
198 | READ ( 11, '(A)', END=10 ) line |
---|
199 | ENDDO |
---|
200 | BACKSPACE ( 11 ) |
---|
201 | |
---|
202 | ! |
---|
203 | !-- Read namelist |
---|
204 | READ ( 11, spectra_par ) |
---|
205 | |
---|
206 | ! |
---|
207 | !-- Default setting of dt_dosp here (instead of check_parameters), because |
---|
208 | !-- its current value is needed in init_pegrid |
---|
209 | IF ( dt_dosp == 9999999.9_wp ) dt_dosp = dt_data_output |
---|
210 | |
---|
211 | ! |
---|
212 | !-- Set general switch that spectra shall be calculated |
---|
213 | calculate_spectra = .TRUE. |
---|
214 | |
---|
215 | 10 CONTINUE |
---|
216 | |
---|
217 | END SUBROUTINE spectra_parin |
---|
218 | |
---|
219 | |
---|
220 | |
---|
221 | !------------------------------------------------------------------------------! |
---|
222 | ! Description: |
---|
223 | ! ------------ |
---|
224 | !> Initialization of spectra related variables |
---|
225 | !------------------------------------------------------------------------------! |
---|
226 | SUBROUTINE spectra_init |
---|
227 | |
---|
228 | USE indices, & |
---|
229 | ONLY: nx, ny, nzb, nzt |
---|
230 | |
---|
231 | IMPLICIT NONE |
---|
232 | |
---|
233 | IF ( spectra_initialized ) RETURN |
---|
234 | |
---|
235 | IF ( dt_dosp /= 9999999.9_wp ) THEN |
---|
236 | ALLOCATE( spectrum_x( 1:nx/2, 1:10, 1:10 ), & |
---|
237 | spectrum_y( 1:ny/2, 1:10, 1:10 ) ) |
---|
238 | spectrum_x = 0.0_wp |
---|
239 | spectrum_y = 0.0_wp |
---|
240 | |
---|
241 | ALLOCATE( var_d(nzb:nzt+1) ) |
---|
242 | var_d = 0.0_wp |
---|
243 | ENDIF |
---|
244 | |
---|
245 | spectra_initialized = .TRUE. |
---|
246 | |
---|
247 | END SUBROUTINE spectra_init |
---|
248 | |
---|
249 | |
---|
250 | |
---|
251 | !------------------------------------------------------------------------------! |
---|
252 | ! Description: |
---|
253 | ! ------------ |
---|
254 | !> Check spectra related quantities |
---|
255 | !------------------------------------------------------------------------------! |
---|
256 | SUBROUTINE spectra_check_parameters |
---|
257 | |
---|
258 | USE control_parameters, & |
---|
259 | ONLY: averaging_interval, message_string, skip_time_data_output |
---|
260 | |
---|
261 | IMPLICIT NONE |
---|
262 | |
---|
263 | ! |
---|
264 | !-- Check the average interval |
---|
265 | IF ( averaging_interval_sp == 9999999.9_wp ) THEN |
---|
266 | averaging_interval_sp = averaging_interval |
---|
267 | ENDIF |
---|
268 | |
---|
269 | IF ( averaging_interval_sp > dt_dosp ) THEN |
---|
270 | WRITE( message_string, * ) 'averaging_interval_sp = ', & |
---|
271 | averaging_interval_sp, ' must be <= dt_dosp = ', dt_dosp |
---|
272 | CALL message( 'spectra_check_parameters', 'PA0087', 1, 2, 0, 6, 0 ) |
---|
273 | ENDIF |
---|
274 | |
---|
275 | ! |
---|
276 | !-- Set the default skip time interval for data output, if necessary |
---|
277 | IF ( skip_time_dosp == 9999999.9_wp ) & |
---|
278 | skip_time_dosp = skip_time_data_output |
---|
279 | |
---|
280 | END SUBROUTINE spectra_check_parameters |
---|
281 | |
---|
282 | |
---|
283 | |
---|
284 | !------------------------------------------------------------------------------! |
---|
285 | ! Description: |
---|
286 | ! ------------ |
---|
287 | !> Header output for spectra |
---|
288 | !> |
---|
289 | !> @todo Output of netcdf data format and compression level |
---|
290 | !------------------------------------------------------------------------------! |
---|
291 | SUBROUTINE spectra_header ( io ) |
---|
292 | |
---|
293 | USE control_parameters, & |
---|
294 | ONLY: dt_averaging_input_pr |
---|
295 | |
---|
296 | ! USE netcdf_interface, & |
---|
297 | ! ONLY: netcdf_data_format_string, netcdf_deflate |
---|
298 | |
---|
299 | IMPLICIT NONE |
---|
300 | |
---|
301 | CHARACTER (LEN=40) :: output_format !< internal string |
---|
302 | |
---|
303 | INTEGER(iwp) :: i !< internal counter |
---|
304 | INTEGER(iwp), INTENT(IN) :: io !< Unit of the output file |
---|
305 | |
---|
306 | ! |
---|
307 | !-- Spectra output |
---|
308 | IF ( dt_dosp /= 9999999.9_wp ) THEN |
---|
309 | WRITE ( io, 1 ) |
---|
310 | |
---|
311 | ! output_format = netcdf_data_format_string |
---|
312 | ! IF ( netcdf_deflate == 0 ) THEN |
---|
313 | ! WRITE ( io, 2 ) output_format |
---|
314 | ! ELSE |
---|
315 | ! WRITE ( io, 3 ) TRIM( output_format ), netcdf_deflate |
---|
316 | ! ENDIF |
---|
317 | WRITE ( io, 2 ) 'see profiles or other quantities' |
---|
318 | WRITE ( io, 4 ) dt_dosp |
---|
319 | IF ( skip_time_dosp /= 0.0_wp ) WRITE ( io, 5 ) skip_time_dosp |
---|
320 | WRITE ( io, 6 ) ( data_output_sp(i), i = 1,10 ), & |
---|
321 | ( spectra_direction(i), i = 1,10 ), & |
---|
322 | ( comp_spectra_level(i), i = 1,100 ), & |
---|
323 | averaging_interval_sp, dt_averaging_input_pr |
---|
324 | ENDIF |
---|
325 | |
---|
326 | 1 FORMAT (' Spectra:') |
---|
327 | 2 FORMAT (' Output format: ',A/) |
---|
328 | 3 FORMAT (' Output format: ',A, ' compressed with level: ',I1/) |
---|
329 | 4 FORMAT (' Output every ',F7.1,' s'/) |
---|
330 | 5 FORMAT (' No output during initial ',F8.2,' s') |
---|
331 | 6 FORMAT (' Arrays: ', 10(A5,',')/ & |
---|
332 | ' Directions: ', 10(A5,',')/ & |
---|
333 | ' height levels k = ', 20(I3,',')/ & |
---|
334 | ' ', 20(I3,',')/ & |
---|
335 | ' ', 20(I3,',')/ & |
---|
336 | ' ', 20(I3,',')/ & |
---|
337 | ' ', 19(I3,','),I3,'.'/ & |
---|
338 | ' Time averaged over ', F7.1, ' s,' / & |
---|
339 | ' Profiles for the time averaging are taken every ', & |
---|
340 | F6.1,' s') |
---|
341 | |
---|
342 | END SUBROUTINE spectra_header |
---|
343 | |
---|
344 | |
---|
345 | |
---|
346 | SUBROUTINE calc_spectra |
---|
347 | |
---|
348 | USE arrays_3d, & |
---|
349 | ONLY: d, tend |
---|
350 | |
---|
351 | USE control_parameters, & |
---|
352 | ONLY: bc_lr_cyc, bc_ns_cyc, message_string, psolver |
---|
353 | |
---|
354 | USE cpulog, & |
---|
355 | ONLY: cpu_log, log_point |
---|
356 | |
---|
357 | USE fft_xy, & |
---|
358 | ONLY: fft_init |
---|
359 | |
---|
360 | USE indices, & |
---|
361 | ONLY: nxl, nxr, nyn, nys, nzb, nzt |
---|
362 | |
---|
363 | USE kinds |
---|
364 | |
---|
365 | USE pegrid, & |
---|
366 | ONLY: myid, pdims |
---|
367 | |
---|
368 | IMPLICIT NONE |
---|
369 | |
---|
370 | INTEGER(iwp) :: m !< |
---|
371 | INTEGER(iwp) :: pr !< |
---|
372 | |
---|
373 | |
---|
374 | ! |
---|
375 | !-- Check if user gave any levels for spectra to be calculated |
---|
376 | IF ( comp_spectra_level(1) == 999999 ) RETURN |
---|
377 | |
---|
378 | CALL cpu_log( log_point(30), 'calc_spectra', 'start' ) |
---|
379 | |
---|
380 | ! |
---|
381 | !-- Initialize spectra related quantities |
---|
382 | CALL spectra_init |
---|
383 | |
---|
384 | ! |
---|
385 | !-- Initialize ffts |
---|
386 | CALL fft_init |
---|
387 | |
---|
388 | ! |
---|
389 | !-- Reallocate array d in required size |
---|
390 | IF ( psolver(1:9) == 'multigrid' ) THEN |
---|
391 | DEALLOCATE( d ) |
---|
392 | ALLOCATE( d(nzb+1:nzt,nys:nyn,nxl:nxr) ) |
---|
393 | ENDIF |
---|
394 | |
---|
395 | m = 1 |
---|
396 | DO WHILE ( data_output_sp(m) /= ' ' .AND. m <= 10 ) |
---|
397 | ! |
---|
398 | !-- Transposition from z --> x ( y --> x in case of a 1d-decomposition |
---|
399 | !-- along x) |
---|
400 | IF ( INDEX( spectra_direction(m), 'x' ) /= 0 ) THEN |
---|
401 | |
---|
402 | ! |
---|
403 | !-- Calculation of spectra works for cyclic boundary conditions only |
---|
404 | IF ( .NOT. bc_lr_cyc ) THEN |
---|
405 | |
---|
406 | message_string = 'non-cyclic lateral boundaries along x do'// & |
---|
407 | ' not & allow calculation of spectra along x' |
---|
408 | CALL message( 'calc_spectra', 'PA0160', 1, 2, 0, 6, 0 ) |
---|
409 | ENDIF |
---|
410 | |
---|
411 | CALL preprocess_spectra( m, pr ) |
---|
412 | |
---|
413 | #if defined( __parallel ) |
---|
414 | IF ( pdims(2) /= 1 ) THEN |
---|
415 | CALL resort_for_zx( d, tend ) |
---|
416 | CALL transpose_zx( tend, d ) |
---|
417 | ELSE |
---|
418 | CALL transpose_yxd( d, d ) |
---|
419 | ENDIF |
---|
420 | CALL calc_spectra_x( d, pr, m ) |
---|
421 | #else |
---|
422 | message_string = 'sorry, calculation of spectra in non paral' // & |
---|
423 | 'lel mode& is still not realized' |
---|
424 | CALL message( 'calc_spectra', 'PA0161', 1, 2, 0, 6, 0 ) |
---|
425 | #endif |
---|
426 | |
---|
427 | ENDIF |
---|
428 | |
---|
429 | ! |
---|
430 | !-- Transposition from z --> y (d is rearranged only in case of a |
---|
431 | !-- 1d-decomposition along x) |
---|
432 | IF ( INDEX( spectra_direction(m), 'y' ) /= 0 ) THEN |
---|
433 | |
---|
434 | ! |
---|
435 | !-- Calculation of spectra works for cyclic boundary conditions only |
---|
436 | IF ( .NOT. bc_ns_cyc ) THEN |
---|
437 | IF ( myid == 0 ) THEN |
---|
438 | message_string = 'non-cyclic lateral boundaries along y' // & |
---|
439 | ' do not & allow calculation of spectr' // & |
---|
440 | 'a along y' |
---|
441 | CALL message( 'calc_spectra', 'PA0162', 1, 2, 0, 6, 0 ) |
---|
442 | ENDIF |
---|
443 | CALL local_stop |
---|
444 | ENDIF |
---|
445 | |
---|
446 | CALL preprocess_spectra( m, pr ) |
---|
447 | |
---|
448 | #if defined( __parallel ) |
---|
449 | CALL transpose_zyd( d, d ) |
---|
450 | CALL calc_spectra_y( d, pr, m ) |
---|
451 | #else |
---|
452 | message_string = 'sorry, calculation of spectra in non paral' // & |
---|
453 | 'lel mode& is still not realized' |
---|
454 | CALL message( 'calc_spectra', 'PA0161', 1, 2, 0, 6, 0 ) |
---|
455 | #endif |
---|
456 | |
---|
457 | ENDIF |
---|
458 | |
---|
459 | ! |
---|
460 | !-- Increase counter for next spectrum |
---|
461 | m = m + 1 |
---|
462 | |
---|
463 | ENDDO |
---|
464 | |
---|
465 | ! |
---|
466 | !-- Increase counter for averaging process in routine plot_spectra |
---|
467 | average_count_sp = average_count_sp + 1 |
---|
468 | |
---|
469 | CALL cpu_log( log_point(30), 'calc_spectra', 'stop' ) |
---|
470 | |
---|
471 | END SUBROUTINE calc_spectra |
---|
472 | |
---|
473 | |
---|
474 | !------------------------------------------------------------------------------! |
---|
475 | ! Description: |
---|
476 | ! ------------ |
---|
477 | !> @todo Missing subroutine description. |
---|
478 | !------------------------------------------------------------------------------! |
---|
479 | SUBROUTINE preprocess_spectra( m, pr ) |
---|
480 | |
---|
481 | USE arrays_3d, & |
---|
482 | ONLY: d, pt, q, u, v, w |
---|
483 | |
---|
484 | USE indices, & |
---|
485 | ONLY: ngp_2dh, nxl, nxr, nyn, nys, nzb, nzt |
---|
486 | |
---|
487 | USE kinds |
---|
488 | |
---|
489 | #if defined( __parallel ) |
---|
490 | #if defined( __mpifh ) |
---|
491 | INCLUDE "mpif.h" |
---|
492 | #else |
---|
493 | USE MPI |
---|
494 | #endif |
---|
495 | #endif |
---|
496 | USE pegrid, & |
---|
497 | ONLY: collective_wait, comm2d, ierr |
---|
498 | |
---|
499 | USE statistics, & |
---|
500 | ONLY: hom |
---|
501 | |
---|
502 | |
---|
503 | IMPLICIT NONE |
---|
504 | |
---|
505 | INTEGER(iwp) :: i !< |
---|
506 | INTEGER(iwp) :: j !< |
---|
507 | INTEGER(iwp) :: k !< |
---|
508 | INTEGER(iwp) :: m !< |
---|
509 | INTEGER(iwp) :: pr !< |
---|
510 | |
---|
511 | REAL(wp), DIMENSION(nzb:nzt+1) :: var_d_l |
---|
512 | |
---|
513 | SELECT CASE ( TRIM( data_output_sp(m) ) ) |
---|
514 | |
---|
515 | CASE ( 'u' ) |
---|
516 | pr = 1 |
---|
517 | d(nzb+1:nzt,nys:nyn,nxl:nxr) = u(nzb+1:nzt,nys:nyn,nxl:nxr) |
---|
518 | |
---|
519 | CASE ( 'v' ) |
---|
520 | pr = 2 |
---|
521 | d(nzb+1:nzt,nys:nyn,nxl:nxr) = v(nzb+1:nzt,nys:nyn,nxl:nxr) |
---|
522 | |
---|
523 | CASE ( 'w' ) |
---|
524 | pr = 3 |
---|
525 | d(nzb+1:nzt,nys:nyn,nxl:nxr) = w(nzb+1:nzt,nys:nyn,nxl:nxr) |
---|
526 | |
---|
527 | CASE ( 'pt' ) |
---|
528 | pr = 4 |
---|
529 | d(nzb+1:nzt,nys:nyn,nxl:nxr) = pt(nzb+1:nzt,nys:nyn,nxl:nxr) |
---|
530 | |
---|
531 | CASE ( 'q' ) |
---|
532 | pr = 41 |
---|
533 | d(nzb+1:nzt,nys:nyn,nxl:nxr) = q(nzb+1:nzt,nys:nyn,nxl:nxr) |
---|
534 | |
---|
535 | CASE DEFAULT |
---|
536 | ! |
---|
537 | !-- The DEFAULT case is reached either if the parameter data_output_sp(m) |
---|
538 | !-- contains a wrong character string or if the user has coded a special |
---|
539 | !-- case in the user interface. There, the subroutine user_spectra |
---|
540 | !-- checks which of these two conditions applies. |
---|
541 | CALL user_spectra( 'preprocess', m, pr ) |
---|
542 | |
---|
543 | END SELECT |
---|
544 | |
---|
545 | ! |
---|
546 | !-- Subtract horizontal mean from the array, for which spectra have to be |
---|
547 | !-- calculated |
---|
548 | var_d_l(:) = 0.0_wp |
---|
549 | DO i = nxl, nxr |
---|
550 | DO j = nys, nyn |
---|
551 | DO k = nzb+1, nzt |
---|
552 | d(k,j,i) = d(k,j,i) - hom(k,1,pr,0) |
---|
553 | var_d_l(k) = var_d_l(k) + d(k,j,i) * d(k,j,i) |
---|
554 | ENDDO |
---|
555 | ENDDO |
---|
556 | ENDDO |
---|
557 | ! |
---|
558 | !-- Compute total variance from local variances |
---|
559 | var_d(:) = 0.0_wp |
---|
560 | #if defined( __parallel ) |
---|
561 | IF ( collective_wait ) CALL MPI_BARRIER( comm2d, ierr ) |
---|
562 | CALL MPI_ALLREDUCE( var_d_l(0), var_d(0), nzt+1-nzb, MPI_REAL, MPI_SUM, & |
---|
563 | comm2d, ierr ) |
---|
564 | #else |
---|
565 | var_d(:) = var_d_l(:) |
---|
566 | #endif |
---|
567 | var_d(:) = var_d(:) / ngp_2dh(0) |
---|
568 | |
---|
569 | END SUBROUTINE preprocess_spectra |
---|
570 | |
---|
571 | |
---|
572 | !------------------------------------------------------------------------------! |
---|
573 | ! Description: |
---|
574 | ! ------------ |
---|
575 | !> @todo Missing subroutine description. |
---|
576 | !------------------------------------------------------------------------------! |
---|
577 | SUBROUTINE calc_spectra_x( ddd, pr, m ) |
---|
578 | |
---|
579 | USE control_parameters, & |
---|
580 | ONLY: fft_method |
---|
581 | |
---|
582 | USE fft_xy, & |
---|
583 | ONLY: fft_x_1d |
---|
584 | |
---|
585 | USE grid_variables, & |
---|
586 | ONLY: dx |
---|
587 | |
---|
588 | USE indices, & |
---|
589 | ONLY: nx, ny |
---|
590 | |
---|
591 | USE kinds |
---|
592 | |
---|
593 | #if defined( __parallel ) |
---|
594 | #if defined( __mpifh ) |
---|
595 | INCLUDE "mpif.h" |
---|
596 | #else |
---|
597 | USE MPI |
---|
598 | #endif |
---|
599 | #endif |
---|
600 | USE pegrid, & |
---|
601 | ONLY: comm2d, ierr, myid |
---|
602 | |
---|
603 | USE transpose_indices, & |
---|
604 | ONLY: nyn_x, nys_x, nzb_x, nzt_x |
---|
605 | |
---|
606 | |
---|
607 | IMPLICIT NONE |
---|
608 | |
---|
609 | INTEGER(iwp) :: i !< |
---|
610 | INTEGER(iwp) :: ishape(1) !< |
---|
611 | INTEGER(iwp) :: j !< |
---|
612 | INTEGER(iwp) :: k !< |
---|
613 | INTEGER(iwp) :: m !< |
---|
614 | INTEGER(iwp) :: n !< |
---|
615 | INTEGER(iwp) :: pr !< |
---|
616 | |
---|
617 | REAL(wp) :: exponent !< |
---|
618 | REAL(wp) :: sum_spec_dum !< wavenumber-integrated spectrum |
---|
619 | |
---|
620 | REAL(wp), DIMENSION(0:nx) :: work !< |
---|
621 | |
---|
622 | REAL(wp), DIMENSION(0:nx/2) :: sums_spectra_l !< |
---|
623 | |
---|
624 | REAL(wp), DIMENSION(0:nx/2,100) :: sums_spectra !< |
---|
625 | |
---|
626 | REAL(wp), DIMENSION(0:nx,nys_x:nyn_x,nzb_x:nzt_x) :: ddd !< |
---|
627 | |
---|
628 | ! |
---|
629 | !-- Exponent for geometric average |
---|
630 | exponent = 1.0_wp / ( ny + 1.0_wp ) |
---|
631 | |
---|
632 | ! |
---|
633 | !-- Loop over all levels defined by the user |
---|
634 | n = 1 |
---|
635 | DO WHILE ( comp_spectra_level(n) /= 999999 .AND. n <= 100 ) |
---|
636 | |
---|
637 | k = comp_spectra_level(n) |
---|
638 | |
---|
639 | ! |
---|
640 | !-- Calculate FFT only if the corresponding level is situated on this PE |
---|
641 | IF ( k >= nzb_x .AND. k <= nzt_x ) THEN |
---|
642 | |
---|
643 | DO j = nys_x, nyn_x |
---|
644 | |
---|
645 | work = ddd(0:nx,j,k) |
---|
646 | CALL fft_x_1d( work, 'forward' ) |
---|
647 | |
---|
648 | ddd(0,j,k) = dx * work(0)**2 |
---|
649 | DO i = 1, nx/2 |
---|
650 | ddd(i,j,k) = dx * ( work(i)**2 + work(nx+1-i)**2 ) |
---|
651 | ENDDO |
---|
652 | |
---|
653 | ENDDO |
---|
654 | |
---|
655 | ! |
---|
656 | !-- Local sum and geometric average of these spectra |
---|
657 | !-- (WARNING: no global sum should be performed, because floating |
---|
658 | !-- point overflow may occur) |
---|
659 | DO i = 0, nx/2 |
---|
660 | |
---|
661 | sums_spectra_l(i) = 1.0_wp |
---|
662 | DO j = nys_x, nyn_x |
---|
663 | sums_spectra_l(i) = sums_spectra_l(i) * ddd(i,j,k)**exponent |
---|
664 | ENDDO |
---|
665 | |
---|
666 | ENDDO |
---|
667 | |
---|
668 | ELSE |
---|
669 | |
---|
670 | sums_spectra_l = 1.0_wp |
---|
671 | |
---|
672 | ENDIF |
---|
673 | |
---|
674 | ! |
---|
675 | !-- Global sum of spectra on PE0 (from where they are written on file) |
---|
676 | sums_spectra(:,n) = 0.0_wp |
---|
677 | #if defined( __parallel ) |
---|
678 | CALL MPI_BARRIER( comm2d, ierr ) ! Necessary? |
---|
679 | CALL MPI_REDUCE( sums_spectra_l(0), sums_spectra(0,n), nx/2+1, & |
---|
680 | MPI_REAL, MPI_PROD, 0, comm2d, ierr ) |
---|
681 | #else |
---|
682 | sums_spectra(:,n) = sums_spectra_l |
---|
683 | #endif |
---|
684 | ! |
---|
685 | !-- Normalize spectra by variance |
---|
686 | sum_spec_dum = SUM( sums_spectra(:,n) ) |
---|
687 | IF ( sum_spec_dum /= 0.0_wp ) THEN |
---|
688 | sums_spectra(:,n) = sums_spectra(:,n) * var_d(k) / sum_spec_dum |
---|
689 | ENDIF |
---|
690 | n = n + 1 |
---|
691 | |
---|
692 | ENDDO |
---|
693 | n = n - 1 |
---|
694 | |
---|
695 | IF ( myid == 0 ) THEN |
---|
696 | ! |
---|
697 | !-- Sum of spectra for later averaging (see routine data_output_spectra) |
---|
698 | DO i = 1, nx/2 |
---|
699 | DO k = 1, n |
---|
700 | spectrum_x(i,k,m) = spectrum_x(i,k,m) + sums_spectra(i,k) |
---|
701 | ENDDO |
---|
702 | ENDDO |
---|
703 | |
---|
704 | ENDIF |
---|
705 | ! |
---|
706 | !-- n_sp_x is needed by data_output_spectra_x |
---|
707 | n_sp_x = n |
---|
708 | |
---|
709 | END SUBROUTINE calc_spectra_x |
---|
710 | |
---|
711 | |
---|
712 | !------------------------------------------------------------------------------! |
---|
713 | ! Description: |
---|
714 | ! ------------ |
---|
715 | !> @todo Missing subroutine description. |
---|
716 | !------------------------------------------------------------------------------! |
---|
717 | SUBROUTINE calc_spectra_y( ddd, pr, m ) |
---|
718 | |
---|
719 | USE control_parameters, & |
---|
720 | ONLY: fft_method |
---|
721 | |
---|
722 | USE fft_xy, & |
---|
723 | ONLY: fft_y_1d |
---|
724 | |
---|
725 | USE grid_variables, & |
---|
726 | ONLY: dy |
---|
727 | |
---|
728 | USE indices, & |
---|
729 | ONLY: nx, ny |
---|
730 | |
---|
731 | USE kinds |
---|
732 | |
---|
733 | #if defined( __parallel ) |
---|
734 | #if defined( __mpifh ) |
---|
735 | INCLUDE "mpif.h" |
---|
736 | #else |
---|
737 | USE MPI |
---|
738 | #endif |
---|
739 | #endif |
---|
740 | USE pegrid, & |
---|
741 | ONLY: comm2d, ierr, myid |
---|
742 | |
---|
743 | USE transpose_indices, & |
---|
744 | ONLY: nxl_yd, nxr_yd, nzb_yd, nzt_yd |
---|
745 | |
---|
746 | |
---|
747 | IMPLICIT NONE |
---|
748 | |
---|
749 | INTEGER(iwp) :: i !< |
---|
750 | INTEGER(iwp) :: j !< |
---|
751 | INTEGER(iwp) :: jshape(1) !< |
---|
752 | INTEGER(iwp) :: k !< |
---|
753 | INTEGER(iwp) :: m !< |
---|
754 | INTEGER(iwp) :: n !< |
---|
755 | INTEGER(iwp) :: pr !< |
---|
756 | |
---|
757 | REAL(wp) :: exponent !< |
---|
758 | REAL(wp) :: sum_spec_dum !< wavenumber-integrated spectrum |
---|
759 | |
---|
760 | REAL(wp), DIMENSION(0:ny) :: work !< |
---|
761 | |
---|
762 | REAL(wp), DIMENSION(0:ny/2) :: sums_spectra_l !< |
---|
763 | |
---|
764 | REAL(wp), DIMENSION(0:ny/2,100) :: sums_spectra !< |
---|
765 | |
---|
766 | REAL(wp), DIMENSION(0:ny,nxl_yd:nxr_yd,nzb_yd:nzt_yd) :: ddd !< |
---|
767 | |
---|
768 | |
---|
769 | ! |
---|
770 | !-- Exponent for geometric average |
---|
771 | exponent = 1.0_wp / ( nx + 1.0_wp ) |
---|
772 | |
---|
773 | ! |
---|
774 | !-- Loop over all levels defined by the user |
---|
775 | n = 1 |
---|
776 | DO WHILE ( comp_spectra_level(n) /= 999999 .AND. n <= 100 ) |
---|
777 | |
---|
778 | k = comp_spectra_level(n) |
---|
779 | |
---|
780 | ! |
---|
781 | !-- Calculate FFT only if the corresponding level is situated on this PE |
---|
782 | IF ( k >= nzb_yd .AND. k <= nzt_yd ) THEN |
---|
783 | |
---|
784 | DO i = nxl_yd, nxr_yd |
---|
785 | |
---|
786 | work = ddd(0:ny,i,k) |
---|
787 | CALL fft_y_1d( work, 'forward' ) |
---|
788 | |
---|
789 | ddd(0,i,k) = dy * work(0)**2 |
---|
790 | DO j = 1, ny/2 |
---|
791 | ddd(j,i,k) = dy * ( work(j)**2 + work(ny+1-j)**2 ) |
---|
792 | ENDDO |
---|
793 | |
---|
794 | ENDDO |
---|
795 | |
---|
796 | ! |
---|
797 | !-- Local sum and geometric average of these spectra |
---|
798 | !-- (WARNING: no global sum should be performed, because floating |
---|
799 | !-- point overflow may occur) |
---|
800 | DO j = 0, ny/2 |
---|
801 | |
---|
802 | sums_spectra_l(j) = 1.0_wp |
---|
803 | DO i = nxl_yd, nxr_yd |
---|
804 | sums_spectra_l(j) = sums_spectra_l(j) * ddd(j,i,k)**exponent |
---|
805 | ENDDO |
---|
806 | |
---|
807 | ENDDO |
---|
808 | |
---|
809 | ELSE |
---|
810 | |
---|
811 | sums_spectra_l = 1.0_wp |
---|
812 | |
---|
813 | ENDIF |
---|
814 | |
---|
815 | ! |
---|
816 | !-- Global sum of spectra on PE0 (from where they are written on file) |
---|
817 | sums_spectra(:,n) = 0.0_wp |
---|
818 | #if defined( __parallel ) |
---|
819 | CALL MPI_BARRIER( comm2d, ierr ) ! Necessary? |
---|
820 | CALL MPI_REDUCE( sums_spectra_l(0), sums_spectra(0,n), ny/2+1, & |
---|
821 | MPI_REAL, MPI_PROD, 0, comm2d, ierr ) |
---|
822 | #else |
---|
823 | sums_spectra(:,n) = sums_spectra_l |
---|
824 | #endif |
---|
825 | ! |
---|
826 | !-- Normalize spectra by variance |
---|
827 | sum_spec_dum = SUM( sums_spectra(:,n) ) |
---|
828 | IF ( SUM(sums_spectra(:,n)) /= 0.0_wp ) THEN |
---|
829 | sums_spectra(:,n) = sums_spectra(:,n) * & |
---|
830 | var_d(k) / SUM(sums_spectra(:,n)) |
---|
831 | ENDIF |
---|
832 | n = n + 1 |
---|
833 | |
---|
834 | ENDDO |
---|
835 | n = n - 1 |
---|
836 | |
---|
837 | |
---|
838 | IF ( myid == 0 ) THEN |
---|
839 | ! |
---|
840 | !-- Sum of spectra for later averaging (see routine data_output_spectra) |
---|
841 | DO j = 1, ny/2 |
---|
842 | DO k = 1, n |
---|
843 | spectrum_y(j,k,m) = spectrum_y(j,k,m) + sums_spectra(j,k) |
---|
844 | ENDDO |
---|
845 | ENDDO |
---|
846 | |
---|
847 | ENDIF |
---|
848 | |
---|
849 | ! |
---|
850 | !-- n_sp_y is needed by data_output_spectra_y |
---|
851 | n_sp_y = n |
---|
852 | |
---|
853 | END SUBROUTINE calc_spectra_y |
---|
854 | |
---|
855 | END MODULE spectra_mod |
---|