65;6003;1cAdding a find_cell method to universes.

This commit is contained in:
Patrick Shriwise 2021-03-29 14:58:18 -05:00
parent 8f9788742a
commit 3293948248
3 changed files with 30 additions and 24 deletions

View file

@ -70,6 +70,8 @@ public:
//! \param group_id An HDF5 group id.
void to_hdf5(hid_t group_id) const;
virtual bool find_cell(Particle &p) const;
BoundingBox bounding_box() const;
GeometryType type_ = GeometryType::CSG;

View file

@ -212,6 +212,31 @@ Universe::to_hdf5(hid_t universes_group) const
close_group(group);
}
bool
Universe::find_cell(Particle& p) const {
const auto& cells {
!partitioner_
? cells_
: partitioner_->get_cells(p.r_local(), p.u_local())
};
for (auto it = cells.begin(); it != cells.end(); it++) {
int32_t i_cell = *it;
int32_t i_univ = p.coord_[p.n_coord_-1].universe;
if (model::cells[i_cell]->universe_ != i_univ) continue;
// Check if this cell contains the particle;
Position r {p.r_local()};
Direction u {p.u_local()};
auto surf = p.surface_;
if (model::cells[i_cell]->contains(r, u, surf)) {
p.coord_[p.n_coord_-1].cell = i_cell;
return true;
}
}
return false;
}
BoundingBox Universe::bounding_box() const {
BoundingBox bbox = {INFTY, -INFTY, INFTY, -INFTY, INFTY, -INFTY};
if (cells_.size() == 0) {

View file

@ -112,34 +112,13 @@ find_cell_inner(Particle& p, const NeighborList* neighbor_list)
// that.
if (i_cell == C_NONE) {
int i_universe = p.coord(p.n_coord() - 1).universe;
const auto& univ {*model::universes[i_universe]};
const auto& cells {
!univ.partitioner_
? model::universes[i_universe]->cells_
: univ.partitioner_->get_cells(p.r_local(), p.u_local())
};
for (auto it = cells.cbegin(); it != cells.cend(); it++) {
i_cell = *it;
// Make sure the search cell is in the same universe.
int i_universe = p.coord(p.n_coord() - 1).universe;
if (model::cells[i_cell]->universe_ != i_universe) continue;
// Check if this cell contains the particle.
Position r {p.r_local()};
Direction u {p.u_local()};
auto surf = p.surface();
if (model::cells[i_cell]->contains(r, u, surf)) {
p.coord(p.n_coord() - 1).cell = i_cell;
found = true;
break;
}
}
const auto& univ {model::universes[i_universe]};
found = univ->find_cell(p);
}
if (!found) {
return found;
}
i_cell = p.coord_[p.n_coord_ - 1].cell;
// Announce the cell that the particle is entering.
if (found && (settings::verbosity >= 10 || p.trace())) {