source: palm/trunk/SOURCE/data_output_ptseries.f90 @ 1771

Last change on this file since 1771 was 1683, checked in by knoop, 8 years ago

last commit documented

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