Commit 6a7e028b authored by Roy Fabrice's avatar Roy Fabrice
Browse files

get cubes info and beginning of select cubes

parent 939f2891
......@@ -35,29 +35,165 @@ module extract_cells_m
implicit none
private
public :: extract_cells
public :: Extract_cells, Get_cells_cube_info, Select_cells_cubes
contains
!------------------------------------------------------------------------------------------------------------------------------------
subroutine extract_cells(center, radius, parameters)
subroutine Extract_cells(cells_array, center, radius, parameters)
use add_cells_to_halos_parameters_m
real(kind=4), dimension(3), intent(in) :: center
real(kind=4), intent(in) :: radius
use cells_array_m
use fortran_hdf5_constants_m
use fortran_hdf5_manage_files_m
use hdf5, only : HID_T
type(cells_array_t), intent(out) :: cells_array
real(kind=8), dimension(3), intent(in) :: center
real(kind=8), intent(in) :: radius
type(add_cells_to_halos_parameters_t) :: parameters
integer(HID_T) :: amr2cell_group_id
integer(HID_T) :: cubeinfo_group_id
integer(HID_T) :: file_id
character(len=H5_FILENAME_LEN) :: file_name
character(len=H5_STR_LEN) :: group_name
integer(HID_T) :: metadata_group_id
#ifdef DEBUG
write(ERROR_UNIT,'(a,i0)') 'extract_cells begins on process', mpi_process%rank
write(ERROR_UNIT,'(a,i0)') 'Extract_cells begins on process', mpi_process%rank
#endif
#ifdef DEBUG
write(ERROR_UNIT,'(a,i0)') 'extract_cells ends on process', mpi_process%rank
write(ERROR_UNIT,'(a,i0)') 'Extract_cells ends on process', mpi_process%rank
#endif
end subroutine extract_cells
end subroutine Extract_cells
!------------------------------------------------------------------------------------------------------------------------------------
subroutine Get_cells_cube_info(cubes_boundaries, parameters)
use add_cells_to_halos_parameters_m
use error_handling_m
use fortran_hdf5_constants_m
use fortran_hdf5_manage_files_m
use fortran_hdf5_manage_groups_m
use fortran_hdf5_read_attribute_m
use hdf5, only : HID_T
use mpi
use mpi_utils_m
real(kind=8), allocatable, dimension(:,:,:), intent(out) :: cubes_boundaries
type(add_cells_to_halos_parameters_t), intent(in) :: parameters
integer :: alloc_stat
integer(HID_T) :: cells_file_id
character(len=H5_FILENAME_LEN) :: cells_file_name
integer(HID_T) :: cubeinfo_group_id
integer(kind=4) :: cube_identity
real(kind=8), dimension(3) :: cube_position
integer(kind=4) :: cubes_number
real(kind=8) :: cubes_size
character(len=ERR_MSG_LEN) :: error_message
integer(kind=4) :: first_cube_file
character(len=H5_STR_LEN) :: group_name
integer(kind=4) :: icube
integer(kind=4) :: last_cube_file
integer(HID_T) :: metadata_group_id
character(len=H5_STR_LEN) :: metadata_name
integer :: mpierr
#ifdef DEBUG
write(ERROR_UNIT,'(a,i0)') 'Get_cells_cube_info begins on process', mpi_process%rank
#endif
if(mpi_process%rank == 0) then
cells_file_name = trim(parameters%cells_data_directory)//trim(parameters%cells_file_name)
call hdf5_open_file(cells_file_name, cells_file_id)
group_name = 'metadata/cube_info'
call hdf5_open_group(cells_file_id, group_name, cubeinfo_group_id)
metadata_name = 'size'
call hdf5_read_attr(cubeinfo_group_id, metadata_name, cubes_size)
metadata_name = 'center_position'
call hdf5_read_attr(cubeinfo_group_id, metadata_name, 3, cube_position)
metadata_name = 'identity'
call hdf5_read_attr(cubeinfo_group_id, metadata_name, cube_identity)
metadata_name = 'number'
call hdf5_read_attr(cubeinfo_group_id, metadata_name, cubes_number)
call hdf5_close_group(cubeinfo_group_id)
call hdf5_close_file(cells_file_id)
end if
call mpi_bcast(cubes_number, 1, MPI_INTEGER, 0, mpi_process%comm%name, mpierr)
call Mpi_distribution(first_cube_file, last_cube_file, cubes_number, mpi_process)
allocate(cubes_boundaries(2,3,cubes_number), stat=alloc_stat, errmsg=error_message)
if(alloc_stat /= 0) then
call Allocate_error('cubes_boundaries','Get_cells_cube_info', error_message, alloc_stat, mpi_process%rank)
end if
cubes_boundaries(:,:,:) = 0.d0
! we consider that the files are all in the cells_data_directory
cells_file_name = trim(parameters%cells_data_directory)//trim(parameters%cells_file_name)
do icube = first_cube_file, last_cube_file
write(cells_file_name(len(trim(cells_file_name))-7:len(trim(cells_file_name))-3),'(i5.5)') icube
call hdf5_open_file(cells_file_name, cells_file_id)
group_name = 'metadata/cube_info'
call hdf5_open_group(cells_file_id, group_name, cubeinfo_group_id)
metadata_name = 'identity'
call hdf5_read_attr(cubeinfo_group_id, metadata_name, cube_identity)
metadata_name = 'size'
call hdf5_read_attr(cubeinfo_group_id, metadata_name, cubes_size)
metadata_name = 'center_position'
call hdf5_read_attr(cubeinfo_group_id, metadata_name, 3, cube_position)
cubes_boundaries(1,:,icube) = cube_position(:) - cubes_size*0.5d0
cubes_boundaries(2,:,icube) = cube_position(:) + cubes_size*0.5d0
call hdf5_close_group(cubeinfo_group_id)
call hdf5_close_file(cells_file_id)
end do
call mpi_allreduce(MPI_IN_PLACE, cubes_boundaries, 2*3*cubes_number, &
MPI_DOUBLE_PRECISION, MPI_SUM, mpi_process%comm%name, mpierr)
#ifdef DEBUG
write(ERROR_UNIT,'(a,i0)') 'Get_cells_cube_info ends on process', mpi_process%rank
#endif
end subroutine Get_cells_cube_info
!------------------------------------------------------------------------------------------------------------------------------------
subroutine Select_cells_cubes(cells_cubes_list, position, radius, cells_cubes_number, cells_cubes_boundaries)
integer, dimension(*), intent(inout) :: cells_cubes_list
real(kind=8), dimension(3), intent(in) :: position
real(kind=8), intent(in) :: radius
integer, intent(in) :: cells_cubes_number
real(kind=8), dimension(2,3,*), intent(in) :: cells_cubes_boundaries
integer :: dimcube
integer :: icube
integer, allocatable, dimension(:,:,:), save :: coords_to_cubes_id
#ifdef DEBUG
write(ERROR_UNIT,'(a,i0)') 'Select_cells_cube begins on process', mpi_process%rank
#endif
! first call to the subroutine
if(.not. allocated(coords_to_cubes_id)) then
! the number of cubes in each dimension is the cubic root of the total number of cubes
dimcube = cells_cubes_number**(1./3.)
write(OUTPUT_UNIT,*) dimcube
end if
#ifdef DEBUG
write(ERROR_UNIT,'(a,i0)') 'Select_cells_cube ends on process', mpi_process%rank
#endif
end subroutine Select_cells_cubes
end module extract_cells_m
\ No newline at end of file
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