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

Last change on this file since 1783 was 1783, checked in by raasch, 8 years ago

NetCDF routines modularized; new parameter netcdf_deflate; further changes in the pmc

  • Property svn:keywords set to Id
File size: 16.7 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! netcdf module name changed + related changes
22!
23! Former revisions:
24! -----------------
25! $Id: data_output_ptseries.f90 1783 2016-03-06 18:36:17Z raasch $
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#if defined( __netcdf )
84    USE NETCDF
85#endif
86
87    USE netcdf_interface,                                                      &
88        ONLY:  dopts_num, id_set_pts, id_var_dopts, id_var_time_pts, nc_stat,  &
89               netcdf_handle_error
90
91    USE particle_attributes,                                                   &
92        ONLY:  grid_particles, number_of_particles, number_of_particle_groups, &
93               particles, prt_count
94
95    USE pegrid
96
97    IMPLICIT NONE
98
99
100    INTEGER(iwp) ::  i    !<
101    INTEGER(iwp) ::  inum !<
102    INTEGER(iwp) ::  j    !<
103    INTEGER(iwp) ::  jg   !<
104    INTEGER(iwp) ::  k    !<
105    INTEGER(iwp) ::  n    !<
106
107    REAL(wp), DIMENSION(:,:), ALLOCATABLE ::  pts_value   !<
108    REAL(wp), DIMENSION(:,:), ALLOCATABLE ::  pts_value_l !<
109
110
111    CALL cpu_log( log_point(36), 'data_output_ptseries', 'start' )
112
113    IF ( myid == 0 )  THEN
114!
115!--    Open file for time series output in NetCDF format
116       dopts_time_count = dopts_time_count + 1
117       CALL check_open( 109 )
118#if defined( __netcdf )
119!
120!--    Update the particle time series time axis
121       nc_stat = NF90_PUT_VAR( id_set_pts, id_var_time_pts,      &
122                               (/ time_since_reference_point /), &
123                               start = (/ dopts_time_count /), count = (/ 1 /) )
124       CALL netcdf_handle_error( 'data_output_ptseries', 391 )
125#endif
126
127    ENDIF
128
129    ALLOCATE( pts_value(0:number_of_particle_groups,dopts_num), &
130              pts_value_l(0:number_of_particle_groups,dopts_num) )
131
132    pts_value_l = 0.0_wp
133    pts_value_l(:,16) = 9999999.9_wp    ! for calculation of minimum radius
134
135!
136!-- Calculate or collect the particle time series quantities for all particles
137!-- and seperately for each particle group (if there is more than one group)
138    DO  i = nxl, nxr
139       DO  j = nys, nyn
140          DO  k = nzb, nzt
141             number_of_particles = prt_count(k,j,i)
142             IF (number_of_particles <= 0)  CYCLE
143             particles => grid_particles(k,j,i)%particles(1:number_of_particles)
144             DO  n = 1, number_of_particles
145
146                IF ( particles(n)%particle_mask )  THEN  ! Restrict analysis to active particles
147
148                   pts_value_l(0,1)  = pts_value_l(0,1) + 1.0_wp  ! total # of particles
149                   pts_value_l(0,2)  = pts_value_l(0,2) +                      &
150                          ( particles(n)%x - particles(n)%origin_x )  ! mean x
151                   pts_value_l(0,3)  = pts_value_l(0,3) +                      &
152                          ( particles(n)%y - particles(n)%origin_y )  ! mean y
153                   pts_value_l(0,4)  = pts_value_l(0,4) +                      &
154                          ( particles(n)%z - particles(n)%origin_z )  ! mean z
155                   pts_value_l(0,5)  = pts_value_l(0,5) + particles(n)%z        ! mean z (absolute)
156                   pts_value_l(0,6)  = pts_value_l(0,6) + particles(n)%speed_x  ! mean u
157                   pts_value_l(0,7)  = pts_value_l(0,7) + particles(n)%speed_y  ! mean v
158                   pts_value_l(0,8)  = pts_value_l(0,8) + particles(n)%speed_z  ! mean w
159                   IF ( .NOT. curvature_solution_effects )  THEN
160                      pts_value_l(0,9)  = pts_value_l(0,9)  + particles(n)%rvar1 ! mean sgsu
161                      pts_value_l(0,10) = pts_value_l(0,10) + particles(n)%rvar2 ! mean sgsv
162                      pts_value_l(0,11) = pts_value_l(0,11) + particles(n)%rvar3 ! mean sgsw
163                   ENDIF
164                   IF ( particles(n)%speed_z > 0.0_wp )  THEN
165                      pts_value_l(0,12) = pts_value_l(0,12) + 1.0_wp  ! # of upward moving prts
166                      pts_value_l(0,13) = pts_value_l(0,13) +                  &
167                                              particles(n)%speed_z ! mean w upw.
168                   ELSE
169                      pts_value_l(0,14) = pts_value_l(0,14) +                  &
170                                              particles(n)%speed_z ! mean w down
171                   ENDIF
172                   pts_value_l(0,15) = pts_value_l(0,15) + particles(n)%radius ! mean rad
173                   pts_value_l(0,16) = MIN( pts_value_l(0,16), particles(n)%radius ) ! minrad
174                   pts_value_l(0,17) = MAX( pts_value_l(0,17), particles(n)%radius ) ! maxrad
175                   pts_value_l(0,18) = pts_value_l(0,18) + 1.0_wp
176                   pts_value_l(0,19) = pts_value_l(0,18) + 1.0_wp
177!
178!--                Repeat the same for the respective particle group
179                   IF ( number_of_particle_groups > 1 )  THEN
180                      jg = particles(n)%group
181
182                      pts_value_l(jg,1)  = pts_value_l(jg,1) + 1.0_wp
183                      pts_value_l(jg,2)  = pts_value_l(jg,2) +                   &
184                           ( particles(n)%x - particles(n)%origin_x )
185                      pts_value_l(jg,3)  = pts_value_l(jg,3) +                   &
186                           ( particles(n)%y - particles(n)%origin_y )
187                      pts_value_l(jg,4)  = pts_value_l(jg,4) +                   &
188                           ( particles(n)%z - particles(n)%origin_z )
189                      pts_value_l(jg,5)  = pts_value_l(jg,5) + particles(n)%z
190                      pts_value_l(jg,6)  = pts_value_l(jg,6) + particles(n)%speed_x
191                      pts_value_l(jg,7)  = pts_value_l(jg,7) + particles(n)%speed_y
192                      pts_value_l(jg,8)  = pts_value_l(jg,8) + particles(n)%speed_z
193                      IF ( .NOT. curvature_solution_effects )  THEN
194                         pts_value_l(jg,9)  = pts_value_l(jg,9)  + particles(n)%rvar1
195                         pts_value_l(jg,10) = pts_value_l(jg,10) + particles(n)%rvar2
196                         pts_value_l(jg,11) = pts_value_l(jg,11) + particles(n)%rvar3
197                      ENDIF
198                      IF ( particles(n)%speed_z > 0.0_wp )  THEN
199                         pts_value_l(jg,12) = pts_value_l(jg,12) + 1.0_wp
200                         pts_value_l(jg,13) = pts_value_l(jg,13) + particles(n)%speed_z
201                      ELSE
202                         pts_value_l(jg,14) = pts_value_l(jg,14) + particles(n)%speed_z
203                      ENDIF
204                      pts_value_l(jg,15) = pts_value_l(jg,15) + particles(n)%radius
205                      pts_value_l(jg,16) = MIN( pts_value(jg,16), particles(n)%radius )
206                      pts_value_l(jg,17) = MAX( pts_value(jg,17), particles(n)%radius )
207                      pts_value_l(jg,18) = pts_value_l(jg,18) + 1.0_wp
208                      pts_value_l(jg,19) = pts_value_l(jg,19) + 1.0_wp
209                   ENDIF
210
211                ENDIF
212
213             ENDDO
214
215          ENDDO
216       ENDDO
217    ENDDO
218
219
220#if defined( __parallel )
221!
222!-- Sum values of the subdomains
223    inum = number_of_particle_groups + 1
224
225    IF ( collective_wait )  CALL MPI_BARRIER( comm2d, ierr )
226    CALL MPI_ALLREDUCE( pts_value_l(0,1), pts_value(0,1), 15*inum, MPI_REAL, &
227                        MPI_SUM, comm2d, ierr )
228    IF ( collective_wait )  CALL MPI_BARRIER( comm2d, ierr )
229    CALL MPI_ALLREDUCE( pts_value_l(0,16), pts_value(0,16), inum, MPI_REAL, &
230                        MPI_MIN, comm2d, ierr )
231    IF ( collective_wait )  CALL MPI_BARRIER( comm2d, ierr )
232    CALL MPI_ALLREDUCE( pts_value_l(0,17), pts_value(0,17), inum, MPI_REAL, &
233                        MPI_MAX, comm2d, ierr )
234    IF ( collective_wait )  CALL MPI_BARRIER( comm2d, ierr )
235    CALL MPI_ALLREDUCE( pts_value_l(0,18), pts_value(0,18), inum, MPI_REAL, &
236                        MPI_MAX, comm2d, ierr )
237    IF ( collective_wait )  CALL MPI_BARRIER( comm2d, ierr )
238    CALL MPI_ALLREDUCE( pts_value_l(0,19), pts_value(0,19), inum, MPI_REAL, &
239                        MPI_MIN, comm2d, ierr )
240#else
241    pts_value(:,1:19) = pts_value_l(:,1:19)
242#endif
243
244!
245!-- Normalize the above calculated quantities (except min/max values) with the
246!-- total number of particles
247    IF ( number_of_particle_groups > 1 )  THEN
248       inum = number_of_particle_groups
249    ELSE
250       inum = 0
251    ENDIF
252
253    DO  j = 0, inum
254
255       IF ( pts_value(j,1) > 0.0_wp )  THEN
256
257          pts_value(j,2:15) = pts_value(j,2:15) / pts_value(j,1)
258          IF ( pts_value(j,12) > 0.0_wp  .AND.  pts_value(j,12) < 1.0_wp )  THEN
259             pts_value(j,13) = pts_value(j,13) / pts_value(j,12)
260             pts_value(j,14) = pts_value(j,14) / ( 1.0_wp - pts_value(j,12) )
261          ELSEIF ( pts_value(j,12) == 0.0_wp )  THEN
262             pts_value(j,13) = -1.0_wp
263          ELSE
264             pts_value(j,14) = -1.0_wp
265          ENDIF
266
267       ENDIF
268
269    ENDDO
270
271!
272!-- Calculate higher order moments of particle time series quantities,
273!-- seperately for each particle group (if there is more than one group)
274    DO  i = nxl, nxr
275       DO  j = nys, nyn
276          DO  k = nzb, nzt
277             number_of_particles = prt_count(k,j,i)
278             IF (number_of_particles <= 0)  CYCLE
279             particles => grid_particles(k,j,i)%particles(1:number_of_particles)
280             DO  n = 1, number_of_particles
281
282                pts_value_l(0,20) = pts_value_l(0,20) + ( particles(n)%x - &
283                                    particles(n)%origin_x - pts_value(0,2) )**2 ! x*2
284                pts_value_l(0,21) = pts_value_l(0,21) + ( particles(n)%y - &
285                                    particles(n)%origin_y - pts_value(0,3) )**2 ! y*2
286                pts_value_l(0,22) = pts_value_l(0,22) + ( particles(n)%z - &
287                                    particles(n)%origin_z - pts_value(0,4) )**2 ! z*2
288                pts_value_l(0,23) = pts_value_l(0,23) + ( particles(n)%speed_x - &
289                                                         pts_value(0,6) )**2   ! u*2
290                pts_value_l(0,24) = pts_value_l(0,24) + ( particles(n)%speed_y - &
291                                                          pts_value(0,7) )**2   ! v*2
292                pts_value_l(0,25) = pts_value_l(0,25) + ( particles(n)%speed_z - &
293                                                          pts_value(0,8) )**2   ! w*2
294                IF ( .NOT. curvature_solution_effects )  THEN
295                   pts_value_l(0,26) = pts_value_l(0,26) + ( particles(n)%rvar1 - &
296                                                             pts_value(0,9) )**2   ! u"2
297                   pts_value_l(0,27) = pts_value_l(0,27) + ( particles(n)%rvar2 - &
298                                                             pts_value(0,10) )**2  ! v"2
299                   pts_value_l(0,28) = pts_value_l(0,28) + ( particles(n)%rvar3 - &
300                                                             pts_value(0,11) )**2  ! w"2
301                ENDIF
302!
303!--             Repeat the same for the respective particle group
304                IF ( number_of_particle_groups > 1 )  THEN
305                   jg = particles(n)%group
306
307                   pts_value_l(jg,20) = pts_value_l(jg,20) + ( particles(n)%x - &
308                                       particles(n)%origin_x - pts_value(jg,2) )**2
309                   pts_value_l(jg,21) = pts_value_l(jg,21) + ( particles(n)%y - &
310                                       particles(n)%origin_y - pts_value(jg,3) )**2
311                   pts_value_l(jg,22) = pts_value_l(jg,22) + ( particles(n)%z - &
312                                       particles(n)%origin_z - pts_value(jg,4) )**2
313                   pts_value_l(jg,23) = pts_value_l(jg,23) + ( particles(n)%speed_x - &
314                                                             pts_value(jg,6) )**2
315                   pts_value_l(jg,24) = pts_value_l(jg,24) + ( particles(n)%speed_y - &
316                                                             pts_value(jg,7) )**2
317                   pts_value_l(jg,25) = pts_value_l(jg,25) + ( particles(n)%speed_z - &
318                                                             pts_value(jg,8) )**2
319                   IF ( .NOT. curvature_solution_effects )  THEN
320                      pts_value_l(jg,26) = pts_value_l(jg,26) + ( particles(n)%rvar1 - &
321                                                                pts_value(jg,9) )**2
322                      pts_value_l(jg,27) = pts_value_l(jg,27) + ( particles(n)%rvar2 - &
323                                                                pts_value(jg,10) )**2
324                      pts_value_l(jg,28) = pts_value_l(jg,28) + ( particles(n)%rvar3 - &
325                                                                pts_value(jg,11) )**2
326                   ENDIF
327                ENDIF
328
329             ENDDO
330          ENDDO
331       ENDDO
332    ENDDO
333
334    pts_value_l(0,29) = ( number_of_particles - pts_value(0,1) / numprocs )**2
335                                                 ! variance of particle numbers
336    IF ( number_of_particle_groups > 1 )  THEN
337       DO  j = 1, number_of_particle_groups
338          pts_value_l(j,29) = ( pts_value_l(j,1) - &
339                                pts_value(j,1) / numprocs )**2
340       ENDDO
341    ENDIF
342
343#if defined( __parallel )
344!
345!-- Sum values of the subdomains
346    inum = number_of_particle_groups + 1
347
348    IF ( collective_wait )  CALL MPI_BARRIER( comm2d, ierr )
349    CALL MPI_ALLREDUCE( pts_value_l(0,20), pts_value(0,20), inum*10, MPI_REAL, &
350                        MPI_SUM, comm2d, ierr )
351#else
352    pts_value(:,20:29) = pts_value_l(:,20:29)
353#endif
354
355!
356!-- Normalize the above calculated quantities with the total number of
357!-- particles
358    IF ( number_of_particle_groups > 1 )  THEN
359       inum = number_of_particle_groups
360    ELSE
361       inum = 0
362    ENDIF
363
364    DO  j = 0, inum
365
366       IF ( pts_value(j,1) > 0.0_wp )  THEN
367          pts_value(j,20:28) = pts_value(j,20:28) / pts_value(j,1)
368       ENDIF
369       pts_value(j,29) = pts_value(j,29) / numprocs
370
371    ENDDO
372
373#if defined( __netcdf )
374!
375!-- Output particle time series quantities in NetCDF format
376    IF ( myid == 0 )  THEN
377       DO  j = 0, inum
378          DO  i = 1, dopts_num
379             nc_stat = NF90_PUT_VAR( id_set_pts, id_var_dopts(i,j),  &
380                                     (/ pts_value(j,i) /),           &
381                                     start = (/ dopts_time_count /), &
382                                     count = (/ 1 /) )
383             CALL netcdf_handle_error( 'data_output_ptseries', 392 )
384          ENDDO
385       ENDDO
386    ENDIF
387#endif
388
389    DEALLOCATE( pts_value, pts_value_l )
390
391    CALL cpu_log( log_point(36), 'data_output_ptseries', 'stop' )
392
393 END SUBROUTINE data_output_ptseries
Note: See TracBrowser for help on using the repository browser.