From 0bba5833fb29402ee48c36dd483b855bf7cc8f9a Mon Sep 17 00:00:00 2001 From: aprilnovak Date: Thu, 4 Feb 2021 15:50:02 -0600 Subject: [PATCH] Allow set_contained to be passed through C-API for setting cell temperatures. Refs #1754 --- docs/source/capi/index.rst | 4 +++- include/openmc/capi.h | 2 +- openmc/lib/cell.py | 11 +++++++---- src/cell.cpp | 4 ++-- 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/docs/source/capi/index.rst b/docs/source/capi/index.rst index e77c70b1c5..eb6493e0e9 100644 --- a/docs/source/capi/index.rst +++ b/docs/source/capi/index.rst @@ -105,7 +105,7 @@ Functions :return: Return status (negative if an error occurred) :rtype: int -.. c:function:: int openmc_cell_set_temperature(index index, double T, const int32_t* instance) +.. c:function:: int openmc_cell_set_temperature(index index, double T, const int32_t* instance, bool set_contained) Set the temperature of a cell. @@ -113,6 +113,8 @@ Functions :param double T: Temperature in Kelvin :param instance: Which instance of the cell. To set the temperature for all instances, pass a null pointer. + :param set_contained: If the cell is not filled by a material, whether to set the temperatures + of all filled cells :type instance: const int32_t* :return: Return status (negative if an error occurred) :rtype: int diff --git a/include/openmc/capi.h b/include/openmc/capi.h index 8094a2e2f8..605d4040ba 100644 --- a/include/openmc/capi.h +++ b/include/openmc/capi.h @@ -18,7 +18,7 @@ extern "C" { int openmc_cell_set_name(int32_t index, const char* name); int openmc_cell_set_fill(int32_t index, int type, int32_t n, const int32_t* indices); int openmc_cell_set_id(int32_t index, int32_t id); - int openmc_cell_set_temperature(int32_t index, double T, const int32_t* instance); + int openmc_cell_set_temperature(int32_t index, double T, const int32_t* instance, bool set_contained = false); int openmc_energy_filter_get_bins(int32_t index, const double** energies, size_t* n); int openmc_energy_filter_set_bins(int32_t index, size_t n, const double* energies); int openmc_energyfunc_filter_get_energy(int32_t index, size_t* n, const double** energy); diff --git a/openmc/lib/cell.py b/openmc/lib/cell.py index 6ed3c7c7f7..5903a1075a 100644 --- a/openmc/lib/cell.py +++ b/openmc/lib/cell.py @@ -1,7 +1,7 @@ import sys from collections.abc import Mapping, Iterable -from ctypes import c_int, c_int32, c_double, c_char_p, POINTER +from ctypes import c_int, c_int32, c_double, c_char_p, POINTER, c_bool from weakref import WeakValueDictionary import numpy as np @@ -43,7 +43,7 @@ _dll.openmc_cell_set_id.argtypes = [c_int32, c_int32] _dll.openmc_cell_set_id.restype = c_int _dll.openmc_cell_set_id.errcheck = _error_handler _dll.openmc_cell_set_temperature.argtypes = [ - c_int32, c_double, POINTER(c_int32)] + c_int32, c_double, POINTER(c_int32), c_bool] _dll.openmc_cell_set_temperature.restype = c_int _dll.openmc_cell_set_temperature.errcheck = _error_handler _dll.openmc_get_cell_index.argtypes = [c_int32, POINTER(c_int32)] @@ -171,7 +171,7 @@ class Cell(_FortranObjectWithID): _dll.openmc_cell_get_temperature(self._index, instance, T) return T.value - def set_temperature(self, T, instance=None): + def set_temperature(self, T, instance=None, set_contained=False): """Set the temperature of a cell Parameters @@ -180,13 +180,16 @@ class Cell(_FortranObjectWithID): Temperature in K instance : int or None Which instance of the cell + set_contained: bool + If cell is not filled by a material, whether to set the temperature of + all filled cells """ if instance is not None: instance = c_int32(instance) - _dll.openmc_cell_set_temperature(self._index, T, instance) + _dll.openmc_cell_set_temperature(self._index, T, instance, set_contained) @property def bounding_box(self): diff --git a/src/cell.cpp b/src/cell.cpp index 418258d8b2..4b18319b64 100644 --- a/src/cell.cpp +++ b/src/cell.cpp @@ -1092,7 +1092,7 @@ openmc_cell_set_fill(int32_t index, int type, int32_t n, } extern "C" int -openmc_cell_set_temperature(int32_t index, double T, const int32_t* instance) +openmc_cell_set_temperature(int32_t index, double T, const int32_t* instance, bool set_contained) { if (index < 0 || index >= model::cells.size()) { strcpy(openmc_err_msg, "Index in cells array is out of bounds."); @@ -1101,7 +1101,7 @@ openmc_cell_set_temperature(int32_t index, double T, const int32_t* instance) int32_t instance_index = instance ? *instance : -1; try { - model::cells[index]->set_temperature(T, instance_index); + model::cells[index]->set_temperature(T, instance_index, set_contained); } catch (const std::exception& e) { set_errmsg(e.what()); return OPENMC_E_UNASSIGNED;