1 | !> @file data_output_ptseries.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: data_output_ptseries.f90 2718 2018-01-02 08:49:38Z raasch $ |
---|
27 | ! Corrected "Former revisions" section |
---|
28 | ! |
---|
29 | ! 2696 2017-12-14 17:12:51Z kanani |
---|
30 | ! Change in file header (GPL part) |
---|
31 | ! |
---|
32 | ! 2312 2017-07-14 20:26:51Z hoffmann |
---|
33 | ! SGS velocities also possible for curvature_solution_effects = .TRUE. |
---|
34 | ! |
---|
35 | ! 2000 2016-08-20 18:09:15Z knoop |
---|
36 | ! Forced header and separation lines into 80 columns |
---|
37 | ! |
---|
38 | ! 1831 2016-04-07 13:15:51Z hoffmann |
---|
39 | ! curvature_solution_effects moved to particle_attributes |
---|
40 | ! |
---|
41 | ! 1783 2016-03-06 18:36:17Z raasch |
---|
42 | ! netcdf module name changed + related changes |
---|
43 | ! |
---|
44 | ! 1682 2015-10-07 23:56:08Z knoop |
---|
45 | ! Code annotations made doxygen readable |
---|
46 | ! |
---|
47 | ! 1359 2014-04-11 17:15:14Z hoffmann |
---|
48 | ! New particle structure integrated. |
---|
49 | ! |
---|
50 | ! 1353 2014-04-08 15:21:23Z heinze |
---|
51 | ! REAL constants provided with KIND-attribute |
---|
52 | ! |
---|
53 | ! 1327 2014-03-21 11:00:16Z raasch |
---|
54 | ! -netcdf output queries |
---|
55 | ! |
---|
56 | ! 1320 2014-03-20 08:40:49Z raasch |
---|
57 | ! ONLY-attribute added to USE-statements, |
---|
58 | ! kind-parameters added to all INTEGER and REAL declaration statements, |
---|
59 | ! kinds are defined in new module kinds, |
---|
60 | ! revision history before 2012 removed, |
---|
61 | ! comment fields (!:) to be used for variable explanations added to |
---|
62 | ! all variable declaration statements |
---|
63 | ! |
---|
64 | ! 1318 2014-03-17 13:35:16Z raasch |
---|
65 | ! barrier argument removed from cpu_log, |
---|
66 | ! module interfaces removed |
---|
67 | ! |
---|
68 | ! 1036 2012-10-22 13:43:42Z raasch |
---|
69 | ! code put under GPL (PALM 3.9) |
---|
70 | ! |
---|
71 | ! 825 2012-02-19 03:03:44Z raasch |
---|
72 | ! mean/minimum/maximum particle radius added as output quantity, |
---|
73 | ! particle attributes speed_x|y|z_sgs renamed rvar1|2|3 |
---|
74 | ! |
---|
75 | ! Revision 1.1 2006/08/04 14:24:18 raasch |
---|
76 | ! Initial revision |
---|
77 | ! |
---|
78 | ! |
---|
79 | ! Description: |
---|
80 | ! ------------ |
---|
81 | !> Output of particle data timeseries in NetCDF format. |
---|
82 | !------------------------------------------------------------------------------! |
---|
83 | SUBROUTINE data_output_ptseries |
---|
84 | |
---|
85 | |
---|
86 | USE control_parameters, & |
---|
87 | ONLY: dopts_time_count, time_since_reference_point |
---|
88 | |
---|
89 | USE cpulog, & |
---|
90 | ONLY: cpu_log, log_point |
---|
91 | |
---|
92 | USE indices, & |
---|
93 | ONLY: nxl, nxr, nys, nyn, nzb, nzt |
---|
94 | |
---|
95 | USE kinds |
---|
96 | |
---|
97 | #if defined( __netcdf ) |
---|
98 | USE NETCDF |
---|
99 | #endif |
---|
100 | |
---|
101 | USE netcdf_interface, & |
---|
102 | ONLY: dopts_num, id_set_pts, id_var_dopts, id_var_time_pts, nc_stat, & |
---|
103 | netcdf_handle_error |
---|
104 | |
---|
105 | USE particle_attributes, & |
---|
106 | ONLY: grid_particles, number_of_particles, number_of_particle_groups, & |
---|
107 | particles, prt_count |
---|
108 | |
---|
109 | USE pegrid |
---|
110 | |
---|
111 | IMPLICIT NONE |
---|
112 | |
---|
113 | |
---|
114 | INTEGER(iwp) :: i !< |
---|
115 | INTEGER(iwp) :: inum !< |
---|
116 | INTEGER(iwp) :: j !< |
---|
117 | INTEGER(iwp) :: jg !< |
---|
118 | INTEGER(iwp) :: k !< |
---|
119 | INTEGER(iwp) :: n !< |
---|
120 | |
---|
121 | REAL(wp), DIMENSION(:,:), ALLOCATABLE :: pts_value !< |
---|
122 | REAL(wp), DIMENSION(:,:), ALLOCATABLE :: pts_value_l !< |
---|
123 | |
---|
124 | |
---|
125 | CALL cpu_log( log_point(36), 'data_output_ptseries', 'start' ) |
---|
126 | |
---|
127 | IF ( myid == 0 ) THEN |
---|
128 | ! |
---|
129 | !-- Open file for time series output in NetCDF format |
---|
130 | dopts_time_count = dopts_time_count + 1 |
---|
131 | CALL check_open( 109 ) |
---|
132 | #if defined( __netcdf ) |
---|
133 | ! |
---|
134 | !-- Update the particle time series time axis |
---|
135 | nc_stat = NF90_PUT_VAR( id_set_pts, id_var_time_pts, & |
---|
136 | (/ time_since_reference_point /), & |
---|
137 | start = (/ dopts_time_count /), count = (/ 1 /) ) |
---|
138 | CALL netcdf_handle_error( 'data_output_ptseries', 391 ) |
---|
139 | #endif |
---|
140 | |
---|
141 | ENDIF |
---|
142 | |
---|
143 | ALLOCATE( pts_value(0:number_of_particle_groups,dopts_num), & |
---|
144 | pts_value_l(0:number_of_particle_groups,dopts_num) ) |
---|
145 | |
---|
146 | pts_value_l = 0.0_wp |
---|
147 | pts_value_l(:,16) = 9999999.9_wp ! for calculation of minimum radius |
---|
148 | |
---|
149 | ! |
---|
150 | !-- Calculate or collect the particle time series quantities for all particles |
---|
151 | !-- and seperately for each particle group (if there is more than one group) |
---|
152 | DO i = nxl, nxr |
---|
153 | DO j = nys, nyn |
---|
154 | DO k = nzb, nzt |
---|
155 | number_of_particles = prt_count(k,j,i) |
---|
156 | IF (number_of_particles <= 0) CYCLE |
---|
157 | particles => grid_particles(k,j,i)%particles(1:number_of_particles) |
---|
158 | DO n = 1, number_of_particles |
---|
159 | |
---|
160 | IF ( particles(n)%particle_mask ) THEN ! Restrict analysis to active particles |
---|
161 | |
---|
162 | pts_value_l(0,1) = pts_value_l(0,1) + 1.0_wp ! total # of particles |
---|
163 | pts_value_l(0,2) = pts_value_l(0,2) + & |
---|
164 | ( particles(n)%x - particles(n)%origin_x ) ! mean x |
---|
165 | pts_value_l(0,3) = pts_value_l(0,3) + & |
---|
166 | ( particles(n)%y - particles(n)%origin_y ) ! mean y |
---|
167 | pts_value_l(0,4) = pts_value_l(0,4) + & |
---|
168 | ( particles(n)%z - particles(n)%origin_z ) ! mean z |
---|
169 | pts_value_l(0,5) = pts_value_l(0,5) + particles(n)%z ! mean z (absolute) |
---|
170 | pts_value_l(0,6) = pts_value_l(0,6) + particles(n)%speed_x ! mean u |
---|
171 | pts_value_l(0,7) = pts_value_l(0,7) + particles(n)%speed_y ! mean v |
---|
172 | pts_value_l(0,8) = pts_value_l(0,8) + particles(n)%speed_z ! mean w |
---|
173 | pts_value_l(0,9) = pts_value_l(0,9) + particles(n)%rvar1 ! mean sgsu |
---|
174 | pts_value_l(0,10) = pts_value_l(0,10) + particles(n)%rvar2 ! mean sgsv |
---|
175 | pts_value_l(0,11) = pts_value_l(0,11) + particles(n)%rvar3 ! mean sgsw |
---|
176 | IF ( particles(n)%speed_z > 0.0_wp ) THEN |
---|
177 | pts_value_l(0,12) = pts_value_l(0,12) + 1.0_wp ! # of upward moving prts |
---|
178 | pts_value_l(0,13) = pts_value_l(0,13) + & |
---|
179 | particles(n)%speed_z ! mean w upw. |
---|
180 | ELSE |
---|
181 | pts_value_l(0,14) = pts_value_l(0,14) + & |
---|
182 | particles(n)%speed_z ! mean w down |
---|
183 | ENDIF |
---|
184 | pts_value_l(0,15) = pts_value_l(0,15) + particles(n)%radius ! mean rad |
---|
185 | pts_value_l(0,16) = MIN( pts_value_l(0,16), particles(n)%radius ) ! minrad |
---|
186 | pts_value_l(0,17) = MAX( pts_value_l(0,17), particles(n)%radius ) ! maxrad |
---|
187 | pts_value_l(0,18) = pts_value_l(0,18) + 1.0_wp |
---|
188 | pts_value_l(0,19) = pts_value_l(0,18) + 1.0_wp |
---|
189 | ! |
---|
190 | !-- Repeat the same for the respective particle group |
---|
191 | IF ( number_of_particle_groups > 1 ) THEN |
---|
192 | jg = particles(n)%group |
---|
193 | |
---|
194 | pts_value_l(jg,1) = pts_value_l(jg,1) + 1.0_wp |
---|
195 | pts_value_l(jg,2) = pts_value_l(jg,2) + & |
---|
196 | ( particles(n)%x - particles(n)%origin_x ) |
---|
197 | pts_value_l(jg,3) = pts_value_l(jg,3) + & |
---|
198 | ( particles(n)%y - particles(n)%origin_y ) |
---|
199 | pts_value_l(jg,4) = pts_value_l(jg,4) + & |
---|
200 | ( particles(n)%z - particles(n)%origin_z ) |
---|
201 | pts_value_l(jg,5) = pts_value_l(jg,5) + particles(n)%z |
---|
202 | pts_value_l(jg,6) = pts_value_l(jg,6) + particles(n)%speed_x |
---|
203 | pts_value_l(jg,7) = pts_value_l(jg,7) + particles(n)%speed_y |
---|
204 | pts_value_l(jg,8) = pts_value_l(jg,8) + particles(n)%speed_z |
---|
205 | pts_value_l(jg,9) = pts_value_l(jg,9) + particles(n)%rvar1 |
---|
206 | pts_value_l(jg,10) = pts_value_l(jg,10) + particles(n)%rvar2 |
---|
207 | pts_value_l(jg,11) = pts_value_l(jg,11) + particles(n)%rvar3 |
---|
208 | IF ( particles(n)%speed_z > 0.0_wp ) THEN |
---|
209 | pts_value_l(jg,12) = pts_value_l(jg,12) + 1.0_wp |
---|
210 | pts_value_l(jg,13) = pts_value_l(jg,13) + particles(n)%speed_z |
---|
211 | ELSE |
---|
212 | pts_value_l(jg,14) = pts_value_l(jg,14) + particles(n)%speed_z |
---|
213 | ENDIF |
---|
214 | pts_value_l(jg,15) = pts_value_l(jg,15) + particles(n)%radius |
---|
215 | pts_value_l(jg,16) = MIN( pts_value(jg,16), particles(n)%radius ) |
---|
216 | pts_value_l(jg,17) = MAX( pts_value(jg,17), particles(n)%radius ) |
---|
217 | pts_value_l(jg,18) = pts_value_l(jg,18) + 1.0_wp |
---|
218 | pts_value_l(jg,19) = pts_value_l(jg,19) + 1.0_wp |
---|
219 | ENDIF |
---|
220 | |
---|
221 | ENDIF |
---|
222 | |
---|
223 | ENDDO |
---|
224 | |
---|
225 | ENDDO |
---|
226 | ENDDO |
---|
227 | ENDDO |
---|
228 | |
---|
229 | |
---|
230 | #if defined( __parallel ) |
---|
231 | ! |
---|
232 | !-- Sum values of the subdomains |
---|
233 | inum = number_of_particle_groups + 1 |
---|
234 | |
---|
235 | IF ( collective_wait ) CALL MPI_BARRIER( comm2d, ierr ) |
---|
236 | CALL MPI_ALLREDUCE( pts_value_l(0,1), pts_value(0,1), 15*inum, MPI_REAL, & |
---|
237 | MPI_SUM, comm2d, ierr ) |
---|
238 | IF ( collective_wait ) CALL MPI_BARRIER( comm2d, ierr ) |
---|
239 | CALL MPI_ALLREDUCE( pts_value_l(0,16), pts_value(0,16), inum, MPI_REAL, & |
---|
240 | MPI_MIN, comm2d, ierr ) |
---|
241 | IF ( collective_wait ) CALL MPI_BARRIER( comm2d, ierr ) |
---|
242 | CALL MPI_ALLREDUCE( pts_value_l(0,17), pts_value(0,17), inum, MPI_REAL, & |
---|
243 | MPI_MAX, comm2d, ierr ) |
---|
244 | IF ( collective_wait ) CALL MPI_BARRIER( comm2d, ierr ) |
---|
245 | CALL MPI_ALLREDUCE( pts_value_l(0,18), pts_value(0,18), inum, MPI_REAL, & |
---|
246 | MPI_MAX, comm2d, ierr ) |
---|
247 | IF ( collective_wait ) CALL MPI_BARRIER( comm2d, ierr ) |
---|
248 | CALL MPI_ALLREDUCE( pts_value_l(0,19), pts_value(0,19), inum, MPI_REAL, & |
---|
249 | MPI_MIN, comm2d, ierr ) |
---|
250 | #else |
---|
251 | pts_value(:,1:19) = pts_value_l(:,1:19) |
---|
252 | #endif |
---|
253 | |
---|
254 | ! |
---|
255 | !-- Normalize the above calculated quantities (except min/max values) with the |
---|
256 | !-- total number of particles |
---|
257 | IF ( number_of_particle_groups > 1 ) THEN |
---|
258 | inum = number_of_particle_groups |
---|
259 | ELSE |
---|
260 | inum = 0 |
---|
261 | ENDIF |
---|
262 | |
---|
263 | DO j = 0, inum |
---|
264 | |
---|
265 | IF ( pts_value(j,1) > 0.0_wp ) THEN |
---|
266 | |
---|
267 | pts_value(j,2:15) = pts_value(j,2:15) / pts_value(j,1) |
---|
268 | IF ( pts_value(j,12) > 0.0_wp .AND. pts_value(j,12) < 1.0_wp ) THEN |
---|
269 | pts_value(j,13) = pts_value(j,13) / pts_value(j,12) |
---|
270 | pts_value(j,14) = pts_value(j,14) / ( 1.0_wp - pts_value(j,12) ) |
---|
271 | ELSEIF ( pts_value(j,12) == 0.0_wp ) THEN |
---|
272 | pts_value(j,13) = -1.0_wp |
---|
273 | ELSE |
---|
274 | pts_value(j,14) = -1.0_wp |
---|
275 | ENDIF |
---|
276 | |
---|
277 | ENDIF |
---|
278 | |
---|
279 | ENDDO |
---|
280 | |
---|
281 | ! |
---|
282 | !-- Calculate higher order moments of particle time series quantities, |
---|
283 | !-- seperately for each particle group (if there is more than one group) |
---|
284 | DO i = nxl, nxr |
---|
285 | DO j = nys, nyn |
---|
286 | DO k = nzb, nzt |
---|
287 | number_of_particles = prt_count(k,j,i) |
---|
288 | IF (number_of_particles <= 0) CYCLE |
---|
289 | particles => grid_particles(k,j,i)%particles(1:number_of_particles) |
---|
290 | DO n = 1, number_of_particles |
---|
291 | |
---|
292 | pts_value_l(0,20) = pts_value_l(0,20) + ( particles(n)%x - & |
---|
293 | particles(n)%origin_x - pts_value(0,2) )**2 ! x*2 |
---|
294 | pts_value_l(0,21) = pts_value_l(0,21) + ( particles(n)%y - & |
---|
295 | particles(n)%origin_y - pts_value(0,3) )**2 ! y*2 |
---|
296 | pts_value_l(0,22) = pts_value_l(0,22) + ( particles(n)%z - & |
---|
297 | particles(n)%origin_z - pts_value(0,4) )**2 ! z*2 |
---|
298 | pts_value_l(0,23) = pts_value_l(0,23) + ( particles(n)%speed_x - & |
---|
299 | pts_value(0,6) )**2 ! u*2 |
---|
300 | pts_value_l(0,24) = pts_value_l(0,24) + ( particles(n)%speed_y - & |
---|
301 | pts_value(0,7) )**2 ! v*2 |
---|
302 | pts_value_l(0,25) = pts_value_l(0,25) + ( particles(n)%speed_z - & |
---|
303 | pts_value(0,8) )**2 ! w*2 |
---|
304 | pts_value_l(0,26) = pts_value_l(0,26) + ( particles(n)%rvar1 - & |
---|
305 | pts_value(0,9) )**2 ! u"2 |
---|
306 | pts_value_l(0,27) = pts_value_l(0,27) + ( particles(n)%rvar2 - & |
---|
307 | pts_value(0,10) )**2 ! v"2 |
---|
308 | pts_value_l(0,28) = pts_value_l(0,28) + ( particles(n)%rvar3 - & |
---|
309 | pts_value(0,11) )**2 ! w"2 |
---|
310 | ! |
---|
311 | !-- Repeat the same for the respective particle group |
---|
312 | IF ( number_of_particle_groups > 1 ) THEN |
---|
313 | jg = particles(n)%group |
---|
314 | |
---|
315 | pts_value_l(jg,20) = pts_value_l(jg,20) + ( particles(n)%x - & |
---|
316 | particles(n)%origin_x - pts_value(jg,2) )**2 |
---|
317 | pts_value_l(jg,21) = pts_value_l(jg,21) + ( particles(n)%y - & |
---|
318 | particles(n)%origin_y - pts_value(jg,3) )**2 |
---|
319 | pts_value_l(jg,22) = pts_value_l(jg,22) + ( particles(n)%z - & |
---|
320 | particles(n)%origin_z - pts_value(jg,4) )**2 |
---|
321 | pts_value_l(jg,23) = pts_value_l(jg,23) + ( particles(n)%speed_x - & |
---|
322 | pts_value(jg,6) )**2 |
---|
323 | pts_value_l(jg,24) = pts_value_l(jg,24) + ( particles(n)%speed_y - & |
---|
324 | pts_value(jg,7) )**2 |
---|
325 | pts_value_l(jg,25) = pts_value_l(jg,25) + ( particles(n)%speed_z - & |
---|
326 | pts_value(jg,8) )**2 |
---|
327 | pts_value_l(jg,26) = pts_value_l(jg,26) + ( particles(n)%rvar1 - & |
---|
328 | pts_value(jg,9) )**2 |
---|
329 | pts_value_l(jg,27) = pts_value_l(jg,27) + ( particles(n)%rvar2 - & |
---|
330 | pts_value(jg,10) )**2 |
---|
331 | pts_value_l(jg,28) = pts_value_l(jg,28) + ( particles(n)%rvar3 - & |
---|
332 | pts_value(jg,11) )**2 |
---|
333 | ENDIF |
---|
334 | |
---|
335 | ENDDO |
---|
336 | ENDDO |
---|
337 | ENDDO |
---|
338 | ENDDO |
---|
339 | |
---|
340 | pts_value_l(0,29) = ( number_of_particles - pts_value(0,1) / numprocs )**2 |
---|
341 | ! variance of particle numbers |
---|
342 | IF ( number_of_particle_groups > 1 ) THEN |
---|
343 | DO j = 1, number_of_particle_groups |
---|
344 | pts_value_l(j,29) = ( pts_value_l(j,1) - & |
---|
345 | pts_value(j,1) / numprocs )**2 |
---|
346 | ENDDO |
---|
347 | ENDIF |
---|
348 | |
---|
349 | #if defined( __parallel ) |
---|
350 | ! |
---|
351 | !-- Sum values of the subdomains |
---|
352 | inum = number_of_particle_groups + 1 |
---|
353 | |
---|
354 | IF ( collective_wait ) CALL MPI_BARRIER( comm2d, ierr ) |
---|
355 | CALL MPI_ALLREDUCE( pts_value_l(0,20), pts_value(0,20), inum*10, MPI_REAL, & |
---|
356 | MPI_SUM, comm2d, ierr ) |
---|
357 | #else |
---|
358 | pts_value(:,20:29) = pts_value_l(:,20:29) |
---|
359 | #endif |
---|
360 | |
---|
361 | ! |
---|
362 | !-- Normalize the above calculated quantities with the total number of |
---|
363 | !-- particles |
---|
364 | IF ( number_of_particle_groups > 1 ) THEN |
---|
365 | inum = number_of_particle_groups |
---|
366 | ELSE |
---|
367 | inum = 0 |
---|
368 | ENDIF |
---|
369 | |
---|
370 | DO j = 0, inum |
---|
371 | |
---|
372 | IF ( pts_value(j,1) > 0.0_wp ) THEN |
---|
373 | pts_value(j,20:28) = pts_value(j,20:28) / pts_value(j,1) |
---|
374 | ENDIF |
---|
375 | pts_value(j,29) = pts_value(j,29) / numprocs |
---|
376 | |
---|
377 | ENDDO |
---|
378 | |
---|
379 | #if defined( __netcdf ) |
---|
380 | ! |
---|
381 | !-- Output particle time series quantities in NetCDF format |
---|
382 | IF ( myid == 0 ) THEN |
---|
383 | DO j = 0, inum |
---|
384 | DO i = 1, dopts_num |
---|
385 | nc_stat = NF90_PUT_VAR( id_set_pts, id_var_dopts(i,j), & |
---|
386 | (/ pts_value(j,i) /), & |
---|
387 | start = (/ dopts_time_count /), & |
---|
388 | count = (/ 1 /) ) |
---|
389 | CALL netcdf_handle_error( 'data_output_ptseries', 392 ) |
---|
390 | ENDDO |
---|
391 | ENDDO |
---|
392 | ENDIF |
---|
393 | #endif |
---|
394 | |
---|
395 | DEALLOCATE( pts_value, pts_value_l ) |
---|
396 | |
---|
397 | CALL cpu_log( log_point(36), 'data_output_ptseries', 'stop' ) |
---|
398 | |
---|
399 | END SUBROUTINE data_output_ptseries |
---|