Populate C++ Universe vector

This commit is contained in:
Sterling Harper 2018-03-02 02:12:31 -05:00
parent 762313943d
commit a69baeaed5
4 changed files with 43 additions and 11 deletions

View file

@ -5,6 +5,7 @@
#include <sstream>
#include <string>
#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);
}
}
}
//==============================================================================

View file

@ -21,8 +21,11 @@ extern "C" {int32_t n_cells {0};}
class Cell;
std::vector<Cell*> cells_c;
std::map<int32_t, int32_t> cell_dict;
std::map<int, int> cell_dict;
class Universe;
std::vector<Universe*> universes_c;
std::map<int32_t, int32_t> universe_dict;
//==============================================================================
//! A geometry primitive that fills all space and contains cells.
@ -30,10 +33,10 @@ std::map<int, int> cell_dict;
class Universe
{
public:
public:
int32_t id; //! Unique ID
int32_t type;
std::vector<int32_t> cells; //! Cells within this universe
std::vector<Cell*> 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<std::int32_t> region;

13
src/constants.h Normal file
View file

@ -0,0 +1,13 @@
#ifndef CONSTANTS_H
#define CONSTANTS_H
namespace openmc{
extern "C" double FP_COINCIDENT;
constexpr double INFTY{std::numeric_limits<double>::max()};
constexpr int C_NONE {-1};
} // namespace openmc
#endif // CONSTANTS_H

View file

@ -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<double>::max()};
constexpr int C_NONE {-1};
//==============================================================================
// Global variables
//==============================================================================