From 6393db8daa42b3d4f98dbd4212f1ad242ff3d194 Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Thu, 8 Nov 2018 15:14:01 -0600 Subject: [PATCH] Put plots in model namespace --- include/openmc/capi.h | 1 - include/openmc/plot.h | 18 +++++++++--------- src/output.cpp | 2 +- src/plot.cpp | 25 ++++++++++++++----------- 4 files changed, 24 insertions(+), 22 deletions(-) diff --git a/include/openmc/capi.h b/include/openmc/capi.h index ace061f54..a9c1a88f9 100644 --- a/include/openmc/capi.h +++ b/include/openmc/capi.h @@ -136,7 +136,6 @@ extern "C" { // Global variables extern char openmc_err_msg[256]; extern int n_nuclides; - extern int32_t n_plots; extern int32_t n_realizations; extern int32_t n_sab_tables; extern int32_t n_sources; diff --git a/include/openmc/plot.h b/include/openmc/plot.h index 64c092ce8..1096d2484 100644 --- a/include/openmc/plot.h +++ b/include/openmc/plot.h @@ -18,14 +18,14 @@ namespace openmc { // Global variables //=============================================================================== -extern int PLOT_LEVEL_LOWEST; //!< lower bound on plot universe level +class Plot; +namespace model { + +extern std::vector plots; //!< Plot instance container extern std::unordered_map plot_map; //!< map of plot ids to index -extern "C" int32_t n_plots; //!< number of plots in openmc run - -class Plot; -extern std::vector plots; //!< Plot instance container +} // namespace model //=============================================================================== // RGBColor holds color information for plotted objects @@ -124,8 +124,7 @@ void draw_mesh_lines(Plot pl, ImageData& data); //! Write a ppm image to file using a plot object's image data //! \param[in] plot object //! \param[out] image data associated with the plot object -void output_ppm(Plot pl, - const ImageData& data); +void output_ppm(Plot pl, const ImageData& data); //! Get the rgb color for a given particle position in a plot //! \param[in] particle with position for current pixel @@ -141,7 +140,7 @@ void position_rgb(Particle p, Plot pl, RGBColor& rgb, int& id); //! \param[out] dataset pointer to voxesl data //! \param[out] pointer to memory space of voxel data void voxel_init(hid_t file_id, const hsize_t* dims, hid_t* dspace, - hid_t* dset, hid_t* memspace); + hid_t* dset, hid_t* memspace); //! Write a section of the voxel data to hdf5 //! \param[in] voxel slice @@ -149,7 +148,8 @@ void voxel_init(hid_t file_id, const hsize_t* dims, hid_t* dspace, //! \param[out] dataset pointer to voxesl data //! \param[out] pointer to data to write void voxel_write_slice(int x, hid_t dspace, hid_t dset, - hid_t memspace, void* buf); + hid_t memspace, void* buf); + //! Close voxel file entities //! \param[in] data space to close //! \param[in] dataset to close diff --git a/src/output.cpp b/src/output.cpp index 6e07e2456..a3424a62f 100644 --- a/src/output.cpp +++ b/src/output.cpp @@ -62,7 +62,7 @@ void print_plot() { header("PLOTTING SUMMARY", 5); - for (auto pl : plots) { + for (auto pl : model::plots) { // Plot id std::cout << "Plot ID: " << pl.id_ << "\n"; // Plot filename diff --git a/src/plot.cpp b/src/plot.cpp index e372a678e..70dcd11b5 100644 --- a/src/plot.cpp +++ b/src/plot.cpp @@ -20,19 +20,23 @@ namespace openmc { +//============================================================================== +// Constants +//============================================================================== + +const RGBColor WHITE {255, 255, 255}; +constexpr int PLOT_LEVEL_LOWEST {-1}; //!< lower bound on plot universe level + //============================================================================== // Global variables //============================================================================== -int PLOT_LEVEL_LOWEST = -1; - -std::unordered_map plot_map; - -int n_plots; +namespace model { std::vector plots; +std::unordered_map plot_map; -const RGBColor WHITE = {255, 255, 255}; +} // namespace model //============================================================================== // RUN_PLOT controls the logic for making one or many plots @@ -43,7 +47,7 @@ int openmc_plot_geometry() { int err; - for (auto pl : plots) { + for (auto pl : model::plots) { std::stringstream ss; ss << "Processing plot " << pl.id_ << ": " << pl.path_plot_ << "..."; @@ -64,11 +68,10 @@ int openmc_plot_geometry() void read_plots(pugi::xml_node* plots_node) { - n_plots = 0; for (auto node : plots_node->children("plot")) { Plot pl(node); - plots.push_back(pl); - plot_map[pl.id_] = n_plots++; + model::plots.push_back(pl); + model::plot_map[pl.id_] = model::plots.size() - 1; } } @@ -156,7 +159,7 @@ Plot::set_id(pugi::xml_node plot_node) } // Check to make sure 'id' hasn't been used - if (plot_map.find(id_) != plot_map.end()) { + if (model::plot_map.find(id_) != model::plot_map.end()) { std::stringstream err_msg; err_msg << "Two or more plots use the same unique ID: " << id_; fatal_error(err_msg.str());