source: palm/tags/release-5.0/SOURCE/data_output_ptseries.f90 @ 3979

Last change on this file since 3979 was 2696, checked in by kanani, 6 years ago

Merge of branch palm4u into trunk

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