From 7d7d9b9f0db6cde385104398b4c65b1e1b211e4d Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Tue, 30 Apr 2019 23:23:46 -0500 Subject: [PATCH 1/5] Fix for latest pip. --- tools/ci/travis-install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/ci/travis-install.sh b/tools/ci/travis-install.sh index 2bca50e4b4..51e45f64b3 100755 --- a/tools/ci/travis-install.sh +++ b/tools/ci/travis-install.sh @@ -23,7 +23,7 @@ fi python tools/ci/travis-install.py # Install Python API in editable mode -pip install -e .[test,vtk] +pip install --no-use-pep517 -e .[test,vtk] # For uploading to coveralls pip install coveralls From 1086b6cada1a4452dafba8a86e474c927fa97839 Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Tue, 7 May 2019 06:59:41 -0500 Subject: [PATCH 2/5] Remove --no-use-pep517 on pip install -e --- tools/ci/travis-install.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/ci/travis-install.sh b/tools/ci/travis-install.sh index 51e45f64b3..2bca50e4b4 100755 --- a/tools/ci/travis-install.sh +++ b/tools/ci/travis-install.sh @@ -23,7 +23,7 @@ fi python tools/ci/travis-install.py # Install Python API in editable mode -pip install --no-use-pep517 -e .[test,vtk] +pip install -e .[test,vtk] # For uploading to coveralls pip install coveralls From 2a2b7e9b3ccfae7078e3c6aac8de882b97252828 Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Mon, 6 May 2019 18:05:04 -0500 Subject: [PATCH 3/5] Fix bug in Plot.__repr__ --- openmc/plots.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openmc/plots.py b/openmc/plots.py index eb582502e4..00d96fd7ee 100644 --- a/openmc/plots.py +++ b/openmc/plots.py @@ -439,7 +439,7 @@ class Plot(IDManagerMixin): string += '{: <16}=\t{}\n'.format('\tBasis', self._basis) string += '{: <16}=\t{}\n'.format('\tWidth', self._width) string += '{: <16}=\t{}\n'.format('\tOrigin', self._origin) - string += '{: <16}=\t{}\n'.format('\tPixels', self._origin) + string += '{: <16}=\t{}\n'.format('\tPixels', self._pixels) string += '{: <16}=\t{}\n'.format('\tColor by', self._color_by) string += '{: <16}=\t{}\n'.format('\tBackground', self._background) string += '{: <16}=\t{}\n'.format('\tMask components', From 18b225f14d9ba2b19a565b8c706d36e028300dd1 Mon Sep 17 00:00:00 2001 From: aprilnovak Date: Mon, 29 Apr 2019 15:40:57 -0700 Subject: [PATCH 4/5] Add openmc_cell_get_temperature method. Refs #1223 --- docs/source/capi/index.rst | 11 +++++++++++ include/openmc/capi.h | 1 + openmc/capi/cell.py | 21 +++++++++++++++++++++ src/cell.cpp | 30 ++++++++++++++++++++++++++++++ 4 files changed, 63 insertions(+) diff --git a/docs/source/capi/index.rst b/docs/source/capi/index.rst index 85e5c8ced3..274a5240f0 100644 --- a/docs/source/capi/index.rst +++ b/docs/source/capi/index.rst @@ -73,6 +73,17 @@ Functions :return: Return status (negative if an error occurred) :rtype: int +.. c:function:: int openmc_cell_get_temperature(int32_t index, const int32_t* instance, double* T) + + Get the temperature of a cell + + :param int32_t index: Index in the cells array + :param int32_t* instance: Which instance of the cell. If a null pointer is passed, the temperature + of the first instance is returned. + :param double* T: temperature of the cell + :return: Return status (negative if an error occurred) + :rtype: int + .. c:function:: int openmc_cell_set_fill(int32_t index, int type, int32_t n, const int32_t* indices) Set the fill for a cell diff --git a/include/openmc/capi.h b/include/openmc/capi.h index 8815d243ab..1f6686df1a 100644 --- a/include/openmc/capi.h +++ b/include/openmc/capi.h @@ -13,6 +13,7 @@ extern "C" { int openmc_cell_filter_get_bins(int32_t index, int32_t** cells, int32_t* n); int openmc_cell_get_fill(int32_t index, int* type, int32_t** indices, int32_t* n); int openmc_cell_get_id(int32_t index, int32_t* id); + int openmc_cell_get_temperature(int32_t index, const int32_t* instance, double* T); 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); diff --git a/openmc/capi/cell.py b/openmc/capi/cell.py index 7ad5c75d7c..ae536e7251 100644 --- a/openmc/capi/cell.py +++ b/openmc/capi/cell.py @@ -24,6 +24,10 @@ _dll.openmc_cell_get_fill.argtypes = [ c_int32, POINTER(c_int), POINTER(POINTER(c_int32)), POINTER(c_int32)] _dll.openmc_cell_get_fill.restype = c_int _dll.openmc_cell_get_fill.errcheck = _error_handler +_dll.openmc_cell_get_temperature.argtypes = [ + c_int32, POINTER(c_int32), POINTER(c_double)] +_dll.openmc_cell_get_temperature.restype = c_int +_dll.openmc_cell_get_temperature.errcheck = _error_handler _dll.openmc_cell_set_fill.argtypes = [ c_int32, c_int, c_int32, POINTER(c_int32)] _dll.openmc_cell_set_fill.restype = c_int @@ -128,6 +132,23 @@ class Cell(_FortranObjectWithID): indices = (c_int32*1)(-1) _dll.openmc_cell_set_fill(self._index, 1, 1, indices) + def get_temperature(self, instance=None): + """Get the temperature of a cell + + Parameters + ---------- + instance: int or None + Which instance of the cell + + """ + + if instance is not None: + instance = c_int32(instance) + + T = c_double() + _dll.openmc_cell_get_temperature(self._index, instance, T) + return T.value + def set_temperature(self, T, instance=None): """Set the temperature of a cell diff --git a/src/cell.cpp b/src/cell.cpp index 59057e0840..650a18a8a0 100644 --- a/src/cell.cpp +++ b/src/cell.cpp @@ -922,6 +922,36 @@ openmc_cell_set_temperature(int32_t index, double T, const int32_t* instance) return 0; } +extern "C" int +openmc_cell_get_temperature(int32_t index, const int32_t* instance, double* T) +{ + if (index < 0 || index >= model::cells.size()) { + strcpy(openmc_err_msg, "Index in cells array is out of bounds."); + return OPENMC_E_OUT_OF_BOUNDS; + } + + Cell& c {*model::cells[index]}; + + if (c.sqrtkT_.size() < 1) { + strcpy(openmc_err_msg, "Cell temperature has not yet been set."); + return OPENMC_E_UNASSIGNED; + } + + if (instance) { + if (*instance >= 0 && *instance < c.n_instances_) { + double sqrtkT = c.sqrtkT_.size() == 1 ? c.sqrtkT_[0] : c.sqrtkT_[*instance]; + *T = sqrtkT * sqrtkT / K_BOLTZMANN; + } else { + strcpy(openmc_err_msg, "Distribcell instance is out of bounds."); + return OPENMC_E_OUT_OF_BOUNDS; + } + } else { + *T = c.sqrtkT_[0] * c.sqrtkT_[0] / K_BOLTZMANN; + } + + return 0; +} + //! Return the index in the cells array of a cell with a given ID extern "C" int openmc_get_cell_index(int32_t id, int32_t* index) From 3cb99504fcd352423314765208dbebeecd49b18e Mon Sep 17 00:00:00 2001 From: aprilnovak Date: Mon, 6 May 2019 13:38:07 -0700 Subject: [PATCH 5/5] Unit tests for getting and setting cell temperature. Refs #1223 --- openmc/capi/cell.py | 8 ++++++-- tests/unit_tests/test_capi.py | 8 ++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/openmc/capi/cell.py b/openmc/capi/cell.py index ae536e7251..959ab08fcf 100644 --- a/openmc/capi/cell.py +++ b/openmc/capi/cell.py @@ -143,7 +143,7 @@ class Cell(_FortranObjectWithID): """ if instance is not None: - instance = c_int32(instance) + instance = c_int32(instance) T = c_double() _dll.openmc_cell_get_temperature(self._index, instance, T) @@ -160,7 +160,11 @@ class Cell(_FortranObjectWithID): Which instance of the cell """ - _dll.openmc_cell_set_temperature(self._index, T, c_int32(instance)) + + if instance is not None: + instance = c_int32(instance) + + _dll.openmc_cell_set_temperature(self._index, T, instance) class _CellMapping(Mapping): diff --git a/tests/unit_tests/test_capi.py b/tests/unit_tests/test_capi.py index be88072d9f..07fef85166 100644 --- a/tests/unit_tests/test_capi.py +++ b/tests/unit_tests/test_capi.py @@ -75,6 +75,14 @@ def test_cell(capi_init): assert str(cell) == 'Cell[0]' +def test_cell_temperature(capi_init): + cell = openmc.capi.cells[1] + cell.set_temperature(100.0, 0) + assert cell.get_temperature(0) == 100.0 + cell.set_temperature(200) + assert cell.get_temperature() == 200.0 + + def test_new_cell(capi_init): with pytest.raises(exc.AllocationError): openmc.capi.Cell(1)