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