Skip to content

Commit

Permalink
Fix distribcell labels for lattices used as fill in multiple cells (#…
Browse files Browse the repository at this point in the history
…2813)

Co-authored-by: Paul Romano <[email protected]>
  • Loading branch information
pshriwise and paulromano authored Apr 8, 2024
1 parent db3b6f3 commit c85ba93
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/geometry_aux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ std::string distribcell_path_inner(int32_t target_cell, int32_t map,

// The desired cell is the first cell that gives an offset smaller or
// equal to the target offset.
if (temp_offset <= target_offset)
if (temp_offset <= target_offset - c.offset_[map])
break;
}
}
Expand Down Expand Up @@ -570,11 +570,11 @@ std::string distribcell_path_inner(int32_t target_cell, int32_t map,
for (ReverseLatticeIter it = lat.rbegin(); it != lat.rend(); ++it) {
int32_t indx = lat.universes_.size() * map + it.indx_;
int32_t temp_offset = offset + lat.offsets_[indx];
if (temp_offset <= target_offset) {
if (temp_offset <= target_offset - c.offset_[map]) {
offset = temp_offset;
path << "(" << lat.index_to_string(it.indx_) << ")->";
path << distribcell_path_inner(
target_cell, map, target_offset, *model::universes[*it], offset);
path << distribcell_path_inner(target_cell, map, target_offset,
*model::universes[*it], offset + c.offset_[map]);
return path.str();
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/tallies/filter_distribcell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ void DistribcellFilter::get_all_bins(
auto& lat {*model::lattices[p.coord(i + 1).lattice]};
const auto& i_xyz {p.coord(i + 1).lattice_i};
if (lat.are_valid_indices(i_xyz)) {
offset += lat.offset(distribcell_index, i_xyz);
offset +=
lat.offset(distribcell_index, i_xyz) + c.offset_[distribcell_index];
}
}
if (cell_ == p.coord(i).cell) {
Expand Down
19 changes: 19 additions & 0 deletions tests/unit_tests/test_cell_instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

@pytest.fixture(scope='module', autouse=True)
def double_lattice_model():
openmc.reset_auto_ids()
model = openmc.Model()

# Create a single material
Expand Down Expand Up @@ -39,6 +40,18 @@ def double_lattice_model():
cell_with_lattice2.translation = (2., 0., 0.)
model.geometry = openmc.Geometry([cell_with_lattice1, cell_with_lattice2])

tally = openmc.Tally()
tally.filters = [openmc.DistribcellFilter(c)]
tally.scores = ['flux']
model.tallies = [tally]

# Add box source that covers the model space well
bbox = model.geometry.bounding_box
bbox[0][2] = -0.5
bbox[1][2] = 0.5
space = openmc.stats.Box(*bbox)
model.settings.source = openmc.IndependentSource(space=space)

# Add necessary settings and export
model.settings.batches = 10
model.settings.inactive = 0
Expand Down Expand Up @@ -71,3 +84,9 @@ def double_lattice_model():
def test_cell_instance_multilattice(r, expected_cell_instance):
_, cell_instance = openmc.lib.find_cell(r)
assert cell_instance == expected_cell_instance


def test_cell_instance_multilattice_results():
openmc.lib.run()
tally_results = openmc.lib.tallies[1].mean
assert (tally_results != 0.0).all()

0 comments on commit c85ba93

Please sign in to comment.