SUBROUTINE data_output_ptseries !--------------------------------------------------------------------------------! ! This file is part of PALM. ! ! PALM is free software: you can redistribute it and/or modify it under the terms ! of the GNU General Public License as published by the Free Software Foundation, ! either version 3 of the License, or (at your option) any later version. ! ! PALM is distributed in the hope that it will be useful, but WITHOUT ANY ! WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR ! A PARTICULAR PURPOSE. See the GNU General Public License for more details. ! ! You should have received a copy of the GNU General Public License along with ! PALM. If not, see . ! ! Copyright 1997-2012 Leibniz University Hannover !--------------------------------------------------------------------------------! ! ! Current revisions: ! ----------------- ! ! ! Former revisions: ! ----------------- ! $Id: data_output_ptseries.f90 1037 2012-10-22 14:10:22Z fricke $ ! ! 1036 2012-10-22 13:43:42Z raasch ! code put under GPL (PALM 3.9) ! ! 825 2012-02-19 03:03:44Z raasch ! mean/minimum/maximum particle radius added as output quantity, ! particle attributes speed_x|y|z_sgs renamed rvar1|2|3 ! ! 622 2010-12-10 08:08:13Z raasch ! optional barriers included in order to speed up collective operations ! ! 291 2009-04-16 12:07:26Z raasch ! simulated_time in NetCDF output replaced by time_since_reference_point. ! Output of NetCDF messages with aid of message handling routine. ! ! 60 2007-03-11 11:50:04Z raasch ! Particles-package is now part of the default code. ! ! RCS Log replace by Id keyword, revision history cleaned up ! ! Revision 1.2 2006/08/22 13:51:13 raasch ! Seperate output for particle groups ! ! Revision 1.1 2006/08/04 14:24:18 raasch ! Initial revision ! ! ! Description: ! ------------ ! Output of particle data timeseries in NetCDF format. !------------------------------------------------------------------------------! USE cloud_parameters USE control_parameters USE cpulog USE indices USE interfaces USE netcdf_control USE particle_attributes USE pegrid IMPLICIT NONE INTEGER :: i, inum, j, n REAL, DIMENSION(:,:), ALLOCATABLE :: pts_value, pts_value_l CALL cpu_log( log_point(36), 'data_output_ptseries', 'start' ) IF ( myid == 0 .AND. netcdf_output ) THEN ! !-- Open file for time series output in NetCDF format dopts_time_count = dopts_time_count + 1 CALL check_open( 109 ) #if defined( __netcdf ) ! !-- Update the particle time series time axis nc_stat = NF90_PUT_VAR( id_set_pts, id_var_time_pts, & (/ time_since_reference_point /), & start = (/ dopts_time_count /), count = (/ 1 /) ) CALL handle_netcdf_error( 'data_output_ptseries', 391 ) #endif ENDIF ALLOCATE( pts_value(0:number_of_particle_groups,dopts_num), & pts_value_l(0:number_of_particle_groups,dopts_num) ) pts_value_l = 0.0 pts_value_l(:,16) = 9999999.9 ! for calculation of minimum radius ! !-- Calculate or collect the particle time series quantities for all particles !-- and seperately for each particle group (if there is more than one group) DO n = 1, number_of_particles pts_value_l(0,1) = number_of_particles ! total # of particles pts_value_l(0,2) = pts_value_l(0,2) + & ( particles(n)%x - particles(n)%origin_x ) ! mean x pts_value_l(0,3) = pts_value_l(0,3) + & ( particles(n)%y - particles(n)%origin_y ) ! mean y pts_value_l(0,4) = pts_value_l(0,4) + & ( particles(n)%z - particles(n)%origin_z ) ! mean z pts_value_l(0,5) = pts_value_l(0,5) + particles(n)%z ! mean z (absolute) pts_value_l(0,6) = pts_value_l(0,6) + particles(n)%speed_x ! mean u pts_value_l(0,7) = pts_value_l(0,7) + particles(n)%speed_y ! mean v pts_value_l(0,8) = pts_value_l(0,8) + particles(n)%speed_z ! mean w IF ( .NOT. curvature_solution_effects ) THEN pts_value_l(0,9) = pts_value_l(0,9) + particles(n)%rvar1 ! mean sgsu pts_value_l(0,10) = pts_value_l(0,10) + particles(n)%rvar2 ! mean sgsv pts_value_l(0,11) = pts_value_l(0,11) + particles(n)%rvar3 ! mean sgsw ENDIF IF ( particles(n)%speed_z > 0.0 ) THEN pts_value_l(0,12) = pts_value_l(0,12) + 1.0 ! # of upward moving prts pts_value_l(0,13) = pts_value_l(0,13) + & particles(n)%speed_z ! mean w upw. ELSE pts_value_l(0,14) = pts_value_l(0,14) + & particles(n)%speed_z ! mean w down ENDIF pts_value_l(0,15) = pts_value_l(0,15) + particles(n)%radius ! mean rad pts_value_l(0,16) = MIN( pts_value_l(0,16), particles(n)%radius ) ! minrad pts_value_l(0,17) = MAX( pts_value_l(0,17), particles(n)%radius ) ! maxrad pts_value_l(0,18) = number_of_particles pts_value_l(0,19) = number_of_particles ! !-- Repeat the same for the respective particle group IF ( number_of_particle_groups > 1 ) THEN j = particles(n)%group pts_value_l(j,1) = pts_value_l(j,1) + 1 pts_value_l(j,2) = pts_value_l(j,2) + & ( particles(n)%x - particles(n)%origin_x ) pts_value_l(j,3) = pts_value_l(j,3) + & ( particles(n)%y - particles(n)%origin_y ) pts_value_l(j,4) = pts_value_l(j,4) + & ( particles(n)%z - particles(n)%origin_z ) pts_value_l(j,5) = pts_value_l(j,5) + particles(n)%z pts_value_l(j,6) = pts_value_l(j,6) + particles(n)%speed_x pts_value_l(j,7) = pts_value_l(j,7) + particles(n)%speed_y pts_value_l(j,8) = pts_value_l(j,8) + particles(n)%speed_z IF ( .NOT. curvature_solution_effects ) THEN pts_value_l(j,9) = pts_value_l(j,9) + particles(n)%rvar1 pts_value_l(j,10) = pts_value_l(j,10) + particles(n)%rvar2 pts_value_l(j,11) = pts_value_l(j,11) + particles(n)%rvar3 ENDIF IF ( particles(n)%speed_z > 0.0 ) THEN pts_value_l(j,12) = pts_value_l(j,12) + 1.0 pts_value_l(j,13) = pts_value_l(j,13) + particles(n)%speed_z ELSE pts_value_l(j,14) = pts_value_l(j,14) + particles(n)%speed_z ENDIF pts_value_l(j,15) = pts_value_l(j,15) + particles(n)%radius pts_value_l(j,16) = MIN( pts_value(j,16), particles(n)%radius ) pts_value_l(j,17) = MAX( pts_value(j,17), particles(n)%radius ) pts_value_l(j,18) = pts_value_l(j,18) + 1.0 pts_value_l(j,19) = pts_value_l(j,19) + 1.0 ENDIF ENDDO #if defined( __parallel ) ! !-- Sum values of the subdomains inum = number_of_particle_groups + 1 IF ( collective_wait ) CALL MPI_BARRIER( comm2d, ierr ) CALL MPI_ALLREDUCE( pts_value_l(0,1), pts_value(0,1), 15*inum, MPI_REAL, & MPI_SUM, comm2d, ierr ) IF ( collective_wait ) CALL MPI_BARRIER( comm2d, ierr ) CALL MPI_ALLREDUCE( pts_value_l(0,16), pts_value(0,16), inum, MPI_REAL, & MPI_MIN, comm2d, ierr ) IF ( collective_wait ) CALL MPI_BARRIER( comm2d, ierr ) CALL MPI_ALLREDUCE( pts_value_l(0,17), pts_value(0,17), inum, MPI_REAL, & MPI_MAX, comm2d, ierr ) IF ( collective_wait ) CALL MPI_BARRIER( comm2d, ierr ) CALL MPI_ALLREDUCE( pts_value_l(0,18), pts_value(0,18), inum, MPI_REAL, & MPI_MAX, comm2d, ierr ) IF ( collective_wait ) CALL MPI_BARRIER( comm2d, ierr ) CALL MPI_ALLREDUCE( pts_value_l(0,19), pts_value(0,19), inum, MPI_REAL, & MPI_MIN, comm2d, ierr ) #else pts_value(:,1:19) = pts_value_l(:,1:19) #endif ! !-- Normalize the above calculated quantities (except min/max values) with the !-- total number of particles IF ( number_of_particle_groups > 1 ) THEN inum = number_of_particle_groups ELSE inum = 0 ENDIF DO j = 0, inum IF ( pts_value(j,1) > 0.0 ) THEN pts_value(j,2:15) = pts_value(j,2:15) / pts_value(j,1) IF ( pts_value(j,12) > 0.0 .AND. pts_value(j,12) < 1.0 ) THEN pts_value(j,13) = pts_value(j,13) / pts_value(j,12) pts_value(j,14) = pts_value(j,14) / ( 1.0 - pts_value(j,12) ) ELSEIF ( pts_value(j,12) == 0.0 ) THEN pts_value(j,13) = -1.0 ELSE pts_value(j,14) = -1.0 ENDIF ENDIF ENDDO ! !-- Calculate higher order moments of particle time series quantities, !-- seperately for each particle group (if there is more than one group) DO n = 1, number_of_particles pts_value_l(0,20) = pts_value_l(0,20) + ( particles(n)%x - & particles(n)%origin_x - pts_value(0,2) )**2 ! x*2 pts_value_l(0,21) = pts_value_l(0,21) + ( particles(n)%y - & particles(n)%origin_y - pts_value(0,3) )**2 ! y*2 pts_value_l(0,22) = pts_value_l(0,22) + ( particles(n)%z - & particles(n)%origin_z - pts_value(0,4) )**2 ! z*2 pts_value_l(0,23) = pts_value_l(0,23) + ( particles(n)%speed_x - & pts_value(0,6) )**2 ! u*2 pts_value_l(0,24) = pts_value_l(0,24) + ( particles(n)%speed_y - & pts_value(0,7) )**2 ! v*2 pts_value_l(0,25) = pts_value_l(0,25) + ( particles(n)%speed_z - & pts_value(0,8) )**2 ! w*2 IF ( .NOT. curvature_solution_effects ) THEN pts_value_l(0,26) = pts_value_l(0,26) + ( particles(n)%rvar1 - & pts_value(0,9) )**2 ! u"2 pts_value_l(0,27) = pts_value_l(0,27) + ( particles(n)%rvar2 - & pts_value(0,10) )**2 ! v"2 pts_value_l(0,28) = pts_value_l(0,28) + ( particles(n)%rvar3 - & pts_value(0,11) )**2 ! w"2 ENDIF ! !-- Repeat the same for the respective particle group IF ( number_of_particle_groups > 1 ) THEN j = particles(n)%group pts_value_l(j,20) = pts_value_l(j,20) + ( particles(n)%x - & particles(n)%origin_x - pts_value(j,2) )**2 pts_value_l(j,21) = pts_value_l(j,21) + ( particles(n)%y - & particles(n)%origin_y - pts_value(j,3) )**2 pts_value_l(j,22) = pts_value_l(j,22) + ( particles(n)%z - & particles(n)%origin_z - pts_value(j,4) )**2 pts_value_l(j,23) = pts_value_l(j,23) + ( particles(n)%speed_x - & pts_value(j,6) )**2 pts_value_l(j,24) = pts_value_l(j,24) + ( particles(n)%speed_y - & pts_value(j,7) )**2 pts_value_l(j,25) = pts_value_l(j,25) + ( particles(n)%speed_z - & pts_value(j,8) )**2 IF ( .NOT. curvature_solution_effects ) THEN pts_value_l(j,26) = pts_value_l(j,26) + ( particles(n)%rvar1 - & pts_value(j,9) )**2 pts_value_l(j,27) = pts_value_l(j,27) + ( particles(n)%rvar2 - & pts_value(j,10) )**2 pts_value_l(j,28) = pts_value_l(j,28) + ( particles(n)%rvar3 - & pts_value(j,11) )**2 ENDIF ENDIF ENDDO pts_value_l(0,29) = ( number_of_particles - pts_value(0,1) / numprocs )**2 ! variance of particle numbers IF ( number_of_particle_groups > 1 ) THEN DO j = 1, number_of_particle_groups pts_value_l(j,29) = ( pts_value_l(j,1) - & pts_value(j,1) / numprocs )**2 ENDDO ENDIF #if defined( __parallel ) ! !-- Sum values of the subdomains inum = number_of_particle_groups + 1 IF ( collective_wait ) CALL MPI_BARRIER( comm2d, ierr ) CALL MPI_ALLREDUCE( pts_value_l(0,20), pts_value(0,20), inum*10, MPI_REAL, & MPI_SUM, comm2d, ierr ) #else pts_value(:,20:29) = pts_value_l(:,20:29) #endif ! !-- Normalize the above calculated quantities with the total number of !-- particles IF ( number_of_particle_groups > 1 ) THEN inum = number_of_particle_groups ELSE inum = 0 ENDIF DO j = 0, inum IF ( pts_value(j,1) > 0.0 ) THEN pts_value(j,20:28) = pts_value(j,20:28) / pts_value(j,1) ENDIF pts_value(j,29) = pts_value(j,29) / numprocs ENDDO #if defined( __netcdf ) ! !-- Output particle time series quantities in NetCDF format IF ( myid == 0 .AND. netcdf_output ) THEN DO j = 0, inum DO i = 1, dopts_num nc_stat = NF90_PUT_VAR( id_set_pts, id_var_dopts(i,j), & (/ pts_value(j,i) /), & start = (/ dopts_time_count /), & count = (/ 1 /) ) CALL handle_netcdf_error( 'data_output_ptseries', 392 ) ENDDO ENDDO ENDIF #endif DEALLOCATE( pts_value, pts_value_l ) CALL cpu_log( log_point(36), 'data_output_ptseries','stop', 'nobarrier' ) END SUBROUTINE data_output_ptseries