Remove global_ prefix from global geometry vectors

This commit is contained in:
Sterling Harper 2018-08-27 19:06:01 -04:00
parent 260bf843e8
commit 0e348e338b
12 changed files with 162 additions and 162 deletions

View file

@ -39,11 +39,11 @@ constexpr int32_t OP_UNION {std::numeric_limits<int32_t>::max() - 4};
extern "C" int32_t n_cells;
class Cell;
extern std::vector<Cell*> global_cells;
extern std::vector<Cell*> cells;
extern std::unordered_map<int32_t, int32_t> cell_map;
class Universe;
extern std::vector<Universe*> global_universes;
extern std::vector<Universe*> universes;
extern std::unordered_map<int32_t, int32_t> universe_map;
//==============================================================================

View file

@ -31,7 +31,7 @@ enum class LatticeType {
//==============================================================================
class Lattice;
extern std::vector<Lattice*> lattices_c;
extern std::vector<Lattice*> lattices;
extern std::unordered_map<int32_t, int32_t> lattice_map;

View file

@ -14,7 +14,7 @@ namespace openmc {
//==============================================================================
class Material;
extern std::vector<Material*> global_materials;
extern std::vector<Material*> materials;
extern std::unordered_map<int32_t, int32_t> material_map;
//==============================================================================

View file

@ -32,7 +32,7 @@ extern "C" const int BC_PERIODIC;
extern "C" int32_t n_surfaces;
class Surface;
extern std::vector<Surface*> global_surfaces;
extern std::vector<Surface*> surfaces;
extern std::map<int, int> surface_map;

View file

@ -24,10 +24,10 @@ namespace openmc {
int32_t n_cells {0};
std::vector<Cell*> global_cells;
std::vector<Cell*> cells;
std::unordered_map<int32_t, int32_t> cell_map;
std::vector<Universe*> global_universes;
std::vector<Universe*> universes;
std::unordered_map<int32_t, int32_t> universe_map;
//==============================================================================
@ -198,7 +198,7 @@ Universe::to_hdf5(hid_t universes_group) const
// Write the contained cells.
if (cells_.size() > 0) {
std::vector<int32_t> cell_ids;
for (auto i_cell : cells_) cell_ids.push_back(global_cells[i_cell]->id_);
for (auto i_cell : cells_) cell_ids.push_back(cells[i_cell]->id_);
write_dataset(group, "cells", cell_ids);
}
@ -417,7 +417,7 @@ Cell::distance(Position r, Direction u, int32_t on_surface) const
// Calculate the distance to this surface.
// Note the off-by-one indexing
bool coincident {token == on_surface};
double d {global_surfaces[abs(token)-1]->distance(r, u, coincident)};
double d {surfaces[abs(token)-1]->distance(r, u, coincident)};
// Check if this distance is the new minimum.
if (d < min_dist) {
@ -445,7 +445,7 @@ Cell::to_hdf5(hid_t cells_group) const
write_string(group, "name", name_, false);
}
write_dataset(group, "universe", global_universes[universe_]->id_);
write_dataset(group, "universe", universes[universe_]->id_);
// Write the region specification.
if (!region_.empty()) {
@ -463,7 +463,7 @@ Cell::to_hdf5(hid_t cells_group) const
} else {
// Note the off-by-one indexing
region_spec << " "
<< copysign(global_surfaces[abs(token)-1]->id_, token);
<< copysign(surfaces[abs(token)-1]->id_, token);
}
}
write_string(group, "region", region_spec.str(), false);
@ -475,7 +475,7 @@ Cell::to_hdf5(hid_t cells_group) const
std::vector<int32_t> mat_ids;
for (auto i_mat : material_) {
if (i_mat != MATERIAL_VOID) {
mat_ids.push_back(global_materials[i_mat]->id);
mat_ids.push_back(materials[i_mat]->id);
} else {
mat_ids.push_back(MATERIAL_VOID);
}
@ -493,7 +493,7 @@ Cell::to_hdf5(hid_t cells_group) const
} else if (type_ == FILL_UNIVERSE) {
write_dataset(group, "fill_type", "universe");
write_dataset(group, "fill", global_universes[fill_]->id_);
write_dataset(group, "fill", universes[fill_]->id_);
if (translation_ != Position(0, 0, 0)) {
write_dataset(group, "translation", translation_);
}
@ -504,7 +504,7 @@ Cell::to_hdf5(hid_t cells_group) const
} else if (type_ == FILL_LATTICE) {
write_dataset(group, "fill_type", "lattice");
write_dataset(group, "lattice", lattices_c[fill_]->id_);
write_dataset(group, "lattice", lattices[fill_]->id_);
}
close_group(group);
@ -526,7 +526,7 @@ Cell::contains_simple(Position r, Direction u, int32_t on_surface) const
return false;
} else {
// Note the off-by-one indexing
bool sense = global_surfaces[abs(token)-1]->sense(r, u);
bool sense = surfaces[abs(token)-1]->sense(r, u);
if (sense != (token > 0)) {return false;}
}
}
@ -568,7 +568,7 @@ Cell::contains_complex(Position r, Direction u, int32_t on_surface) const
stack[i_stack] = false;
} else {
// Note the off-by-one indexing
bool sense = global_surfaces[abs(token)-1]->sense(r, u);
bool sense = surfaces[abs(token)-1]->sense(r, u);
stack[i_stack] = (sense == (token > 0));
}
}
@ -599,25 +599,25 @@ read_cells(pugi::xml_node* node)
}
// Loop over XML cell elements and populate the array.
global_cells.reserve(n_cells);
cells.reserve(n_cells);
for (pugi::xml_node cell_node: node->children("cell")) {
global_cells.push_back(new Cell(cell_node));
cells.push_back(new Cell(cell_node));
}
// Populate the Universe vector and map.
for (int i = 0; i < global_cells.size(); i++) {
int32_t uid = global_cells[i]->universe_;
for (int i = 0; i < cells.size(); i++) {
int32_t uid = cells[i]->universe_;
auto it = universe_map.find(uid);
if (it == universe_map.end()) {
global_universes.push_back(new Universe());
global_universes.back()->id_ = uid;
global_universes.back()->cells_.push_back(i);
universe_map[uid] = global_universes.size() - 1;
universes.push_back(new Universe());
universes.back()->id_ = uid;
universes.back()->cells_.push_back(i);
universe_map[uid] = universes.size() - 1;
} else {
global_universes[it->second]->cells_.push_back(i);
universes[it->second]->cells_.push_back(i);
}
}
global_universes.shrink_to_fit();
universes.shrink_to_fit();
// Allocate the cell overlap count if necessary.
if (openmc_check_overlaps) overlap_check_count.resize(n_cells, 0);
@ -630,9 +630,9 @@ read_cells(pugi::xml_node* node)
extern "C" int
openmc_cell_get_fill(int32_t index, int* type, int32_t** indices, int32_t* n)
{
if (index >= 1 && index <= global_cells.size()) {
if (index >= 1 && index <= cells.size()) {
//TODO: off-by-one
Cell& c {*global_cells[index - 1]};
Cell& c {*cells[index - 1]};
*type = c.type_;
if (c.type_ == FILL_MATERIAL) {
*indices = c.material_.data();
@ -652,9 +652,9 @@ extern "C" int
openmc_cell_set_fill(int32_t index, int type, int32_t n,
const int32_t* indices)
{
if (index >= 1 && index <= global_cells.size()) {
if (index >= 1 && index <= cells.size()) {
//TODO: off-by-one
Cell& c {*global_cells[index - 1]};
Cell& c {*cells[index - 1]};
if (type == FILL_MATERIAL) {
c.type_ = FILL_MATERIAL;
c.material_.clear();
@ -662,7 +662,7 @@ openmc_cell_set_fill(int32_t index, int type, int32_t n,
int i_mat = indices[i];
if (i_mat == MATERIAL_VOID) {
c.material_.push_back(MATERIAL_VOID);
} else if (i_mat >= 1 && i_mat <= global_materials.size()) {
} else if (i_mat >= 1 && i_mat <= materials.size()) {
//TODO: off-by-one
c.material_.push_back(i_mat - 1);
} else {
@ -687,9 +687,9 @@ openmc_cell_set_fill(int32_t index, int type, int32_t n,
extern "C" int
openmc_cell_set_temperature(int32_t index, double T, const int32_t* instance)
{
if (index >= 1 && index <= global_cells.size()) {
if (index >= 1 && index <= cells.size()) {
//TODO: off-by-one
Cell& c {*global_cells[index - 1]};
Cell& c {*cells[index - 1]};
if (instance) {
if (*instance >= 0 && *instance < c.sqrtkT_.size()) {
@ -717,7 +717,7 @@ openmc_cell_set_temperature(int32_t index, double T, const int32_t* instance)
//==============================================================================
extern "C" {
Cell* cell_pointer(int32_t cell_ind) {return global_cells[cell_ind];}
Cell* cell_pointer(int32_t cell_ind) {return cells[cell_ind];}
int32_t cell_id(Cell* c) {return c->id_;}
@ -751,17 +751,17 @@ extern "C" {
void extend_cells_c(int32_t n)
{
global_cells.reserve(global_cells.size() + n);
cells.reserve(cells.size() + n);
for (int32_t i = 0; i < n; i++) {
global_cells.push_back(new Cell());
cells.push_back(new Cell());
}
n_cells = global_cells.size();
n_cells = cells.size();
}
int32_t universe_id(int i_univ) {return global_universes[i_univ]->id_;}
int32_t universe_id(int i_univ) {return universes[i_univ]->id_;}
void universes_to_hdf5(hid_t universes_group)
{for (Universe* u : global_universes) u->to_hdf5(universes_group);}
{for (Universe* u : universes) u->to_hdf5(universes_group);}
}

View file

@ -25,17 +25,17 @@ check_cell_overlap(Particle* p) {
// Loop through each coordinate level
for (int j = 0; j < n_coord; j++) {
Universe& univ = *global_universes[p->coord[j].universe];
Universe& univ = *universes[p->coord[j].universe];
int n = univ.cells_.size();
// Loop through each cell on this level
for (auto index_cell : univ.cells_) {
Cell& c = *global_cells[index_cell];
Cell& c = *cells[index_cell];
if (c.contains(p->coord[j].xyz, p->coord[j].uvw, p->surface)) {
if (index_cell != p->coord[j].cell) {
std::stringstream err_msg;
err_msg << "Overlapping cells detected: " << c.id_ << ", "
<< global_cells[p->coord[j].cell]->id_ << " on universe "
<< cells[p->coord[j].cell]->id_ << " on universe "
<< univ.id_;
fatal_error(err_msg);
}
@ -67,12 +67,12 @@ find_cell(Particle* p, int search_surf) {
// the positive or negative side of the surface should be searched.
const std::vector<int>* search_cells;
if (search_surf > 0) {
search_cells = &global_surfaces[search_surf-1]->neighbor_pos_;
search_cells = &surfaces[search_surf-1]->neighbor_pos_;
} else if (search_surf < 0) {
search_cells = &global_surfaces[-search_surf-1]->neighbor_neg_;
search_cells = &surfaces[-search_surf-1]->neighbor_neg_;
} else {
// No surface was indicated, search all cells in the universe.
search_cells = &global_universes[i_universe]->cells_;
search_cells = &universes[i_universe]->cells_;
}
// Find which cell of this universe the particle is in.
@ -82,17 +82,17 @@ find_cell(Particle* p, int search_surf) {
i_cell = (*search_cells)[i];
// Make sure the search cell is in the same universe.
if (global_cells[i_cell]->universe_ != i_universe) continue;
if (cells[i_cell]->universe_ != i_universe) continue;
Position r {p->coord[p->n_coord-1].xyz};
Direction u {p->coord[p->n_coord-1].uvw};
int32_t surf = p->surface;
if (global_cells[i_cell]->contains(r, u, surf)) {
if (cells[i_cell]->contains(r, u, surf)) {
p->coord[p->n_coord-1].cell = i_cell;
if (openmc_verbosity >= 10 || openmc_trace) {
std::stringstream msg;
msg << " Entering cell " << global_cells[i_cell]->id_;
msg << " Entering cell " << cells[i_cell]->id_;
write_message(msg, 1);
}
found = true;
@ -101,7 +101,7 @@ find_cell(Particle* p, int search_surf) {
}
if (found) {
Cell& c {*global_cells[i_cell]};
Cell& c {*cells[i_cell]};
if (c.type_ == FILL_MATERIAL) {
//=======================================================================
//! Found a material cell which means this is the lowest coord level.
@ -112,11 +112,11 @@ find_cell(Particle* p, int search_surf) {
int distribcell_index = c.distribcell_index_ - 1;
int offset = 0;
for (int i = 0; i < p->n_coord; i++) {
Cell& c_i {*global_cells[p->coord[i].cell]};
Cell& c_i {*cells[p->coord[i].cell]};
if (c_i.type_ == FILL_UNIVERSE) {
offset += c_i.offset_[distribcell_index];
} else if (c_i.type_ == FILL_LATTICE) {
Lattice& lat {*lattices_c[p->coord[i+1].lattice-1]};
Lattice& lat {*lattices[p->coord[i+1].lattice-1]};
int i_xyz[3] {p->coord[i+1].lattice_x,
p->coord[i+1].lattice_y,
p->coord[i+1].lattice_z};
@ -201,7 +201,7 @@ find_cell(Particle* p, int search_surf) {
//========================================================================
//! Found a lower lattice, update this coord level then search the next.
Lattice& lat {*lattices_c[c.fill_]};
Lattice& lat {*lattices[c.fill_]};
// Determine lattice indices.
Position r {p->coord[p->n_coord-1].xyz};
@ -252,7 +252,7 @@ find_cell(Particle* p, int search_surf) {
extern "C" void
cross_lattice(Particle* p, int lattice_translation[3])
{
Lattice& lat {*lattices_c[p->coord[p->n_coord-1].lattice-1]};
Lattice& lat {*lattices[p->coord[p->n_coord-1].lattice-1]};
if (openmc_verbosity >= 10 || openmc_trace) {
std::stringstream msg;
@ -327,7 +327,7 @@ distance_to_boundary(Particle* p, double* dist, int* surface_crossed,
for (int i = 0; i < p->n_coord; i++) {
Position r {p->coord[i].xyz};
Direction u {p->coord[i].uvw};
Cell& c {*global_cells[p->coord[i].cell]};
Cell& c {*cells[p->coord[i].cell]};
// Find the oncoming surface in this cell and the distance to it.
auto surface_distance = c.distance(r, u, p->surface);
@ -336,7 +336,7 @@ distance_to_boundary(Particle* p, double* dist, int* surface_crossed,
// Find the distance to the next lattice tile crossing.
if (p->coord[i].lattice != F90_NONE) {
Lattice& lat {*lattices_c[p->coord[i].lattice-1]};
Lattice& lat {*lattices[p->coord[i].lattice-1]};
std::array<int, 3> i_xyz {p->coord[i].lattice_x, p->coord[i].lattice_y,
p->coord[i].lattice_z};
//TODO: refactor so both lattice use the same position argument (which
@ -378,7 +378,7 @@ distance_to_boundary(Particle* p, double* dist, int* surface_crossed,
*surface_crossed = level_surf_cross;
} else {
Position r_hit = r + d_surf * u;
Surface& surf {*global_surfaces[std::abs(level_surf_cross)-1]};
Surface& surf {*surfaces[std::abs(level_surf_cross)-1]};
Direction norm = surf.normal(r_hit);
if (u.dot(norm) > 0) {
*surface_crossed = std::abs(level_surf_cross);

View file

@ -22,7 +22,7 @@ void
adjust_indices()
{
// Adjust material/fill idices.
for (Cell* c : global_cells) {
for (Cell* c : cells) {
if (c->fill_ != C_NONE) {
int32_t id = c->fill_;
auto search_univ = universe_map.find(id);
@ -59,7 +59,7 @@ adjust_indices()
}
// Change cell.universe values from IDs to indices.
for (Cell* c : global_cells) {
for (Cell* c : cells) {
auto search = universe_map.find(c->universe_);
if (search != universe_map.end()) {
c->universe_ = search->second;
@ -72,7 +72,7 @@ adjust_indices()
}
// Change all lattice universe values from IDs to indices.
for (Lattice* l : lattices_c) {
for (Lattice* l : lattices) {
l->adjust_indices();
}
}
@ -82,7 +82,7 @@ adjust_indices()
void
assign_temperatures()
{
for (Cell* c : global_cells) {
for (Cell* c : cells) {
// Ignore non-material cells and cells with defined temperature.
if (c->material_.size() == 0) continue;
if (c->sqrtkT_.size() > 0) continue;
@ -94,9 +94,9 @@ assign_temperatures()
c->sqrtkT_.push_back(0);
} else {
if (global_materials[i_mat]->temperature_ >= 0) {
if (materials[i_mat]->temperature_ >= 0) {
// This material has a default temperature; use that value.
auto T = global_materials[i_mat]->temperature_;
auto T = materials[i_mat]->temperature_;
c->sqrtkT_.push_back(std::sqrt(K_BOLTZMANN * T));
} else {
// Use the global default temperature.
@ -114,12 +114,12 @@ find_root_universe()
{
// Find all the universes listed as a cell fill.
std::unordered_set<int32_t> fill_univ_ids;
for (Cell* c : global_cells) {
for (Cell* c : cells) {
fill_univ_ids.insert(c->fill_);
}
// Find all the universes contained in a lattice.
for (Lattice* lat : lattices_c) {
for (Lattice* lat : lattices) {
for (auto it = lat->begin(); it != lat->end(); ++it) {
fill_univ_ids.insert(*it);
}
@ -131,8 +131,8 @@ find_root_universe()
// Figure out which universe is not in the set. This is the root universe.
bool root_found {false};
int32_t root_univ;
for (int32_t i = 0; i < global_universes.size(); i++) {
auto search = fill_univ_ids.find(global_universes[i]->id_);
for (int32_t i = 0; i < universes.size(); i++) {
auto search = fill_univ_ids.find(universes[i]->id_);
if (search == fill_univ_ids.end()) {
if (root_found) {
fatal_error("Two or more universes are not used as fill universes, so "
@ -157,21 +157,21 @@ neighbor_lists()
{
write_message("Building neighboring cells lists for each surface...", 6);
for (int i = 0; i < global_cells.size(); i++) {
for (auto token : global_cells[i]->region_) {
for (int i = 0; i < cells.size(); i++) {
for (auto token : cells[i]->region_) {
// Skip operator tokens.
if (std::abs(token) >= OP_UNION) continue;
// This token is a surface index. Add the cell to the surface's list.
if (token > 0) {
global_surfaces[std::abs(token)-1]->neighbor_pos_.push_back(i);
surfaces[std::abs(token)-1]->neighbor_pos_.push_back(i);
} else {
global_surfaces[std::abs(token)-1]->neighbor_neg_.push_back(i);
surfaces[std::abs(token)-1]->neighbor_neg_.push_back(i);
}
}
}
for (Surface* surf : global_surfaces) {
for (Surface* surf : surfaces) {
surf->neighbor_pos_.shrink_to_fit();
surf->neighbor_neg_.shrink_to_fit();
}
@ -190,8 +190,8 @@ prepare_distribcell(int32_t* filter_cell_list, int n)
// Find all cells with distributed materials or temperatures. Make sure that
// the number of materials/temperatures matches the number of cell instances.
for (int i = 0; i < global_cells.size(); i++) {
Cell& c {*global_cells[i]};
for (int i = 0; i < cells.size(); i++) {
Cell& c {*cells[i]};
if (c.material_.size() > 1) {
if (c.material_.size() != c.n_instances_) {
@ -223,10 +223,10 @@ prepare_distribcell(int32_t* filter_cell_list, int n)
//TODO: off-by-one
int distribcell_index = 1;
std::vector<int32_t> target_univ_ids;
for (Universe* u : global_universes) {
for (Universe* u : universes) {
for (auto cell_indx : u->cells_) {
if (distribcells.find(cell_indx) != distribcells.end()) {
global_cells[cell_indx]->distribcell_index_ = distribcell_index;
cells[cell_indx]->distribcell_index_ = distribcell_index;
target_univ_ids.push_back(u->id_);
++distribcell_index;
}
@ -235,22 +235,22 @@ prepare_distribcell(int32_t* filter_cell_list, int n)
// Allocate the cell and lattice offset tables.
int n_maps = target_univ_ids.size();
for (Cell* c : global_cells) {
for (Cell* c : cells) {
if (c->type_ != FILL_MATERIAL) {
c->offset_.resize(n_maps, C_NONE);
}
}
for (Lattice* lat : lattices_c) {
for (Lattice* lat : lattices) {
lat->allocate_offset_table(n_maps);
}
// Fill the cell and lattice offset tables.
for (int map = 0; map < target_univ_ids.size(); map++) {
auto target_univ_id = target_univ_ids[map];
for (Universe* univ : global_universes) {
for (Universe* univ : universes) {
int32_t offset {0}; // TODO: is this a bug? It matches F90 implementation.
for (int32_t cell_indx : univ->cells_) {
Cell& c = *global_cells[cell_indx];
Cell& c = *cells[cell_indx];
if (c.type_ == FILL_UNIVERSE) {
c.offset_[map] = offset;
@ -258,7 +258,7 @@ prepare_distribcell(int32_t* filter_cell_list, int n)
offset += count_universe_instances(search_univ, target_univ_id);
} else if (c.type_ == FILL_LATTICE) {
Lattice& lat = *lattices_c[c.fill_];
Lattice& lat = *lattices[c.fill_];
offset = lat.fill_offset_table(offset, target_univ_id, map);
}
}
@ -271,8 +271,8 @@ prepare_distribcell(int32_t* filter_cell_list, int n)
void
count_cell_instances(int32_t univ_indx)
{
for (int32_t cell_indx : global_universes[univ_indx]->cells_) {
Cell& c = *global_cells[cell_indx];
for (int32_t cell_indx : universes[univ_indx]->cells_) {
Cell& c = *cells[cell_indx];
++c.n_instances_;
if (c.type_ == FILL_UNIVERSE) {
@ -281,7 +281,7 @@ count_cell_instances(int32_t univ_indx)
} else if (c.type_ == FILL_LATTICE) {
// This cell contains a lattice. Recurse into the lattice universes.
Lattice& lat = *lattices_c[c.fill_];
Lattice& lat = *lattices[c.fill_];
for (auto it = lat.begin(); it != lat.end(); ++it) {
count_cell_instances(*it);
}
@ -295,20 +295,20 @@ int
count_universe_instances(int32_t search_univ, int32_t target_univ_id)
{
// If this is the target, it can't contain itself.
if (global_universes[search_univ]->id_ == target_univ_id) {
if (universes[search_univ]->id_ == target_univ_id) {
return 1;
}
int count {0};
for (int32_t cell_indx : global_universes[search_univ]->cells_) {
Cell& c = *global_cells[cell_indx];
for (int32_t cell_indx : universes[search_univ]->cells_) {
Cell& c = *cells[cell_indx];
if (c.type_ == FILL_UNIVERSE) {
int32_t next_univ = c.fill_;
count += count_universe_instances(next_univ, target_univ_id);
} else if (c.type_ == FILL_LATTICE) {
Lattice& lat = *lattices_c[c.fill_];
Lattice& lat = *lattices[c.fill_];
for (auto it = lat.begin(); it != lat.end(); ++it) {
int32_t next_univ = *it;
count += count_universe_instances(next_univ, target_univ_id);
@ -333,7 +333,7 @@ distribcell_path_inner(int32_t target_cell, int32_t map, int32_t target_offset,
// write to the path and return.
for (int32_t cell_indx : search_univ.cells_) {
if ((cell_indx == target_cell) && (offset == target_offset)) {
Cell& c = *global_cells[cell_indx];
Cell& c = *cells[cell_indx];
path << "c" << c.id_;
return path.str();
}
@ -345,7 +345,7 @@ distribcell_path_inner(int32_t target_cell, int32_t map, int32_t target_offset,
std::vector<std::int32_t>::const_reverse_iterator cell_it
{search_univ.cells_.crbegin()};
for (; cell_it != search_univ.cells_.crend(); ++cell_it) {
Cell& c = *global_cells[*cell_it];
Cell& c = *cells[*cell_it];
// Material cells don't contain other cells so ignore them.
if (c.type_ != FILL_MATERIAL) {
@ -353,7 +353,7 @@ distribcell_path_inner(int32_t target_cell, int32_t map, int32_t target_offset,
if (c.type_ == FILL_UNIVERSE) {
temp_offset = offset + c.offset_[map];
} else {
Lattice& lat = *lattices_c[c.fill_];
Lattice& lat = *lattices[c.fill_];
int32_t indx = lat.universes_.size()*map + lat.begin().indx_;
temp_offset = offset + lat.offsets_[indx];
}
@ -365,18 +365,18 @@ distribcell_path_inner(int32_t target_cell, int32_t map, int32_t target_offset,
}
// Add the cell to the path string.
Cell& c = *global_cells[*cell_it];
Cell& c = *cells[*cell_it];
path << "c" << c.id_ << "->";
if (c.type_ == FILL_UNIVERSE) {
// Recurse into the fill cell.
offset += c.offset_[map];
path << distribcell_path_inner(target_cell, map, target_offset,
*global_universes[c.fill_], offset);
*universes[c.fill_], offset);
return path.str();
} else {
// Recurse into the lattice cell.
Lattice& lat = *lattices_c[c.fill_];
Lattice& lat = *lattices[c.fill_];
path << "l" << lat.id_;
for (ReverseLatticeIter it = lat.rbegin(); it != lat.rend(); ++it) {
int32_t indx = lat.universes_.size()*map + it.indx_;
@ -385,7 +385,7 @@ distribcell_path_inner(int32_t target_cell, int32_t map, int32_t target_offset,
offset = temp_offset;
path << "(" << lat.index_to_string(it.indx_) << ")->";
path << distribcell_path_inner(target_cell, map, target_offset,
*global_universes[*it], offset);
*universes[*it], offset);
return path.str();
}
}
@ -398,7 +398,7 @@ int
distribcell_path_len(int32_t target_cell, int32_t map, int32_t target_offset,
int32_t root_univ)
{
Universe& root = *global_universes[root_univ];
Universe& root = *universes[root_univ];
std::string path_ {distribcell_path_inner(target_cell, map, target_offset,
root, 0)};
return path_.size() + 1;
@ -410,7 +410,7 @@ void
distribcell_path(int32_t target_cell, int32_t map, int32_t target_offset,
int32_t root_univ, char* path)
{
Universe& root = *global_universes[root_univ];
Universe& root = *universes[root_univ];
std::string path_ {distribcell_path_inner(target_cell, map, target_offset,
root, 0)};
path_.copy(path, path_.size());
@ -424,13 +424,13 @@ maximum_levels(int32_t univ)
{
int levels_below {0};
for (int32_t cell_indx : global_universes[univ]->cells_) {
Cell& c = *global_cells[cell_indx];
for (int32_t cell_indx : universes[univ]->cells_) {
Cell& c = *cells[cell_indx];
if (c.type_ == FILL_UNIVERSE) {
int32_t next_univ = c.fill_;
levels_below = std::max(levels_below, maximum_levels(next_univ));
} else if (c.type_ == FILL_LATTICE) {
Lattice& lat = *lattices_c[c.fill_];
Lattice& lat = *lattices[c.fill_];
for (auto it = lat.begin(); it != lat.end(); ++it) {
int32_t next_univ = *it;
levels_below = std::max(levels_below, maximum_levels(next_univ));
@ -447,17 +447,17 @@ maximum_levels(int32_t univ)
void
free_memory_geometry_c()
{
for (Cell* c : global_cells) {delete c;}
global_cells.clear();
for (Cell* c : cells) {delete c;}
cells.clear();
cell_map.clear();
n_cells = 0;
for (Universe* u : global_universes) {delete u;}
global_universes.clear();
for (Universe* u : universes) {delete u;}
universes.clear();
universe_map.clear();
for (Lattice* lat : lattices_c) {delete lat;}
lattices_c.clear();
for (Lattice* lat : lattices) {delete lat;}
lattices.clear();
lattice_map.clear();
overlap_check_count.clear();

View file

@ -18,7 +18,7 @@ namespace openmc {
// Global variables
//==============================================================================
std::vector<Lattice*> lattices_c;
std::vector<Lattice*> lattices;
std::unordered_map<int32_t, int32_t> lattice_map;
@ -118,7 +118,7 @@ Lattice::to_hdf5(hid_t lattices_group) const
}
if (outer_ != NO_OUTER_UNIVERSE) {
int32_t outer_id = global_universes[outer_]->id_;
int32_t outer_id = universes[outer_]->id_;
write_dataset(lat_group, "outer", outer_id);
} else {
write_dataset(lat_group, "outer", outer_);
@ -370,7 +370,7 @@ RectLattice::to_hdf5_inner(hid_t lat_group) const
for (int j = 0; j < nx; j++) {
int indx1 = nx*ny*m + nx*k + j;
int indx2 = nx*ny*m + nx*(ny-k-1) + j;
out[indx2] = global_universes[universes_[indx1]]->id_;
out[indx2] = universes[universes_[indx1]]->id_;
}
}
}
@ -387,7 +387,7 @@ RectLattice::to_hdf5_inner(hid_t lat_group) const
for (int j = 0; j < nx; j++) {
int indx1 = nx*k + j;
int indx2 = nx*(ny-k-1) + j;
out[indx2] = global_universes[universes_[indx1]]->id_;
out[indx2] = universes[universes_[indx1]]->id_;
}
}
@ -847,7 +847,7 @@ HexLattice::to_hdf5_inner(hid_t lat_group) const
// This array position is never used; put a -1 to indicate this.
out[indx] = -1;
} else {
out[indx] = global_universes[universes_[indx]]->id_;
out[indx] = universes[universes_[indx]]->id_;
}
}
}
@ -865,15 +865,15 @@ extern "C" void
read_lattices(pugi::xml_node *node)
{
for (pugi::xml_node lat_node : node->children("lattice")) {
lattices_c.push_back(new RectLattice(lat_node));
lattices.push_back(new RectLattice(lat_node));
}
for (pugi::xml_node lat_node : node->children("hex_lattice")) {
lattices_c.push_back(new HexLattice(lat_node));
lattices.push_back(new HexLattice(lat_node));
}
// Fill the lattice map.
for (int i_lat = 0; i_lat < lattices_c.size(); i_lat++) {
int id = lattices_c[i_lat]->id_;
for (int i_lat = 0; i_lat < lattices.size(); i_lat++) {
int id = lattices[i_lat]->id_;
auto in_map = lattice_map.find(id);
if (in_map == lattice_map.end()) {
lattice_map[id] = i_lat;
@ -890,7 +890,7 @@ read_lattices(pugi::xml_node *node)
//==============================================================================
extern "C" {
Lattice* lattice_pointer(int lat_ind) {return lattices_c[lat_ind];}
Lattice* lattice_pointer(int lat_ind) {return lattices[lat_ind];}
int32_t lattice_id(Lattice *lat) {return lat->id_;}

View file

@ -13,7 +13,7 @@ namespace openmc {
// Global variables
//==============================================================================
std::vector<Material*> global_materials;
std::vector<Material*> materials;
std::unordered_map<int32_t, int32_t> material_map;
//==============================================================================
@ -46,13 +46,13 @@ read_materials(pugi::xml_node* node)
{
// Loop over XML material elements and populate the array.
for (pugi::xml_node material_node : node->children("material")) {
global_materials.push_back(new Material(material_node));
materials.push_back(new Material(material_node));
}
global_materials.shrink_to_fit();
materials.shrink_to_fit();
// Populate the material map.
for (int i = 0; i < global_materials.size(); i++) {
int32_t mid = global_materials[i]->id;
for (int i = 0; i < materials.size(); i++) {
int32_t mid = materials[i]->id;
auto search = material_map.find(mid);
if (search == material_map.end()) {
material_map[mid] = i;
@ -71,8 +71,8 @@ read_materials(pugi::xml_node* node)
extern "C" int
openmc_material_get_volume(int32_t index, double* volume)
{
if (index >= 1 && index <= global_materials.size()) {
Material* m = global_materials[index - 1];
if (index >= 1 && index <= materials.size()) {
Material* m = materials[index - 1];
if (m->volume_ >= 0.0) {
*volume = m->volume_;
return 0;
@ -91,8 +91,8 @@ openmc_material_get_volume(int32_t index, double* volume)
extern "C" int
openmc_material_set_volume(int32_t index, double volume)
{
if (index >= 1 && index <= global_materials.size()) {
Material* m = global_materials[index - 1];
if (index >= 1 && index <= materials.size()) {
Material* m = materials[index - 1];
if (volume >= 0.0) {
m->volume_ = volume;
return 0;
@ -111,7 +111,7 @@ openmc_material_set_volume(int32_t index, double volume)
//==============================================================================
extern "C" {
Material* material_pointer(int32_t indx) {return global_materials[indx];}
Material* material_pointer(int32_t indx) {return materials[indx];}
int32_t material_id(Material* mat) {return mat->id;}
@ -124,16 +124,16 @@ extern "C" {
void extend_materials_c(int32_t n)
{
global_materials.reserve(global_materials.size() + n);
materials.reserve(materials.size() + n);
for (int32_t i = 0; i < n; i++) {
global_materials.push_back(new Material());
materials.push_back(new Material());
}
}
void free_memory_material_c()
{
for (Material *mat : global_materials) {delete mat;}
global_materials.clear();
for (Material *mat : materials) {delete mat;}
materials.clear();
material_map.clear();
}
}

View file

@ -56,10 +56,10 @@ print_overlap_check() {
std::vector<int32_t> sparse_cell_ids;
for (int i = 0; i < n_cells; i++) {
std::cout << " " << std::setw(8) << global_cells[i]->id_ << std::setw(17)
std::cout << " " << std::setw(8) << cells[i]->id_ << std::setw(17)
<< overlap_check_count[i] << "\n";
if (overlap_check_count[i] < 10) {
sparse_cell_ids.push_back(global_cells[i]->id_);
sparse_cell_ids.push_back(cells[i]->id_);
}
}

View file

@ -9,25 +9,25 @@ namespace openmc {
extern "C" void
write_geometry(hid_t file_id) {
auto geom_group = create_group(file_id, "geometry");
write_attribute(geom_group, "n_cells", global_cells.size());
write_attribute(geom_group, "n_surfaces", global_surfaces.size());
write_attribute(geom_group, "n_universes", global_universes.size());
write_attribute(geom_group, "n_lattices", lattices_c.size());
write_attribute(geom_group, "n_cells", cells.size());
write_attribute(geom_group, "n_surfaces", surfaces.size());
write_attribute(geom_group, "n_universes", universes.size());
write_attribute(geom_group, "n_lattices", lattices.size());
auto cells_group = create_group(geom_group, "cells");
for (Cell* c : global_cells) c->to_hdf5(cells_group);
for (Cell* c : cells) c->to_hdf5(cells_group);
close_group(cells_group);
auto surfaces_group = create_group(geom_group, "surfaces");
for (Surface* surf : global_surfaces) surf->to_hdf5(surfaces_group);
for (Surface* surf : surfaces) surf->to_hdf5(surfaces_group);
close_group(surfaces_group);
auto universes_group = create_group(geom_group, "universes");
for (Universe* u : global_universes) u->to_hdf5(universes_group);
for (Universe* u : universes) u->to_hdf5(universes_group);
close_group(universes_group);
auto lattices_group = create_group(geom_group, "lattices");
for (Lattice* lat : lattices_c) lat->to_hdf5(lattices_group);
for (Lattice* lat : lattices) lat->to_hdf5(lattices_group);
close_group(lattices_group);
close_group(geom_group);

View file

@ -27,7 +27,7 @@ extern "C" const int BC_PERIODIC {3};
int32_t n_surfaces;
std::vector<Surface*> global_surfaces;
std::vector<Surface*> surfaces;
std::map<int, int> surface_map;
@ -1032,7 +1032,7 @@ read_surfaces(pugi::xml_node* node)
}
// Loop over XML surface elements and populate the array.
global_surfaces.reserve(n_surfaces);
surfaces.reserve(n_surfaces);
{
pugi::xml_node surf_node;
int i_surf;
@ -1041,40 +1041,40 @@ read_surfaces(pugi::xml_node* node)
std::string surf_type = get_node_value(surf_node, "type", true, true);
if (surf_type == "x-plane") {
global_surfaces.push_back(new SurfaceXPlane(surf_node));
surfaces.push_back(new SurfaceXPlane(surf_node));
} else if (surf_type == "y-plane") {
global_surfaces.push_back(new SurfaceYPlane(surf_node));
surfaces.push_back(new SurfaceYPlane(surf_node));
} else if (surf_type == "z-plane") {
global_surfaces.push_back(new SurfaceZPlane(surf_node));
surfaces.push_back(new SurfaceZPlane(surf_node));
} else if (surf_type == "plane") {
global_surfaces.push_back(new SurfacePlane(surf_node));
surfaces.push_back(new SurfacePlane(surf_node));
} else if (surf_type == "x-cylinder") {
global_surfaces.push_back(new SurfaceXCylinder(surf_node));
surfaces.push_back(new SurfaceXCylinder(surf_node));
} else if (surf_type == "y-cylinder") {
global_surfaces.push_back(new SurfaceYCylinder(surf_node));
surfaces.push_back(new SurfaceYCylinder(surf_node));
} else if (surf_type == "z-cylinder") {
global_surfaces.push_back(new SurfaceZCylinder(surf_node));
surfaces.push_back(new SurfaceZCylinder(surf_node));
} else if (surf_type == "sphere") {
global_surfaces.push_back(new SurfaceSphere(surf_node));
surfaces.push_back(new SurfaceSphere(surf_node));
} else if (surf_type == "x-cone") {
global_surfaces.push_back(new SurfaceXCone(surf_node));
surfaces.push_back(new SurfaceXCone(surf_node));
} else if (surf_type == "y-cone") {
global_surfaces.push_back(new SurfaceYCone(surf_node));
surfaces.push_back(new SurfaceYCone(surf_node));
} else if (surf_type == "z-cone") {
global_surfaces.push_back(new SurfaceZCone(surf_node));
surfaces.push_back(new SurfaceZCone(surf_node));
} else if (surf_type == "quadric") {
global_surfaces.push_back(new SurfaceQuadric(surf_node));
surfaces.push_back(new SurfaceQuadric(surf_node));
} else {
std::stringstream err_msg;
@ -1086,7 +1086,7 @@ read_surfaces(pugi::xml_node* node)
// Fill the surface map.
for (int i_surf = 0; i_surf < n_surfaces; i_surf++) {
int id = global_surfaces[i_surf]->id_;
int id = surfaces[i_surf]->id_;
auto in_map = surface_map.find(id);
if (in_map == surface_map.end()) {
surface_map[id] = i_surf;
@ -1102,9 +1102,9 @@ read_surfaces(pugi::xml_node* node)
zmin {INFTY}, zmax {-INFTY};
int i_xmin, i_xmax, i_ymin, i_ymax, i_zmin, i_zmax;
for (int i_surf = 0; i_surf < n_surfaces; i_surf++) {
if (global_surfaces[i_surf]->bc_ == BC_PERIODIC) {
if (surfaces[i_surf]->bc_ == BC_PERIODIC) {
// Downcast to the PeriodicSurface type.
Surface* surf_base = global_surfaces[i_surf];
Surface* surf_base = surfaces[i_surf];
PeriodicSurface* surf = dynamic_cast<PeriodicSurface*>(surf_base);
// Make sure this surface inherits from PeriodicSurface.
@ -1147,9 +1147,9 @@ read_surfaces(pugi::xml_node* node)
// Set i_periodic for periodic BC surfaces.
for (int i_surf = 0; i_surf < n_surfaces; i_surf++) {
if (global_surfaces[i_surf]->bc_ == BC_PERIODIC) {
if (surfaces[i_surf]->bc_ == BC_PERIODIC) {
// Downcast to the PeriodicSurface type.
Surface* surf_base = global_surfaces[i_surf];
Surface* surf_base = surfaces[i_surf];
PeriodicSurface* surf = dynamic_cast<PeriodicSurface*>(surf_base);
// Also try downcasting to the SurfacePlane type (which must be handled
@ -1196,7 +1196,7 @@ read_surfaces(pugi::xml_node* node)
}
// Make sure the opposite surface is also periodic.
if (global_surfaces[surf->i_periodic_]->bc_ != BC_PERIODIC) {
if (surfaces[surf->i_periodic_]->bc_ != BC_PERIODIC) {
std::stringstream err_msg;
err_msg << "Could not find matching surface for periodic boundary "
"condition on surface " << surf->id_;
@ -1211,7 +1211,7 @@ read_surfaces(pugi::xml_node* node)
//==============================================================================
extern "C" {
Surface* surface_pointer(int surf_ind) {return global_surfaces[surf_ind];}
Surface* surface_pointer(int surf_ind) {return surfaces[surf_ind];}
int surface_id(Surface* surf) {return surf->id_;}
@ -1251,8 +1251,8 @@ extern "C" {
void free_memory_surfaces_c()
{
for (Surface* surf : global_surfaces) {delete surf;}
global_surfaces.clear();
for (Surface* surf : surfaces) {delete surf;}
surfaces.clear();
n_surfaces = 0;
surface_map.clear();
}