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

Last change on this file since 1342 was 1329, checked in by raasch, 10 years ago

last commit documented

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