added binary writer and reader for particle restart

This commit is contained in:
Bryan Herman 2013-04-08 08:39:03 -07:00
parent d0919de1b8
commit 34bb27bf7d
3 changed files with 120 additions and 17 deletions

View file

@ -350,13 +350,14 @@ module constants
MODE_PARTICLE = 5 ! Particle restart mode
! Unit numbers
integer, parameter :: UNIT_SUMMARY = 11 ! unit # for writing summary file
integer, parameter :: UNIT_TALLY = 12 ! unit # for writing tally file
integer, parameter :: UNIT_PLOT = 13 ! unit # for writing plot file
integer, parameter :: UNIT_XS = 14 ! unit # for writing xs summary file
integer, parameter :: UNIT_SOURCE = 15 ! unit # for writing source file
integer, parameter :: UNIT_STATE = 16 ! unit # for writing state point
integer, parameter :: CMFD_BALANCE = 17 ! unit # for writing cmfd balance file
integer, parameter :: UNIT_SUMMARY = 11 ! unit # for writing summary file
integer, parameter :: UNIT_TALLY = 12 ! unit # for writing tally file
integer, parameter :: UNIT_PLOT = 13 ! unit # for writing plot file
integer, parameter :: UNIT_XS = 14 ! unit # for writing xs summary file
integer, parameter :: UNIT_SOURCE = 15 ! unit # for writing source file
integer, parameter :: UNIT_STATE = 16 ! unit # for writing state point
integer, parameter :: CMFD_BALANCE = 17 ! unit # for writing cmfd balance file
integer, parameter :: UNIT_PARTICLE = 18 ! unit # for writing particle restart
!=============================================================================
! CMFD CONSTANTS

View file

@ -30,12 +30,14 @@ module particle_restart
contains
#ifdef HDF5
!===============================================================================
! READ_PARTICLE_RESTART
! READ_HDF5_PARTICLE_RESTART
!===============================================================================
subroutine read_hdf5_particle_restart()
#ifdef HDF5
integer(HSIZE_T) :: dims1(1)
! write meessage
@ -68,15 +70,52 @@ contains
! close hdf5 file
call h5fclose_f(hdf5_particle_file, hdf5_err)
#endif
end subroutine read_hdf5_particle_restart
#endif
!===============================================================================
! READ_BINARY_PARTICLE_RESTART
!===============================================================================
subroutine read_binary_particle_restart()
! write meessage
message = "Loading particle restart file " // trim(path_particle_restart) &
// "..."
call write_message(1)
! open file
open(UNIT=UNIT_PARTICLE, FILE=path_particle_restart, STATUS='old', &
ACCESS='stream')
! read data from file
read(UNIT_PARTICLE) current_batch
read(UNIT_PARTICLE) gen_per_batch
read(UNIT_PARTICLE) current_gen
read(UNIT_PARTICLE) n_particles
read(UNIT_PARTICLE) p % id
read(UNIT_PARTICLE) p % wgt
read(UNIT_PARTICLE) p % E
read(UNIT_PARTICLE) p % coord % xyz
read(UNIT_PARTICLE) p % coord % uvw
! set particle last attributes
p % last_wgt = p % wgt
p % last_xyz = p % coord % xyz
p % last_E = p % E
! close hdf5 file
close(UNIT_PARTICLE)
end subroutine read_binary_particle_restart
!===============================================================================
! RUN_PARTICLE_RESTART
!===============================================================================
subroutine run_particle_restart()
#ifdef HDF5
integer(8) :: particle_seed
@ -85,7 +124,11 @@ contains
call initialize_particle()
! read in the restart information
#ifdef HDF5
call read_hdf5_particle_restart()
#else
call read_binary_particle_restart()
#endif
! set all tallies to 0 for now (just tracking errors)
n_tallies = 0
@ -97,12 +140,14 @@ contains
! transport neutron
call transport()
print *, 'WEIGHT:', p % wgt
print *, 'ENERGY:', p % E
print *, 'LOCATION:', p % coord % xyz
print *, 'ANGLE:', p % coord % uvw
#endif HDF5
! write output if particle made it
write(ou,*) 'Particle Successfully Transport:'
write(ou,*) 'WEIGHT:', p % wgt
write(ou,*) 'ENERGY:', p % E
write(ou,*) 'LOCATION:', p % coord % xyz
write(ou,*) 'ANGLE:', p % coord % uvw
end subroutine run_particle_restart
end module particle_restart

View file

@ -25,7 +25,27 @@ contains
!===============================================================================
subroutine write_particle_restart()
! Dont write another restart file if in particle restart mode
if (run_mode == MODE_PARTICLE) return
! write out binary or HDF5 file
#ifdef HDF5
call write_particle_restart_hdf5()
#else
call write_particle_restart_binary()
#endif
end subroutine write_particle_restart
#ifdef HDF5
!===============================================================================
! WRITE_PARTICLE_RESTART_HDF5
!===============================================================================
subroutine write_particle_restart_hdf5()
character(MAX_FILE_LEN) :: filename
integer(HSIZE_T) :: dims1(1)
type(Bank), pointer :: src => null()
@ -55,7 +75,44 @@ contains
! close hdf5 file
call h5fclose_f(hdf5_particle_file, hdf5_err)
end subroutine write_particle_restart_hdf5
#endif
end subroutine write_particle_restart
!===============================================================================
! WRITE_PARTICLE_RESTART_BINARY
!===============================================================================
subroutine write_particle_restart_binary()
character(MAX_FILE_LEN) :: filename
type(Bank), pointer :: src => null()
! set up file name
filename = 'particle_'//trim(to_str(rank))//'.binary'
! create hdf5 file
open(UNIT=UNIT_PARTICLE, FILE=filename, STATUS='replace', &
ACCESS='stream')
! get information about source particle
src => source_bank(current_work)
! write data to file
write(UNIT_PARTICLE) current_batch
write(UNIT_PARTICLE) gen_per_batch
write(UNIT_PARTICLE) current_gen
write(UNIT_PARTICLE) n_particles
write(UNIT_PARTICLE) p % id
write(UNIT_PARTICLE) src % wgt
write(UNIT_PARTICLE) src % E
write(UNIT_PARTICLE) src % xyz
write(UNIT_PARTICLE) src % uvw
! close hdf5 file
close(UNIT_PARTICLE)
end subroutine write_particle_restart_binary
end module particle_restart_write