mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-27 21:55:41 -04:00
Make HDF5 only binary output option in source and Python API. Still need to
update test suite and get rid of output_interface.
This commit is contained in:
parent
ab59b90cfe
commit
e93afed7a0
13 changed files with 109 additions and 770 deletions
|
|
@ -40,13 +40,8 @@ class Particle(object):
|
|||
"""
|
||||
|
||||
def __init__(self, filename):
|
||||
if filename.endswith('.h5'):
|
||||
import h5py
|
||||
self._f = h5py.File(filename, 'r')
|
||||
self._hdf5 = True
|
||||
else:
|
||||
self._f = open(filename, 'rb')
|
||||
self._hdf5 = False
|
||||
import h5py
|
||||
self._f = h5py.File(filename, 'r')
|
||||
|
||||
# Read all metadata
|
||||
self._read_data()
|
||||
|
|
@ -74,36 +69,17 @@ class Particle(object):
|
|||
self.xyz = self._get_double(3, path='xyz')
|
||||
self.uvw = self._get_double(3, path='uvw')
|
||||
|
||||
def _get_data(self, n, typeCode, size):
|
||||
return list(struct.unpack('={0}{1}'.format(n, typeCode),
|
||||
self._f.read(n*size)))
|
||||
|
||||
def _get_int(self, n=1, path=None):
|
||||
if self._hdf5:
|
||||
return [int(v) for v in self._f[path].value]
|
||||
else:
|
||||
return [int(v) for v in self._get_data(n, 'i', 4)]
|
||||
return [int(v) for v in self._f[path].value]
|
||||
|
||||
def _get_long(self, n=1, path=None):
|
||||
if self._hdf5:
|
||||
return [int(v) for v in self._f[path].value]
|
||||
else:
|
||||
return [int(v) for v in self._get_data(n, 'q', 8)]
|
||||
return [int(v) for v in self._f[path].value]
|
||||
|
||||
def _get_float(self, n=1, path=None):
|
||||
if self._hdf5:
|
||||
return [float(v) for v in self._f[path].value]
|
||||
else:
|
||||
return [float(v) for v in self._get_data(n, 'f', 4)]
|
||||
return [float(v) for v in self._f[path].value]
|
||||
|
||||
def _get_double(self, n=1, path=None):
|
||||
if self._hdf5:
|
||||
return [float(v) for v in self._f[path].value]
|
||||
else:
|
||||
return [float(v) for v in self._get_data(n, 'd', 8)]
|
||||
return [float(v) for v in self._f[path].value]
|
||||
|
||||
def _get_string(self, n=1, path=None):
|
||||
if self._hdf5:
|
||||
return str(self._f[path].value)
|
||||
else:
|
||||
return str(self._get_data(n, 's', 1)[0])
|
||||
return str(self._f[path].value)
|
||||
|
|
|
|||
|
|
@ -92,13 +92,8 @@ class StatePoint(object):
|
|||
"""
|
||||
|
||||
def __init__(self, filename):
|
||||
if filename.endswith('.h5'):
|
||||
import h5py
|
||||
self._f = h5py.File(filename, 'r')
|
||||
self._hdf5 = True
|
||||
else:
|
||||
self._f = open(filename, 'rb')
|
||||
self._hdf5 = False
|
||||
import h5py
|
||||
self._f = h5py.File(filename, 'r')
|
||||
|
||||
# Set flags for what data has been read
|
||||
self._results = False
|
||||
|
|
@ -171,12 +166,9 @@ class StatePoint(object):
|
|||
raise Exception('Statepoint Revision is not consistent.')
|
||||
|
||||
# Read OpenMC version
|
||||
if self._hdf5:
|
||||
self._version = [self._get_int(path='version_major')[0],
|
||||
self._get_int(path='version_minor')[0],
|
||||
self._get_int(path='version_release')[0]]
|
||||
else:
|
||||
self._version = self._get_int(3)
|
||||
self._version = [self._get_int(path='version_major')[0],
|
||||
self._get_int(path='version_minor')[0],
|
||||
self._get_int(path='version_release')[0]]
|
||||
|
||||
# Read date and time
|
||||
self._date_and_time = self._get_string(19, path='date_and_time')
|
||||
|
|
@ -473,13 +465,8 @@ class StatePoint(object):
|
|||
# Read global Tallies
|
||||
n_global_tallies = self._get_int(path='n_global_tallies')[0]
|
||||
|
||||
if self._hdf5:
|
||||
data = self._f['global_tallies'].value
|
||||
self._global_tallies = np.column_stack((data['sum'], data['sum_sq']))
|
||||
|
||||
else:
|
||||
self._global_tallies = np.array(self._get_double(2*n_global_tallies))
|
||||
self._global_tallies.shape = (n_global_tallies, 2)
|
||||
data = self._f['global_tallies'].value
|
||||
self._global_tallies = np.column_stack((data['sum'], data['sum_sq']))
|
||||
|
||||
# Flag indicating if Tallies are present
|
||||
self._tallies_present = self._get_int(path='tallies/tallies_present')[0]
|
||||
|
|
@ -499,15 +486,9 @@ class StatePoint(object):
|
|||
num_tot_bins = tally.num_bins
|
||||
|
||||
# Extract Tally data from the file
|
||||
if self._hdf5:
|
||||
data = self._f['{0}{1}/results'.format(base, tally_key)].value
|
||||
sum = data['sum']
|
||||
sum_sq = data['sum_sq']
|
||||
|
||||
else:
|
||||
results = np.array(self._get_double(2*num_tot_bins))
|
||||
sum = results[0::2]
|
||||
sum_sq = results[1::2]
|
||||
data = self._f['{0}{1}/results'.format(base, tally_key)].value
|
||||
sum = data['sum']
|
||||
sum_sq = data['sum_sq']
|
||||
|
||||
# Define a routine to convert 0 to 1
|
||||
def nonzero(val):
|
||||
|
|
@ -547,8 +528,7 @@ class StatePoint(object):
|
|||
self._source = np.empty(self._n_particles, dtype=SourceSite)
|
||||
|
||||
# For HDF5 state points, copy entire bank
|
||||
if self._hdf5:
|
||||
source_sites = self._f['source_bank'].value
|
||||
source_sites = self._f['source_bank'].value
|
||||
|
||||
# Initialize SourceSite object for each particle
|
||||
for i in range(self._n_particles):
|
||||
|
|
@ -556,13 +536,7 @@ class StatePoint(object):
|
|||
site = SourceSite()
|
||||
|
||||
# Read position, angle, and energy
|
||||
if self._hdf5:
|
||||
site._weight, site._xyz, site._uvw, site._E = source_sites[i]
|
||||
else:
|
||||
site._weight = self._get_double()[0]
|
||||
site._xyz = self._get_double(3)
|
||||
site._uvw = self._get_double(3)
|
||||
site._E = self._get_double()[0]
|
||||
site._weight, site._xyz, site._uvw, site._E = source_sites[i]
|
||||
|
||||
# Store the source site in the NumPy array
|
||||
self._source[i] = site
|
||||
|
|
@ -798,37 +772,19 @@ class StatePoint(object):
|
|||
self._f.read(n*size)))
|
||||
|
||||
def _get_int(self, n=1, path=None):
|
||||
if self._hdf5:
|
||||
return [int(v) for v in self._f[path].value]
|
||||
else:
|
||||
return [int(v) for v in self._get_data(n, 'i', 4)]
|
||||
return [int(v) for v in self._f[path].value]
|
||||
|
||||
def _get_long(self, n=1, path=None):
|
||||
if self._hdf5:
|
||||
return [long(v) for v in self._f[path].value]
|
||||
else:
|
||||
return [long(v) for v in self._get_data(n, 'q', 8)]
|
||||
return [long(v) for v in self._f[path].value]
|
||||
|
||||
def _get_float(self, n=1, path=None):
|
||||
if self._hdf5:
|
||||
return [float(v) for v in self._f[path].value]
|
||||
else:
|
||||
return [float(v) for v in self._get_data(n, 'f', 4)]
|
||||
return [float(v) for v in self._f[path].value]
|
||||
|
||||
def _get_double(self, n=1, path=None):
|
||||
if self._hdf5:
|
||||
return [float(v) for v in self._f[path].value]
|
||||
else:
|
||||
return [float(v) for v in self._get_data(n, 'd', 8)]
|
||||
return [float(v) for v in self._f[path].value]
|
||||
|
||||
def _get_double_array(self, n=1, path=None):
|
||||
if self._hdf5:
|
||||
return self._f[path].value
|
||||
else:
|
||||
return self._get_data(n, 'd', 8)
|
||||
return self._f[path].value
|
||||
|
||||
def _get_string(self, n=1, path=None):
|
||||
if self._hdf5:
|
||||
return str(self._f[path].value)
|
||||
else:
|
||||
return str(self._get_data(n, 's', 1)[0])
|
||||
return str(self._f[path].value)
|
||||
|
|
|
|||
|
|
@ -9,9 +9,7 @@ module finalize
|
|||
use message_passing
|
||||
#endif
|
||||
|
||||
#ifdef HDF5
|
||||
use hdf5_interface, only: h5tclose_f, h5close_f, hdf5_err
|
||||
#endif
|
||||
|
||||
implicit none
|
||||
|
||||
|
|
@ -51,14 +49,12 @@ contains
|
|||
! Deallocate arrays
|
||||
call free_memory()
|
||||
|
||||
#ifdef HDF5
|
||||
! Release compound datatypes
|
||||
call h5tclose_f(hdf5_tallyresult_t, hdf5_err)
|
||||
call h5tclose_f(hdf5_bank_t, hdf5_err)
|
||||
|
||||
! Close FORTRAN interface.
|
||||
call h5close_f(hdf5_err)
|
||||
#endif
|
||||
|
||||
#ifdef MPI
|
||||
! Free all MPI types
|
||||
|
|
|
|||
|
|
@ -16,9 +16,7 @@ module global
|
|||
use trigger_header, only: KTrigger
|
||||
use timer_header, only: Timer
|
||||
|
||||
#ifdef HDF5
|
||||
use hdf5_interface, only: HID_T
|
||||
#endif
|
||||
#ifdef MPIF08
|
||||
use mpi_f08
|
||||
#endif
|
||||
|
|
@ -270,12 +268,10 @@ module global
|
|||
! ============================================================================
|
||||
! HDF5 VARIABLES
|
||||
|
||||
#ifdef HDF5
|
||||
integer(HID_T) :: hdf5_output_file ! identifier for output file
|
||||
integer(HID_T) :: hdf5_tallyresult_t ! Compound type for TallyResult
|
||||
integer(HID_T) :: hdf5_bank_t ! Compound type for Bank
|
||||
integer(HID_T) :: hdf5_integer8_t ! type for integer(8)
|
||||
#endif
|
||||
|
||||
! ============================================================================
|
||||
! MISCELLANEOUS VARIABLES
|
||||
|
|
|
|||
|
|
@ -1,7 +1,5 @@
|
|||
module hdf5_interface
|
||||
|
||||
#ifdef HDF5
|
||||
|
||||
use hdf5
|
||||
use h5lt
|
||||
use, intrinsic :: ISO_C_BINDING
|
||||
|
|
@ -1811,6 +1809,4 @@ contains
|
|||
|
||||
# endif
|
||||
|
||||
#endif
|
||||
|
||||
end module hdf5_interface
|
||||
|
|
|
|||
|
|
@ -1,7 +1,5 @@
|
|||
module hdf5_summary
|
||||
|
||||
#ifdef HDF5
|
||||
|
||||
use ace_header, only: Reaction, UrrData, Nuclide
|
||||
use constants
|
||||
use endf, only: reaction_name
|
||||
|
|
@ -875,6 +873,4 @@ contains
|
|||
|
||||
end subroutine hdf5_write_timing
|
||||
|
||||
#endif
|
||||
|
||||
end module hdf5_summary
|
||||
|
|
|
|||
|
|
@ -15,9 +15,8 @@ module initialize
|
|||
use input_xml, only: read_input_xml, read_cross_sections_xml, &
|
||||
cells_in_univ_dict, read_plots_xml
|
||||
use material_header, only: Material
|
||||
use output, only: title, header, write_summary, print_version, &
|
||||
print_usage, write_xs_summary, print_plot, &
|
||||
write_message
|
||||
use output, only: title, header, print_version, write_message, &
|
||||
print_usage, write_xs_summary, print_plot
|
||||
use output_interface
|
||||
use random_lcg, only: initialize_prng
|
||||
use state_point, only: load_state_point
|
||||
|
|
@ -33,10 +32,8 @@ module initialize
|
|||
use omp_lib
|
||||
#endif
|
||||
|
||||
#ifdef HDF5
|
||||
use hdf5_interface
|
||||
use hdf5_summary, only: hdf5_write_summary
|
||||
#endif
|
||||
|
||||
implicit none
|
||||
|
||||
|
|
@ -60,10 +57,8 @@ contains
|
|||
call initialize_mpi()
|
||||
#endif
|
||||
|
||||
#ifdef HDF5
|
||||
! Initialize HDF5 interface
|
||||
call hdf5_initialize()
|
||||
#endif
|
||||
|
||||
! Read command line arguments
|
||||
call read_command_line()
|
||||
|
|
@ -155,11 +150,7 @@ contains
|
|||
call print_plot()
|
||||
else
|
||||
! Write summary information
|
||||
#ifdef HDF5
|
||||
if (output_summary) call hdf5_write_summary()
|
||||
#else
|
||||
if (output_summary) call write_summary()
|
||||
#endif
|
||||
|
||||
! Write cross section information
|
||||
if (output_xs) call write_xs_summary()
|
||||
|
|
@ -275,8 +266,6 @@ contains
|
|||
end subroutine initialize_mpi
|
||||
#endif
|
||||
|
||||
#ifdef HDF5
|
||||
|
||||
!===============================================================================
|
||||
! HDF5_INITIALIZE
|
||||
!===============================================================================
|
||||
|
|
@ -319,8 +308,6 @@ contains
|
|||
|
||||
end subroutine hdf5_initialize
|
||||
|
||||
#endif
|
||||
|
||||
!===============================================================================
|
||||
! READ_COMMAND_LINE reads all parameters from the command line
|
||||
!===============================================================================
|
||||
|
|
|
|||
|
|
@ -1203,98 +1203,6 @@ contains
|
|||
|
||||
end subroutine print_sab_table
|
||||
|
||||
!===============================================================================
|
||||
! WRITE_SUMMARY displays summary information about the problem about to be run
|
||||
! after reading all input files
|
||||
!===============================================================================
|
||||
|
||||
subroutine write_summary()
|
||||
|
||||
integer :: i ! loop index
|
||||
character(MAX_FILE_LEN) :: path ! path of summary file
|
||||
type(Material), pointer :: m => null()
|
||||
type(TallyObject), pointer :: t => null()
|
||||
|
||||
! Create filename for log file
|
||||
path = trim(path_output) // "summary.out"
|
||||
|
||||
! Open log file for writing
|
||||
open(UNIT=UNIT_SUMMARY, FILE=path, STATUS='replace', ACTION='write')
|
||||
|
||||
call header("OpenMC Monte Carlo Code", unit=UNIT_SUMMARY, level=1)
|
||||
write(UNIT=UNIT_SUMMARY, FMT=*) &
|
||||
"Copyright: 2011-2015 Massachusetts Institute of Technology"
|
||||
write(UNIT=UNIT_SUMMARY, FMT='(1X,A,7X,2(I1,"."),I1)') &
|
||||
"Version:", VERSION_MAJOR, VERSION_MINOR, VERSION_RELEASE
|
||||
#ifdef GIT_SHA1
|
||||
write(UNIT=UNIT_SUMMARY, FMT='(1X,"Git SHA1:",6X,A)') GIT_SHA1
|
||||
#endif
|
||||
write(UNIT=UNIT_SUMMARY, FMT='(1X,"Date/Time:",5X,A)') &
|
||||
time_stamp()
|
||||
|
||||
! Write information on number of processors
|
||||
#ifdef MPI
|
||||
write(UNIT=UNIT_SUMMARY, FMT='(1X,"MPI Processes:",1X,A)') &
|
||||
trim(to_str(n_procs))
|
||||
#endif
|
||||
|
||||
! Display problem summary
|
||||
call header("PROBLEM SUMMARY", unit=UNIT_SUMMARY)
|
||||
select case(run_mode)
|
||||
case (MODE_EIGENVALUE)
|
||||
write(UNIT_SUMMARY,100) 'Problem type:', 'k eigenvalue'
|
||||
write(UNIT_SUMMARY,101) 'Number of Batches:', n_batches
|
||||
write(UNIT_SUMMARY,101) 'Number of Inactive Batches:', n_inactive
|
||||
write(UNIT_SUMMARY,101) 'Generations per Batch:', gen_per_batch
|
||||
case (MODE_FIXEDSOURCE)
|
||||
write(UNIT_SUMMARY,100) 'Problem type:', 'fixed source'
|
||||
end select
|
||||
write(UNIT_SUMMARY,101) 'Number of Particles:', n_particles
|
||||
|
||||
! Display geometry summary
|
||||
call header("GEOMETRY SUMMARY", unit=UNIT_SUMMARY)
|
||||
write(UNIT_SUMMARY,101) 'Number of Cells:', n_cells
|
||||
write(UNIT_SUMMARY,101) 'Number of Surfaces:', n_surfaces
|
||||
write(UNIT_SUMMARY,101) 'Number of Materials:', n_materials
|
||||
|
||||
! print summary of all geometry
|
||||
call print_geometry()
|
||||
|
||||
! print summary of materials
|
||||
call header("MATERIAL SUMMARY", unit=UNIT_SUMMARY)
|
||||
do i = 1, n_materials
|
||||
m => materials(i)
|
||||
call print_material(m, unit=UNIT_SUMMARY)
|
||||
end do
|
||||
|
||||
! print summary of tallies
|
||||
if (n_tallies > 0) then
|
||||
call header("TALLY SUMMARY", unit=UNIT_SUMMARY)
|
||||
do i = 1, n_tallies
|
||||
t=> tallies(i)
|
||||
call print_tally(t, unit=UNIT_SUMMARY)
|
||||
end do
|
||||
end if
|
||||
|
||||
! print summary of variance reduction
|
||||
call header("VARIANCE REDUCTION", unit=UNIT_SUMMARY)
|
||||
if (survival_biasing) then
|
||||
write(UNIT_SUMMARY,100) "Survival Biasing:", "on"
|
||||
else
|
||||
write(UNIT_SUMMARY,100) "Survival Biasing:", "off"
|
||||
end if
|
||||
write(UNIT_SUMMARY,100) "Weight Cutoff:", trim(to_str(weight_cutoff))
|
||||
write(UNIT_SUMMARY,100) "Survival weight:", trim(to_str(weight_survive))
|
||||
|
||||
! Close summary file
|
||||
close(UNIT_SUMMARY)
|
||||
|
||||
! Format descriptor for columns
|
||||
100 format (1X,A,T35,A)
|
||||
101 format (1X,A,T35,I11)
|
||||
|
||||
end subroutine write_summary
|
||||
|
||||
!===============================================================================
|
||||
! WRITE_XS_SUMMARY writes information about each nuclide and S(a,b) table to a
|
||||
! file called cross_sections.out. This file shows the list of reactions as well
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -32,11 +32,7 @@ contains
|
|||
! Set up file name
|
||||
filename = trim(path_output) // 'particle_' // trim(to_str(current_batch)) &
|
||||
// '_' // trim(to_str(p % id))
|
||||
#ifdef HDF5
|
||||
filename = trim(filename) // '.h5'
|
||||
#else
|
||||
filename = trim(filename) // '.binary'
|
||||
#endif
|
||||
|
||||
!$omp critical (WriteParticleRestart)
|
||||
! Create file
|
||||
|
|
|
|||
|
|
@ -79,11 +79,7 @@ contains
|
|||
! Write out initial source
|
||||
if (write_initial_source) then
|
||||
call write_message('Writing out initial source...', 1)
|
||||
#ifdef HDF5
|
||||
filename = trim(path_output) // 'initial_source.h5'
|
||||
#else
|
||||
filename = trim(path_output) // 'initial_source.binary'
|
||||
#endif
|
||||
call sp % file_create(filename, serial = .false.)
|
||||
call sp % write_source_bank()
|
||||
call sp % file_close()
|
||||
|
|
|
|||
|
|
@ -55,11 +55,7 @@ contains
|
|||
& zero_padded(current_batch, count_digits(n_max_batches))
|
||||
|
||||
! Append appropriate extension
|
||||
#ifdef HDF5
|
||||
filename = trim(filename) // '.h5'
|
||||
#else
|
||||
filename = trim(filename) // '.binary'
|
||||
#endif
|
||||
|
||||
! Write message
|
||||
call write_message("Creating state point " // trim(filename) // "...", 1)
|
||||
|
|
@ -118,10 +114,8 @@ contains
|
|||
|
||||
! Write out CMFD info
|
||||
if (cmfd_on) then
|
||||
#ifdef HDF5
|
||||
call sp % open_group("cmfd")
|
||||
call sp % close_group()
|
||||
#endif
|
||||
call sp % write_data(1, "cmfd_on")
|
||||
call sp % write_data(cmfd % indices, "indices", length=4, group="cmfd")
|
||||
call sp % write_data(cmfd % k_cmfd, "k_cmfd", length=current_batch, &
|
||||
|
|
@ -143,10 +137,8 @@ contains
|
|||
end if
|
||||
end if
|
||||
|
||||
#ifdef HDF5
|
||||
call sp % open_group("tallies")
|
||||
call sp % close_group()
|
||||
#endif
|
||||
|
||||
! Write number of meshes
|
||||
call sp % write_data(n_meshes, "n_meshes", group="tallies/meshes")
|
||||
|
|
@ -414,11 +406,7 @@ contains
|
|||
filename = trim(path_output) // 'source.' // &
|
||||
& zero_padded(current_batch, count_digits(n_max_batches))
|
||||
|
||||
#ifdef HDF5
|
||||
filename = trim(filename) // '.h5'
|
||||
#else
|
||||
filename = trim(filename) // '.binary'
|
||||
#endif
|
||||
|
||||
! Write message for new file creation
|
||||
call write_message("Creating source file " // trim(filename) // "...", &
|
||||
|
|
@ -434,12 +422,8 @@ contains
|
|||
|
||||
! Set filename for state point
|
||||
filename = trim(path_output) // 'statepoint.' // &
|
||||
& zero_padded(current_batch, count_digits(n_max_batches))
|
||||
#ifdef HDF5
|
||||
zero_padded(current_batch, count_digits(n_max_batches))
|
||||
filename = trim(filename) // '.h5'
|
||||
#else
|
||||
filename = trim(filename) // '.binary'
|
||||
#endif
|
||||
|
||||
! Reopen statepoint file in parallel
|
||||
call sp % file_open(filename, 'w', serial = .false.)
|
||||
|
|
@ -456,14 +440,9 @@ contains
|
|||
|
||||
! Also check to write source separately in overwritten file
|
||||
if (source_latest) then
|
||||
|
||||
! Set filename
|
||||
filename = trim(path_output) // 'source'
|
||||
#ifdef HDF5
|
||||
filename = trim(filename) // '.h5'
|
||||
#else
|
||||
filename = trim(filename) // '.binary'
|
||||
#endif
|
||||
|
||||
! Write message for new file creation
|
||||
call write_message("Creating source file " // trim(filename) // "...", 1)
|
||||
|
|
|
|||
|
|
@ -95,15 +95,9 @@ contains
|
|||
integer, allocatable :: n_coords(:)
|
||||
integer :: n_particle_tracks
|
||||
|
||||
#ifdef HDF5
|
||||
fname = trim(path_output) // 'track_' // trim(to_str(current_batch)) &
|
||||
// '_' // trim(to_str(current_gen)) // '_' // trim(to_str(p % id)) &
|
||||
// '.h5'
|
||||
#else
|
||||
fname = trim(path_output) // 'track_' // trim(to_str(current_batch)) &
|
||||
// '_' // trim(to_str(current_gen)) // '_' // trim(to_str(p % id)) &
|
||||
// '.binary'
|
||||
#endif
|
||||
|
||||
! Determine total number of particles and number of coordinates for each
|
||||
n_particle_tracks = size(tracks)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue