Include source bank in statepoint by default

This commit is contained in:
Sterling Harper 2018-08-08 12:19:59 -04:00
parent 4b62006d23
commit d5a85164e2
3 changed files with 26 additions and 22 deletions

View file

@ -1,6 +1,6 @@
from contextlib import contextmanager
from ctypes import (CDLL, c_int, c_int32, c_int64, c_double, c_char_p, c_char,
POINTER, Structure, c_void_p, create_string_buffer)
from ctypes import (CDLL, c_bool, c_int, c_int32, c_int64, c_double, c_char_p,
c_char, POINTER, Structure, c_void_p, create_string_buffer)
from warnings import warn
import numpy as np
@ -52,7 +52,7 @@ _dll.openmc_simulation_init.restype = c_int
_dll.openmc_simulation_init.errcheck = _error_handler
_dll.openmc_simulation_finalize.restype = c_int
_dll.openmc_simulation_finalize.errcheck = _error_handler
_dll.openmc_statepoint_write.argtypes = [POINTER(c_char_p), POINTER(c_int)]
_dll.openmc_statepoint_write.argtypes = [POINTER(c_char_p), POINTER(c_bool)]
_dll.openmc_statepoint_write.restype = c_int
_dll.openmc_statepoint_write.errcheck = _error_handler
@ -269,7 +269,7 @@ def source_bank():
return as_array(ptr, (n.value,)).view(bank_dtype)
def statepoint_write(filename=None, write_source=False):
def statepoint_write(filename=None, write_source=True):
"""Write a statepoint file.
Parameters
@ -283,7 +283,7 @@ def statepoint_write(filename=None, write_source=False):
"""
if filename is not None:
filename = c_char_p(filename.encode())
_dll.openmc_statepoint_write(filename, c_int(write_source))
_dll.openmc_statepoint_write(filename, c_bool(write_source))
@contextmanager

View file

@ -352,9 +352,9 @@ contains
if (statepoint_batch % contains(current_batch)) then
if (sourcepoint_batch % contains(current_batch) .and. source_write &
.and. .not. source_separate) then
err = openmc_statepoint_write(write_source=1)
err = openmc_statepoint_write(write_source=.true._C_BOOL)
else
err = openmc_statepoint_write(write_source=0)
err = openmc_statepoint_write(write_source=.false._C_BOOL)
end if
end if

View file

@ -59,10 +59,11 @@ contains
!===============================================================================
function openmc_statepoint_write(filename, write_source) result(err) bind(C)
type(C_PTR), intent(in), optional :: filename
integer(C_INT), intent(in), optional :: write_source
type(C_PTR), intent(in), optional :: filename
logical(C_BOOL), intent(in), optional :: write_source
integer(C_INT) :: err
logical :: write_source_
integer :: i, j, k
integer :: i_xs
integer, allocatable :: id_array(:)
@ -79,6 +80,8 @@ contains
logical :: parallel
err = 0
! Set the filename
if (present(filename)) then
call c_f_pointer(filename, string, [MAX_FILE_LEN])
filename_ = to_f_string(string)
@ -89,6 +92,13 @@ contains
filename_ = trim(filename_) // '.h5'
end if
! Determine whether or not to write the source bank
if (present(write_source)) then
write_source_ = write_source
else
write_source_ = .true.
end if
! Write message
call write_message("Creating state point " // trim(filename_) // "...", 5)
@ -141,12 +151,8 @@ contains
call write_dataset(file_id, "current_batch", current_batch)
! Indicate whether source bank is stored in statepoint
if (present(write_source)) then
if (write_source /= 0) then
call write_attribute(file_id, "source_present", 1)
else
call write_attribute(file_id, "source_present", 0)
end if
if (write_source_) then
call write_attribute(file_id, "source_present", 1)
else
call write_attribute(file_id, "source_present", 0)
end if
@ -447,14 +453,12 @@ contains
#endif
! Write the source bank if desired
if (present(write_source)) then
if (write_source /= 0) then
if (master .or. parallel) then
file_id = file_open(filename_, 'a', parallel=.true.)
end if
call write_source_bank(file_id, work_index, source_bank)
if (master .or. parallel) call file_close(file_id)
if (write_source_) then
if (master .or. parallel) then
file_id = file_open(filename_, 'a', parallel=.true.)
end if
call write_source_bank(file_id, work_index, source_bank)
if (master .or. parallel) call file_close(file_id)
end if
end function openmc_statepoint_write