PartMC 2.1.4
aero_info.F90
Go to the documentation of this file.
00001 ! Copyright (C) 2009-2011 Nicole Riemer and Matthew West
00002 ! Licensed under the GNU General Public License version 2 or (at your
00003 ! option) any later version. See the file COPYING for details.
00004 
00005 !> \file
00006 !> The pmc_aero_info module.
00007 
00008 !> The aero_info_t structure and associated subroutines.
00009 module pmc_aero_info
00010 
00011   use pmc_util
00012   use pmc_spec_file
00013   use pmc_mpi
00014 #ifdef PMC_USE_MPI
00015   use mpi
00016 #endif
00017 
00018   !> No information.
00019   integer, parameter :: AERO_INFO_NONE = 0
00020   !> Particle was removed due to dilution with outside air.
00021   integer, parameter :: AERO_INFO_DILUTION = 1
00022   !> Particle was removed due to coagulation.
00023   integer, parameter :: AERO_INFO_COAG = 2
00024   !> Particle was removed due to halving of the aerosol population.
00025   integer, parameter :: AERO_INFO_HALVED = 3
00026   !> Particle was removed due to adjustments in the particle's
00027   !> weighting function.
00028   integer, parameter :: AERO_INFO_WEIGHT = 4
00029 
00030   !> Information about removed particles describing the sink.
00031   !!
00032   !! For each particle that is removed from the particle population
00033   !! the aero_info_t structure gives the ID of the removed particle
00034   !! and the action (dilution, coagulation, emission, etc) that caused
00035   !! the removal. The action must be one of the AERO_INFO_* parameters
00036   !! in the pmc_aero_info module. If the action is AERO_INFO_COAG then
00037   !! the other_id field will store the ID of the particle that was
00038   !! produced by the coagulation.
00039   !!
00040   !! Coagulation always occurs between two particles and the resulting
00041   !! particle takes the ID of one of the two original particles, or a
00042   !! new ID. If either of the coagulating particles does not have its
00043   !! ID inherited by the new particle then it will be recorded in an
00044   !! \c aero_info_t structure. If the ID of the new coagulated
00045   !! particle is the same as one of the coagulating particles then it
00046   !! is not considered to have been lost and is not recorded in an
00047   !! aero_info_t structure.
00048   type aero_info_t
00049      !> Particle ID number.
00050      integer :: id
00051      !> Action on this particle (from AERO_INFO_* parameters).
00052      integer :: action
00053      !> ID number of the new coagulated particle, or 0 if the new
00054      !> particle was not created.
00055      integer :: other_id
00056   end type aero_info_t
00057 
00058 contains
00059 
00060 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
00061 
00062   !> Allocates and initializes.
00063   subroutine aero_info_allocate(aero_info)
00064 
00065     !> Result.
00066     type(aero_info_t), intent(out) :: aero_info
00067 
00068     call aero_info_zero(aero_info)
00069 
00070   end subroutine aero_info_allocate
00071   
00072 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
00073 
00074   !> Deallocates.
00075   subroutine aero_info_deallocate(aero_info)
00076 
00077     !> Structure to deallocate.
00078     type(aero_info_t), intent(inout) :: aero_info
00079 
00080   end subroutine aero_info_deallocate
00081   
00082 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
00083 
00084   !> Copies aero_info_from to aero_info_to, both
00085   !> of which must already be allocated.
00086   subroutine aero_info_copy(aero_info_from, &
00087        aero_info_to)
00088 
00089     !> Origin structure.
00090     type(aero_info_t), intent(in) :: aero_info_from
00091     !> Destination structure.
00092     type(aero_info_t), intent(inout) :: aero_info_to
00093 
00094     aero_info_to%id = aero_info_from%id
00095     aero_info_to%action = aero_info_from%action
00096     aero_info_to%other_id = aero_info_from%other_id
00097 
00098   end subroutine aero_info_copy
00099   
00100 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
00101 
00102   !> Resets an aero_info to contain zero particles.
00103   subroutine aero_info_zero(aero_info)
00104 
00105     !> Structure to reset.
00106     type(aero_info_t), intent(inout) :: aero_info
00107 
00108     aero_info%id = 0
00109     aero_info%action = AERO_INFO_NONE
00110     aero_info%other_id = 0
00111 
00112   end subroutine aero_info_zero
00113   
00114 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
00115 
00116   !> Determines the number of bytes required to pack the given value.
00117   integer function pmc_mpi_pack_size_aero_info(val)
00118 
00119     !> Value to pack.
00120     type(aero_info_t), intent(in) :: val
00121 
00122     integer :: total_size
00123 
00124     total_size = 0
00125     total_size = total_size + pmc_mpi_pack_size_integer(val%id)
00126     total_size = total_size + pmc_mpi_pack_size_integer(val%action)
00127     total_size = total_size + pmc_mpi_pack_size_integer(val%other_id)
00128     pmc_mpi_pack_size_aero_info = total_size
00129 
00130   end function pmc_mpi_pack_size_aero_info
00131 
00132 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
00133 
00134   !> Packs the given value into the buffer, advancing position.
00135   subroutine pmc_mpi_pack_aero_info(buffer, position, val)
00136 
00137     !> Memory buffer.
00138     character, intent(inout) :: buffer(:)
00139     !> Current buffer position.
00140     integer, intent(inout) :: position
00141     !> Value to pack.
00142     type(aero_info_t), intent(in) :: val
00143 
00144 #ifdef PMC_USE_MPI
00145     integer :: prev_position
00146 
00147     prev_position = position
00148     call pmc_mpi_pack_integer(buffer, position, val%id)
00149     call pmc_mpi_pack_integer(buffer, position, val%action)
00150     call pmc_mpi_pack_integer(buffer, position, val%other_id)
00151     call assert(842929827, &
00152          position - prev_position <= pmc_mpi_pack_size_aero_info(val))
00153 #endif
00154 
00155   end subroutine pmc_mpi_pack_aero_info
00156 
00157 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
00158 
00159   !> Unpacks the given value from the buffer, advancing position.
00160   subroutine pmc_mpi_unpack_aero_info(buffer, position, val)
00161 
00162     !> Memory buffer.
00163     character, intent(inout) :: buffer(:)
00164     !> Current buffer position.
00165     integer, intent(inout) :: position
00166     !> Value to pack.
00167     type(aero_info_t), intent(inout) :: val
00168 
00169 #ifdef PMC_USE_MPI
00170     integer :: prev_position
00171 
00172     prev_position = position
00173     call pmc_mpi_unpack_integer(buffer, position, val%id)
00174     call pmc_mpi_unpack_integer(buffer, position, val%action)
00175     call pmc_mpi_unpack_integer(buffer, position, val%other_id)
00176     call assert(841267392, &
00177          position - prev_position <= pmc_mpi_pack_size_aero_info(val))
00178 #endif
00179 
00180   end subroutine pmc_mpi_unpack_aero_info
00181 
00182 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
00183   
00184 end module pmc_aero_info