Commit c9671aaa authored by Roy Fabrice's avatar Roy Fabrice
Browse files

read cube implementation (ongoing)

parent 0286c131
......@@ -57,7 +57,8 @@ module amr2cell_hdf5_parameters_m
procedure :: Check => Check_amr2cell_hdf5_parameters
procedure :: Print => Print_amr2cell_hdf5_parameters
procedure :: Read => Read_amr2cell_hdf5_parameters
procedure :: Write => Write_hdf5_amr2cell_hdf5_parameters
procedure :: Read_hdf5 => Read_hdf5_amr2cell_hdf5_parameters
procedure :: Write_hdf5 => Write_hdf5_amr2cell_hdf5_parameters
end type amr2cell_hdf5_parameters_t
contains
......@@ -317,6 +318,58 @@ contains
end subroutine Read_amr2cell_hdf5_parameters
!----------------------------------------------------------------------------------------------------------------------------------
subroutine Read_hdf5_amr2cell_hdf5_parameters(this, hdf5_id, mpi_process)
use fortran_hdf5_constants_m, only : H5_STR_LEN
use fortran_hdf5_manage_groups_m, only : Hdf5_close_group, Hdf5_create_group
use fortran_hdf5_read_attribute_m, only : Hdf5_read_attr
use hdf5, only : HID_T
use mpi_process_m, only : mpi_process_t
integer(HID_T), intent(in) :: hdf5_id
type(mpi_process_t), intent(in) :: mpi_process
class(amr2cell_hdf5_parameters_t), intent(out) :: this
character(len=H5_STR_LEN) :: groupname
character(len=H5_STR_LEN) :: aname
integer(kind=HID_T) :: gr_id
#ifdef DEBUG
write(ERROR_UNIT,'(a,i0)') 'Read_hdf5_amr2cell_hdf5_parameters begins on process', mpi_process%rank
#endif
groupname = 'amr2cell_hdf5_parameters'
call Hdf5_open_group(hdf5_id,groupname,gr_id)
aname = 'data_dir'
call Hdf5_read_attr(gr_id,aname,LEN_STRING,this%data_dir)
aname = 'amr_filename'
call Hdf5_read_attr(gr_id,aname,LEN_STRING,this%amr_filename)
aname = 'hydro_filename'
call Hdf5_read_attr(gr_id,aname,LEN_STRING,this%hydro_filename)
aname = 'hydro_descriptor_filename'
call Hdf5_read_attr(gr_id,aname,LEN_STRING,this%hydro_descriptor_filename)
aname = 'info_filename'
call Hdf5_read_attr(gr_id,aname,LEN_STRING,this%info_filename)
aname = 'cube_filename'
call Hdf5_read_attr(gr_id,aname,LEN_STRING,this%cube_filename)
aname = 'cube_level'
call Hdf5_read_attr(gr_id,aname,this%cube_level)
aname = 'cell_level_min'
call Hdf5_read_attr(gr_id,aname,this%cell_level_min)
aname = 'cell_level_max'
call Hdf5_read_attr(gr_id,aname,this%cell_level_max)
call Hdf5_close_group(gr_id)
#ifdef DEBUG
write(ERROR_UNIT,'(a,i0)') 'Read_hdf5_amr2cell_hdf5_parameters ends on process', mpi_process%rank
#endif
end subroutine Read_hdf5_amr2cell_hdf5_parameters
!----------------------------------------------------------------------------------------------------------------------------------
subroutine Write_hdf5_amr2cell_hdf5_parameters(this, hdf5_id, mpi_process)
use fortran_hdf5_constants_m, only : H5_STR_LEN
......
......@@ -49,6 +49,7 @@ module cells_array_m
procedure Deallocate => Deallocate_cells_array
procedure Distribute => Distribute_cells_array
procedure Clean => Clean_unused_cells
procedure Read_hdf5 => Read_hdf5_cells_array
procedure, private :: Remove_duplicate_cells
procedure, private :: Remove_large_cells
procedure, private :: Remove_small_cells
......@@ -56,7 +57,7 @@ module cells_array_m
procedure, private :: Sort_heapify_cells
procedure, private :: Sort_sink_cells
procedure, private :: Sort_swap_cells
procedure :: Write => Write_hdf5_cells_array
procedure :: Write_hdf5 => Write_hdf5_cells_array
end type cells_array_t
contains
......@@ -326,7 +327,46 @@ contains
end subroutine Distribute_cells_array
!------------------------------------------------------------------------------------------------------------------------------------
subroutine Read_hdf5_cells_array(this, hdf5_id)
use char_utils_m, only : int_to_char12
use fortran_hdf5_constants_m
use fortran_hdf5_manage_groups_m
use fortran_hdf5_read_attribute_m
use fortran_hdf5_read_data_m
use hdf5
class(cells_array_t),intent(out) :: this
integer(kind=hid_t),intent(in) :: hdf5_id
character(len=H5_STR_LEN) :: attr_name
character(len=H5_STR_LEN) :: groupname
integer(kind=hid_t) :: cell_gr_id
integer :: icell
#ifdef DEBUG
write(ERROR_UNIT,'(a,i0)') 'Read_hdf5_cells_array begins on process', mpi_process%rank
#endif
! read number of cells in this array
attr_name = 'ncells'
call Hdf5_read_data(hdf5_id,attr_name,ncells)
call this%Allocate(nthp,nps,ncells)
do icell = 1, this%ncells
groupname = 'cell_'//int_to_char12(icell)
call Hdf5_open_group(hdf5_id, groupname, cell_gr_id)
call this%elts(icell)%Read_hdf5(cell_gr_id)
call Hdf5_close_group(cell_gr_id)
end do
#ifdef DEBUG
write(ERROR_UNIT,'(a,i0)') 'Read_hdf5_cells_array ends on process', mpi_process%rank
#endif
end subroutine Read_hdf5_cells_array
!------------------------------------------------------------------------------------------------------------------------------------
subroutine Remove_duplicate_cells(this)
class(cells_array_t), intent(inout) :: this
......@@ -629,6 +669,9 @@ contains
#ifdef DEBUG
write(ERROR_UNIT,'(a,i0)') 'Write_hdf5_cells_array begins on process', mpi_process%rank
#endif
! write number of cells in this array: it could be an integer(8) so write as data
attr_name = 'ncells'
call Hdf5_write_data(hdf5_id, attr_name, this%ncells)
do icell = 1, this%ncells
groupname = 'cell_'//int_to_char12(icell)
......@@ -637,7 +680,6 @@ contains
call Hdf5_close_group(cell_gr_id)
end do
#ifdef DEBUG
write(ERROR_UNIT,'(a,i0)') 'Write_hdf5_cells_array ends on process', mpi_process%rank
#endif
......
......@@ -56,7 +56,8 @@ module cube_m
contains
procedure :: Init => Init_cube
procedure :: Print_info => Print_info_cube
procedure :: Write => Write_hdf5_cube
procedure :: Read_hdf5 => Read_hdf5_cube
procedure :: Write_hdf5 => Write_hdf5_cube
end type cube_t
contains
......@@ -130,6 +131,76 @@ contains
end subroutine Print_info_cube
!----------------------------------------------------------------------------------------------------------------------------------
subroutine Read_hdf5_cube(this, filename, amr2cell_hdf5_parameters)
use amr2cell_hdf5_parameters_m, only : amr2cell_hdf5_parameters_t
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
class(cube_t), intent(out) :: this
character(len=H5_FILENAME_LEN), intent(in) :: filename
type(amr2cell_hdf5_parameters_t), intent(out) :: amr2cell_hdf5_parameters
integer(kind=hid_t) :: cells_group_id
integer(kind=hid_t) :: cube_file_id
integer(kind=hid_t) :: cube_info_id
character(len=H5_STR_LEN) :: groupname
integer :: icell
integer(HID_T) :: metadata_id
character(len=H5_STR_LEN) :: metadata_name
#ifdef DEBUG
write(ERROR_UNIT,'(a,i0)') 'Read_hdf5_cube begins on process', mpi_process%rank
#endif
call timer%Set_ref()
call Hdf5_open_file(filename, cube_file_id)
groupname = 'metadata'
call Hdf5_open_group(cube_file_id, groupname, metadata_id)
call this%ramses_info%Read_hdf5(metadata_id,mpi_process)
call amr2cell_hdf5_parameters%Read_hdf5(metadata_id,mpi_process)
! write metadata
groupname = 'cube_info'
call Hdf5_open_group(metadata_id, groupname, cube_info_id)
metadata_name = 'level'
call Hdf5_read_attr(cube_info_id, metadata_name, this%level)
metadata_name = 'filename'
call Hdf5_read_attr(cube_info_id, metadata_name, H5_FILENAME_LEN, this%filename)
metadata_name = 'size'
call Hdf5_read_attr(cube_info_id, metadata_name, this%size)
metadata_name = 'center_position'
call Hdf5_read_attr(cube_info_id, metadata_name, 3, this%center_position)
metadata_name = 'number'
call Hdf5_read_attr(cube_info_id, metadata_name, this%number)
metadata_name = 'identity'
call Hdf5_read_attr(cube_info_id, metadata_name, this%identity)
metadata_name = 'process_rank'
call Hdf5_read_attr(cube_info_id, metadata_name, this%process_rank)
call Hdf5_close_group(cube_info_id)
call Hdf5_close_group(metadata_id)
groupname = 'cells'
call Hdf5_open_group(cube_file_id, groupname, cells_group_id)
call this%cells_array%Read(cells_group_id)
call Hdf5_close_group(cells_group_id)
call Hdf5_close_file(cube_file_id)
call timer%Inc_inp()
#ifdef DEBUG
write(ERROR_UNIT,'(a,i0)') 'Read_hdf5_cube ends on process', mpi_process%rank
#endif
end subroutine Read_hdf5_cube
!----------------------------------------------------------------------------------------------------------------------------------
subroutine Write_hdf5_cube(this, amr2cell_hdf5_parameters)
......@@ -137,17 +208,20 @@ contains
use fortran_hdf5_constants_m
use fortran_hdf5_manage_files_m
use fortran_hdf5_manage_groups_m
use fortran_hdf5_write_attribute_m
use hdf5
type(amr2cell_hdf5_parameters_t), intent(in) :: amr2cell_hdf5_parameters
class(cube_t), intent(in) :: this
integer(kind=hid_t) :: cells_group_id
integer(kind=hid_t) :: cube_file_id
integer(kind=hid_t) :: cube_info_id
character(len=H5_FILENAME_LEN) :: filename
character(len=H5_STR_LEN) :: groupname
integer(kind=hid_t) :: cube_file_id
integer(kind=hid_t) :: cells_group_id
integer :: icell
integer(HID_T) :: metadata_id
character(len=H5_STR_LEN) :: metadata_name
#ifdef DEBUG
write(ERROR_UNIT,'(a,i0)') 'Write_hdf5_cube begins on process', mpi_process%rank
......@@ -160,7 +234,29 @@ contains
groupname = 'metadata'
call Hdf5_open_group(cube_file_id, groupname, metadata_id)
call this%ramses_info%Write_hdf5(metadata_id,mpi_process)
call amr2cell_hdf5_parameters%Write(metadata_id,mpi_process)
call amr2cell_hdf5_parameters%Write_hdf5(metadata_id,mpi_process)
! write metadata
groupname = 'cube_info'
call Hdf5_create_group(metadata_id, groupname, cube_info_id)
metadata_name = 'level'
call Hdf5_write_attr(cube_info_id, metadata_name, this%level)
metadata_name = 'filename'
call Hdf5_write_attr(cube_info_id, metadata_name, this%filename)
metadata_name = 'size'
call Hdf5_write_attr(cube_info_id, metadata_name, this%size)
metadata_name = 'center_position'
call Hdf5_write_attr(cube_info_id, metadata_name, 3, this%center_position)
metadata_name = 'number'
call Hdf5_write_attr(cube_info_id, metadata_name, this%number)
metadata_name = 'identity'
call Hdf5_write_attr(cube_info_id, metadata_name, this%identity)
metadata_name = 'process_rank'
call Hdf5_write_attr(cube_info_id, metadata_name, this%process_rank)
call Hdf5_close_group(cube_info_id)
call Hdf5_close_group(metadata_id)
groupname = 'cells'
call Hdf5_create_group(cube_file_id, groupname, cells_group_id)
......
......@@ -212,7 +212,7 @@ contains
do icube = 1, this%ncubes
if ( this%elts(icube)%process_rank == mpi_process%rank ) then
call this%elts(icube)%Write(amr2cell_hdf5_parameters)
call this%elts(icube)%Write_hdf5(amr2cell_hdf5_parameters)
end if
end do
......
......@@ -47,6 +47,8 @@ module ramses_hydro_descriptor_m
contains
procedure :: Print => Print_ramses_hydro_descriptor
procedure :: Read => Read_ramses_hydro_descriptor
procedure :: Read_hdf5 => Read_hdf5_ramses_hydro_descriptor
procedure :: Write_hdf5 => Write_hdf5_ramses_hydro_descriptor
end type ramses_hydro_descriptor_t
contains
......@@ -143,4 +145,62 @@ contains
end subroutine Read_ramses_hydro_descriptor
!------------------------------------------------------------------------------------------------------------------------------------
subroutine Read_hdf5_ramses_hydro_descriptor
#ifdef DEBUG
write(ERROR_UNIT,'(a,i0)') 'Read_hdf5_ramses_hydro_descriptor begins on process', mpi_process%rank
#endif
call timer%Set_ref()
call timer%Inc_inp()
#ifdef DEBUG
write(ERROR_UNIT,'(a,i0)') 'Read_hdf5_ramses_hydro_descriptor ends on process', mpi_process%rank
#endif
end subroutine Read_hdf5_ramses_hydro_descriptor
!------------------------------------------------------------------------------------------------------------------------------------
subroutine Write_hdf5_ramses_hydro_descriptor(this, hdf5_id)
use fortran_hdf5_constants_m, only : H5_STR_LEN
use fortran_hdf5_manage_groups_m, only : Hdf5_close_group, Hdf5_create_group
use fortran_hdf5_write_attribute_m, only : Hdf5_write_attr
use hdf5, only : HID_T
class(ramses_hydro_descriptor_t), intent(in) :: this
integer(HID_T), intent(in) :: hdf5_id
character(len=H5_STR_LEN) :: groupname
character(len=H5_STR_LEN) :: aname
integer(kind=HID_T) :: gr_id
#ifdef DEBUG
write(ERROR_UNIT,'(a,i0)') 'Write_hdf5_ramses_hydro_descriptor begins on process', mpi_process%rank
#endif
call timer%Set_ref()
groupname = 'ramses_hydro_descriptor_info'
call Hdf5_create_group(hdf5_id,groupname,gr_id)
aname = 'nvar'
call Hdf5_write_attr(gr_id, aname, this%nvar)
aname = 'n_non_thermal_pressures'
call Hdf5_write_attr(gr_id, aname, this%n_non_thermal_pressures)
aname = 'n_passive_scalars'
call Hdf5_write_attr(gr_id, aname, this%n_passive_scalars)
aname = 'variable_names'
call Hdf5_write_attr(gr_id, aname, nvar, this%variable_names)
call Hdf5_close_group(gr_id)
call timer%Inc_out()
#ifdef DEBUG
write(ERROR_UNIT,'(a,i0)') 'Write_hdf5_ramses_hydro_descriptor ends on process', mpi_process%rank
#endif
end subroutine Write_hdf5_ramses_hydro_descriptor
end module ramses_hydro_descriptor_m
......@@ -59,6 +59,7 @@ module ramses_info_m
contains
procedure :: Print => Print_ramses_info
procedure :: Read => Read_ramses_info
procedure :: Read_hdf5 => Read_hdf5_ramses_info
procedure :: Write_hdf5 => Write_hdf5_ramses_info
end type ramses_info_t
......@@ -114,6 +115,74 @@ contains
end subroutine Print_ramses_info
!------------------------------------------------------------------------------------------------------------------------------------
!> Read Ramses info as metadata from a HDF5 object
subroutine Read_hdf5_ramses_info(this, hdf5_id, mpi_process)
use fortran_hdf5_constants_m, only : H5_STR_LEN
use fortran_hdf5_manage_groups_m, only : Hdf5_close_group, Hdf5_create_group
use fortran_hdf5_read_attribute_m, only : Hdf5_read_attr
use hdf5, only : HID_T
use mpi_process_m, only : mpi_process_t
integer(HID_T), intent(in) :: hdf5_id
type(mpi_process_t), intent(in) :: mpi_process
class(ramses_info_t), intent(out) :: this !< info structure
character(len=H5_STR_LEN) :: groupname
character(len=H5_STR_LEN) :: aname
integer(kind=HID_T) :: gr_id
integer(kind=HID_T) :: gr_ramses_id
#ifdef DEBUG
write(OUTPUT_UNIT,*) 'ramses_info%Read_hdf5 begins on process ', mpi_process%rank
#endif
! Ramses Info Metadata
groupname = 'ramses_info'
call Hdf5_open_group(hdf5_id,groupname,gr_ramses_id)
aname = 'ncpu'
call Hdf5_read_attr(gr_ramses_id,aname,this%ncpu)
aname = 'ndim'
call Hdf5_read_attr(gr_ramses_id,aname,this%ndim)
aname = 'levelmin'
call Hdf5_read_attr(gr_ramses_id,aname,this%levelmin)
aname = 'levelmax'
call Hdf5_read_attr(gr_ramses_id,aname,this%levelmax)
aname = 'ngridmax'
call Hdf5_read_attr(gr_ramses_id,aname,this%ngridmax)
aname = 'nstep_coarse'
call Hdf5_read_attr(gr_ramses_id,aname,this%nstep_coarse)
aname = 'boxlen'
call Hdf5_read_attr(gr_ramses_id,aname,this%boxlen)
aname = 'time'
call Hdf5_read_attr(gr_ramses_id,aname,this%time)
aname = 'aexp'
call Hdf5_read_attr(gr_ramses_id,aname,this%aexp)
aname = 'h0'
call Hdf5_read_attr(gr_ramses_id,aname,this%h0)
aname = 'omega_m'
call Hdf5_read_attr(gr_ramses_id,aname,this%omega_m)
aname = 'omega_l'
call Hdf5_read_attr(gr_ramses_id,aname,this%omega_l)
aname = 'omega_k'
call Hdf5_read_attr(gr_ramses_id,aname,this%omega_k)
aname = 'omega_b'
call Hdf5_read_attr(gr_ramses_id,aname,this%omega_b)
aname = 'unit_l'
call Hdf5_read_attr(gr_ramses_id,aname,this%unit_l)
aname = 'unit_d'
call Hdf5_read_attr(gr_ramses_id,aname,this%unit_d)
aname = 'unit_t'
call Hdf5_read_attr(gr_ramses_id,aname,this%unit_t)
call Hdf5_close_group(gr_ramses_id)
#ifdef DEBUG
write(OUTPUT_UNIT,*) 'ramses_info%Read_hdf5 ends on process ', mpi_process%rank
#endif
end subroutine Read_hdf5_ramses_info
!=======================================================================
!> Read RAMSES snapshot info file
subroutine Read_ramses_info(this, filename, mpi_process)
......@@ -207,7 +276,7 @@ contains
end subroutine Read_ramses_info
!------------------------------------------------------------------------------------------------------------------------------------
!------------------------------------------------------------------------------------------------------------------------------------
!> Write Ramses info as metadata in a HDF5 object
subroutine Write_hdf5_ramses_info(this, hdf5_id, mpi_process)
......
Markdown is supported
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