More namespacing for global variables

This commit is contained in:
Paul Romano 2018-11-08 13:41:23 -06:00
parent 3cfe71621b
commit 6436cab302
15 changed files with 105 additions and 71 deletions

View file

@ -135,14 +135,12 @@ extern "C" {
// Global variables
extern char openmc_err_msg[256];
extern int32_t n_lattices;
extern int32_t n_materials;
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;
extern int32_t n_surfaces;
extern int32_t n_tallies;
extern int32_t n_universes;

View file

@ -10,12 +10,24 @@
namespace openmc {
//==============================================================================
// Global variables
//==============================================================================
namespace model {
extern moab::DagMC* DAG;
} // namespace model
//==============================================================================
// Non-member functions
//==============================================================================
extern "C" void load_dagmc_geometry();
extern "C" void free_memory_dagmc();
}
} // namespace openmc
#endif // DAGMC

View file

@ -13,10 +13,14 @@ namespace openmc {
// Global variables
//==============================================================================
extern "C" int openmc_root_universe;
namespace model {
extern "C" int root_universe;
extern std::vector<int64_t> overlap_check_count;
} // namespace model
//==============================================================================
//! Check for overlapping cells at a particle's position.
//==============================================================================

View file

@ -31,10 +31,14 @@ enum class LatticeType {
//==============================================================================
class Lattice;
extern std::vector<Lattice*> lattices;
namespace model {
extern std::vector<Lattice*> lattices;
extern std::unordered_map<int32_t, int32_t> lattice_map;
} // namespace model
//==============================================================================
//! \class Lattice
//! \brief Abstract type for ordered array of universes.

View file

@ -509,7 +509,7 @@ CSGCell::to_hdf5(hid_t cell_group) const
} else if (type_ == FILL_LATTICE) {
write_dataset(group, "fill_type", "lattice");
write_dataset(group, "lattice", lattices[fill_]->id_);
write_dataset(group, "lattice", model::lattices[fill_]->id_);
}
close_group(group);
@ -682,7 +682,7 @@ read_cells(pugi::xml_node* node)
model::universes.shrink_to_fit();
// Allocate the cell overlap count if necessary.
if (settings::check_overlaps) overlap_check_count.resize(model::n_cells, 0);
if (settings::check_overlaps) model::overlap_check_count.resize(model::n_cells, 0);
}
//==============================================================================

View file

