From 1e7271d0b4792c86c9443a1d1ab3c8a713ca67ed Mon Sep 17 00:00:00 2001 From: Patrick Shriwise Date: Fri, 8 Mar 2019 09:23:33 -0600 Subject: [PATCH] Going back to PlotBase. Makes more sense as Plot inherits from it. --- include/openmc/plot.h | 4 ++-- openmc/capi/plot.py | 16 ++++++++-------- src/plot.cpp | 36 ++++++++++++++++++------------------ 3 files changed, 28 insertions(+), 28 deletions(-) diff --git a/include/openmc/plot.h b/include/openmc/plot.h index a5fa4b065..c6ad951cb 100644 --- a/include/openmc/plot.h +++ b/include/openmc/plot.h @@ -73,7 +73,7 @@ enum class PlotColorBy { //=============================================================================== // Plot class //=============================================================================== -struct Slice { +struct PlotBase { // Members Position origin_; //!< Plot origin in geometry Position width_; //!< Plot width in geometry @@ -82,7 +82,7 @@ struct Slice { int level_; //!< Plot universe level }; -class Plot : public Slice +class Plot : public PlotBase { public: diff --git a/openmc/capi/plot.py b/openmc/capi/plot.py index c66ab076e..d66c62746 100644 --- a/openmc/capi/plot.py +++ b/openmc/capi/plot.py @@ -64,8 +64,8 @@ class _Position(Structure): return "Position: ({}, {}, {})".format(self.x, self.y, self.z) -class _Slice(Structure): - """A structure defining a 2-D slice with underlying c-types +class _PlotBase(Structure): + """A structure defining a 2-D geometry slice with underlying c-types C-Type Attributes ----------------- @@ -212,20 +212,20 @@ class _Slice(Structure): return self.__repr__() -_dll.openmc_id_map.argtypes = [POINTER(_Slice), POINTER(c_int32)] +_dll.openmc_id_map.argtypes = [POINTER(_PlotBase), POINTER(c_int32)] _dll.openmc_id_map.restype = c_int _dll.openmc_id_map.errcheck = _error_handler -def id_map(slice_view): +def id_map(plot): """ Generate a 2-D map of (cell_id, material_id). Used for in-memory image generation. Parameters ---------- - plot : An openmc.capi.plot._Slice object describing the slice of the model - to be generated + plot : An openmc.capi.plot._PlotBase object describing the slice of the + model to be generated Returns ------- @@ -233,8 +233,8 @@ def id_map(slice_view): of OpenMC property ids with dtype int32 """ - img_data = np.zeros((slice_view.vRes, slice_view.hRes, 2), + img_data = np.zeros((plot.vRes, plot.hRes, 2), dtype=np.dtype('int32')) - _dll.openmc_id_map(POINTER(_Slice)(slice_view), + _dll.openmc_id_map(POINTER(_PlotBase)(plot), img_data.ctypes.data_as(POINTER(c_int32))) return img_data diff --git a/src/plot.cpp b/src/plot.cpp index b5b91adba..2dbf0b6f7 100644 --- a/src/plot.cpp +++ b/src/plot.cpp @@ -952,20 +952,20 @@ RGBColor random_color() { return {int(prn()*255), int(prn()*255), int(prn()*255)}; } -extern "C" int openmc_id_map(void* slice, int32_t* data_out) { +extern "C" int openmc_id_map(void* plot, int32_t* data_out) { - auto sl = reinterpret_cast(slice); - if (!sl) { + auto plt = reinterpret_cast(plot); + if (!plt) { set_errmsg("Invalid slice pointer passed to openmc_id_map"); return OPENMC_E_INVALID_ARGUMENT; } - size_t width = sl->pixels_[0]; - size_t height = sl->pixels_[1]; + size_t width = plt->pixels_[0]; + size_t height = plt->pixels_[1]; // get pixel size - double in_pixel = (sl->width_[0])/static_cast(width); - double out_pixel = (sl->width_[1])/static_cast(height); + double in_pixel = (plt->width_[0])/static_cast(width); + double out_pixel = (plt->width_[1])/static_cast(height); // size data array IDData data; @@ -974,27 +974,27 @@ extern "C" int openmc_id_map(void* slice, int32_t* data_out) { // setup basis indices and initial position centered on pixel int in_i, out_i; double xyz[3]; - switch(sl->basis_) { + switch(plt->basis_) { case PlotBasis::xy : in_i = 0; out_i = 1; - xyz[0] = sl->origin_[0] - sl->width_[0] / 2. + in_pixel / 2.; - xyz[1] = sl->origin_[1] + sl->width_[1] / 2. - out_pixel / 2.; - xyz[2] = sl->origin_[2]; + xyz[0] = plt->origin_[0] - plt->width_[0] / 2. + in_pixel / 2.; + xyz[1] = plt->origin_[1] + plt->width_[1] / 2. - out_pixel / 2.; + xyz[2] = plt->origin_[2]; break; case PlotBasis::xz : in_i = 0; out_i = 2; - xyz[0] = sl->origin_[0] - sl->width_[0] / 2. + in_pixel / 2.; - xyz[1] = sl->origin_[1]; - xyz[2] = sl->origin_[2] + sl->width_[1] / 2. - out_pixel / 2.; + xyz[0] = plt->origin_[0] - plt->width_[0] / 2. + in_pixel / 2.; + xyz[1] = plt->origin_[1]; + xyz[2] = plt->origin_[2] + plt->width_[1] / 2. - out_pixel / 2.; break; case PlotBasis::yz : in_i = 1; out_i = 2; - xyz[0] = sl->origin_[0]; - xyz[1] = sl->origin_[1] - sl->width_[0] / 2. + in_pixel / 2.; - xyz[2] = sl->origin_[2] + sl->width_[1] / 2. - out_pixel / 2.; + xyz[0] = plt->origin_[0]; + xyz[1] = plt->origin_[1] - plt->width_[0] / 2. + in_pixel / 2.; + xyz[2] = plt->origin_[2] + plt->width_[1] / 2. - out_pixel / 2.; break; } @@ -1007,7 +1007,7 @@ extern "C" int openmc_id_map(void* slice, int32_t* data_out) { p.r() = xyz; p.u() = dir; p.coord_[0].universe = model::root_universe; - int level = sl->level_; + int level = plt->level_; int j{}; #pragma omp for