mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-27 21:55:41 -04:00
Updates to CAPI bounding box methods. Addition of global bounding box method. Adding tests for PWR pincell model.
This commit is contained in:
parent
2ac505814e
commit
a105702455
4 changed files with 92 additions and 14 deletions
|
|
@ -30,6 +30,7 @@ extern "C" {
|
|||
int openmc_finalize();
|
||||
int openmc_find_cell(const double* xyz, int32_t* index, int32_t* instance);
|
||||
int openmc_bounding_box(const char* geom_type, const int32_t id, double* llc, double* urc);
|
||||
int openmc_global_bounding_box(double* llc, double* urc);
|
||||
int openmc_fission_bank(void** ptr, int64_t* n);
|
||||
int openmc_get_cell_index(int32_t id, int32_t* index);
|
||||
int openmc_get_filter_index(int32_t id, int32_t* index);
|
||||
|
|
|
|||
|
|
@ -73,11 +73,23 @@ _dll.openmc_simulation_finalize.errcheck = _error_handler
|
|||
_dll.openmc_statepoint_write.argtypes = [c_char_p, POINTER(c_bool)]
|
||||
_dll.openmc_statepoint_write.restype = c_int
|
||||
_dll.openmc_statepoint_write.errcheck = _error_handler
|
||||
|
||||
_dll.openmc_bounding_box.argtypes = [c_char_p, c_int, POINTER(c_double),
|
||||
POINTER(c_double)]
|
||||
_dll.openmc_bounding_box.restype = c_int
|
||||
_dll.openmc_bounding_box.errcheck = _error_handler
|
||||
_dll.openmc_global_bounding_box.argtypes = [POINTER(c_double),
|
||||
POINTER(c_double)]
|
||||
_dll.openmc_global_bounding_box.restype = c_int
|
||||
_dll.openmc_global_bounding_box.errcheck = _error_handler
|
||||
|
||||
def global_bounding_box():
|
||||
|
||||
llc = np.zeros((3,), dtype=float)
|
||||
urc = np.zeros((3,), dtype=float)
|
||||
_dll.openmc_global_bounding_box(llc.ctypes.data_as(POINTER(c_double)),
|
||||
urc.ctypes.data_as(POINTER(c_double)))
|
||||
|
||||
return llc, urc
|
||||
|
||||
def bounding_box(geom_type, geom_id):
|
||||
|
||||
|
|
|
|||
|
|
@ -484,19 +484,18 @@ openmc_bounding_box(const char* geom_type, const int32_t id, double* llc, double
|
|||
std::string gtype(geom_type);
|
||||
to_lower(gtype);
|
||||
|
||||
std::cout << gtype << std::endl;
|
||||
|
||||
if (gtype == "universe") {
|
||||
// negative ids only apply to surfaces
|
||||
if (id < 0) { return OPENMC_E_GEOMETRY; }
|
||||
if (id <= 0) { return OPENMC_E_GEOMETRY; }
|
||||
const auto& u = model::universes[model::universe_map[id]];
|
||||
bbox = u->bounding_box();
|
||||
} else if (gtype == "cell") {
|
||||
// negative ids only apply to surfaces
|
||||
if (id < 0) { return OPENMC_E_GEOMETRY; }
|
||||
if (id <= 0) { return OPENMC_E_GEOMETRY; }
|
||||
const auto& c = model::cells[model::cell_map[id]];
|
||||
bbox = c->bounding_box();
|
||||
} else if (gtype == "surface") {
|
||||
if (id == 0) { return OPENMC_E_GEOMETRY; }
|
||||
const auto& s = model::surfaces[model::surface_map[abs(id)]];
|
||||
bbox = s->bounding_box(id > 0);
|
||||
} else {
|
||||
|
|
@ -518,4 +517,21 @@ openmc_bounding_box(const char* geom_type, const int32_t id, double* llc, double
|
|||
return 0;
|
||||
}
|
||||
|
||||
extern "C" int openmc_global_bounding_box(double* llc, double* urc) {
|
||||
auto bbox = model::universes[model::root_universe]->bounding_box();
|
||||
|
||||
// set lower left corner values
|
||||
llc[0] = bbox.xmin;
|
||||
llc[1] = bbox.ymin;
|
||||
llc[2] = bbox.zmin;
|
||||
|
||||
// set upper right corner values
|
||||
urc[0] = bbox.xmax;
|
||||
urc[1] = bbox.ymax;
|
||||
urc[2] = bbox.zmax;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
} // namespace openmc
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
from collections.abc import Mapping
|
||||
import os
|
||||
import sys
|
||||
|
||||
import numpy as np
|
||||
import pytest
|
||||
|
|
@ -472,15 +473,63 @@ def test_position(capi_init):
|
|||
|
||||
def test_bounding_box(capi_init):
|
||||
|
||||
expected_llc = (-0.63, -0.63, -np.inf)
|
||||
expected_urc = (0.63, 0.63, np.inf)
|
||||
inf = sys.float_info.max
|
||||
|
||||
llc, urc = openmc.capi.bounding_box("Universe", 0)
|
||||
expected_llc = (-inf, -0.63, -inf)
|
||||
expected_urc = (inf, inf, inf)
|
||||
|
||||
assert llc[0] == expected_llc[0]
|
||||
assert llc[1] == expected_llc[1]
|
||||
assert llc[2] < 1.0E10
|
||||
llc, urc = openmc.capi.bounding_box("Surface", 5)
|
||||
|
||||
assert urc[0] == expected_urc[0]
|
||||
assert urc[1] == expected_urc[1]
|
||||
assert urc[2] > 1.E10
|
||||
print(llc)
|
||||
print(urc)
|
||||
|
||||
assert tuple(llc) == expected_llc
|
||||
assert tuple(urc) == expected_urc
|
||||
|
||||
|
||||
expected_llc = (-inf, -inf, -inf)
|
||||
expected_urc = (inf, -0.63, inf)
|
||||
|
||||
llc, urc = openmc.capi.bounding_box("Surface", -5)
|
||||
|
||||
assert tuple(llc) == expected_llc
|
||||
assert tuple(urc) == expected_urc
|
||||
|
||||
expected_llc = (-0.39218, -0.39218, -inf)
|
||||
expected_urc = (0.39218, 0.39218, inf)
|
||||
|
||||
llc, urc = openmc.capi.bounding_box("Cell", 1)
|
||||
|
||||
assert tuple(llc) == expected_llc
|
||||
assert tuple(urc) == expected_urc
|
||||
|
||||
expected_llc = (-0.45720, -0.45720, -inf)
|
||||
expected_urc = (0.45720, 0.45720, inf)
|
||||
|
||||
llc, urc = openmc.capi.bounding_box("Cell", 2)
|
||||
|
||||
assert tuple(llc) == expected_llc
|
||||
assert tuple(urc) == expected_urc
|
||||
|
||||
# make sure that proper assertions are raised
|
||||
with pytest.raises(openmc.exceptions.GeometryError):
|
||||
openmc.capi.bounding_box("Cell", -1)
|
||||
|
||||
with pytest.raises(openmc.exceptions.GeometryError):
|
||||
openmc.capi.bounding_box("Surface", 0)
|
||||
|
||||
with pytest.raises(openmc.exceptions.GeometryError):
|
||||
openmc.capi.bounding_box("Region", 1)
|
||||
|
||||
|
||||
def test_global_bounding_box(capi_init):
|
||||
|
||||
inf = sys.float_info.max
|
||||
|
||||
expected_llc = (-0.63, -0.63, -inf)
|
||||
expected_urc = (0.63, 0.63, inf)
|
||||
|
||||
llc, urc = openmc.capi.global_bounding_box()
|
||||
|
||||
assert tuple(llc) == expected_llc
|
||||
assert tuple(urc) == expected_urc
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue