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