More updates. Adding complex cell test to unit tests.

This commit is contained in:
Patrick Shriwise 2019-07-18 18:14:57 -05:00
parent c1d8f06ac1
commit 72e92e9ad0
6 changed files with 99 additions and 35 deletions

View file

@ -14,7 +14,7 @@ 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_name(int32_t index, const char*& name);
int openmc_cell_get_name(int32_t index, const char** name);
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);
@ -60,7 +60,7 @@ extern "C" {
int openmc_material_set_density(int32_t index, double density, const char* units);
int openmc_material_set_densities(int32_t index, int n, const char** name, const double* density);
int openmc_material_set_id(int32_t index, int32_t id);
int openmc_material_get_name(int32_t index, const char*& name);
int openmc_material_get_name(int32_t index, const char** name);
int openmc_material_set_name(int32_t index, const char* name);
int openmc_material_set_volume(int32_t index, double volume);
int openmc_material_filter_get_bins(int32_t index, const int32_t** bins, size_t* n);

View file

@ -1085,14 +1085,13 @@ openmc_cell_get_temperature(int32_t index, const int32_t* instance, double* T)
//! Get the name of a cell
extern "C" int
openmc_cell_get_name(int32_t index, char** name) {
openmc_cell_get_name(int32_t index, const char** name) {
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;
}
auto name_str = model::cells[index]->name_;
strcpy(*name, name_str.c_str());
*name = model::cells[index]->name_.c_str();
return 0;
}

View file

@ -1382,14 +1382,13 @@ openmc_material_set_id(int32_t index, int32_t id)
}
extern "C" int
openmc_material_get_name(int32_t index, char** name) {
openmc_material_get_name(int32_t index, const char** name) {
if (index < 0 || index >= model::materials.size()) {
strcpy(openmc_err_msg, "Index in materials array is out of bounds.");
return OPENMC_E_OUT_OF_BOUNDS;
}
auto name_str = model::materials[index]->name();
strcpy(*name, name_str.c_str());
*name = model::materials[index]->name_.data();
return 0;
}

View file

@ -7,27 +7,3 @@ import openmc.capi
def test_complex_cell():
harness = TestHarness('statepoint.10.h5')
harness.main()
def test_complex_cell_capi():
# initialize
openmc.capi.init([])
inf = sys.float_info.max
expected_boxes = { 1 : (( -4., -4., -inf), ( 4., 4., inf)),
2 : (( -7., -7., -inf), ( 7., 7., inf)),
3 : ((-10., -10., -inf), (10., 10., inf)),
4 : ((-10., -10., -inf), (10., 10., inf)) }
for cell_id, cell in openmc.capi.cells.items():
cell_box = cell.bounding_box
assert tuple(cell_box[0]) == expected_boxes[cell_id][0]
assert tuple(cell_box[1]) == expected_boxes[cell_id][1]
cell_box = openmc.capi.bounding_box("Cell", cell_id)
assert tuple(cell_box[0]) == expected_boxes[cell_id][0]
assert tuple(cell_box[1]) == expected_boxes[cell_id][1]
openmc.capi.finalize()

View file

@ -479,9 +479,6 @@ def test_bounding_box(capi_init):
llc, urc = openmc.capi.bounding_box("Surface", 5)
print(llc)
print(urc)
assert tuple(llc) == expected_llc
assert tuple(urc) == expected_urc

View file

@ -0,0 +1,93 @@
import sys
import numpy as np
import openmc.capi
def test_complex_cell(run_in_tmpdir):
openmc.reset_auto_ids()
model = openmc.model.Model()
u235 = openmc.Material()
u235.set_density('g/cc', 4.5)
u235.add_nuclide("U235", 1.0)
u238 = openmc.Material()
u238.set_density('g/cc', 4.5)
u238.add_nuclide("U238", 1.0)
zr90 = openmc.Material()
zr90.set_density('g/cc', 2.0)
zr90.add_nuclide("Zr90", 1.0)
n14 = openmc.Material()
n14.set_density('g/cc', 0.1)
n14.add_nuclide("N14", 1.0)
model.materials = (u235, u238, zr90, n14)
s1 = openmc.XPlane(x0=-10.0, boundary_type='vacuum')
s2 = openmc.XPlane(x0=-7.0)
s3 = openmc.XPlane(x0=-4.0)
s4 = openmc.XPlane(x0=4.0)
s5 = openmc.XPlane(x0=7.0)
s6 = openmc.XPlane(x0=10.0, boundary_type='vacuum')
s7 = openmc.XPlane(x0=0.0)
s11 = openmc.YPlane(y0=-10.0, boundary_type='vacuum')
s12 = openmc.YPlane(y0=-7.0)
s13 = openmc.YPlane(y0=-4.0)
s14 = openmc.YPlane(y0=4.0)
s15 = openmc.YPlane(y0=7.0)
s16 = openmc.YPlane(y0=10.0, boundary_type='vacuum')
s17 = openmc.YPlane(y0=0.0)
c1 = openmc.Cell(fill=u235)
c1.region = +s3 & -s4 & +s13 & -s14
c2 = openmc.Cell(fill=u238)
c2.region = +s2 & -s5 & +s12 & -s15 & ~(+s3 & -s4 & +s13 & -s14)
c3 = openmc.Cell(fill=zr90)
c3.region = ((+s1 & -s7 & +s17 & -s16) | (+s7 & -s6 & +s11 & -s17)) & (-s2 | +s5 | -s12 | +s15)
c4 = openmc.Cell(fill=n14)
c4.region = ((+s1 & -s7 & +s11 & -s17) | (+s7 & -s6 & +s17 & -s16)) & ~(+s2 & -s5 & +s12 & -s15)
model.geometry.root_universe = openmc.Universe()
model.geometry.root_universe.add_cells([c1, c2, c3, c4])
model.settings.batches = 10
model.settings.inactive = 5
model.settings.particles = 100
model.settings.source = openmc.Source(space=openmc.stats.Box(
[-10., -10., -1.], [10., 10., 1.]))
model.settings.verbosity = 1
model.export_to_xml()
openmc.capi.finalize()
openmc.capi.init()
inf = sys.float_info.max
expected_boxes = { 1 : (( -4., -4., -inf), ( 4., 4., inf)),
2 : (( -7., -7., -inf), ( 7., 7., inf)),
3 : ((-10., -10., -inf), (10., 10., inf)),
4 : ((-10., -10., -inf), (10., 10., inf)) }
for cell_id, cell in openmc.capi.cells.items():
cell_box = cell.bounding_box
assert tuple(cell_box[0]) == expected_boxes[cell_id][0]
assert tuple(cell_box[1]) == expected_boxes[cell_id][1]
cell_box = openmc.capi.bounding_box("Cell", cell_id)
assert tuple(cell_box[0]) == expected_boxes[cell_id][0]
assert tuple(cell_box[1]) == expected_boxes[cell_id][1]
openmc.capi.finalize()