Skip to content

Commit 06d6437

Browse files
authored
Tweaks to Universe::find_cell (openmc-dev#2662)
1 parent ffbf1b9 commit 06d6437

6 files changed

Lines changed: 44 additions & 42 deletions

File tree

‎src/dagmc.cpp‎

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -182,10 +182,11 @@ void DAGUniverse::init_geometry()
182182
model::cell_map[c->id_] = model::cells.size();
183183
} else {
184184
warning(fmt::format("DAGMC Cell IDs: {}", dagmc_ids_for_dim(3)));
185-
fatal_error(fmt::format("DAGMC Universe {} contains a cell with ID {}, which "
186-
"already exists elsewhere in the geometry. Setting auto_geom_ids "
187-
"to True when initiating the DAGMC Universe may "
188-
"resolve this issue",
185+
fatal_error(fmt::format(
186+
"DAGMC Universe {} contains a cell with ID {}, which "
187+
"already exists elsewhere in the geometry. Setting auto_geom_ids "
188+
"to True when initiating the DAGMC Universe may "
189+
"resolve this issue",
189190
this->id_, c->id_));
190191
}
191192

@@ -395,7 +396,7 @@ bool DAGUniverse::find_cell(Particle& p) const
395396
// cells, place it in the implicit complement
396397
bool found = Universe::find_cell(p);
397398
if (!found && model::universe_map[this->id_] != model::root_universe) {
398-
p.coord(p.n_coord() - 1).cell = implicit_complement_idx();
399+
p.lowest_coord().cell = implicit_complement_idx();
399400
found = true;
400401
}
401402
return found;
@@ -581,7 +582,7 @@ std::pair<double, int32_t> DAGCell::distance(
581582
p->history().reset();
582583
}
583584

584-
const auto& univ = model::universes[p->coord(p->n_coord() - 1).universe];
585+
const auto& univ = model::universes[p->lowest_coord().universe];
585586

586587
DAGUniverse* dag_univ = static_cast<DAGUniverse*>(univ.get());
587588
if (!dag_univ)
@@ -609,7 +610,8 @@ std::pair<double, int32_t> DAGCell::distance(
609610
// into the implicit complement on the other side where no intersection will
610611
// be found. Treating this as a lost particle is problematic when plotting.
611612
// Instead, the infinite distance and invalid surface index are returned.
612-
if (settings::run_mode == RunMode::PLOTTING) return {INFTY, -1};
613+
if (settings::run_mode == RunMode::PLOTTING)
614+
return {INFTY, -1};
613615

614616
// the particle should be marked as lost immediately if an intersection
615617
// isn't found in a volume that is not the implicit complement. In the case
@@ -739,7 +741,8 @@ void check_dagmc_root_univ()
739741
}
740742
}
741743

742-
int32_t next_cell(int32_t surf, int32_t curr_cell, int32_t univ) {
744+
int32_t next_cell(int32_t surf, int32_t curr_cell, int32_t univ)
745+
{
743746
auto surfp = dynamic_cast<DAGSurface*>(model::surfaces[surf - 1].get());
744747
auto cellp = dynamic_cast<DAGCell*>(model::cells[curr_cell].get());
745748
auto univp = static_cast<DAGUniverse*>(model::universes[univ].get());
@@ -750,11 +753,12 @@ int32_t next_cell(int32_t surf, int32_t curr_cell, int32_t univ) {
750753
cellp->dagmc_ptr()->entity_by_index(3, cellp->dag_index());
751754

752755
moab::EntityHandle new_vol;
753-
moab::ErrorCode rval = cellp->dagmc_ptr()->next_vol(surf_handle, curr_vol, new_vol);
754-
if (rval != moab::MB_SUCCESS) return -1;
756+
moab::ErrorCode rval =
757+
cellp->dagmc_ptr()->next_vol(surf_handle, curr_vol, new_vol);
758+
if (rval != moab::MB_SUCCESS)
759+
return -1;
755760

756-
return cellp->dagmc_ptr()->index_by_handle(new_vol) +
757-
univp->cell_idx_offset_;
761+
return cellp->dagmc_ptr()->index_by_handle(new_vol) + univp->cell_idx_offset_;
758762
}
759763

760764
} // namespace openmc

‎src/geometry.cpp‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ bool find_cell_inner(Particle& p, const NeighborList* neighbor_list)
110110
i_cell = *it;
111111

112112
// Make sure the search cell is in the same universe.
113-
int i_universe = p.coord(p.n_coord() - 1).universe;
113+
int i_universe = p.lowest_coord().universe;
114114
if (model::cells[i_cell]->universe_ != i_universe)
115115
continue;
116116

@@ -119,7 +119,7 @@ bool find_cell_inner(Particle& p, const NeighborList* neighbor_list)
119119
Direction u {p.u_local()};
120120
auto surf = p.surface();
121121
if (model::cells[i_cell]->contains(r, u, surf)) {
122-
p.coord(p.n_coord() - 1).cell = i_cell;
122+
p.lowest_coord().cell = i_cell;
123123
found = true;
124124
break;
125125
}
@@ -145,15 +145,15 @@ bool find_cell_inner(Particle& p, const NeighborList* neighbor_list)
145145
// code below this conditional, we set i_cell back to C_NONE to indicate
146146
// that.
147147
if (i_cell == C_NONE) {
148-
int i_universe = p.coord(p.n_coord() - 1).universe;
148+
int i_universe = p.lowest_coord().universe;
149149
const auto& univ {model::universes[i_universe]};
150150
found = univ->find_cell(p);
151151
}
152152

153153
if (!found) {
154154
return found;
155155
}
156-
i_cell = p.coord(p.n_coord() - 1).cell;
156+
i_cell = p.lowest_coord().cell;
157157

158158
// Announce the cell that the particle is entering.
159159
if (found && (settings::verbosity >= 10 || p.trace())) {
@@ -289,7 +289,7 @@ bool neighbor_list_find_cell(Particle& p)
289289

290290
bool exhaustive_find_cell(Particle& p)
291291
{
292-
int i_universe = p.coord(p.n_coord() - 1).universe;
292+
int i_universe = p.lowest_coord().universe;
293293
if (i_universe == C_NONE) {
294294
p.coord(0).universe = model::root_universe;
295295
p.n_coord() = 1;
@@ -306,7 +306,7 @@ bool exhaustive_find_cell(Particle& p)
306306

307307
void cross_lattice(Particle& p, const BoundaryInfo& boundary)
308308
{
309-
auto& coord {p.coord(p.n_coord() - 1)};
309+
auto& coord {p.lowest_coord()};
310310
auto& lat {*model::lattices[coord.lattice]};
311311

312312
if (settings::verbosity >= 10 || p.trace()) {
@@ -344,7 +344,7 @@ void cross_lattice(Particle& p, const BoundaryInfo& boundary)
344344

345345
} else {
346346
// Find cell in next lattice element.
347-
p.coord(p.n_coord() - 1).universe = lat[coord.lattice_i];
347+
p.lowest_coord().universe = lat[coord.lattice_i];
348348
bool found = exhaustive_find_cell(p);
349349

350350
if (!found) {
@@ -472,7 +472,7 @@ extern "C" int openmc_find_cell(
472472
return OPENMC_E_GEOMETRY;
473473
}
474474

475-
*index = p.coord(p.n_coord() - 1).cell;
475+
*index = p.lowest_coord().cell;
476476
*instance = p.cell_instance();
477477
return 0;
478478
}

‎src/particle.cpp‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ void Particle::event_calculate_xs()
147147
// If the cell hasn't been determined based on the particle's location,
148148
// initiate a search for the current cell. This generally happens at the
149149
// beginning of the history and again for any secondary particles
150-
if (coord(n_coord() - 1).cell == C_NONE) {
150+
if (lowest_coord().cell == C_NONE) {
151151
if (!exhaustive_find_cell(*this)) {
152152
mark_as_lost(
153153
"Could not find the cell containing particle " + std::to_string(id()));
@@ -156,7 +156,7 @@ void Particle::event_calculate_xs()
156156

157157
// Set birth cell attribute
158158
if (cell_born() == C_NONE)
159-
cell_born() = coord(n_coord() - 1).cell;
159+
cell_born() = lowest_coord().cell;
160160
}
161161

162162
// Write particle track.
@@ -392,15 +392,15 @@ void Particle::event_revive_from_secondary()
392392
// Since the birth cell of the particle has not been set we
393393
// have to determine it before the energy of the secondary particle can be
394394
// removed from the pulse-height of this cell.
395-
if (coord(n_coord() - 1).cell == C_NONE) {
395+
if (lowest_coord().cell == C_NONE) {
396396
if (!exhaustive_find_cell(*this)) {
397397
mark_as_lost("Could not find the cell containing particle " +
398398
std::to_string(id()));
399399
return;
400400
}
401401
// Set birth cell attribute
402402
if (cell_born() == C_NONE)
403-
cell_born() = coord(n_coord() - 1).cell;
403+
cell_born() = lowest_coord().cell;
404404
}
405405
pht_secondary_particles();
406406
}
@@ -456,7 +456,7 @@ void Particle::pht_collision_energy()
456456

457457
// determine index of cell in pulse_height_cells
458458
auto it = std::find(model::pulse_height_cells.begin(),
459-
model::pulse_height_cells.end(), coord(n_coord() - 1).cell);
459+
model::pulse_height_cells.end(), lowest_coord().cell);
460460

461461
if (it != model::pulse_height_cells.end()) {
462462
int index = std::distance(model::pulse_height_cells.begin(), it);
@@ -535,7 +535,7 @@ void Particle::cross_surface()
535535
material_last() = material();
536536
sqrtkT_last() = sqrtkT();
537537
// set new cell value
538-
coord(n_coord() - 1).cell = i_cell;
538+
lowest_coord().cell = i_cell;
539539
cell_instance() = 0;
540540
material() = model::cells[i_cell]->material_[0];
541541
sqrtkT() = model::cells[i_cell]->sqrtkT_[0];

‎src/plot.cpp‎

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ void IdData::set_value(size_t y, size_t x, const Particle& p, int level)
5858
}
5959

6060
// set material data
61-
Cell* c = model::cells.at(p.coord(p.n_coord() - 1).cell).get();
61+
Cell* c = model::cells.at(p.lowest_coord().cell).get();
6262
if (p.material() == MATERIAL_VOID) {
6363
data_(y, x, 2) = MATERIAL_VOID;
6464
return;
@@ -79,7 +79,7 @@ PropertyData::PropertyData(size_t h_res, size_t v_res)
7979

8080
void PropertyData::set_value(size_t y, size_t x, const Particle& p, int level)
8181
{
82-
Cell* c = model::cells.at(p.coord(p.n_coord() - 1).cell).get();
82+
Cell* c = model::cells.at(p.lowest_coord().cell).get();
8383
data_(y, x, 0) = (p.sqrtkT() * p.sqrtkT()) / K_BOLTZMANN;
8484
if (c->type_ != Fill::UNIVERSE && p.material() != MATERIAL_VOID) {
8585
Material* m = model::materials.at(p.material()).get();
@@ -1327,9 +1327,8 @@ void ProjectionPlot::create_output() const
13271327
// edges on the model boundary for the same cell.
13281328
if (first_inside_model) {
13291329
this_line_segments[tid][horiz].emplace_back(
1330-
color_by_ == PlotColorBy::mats
1331-
? p.material()
1332-
: p.coord(p.n_coord() - 1).cell,
1330+
color_by_ == PlotColorBy::mats ? p.material()
1331+
: p.lowest_coord().cell,
13331332
0.0, first_surface);
13341333
first_inside_model = false;
13351334
}
@@ -1339,7 +1338,7 @@ void ProjectionPlot::create_output() const
13391338
auto dist = distance_to_boundary(p);
13401339
this_line_segments[tid][horiz].emplace_back(
13411340
color_by_ == PlotColorBy::mats ? p.material()
1342-
: p.coord(p.n_coord() - 1).cell,
1341+
: p.lowest_coord().cell,
13431342
dist.distance, std::abs(dist.surface_index));
13441343

13451344
// Advance particle

‎src/tallies/filter_cell_instance.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ void CellInstanceFilter::set_cell_instances(gsl::span<CellInstance> instances)
7272
void CellInstanceFilter::get_all_bins(
7373
const Particle& p, TallyEstimator estimator, FilterMatch& match) const
7474
{
75-
gsl::index index_cell = p.coord(p.n_coord() - 1).cell;
75+
gsl::index index_cell = p.lowest_coord().cell;
7676
gsl::index instance = p.cell_instance();
7777

7878
if (cells_.count(index_cell) > 0) {

‎src/universe.cpp‎

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,18 +41,17 @@ bool Universe::find_cell(Particle& p) const
4141
const auto& cells {
4242
!partitioner_ ? cells_ : partitioner_->get_cells(p.r_local(), p.u_local())};
4343

44-
for (auto it = cells.begin(); it != cells.end(); it++) {
45-
int32_t i_cell = *it;
46-
int32_t i_univ = p.coord(p.n_coord() - 1).universe;
44+
Position r {p.r_local()};
45+
Position u {p.u_local()};
46+
auto surf = p.surface();
47+
int32_t i_univ = p.lowest_coord().universe;
48+
49+
for (auto i_cell : cells) {
4750
if (model::cells[i_cell]->universe_ != i_univ)
4851
continue;
49-
50-
// Check if this cell contains the particle;
51-
Position r {p.r_local()};
52-
Direction u {p.u_local()};
53-
auto surf = p.surface();
52+
// Check if this cell contains the particle
5453
if (model::cells[i_cell]->contains(r, u, surf)) {
55-
p.coord(p.n_coord() - 1).cell = i_cell;
54+
p.lowest_coord().cell = i_cell;
5655
return true;
5756
}
5857
}

0 commit comments

Comments
 (0)