diff --git a/include/openmc/capi.h b/include/openmc/capi.h index 5d07edb212..5e74446f1a 100644 --- a/include/openmc/capi.h +++ b/include/openmc/capi.h @@ -70,7 +70,8 @@ extern "C" { int openmc_next_batch(int* status); int openmc_nuclide_name(int index, const char** name); int openmc_plot_geometry(); - int openmc_id_map(const void* slice, int32_t* data_out); + int openmc_id_map(const void* slice, int32_t *data_out); + int openmc_property_map(void* slice, double *data_out); int openmc_reset(); int openmc_run(); void openmc_set_seed(int64_t new_seed); diff --git a/openmc/capi/plot.py b/openmc/capi/plot.py index 78fcef912c..e8d1c06b4c 100644 --- a/openmc/capi/plot.py +++ b/openmc/capi/plot.py @@ -218,3 +218,26 @@ def id_map(plot): _dll.openmc_id_map(POINTER(_PlotBase)(plot), img_data.ctypes.data_as(POINTER(c_int32))) return img_data + + +def property_map(plot): + """ + Generate a 2-D map of (cell_temperature, material_density). Used for + in-memory image generation. + + Parameters + ---------- + plot : An openmc.capi.plot._PlotBase object describing the slice of the + model to be generated + + Returns + ------- + property_map : a NumPy array with shape (vertical pixels, horizontal pixels, 2) + of OpenMC property ids with dtype float + + """ + prop_data = np.zeros((plot.vRes, plot.hRes, 2), + dtype=np.dtype('float')) + _dll.openmc_property_map(POINTER(_PlotBase)(plot), + prop_data.ctypes.data_as(POINTER(c_double))) + return prop_data diff --git a/src/plot.cpp b/src/plot.cpp index 95f7acad76..5a35ceb40c 100644 --- a/src/plot.cpp +++ b/src/plot.cpp @@ -46,7 +46,7 @@ struct id_setter { struct property_setter { void operator()(const Particle& p, PropertyData& props, int y, int x, int level) { Cell* c = model::cells[p.coord_[level].cell].get(); - props(y,x,0) = (p.sqrtkT_ * p.sqrtkT_) * K_BOLTZMANN; + props(y,x,0) = (p.sqrtkT_ * p.sqrtkT_) / K_BOLTZMANN; if (c->type_ == FILL_UNIVERSE || p.material_ == MATERIAL_VOID) { props(y,x, 1) = NOT_FOUND; } else { @@ -1075,4 +1075,22 @@ extern "C" int openmc_id_map(const void* plot, int32_t* data_out) return 0; } +extern "C" int openmc_property_map(void* plot, double* data_out) { + + auto plt = reinterpret_cast(plot); + if (!plt) { + set_errmsg("Invalid slice pointer passed to openmc_id_map"); + return OPENMC_E_INVALID_ARGUMENT; + } + + PropertyData data = plt->get_property_map(); + + // write id data to array + size_t i = 0; + for (auto v : data) { data_out[i++] = v; } + + return 0; +} + + } // namespace openmc diff --git a/tests/unit_tests/test_capi.py b/tests/unit_tests/test_capi.py index 97d18531bd..1d2fb2ecba 100644 --- a/tests/unit_tests/test_capi.py +++ b/tests/unit_tests/test_capi.py @@ -419,3 +419,24 @@ def test_id_map(capi_init): ids = openmc.capi.plot.id_map(s) assert np.array_equal(expected_ids, ids) + +def test_property_map(capi_init): + expected_properties = np.array( + [[(293.6, 0.740582), (293.6, 6.55), (293.6, 0.740582)], + [ (293.6, 6.55), (293.6, 10.29769), (293.6, 6.55)], + [(293.6, 0.740582), (293.6, 6.55), (293.6, 0.740582)]], dtype='float') + + # create a plot object + s = openmc.capi.plot._PlotBase() + s.width = 1.26 + s.height = 1.26 + s.vRes = 3 + s.hRes = 3 + s.origin = (0.0, 0.0, 0.0) + s.basis = 'xy' + s.level = -1 + + properties = openmc.capi.plot.property_map(s) + print(properties) + print(expected_properties) + assert np.allclose(expected_properties, properties, atol=1e-04)