@ -18,16 +18,16 @@ moab::DagMC* DAG;
void load_dagmc_geometry()
{
if (!DAG) {
DAG = new moab::DagMC();
if (!model::DAG) {
model::DAG = new moab::DagMC();
}
int32_t dagmc_univ_id = 0; // universe is always 0 for DAGMC
moab::ErrorCode rval = DAG->load_file("dagmc.h5m");
moab::ErrorCode rval = model::DAG->load_file("dagmc.h5m");
MB_CHK_ERR_CONT(rval);
rval = DAG->init_OBBTree();
rval = model::DAG->init_OBBTree();
MB_CHK_ERR_CONT(rval);
std::vector<std::string> prop_keywords;
@ -35,22 +35,22 @@ void load_dagmc_geometry()
prop_keywords.push_back("boundary");
std::map<std::string, std::string> ph;
DAG->parse_properties(prop_keywords, ph, ":");
model::DAG->parse_properties(prop_keywords, ph, ":");
MB_CHK_ERR_CONT(rval);
// initialize cell objects
model::n_cells = DAG->num_entities(3);
model::n_cells = model::DAG->num_entities(3);
// Allocate the cell overlap count if necessary.
if (settings::check_overlaps) overlap_check_count.resize(model::n_cells, 0);
if (settings::check_overlaps) model::overlap_check_count.resize(model::n_cells, 0);
for (int i = 0; i < model::n_cells; i++) {
moab::EntityHandle vol_handle = DAG->entity_by_index(3, i+1);
moab::EntityHandle vol_handle = model::DAG->entity_by_index(3, i+1);
// set cell ids using global IDs
DAGCell* c = new DAGCell();
c->id_ = DAG->id_by_index(3, i+1);
c->dagmc_ptr_ = DAG;
c->id_ = model::DAG->id_by_index(3, i+1);
c->dagmc_ptr_ = model::DAG;
c->universe_ = dagmc_univ_id; // set to zero for now
c->fill_ = C_NONE; // no fill, single universe
@ -68,15 +68,15 @@ void load_dagmc_geometry()
model::universes[it->second]->cells_.push_back(i);
}
if (DAG->is_implicit_complement(vol_handle)) {
if (model::DAG->is_implicit_complement(vol_handle)) {
// assuming implicit complement is void for now
c->material_.push_back(MATERIAL_VOID);
continue;
}
if (DAG->has_prop(vol_handle, "mat")){
if (model::DAG->has_prop(vol_handle, "mat")){
std::string mat_value;
rval = DAG->prop_value(vol_handle, "mat", mat_value);
rval = model::DAG->prop_value(vol_handle, "mat", mat_value);
MB_CHK_ERR_CONT(rval);
to_lower(mat_value);
@ -93,20 +93,20 @@ void load_dagmc_geometry()
}
// initialize surface objects
n_surfaces = DAG->num_entities(2);
n_surfaces = model::DAG->num_entities(2);
surfaces.resize(n_surfaces);
for (int i = 0; i < n_surfaces; i++) {
moab::EntityHandle surf_handle = DAG->entity_by_index(2, i+1);
moab::EntityHandle surf_handle = model::DAG->entity_by_index(2, i+1);
// set cell ids using global IDs
DAGSurface* s = new DAGSurface();
s->id_ = DAG->id_by_index(2, i+1);
s->dagmc_ptr_ = DAG;
s->id_ = model::DAG->id_by_index(2, i+1);
s->dagmc_ptr_ = model::DAG;
if (DAG->has_prop(surf_handle, "boundary")) {
if (model::DAG->has_prop(surf_handle, "boundary")) {
std::string bc_value;
rval = DAG->prop_value(surf_handle, "boundary", bc_value);
rval = model::DAG->prop_value(surf_handle, "boundary", bc_value);
MB_CHK_ERR_CONT(rval);
to_lower(bc_value);
@ -138,7 +138,7 @@ void load_dagmc_geometry()
void free_memory_dagmc()
{
delete DAG;
delete model::DAG;
}
}

View file

@ -78,7 +78,7 @@ int openmc_finalize()
energy_max = {INFTY, INFTY};
energy_min = {0.0, 0.0};
n_tallies = 0;
openmc_root_universe = -1;
model::root_universe = -1;
openmc_set_seed(DEFAULT_SEED);
// Deallocate arrays

View file

@ -14,8 +14,21 @@
namespace openmc {
//==============================================================================
// Global variables
//==============================================================================
namespace model {
int root_universe {-1};
std::vector<int64_t> overlap_check_count;
} // namespace model
//==============================================================================
// Non-member functions
//==============================================================================
extern "C" bool
@ -38,7 +51,7 @@ check_cell_overlap(Particle* p) {
<< univ.id_;
fatal_error(err_msg);
}
++overlap_check_count[index_cell];
++model::overlap_check_count[index_cell];
}
}
}
@ -57,8 +70,8 @@ find_cell(Particle* p, int search_surf) {
// Determine universe (if not yet set, use root universe)
int i_universe = p->coord[p->n_coord-1].universe;
if (i_universe == C_NONE) {
p->coord[p->n_coord-1].universe = openmc_root_universe;
i_universe = openmc_root_universe;
p->coord[p->n_coord-1].universe = model::root_universe;
i_universe = model::root_universe;
}
// If a surface was indicated, only search cells from the neighbor list of
@ -113,7 +126,7 @@ find_cell(Particle* p, int search_surf) {
if (c_i.type_ == FILL_UNIVERSE) {
offset += c_i.offset_[c.distribcell_index_];
} else if (c_i.type_ == FILL_LATTICE) {
Lattice& lat {*lattices[p->coord[i+1].lattice-1]};
Lattice& lat {*model::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};
@ -198,7 +211,7 @@ find_cell(Particle* p, int search_surf) {
//========================================================================
//! Found a lower lattice, update this coord level then search the next.
Lattice& lat {*lattices[c.fill_]};
Lattice& lat {*model::lattices[c.fill_]};
// Determine lattice indices.
Position r {p->coord[p->n_coord-1].xyz};
@ -251,7 +264,7 @@ find_cell(Particle* p, int search_surf) {
extern "C" void
cross_lattice(Particle* p, int lattice_translation[3])
{
Lattice& lat {*lattices[p->coord[p->n_coord-1].lattice-1]};
Lattice& lat {*model::lattices[p->coord[p->n_coord-1].lattice-1]};
if (settings::verbosity >= 10 || simulation::trace) {
std::stringstream msg;
@ -335,7 +348,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[p->coord[i].lattice-1]};
Lattice& lat {*model::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

View file

@ -28,11 +28,11 @@ adjust_indices()
if (c->fill_ != C_NONE) {
int32_t id = c->fill_;
auto search_univ = model::universe_map.find(id);
auto search_lat = lattice_map.find(id);
auto search_lat = model::lattice_map.find(id);
if (search_univ != model::universe_map.end()) {
c->type_ = FILL_UNIVERSE;
c->fill_ = search_univ->second;
} else if (search_lat != lattice_map.end()) {
} else if (search_lat != model::lattice_map.end()) {
c->type_ = FILL_LATTICE;
c->fill_ = search_lat->second;
} else {
@ -74,7 +74,7 @@ adjust_indices()
}
// Change all lattice universe values from IDs to indices.
for (Lattice* l : lattices) {
for (Lattice* l : model::lattices) {
l->adjust_indices();
}
}
@ -122,7 +122,7 @@ find_root_universe()
}
// Find all the universes contained in a lattice.
for (Lattice* lat : lattices) {
for (Lattice* lat : model::lattices) {
for (auto it = lat->begin(); it != lat->end(); ++it) {
fill_univ_ids.insert(*it);
}
@ -245,7 +245,7 @@ prepare_distribcell()
c->offset_.resize(n_maps, C_NONE);
}
}
for (Lattice* lat : lattices) {
for (Lattice* lat : model::lattices) {
lat->allocate_offset_table(n_maps);
}
@ -263,7 +263,7 @@ prepare_distribcell()
offset += count_universe_instances(search_univ, target_univ_id);
} else if (c.type_ == FILL_LATTICE) {
Lattice& lat = *lattices[c.fill_];
Lattice& lat = *model::lattices[c.fill_];
offset = lat.fill_offset_table(offset, target_univ_id, map);
}
}
@ -286,7 +286,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.fill_];
Lattice& lat = *model::lattices[c.fill_];
for (auto it = lat.begin(); it != lat.end(); ++it) {
count_cell_instances(*it);
}
@ -313,7 +313,7 @@ count_universe_instances(int32_t search_univ, int32_t target_univ_id)
count += count_universe_instances(next_univ, target_univ_id);
} else if (c.type_ == FILL_LATTICE) {
Lattice& lat = *lattices[c.fill_];
Lattice& lat = *model::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);
@ -358,7 +358,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.fill_];
Lattice& lat = *model::lattices[c.fill_];
int32_t indx = lat.universes_.size()*map + lat.begin().indx_;
temp_offset = offset + lat.offsets_[indx];
}
@ -381,7 +381,7 @@ distribcell_path_inner(int32_t target_cell, int32_t map, int32_t target_offset,
return path.str();
} else {
// Recurse into the lattice cell.
Lattice& lat = *lattices[c.fill_];
Lattice& lat = *model::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_;
@ -401,7 +401,7 @@ distribcell_path_inner(int32_t target_cell, int32_t map, int32_t target_offset,
std::string
distribcell_path(int32_t target_cell, int32_t map, int32_t target_offset)
{
auto& root_univ = *model::universes[openmc_root_universe];
auto& root_univ = *model::universes[model::root_universe];
return distribcell_path_inner(target_cell, map, target_offset, root_univ, 0);
}
@ -418,7 +418,7 @@ maximum_levels(int32_t univ)
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.fill_];
Lattice& lat = *model::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));
@ -444,11 +444,11 @@ free_memory_geometry_c()
model::universes.clear();
model::universe_map.clear();
for (Lattice* lat : lattices) {delete lat;}
lattices.clear();
lattice_map.clear();
for (Lattice* lat : model::lattices) {delete lat;}
model::lattices.clear();
model::lattice_map.clear();
overlap_check_count.clear();
model::overlap_check_count.clear();
}
} // namespace openmc

View file

@ -143,7 +143,7 @@ module geometry_header
end type Cell
! array index of the root universe
integer(C_INT), bind(C, name='openmc_root_universe') :: root_universe = -1
integer(C_INT), bind(C) :: root_universe
integer(C_INT32_T), bind(C) :: n_cells ! # of cells
integer(C_INT32_T), bind(C) :: n_universes ! # of universes

View file

@ -18,10 +18,13 @@ namespace openmc {
// Global variables
//==============================================================================
std::vector<Lattice*> lattices;
namespace model {
std::vector<Lattice*> lattices;
std::unordered_map<int32_t, int32_t> lattice_map;
}
//==============================================================================
// Lattice implementation
//==============================================================================
@ -865,18 +868,18 @@ extern "C" void
read_lattices(pugi::xml_node *node)
{
for (pugi::xml_node lat_node : node->children("lattice")) {
lattices.push_back(new RectLattice(lat_node));
model::lattices.push_back(new RectLattice(lat_node));
}
for (pugi::xml_node lat_node : node->children("hex_lattice")) {
lattices.push_back(new HexLattice(lat_node));
model::lattices.push_back(new HexLattice(lat_node));
}
// Fill the lattice map.
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;
for (int i_lat = 0; i_lat < model::lattices.size(); i_lat++) {
int id = model::lattices[i_lat]->id_;
auto in_map = model::lattice_map.find(id);
if (in_map == model::lattice_map.end()) {
model::lattice_map[id] = i_lat;
} else {
std::stringstream err_msg;
err_msg << "Two or more lattices use the same unique ID: " << id;
@ -890,7 +893,7 @@ read_lattices(pugi::xml_node *node)
//==============================================================================
extern "C" {
Lattice* lattice_pointer(int lat_ind) {return lattices[lat_ind];}
Lattice* lattice_pointer(int lat_ind) {return model::lattices[lat_ind];}
int32_t lattice_id(Lattice *lat) {return lat->id_;}
}

View file

@ -129,9 +129,9 @@ void print_plot() {
void
print_overlap_check() {
#ifdef OPENMC_MPI
std::vector<int64_t> temp(overlap_check_count);
int err = MPI_Reduce(temp.data(), overlap_check_count.data(),
overlap_check_count.size(), MPI_INT64_T, MPI_SUM, 0,
std::vector<int64_t> temp(model::overlap_check_count);
int err = MPI_Reduce(temp.data(), model::overlap_check_count.data(),
model::overlap_check_count.size(), MPI_INT64_T, MPI_SUM, 0,
mpi::intracomm);
#endif
@ -142,8 +142,8 @@ print_overlap_check() {
std::vector<int32_t> sparse_cell_ids;
for (int i = 0; i < model::n_cells; i++) {
std::cout << " " << std::setw(8) << model::cells[i]->id_ << std::setw(17)
<< overlap_check_count[i] << "\n";
if (overlap_check_count[i] < 10) {
<< model::overlap_check_count[i] << "\n";
if (model::overlap_check_count[i] < 10) {
sparse_cell_ids.push_back(model::cells[i]->id_);
}
}

View file

@ -123,7 +123,7 @@ void create_ppm(Plot pl)
p.initialize();
std::copy(xyz, xyz+3, p.coord[0].xyz);
std::copy(dir, dir+3, p.coord[0].uvw);
p.coord[0].universe = openmc_root_universe;
p.coord[0].universe = model::root_universe;
#pragma omp for
for (int y = 0; y < height; y++) {
@ -852,7 +852,7 @@ void create_voxel(Plot pl)
p.initialize();
std::copy(ll.begin(), ll.begin()+ll.size(), p.coord[0].xyz);
std::copy(dir, dir+3, p.coord[0].uvw);
p.coord[0].universe = openmc_root_universe;
p.coord[0].universe = model::root_universe;
// Open binary plot file for writing
std::ofstream of;

View file

@ -21,7 +21,7 @@ write_geometry(hid_t file_id) {
write_attribute(geom_group, "n_cells", model::cells.size());
write_attribute(geom_group, "n_surfaces", surfaces.size());
write_attribute(geom_group, "n_universes", model::universes.size());
write_attribute(geom_group, "n_lattices", lattices.size());
write_attribute(geom_group, "n_lattices", model::lattices.size());
auto cells_group = create_group(geom_group, "cells");
for (Cell* c : model::cells) c->to_hdf5(cells_group);
@ -36,7 +36,7 @@ write_geometry(hid_t file_id) {
close_group(universes_group);
auto lattices_group = create_group(geom_group, "lattices");
for (Lattice* lat : lattices) lat->to_hdf5(lattices_group);
for (Lattice* lat : model::lattices) lat->to_hdf5(lattices_group);
close_group(lattices_group);
close_group(geom_group);

View file

@ -45,7 +45,7 @@ DistribcellFilter::get_all_bins(const Particle* p, int estimator,
if (c.type_ == FILL_UNIVERSE) {
offset += c.offset_[distribcell_index];
} else if (c.type_ == FILL_LATTICE) {
auto& lat {*lattices[p->coord[i+1].lattice-1]};
auto& lat {*model::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};