mirror of
https://github.com/openmc-dev/openmc.git
synced 2026-07-26 21:25:36 -04:00
Moving the compute_instance method to the ParentCellStack and adding some documentation there.
This commit is contained in:
parent
0bed3f53b2
commit
64e93c930c
2 changed files with 24 additions and 14 deletions
|
|
@ -321,27 +321,42 @@ struct ParentCell {
|
|||
gsl::index lattice_index;
|
||||
};
|
||||
|
||||
struct ParentCellHash {
|
||||
std::size_t operator()(const ParentCell& p) const
|
||||
{
|
||||
return 4096*p.cell_index + p.lattice_index;
|
||||
}
|
||||
};
|
||||
|
||||
struct ParentCellStack {
|
||||
|
||||
//! push method that adds to the parent_cells visited cells for this search universe
|
||||
void push(int32_t search_universe, const ParentCell& pc) {
|
||||
parent_cells_.push_back(pc);
|
||||
// add parent cell to the set of cells we've visited for this search universe
|
||||
visited_cells_[search_universe].insert(pc);
|
||||
}
|
||||
|
||||
//! removes the last parent_cell and clears the visited cells for the popped cell's universe
|
||||
void pop() {
|
||||
visited_cells_[this->current_univ()].clear();
|
||||
parent_cells_.pop_back();
|
||||
}
|
||||
|
||||
bool visited(int32_t univ_idx, const ParentCell& parent_cell) {
|
||||
return visited_cells_[univ_idx].count(parent_cell) != 0;
|
||||
//! checks whether or not the parent cell has been visited already for this search universe
|
||||
bool visited(int32_t search_universe, const ParentCell& parent_cell) {
|
||||
return visited_cells_[search_universe].count(parent_cell) != 0;
|
||||
}
|
||||
|
||||
//! return the next universe to search for a parent cell
|
||||
int32_t current_univ() const { return model::cells[parent_cells_.back().cell_index]->universe_; }
|
||||
|
||||
//! indicates whether nor not parent cells are present on the stack
|
||||
bool empty() const { return parent_cells_.empty(); }
|
||||
|
||||
//! compute an instance for the provided distribcell index
|
||||
int32_t compute_instance(int32_t distribcell_index) const;
|
||||
|
||||
// Accessors
|
||||
std::vector<ParentCell>& parent_cells() { return parent_cells_; }
|
||||
const std::vector<ParentCell>& parent_cells() const { return parent_cells_; }
|
||||
|
|
@ -351,13 +366,6 @@ struct ParentCellStack {
|
|||
std::unordered_map<int32_t, std::set<ParentCell>> visited_cells_;
|
||||
};
|
||||
|
||||
struct ParentCellHash {
|
||||
std::size_t operator()(const ParentCell& p) const
|
||||
{
|
||||
return 4096*p.cell_index + p.lattice_index;
|
||||
}
|
||||
};
|
||||
|
||||
//==============================================================================
|
||||
//! Define an instance of a particular cell
|
||||
//==============================================================================
|
||||
|
|
|
|||
12
src/cell.cpp
12
src/cell.cpp
|
|
@ -1266,7 +1266,7 @@ Cell::find_parent_cells(vector<ParentCell>& parent_cells, int32_t instance) cons
|
|||
}
|
||||
|
||||
// if we're at the top of the geometry and the instance matches, we're done
|
||||
if (univ_idx == model::root_universe && this->compute_instance(stack.parent_cells()) == instance) break;
|
||||
if (univ_idx == model::root_universe && stack.compute_instance(this->distribcell_index_) == instance) break;
|
||||
|
||||
// if there was no match on the current cell's universe, report an error
|
||||
if (univ_idx == this->universe_) {
|
||||
|
|
@ -1286,15 +1286,17 @@ Cell::find_parent_cells(vector<ParentCell>& parent_cells, int32_t instance) cons
|
|||
return stack.parent_cells();
|
||||
}
|
||||
|
||||
int32_t Cell::compute_instance(const vector<ParentCell>& parent_cells) const {
|
||||
int32_t
|
||||
ParentCellStack::compute_instance(int32_t distribcell_index) const
|
||||
{
|
||||
int32_t instance = 0;
|
||||
for (const auto& parent_cell : parent_cells) {
|
||||
for (const auto& parent_cell : this->parent_cells_) {
|
||||
auto& cell = model::cells[parent_cell.cell_index];
|
||||
if (cell->type_ == Fill::UNIVERSE) {
|
||||
instance += cell->offset_[this->distribcell_index_];
|
||||
instance += cell->offset_[distribcell_index];
|
||||
} else if (cell->type_ == Fill::LATTICE) {
|
||||
auto& lattice = model::lattices[cell->fill_];
|
||||
instance += lattice->offset(this->distribcell_index_, parent_cell.lattice_index);
|
||||
instance += lattice->offset(distribcell_index, parent_cell.lattice_index);
|
||||
}
|
||||
}
|
||||
return instance;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue