From 712352c8e1bc9cf427c223838f84b331aa0d140e Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Tue, 4 Jul 2017 15:06:33 -0500 Subject: [PATCH] Add optional instance argument for openmc_cell_set_temperature --- docs/source/capi/index.rst | 5 ++++- openmc/capi.py | 11 +++++++++-- src/api.F90 | 19 ++++++++++++++----- 3 files changed, 27 insertions(+), 8 deletions(-) diff --git a/docs/source/capi/index.rst b/docs/source/capi/index.rst index c932bcde9..4cc195ef2 100644 --- a/docs/source/capi/index.rst +++ b/docs/source/capi/index.rst @@ -8,7 +8,7 @@ C API Run a stochastic volume calculation -.. c:function:: int openmc_cell_set_temperature(int id, double T) +.. c:function:: int openmc_cell_set_temperature(int id, double T, int* instance) Set the temperature of a cell. @@ -16,6 +16,9 @@ C API :type id: int :param T: Temperature in Kelvin :type T: double + :param instance: Which instance of the cell. To set the temperature for all + instances, pass a null pointer. + :type instance: int* :return: Return status (negative if an error occurred) :rtype: int diff --git a/openmc/capi.py b/openmc/capi.py index 2df55abce..ea6f1e7c9 100644 --- a/openmc/capi.py +++ b/openmc/capi.py @@ -66,7 +66,7 @@ class OpenMCLibrary(object): """Run stochastic volume calculation""" return self._dll.openmc_calculate_volumes() - def cell_set_temperature(self, cell_id, T): + def cell_set_temperature(self, cell_id, T, instance=None): """Set the temperature of a cell Parameters @@ -75,9 +75,16 @@ class OpenMCLibrary(object): ID of the cell T : float Temperature in K + instance : int or None + Which instance of the cell """ - return self._dll.openmc_cell_set_temperature(cell_id, T) + if instance is not None: + return self._dll.openmc_cell_set_temperature( + cell_id, T, byref(c_int(instance))) + else: + return self._dll.openmc_cell_set_temperature(cell_id, T, None) + def finalize(self): """Finalize simulation and free memory""" diff --git a/src/api.F90 b/src/api.F90 index 72879f41f..444dc71f9 100644 --- a/src/api.F90 +++ b/src/api.F90 @@ -41,12 +41,13 @@ contains ! OPENMC_CELL_SET_TEMPERATURE sets the temperature of a cell !=============================================================================== - function openmc_cell_set_temperature(id, T) result(err) bind(C) + function openmc_cell_set_temperature(id, T, instance) result(err) bind(C) integer(C_INT), value, intent(in) :: id ! id of cell real(C_DOUBLE), value, intent(in) :: T + integer(C_INT), optional, intent(in) :: instance integer(C_INT) :: err - integer :: i + integer :: i, n err = -1 if (allocated(cells)) then @@ -54,8 +55,16 @@ contains i = cell_dict % get_key(id) associate (c => cells(i)) if (allocated(c % sqrtkT)) then - c % sqrtkT(:) = sqrt(K_BOLTZMANN * T) - err = 0 + n = size(c % sqrtkT) + if (present(instance) .and. n > 1) then + if (instance >= 0 .and. instance < n) then + c % sqrtkT(instance + 1) = sqrt(K_BOLTZMANN * T) + err = 0 + end if + else + c % sqrtkT(:) = sqrt(K_BOLTZMANN * T) + err = 0 + end if end if end associate end if @@ -92,7 +101,7 @@ contains id = materials(p % material) % id end if end if - instance = p % cell_instance + instance = p % cell_instance - 1 end if end subroutine openmc_find