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