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