Commit 2baa4a27 authored by Roy Fabrice's avatar Roy Fabrice
Browse files

add some members + read for simple cube

+ change some routine name
parent c0521e24
......@@ -31,16 +31,22 @@ module particles_cube_m
use arrays_of_particle_properties_m, only : arrays_of_particle_properties_t
use common_metadata_m, only : common_metadata_t
use common_shared_variables_m, only : mpi_process, timer
use iso_fortran_env, only : ERROR_UNIT, REAL32
use constants_m, only : IDKIND
use iso_fortran_env, only : ERROR_UNIT, INT32, REAL32
use ramses_info_m, only : ramses_info_t
implicit none
private
public :: particles_cube_t
type particles_cube_t
integer(INT32) :: process_particles_number !< local dark matter particles number
integer(INT32) :: process_stars_number !< local stars number
integer(IDKIND) :: simulation_grid_points_number !< total number of grid points: ngrid = nres ** 3
integer(INT32) :: simulation_grid_resolution !< 1-D resolution: number of grid points in each dimension ; nres = 2 ** lmin
integer(IDKIND) :: simulation_particles_number !< total dark matter particles number: npart = nres ** 3
integer(IDKIND) :: simulation_stars_number !< global stars number
type(common_metadata_t) :: common_metadata
type(ramses_info_t) :: ramses_info
real(REAL32), dimension(6) :: boundaries
......@@ -65,7 +71,7 @@ contains
!> @param[in] parameters : parameters of the run
subroutine Read_hdf5_particles_cube(this, parameters)
use error_codes_m, only : UNKNOWN_FILE_TYPE_ERROR_CODE
use error_codes_m, only : FILE_NOT_FOUND_ERROR_CODE, UNKNOWN_FILE_TYPE_ERROR_CODE
use error_handling_m, only : Algorithmic_error, ERR_MSG_LEN
use fortran_hdf5_constants_m, only : H5_FILENAME_LEN, H5_STR_LEN
use fortran_hdf5_manage_files_m, only : hdf5_close_file, hdf5_open_file
......@@ -79,6 +85,7 @@ contains
class(pfof_parameters_t), intent(in) :: parameters !! JE PENSE QUE LES PARAMETRES SPECIFIQUES A PFOF_SNAP SE RETROUVENT AVEC MPI_PROCESS
character(ERR_MSG_LEN) :: error_message
logical :: file_exist
integer(kind=HID_T) :: file_id
character(len=H5_FILENAME_LEN) :: file_name
character(len=H5_STR_LEN) :: file_type
......@@ -93,13 +100,18 @@ contains
if(mpi_process%rank == 0) then
file_name = trim(parameters%input_path)//trim(parameters%part_input_file)
call hdf5_open_file(file_name, file_id)
h5_name = 'metadata'
call hdf5_open_group(file_id, h5_name, group_id)
h5_name = 'file_type'
call hdf5_read_attr(group_id, h5_name, len(file_type), file_type)
call hdf5_close_group(group_id)
call hdf5_close_file(file_id)
inquire(File=file_name,exist=file_exist)
if(.not.file_exist) then
call Algorithmic_error(ROUTINE_NAME, 'Input HDF5 cube file not found.', FILE_NOT_FOUND_ERROR_CODE, mpi_process%rank)
else
call hdf5_open_file(file_name, file_id)
h5_name = 'metadata'
call hdf5_open_group(file_id, h5_name, group_id)
h5_name = 'file_type'
call hdf5_read_attr(group_id, h5_name, len(file_type), file_type)
call hdf5_close_group(group_id)
call hdf5_close_file(file_id)
end if
end if
call Mpi_Bcast(file_type, len(file_type), MPI_CHARACTER, 0, mpi_process%comm%name, mpierr)
......@@ -125,7 +137,7 @@ contains
end subroutine Read_hdf5_particles_cube
!----------------------------------------------------------------------------------------------------------------------------------
subroutine Read_hdf5_unsorted_particles_cube(this, parameters)
subroutine Read_hdf5_sorted_particles_cube(this, parameters)
use fortran_hdf5_constants_m, only : H5_FILENAME_LEN, H5_STR_LEN
use fortran_hdf5_manage_files_m, only : hdf5_close_file, hdf5_open_file
......@@ -143,7 +155,7 @@ contains
character(len=H5_STR_LEN) :: h5_name
character(len=H5_STR_LEN) :: file_type
integer(kind=4) :: mpierr
character(*), parameter :: ROUTINE_NAME = 'Read_hdf5_unsorted_particles_cube'
character(*), parameter :: ROUTINE_NAME = 'Read_hdf5_sorted_particles_cube'
#ifdef DEBUG
write(ERROR_UNIT,'(a,i0)') ROUTINE_NAME//' begins on process', mpi_process%rank
......@@ -154,42 +166,158 @@ contains
write(ERROR_UNIT,'(a,i0)') ROUTINE_NAME//' ends on process', mpi_process%rank
#endif
end subroutine Read_hdf5_unsorted_particles_cube
end subroutine Read_hdf5_sorted_particles_cube
!----------------------------------------------------------------------------------------------------------------------------------
subroutine Read_hdf5_sorted_particles_cube(this, parameters)
subroutine Read_hdf5_unsorted_particles_cube(this, parameters)
use allocation_m, only : Alloc, Realloc
use error_codes_m, only : FILE_NOT_FOUND_ERROR_CODE, ALLOCATE_ERROR_CODE, DEALLOCATE_ERROR_CODE
use error_handling_m, only : Algorithmic_error, Allocate_error, Deallocate_error
use fortran_hdf5_constants_m, only : H5_FILENAME_LEN, H5_STR_LEN
use fortran_hdf5_manage_files_m, only : hdf5_close_file, hdf5_open_file
use fortran_hdf5_manage_groups_m, only : hdf5_close_group, hdf5_open_group
use fortran_hdf5_read_data_m, only : hdf5_read_data
use fortran_hdf5_read_attribute_m, only : hdf5_read_attr
use hdf5, only : HID_T
use iso_fortran_env, only : INT64
use pfof_parameters_m, only : pfof_parameters_t
class(particles_cube_t), intent(out) :: this
class(particles_cube_t), intent(inout) :: this
class(pfof_parameters_t), intent(in) :: parameters !! JE PENSE QUE LES PARAMETRES SPECIFIQUES A PFOF_SNAP SE RETROUVENT AVEC MPI_PROCESS
integer(kind=HID_T) :: file_id
integer(kind=HID_T) :: group_id
character(len=H5_FILENAME_LEN) :: file_name
character(len=H5_STR_LEN) :: h5_name
character(len=H5_STR_LEN) :: file_type
integer(kind=4) :: mpierr
character(*), parameter :: ROUTINE_NAME = 'Read_hdf5_sorted_particles_cube'
character(H5_STR_LEN) :: attr_name
character(len=H5_STR_LEN) :: dataset_name
logical :: file_exist
integer(HID_T) :: file_id
character(H5_FILENAME_LEN) :: file_name
integer(HID_T) :: group_id
character(H5_STR_LEN) :: group_name
integer :: length
integer :: mpierr
integer(INT64) :: tmpint64
character(*), parameter :: ROUTINE_NAME = 'Read_hdf5_unsorted_particles_cube'
character(512) :: error_message
integer :: alloc_stat
#ifdef DEBUG
write(ERROR_UNIT,'(a,i0)') ROUTINE_NAME//' begins on process', mpi_process%rank
#endif
file_name = trim(parameters%input_path)//trim(parameters%part_input_file)
length=len_trim(file_name)
write(file_name(length-7:length-3),'(I5.5)') mpi_process%rank
inquire(file=file_name, exist=file_exist)
if(.not.file_exist) then
call Algorithmic_error(ROUTINE_NAME, 'Input HDF5 cube file not found.', FILE_NOT_FOUND_ERROR_CODE, mpi_process%rank)
else ! open the file
call hdf5_open_file(file_name, file_id)
call this%common_metadata%Read_hdf5(file_id)
! open the metadata group
group_name = 'metadata'
call hdf5_open_group(file_id, group_name, group_id)
call this%ramses_info%Read_hdf5(group_id, mpi_process)
this%simulation_grid_resolution = 2**this%ramses_info%levelmin
this%simulation_grid_points_number = int(this%simulation_grid_resolution,kind=IDKIND)**3
this%simulation_particles_number = int(this%common_metadata%simulation_particles_number,kind=IDKIND)
#ifdef DEBUG
write(ERROR_UNIT,'(a,i0,a,i0)') 'ramses_info%levelmin = ', this%ramses_info%levelmin, ' on process ', mpi_process%rank
write(ERROR_UNIT,'(a,i0,a,i0)') 'this%simulation_grid_resolution = ',this%simulation_grid_resolution, ' on process ', mpi_process%rank
write(ERROR_UNIT,'(a,i0,a,i0)') 'this%simulation_grid_points_number = ',this%simulation_grid_points_number, ' on process ', mpi_process%rank
#endif
! read attribute partNB
dataset_name = 'npart_file'
call hdf5_read_data(group_id, dataset_name, tmpint64)
this%process_particles_number = int(tmpint64, kind=INT32)
! read attribute boundaries
attr_name = 'boundaries'
call hdf5_read_attr(group_id, attr_name, 6, this%boundaries)
! xmin=boundaries(1)
! xmax=boundaries(2)
! ymin=boundaries(3)
! ymax=boundaries(4)
! zmin=boundaries(5)
! zmax=boundaries(6)
call hdf5_close_group(group_id)
call Realloc(this%ramses_particles%identity_p, this%process_particles_number, 'this%ramses_particles%identity_p', ROUTINE_NAME)
! if(allocated(this%ramses_particles%positions)) then
! write(ERROR_UNIT,*) 'ALLOUE ? : ', allocated(this%ramses_particles%positions), (/3,this%process_particles_number/)
! deallocate(this%ramses_particles%positions, stat=alloc_stat, errmsg=error_message)
! if(alloc_stat /= 0) then
! call Deallocate_error('this%ramses_particles%positions', ROUTINE_NAME, error_message, DEALLOCATE_ERROR_CODE, mpi_process%rank)
! end if
! allocate(this%ramses_particles%positions(3,this%process_particles_number), stat=alloc_stat, errmsg=error_message)
! if(alloc_stat /= 0) then
! call Allocate_error('this%ramses_particles%positions', ROUTINE_NAME, error_message, ALLOCATE_ERROR_CODE, mpi_process%rank)
! end if
! else
! write(ERROR_UNIT,*) 'PAS ALLOUE READ ? : ', allocated(this%ramses_particles%positions), (/3,this%process_particles_number/)
! ! deallocate(this%ramses_particles%positions)
! allocate(this%ramses_particles%positions(3,this%process_particles_number), stat=alloc_stat, errmsg=error_message)
! write(ERROR_UNIT,*) 'PAS ALLOUE READ ? : ', allocated(this%ramses_particles%positions), alloc_stat, error_message
! if(alloc_stat /= 0) then
! call Allocate_error('this%ramses_particles%positions', ROUTINE_NAME, error_message, ALLOCATE_ERROR_CODE, mpi_process%rank)
! end if
! end if
call Realloc(this%ramses_particles%positions, (/3,this%process_particles_number/), 'this%ramses_particles%positions', ROUTINE_NAME)
call Realloc(this%ramses_particles%velocities, (/3,this%process_particles_number/), 'this%ramses_particles%velocities', ROUTINE_NAME)
group_name = 'data'
call hdf5_open_group(file_id, group_name, group_id)
! read position of the particles
dataset_name = 'position_part'
call hdf5_read_data(group_id, dataset_name, 3, this%process_particles_number, this%ramses_particles%positions)
! ! read velocity of the particles
dataset_name = 'velocity_part'
call hdf5_read_data(group_id, dataset_name, 3, this%process_particles_number, this%ramses_particles%velocities)
! read id of the particles
dataset_name = 'identity_part'
call hdf5_read_data(group_id, dataset_name, this%process_particles_number, this%ramses_particles%identity_p)
if(parameters%do_read_potential) then
call Realloc(this%ramses_particles%potential, this%process_particles_number, 'this%ramses_particles%potential', ROUTINE_NAME)
dataset_name = 'potential_part'
call hdf5_read_data(group_id, dataset_name, this%process_particles_number, this%ramses_particles%potential)
end if
if(parameters%do_read_gravitational_field) then
call Realloc(this%ramses_particles%gravitational_field, (/3,this%process_particles_number/), 'this%ramses_particles%gravitational_field', ROUTINE_NAME)
dataset_name = 'gravitational_field_part'
call hdf5_read_data(group_id, dataset_name, 3, this%process_particles_number, this%ramses_particles%gravitational_field)
end if
! Close the root group.
call hdf5_close_group(group_id)
call hdf5_close_file(file_id)
end if
#ifdef DEBUG
write(ERROR_UNIT,'(a,i0)') ROUTINE_NAME//' ends on process', mpi_process%rank
#endif
end subroutine Read_hdf5_sorted_particles_cube
end subroutine Read_hdf5_unsorted_particles_cube
!----------------------------------------------------------------------------------------------------------------------------------
subroutine Read_hdf5_unsorted_particles_mpi_cube(this, parameters)
subroutine Read_hdf5_sorted_particles_mpi_cube(this, parameters)
use fortran_hdf5_constants_m, only : H5_FILENAME_LEN, H5_STR_LEN
use fortran_hdf5_manage_files_m, only : hdf5_close_file, hdf5_open_file
......@@ -199,7 +327,7 @@ contains
use pfof_parameters_m, only : pfof_parameters_t
class(particles_cube_t), intent(out) :: this
class(pfof_parameters_t), intent(in) :: parameters !! JE PENSE QUE LES PARAMETRES SPECIFIQUES A PFOF_SNAP SE RETROUVENT AVEC MPI_PROCESS
class(pfof_parameters_t), intent(in) :: parameters
integer(kind=HID_T) :: file_id
integer(kind=HID_T) :: group_id
......@@ -207,7 +335,7 @@ contains
character(len=H5_STR_LEN) :: h5_name
character(len=H5_STR_LEN) :: file_type
integer(kind=4) :: mpierr
character(*), parameter :: ROUTINE_NAME = 'Read_hdf5_unsorted_particles_mpi_cube'
character(*), parameter :: ROUTINE_NAME = 'Read_hdf5_sorted_particles_mpi_cube'
#ifdef DEBUG
write(ERROR_UNIT,'(a,i0)') ROUTINE_NAME//' begins on process', mpi_process%rank
......@@ -216,12 +344,12 @@ contains
#ifdef DEBUG
write(ERROR_UNIT,'(a,i0)') ROUTINE_NAME//' ends on process', mpi_process%rank
#endif
#endif
end subroutine Read_hdf5_unsorted_particles_mpi_cube
end subroutine Read_hdf5_sorted_particles_mpi_cube
!----------------------------------------------------------------------------------------------------------------------------------
subroutine Read_hdf5_sorted_particles_mpi_cube(this, parameters)
subroutine Read_hdf5_unsorted_particles_mpi_cube(this, parameters)
use fortran_hdf5_constants_m, only : H5_FILENAME_LEN, H5_STR_LEN
use fortran_hdf5_manage_files_m, only : hdf5_close_file, hdf5_open_file
......@@ -231,7 +359,7 @@ contains
use pfof_parameters_m, only : pfof_parameters_t
class(particles_cube_t), intent(out) :: this
class(pfof_parameters_t), intent(in) :: parameters
class(pfof_parameters_t), intent(in) :: parameters !! JE PENSE QUE LES PARAMETRES SPECIFIQUES A PFOF_SNAP SE RETROUVENT AVEC MPI_PROCESS
integer(kind=HID_T) :: file_id
integer(kind=HID_T) :: group_id
......@@ -239,7 +367,7 @@ contains
character(len=H5_STR_LEN) :: h5_name
character(len=H5_STR_LEN) :: file_type
integer(kind=4) :: mpierr
character(*), parameter :: ROUTINE_NAME = 'Read_hdf5_sorted_particles_mpi_cube'
character(*), parameter :: ROUTINE_NAME = 'Read_hdf5_unsorted_particles_mpi_cube'
#ifdef DEBUG
write(ERROR_UNIT,'(a,i0)') ROUTINE_NAME//' begins on process', mpi_process%rank
......@@ -248,8 +376,8 @@ contains
#ifdef DEBUG
write(ERROR_UNIT,'(a,i0)') ROUTINE_NAME//' ends on process', mpi_process%rank
#endif
#endif
end subroutine Read_hdf5_sorted_particles_mpi_cube
end subroutine Read_hdf5_unsorted_particles_mpi_cube
end module particles_cube_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