From a69baeaed55d8a738e25907ebd1380ee9a0e5333 Mon Sep 17 00:00:00 2001 From: Sterling Harper Date: Fri, 2 Mar 2018 02:12:31 -0500 Subject: [PATCH] Populate C++ Universe vector --- src/cell.cpp | 21 +++++++++++++++++++++ src/cell.h | 10 +++++++--- src/constants.h | 13 +++++++++++++ src/surface.h | 10 ++-------- 4 files changed, 43 insertions(+), 11 deletions(-) create mode 100644 src/constants.h diff --git a/src/cell.cpp b/src/cell.cpp index fe04f8c69..136f36e06 100644 --- a/src/cell.cpp +++ b/src/cell.cpp @@ -5,6 +5,7 @@ #include #include +#include "constants.h" #include "error.h" #include "hdf5_interface.h" #include "surface.h" @@ -204,6 +205,12 @@ Cell::Cell(pugi::xml_node cell_node) universe = 0; } + if (check_for_node(cell_node, "fill")) { + fill = stoi(get_node_value(cell_node, "fill")); + } else { + fill = C_NONE; + } + std::string region_spec {""}; if (check_for_node(cell_node, "region")) { region_spec = get_node_value(cell_node, "region"); @@ -405,6 +412,20 @@ read_cells(pugi::xml_node *node) for (pugi::xml_node cell_node: node->children("cell")) { cells_c.push_back(new Cell(cell_node)); } + + // Populate the Universe vector and dictionary. + for (Cell *c : cells_c) { + int32_t uid = c->universe; + auto it = universe_dict.find(uid); + if (it == universe_dict.end()) { + universes_c.push_back(new Universe()); + universes_c.back()->id = uid; + universes_c.back()->cells.push_back(c); + universe_dict[uid] = universes_c.size() - 1; + } else { + universes_c[it->second]->cells.push_back(c); + } + } } //============================================================================== diff --git a/src/cell.h b/src/cell.h index de5e25aa7..8b540be35 100644 --- a/src/cell.h +++ b/src/cell.h @@ -21,8 +21,11 @@ extern "C" {int32_t n_cells {0};} class Cell; std::vector cells_c; +std::map cell_dict; -std::map cell_dict; +class Universe; +std::vector universes_c; +std::map universe_dict; //============================================================================== //! A geometry primitive that fills all space and contains cells. @@ -30,10 +33,10 @@ std::map cell_dict; class Universe { - public: +public: int32_t id; //! Unique ID int32_t type; - std::vector cells; //! Cells within this universe + std::vector cells; //! Cells within this universe double x0, y0, z0; //! Translation coordinates. }; @@ -47,6 +50,7 @@ public: int32_t id; //!< Unique ID std::string name{""}; //!< User-defined name int32_t universe; //!< Universe # this cell is in + int32_t fill; //!< Universe # filling this cell //! Definition of spatial region as Boolean expression of half-spaces std::vector region; diff --git a/src/constants.h b/src/constants.h new file mode 100644 index 000000000..b725809fe --- /dev/null +++ b/src/constants.h @@ -0,0 +1,13 @@ +#ifndef CONSTANTS_H +#define CONSTANTS_H + + +namespace openmc{ + +extern "C" double FP_COINCIDENT; +constexpr double INFTY{std::numeric_limits::max()}; +constexpr int C_NONE {-1}; + +} // namespace openmc + +#endif // CONSTANTS_H diff --git a/src/surface.h b/src/surface.h index 046610daa..2be21c063 100644 --- a/src/surface.h +++ b/src/surface.h @@ -8,6 +8,8 @@ #include "hdf5.h" #include "pugixml/pugixml.hpp" +#include "constants.h" + namespace openmc { @@ -20,14 +22,6 @@ extern "C" const int BC_VACUUM; extern "C" const int BC_REFLECT; extern "C" const int BC_PERIODIC; -//============================================================================== -// Constants that should eventually be moved out of this file -//============================================================================== - -extern "C" double FP_COINCIDENT; -constexpr double INFTY{std::numeric_limits::max()}; -constexpr int C_NONE {-1}; - //============================================================================== // Global variables //==============================================================================