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