Commit 3f2a8862 authored by Roy Fabrice's avatar Roy Fabrice
Browse files

part becomes dm in the name of some subroutine and files

modwritepartcube.f90 becomes modwritedmcube.f90
the name of the subroutines in this file also changes
and call to these subroutines changes in pfof_snap.f90
parent e042b552
......@@ -24,7 +24,7 @@ SRC = modhdf5.f90 \
modvariables.f90 \
modmpicom.f90 \
modreadcube.f90 \
modwritepartcube.f90 \
modwritedmcube.f90 \
read_ramses_part_mod.f90 \
select_dm_mod.f90 \
modio.f90 \
......
!==============================================================================
! Project: pFoF
! File: pfof_snap/src/modwritepartcube.f90
! File: pfof_snap/src/modwritedmcube.f90
! Copyright Fabrice Roy (2015)
! Fabrice.Roy@obspm.fr
!
......@@ -40,7 +40,7 @@
!> This module contains subroutines used to write HDF5 dark matter particles cubes.
!> Authors: F. Roy
module modwritepartcube
module modwritedmcube
use mpi
use modvarcommons, only : field, local_npart, mass, pfof_id, position, potential, velocity
......@@ -55,36 +55,36 @@ module modwritepartcube
implicit none
procedure(), pointer :: Writepartcube
procedure(), pointer :: Writedmcube
private
public :: Selectwritepartcube, Writepartcube
public :: Selectwritedmcube, Writedmcube
contains
!=======================================================================
subroutine Selectwritepartcube()
subroutine Selectwritedmcube()
if(param%gatherwrite_factor==1) then
if(param%do_sort_cube) then
Writepartcube => H5writesortedpartcube
Writedmcube => H5writesorteddmcube
else
Writepartcube => H5writepartcube
Writedmcube => H5writedmcube
end if
else
if(param%do_sort_cube) then
Writepartcube => Mpih5writesortedpartcube
Writedmcube => Mpih5writesorteddmcube
else
Writepartcube => Mpih5writepartcube
Writedmcube => Mpih5writedmcube
end if
end if
end subroutine Selectwritepartcube
end subroutine Selectwritedmcube
!=======================================================================
!> This subroutine writes the position, velocity and id of each particle on the process in a hdf5 file.
!! One file is written per MPI process
subroutine H5writepartcube()
subroutine H5writedmcube()
character(len=H5_FILENAME_LEN) :: filecube
character(len=5) :: pid_char
......@@ -103,9 +103,9 @@ contains
integer(kind=4), dimension(procNB) :: nparttab
integer(kind=8) :: npart8
logical(kind=4) :: islast
integer(kind=4) :: constant_mass
#ifdef DEBUG
print *,"Enter H5writepartcube on process ",procID
print *,"Enter H5writedmcube on process ",procID
#endif
write(pid_char(1:5),'(I5.5)') procID
......@@ -120,7 +120,12 @@ contains
codename='pfof_snap'
npart8 = 2**(inforamses%levelmin)
npart8 = npart8**3
call Write_meta_common(file_id, codename, npart8)
if(.not.param%do_skip_mass) then
constant_mass = -1
call Write_meta_common(file_id, codename, npart8, constant_mass = constant_mass)
else
call Write_meta_common(file_id, codename, npart8)
end if
call Write_meta_halofinder_parameter(file_id, param)
islast = .false.
call Write_meta_info_ramses(file_id, inforamses, islast)
......@@ -197,17 +202,17 @@ contains
call hdf5_close_file(file_id)
#ifdef DEBUG
print *,'Exit H5writepartcube on process ',procID
print *,'Exit H5writedmcube on process ',procID
#endif
end subroutine H5writepartcube
end subroutine H5writedmcube
!=======================================================================
!> This subroutine writes the position, the velocity and the id of each particle
!! on the process in a hdf5 file.
!! The particles are gathered
subroutine Mpih5writepartcube()
subroutine Mpih5writedmcube()
character(len=H5_FILENAME_LEN) :: filecube
character(len=5) :: pid_char
......@@ -231,9 +236,10 @@ contains
integer(kind=8) :: npart8
integer(kind=4) :: mpierr
logical(kind=4) :: islast
integer(kind=4) :: constant_mass
#ifdef DEBUG
print *,"Enter Mpih5writepartcube on process ",procID
print *,"Enter Mpih5writedmcube on process ",procID
#endif
! number of processes writing in the same file
......@@ -251,6 +257,12 @@ contains
codename='pfof_snap'
npart8 = 2**(inforamses%levelmin)
npart8 = npart8**3
if(.not.param%do_skip_mass) then
constant_mass = -1
call Write_meta_common(file_id, codename, npart8, constant_mass = constant_mass)
else
call Write_meta_common(file_id, codename, npart8)
end if
call Write_meta_common(file_id, codename, npart8)
call Write_meta_halofinder_parameter(file_id, param)
islast = .false.
......@@ -347,15 +359,15 @@ contains
call hdf5_close_mpi_file(file_id)
#ifdef DEBUG
print *,"Exit Mpih5writepartcube on process ",procID
print *,"Exit Mpih5writedmcube on process ",procID
#endif
end subroutine Mpih5writepartcube
end subroutine Mpih5writedmcube
!=======================================================================
subroutine H5writesortedpartcube()
subroutine H5writesorteddmcube()
use modconstant, only : IDKIND
use modsort
......@@ -379,25 +391,26 @@ contains
integer(kind=4) :: ix, iy, iz, ip, deb, fin, nc, ncdim, deltam1
integer(kind=IDKIND) :: ic
integer(kind=4), dimension(:), allocatable :: npartcube
integer(kind=4), dimension(:), allocatable :: ndmcube
integer(kind=IDKIND), dimension(:), allocatable :: ictable
logical(kind=4) :: fileexist, fileopened
integer(kind=8) :: npart8
logical(kind=4) :: islast
integer(kind=4) :: constant_mass
#ifdef DEBUG
integer(kind=4), dimension(3) :: tmp1, tmp2
print *,"Enter H5writesortedpartcube on process ",procID
print *,"Enter H5writesorteddmcube on process ",procID
#endif
! each FoF cube is divided into nc=512=8x8x8 groups, with ncdim=8
ncdim = 8
nc = ncdim*ncdim*ncdim
allocate(ictable(local_npart))
allocate(npartcube(nc))
npartcube = 0
allocate(ndmcube(nc))
ndmcube = 0
! Ramses coarse grid is composed of nres^3 cells
! on a process: nres^3 / procNB cells
! => there is (nres/(ncdim*dims(1))^3 coarse cells in each group
......@@ -427,7 +440,7 @@ contains
call coord_to_id((/ix,iy,iz/),ic,(/ncdim,ncdim,ncdim/))
#endif
ictable(ip) = ic
npartcube(ic) = npartcube(ic) + 1
ndmcube(ic) = ndmcube(ic) + 1
end do
! We sort the particles along their group id
......@@ -476,6 +489,12 @@ contains
codename='pfof_snap'
npart8 = 2**(inforamses%levelmin)
npart8 = npart8**3
if(.not.param%do_skip_mass) then
constant_mass = -1
call Write_meta_common(file_id, codename, npart8, constant_mass = constant_mass)
else
call Write_meta_common(file_id, codename, npart8)
end if
call Write_meta_common(file_id, codename, npart8)
call Write_meta_halofinder_parameter(file_id, param)
islast = .false.
......@@ -519,7 +538,7 @@ contains
call hdf5_write_attr(gr_id, aname, deltam1)
dsetname = 'npart_grp_array'
call hdf5_write_data(gr_id, dsetname, nc, npartcube)
call hdf5_write_data(gr_id, dsetname, nc, ndmcube)
call hdf5_close_group(gr_id)
......@@ -529,42 +548,42 @@ contains
deb = 1
! For each non empty group we create an HDF5 group and write dataset into it
do ic = 1, nc
if(npartcube(ic) /= 0) then
if(ndmcube(ic) /= 0) then
write(charic(1:8),'(I8.8)') ic
groupname = 'group'//charic
call hdf5_create_group(gr_data_id,groupname,gr_id)
fin = deb + npartcube(ic) - 1
fin = deb + ndmcube(ic) - 1
! Write the position of the particles
dsetname='position_part'
call hdf5_write_data(gr_id, dsetname, 3, npartcube(ic), position(:,deb:fin))
call hdf5_write_data(gr_id, dsetname, 3, ndmcube(ic), position(:,deb:fin))
! Write the velocity of the particles
dsetname='velocity_part'
call hdf5_write_data(gr_id, dsetname, 3, npartcube(ic), velocity(:,deb:fin))
call hdf5_write_data(gr_id, dsetname, 3, ndmcube(ic), velocity(:,deb:fin))
! Write the ID of the particles
dsetname='identity_part'
call hdf5_write_data(gr_id, dsetname, npartcube(ic), pfof_id(deb:fin))
call hdf5_write_data(gr_id, dsetname, ndmcube(ic), pfof_id(deb:fin))
! Write mass if it is used
if(.not.param%do_skip_mass) then
dsetname = 'mass_part'
call hdf5_write_data(gr_id, dsetname, npartcube(ic), mass(deb:fin))
call hdf5_write_data(gr_id, dsetname, ndmcube(ic), mass(deb:fin))
end if
! Write potential if it is used
if(param%do_read_potential) then
dsetname = 'potential_part'
call hdf5_write_data(gr_id, dsetname, npartcube(ic), potential(deb:fin))
call hdf5_write_data(gr_id, dsetname, ndmcube(ic), potential(deb:fin))
end if
! Write force if it is used
if(param%do_read_gravitational_field) then
dsetname = 'gravitational_field_part'
call hdf5_write_data(gr_id, dsetname, 3, npartcube(ic), field(:,deb:fin))
call hdf5_write_data(gr_id, dsetname, 3, ndmcube(ic), field(:,deb:fin))
end if
call hdf5_close_group(gr_id)
......@@ -578,17 +597,17 @@ contains
call hdf5_close_file(file_id)
#ifdef DEBUG
print *,'Exit H5writesortedpartcube on process ',procID
print *,'Exit H5writesorteddmcube on process ',procID
#endif
end subroutine H5writesortedpartcube
end subroutine H5writesorteddmcube
!=======================================================================
!> This subroutine writes the position, the velocity and the id of each particle
!! on the process in a hdf5 file.
!! The particles are gathered
subroutine Mpih5writesortedpartcube()
subroutine Mpih5writesorteddmcube()
use modconstant, only : IDKIND
use modsort
......@@ -611,7 +630,7 @@ contains
integer(kind=4) :: npart
integer(kind=4) :: nfile
integer(kind=4) :: ic, ix, iy, iz, ip, deb, fin, nc, ncdim, deltam1, fic
integer(kind=4), dimension(:), allocatable :: npartcube
integer(kind=4), dimension(:), allocatable :: ndmcube
integer(kind=IDKIND), dimension(:), allocatable :: ictable
integer(kind=4), dimension(:), allocatable :: partnb_tab
......@@ -624,9 +643,10 @@ contains
integer(kind=4) :: mpierr
integer(kind=8) :: npart8
logical(kind=4) :: islast
integer(kind=4) :: constant_mass
#ifdef DEBUG
print *,"Enter Mpih5writesortedpartcube on process ",procID
print *,"Enter Mpih5writesorteddmcube on process ",procID
#endif
......@@ -634,8 +654,8 @@ contains
ncdim = 8
nc = ncdim*ncdim*ncdim
allocate(ictable(local_npart))
allocate(npartcube(nc))
npartcube = 0
allocate(ndmcube(nc))
ndmcube = 0
! Ramses coarse grid is composed of nres^3 cells
! on a process: nres^3 / procNB cells
! => there is (nres/(ncdim*dims(1))^3 coarse cells in each group
......@@ -654,7 +674,7 @@ contains
if(iz>ncdim) iz=ncdim
ic = ix + (iy-1)*ncdim + (iz-1)*ncdim*ncdim
ictable(ip) = ic
npartcube(ic) = npartcube(ic) + 1
ndmcube(ic) = ndmcube(ic) + 1
end do
! We sort the particles along their group id
......@@ -707,6 +727,12 @@ contains
codename = 'pfof_snap'
npart8 = 2**(inforamses%levelmin)
npart8 = npart8**3
if(.not.param%do_skip_mass) then
constant_mass = -1
call Write_meta_common(file_id, codename, npart8, constant_mass = constant_mass)
else
call Write_meta_common(file_id, codename, npart8)
end if
call Write_meta_common(file_id, codename, npart8)
call Write_meta_halofinder_parameter(file_id, param)
islast = .false.
......@@ -729,7 +755,7 @@ contains
call hdf5_write_attr(gr_id, aname, deltam1)
dsetname = 'npart_grp_array'
call hdf5_write_mpi_data(gr_id, dsetname, nc, npartcube, info_proc%write_comm%name)
call hdf5_write_mpi_data(gr_id, dsetname, nc, ndmcube, info_proc%write_comm%name)
aname = 'gatherwrite_factor'
call hdf5_write_attr(gr_id, aname, param%gatherwrite_factor)
......@@ -791,7 +817,7 @@ contains
fic = ic - nc*info_proc%write_comm%pid
if(fic>=1 .and. fic<=nc) then
if(npartcube(fic) == 0) then
if(ndmcube(fic) == 0) then
empty = .true.
if(deb>local_npart) then
deb=1
......@@ -799,7 +825,7 @@ contains
end if
else
empty = .false.
fin = deb + npartcube(fic) - 1
fin = deb + ndmcube(fic) - 1
#ifdef DEBUG
print *,'group ',groupname,' opened:', procID, fic, deb, fin
#endif
......@@ -851,7 +877,7 @@ contains
call hdf5_close_group(gr_id)
if(fic>=1 .and. fic<=nc) then
if(npartcube(fic) /= 0) then
if(ndmcube(fic) /= 0) then
deb = fin + 1
#ifdef DEBUG
print *,'group ',groupname,' closed'
......@@ -868,9 +894,9 @@ contains
call hdf5_close_mpi_file(file_id)
#ifdef DEBUG
print *,"Exit Mpih5writesortedpartcube on process ",procID
print *,"Exit Mpih5writesorteddmcube on process ",procID
#endif
end subroutine Mpih5writesortedpartcube
end subroutine Mpih5writesorteddmcube
end module modwritepartcube
end module modwritedmcube
......@@ -84,7 +84,7 @@ program Friend
use modtiming, only : tfof, tfofinit, tfofloc, timeint, tobs, tout, traccord, tread, treadfile
use modvarcommons, only : nres
use modvariables, only : ngrid, param
use modwritepartcube, only : Selectwritepartcube, Writepartcube
use modwritedmcube, only : Selectwritedmcube, Writedmcube
use mpi
use select_dm_mod, only : Select_dm_particles
......@@ -160,8 +160,8 @@ program Friend
if(param%do_write_cube) then
if(procID==0) write(OUTPUT_UNIT ,*) 'write particles distributed in a cartesian grid'
if(procID==0) write(LOG_UNIT,*) 'write particles distributed in a cartesian grid'
call Selectwritepartcube()
call Writepartcube()
call Selectwritedmcube()
call Writedmcube()
end if
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment