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