diff --git a/CMakeLists.txt b/CMakeLists.txt index b0743bdf1b..614d4524a1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -299,6 +299,7 @@ set(LIBOPENMC_FORTRAN_SRC src/angle_distribution.F90 src/angleenergy_header.F90 src/bank_header.F90 + src/capi.F90 src/cmfd_data.F90 src/cmfd_execute.F90 src/cmfd_header.F90 diff --git a/openmc/libopenmc.py b/openmc/libopenmc.py index f95f72aac6..031c54564b 100644 --- a/openmc/libopenmc.py +++ b/openmc/libopenmc.py @@ -24,6 +24,9 @@ class _OpenMCLibrary(object): c_int, POINTER(POINTER(c_double)), ndpointer( np.intc, shape=(3,))] self._dll.openmc_tally_results.restype = None + self._dll.openmc_cell_set_temperature.argtypes = [ + c_int, c_double] + self._dll.openmc_cell_set_temperature.restype = c_int def init(self, intracomm=None): """Initialize OpenMC @@ -87,6 +90,10 @@ class _OpenMCLibrary(object): else: return None + def cell_set_temperature(self, cell_id, temperature): + """Set the temperature of a cell""" + return self._dll.openmc_cell_set_temperature(cell_id, temperature) + def __getattr__(self, key): # Fall-back for other functions that may be available from library try: diff --git a/src/capi.F90 b/src/capi.F90 new file mode 100644 index 0000000000..0c7a54c5bf --- /dev/null +++ b/src/capi.F90 @@ -0,0 +1,65 @@ +module openmc_capi + + use, intrinsic :: ISO_C_BINDING + + use constants, only: K_BOLTZMANN + use eigenvalue, only: k_sum + use global + + private + public :: openmc_cell_set_temperature + public :: openmc_reset + +contains + +!=============================================================================== +! OPENMC_CELL_SET_TEMPERATURE sets the temperature of a cell +!=============================================================================== + + function openmc_cell_set_temperature(id, T) result(err) bind(C) + integer(C_INT), value, intent(in) :: id ! id of cell + real(C_DOUBLE), value, intent(in) :: T + integer(C_INT) :: err + + integer :: i + + err = -1 + if (allocated(cells)) then + if (cell_dict % has_key(id)) then + i = cell_dict % get_key(id) + associate (c => cells(i)) + if (allocated(c % sqrtkT)) then + c % sqrtkT(:) = sqrt(K_BOLTZMANN * T) + err = 0 + end if + end associate + end if + end if + end function openmc_cell_set_temperature + +!=============================================================================== +! OPENMC_RESET resets all tallies +!=============================================================================== + + subroutine openmc_reset() bind(C) + integer :: i + + do i = 1, size(tallies) + tallies(i) % n_realizations = 0 + if (allocated(tallies(i) % results)) then + tallies(i) % results(:, :, :) = ZERO + end if + end do + + n_realizations = 0 + if (allocated(global_tallies)) then + global_tallies(:, :) = ZERO + end if + k_col_abs = ZERO + k_col_tra = ZERO + k_abs_tra = ZERO + k_sum(:) = ZERO + + end subroutine openmc_reset + +end module openmc_capi diff --git a/src/simulation.F90 b/src/simulation.F90 index 5423037508..8c4016f967 100644 --- a/src/simulation.F90 +++ b/src/simulation.F90 @@ -27,7 +27,7 @@ module simulation implicit none private - public :: openmc_run, openmc_reset + public :: openmc_run contains @@ -423,29 +423,4 @@ contains end subroutine reduce_overlap_count -!=============================================================================== -! OPENMC_RESET resets all tallies -!=============================================================================== - - subroutine openmc_reset() bind(C) - integer :: i - - do i = 1, size(tallies) - tallies(i) % n_realizations = 0 - if (allocated(tallies(i) % results)) then - tallies(i) % results(:, :, :) = ZERO - end if - end do - - n_realizations = 0 - if (allocated(global_tallies)) then - global_tallies(:, :) = ZERO - end if - k_col_abs = ZERO - k_col_tra = ZERO - k_abs_tra = ZERO - k_sum(:) = ZERO - - end subroutine openmc_reset - end module simulation