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