mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-27 21:55:41 -04:00
Added a set/get_translation attribute to the Cell C-API interface. This is also tested.
This commit is contained in:
parent
c373d9548f
commit
1d8f4c922e
4 changed files with 65 additions and 0 deletions
|
|
@ -14,12 +14,14 @@ extern "C" {
|
|||
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_get_translation(int32_t index, double xyz[]);
|
||||
int openmc_cell_get_name(int32_t index, const char** name);
|
||||
int openmc_cell_get_num_instances(int32_t index, int32_t* num_instances);
|
||||
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, bool set_contained = false);
|
||||
int openmc_cell_set_translation(int32_t index, const double xyz[]);
|
||||
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);
|
||||
|
|
|
|||
|
|
@ -35,6 +35,9 @@ _dll.openmc_cell_get_temperature.errcheck = _error_handler
|
|||
_dll.openmc_cell_get_name.argtypes = [c_int32, POINTER(c_char_p)]
|
||||
_dll.openmc_cell_get_name.restype = c_int
|
||||
_dll.openmc_cell_get_name.errcheck = _error_handler
|
||||
_dll.openmc_cell_get_translation.argtypes = [c_int32, POINTER(c_double)]
|
||||
_dll.openmc_cell_get_translation.restype = c_int
|
||||
_dll.openmc_cell_get_translation.errcheck = _error_handler
|
||||
_dll.openmc_cell_set_name.argtypes = [c_int32, c_char_p]
|
||||
_dll.openmc_cell_set_name.restype = c_int
|
||||
_dll.openmc_cell_set_name.errcheck = _error_handler
|
||||
|
|
@ -49,6 +52,9 @@ _dll.openmc_cell_set_temperature.argtypes = [
|
|||
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_cell_set_translation.argtypes = [c_int32, POINTER(c_double)]
|
||||
_dll.openmc_cell_set_translation.restype = c_int
|
||||
_dll.openmc_cell_set_translation.errcheck = _error_handler
|
||||
_dll.openmc_get_cell_index.argtypes = [c_int32, POINTER(c_int32)]
|
||||
_dll.openmc_get_cell_index.restype = c_int
|
||||
_dll.openmc_get_cell_index.errcheck = _error_handler
|
||||
|
|
@ -213,6 +219,29 @@ class Cell(_FortranObjectWithID):
|
|||
|
||||
_dll.openmc_cell_set_temperature(self._index, T, instance, set_contained)
|
||||
|
||||
def get_translation(self):
|
||||
"""Get the translation vector of a cell
|
||||
|
||||
"""
|
||||
|
||||
translation = np.zeros(3)
|
||||
_dll.openmc_cell_get_translation(
|
||||
self._index, translation.ctypes.data_as(POINTER(c_double)))
|
||||
return translation
|
||||
|
||||
def set_translation(self, translation):
|
||||
"""Set the translation vector of a cell
|
||||
|
||||
Parameters
|
||||
----------
|
||||
translation : numpy.ndarray
|
||||
3-D translation vector
|
||||
|
||||
"""
|
||||
|
||||
_dll.openmc_cell_set_translation(
|
||||
self._index, translation.ctypes.data_as(POINTER(c_double)))
|
||||
|
||||
@property
|
||||
def bounding_box(self):
|
||||
inf = sys.float_info.max
|
||||
|
|
|
|||
28
src/cell.cpp
28
src/cell.cpp
|
|
@ -1299,6 +1299,34 @@ openmc_cell_set_id(int32_t index, int32_t id)
|
|||
}
|
||||
}
|
||||
|
||||
//! Return the translation vector of a cell
|
||||
extern "C" int openmc_cell_get_translation(int32_t index, double xyz[])
|
||||
{
|
||||
if (index >= 0 && index < model::cells.size()) {
|
||||
auto& cell = openmc::model::cells[index];
|
||||
xyz[0] = cell->translation_.x;
|
||||
xyz[1] = cell->translation_.y;
|
||||
xyz[2] = cell->translation_.z;
|
||||
return 0;
|
||||
} else {
|
||||
set_errmsg("Index in cells array is out of bounds.");
|
||||
return OPENMC_E_OUT_OF_BOUNDS;
|
||||
}
|
||||
}
|
||||
|
||||
//! Set the translation vector of a cell
|
||||
extern "C" int openmc_cell_set_translation(int32_t index, const double xyz[])
|
||||
{
|
||||
if (index >= 0 && index < model::cells.size()) {
|
||||
model::cells[index]->translation_ = Position(xyz);
|
||||
return 0;
|
||||
} else {
|
||||
set_errmsg("Index in cells array is out of bounds.");
|
||||
return OPENMC_E_OUT_OF_BOUNDS;
|
||||
}
|
||||
}
|
||||
|
||||
//! Get the number of instances of the requested cell
|
||||
extern "C" int
|
||||
openmc_cell_get_num_instances(int32_t index, int32_t* num_instances)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -141,6 +141,12 @@ def test_properties_temperature(lib_init):
|
|||
openmc.lib.import_properties('properties.h5')
|
||||
assert cell.get_temperature() == pytest.approx(200.0)
|
||||
|
||||
def test_cell_translation(lib_init):
|
||||
cell = openmc.lib.cells[1]
|
||||
assert cell.get_translation() == pytest.approx([0., 0., 0.])
|
||||
cell.set_translation(np.array([1., 0., -1.]))
|
||||
assert cell.get_translation() == pytest.approx([1., 0., -1.])
|
||||
|
||||
|
||||
def test_new_cell(lib_init):
|
||||
with pytest.raises(exc.AllocationError):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue